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

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java (-4 / +8 lines)
Lines 1449-1459 Link Here
1449
		System.out.println("Reporting match"); //$NON-NLS-1$
1449
		System.out.println("Reporting match"); //$NON-NLS-1$
1450
		System.out.println("\tResource: " + match.getResource()); //$NON-NLS-2$//$NON-NLS-1$
1450
		System.out.println("\tResource: " + match.getResource()); //$NON-NLS-2$//$NON-NLS-1$
1451
		System.out.println("\tPositions: [offset=" + match.getOffset() + ", length=" + match.getLength() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1451
		System.out.println("\tPositions: [offset=" + match.getOffset() + ", length=" + match.getLength() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1452
		if (this.parser != null && match.getOffset() > 0 && match.getLength() > 0 && !(match.getElement() instanceof BinaryMember)) {
1452
		try {
1453
			String selection = new String(this.parser.scanner.source, match.getOffset(), match.getLength());
1453
			if (this.parser != null && match.getOffset() > 0 && match.getLength() > 0 && !(match.getElement() instanceof BinaryMember)) {
1454
			System.out.println("\tSelection: -->" + selection + "<--"); //$NON-NLS-1$ //$NON-NLS-2$
1454
				String selection = new String(this.parser.scanner.source, match.getOffset(), match.getLength());
1455
				System.out.println("\tSelection: -->" + selection + "<--"); //$NON-NLS-1$ //$NON-NLS-2$
1456
				System.out.println("\tJava element: " + ((JavaElement)match.getElement()).toStringWithAncestors()); //$NON-NLS-1$
1457
			}
1458
		} catch (Exception e) {
1459
			// it's just for debug purposes... ignore all exceptions in this area
1455
		}
1460
		}
1456
		System.out.println("\tJava element: " + ((JavaElement)match.getElement()).toStringWithAncestors()); //$NON-NLS-1$
1457
		System.out.println(match.getAccuracy() == SearchMatch.A_ACCURATE
1461
		System.out.println(match.getAccuracy() == SearchMatch.A_ACCURATE
1458
			? "\tAccuracy: EXACT_MATCH" //$NON-NLS-1$
1462
			? "\tAccuracy: EXACT_MATCH" //$NON-NLS-1$
1459
			: "\tAccuracy: POTENTIAL_MATCH"); //$NON-NLS-1$
1463
			: "\tAccuracy: POTENTIAL_MATCH"); //$NON-NLS-1$
(-)search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java (-4 / +60 lines)
Lines 91-98 Link Here
91
		ASTNode[] args = node.arguments;
91
		ASTNode[] args = node.arguments;
92
		int argsLength = args == null ? 0 : args.length;
92
		int argsLength = args == null ? 0 : args.length;
93
		if (length != argsLength) return IMPOSSIBLE_MATCH;
93
		if (length != argsLength) return IMPOSSIBLE_MATCH;
94
		for (int i = 0; i < argsLength; i++) {
94
		// Disable filter on argument syntax to allow generic type search.
95
			if (!matchesTypeReference(this.pattern.parameterSimpleNames[i], ((Argument) args[i]).type)) return IMPOSSIBLE_MATCH;
95
		// (see  bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=79990)
96
		if (!this.pattern.mustResolveGeneric) {
97
			for (int i = 0; i < argsLength; i++) {
98
				if (!matchesTypeReference(this.pattern.parameterSimpleNames[i], ((Argument) args[i]).type)) return IMPOSSIBLE_MATCH;
99
			}
96
		}
100
		}
97
	}
101
	}
98
102
Lines 215-220 Link Here
215
	return level;
219
	return level;
216
}
220
}
217
/**
221
/**
222
 * Return if pattern method may override a method in super classes
223
 * or or implement one in super interfaces of given type.
224
 * @param type
225
 * @return level
226
 */
