List of usage examples for org.eclipse.jdt.internal.core.search.matching PatternLocator CLASS_CONTAINER
int CLASS_CONTAINER
To view the source code for org.eclipse.jdt.internal.core.search.matching PatternLocator CLASS_CONTAINER.
Click Source Link
From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java
License:Open Source License
/** * Visit the given type declaration and report the nodes that match exactly the * search pattern (i.e. the ones in the matching nodes set) *///from www .j ava2 s. c om protected void reportMatching(TypeDeclaration type, IJavaElement parent, int accuracy, MatchingNodeSet nodeSet, int occurrenceCount) throws CoreException { // create type handle IJavaElement enclosingElement = parent; if (enclosingElement == null) { enclosingElement = createTypeHandle(new String(type.name)); } else if (enclosingElement instanceof IType) { enclosingElement = ((IType) parent).getType(new String(type.name)); } else if (enclosingElement instanceof IMember) { IMember member = (IMember) parent; if (member.isBinary()) { enclosingElement = ((IClassFile) this.currentPossibleMatch.openable).getType(); } else { enclosingElement = member.getType(new String(type.name), occurrenceCount); } } if (enclosingElement == null) return; boolean enclosesElement = encloses(enclosingElement); // report the type declaration if (accuracy > -1 && enclosesElement) { int offset = type.sourceStart; SearchMatch match = this.patternLocator.newDeclarationMatch(type, enclosingElement, type.binding, accuracy, type.sourceEnd - offset + 1, this); report(match); } boolean matchedClassContainer = (this.matchContainer & PatternLocator.CLASS_CONTAINER) != 0; // report the type parameters if (type.typeParameters != null) { reportMatching(type.typeParameters, enclosingElement, parent, type.binding, nodeSet); } // report annotations if (type.annotations != null) { reportMatching(type.annotations, enclosingElement, null, type.binding, nodeSet, matchedClassContainer, enclosesElement); } // report references in javadoc if (type.javadoc != null) { ASTNode[] nodes = nodeSet.matchingNodes(type.declarationSourceStart, type.sourceStart); if (nodes != null) { if (!matchedClassContainer) { for (int i = 0, l = nodes.length; i < l; i++) nodeSet.matchingNodes.removeKey(nodes[i]); } else { for (int i = 0, l = nodes.length; i < l; i++) { ASTNode node = nodes[i]; Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); if (enclosesElement) { this.patternLocator.matchReportReference(node, enclosingElement, null, null, type.binding, level.intValue(), this); } } } } } // super types if ((type.bits & ASTNode.IsAnonymousType) != 0) { TypeReference superType = type.allocation.type; if (superType != null) { Integer level = (Integer) nodeSet.matchingNodes.removeKey(superType); if (level != null && matchedClassContainer) this.patternLocator.matchReportReference(superType, enclosingElement, null, null, type.binding, level.intValue(), this); } } else { TypeReference superClass = type.superclass; if (superClass != null) { reportMatchingSuper(superClass, enclosingElement, type.binding, nodeSet, matchedClassContainer); } TypeReference[] superInterfaces = type.superInterfaces; if (superInterfaces != null) { for (int i = 0, l = superInterfaces.length; i < l; i++) { reportMatchingSuper(superInterfaces[i], enclosingElement, type.binding, nodeSet, matchedClassContainer); } } } // filter out element not in hierarchy scope boolean typeInHierarchy = type.binding == null || typeInHierarchy(type.binding); matchedClassContainer = matchedClassContainer && typeInHierarchy; // Visit fields FieldDeclaration[] fields = type.fields; if (fields != null) { if (nodeSet.matchingNodes.elementSize == 0) return; // end as all matching nodes were reported FieldDeclaration[] otherFields = null; int first = -1; int length = fields.length; for (int i = 0; i < length; i++) { FieldDeclaration field = fields[i]; boolean last = field.endPart2Position == 0 || field.declarationEnd == field.endPart2Position; // Store first index of multiple field declaration if (!last) { if (first == -1) { first = i; } } if (first >= 0) { // Store all multiple fields but first one for other elements if (i > first) { if (otherFields == null) { otherFields = new FieldDeclaration[length - i]; } otherFields[i - 1 - first] = field; } // On last field, report match with all other elements if (last) { for (int j = first; j <= i; j++) { Integer level = (Integer) nodeSet.matchingNodes.removeKey(fields[j]); int value = (level != null && matchedClassContainer) ? level.intValue() : -1; reportMatching(fields[j], otherFields, type, enclosingElement, value, typeInHierarchy, nodeSet); } first = -1; otherFields = null; } } else { // Single field, report normally Integer level = (Integer) nodeSet.matchingNodes.removeKey(field); int value = (level != null && matchedClassContainer) ? level.intValue() : -1; reportMatching(field, null, type, enclosingElement, value, typeInHierarchy, nodeSet); } } } // Visit methods AbstractMethodDeclaration[] methods = type.methods; if (methods != null) { if (nodeSet.matchingNodes.elementSize == 0) return; // end as all matching nodes were reported for (int i = 0, l = methods.length; i < l; i++) { AbstractMethodDeclaration method = methods[i]; Integer level = (Integer) nodeSet.matchingNodes.removeKey(method); int value = (level != null && matchedClassContainer) ? level.intValue() : -1; reportMatching(method, type, enclosingElement, value, typeInHierarchy, nodeSet); } } // Visit types TypeDeclaration[] memberTypes = type.memberTypes; if (memberTypes != null) { for (int i = 0, l = memberTypes.length; i < l; i++) { if (nodeSet.matchingNodes.elementSize == 0) return; // end as all matching nodes were reported TypeDeclaration memberType = memberTypes[i]; Integer level = (Integer) nodeSet.matchingNodes.removeKey(memberType); int value = (level != null && matchedClassContainer) ? level.intValue() : -1; reportMatching(memberType, enclosingElement, value, nodeSet, 1); } } }
From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java
License:Open Source License
protected void reportMatchingSuper(TypeReference superReference, IJavaElement enclosingElement, Binding elementBinding, MatchingNodeSet nodeSet, boolean matchedClassContainer) throws CoreException { ASTNode[] nodes = null;//from ww w . ja v a 2s .c om if (superReference instanceof ParameterizedSingleTypeReference || superReference instanceof ParameterizedQualifiedTypeReference) { long lastTypeArgumentInfo = findLastTypeArgumentInfo(superReference); nodes = nodeSet.matchingNodes(superReference.sourceStart, (int) lastTypeArgumentInfo); } if (nodes != null) { if ((this.matchContainer & PatternLocator.CLASS_CONTAINER) == 0) { for (int i = 0, l = nodes.length; i < l; i++) nodeSet.matchingNodes.removeKey(nodes[i]); } else { if (encloses(enclosingElement)) for (int i = 0, l = nodes.length; i < l; i++) { ASTNode node = nodes[i]; Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); this.patternLocator.matchReportReference(node, enclosingElement, null, null, elementBinding, level.intValue(), this); } } } else if (encloses(enclosingElement)) { Integer level = (Integer) nodeSet.matchingNodes.removeKey(superReference); if (level != null && matchedClassContainer) this.patternLocator.matchReportReference(superReference, enclosingElement, null, null, elementBinding, level.intValue(), this); } }
From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocatorParser.java
License:Open Source License
public //GROOVY End// ww w. j a v a 2s . c o m MatchLocatorParser(ProblemReporter problemReporter, MatchLocator locator) { super(problemReporter, true); this.reportOnlyOneSyntaxError = true; this.patternLocator = locator.patternLocator; if ((locator.matchContainer & PatternLocator.CLASS_CONTAINER) != 0) { this.localDeclarationVisitor = (locator.matchContainer & PatternLocator.METHOD_CONTAINER) != 0 ? new ClassAndMethodDeclarationVisitor() : new ClassButNoMethodDeclarationVisitor(); } else { this.localDeclarationVisitor = (locator.matchContainer & PatternLocator.METHOD_CONTAINER) != 0 ? new MethodButNoClassDeclarationVisitor() : new NoClassNoMethodDeclarationVisitor(); } this.patternFineGrain = this.patternLocator.fineGrain(); }