View | Details | Raw Unified | Return to bug 43587 | Differences between
and this patch

Collapse All | Expand All

(-)search/org/eclipse/jdt/core/search/MethodReferenceMatch.java (-2 / +28 lines)
Lines 23-28 Link Here
23
 * @since 3.0
23
 * @since 3.0
24
 */
24
 */
25
public class MethodReferenceMatch extends SearchMatch {
25
public class MethodReferenceMatch extends SearchMatch {
26
	private boolean constructor;
27
	private boolean synthetic;
26
28
27
	/**
29
	/**
28
	 * Creates a new method reference match.
30
	 * Creates a new method reference match.
Lines 31-43 Link Here
31
	 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
33
	 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
32
	 * @param offset the offset the match starts at, or -1 if unknown
34
	 * @param offset the offset the match starts at, or -1 if unknown
33
	 * @param length the length of the match, or -1 if unknown
35
	 * @param length the length of the match, or -1 if unknown
34
	 * @param insideDocComment <code>true</code> if this search match is inside a doc
35
	 * comment, and <code>false</code> otherwise
36
	 * comment, and <code>false</code> otherwise
37
	 * @param constructor <code>true</code> if this search match is a constructor
38
	 * <code>false</code> otherwise
39
	 * @param synthetic <code>true</code> if this search match is a synthetic element
40
	 * <code>false</code> otherwise
41
	 * @param insideDocComment <code>true</code> if this search match is inside a doc
36
	 * @param participant the search participant that created the match
42
	 * @param participant the search participant that created the match
37
	 * @param resource the resource of the element
43
	 * @param resource the resource of the element
38
	 */
44
	 */
39
	public MethodReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean insideDocComment, SearchParticipant participant, IResource resource) {
45
	public MethodReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean constructor, boolean synthetic, boolean insideDocComment, SearchParticipant participant, IResource resource) {
40
		super(enclosingElement, accuracy, offset, length, participant, resource);
46
		super(enclosingElement, accuracy, offset, length, participant, resource);
41
		setInsideDocComment(insideDocComment);
47
		setInsideDocComment(insideDocComment);
48
		this.constructor = constructor;
49
		this.synthetic = synthetic;
50
	}
51
52
	/**
53
	 * @return Returns whether the reference is on a constructor or not.
54
	 */
55
	public final boolean isConstructor() {
56
		return this.constructor;
57
	}
58
	
59
	/**
60
	 * Returns whether the reference is on a synthetic element.
61
	 * Note that for a constructor reference, it can be synthetic when default constructor
62
	 * declaration is used or implicit super constructor is called.
63
	 * 
64
	 * @return whether the reference is synthetic or not.
65
	 */
66
	public final boolean isSynthetic() {
67
		return this.synthetic;
42
	}
68
	}
43
}
69
}
(-)search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java (+28 lines)
Lines 11-16 Link Here
11
package org.eclipse.jdt.internal.core.search.matching;
11
package org.eclipse.jdt.internal.core.search.matching;
12
12
13
import org.eclipse.jdt.core.IJavaElement;
13
import org.eclipse.jdt.core.IJavaElement;
14
import org.eclipse.jdt.core.search.SearchMatch;
14
import org.eclipse.jdt.internal.compiler.ast.*;
15
import org.eclipse.jdt.internal.compiler.ast.*;
15
import org.eclipse.jdt.internal.compiler.lookup.Binding;
16
import org.eclipse.jdt.internal.compiler.lookup.Binding;
16
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
17
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
Lines 114-119 Link Here
114
	}
115
	}
115
116
116
	return ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
117
	return ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
