List of usage examples for org.eclipse.jdt.core ITypeRoot getJavaProject
IJavaProject getJavaProject();
null
if this element is not contained in any Java project (for instance, the IJavaModel
is not contained in any Java project). From source file:cideplus.ui.astview.ASTView.java
License:Open Source License
public void setInput(ITextEditor editor) throws CoreException { if (fEditor != null) { uninstallModificationListener(); }//from w w w .ja va 2 s. c o m fEditor = null; fRoot = null; if (editor != null) { ITypeRoot typeRoot = EditorUtility.getJavaInput(editor); /* try { System.out.println(editor.getEditorInput().getName()); Field declaredField = AbstractTextEditor.class.getDeclaredField("fSourceViewer"); declaredField.setAccessible(true); ISourceViewer sourceViewer = (ISourceViewer) declaredField.get(editor); ((ITextViewerExtension4)sourceViewer).addTextPresentationListener(new ColorPresentation(sourceViewer, editor)); sourceViewer.changeTextPresentation(new TextPresentation(200), false); } catch (Exception e) { System.err.println("ERRROOO "+e+" "+e.getMessage()); e.printStackTrace(); } */ if (typeRoot == null) { throw new CoreException(getErrorStatus("Editor not showing a CU or class file", null)); //$NON-NLS-1$ } fTypeRoot = typeRoot; int astLevel = getInitialASTLevel(typeRoot); ISelection selection = editor.getSelectionProvider().getSelection(); if (selection instanceof ITextSelection) { ITextSelection textSelection = (ITextSelection) selection; fRoot = internalSetInput(typeRoot, textSelection.getOffset(), textSelection.getLength(), astLevel); fEditor = editor; setASTLevel(astLevel, false); } /* Inicia o featuresManager para o projeto selecionado */ featuresManager = FeaturesConfigurationUtil.getFeaturesManager(typeRoot.getJavaProject().getProject()); if (fEditor.getEditorInput() instanceof IFileEditorInput) { //IFile file = ((IFileEditorInput) fEditor.getEditorInput()).getFile(); //javaFileFullPath = file.getFullPath().toString(); final IProblemRequestor problemRequestor = new IProblemRequestor() { //strange: don't get bindings when supplying null as problemRequestor public void acceptProblem(IProblem problem) { /*not interested*/} public void beginReporting() { /*not interested*/} public void endReporting() { /*not interested*/} public boolean isActive() { return true; } }; WorkingCopyOwner copyOwner = new WorkingCopyOwner() { @Override public IProblemRequestor getProblemRequestor(ICompilationUnit workingCopy) { return problemRequestor; } }; ICompilationUnit compilation = typeRoot.getWorkingCopy(copyOwner, null); try { compilationUnitFeaturesManager = featuresManager.getManagerForFile(compilation); fASTLabelProvider.setCompilationUnitFeaturesManager(compilationUnitFeaturesManager); //refreshAST(); fViewer.refresh(); } catch (Exception e) { showAndLogError("Could not read featurer file for compilation unit. " + e.getMessage(), e); } } installModificationListener(); } }
From source file:cideplus.ui.astview.ASTView.java
License:Open Source License
private int getInitialASTLevel(ITypeRoot typeRoot) { String option = typeRoot.getJavaProject().getOption(JavaCore.COMPILER_SOURCE, true); if (option.compareTo(JavaCore.VERSION_1_5) >= 0) { return JLS3; }/* w ww. j a v a 2s .c o m*/ return fCurrentASTLevel; // use previous level }
From source file:com.intel.ide.eclipse.mpt.ast.UnresolvedElementsSubProcessor.java
License:Open Source License
private static String getExpressionBaseName(Expression expr) { IBinding argBinding = Bindings.resolveExpressionBinding(expr, true); if (argBinding instanceof IVariableBinding) { IJavaProject project = null;//from www. ja v a 2s . c om ASTNode root = expr.getRoot(); if (root instanceof CompilationUnit) { ITypeRoot typeRoot = ((CompilationUnit) root).getTypeRoot(); if (typeRoot != null) project = typeRoot.getJavaProject(); } return StubUtility.getBaseName((IVariableBinding) argBinding, project); } if (expr instanceof SimpleName) return ((SimpleName) expr).getIdentifier(); return null; }
From source file:jmockit.assist.ASTUtil.java
License:Open Source License
public static CompilationUnit parse(final ITypeRoot unit, final IProgressMonitor mon) { ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setKind(ASTParser.K_COMPILATION_UNIT); parser.setSource(unit);// w ww . ja v a 2 s .c o m parser.setProject(unit.getJavaProject()); parser.setResolveBindings(true); parser.setStatementsRecovery(true); return (CompilationUnit) parser.createAST(mon); // parse }
From source file:org.eclipse.che.plugin.java.server.JavaNavigation.java
License:Open Source License
/** * Get the compilation unit representation of the java file. * * @param javaProject/* w w w.j a v a 2 s . c o m*/ * path to the project which is contained class file * @param fqn * fully qualified name of the class file * @param isShowingInheritedMembers * <code>true</code> iff inherited members are shown * @return instance of {@link CompilationUnit} * @throws JavaModelException * when JavaModel has a failure */ public CompilationUnit getCompilationUnitByPath(IJavaProject javaProject, String fqn, boolean isShowingInheritedMembers) throws JavaModelException { IType type = javaProject.findType(fqn); CompilationUnit compilationUnit = DtoFactory.newDto(CompilationUnit.class); ITypeRoot unit; if (type.isBinary()) { unit = type.getClassFile(); compilationUnit.setPath(((IClassFile) unit).getType().getFullyQualifiedName()); } else { unit = type.getCompilationUnit(); compilationUnit.setProjectPath(unit.getJavaProject().getPath().toOSString()); compilationUnit.setPath(unit.getResource().getFullPath().toOSString()); } compilationUnit.setElementName(unit.getElementName()); compilationUnit.setHandleIdentifier(unit.getHandleIdentifier()); compilationUnit.setLabel(org.eclipse.jdt.ui.JavaElementLabels.getElementLabel(unit, org.eclipse.jdt.ui.JavaElementLabels.ALL_DEFAULT)); List<Type> types = new ArrayList<>(1); Type dtoType = convertToDTOType(type); dtoType.setPrimary(true); types.add(dtoType); compilationUnit.setTypes(types); if (isShowingInheritedMembers) { compilationUnit.setSuperTypes(calculateSuperTypes(type)); } return compilationUnit; }
From source file:org.eclipse.modisco.java.discoverer.internal.io.java.JavaReader.java
License:Open Source License
protected void parseTypeRoot(final ITypeRoot source) { org.eclipse.jdt.core.dom.CompilationUnit parsedCompilationUnit = parseCompilationUnit(source); String fileContent = null;/*from w w w . j av a 2s . c o m*/ String filePath = null; try { if (source instanceof ICompilationUnit) { IFile theIFile = ResourcesPlugin.getWorkspace().getRoot() .getFile(parsedCompilationUnit.getJavaElement().getPath()); // getContent(IFile) is faster than ICompilationUnit.getSource() fileContent = getContent(theIFile).toString(); IProject project = source.getJavaProject().getProject(); filePath = getRelativePath(project, parsedCompilationUnit); } else { // IJavaElement.CLASS_FILE fileContent = LibraryReader.getFileContent((IClassFile) source); filePath = LibraryReader.getPath((IClassFile) source); } visitCompilationUnit(getResultModel(), parsedCompilationUnit, filePath, fileContent); } catch (Exception e) { MoDiscoLogger.logError(e, JavaActivator.getDefault()); } }
From source file:org.eclipse.recommenders.codesearch.rcp.index.indexer.AstHelper.java
License:Open Source License
public static IProject getProject(ASTNode node) { while (node != null && !(node instanceof CompilationUnit)) { node = node.getParent();/*from w w w. j a v a 2s.c om*/ } final ITypeRoot root = ((CompilationUnit) node).getTypeRoot(); if (root == null) { final IJavaProject property = (IJavaProject) node.getProperty("project"); return property.getProject(); } return root.getJavaProject().getProject(); }
From source file:org.jboss.tools.arquillian.ui.internal.detectors.ArquillianResourceHyperlinkDetector.java
License:Open Source License
private IFile getFile(String resource, ITypeRoot javaElement) { IJavaProject project = javaElement.getJavaProject(); try {//from www. j a v a 2s. co m IPackageFragmentRoot[] roots = project.getAllPackageFragmentRoots(); for (IPackageFragmentRoot root : roots) { if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { IPath path = root.getPath(); path = path.append(resource); path = path.removeFirstSegments(1); IFile file = project.getProject().getFile(path); if (file != null && file.exists()) { return file; } } } } catch (JavaModelException e) { ArquillianUIActivator.log(e); } return null; }
From source file:org.jboss.tools.cdi.deltaspike.text.ext.AuthorizerHyperlinkDetector.java
License:Open Source License
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) { this.region = region; this.viewer = textViewer; ITextEditor textEditor = (ITextEditor) getAdapter(ITextEditor.class); if (region == null || !canShowMultipleHyperlinks || !(textEditor instanceof JavaEditor)) return null; int offset = region.getOffset(); ITypeRoot input = EditorUtility.getEditorInputJavaElement(textEditor, false); if (input == null) return null; document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); IRegion wordRegion = JavaWordFinder.findWord(document, offset); if (wordRegion == null) return null; IProject project = null;//from w ww. java2 s.com project = input.getJavaProject().getProject(); if (project == null) return null; CDICoreNature cdiNature = CDIUtil.getCDINatureWithProgress(project); if (cdiNature == null) return null; IJavaElement[] elements = null; IType annotationType = null; try { elements = input.codeSelect(wordRegion.getOffset(), wordRegion.getLength()); if (elements == null) return null; if (elements.length != 1) return null; ArrayList<IHyperlink> hyperlinks = new ArrayList<IHyperlink>(); int position = 0; if (elements[0] instanceof IType) { annotationType = (IType) elements[0]; if (!annotationType.isAnnotation()) { annotationType = null; } elements[0] = input.getElementAt(wordRegion.getOffset()); if (elements[0] == null) return null; if (elements[0] instanceof IMethod) { position = offset; } } findAuthorizerMethods(cdiNature, elements[0], annotationType, position, input.getPath(), hyperlinks); if (hyperlinks != null && !hyperlinks.isEmpty()) { return (IHyperlink[]) hyperlinks.toArray(new IHyperlink[hyperlinks.size()]); } } catch (JavaModelException jme) { DeltaspikeCorePlugin.getDefault().logError(jme); } return null; }
From source file:org.jboss.tools.cdi.seam.text.ext.hyperlink.GenericInjectedPointHyperlinkDetector.java
License:Open Source License
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) { this.region = region; this.viewer = textViewer; ITextEditor textEditor = (ITextEditor) getAdapter(ITextEditor.class); if (region == null || !canShowMultipleHyperlinks || !(textEditor instanceof JavaEditor)) return null; int offset = region.getOffset(); ITypeRoot input = EditorUtility.getEditorInputJavaElement(textEditor, false); if (input == null) return null; document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); IRegion wordRegion = JavaWordFinder.findWord(document, offset); if (wordRegion == null) return null; IProject project = null;// ww w . j ava2 s . c o m project = input.getJavaProject().getProject(); if (project == null) return null; CDICoreNature cdiNature = CDIUtil.getCDINatureWithProgress(project); if (cdiNature == null) return null; IJavaElement[] elements = null; try { elements = input.codeSelect(wordRegion.getOffset(), wordRegion.getLength()); if (elements == null) return null; if (elements.length != 1) return null; ArrayList<IHyperlink> hyperlinks = new ArrayList<IHyperlink>(); int position = 0; if (elements[0] instanceof IType) { elements[0] = input.getElementAt(wordRegion.getOffset()); if (elements[0] == null) return null; if (elements[0] instanceof IMethod) { position = offset; } } findInjectedBeans(cdiNature, elements[0], position, input.getPath(), hyperlinks); if (hyperlinks != null && !hyperlinks.isEmpty()) { return (IHyperlink[]) hyperlinks.toArray(new IHyperlink[hyperlinks.size()]); } } catch (JavaModelException jme) { CDISeamExtPlugin.getDefault().logError(jme); } return null; }