View | Details | Raw Unified | Return to bug 83230
Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/compiler/SourceElementParser.java (+14 lines)
Lines 329-334 Link Here
329
		requestor.acceptFieldReference(fr.token, fr.sourceStart);
329
		requestor.acceptFieldReference(fr.token, fr.sourceStart);
330
	}
330
	}
331
}
331
}
332
protected void consumeMemberValuePair() {
333
	super.consumeMemberValuePair();
334
	MemberValuePair memberValuepair = (MemberValuePair) this.astStack[this.astPtr];
335
	if (reportReferenceInfo) {
336
		requestor.acceptMethodReference(memberValuepair.name, 0, memberValuepair.sourceStart);
337
	}
338
}
332
protected void consumeMethodHeaderName(boolean isAnnotationMethod) {
339
protected void consumeMethodHeaderName(boolean isAnnotationMethod) {
333
	long selectorSourcePositions = this.identifierPositionStack[this.identifierPtr];
340
	long selectorSourcePositions = this.identifierPositionStack[this.identifierPtr];
334
	int selectorSourceEnd = (int) selectorSourcePositions;
341
	int selectorSourceEnd = (int) selectorSourcePositions;
Lines 435-440 Link Here
435
			(int)(messageSend.nameSourcePosition >>> 32));
442
			(int)(messageSend.nameSourcePosition >>> 32));
436
	}
443
	}
437
}
444
}
445
protected void consumeSingleMemberAnnotation() {
446
	super.consumeSingleMemberAnnotation();
447
	SingleMemberAnnotation member = (SingleMemberAnnotation) expressionStack[expressionPtr];
448
	if (reportReferenceInfo) {
449
		requestor.acceptMethodReference(TypeConstants.VALUE, 0, member.sourceStart);
450
	}
451
}
438
protected void consumeSingleStaticImportDeclarationName() {
452
protected void consumeSingleStaticImportDeclarationName() {
439
	// SingleTypeImportDeclarationName ::= 'import' 'static' Name
453
	// SingleTypeImportDeclarationName ::= 'import' 'static' Name
440
	super.consumeSingleStaticImportDeclarationName();
454
	super.consumeSingleStaticImportDeclarationName();
(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java (-26 / +38 lines)
Lines 1767-1781 Link Here
1767
1767
1768
	// report annotations
1768
	// report annotations
1769
	if (method.annotations != null) {
1769
	if (method.annotations != null) {
1770
		for (int i=0, al=method.annotations.length; i<al; i++) {
1770
		if (enclosingElement == null) {
1771
			TypeReference typeRef = method.annotations[i].type;
1771
			enclosingElement = createHandle(method, parent);
1772
			Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeRef);
1773
			if (level != null) {
1774
				if (enclosingElement == null)
1775
					enclosingElement = createHandle(method, parent);
1776
				this.patternLocator.matchReportReference(typeRef, enclosingElement, method.binding, level.intValue(), this);
1777
			}
1778
		}
1772
		}
1773
		reportMatching(method.annotations, enclosingElement, method.binding, nodeSet, true, true);
1779
	}
1774
	}
1780
1775
1781
	// references in this method
1776
	// references in this method
Lines 1800-1805 Link Here
1800
	}
1795
	}
1801
}
1796
}
1802
/**
1797
/**
1798
 * Report matching in annotations.
1799
 */
1800
protected void reportMatching(Annotation[] annotations, IJavaElement enclosingElement, Binding elementBinding, MatchingNodeSet nodeSet, boolean matchedContainer, boolean enclosesElement) throws CoreException {
1801
	for (int i=0, al=annotations.length; i<al; i++) {
1802
		Annotation annotationType = annotations[i];
1803
1804
		// Look for annotation type ref
1805
		TypeReference typeRef = annotationType.type;
1806
		Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeRef);
1807
		if (level != null && matchedContainer) {
1808
			this.patternLocator.matchReportReference(typeRef, enclosingElement, elementBinding, level.intValue(), this);
1809
		}
1810
		
1811
		// Look for attribute ref
1812
		MemberValuePair[] pairs = annotationType.memberValuePairs();
1813
		for (int j = 0, pl = pairs.length; j < pl; j++) {
1814
			MemberValuePair pair = pairs[j];
1815
			level = (Integer) nodeSet.matchingNodes.removeKey(pair);
1816
			if (level != null && enclosesElement) {
1817
				ASTNode reference = (annotationType instanceof SingleMemberAnnotation) ? (ASTNode) annotationType: pair;
1818
				this.patternLocator.matchReportReference(reference, enclosingElement, pair.binding, level.intValue(), this);
1819
			}
1820
		}
1821
	}
