public static ICompilationUnit getCompilationUnit(IJavaElement javaElement){ if (javaElement instanceof ICompilationUnit) { return (ICompilationUnit) javaElement; } return (ICompilationUnit) javaElement.getAncestor(IJavaElement.COMPILATION_UNIT); }
protected static final ICompilationUnit getEnclosingCompilationUnit(IJavaElement element) { if (element instanceof ICompilationUnit) { return (ICompilationUnit) element; } return (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT); }
public static IType getDeclaringType(IJavaElement element) { if (element == null) { return null; } if (!(element instanceof IType)) { element = element.getAncestor(IJavaElement.TYPE); } return (IType) element; }
private static IType convertToEnclosingType(IJavaElement element) { if (element == null) return null; if (! (element instanceof IType)) element= element.getAncestor(IJavaElement.TYPE); return (IType)element; } }
/** * Returns the package fragment root of <code>IJavaElement</code>. If the given * element is already a package fragment root, the element itself is returned. */ public static IPackageFragmentRoot getPackageFragmentRoot(IJavaElement element) { return (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); }
private static ICompilationUnit getEnclosingCu(IJavaElement destination) { if (destination instanceof ICompilationUnit) return (ICompilationUnit) destination; return (ICompilationUnit) destination.getAncestor(IJavaElement.COMPILATION_UNIT); }
private static IType convertToEnclosingType(IJavaElement element) { if (element == null) return null; if (! (element instanceof IType)) element= element.getAncestor(IJavaElement.TYPE); return (IType)element; } }
/** * Returns the package fragment root of <code>IJavaElement</code>. If the given * element is already a package fragment root, the element itself is returned. * @param element the element * @return the package fragment root of the element or <code>null</code> */ public static IPackageFragmentRoot getPackageFragmentRoot(IJavaElement element) { return (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); }
private static IType convertToEnclosingType(IJavaElement element) { if (element == null) return null; if (! (element instanceof IType)) element= element.getAncestor(IJavaElement.TYPE); return (IType)element; } }
private static IType getEnclosingType(IJavaElement element) { if (element instanceof IType) return (IType) element; return (IType) element.getAncestor(IJavaElement.TYPE); }
@Override public void acceptSearchMatch(SearchMatch match) throws CoreException { Object o = match.getElement(); if (o instanceof IJavaElement && ((IJavaElement) o).getAncestor(IJavaElement.COMPILATION_UNIT) != null) { count.incrementAndGet(); } } }, monitor);
private IClassFile getSourceClassFile() { // all have a common parent, so all must be in the same classfile // we checked before that the array in not null and not empty return (IClassFile) getJavaElements()[0].getAncestor(IJavaElement.CLASS_FILE); } }
public static FindOccurrencesEngine create(IJavaElement root, IOccurrencesFinder finder) { if (root == null || finder == null) return null; ICompilationUnit unit= (ICompilationUnit)root.getAncestor(IJavaElement.COMPILATION_UNIT); if (unit != null) return new FindOccurencesCUEngine(unit, finder); IClassFile cf= (IClassFile)root.getAncestor(IJavaElement.CLASS_FILE); if (cf != null) return new FindOccurencesClassFileEngine(cf, finder); return null; }
private IClassFile getSourceClassFile() { // all have a common parent, so all must be in the same classfile // we checked before that the array in not null and not empty return (IClassFile) getJavaElements()[0].getAncestor(IJavaElement.CLASS_FILE); } }
public static boolean isArchiveOrExternalMember(IJavaElement[] elements) { for (int i= 0; i < elements.length; i++) { IJavaElement element= elements[i]; IPackageFragmentRoot root= (IPackageFragmentRoot)element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root != null && (root.isArchive() || root.isExternal())) { return true; } } return false; }
public static boolean isArchiveOrExternalMember(IJavaElement[] elements) { for (int i= 0; i < elements.length; i++) { IJavaElement element= elements[i]; IPackageFragmentRoot root= (IPackageFragmentRoot)element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root != null && (root.isArchive() || root.isExternal())) return true; } return false; }
private String getEnclosingTypeName(int codeAssistOffset, ICompilationUnit compilationUnit) throws JavaModelException { IJavaElement element= compilationUnit.getElementAt(codeAssistOffset); if (element == null) return null; element= element.getAncestor(IJavaElement.TYPE); if (element == null) return null; return element.getElementName(); }
private static void convertTextChange(WorkspaceEdit root, IJavaElement element, TextChange textChange) { TextEdit textEdits = textChange.getEdit(); if (textEdits == null) { return; } ICompilationUnit compilationUnit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT); convertTextEdit(root, compilationUnit, textEdits); }
private static IJavaElement getAsTypeOrCu(IJavaElement element) { //try to get type first if (element.getElementType() == IJavaElement.COMPILATION_UNIT || element.getElementType() == IJavaElement.TYPE) return element; IJavaElement ancestorType= element.getAncestor(IJavaElement.TYPE); if (ancestorType != null) return ancestorType; return ReorgUtils.getCompilationUnit(element); } private static class ReorgTypedSourcePasteStarter {
static class IntArrayList { public int[] list = new int[5]; public int length = 0; public void add(int i) { if (this.list.length == this.length) { System.arraycopy(this.list, 0, this.list = new int[this.length*2], 0, this.length); } this.list[this.length++] = i; } }