Example usage for org.eclipse.jdt.internal.core.search.matching MatchLocator encloses

List of usage examples for org.eclipse.jdt.internal.core.search.matching MatchLocator encloses

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core.search.matching MatchLocator encloses.

Prototype

protected boolean encloses(IJavaElement element) 

Source Link

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.search.matching.ReferenceToTeamLocator.java

License:Open Source License

/**
 * A match was found, perform final check:
 * if a role was specified check the current compilation unit's first type against the role name.
 * If successful report as a type reference match regarding this first type.
 *///w  w  w  .  ja  va 2s .  c o m
@Override
protected void matchReportImportRef(ImportReference importRef, Binding binding, IJavaElement element,
        int accuracy, MatchLocator locator) throws CoreException {
    if (locator.encloses(element)) {
        ICompilationUnit cu = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
        if (cu != null) {
            IType[] types = cu.getTypes();
            if (types != null && types.length > 0) {
                // only now we have the info to check the role name:
                if (this.pattern.roleName != null
                        && !new String(this.pattern.roleName).equals(types[0].getElementName()))
                    return;

                int offset = importRef.sourceStart;
                int length = importRef.sourceEnd - offset + 1;
                this.match = locator.newTypeReferenceMatch(types[0], null/*binding*/, accuracy, offset, length,
                        importRef);
                if (this.match != null)
                    locator.report(this.match);
            }
        }
    }
}