1822
}
1823
/**
1803
 * Visit the given resolved parse tree and report the nodes that match the search pattern.
1824
 * Visit the given resolved parse tree and report the nodes that match the search pattern.
1804
 */
1825
 */
1805
protected void reportMatching(CompilationUnitDeclaration unit, boolean mustResolve) throws CoreException {
1826
protected void reportMatching(CompilationUnitDeclaration unit, boolean mustResolve) throws CoreException {
Lines 1889-1903 Link Here
1889
1910
1890
	// report annotations
1911
	// report annotations
1891
	if (field.annotations != null) {
1912
	if (field.annotations != null) {
1892
		for (int i=0, al=field.annotations.length; i<al; i++) {
1913
		if (enclosingElement == null) {
1893
			TypeReference typeRef = field.annotations[i].type;
1914
			enclosingElement = createHandle(field, type, parent);
1894
			Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeRef);
1895
			if (level != null) {
1896
				if (enclosingElement == null)
1897
					enclosingElement = createHandle(field, type, parent);
1898
				this.patternLocator.matchReportReference(typeRef, enclosingElement, field.binding, level.intValue(), this);
1899
			}
1900
		}
1915
		}
1916
		reportMatching(field.annotations, enclosingElement, field.binding, nodeSet, true, true);
1901
	}
1917
	}
1902
1918
1903
	if (typeInHierarchy) {
1919
	if (typeInHierarchy) {
Lines 1940-1948 Link Here
1940
			enclosingElement = member.getType(new String(type.name), occurrenceCount);
1956
			enclosingElement = member.getType(new String(type.name), occurrenceCount);
1941
	}
1957
	}
1942
	if (enclosingElement == null) return;
1958
	if (enclosingElement == null) return;
1959
	boolean enclosesElement = encloses(enclosingElement);
1943
1960
1944
	// report the type declaration
1961
	// report the type declaration
1945
	if (accuracy > -1 && encloses(enclosingElement)) {
1962
	if (accuracy > -1 && enclosesElement) {
1946
		int offset = type.sourceStart;
1963
		int offset = type.sourceStart;
1947
		SearchMatch match = this.patternLocator.newDeclarationMatch(type, enclosingElement, type.binding, accuracy, type.sourceEnd-offset+1, this);
1964
		SearchMatch match = this.patternLocator.newDeclarationMatch(type, enclosingElement, type.binding, accuracy, type.sourceEnd-offset+1, this);
1948
		report(match);
1965
		report(match);
Lines 1957-1963 Link Here
1957
			if (typeParameter != null) {
1974
			if (typeParameter != null) {
1958
				Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeParameter);
1975
				Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeParameter);
1959
				if (level != null && matchedClassContainer) {
1976
				if (level != null && matchedClassContainer) {
1960
					if (level.intValue() > -1 && encloses(enclosingElement)) {
1977
					if (level.intValue() > -1 && enclosesElement) {
1961
						int offset = typeParameter.sourceStart;
1978
						int offset = typeParameter.sourceStart;
1962
						SearchMatch match = this.patternLocator.newDeclarationMatch(typeParameter, enclosingElement, type.binding, level.intValue(), typeParameter.sourceEnd-offset+1, this);
1979
						SearchMatch match = this.patternLocator.newDeclarationMatch(typeParameter, enclosingElement, type.binding, level.intValue(), typeParameter.sourceEnd-offset+1, this);
1963
						report(match);
1980
						report(match);
Lines 1983-1995 Link Here
1983
2000
1984
	// report annotations
2001
	// report annotations
1985
	if (type.annotations != null) {
2002
	if (type.annotations != null) {
1986
		for (int i=0, al=type.annotations.length; i<al; i++) {
2003
		reportMatching(type.annotations, enclosingElement, type.binding, nodeSet, matchedClassContainer, enclosesElement);
1987
			TypeReference typeRef = type.annotations[i].type;
1988
			Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeRef);
1989
			if (level != null && matchedClassContainer) {
1990
				this.patternLocator.matchReportReference(typeRef, enclosingElement, type.binding, level.intValue(), this);
1991
			}
1992
		}
1993
	}
2004
	}
1994
2005
1995
	// report references in javadoc
2006
	// report references in javadoc
Lines 2003-2010 Link Here
2003
				for (int i = 0, l = nodes.length; i < l; i++) {
2014
				for (int i = 0, l = nodes.length; i < l; i++) {
2004
					ASTNode node = nodes[i];
2015
					ASTNode node = nodes[i];
2005
					Integer level = (Integer) nodeSet.matchingNodes.removeKey(node);
2016
					Integer level = (Integer) nodeSet.matchingNodes.removeKey(node);
2006
					if (encloses(enclosingElement))
2017
					if (enclosesElement) {
2007
						this.patternLocator.matchReportReference(node, enclosingElement, type.binding, level.intValue(), this);
2018
						this.patternLocator.matchReportReference(node, enclosingElement, type.binding, level.intValue(), this);
2019
					}
2008
				}
2020
				}
2009
			}
2021
			}
2010
		}
2022
		}
(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java (+17 lines)
Lines 75-80 Link Here
75
		patternLocator.match(methodDeclaration, nodeSet);
75
		patternLocator.match(methodDeclaration, nodeSet);
76
		return (methodDeclaration.bits & ASTNode.HasLocalTypeMASK) != 0; // continue only if it has local type
76
		return (methodDeclaration.bits & ASTNode.HasLocalTypeMASK) != 0; // continue only if it has local type
77
	}
77
	}
78
	public boolean visit(AnnotationMethodDeclaration methodDeclaration, ClassScope scope) {
79
		patternLocator.match(methodDeclaration, nodeSet);
80
		return false; // no local type for annotation type members
81
	}
78
}
82
}
79
public class ClassAndMethodDeclarationVisitor extends ClassButNoMethodDeclarationVisitor {
83
public class ClassAndMethodDeclarationVisitor extends ClassButNoMethodDeclarationVisitor {
80
	public boolean visit(TypeDeclaration localTypeDeclaration, BlockScope scope) {
84
	public boolean visit(TypeDeclaration localTypeDeclaration, BlockScope scope) {
Lines 232-237 Link Here
232
	// this is always a LocalDeclaration
236
	// this is always a LocalDeclaration
233
	this.patternLocator.match((LocalDeclaration) this.astStack[this.astPtr], this.nodeSet);
237
	this.patternLocator.match((LocalDeclaration) this.astStack[this.astPtr], this.nodeSet);
234
}
238
}
239
protected void consumeMemberValuePair() {
240
	super.consumeMemberValuePair();
241
242
	// this is always a MemberValuePair
243
	this.patternLocator.match((MemberValuePair) this.astStack[this.astPtr], this.nodeSet);
244
}
235
protected void consumeMethodInvocationName() {
245
protected void consumeMethodInvocationName() {
236
	super.consumeMethodInvocationName();
246
	super.consumeMethodInvocationName();
237
247
Lines 283-288 Link Here
283
	intPtr--;
293
	intPtr--;
284
	intPtr--;
294
	intPtr--;
285
}
295
}
296
protected void consumeSingleMemberAnnotation() {
297
	super.consumeSingleMemberAnnotation();
298
	MemberValuePair[] pairs = ((SingleMemberAnnotation) expressionStack[expressionPtr]).memberValuePairs();
299
	if (pairs != null && pairs.length==1) {
300
		this.patternLocator.match(pairs[0], nodeSet);
301
	}
302
}
286
protected void consumeTypeArgument() {
303
protected void consumeTypeArgument() {
287
	super.consumeTypeArgument();
304
	super.consumeTypeArgument();
288
	patternLocator.match((TypeReference)genericsStack[genericsPtr], nodeSet);
305
	patternLocator.match((TypeReference)genericsStack[genericsPtr], nodeSet);
(-)search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java (-5 / +23 lines)
Lines 104-109 Link Here
104
	// Method declaration may match pattern
104
	// Method declaration may match pattern
105
	return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
105
	return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
106
}
106
}
107
public int match(MemberValuePair node, MatchingNodeSet nodeSet) {
108
	if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH;
109
110
	if (!matchesName(this.pattern.selector, node.name)) return IMPOSSIBLE_MATCH;
111
112
	return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
113
}
107
public int match(MessageSend node, MatchingNodeSet nodeSet) {
114
public int match(MessageSend node, MatchingNodeSet nodeSet) {
108
	if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH;
115
	if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH;
109
116
Lines 223-229 Link Here
223
		} else {
230
		} else {
224
			int offset = reference.sourceStart;
231
			int offset = reference.sourceStart;
225
			match.setOffset(offset);
232
			match.setOffset(offset);
226
			match.setLength(reference.sourceEnd-offset+1);
233
			int length = (reference instanceof SingleMemberAnnotation) ? 0 : reference.sourceEnd - offset + 1;
234
			match.setLength(length);
227
			locator.report(match);
235
			locator.report(match);
228
		}
236
		}
229
	}
237
	}