227
int matchOverriddenMethod(ReferenceBinding type) {
228
	if (type == null) return INACCURATE_MATCH;
229
	int level = IMPOSSIBLE_MATCH;
230
231
	// matches superclass
232
	if (!type.isInterface() && !CharOperation.equals(type.compoundName, TypeConstants.JAVA_LANG_OBJECT)) {
233
		if (type.superclass().isParameterizedType()) {
234
			TypeBinding erasure = ((ParameterizedTypeBinding)type.superclass()).erasure();
235
			if (erasure instanceof ReferenceBinding) {
236
				MethodBinding[] methods = ((ReferenceBinding)erasure).getMethods(this.pattern.selector);
237
				int length = methods.length;
238
				for (int i = 0; i<length && level == IMPOSSIBLE_MATCH; i++) {
239
					level = matchMethod(methods[i]);
240
				}
241
				if (level != IMPOSSIBLE_MATCH) return level;
242
			}
243
		}
244
		level = matchOverriddenMethod(type.superclass());
245
		if (level != IMPOSSIBLE_MATCH) return level;
246
	}
247
248
	// matches interfaces
249
	ReferenceBinding[] interfaces = type.superInterfaces();
250
	if (interfaces == null) return INACCURATE_MATCH;
251
	int iLength = interfaces.length;
252
	for (int i = 0; i<iLength; i++) {
253
		if (interfaces[i].isParameterizedType()) {
254
			TypeBinding erasure = ((ParameterizedTypeBinding)interfaces[i]).erasure();
255
			if (erasure instanceof ReferenceBinding) {
256
				MethodBinding[] methods = ((ReferenceBinding)erasure).getMethods(this.pattern.selector);
257
				int mLength = methods.length;
258
				for (int j = 0; j<mLength && level == IMPOSSIBLE_MATCH; j++) {
259
					level = matchMethod(methods[j]);
260
				}
261
				if (level != IMPOSSIBLE_MATCH) return level;
262
			}
263
		}
264
		level = matchOverriddenMethod(interfaces[i]);
265
		if (level != IMPOSSIBLE_MATCH) return level;
266
	}
267
	return IMPOSSIBLE_MATCH;
268
}
269
/**
218
 * @see org.eclipse.jdt.internal.core.search.matching.PatternLocator#matchReportReference(org.eclipse.jdt.internal.compiler.ast.ASTNode, org.eclipse.jdt.core.IJavaElement, Binding, int, org.eclipse.jdt.internal.core.search.matching.MatchLocator)
270
 * @see org.eclipse.jdt.internal.core.search.matching.PatternLocator#matchReportReference(org.eclipse.jdt.internal.compiler.ast.ASTNode, org.eclipse.jdt.core.IJavaElement, Binding, int, org.eclipse.jdt.internal.core.search.matching.MatchLocator)
219
 */
271
 */
220
protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
272
protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
Lines 415-422 Link Here
415
	int methodLevel = matchMethod(method);
467
	int methodLevel = matchMethod(method);
416
	if (methodLevel == IMPOSSIBLE_MATCH) {
468
	if (methodLevel == IMPOSSIBLE_MATCH) {
417
		if (method != method.original()) methodLevel = matchMethod(method.original());
469
		if (method != method.original()) methodLevel = matchMethod(method.original());
418
		if (methodLevel == IMPOSSIBLE_MATCH) return IMPOSSIBLE_MATCH;
470
		if (methodLevel == IMPOSSIBLE_MATCH && this.pattern.findDeclarations && this.pattern.mustResolveGeneric) {
419
		method = method.original();
471
			methodLevel = matchOverriddenMethod(method.declaringClass);
472
			if (methodLevel == IMPOSSIBLE_MATCH) return IMPOSSIBLE_MATCH;
473
		} else {
474
			method = method.original();
475
		}
420
	}
476
	}
421
477
422
	// declaring type
478
	// declaring type
(-)search/org/eclipse/jdt/internal/core/search/matching/MethodPattern.java (+21 lines)
Lines 36-41 Link Here
36
public char[][] parameterSimpleNames;
36
public char[][] parameterSimpleNames;
37
public int parameterCount;
37
public int parameterCount;
38
public int flags = 0;
38
public int flags = 0;
39
public boolean mustResolveGeneric = false;
39
40
40
// extra reference info
41
// extra reference info
41
protected IType declaringType;
42
protected IType declaringType;
Lines 180-185 Link Here
180
	// Store type signatures and arguments for method
181
	// Store type signatures and arguments for method
181
	methodArguments = extractMethodArguments(method);
182
	methodArguments = extractMethodArguments(method);
182
	if (hasMethodArguments())  ((InternalSearchPattern)this).mustResolve = true;
183
	if (hasMethodArguments())  ((InternalSearchPattern)this).mustResolve = true;
184
	
185
	// See if we must resolve specifically for generics
186
	if (parameterSimpleNames != null && parameterSimpleNames.length > 0) {
187
		int psLength = parameterSimpleNames.length;
188
		try {
189
			ITypeParameter[] typeParameters = this.declaringType.getTypeParameters();
190
			if (typeParameters != null && typeParameters.length > 0) {
191
				int tpLength = typeParameters.length;
192
				for (int i=0; i<psLength && !this.mustResolveGeneric; i++) {
193
					for (int j=0; j<tpLength && !this.mustResolveGeneric; j++) {
194
						if (CharOperation.equals(parameterSimpleNames[i], typeParameters[j].getElementName().toCharArray())) {
195
							this.mustResolveGeneric = true;
196
						}
197
					}
198
				}
199
			}
200
		} catch (JavaModelException e) {
201
			// ignore
202
		}
203
	}
183
}
204
}
184
/*
205
/*
185
 * Instanciate a method pattern with signatures for generics search
206
 * Instanciate a method pattern with signatures for generics search

Return to bug 79990