118
}
119
public SearchMatch newDeclarationMatch(ASTNode reference, IJavaElement element, int accuracy, int length, MatchLocator locator) {
120
	SearchMatch match = null;
121
	int offset = reference.sourceStart;
122
	if (this.pattern.findReferences) {
123
		if (reference instanceof TypeDeclaration) {
124
			TypeDeclaration type = (TypeDeclaration) reference;
125
			AbstractMethodDeclaration[] methods = type.methods;
126
			if (methods != null) {
127
				for (int i = 0, max = methods.length; i < max; i++) {
128
					AbstractMethodDeclaration method = methods[i];
129
					boolean synthetic = method.isDefaultConstructor() && method.sourceStart < type.bodyStart;
130
					match = locator.newMethodReferenceMatch(element, accuracy, offset, length, method.isConstructor(), synthetic, method);
131
				}
132
			}
133
		} else if (reference instanceof ConstructorDeclaration) {
134
			ConstructorDeclaration constructor = (ConstructorDeclaration) reference;
135
			ExplicitConstructorCall call = constructor.constructorCall;
136
			boolean synthetic = call != null && call.isSuperAccess();
137
			match = locator.newMethodReferenceMatch(element, accuracy, offset, length, constructor.isConstructor(), synthetic, constructor);
138
		}
139
	}
140
	if (match != null) {
141
		return match;
142
	}
143
	// super implementation...
144
    return locator.newDeclarationMatch(element, accuracy, reference.sourceStart, length);
117
}
145
}
118
public int resolveLevel(ASTNode node) {
146
public int resolveLevel(ASTNode node) {
119
	if (this.pattern.findReferences) {
147
	if (this.pattern.findReferences) {
(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java (-3 / +21 lines)
Lines 994-999 Link Here
994
	if (type.exists()) return type;
994
	if (type.exists()) return type;
995
	return null;
995
	return null;
996
}
996
}
997
/*
998
public SearchMatch newConstructorReferenceMatch(
999
		IJavaElement enclosingElement,
1000
		int accuracy,
1001
		int offset,  
1002
		int length,
1003
		ASTNode reference,
1004
		boolean synthetic) {
1005
	SearchParticipant participant = getParticipant(); 
1006
	IResource resource = this.currentPossibleMatch.resource;
1007
	boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0;
1008
	return new ConstructorReferenceMatch(enclosingElement, accuracy, offset, length, insideDocComment, synthetic, participant, resource);
1009
}
1010
*/
997
public SearchMatch newDeclarationMatch(
1011
public SearchMatch newDeclarationMatch(
998
		IJavaElement element,
1012
		IJavaElement element,
999
		int accuracy,
1013
		int accuracy,
Lines 1064-1074 Link Here
1064
		int accuracy,
1078
		int accuracy,
1065
		int offset,  
1079
		int offset,  
1066
		int length,
1080
		int length,
1081
		boolean isConstructor,
1082
		boolean isSynthetic,
1067
		ASTNode reference) {
1083
		ASTNode reference) {
1068
	SearchParticipant participant = getParticipant(); 
1084
	SearchParticipant participant = getParticipant(); 
1069
	IResource resource = this.currentPossibleMatch.resource;
1085
	IResource resource = this.currentPossibleMatch.resource;
1070
	boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0;
1086
	boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0;
1071
	return new MethodReferenceMatch(enclosingElement, accuracy, offset, length, insideDocComment, participant, resource);
1087
	return new MethodReferenceMatch(enclosingElement, accuracy, offset, length, isConstructor, isSynthetic, insideDocComment, participant, resource);
1072
}
1088
}
1073
1089
1074
public SearchMatch newPackageReferenceMatch(
1090
public SearchMatch newPackageReferenceMatch(
Lines 1342-1348 Link Here
1342
			}
1358
			}
1343
			if (encloses(enclosingElement)) {
1359
			if (encloses(enclosingElement)) {
1344
				int length = scanner.currentPosition - nameSourceStart;
1360
				int length = scanner.currentPosition - nameSourceStart;
1345
				SearchMatch match = newDeclarationMatch(enclosingElement, accuracy, nameSourceStart, length);
1361
//				SearchMatch match = newDeclarationMatch(enclosingElement, accuracy, nameSourceStart, length);
1362
				SearchMatch match = this.patternLocator.newDeclarationMatch(method, enclosingElement, accuracy, length, this);
1346
				report(match);
1363
				report(match);
1347
			}
1364
			}
1348
		}
1365
		}
Lines 1534-1540 Link Here
1534
	// report the type declaration
1551
	// report the type declaration
1535
	if (accuracy > -1 && encloses(enclosingElement)) {
1552
	if (accuracy > -1 && encloses(enclosingElement)) {
1536
		int offset = type.sourceStart;
1553
		int offset = type.sourceStart;
1537
		SearchMatch match = newDeclarationMatch(enclosingElement, accuracy, offset, type.sourceEnd-offset+1);
1554
//		SearchMatch match = newDeclarationMatch(enclosingElement, accuracy, offset, type.sourceEnd-offset+1);
1555
		SearchMatch match = this.patternLocator.newDeclarationMatch(type, enclosingElement, accuracy, type.sourceEnd-offset+1, this);
1538
		report(match);
1556
		report(match);
1539
	}
1557
	}
1540
1558
(-)search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java (-2 / +2 lines)
Lines 145-155 Link Here
145
			reportDeclaration(((MessageSend) reference).binding, locator, declPattern.knownMethods);
145
			reportDeclaration(((MessageSend) reference).binding, locator, declPattern.knownMethods);
146
	} else if (this.pattern.findReferences && reference instanceof MessageSend) {
146
	} else if (this.pattern.findReferences && reference instanceof MessageSend) {
147
		int offset = (int) (((MessageSend) reference).nameSourcePosition >>> 32);
147
		int offset = (int) (((MessageSend) reference).nameSourcePosition >>> 32);
148
		SearchMatch match = locator.newMethodReferenceMatch(element, accuracy, offset, reference.sourceEnd-offset+1, reference);
148
		SearchMatch match = locator.newMethodReferenceMatch(element, accuracy, offset, reference.sourceEnd-offset+1, false /*not constructor*/, false/*not synthetic*/, reference);
149
		locator.report(match);
149
		locator.report(match);
150
	} else {
150
	} else {
151
		int offset = reference.sourceStart;
151
		int offset = reference.sourceStart;
152
		SearchMatch match = locator.newMethodReferenceMatch(element, accuracy, offset, reference.sourceEnd-offset+1, reference);
152
		SearchMatch match = locator.newMethodReferenceMatch(element, accuracy, offset, reference.sourceEnd-offset+1, false /*not constructor*/, false/*not synthetic*/, reference);
153
		locator.report(match);
153
		locator.report(match);
154
	}
