Example usage for org.eclipse.jdt.internal.core.search.matching PatternLocator COMPILATION_UNIT_CONTAINER

List of usage examples for org.eclipse.jdt.internal.core.search.matching PatternLocator COMPILATION_UNIT_CONTAINER

Introduction

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

Prototype

int COMPILATION_UNIT_CONTAINER

To view the source code for org.eclipse.jdt.internal.core.search.matching PatternLocator COMPILATION_UNIT_CONTAINER.

Click Source Link

Usage

From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java

License:Open Source License

/**
 * Visit the given resolved parse tree and report the nodes that match the search pattern.
 *//*from   ww w . java2  s.co  m*/
protected void reportMatching(CompilationUnitDeclaration unit, boolean mustResolve) throws CoreException {
    MatchingNodeSet nodeSet = this.currentPossibleMatch.nodeSet;
    boolean locatorMustResolve = this.patternLocator.mustResolve;
    if (nodeSet.mustResolve)
        this.patternLocator.mustResolve = true;
    if (BasicSearchEngine.VERBOSE) {
        System.out.println("Report matching: "); //$NON-NLS-1$
        int size = nodeSet.matchingNodes == null ? 0 : nodeSet.matchingNodes.elementSize;
        System.out.print("   - node set: accurate=" + size); //$NON-NLS-1$
        size = nodeSet.possibleMatchingNodesSet == null ? 0 : nodeSet.possibleMatchingNodesSet.elementSize;
        System.out.println(", possible=" + size); //$NON-NLS-1$
        System.out.print("   - must resolve: " + mustResolve); //$NON-NLS-1$
        System.out.print(" (locator: " + this.patternLocator.mustResolve); //$NON-NLS-1$
        System.out.println(", nodeSet: " + nodeSet.mustResolve + ')'); //$NON-NLS-1$
        System.out.println("   - fine grain flags=" //$NON-NLS-1$
                + JavaSearchPattern.getFineGrainFlagString(this.patternLocator.fineGrain()));
    }
    if (mustResolve) {
        this.unitScope = unit.scope.compilationUnitScope();
        // move the possible matching nodes that exactly match the search pattern to the matching nodes set
        Object[] nodes = nodeSet.possibleMatchingNodesSet.values;
        for (int i = 0, l = nodes.length; i < l; i++) {
            ASTNode node = (ASTNode) nodes[i];
            if (node == null)
                continue;
            if (node instanceof ImportReference) {
                // special case for import refs: they don't know their binding
                // import ref cannot be in the hierarchy of a type
                if (this.hierarchyResolver != null)
                    continue;

                ImportReference importRef = (ImportReference) node;
                Binding binding = (importRef.bits & ASTNode.OnDemand) != 0
                        ? this.unitScope.getImport(
                                CharOperation.subarray(importRef.tokens, 0, importRef.tokens.length), true,
                                importRef.isStatic())
                        : this.unitScope.getImport(importRef.tokens, false, importRef.isStatic());
                this.patternLocator.matchLevelAndReportImportRef(importRef, binding, this);
            } else {
                nodeSet.addMatch(node, this.patternLocator.resolveLevel(node));
            }
        }
        nodeSet.possibleMatchingNodesSet = new SimpleSet(3);
        if (BasicSearchEngine.VERBOSE) {
            int size = nodeSet.matchingNodes == null ? 0 : nodeSet.matchingNodes.elementSize;
            System.out.print("   - node set: accurate=" + size); //$NON-NLS-1$
            size = nodeSet.possibleMatchingNodesSet == null ? 0 : nodeSet.possibleMatchingNodesSet.elementSize;
            System.out.println(", possible=" + size); //$NON-NLS-1$
        }
    } else {
        this.unitScope = null;
    }

    if (nodeSet.matchingNodes.elementSize == 0)
        return; // no matching nodes were found
    this.methodHandles = new HashSet();

    boolean matchedUnitContainer = (this.matchContainer & PatternLocator.COMPILATION_UNIT_CONTAINER) != 0;

    // report references in javadoc
    if (unit.javadoc != null) {
        ASTNode[] nodes = nodeSet.matchingNodes(unit.javadoc.sourceStart, unit.javadoc.sourceEnd);
        if (nodes != null) {
            if (!matchedUnitContainer) {
                for (int i = 0, l = nodes.length; i < l; i++)
                    nodeSet.matchingNodes.removeKey(nodes[i]);
            } else {
                IJavaElement element = createPackageDeclarationHandle(unit);
                for (int i = 0, l = nodes.length; i < l; i++) {
                    ASTNode node = nodes[i];
                    Integer level = (Integer) nodeSet.matchingNodes.removeKey(node);
                    if (encloses(element)) {
                        this.patternLocator.matchReportReference(node, element, null, null, null/*no binding*/,
                                level.intValue(), this);
                    }
                }
            }
        }
    }

    if (matchedUnitContainer) {
        ImportReference pkg = unit.currentPackage;
        if (pkg != null && pkg.annotations != null) {
            IJavaElement element = createPackageDeclarationHandle(unit);
            if (element != null) {
                reportMatching(pkg.annotations, element, null, null, nodeSet, true, encloses(element));
            }
        }

        ImportReference[] imports = unit.imports;
        if (imports != null) {
            for (int i = 0, l = imports.length; i < l; i++) {
                ImportReference importRef = imports[i];
                Integer level = (Integer) nodeSet.matchingNodes.removeKey(importRef);
                if (level != null) {
                    this.patternLocator.matchReportImportRef(importRef, null /*no binding*/,
                            createImportHandle(importRef), level.intValue(), this);
                }
            }
        }
    }

    TypeDeclaration[] types = unit.types;
    if (types != null) {
        for (int i = 0, l = types.length; i < l; i++) {
            if (nodeSet.matchingNodes.elementSize == 0)
                return; // reported all the matching nodes
            TypeDeclaration type = types[i];
            Integer level = (Integer) nodeSet.matchingNodes.removeKey(type);
            int accuracy = (level != null && matchedUnitContainer) ? level.intValue() : -1;
            reportMatching(type, null, accuracy, nodeSet, 1);
        }
    }

    // Clear handle cache
    this.methodHandles = null;
    this.bindings.removeKey(this.pattern);
    this.patternLocator.mustResolve = locatorMustResolve;
}

From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocatorParser.java

License:Open Source License

public static MatchLocatorParser createParser(ProblemReporter problemReporter, MatchLocator locator) {
    // GROOVY Start
    /* old {//  w  w  w.  j a v a2 s.c om
    if ((locator.matchContainer & PatternLocator.COMPILATION_UNIT_CONTAINER) != 0) {
       return new ImportMatchLocatorParser(problemReporter, locator);
    }
    return new MatchLocatorParser(problemReporter, locator);
    } new */
    // use multiplexing parsers instead
    if ((locator.matchContainer & PatternLocator.COMPILATION_UNIT_CONTAINER) != 0) {
        return LanguageSupportFactory.getImportMatchLocatorParser(problemReporter, locator);
    }
    return LanguageSupportFactory.getMatchLocatorParser(problemReporter, locator);
    // GROOVY End
}