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

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java (-17 / +46 lines)
Lines 50-98 Link Here
50
	}
50
	}
51
}
51
}
52
/*
52
/*
53
 * Return whether a method may override a method in super classes erasures or not.
53
 * Return possible type hierarchy method which may override a given method binding.
54
 */
54
 */
55
private boolean isErasureMethodOverride(ReferenceBinding type, MethodBinding method) {
55
private MethodBinding possibleOverriddenMethod(ReferenceBinding type, MethodBinding method) {
56
	if (type == null) return false;
56
	if (type == null) return null;
57
57
58
	// matches superclass
58
	// matches superclass
59
	if (!type.isInterface() && !CharOperation.equals(type.compoundName, TypeConstants.JAVA_LANG_OBJECT)) {
59
	if (!type.isInterface() && !CharOperation.equals(type.compoundName, TypeConstants.JAVA_LANG_OBJECT)) {
60
		ReferenceBinding superClass = type.superclass();
60
		ReferenceBinding superClass = type.superclass();
61
		if (superClass.isParameterizedType()) {
61
		if (superClass.isParameterizedType()) {
62
			MethodBinding[] methods = superClass.getMethods(this.pattern.selector);
63
			int length = methods.length;
64
			for (int i = 0; i<length; i++) {
65
				if (methods[i].areParametersEqual(method)) return methods[i];
66
			}
62
			TypeBinding erasure = ((ParameterizedTypeBinding)superClass).erasure();
67
			TypeBinding erasure = ((ParameterizedTypeBinding)superClass).erasure();
63
			if (erasure instanceof ReferenceBinding) {
68
			if (erasure instanceof ReferenceBinding) {
64
				MethodBinding[] methods = superClass.getMethods(this.pattern.selector);
69
				methods = ((ReferenceBinding)erasure).getMethods(this.pattern.selector);
65
				int length = methods.length;
70
				length = methods.length;
66
				for (int i = 0; i<length; i++) {
71
				for (int i = 0; i<length; i++) {
67
					if (methods[i].areParametersEqual(method)) return true;
72
					if (methods[i].areParametersEqual(method)) return methods[i];
68
				}
73
				}
69
			}
74
			}
70
		}
75
		}
71
		if (isErasureMethodOverride(superClass, method)) {
76
		MethodBinding possibleMethod = possibleOverriddenMethod(superClass, method);
72
			return true;
77
		if (possibleMethod != null) {
78
			return possibleMethod;
73
		}
79
		}
74
	}
80
	}
75
81
76
	// matches interfaces
82
	// matches interfaces
77
	ReferenceBinding[] interfaces = type.superInterfaces();
83
	ReferenceBinding[] interfaces = type.superInterfaces();
78
	if (interfaces == null) return false;
84
	if (interfaces == null) return null;
79
	int iLength = interfaces.length;
85
	int iLength = interfaces.length;
80
	for (int i = 0; i<iLength; i++) {
86
	for (int i = 0; i<iLength; i++) {
81
		if (interfaces[i].isParameterizedType()) {
87
		if (interfaces[i].isParameterizedType()) {
88
			MethodBinding[] methods = interfaces[i].getMethods(this.pattern.selector);
89
			int length = methods.length;
90
			for (int j = 0; j<length; j++) {
91
				if (methods[i].areParametersEqual(method)) return methods[i];
92
			}
82
			TypeBinding erasure = ((ParameterizedTypeBinding)interfaces[i]).erasure();
93
			TypeBinding erasure = ((ParameterizedTypeBinding)interfaces[i]).erasure();
83
			if (erasure instanceof ReferenceBinding) {
94
			if (erasure instanceof ReferenceBinding) {
84
				MethodBinding[] methods = ((ReferenceBinding)erasure).getMethods(this.pattern.selector);
95
				methods = ((ReferenceBinding)erasure).getMethods(this.pattern.selector);
85
				int length = methods.length;
96
				length = methods.length;
86
				for (int j = 0; j<length; j++) {
97
				for (int j = 0; j<length; j++) {
87
					if (methods[i].areParametersEqual(method)) return true;
98
					if (methods[i].areParametersEqual(method)) return methods[i];
88
				}
99
				}
89
			}
100
			}
90
		}
101
		}
91
		if (isErasureMethodOverride(interfaces[i], method)) {
102
		MethodBinding possibleMethod = possibleOverriddenMethod(interfaces[i], method);
92
			return true;
103
		if (possibleMethod != null) {
104
			return possibleMethod;
93
		}
105
		}
94
	}
106
	}
95
	return false;
107
	return null;
96
}
108
}
97
/*
109
/*
98
 * Return whether a type name is in pattern all super declaring types names.
110
 * Return whether a type name is in pattern all super declaring types names.
Lines 423-436 Link Here
423
		}
435
		}
424
		// If arguments are not equals then try to see if method arguments can match erasures in hierarchy
436
		// If arguments are not equals then try to see if method arguments can match erasures in hierarchy
425
		if (!equals && this.pattern.findDeclarations && this.mayBeGeneric) {
437
		if (!equals && this.pattern.findDeclarations && this.mayBeGeneric) {
426
			if (isErasureMethodOverride(methodBinding.declaringClass, methodBinding)) {
438
			MethodBinding possibleMethod = possibleOverriddenMethod(methodBinding.declaringClass, methodBinding);
439
			if (possibleMethod != null && methodsParametersEqual(methodBinding, possibleMethod)) {
427
				return super.newDeclarationMatch(reference, element, elementBinding, accuracy, length, locator);
440
				return super.newDeclarationMatch(reference, element, elementBinding, accuracy, length, locator);
428
			}
441
			}
429
			if (isTypeInSuperDeclaringTypeNames(methodBinding.declaringClass.compoundName)) {
442
			if (isTypeInSuperDeclaringTypeNames(methodBinding.declaringClass.compoundName)) {
430
				MethodBinding patternBinding = locator.getMethodBinding(this.pattern);
443
				MethodBinding patternBinding = locator.getMethodBinding(this.pattern);
431
				if (patternBinding != null) {
444
				if (patternBinding != null) {
432
					patternBinding = patternBinding.original();
445
					patternBinding = patternBinding.original();
433
					if (!isErasureMethodOverride(patternBinding.declaringClass, patternBinding)) {
446
					possibleMethod = possibleOverriddenMethod(patternBinding.declaringClass, patternBinding);
447
					if (possibleMethod == null || !methodsParametersEqual(possibleMethod, patternBinding)) {
434
						return null;
448
						return null;
435
					}
449
					}
436
				}
450
				}
Lines 441-446 Link Here
441
	}
455
	}
442
	return super.newDeclarationMatch(reference, element, elementBinding, accuracy, length, locator);
456
	return super.newDeclarationMatch(reference, element, elementBinding, accuracy, length, locator);
443
}
457
}
458
/*
459
 * Return whether 2 methods parameters are equals or not.
460
 */
461
private boolean methodsParametersEqual(MethodBinding first, MethodBinding second) {
462
	TypeBinding[] firstParameters = first.parameters;
463
	TypeBinding[] secondParameters = second.parameters;
464
	if (firstParameters == secondParameters) return true;
465
466
	int length = firstParameters.length;
467
	if (length != secondParameters.length) return false;
468
469
	for (int i = 0; i < length; i++)
470
		if (firstParameters[i] != secondParameters[i]) return false;
471
	return true;
472
}
444
protected void reportDeclaration(MethodBinding methodBinding, MatchLocator locator, SimpleSet knownMethods) throws CoreException {
473
protected void reportDeclaration(MethodBinding methodBinding, MatchLocator locator, SimpleSet knownMethods) throws CoreException {
445
	ReferenceBinding declaringClass = methodBinding.declaringClass;
474
	ReferenceBinding declaringClass = methodBinding.declaringClass;
446
	IType type = locator.lookupType(declaringClass);
475
	IType type = locator.lookupType(declaringClass);

Return to bug 100772