Lines 354-363 Link Here
354
	}
362
	}
355
}
363
}
356
public int resolveLevel(ASTNode possibleMatchingNode) {
364
public int resolveLevel(ASTNode possibleMatchingNode) {
357
	if (this.pattern.findReferences && possibleMatchingNode instanceof MessageSend)
365
	if (this.pattern.findReferences) {
358
		return resolveLevel((MessageSend) possibleMatchingNode);
366
		if (possibleMatchingNode instanceof MessageSend) {
359
	if (this.pattern.findDeclarations && possibleMatchingNode instanceof MethodDeclaration)
367
			return resolveLevel((MessageSend) possibleMatchingNode);
360
		return resolveLevel(((MethodDeclaration) possibleMatchingNode).binding);
368
		}
369
		if (possibleMatchingNode instanceof MemberValuePair) {
370
			MemberValuePair memberValuePair = (MemberValuePair) possibleMatchingNode;
371
			return resolveLevel(memberValuePair.binding);
372
		}
373
	}
374
	if (this.pattern.findDeclarations) {
375
		if (possibleMatchingNode instanceof MethodDeclaration) {
376
			return resolveLevel(((MethodDeclaration) possibleMatchingNode).binding);
377
		}
378
	}
361
	return IMPOSSIBLE_MATCH;
379
	return IMPOSSIBLE_MATCH;
362
}
380
}
363
public int resolveLevel(Binding binding) {
381
public int resolveLevel(Binding binding) {
(-)search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java (+4 lines)
Lines 180-185 Link Here
180
	// each subtype should override if needed
180
	// each subtype should override if needed
181
	return IMPOSSIBLE_MATCH;
181
	return IMPOSSIBLE_MATCH;
182
}
182
}
183
public int match(MemberValuePair node, MatchingNodeSet nodeSet) {
184
	// each subtype should override if needed
185
	return IMPOSSIBLE_MATCH;
186
}
183
public int match(MessageSend node, MatchingNodeSet nodeSet) {
187
public int match(MessageSend node, MatchingNodeSet nodeSet) {
184
	// each subtype should override if needed
188
	// each subtype should override if needed
185
	return IMPOSSIBLE_MATCH;
189
	return IMPOSSIBLE_MATCH;

Return to bug 83230