154
	}
155
}
155
}
(-)search/org/eclipse/jdt/internal/core/search/matching/OrLocator.java (+18 lines)
Lines 193-198 Link Here
193
	if (closestPattern != null)
193
	if (closestPattern != null)
194
		closestPattern.matchReportReference(reference, element, accuracy, locator);
194
		closestPattern.matchReportReference(reference, element, accuracy, locator);
195
}
195
}
196
public SearchMatch newDeclarationMatch(ASTNode reference, IJavaElement element, int accuracy, int length, MatchLocator locator) {
197
	PatternLocator closestPattern = null;
198
	int level = IMPOSSIBLE_MATCH;
199
	for (int i = 0, pl = this.patternLocators.length; i < pl; i++) {
200
		PatternLocator patternLocator = this.patternLocators[i];
201
		int newLevel = patternLocator.referenceType() == 0 ? IMPOSSIBLE_MATCH : patternLocator.resolveLevel(reference);
202
		if (newLevel > level) {
203
			closestPattern = patternLocator;
204
			if (newLevel == ACCURATE_MATCH) break;
205
			level = newLevel;
206
		}
207
	}
208
	if (closestPattern != null) {
209
	    return closestPattern.newDeclarationMatch(reference, element, accuracy, length, locator);
210
	}
211
	// super implementation...
212
    return locator.newDeclarationMatch(element, accuracy, reference.sourceStart, length);
213
}
196
public int resolveLevel(ASTNode node) {
214
public int resolveLevel(ASTNode node) {
197
	int level = IMPOSSIBLE_MATCH;
215
	int level = IMPOSSIBLE_MATCH;
198
	for (int i = 0, length = this.patternLocators.length; i < length; i++) {
216
	for (int i = 0, length = this.patternLocators.length; i < length; i++) {
(-)search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java (-1 / +4 lines)
Lines 241-247 Link Here
241
			match = locator.newFieldReferenceMatch(element, accuracy, offset, reference.sourceEnd-offset+1, reference);
241
			match = locator.newFieldReferenceMatch(element, accuracy, offset, reference.sourceEnd-offset+1, reference);
242
			break;
242
			break;
243
		case IJavaElement.METHOD:
243
		case IJavaElement.METHOD:
244
			match = locator.newMethodReferenceMatch(element, accuracy, offset, reference.sourceEnd-offset+1, reference);
244
			match = locator.newMethodReferenceMatch(element, accuracy, offset, reference.sourceEnd-offset+1, reference instanceof ExplicitConstructorCall, false/*not synthetic*/, reference);
245
			break;
245
			break;
246
		case IJavaElement.LOCAL_VARIABLE:
246
		case IJavaElement.LOCAL_VARIABLE:
247
			match = locator.newLocalVariableReferenceMatch(element, accuracy, offset, reference.sourceEnd-offset+1, reference);
247
			match = locator.newLocalVariableReferenceMatch(element, accuracy, offset, reference.sourceEnd-offset+1, reference);
Lines 250-255 Link Here
250
	if (match != null) {
250
	if (match != null) {
251
		locator.report(match);
251
		locator.report(match);
252
	}
252
	}
253
}
254
public SearchMatch newDeclarationMatch(ASTNode reference, IJavaElement element, int accuracy, int length, MatchLocator locator) {
255
    return locator.newDeclarationMatch(element, accuracy, reference.sourceStart, length);
253
}
256
}
254
protected int referenceType() {
257
protected int referenceType() {
255
	return 0; // defaults to unknown (a generic JavaSearchMatch will be created)
258
	return 0; // defaults to unknown (a generic JavaSearchMatch will be created)

Return to bug 43587