List of usage examples for org.eclipse.jdt.internal.core.search.matching PatternLocator FIELD_CONTAINER
int FIELD_CONTAINER
To view the source code for org.eclipse.jdt.internal.core.search.matching PatternLocator FIELD_CONTAINER.
Click Source Link
From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java
License:Open Source License
/** * Visit the given field declaration and report the nodes that match exactly the * search pattern (i.e. the ones in the matching nodes set) *//*from www.ja v a 2 s . co m*/ protected void reportMatching(FieldDeclaration field, FieldDeclaration[] otherFields, TypeDeclaration type, IJavaElement parent, int accuracy, boolean typeInHierarchy, MatchingNodeSet nodeSet) throws CoreException { IJavaElement enclosingElement = null; if (accuracy > -1) { enclosingElement = createHandle(field, type, parent); if (encloses(enclosingElement)) { int offset = field.sourceStart; SearchMatch match = newDeclarationMatch(enclosingElement, field.binding, accuracy, offset, field.sourceEnd - offset + 1); if (field.initialization instanceof AllocationExpression) { reportAccurateEnumConstructorReference(match, field, (AllocationExpression) field.initialization); } else { report(match); } } } // handle the nodes for the local type first if ((field.bits & ASTNode.HasLocalType) != 0) { if (enclosingElement == null) { enclosingElement = createHandle(field, type, parent); } // Traverse field declaration(s) to report matches both in local types declaration // and in local variables declaration int fieldEnd = field.endPart2Position == 0 ? field.declarationSourceEnd : field.endPart2Position; ASTNode[] nodes = typeInHierarchy ? nodeSet.matchingNodes(field.sourceStart, fieldEnd) : null; boolean report = (this.matchContainer & PatternLocator.FIELD_CONTAINER) != 0 && encloses(enclosingElement); MemberDeclarationVisitor declarationVisitor = new MemberDeclarationVisitor(enclosingElement, report ? nodes : null, nodeSet, this); try { field.traverse(declarationVisitor, (MethodScope) null); } catch (WrappedCoreException e) { throw e.coreException; } // Report all nodes and remove them if (nodes != null) { int length = nodes.length; for (int i = 0; i < length; i++) { ASTNode node = nodes[i]; Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); if (report && level != null) { if (node instanceof TypeDeclaration) { // use field declaration to report match (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=88174) AllocationExpression allocation = ((TypeDeclaration) node).allocation; if (allocation != null && allocation.enumConstant != null) { node = field; } } this.patternLocator.matchReportReference(node, enclosingElement, declarationVisitor.getLocalElement(i), declarationVisitor.getOtherElements(i), field.binding, level.intValue(), this); } } } } // report annotations IJavaElement[] otherElements = null; if (field.annotations != null) { if (enclosingElement == null) { enclosingElement = createHandle(field, type, parent); } if (otherFields != null) { otherElements = createHandles(otherFields, type, parent); } reportMatching(field.annotations, enclosingElement, otherElements, field.binding, nodeSet, true, true); } if (typeInHierarchy) { // Look at field declaration if (field.endPart1Position != 0) { // not necessary if field is an initializer ASTNode[] nodes = nodeSet.matchingNodes(field.declarationSourceStart, field.endPart1Position); if (nodes != null) { if ((this.matchContainer & PatternLocator.FIELD_CONTAINER) == 0) { for (int i = 0, l = nodes.length; i < l; i++) nodeSet.matchingNodes.removeKey(nodes[i]); } else { if (enclosingElement == null) enclosingElement = createHandle(field, type, parent); if (encloses(enclosingElement)) { for (int i = 0, l = nodes.length; i < l; i++) { ASTNode node = nodes[i]; Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); if (otherFields != null && otherElements == null) { otherElements = createHandles(otherFields, type, parent); } this.patternLocator.matchReportReference(node, enclosingElement, null, otherElements, field.binding, level.intValue(), this); } } } } } // Look in initializer int fieldEnd = field.endPart2Position == 0 ? field.declarationSourceEnd : field.endPart2Position; ASTNode[] nodes = nodeSet.matchingNodes(field.sourceStart, fieldEnd); if (nodes != null) { if ((this.matchContainer & PatternLocator.FIELD_CONTAINER) == 0) { for (int i = 0, l = nodes.length; i < l; i++) { nodeSet.matchingNodes.removeKey(nodes[i]); } } else { if (enclosingElement == null) { enclosingElement = createHandle(field, type, parent); } if (encloses(enclosingElement)) { MemberDeclarationVisitor declarationVisitor = new MemberDeclarationVisitor(enclosingElement, nodes, nodeSet, this); field.traverse(declarationVisitor, (MethodScope) null); int length = nodes.length; for (int i = 0; i < length; i++) { ASTNode node = nodes[i]; Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); if (level != null) { // ensure that the reference has not been already reported while visiting if (node instanceof TypeDeclaration) { // use field declaration to report match (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=88174) AllocationExpression allocation = ((TypeDeclaration) node).allocation; if (allocation != null && allocation.enumConstant != null) { node = field; } } this.patternLocator.matchReportReference(node, enclosingElement, declarationVisitor.getLocalElement(i), declarationVisitor.getOtherElements(i), field.binding, level.intValue(), this); } } return; } } } } }