List of usage examples for org.eclipse.jdt.core ITypeRoot getElementType
int getElementType();
From source file:com.ashigeru.eclipse.util.jdt.internal.ui.handlers.InsertAssertionHandler.java
License:Apache License
private ICompilationUnit getJavaElement(IEditorPart editor) { assert editor != null; IEditorInput input = editor.getEditorInput(); ITypeRoot element = JavaUI.getEditorInputTypeRoot(input); if (element == null || element.getElementType() != IJavaElement.COMPILATION_UNIT) { return null; }/*from w w w . j a v a2 s .c o m*/ return (ICompilationUnit) element; }
From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java
License:Open Source License
/** * Find the java element corresponding to the handle. We know that it exists in * as a class file in a binary folder, but it may actually be * a source file in a different project//from ww w . j a v a2 s . co m */ private IJavaElement findElementInBinaryFolder(HandleInfo handleInfo, IClassFile classFile) throws JavaModelException { IJavaElement candidate = classFile; // we have a class file that is not in a jar. // can we find this as a source file in some project? IPath path = classFile.getPath(); IJavaProject otherProject = JavaCore.create(project).getJavaModel().getJavaProject(path.segment(0)); ITypeRoot typeRoot = classFile; if (otherProject.exists()) { IType type = otherProject.findType(handleInfo.sourceTypeQualName()); typeRoot = type.getTypeRoot(); if (typeRoot instanceof ICompilationUnit) { AJCompilationUnit newUnit = CompilationUnitTools .convertToAJCompilationUnit((ICompilationUnit) typeRoot); typeRoot = newUnit != null ? newUnit : typeRoot; } } if (handleInfo.isType) { switch (typeRoot.getElementType()) { case IJavaElement.CLASS_FILE: candidate = ((IClassFile) typeRoot).getType(); break; case IJavaElement.COMPILATION_UNIT: candidate = CompilationUnitTools.findType((ICompilationUnit) typeRoot, classFile.getType().getElementName(), true); break; default: // shouldn't happen break; } } else if (!handleInfo.isFile && !handleInfo.isType) { // program element will exist only if coming from aspect path IProgramElement ipe = getProgramElement(handleInfo.origAJHandle); if (ipe != IHierarchy.NO_STRUCTURE) { candidate = typeRoot.getElementAt(offsetFromLine(typeRoot, ipe.getSourceLocation())); } else { String newHandle = typeRoot.getHandleIdentifier() + handleInfo.restHandle; candidate = AspectJCore.create(newHandle); } } return candidate; }