List of usage examples for org.eclipse.jdt.core ITypeRoot getAncestor
IJavaElement getAncestor(int ancestorType);
From source file:org.eclipse.recommenders.internal.rcp.JavaElementSelections.java
License:Open Source License
private static boolean isInvalidSelection(ITypeRoot root, final int offset) { try {// w w w . ja v a 2s. c om if (!root.exists()) { return true; } // check whether the type root is part of an package fragment root. If not, it's an invalid selection and // all resolutions are likely to fail. Thus, return true (=invalid): IJavaElement ancestor = root.getAncestor(IJavaProject.PACKAGE_FRAGMENT_ROOT); if (!ancestor.exists()) { return true; } ISourceRange range = root.getSourceRange(); return range == null || offset < 0 || offset > range.getLength(); } catch (Exception e) { log(ERROR_EXCEPTION_WHILE_CHECKING_OFFSETS, e); return false; } }