Example usage for org.eclipse.jdt.core ITypeRoot getAncestor

List of usage examples for org.eclipse.jdt.core ITypeRoot getAncestor

Introduction

In this page you can find the example usage for org.eclipse.jdt.core ITypeRoot getAncestor.

Prototype

IJavaElement getAncestor(int ancestorType);

Source Link

Document

Returns this Java element or the first ancestor of this element that has the given type.

Usage

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;
    }
}