Lines 23-28
Link Here
|
23 |
ReferenceBinding runtimeException; |
23 |
ReferenceBinding runtimeException; |
24 |
ReferenceBinding errorException; |
24 |
ReferenceBinding errorException; |
25 |
LookupEnvironment environment; |
25 |
LookupEnvironment environment; |
|
|
26 |
boolean allowCompatibleReturnTypes; |
26 |
/* |
27 |
/* |
27 |
Binding creation is responsible for reporting all problems with types: |
28 |
Binding creation is responsible for reporting all problems with types: |
28 |
- all modifier problems (duplicates & multiple visibility modifiers + incompatible combinations - abstract/final) |
29 |
- all modifier problems (duplicates & multiple visibility modifiers + incompatible combinations - abstract/final) |
Lines 47-52
Link Here
|
47 |
this.runtimeException = null; |
48 |
this.runtimeException = null; |
48 |
this.errorException = null; |
49 |
this.errorException = null; |
49 |
this.environment = environment; |
50 |
this.environment = environment; |
|
|
51 |
this.allowCompatibleReturnTypes = |
52 |
environment.globalOptions.complianceLevel >= org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_5 |
53 |
&& environment.globalOptions.sourceLevel < org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_5; |
50 |
} |
54 |
} |
51 |
boolean areMethodsEqual(MethodBinding one, MethodBinding two) { |
55 |
boolean areMethodsEqual(MethodBinding one, MethodBinding two) { |
52 |
return doesMethodOverride(one, two) && areReturnTypesEqual(one, two); |
56 |
return doesMethodOverride(one, two) && areReturnTypesEqual(one, two); |
Lines 63-70
Link Here
|
63 |
if (!areTypesEqual(oneArgs[i], twoArgs[i])) return false; |
67 |
if (!areTypesEqual(oneArgs[i], twoArgs[i])) return false; |
64 |
return true; |
68 |
return true; |
65 |
} |
69 |
} |
|
|
70 |
boolean areReturnTypesCompatible(MethodBinding one, MethodBinding substituteTwo) { |
71 |
if (one.returnType == substituteTwo.returnType) return true; |
72 |
|
73 |
// short is compatible with int, but as far as covariance is concerned, its not |
74 |
if (one.returnType.isBaseType()) return false; |
75 |
|
76 |
if (!one.declaringClass.isInterface()) { |
77 |
if (one.declaringClass.id == TypeIds.T_JavaLangObject) |
78 |
return substituteTwo.returnType.isCompatibleWith(one.returnType); // interface methods inherit from Object |
79 |
return one.returnType.isCompatibleWith(substituteTwo.returnType); |
80 |
} |
81 |
|
82 |
// check for methods from Object, every interface inherits from Object |
83 |
if (substituteTwo.declaringClass.id == TypeIds.T_JavaLangObject) |
84 |
return one.returnType.isCompatibleWith(substituteTwo.returnType); |
85 |
|
86 |
// both are interfaces, see if they're related |
87 |
if (one.declaringClass.implementsInterface(substituteTwo.declaringClass, true)) |
88 |
return one.returnType.isCompatibleWith(substituteTwo.returnType); |
89 |
if (substituteTwo.declaringClass.implementsInterface(one.declaringClass, true)) |
90 |
return substituteTwo.returnType.isCompatibleWith(one.returnType); |
91 |
|
92 |
// unrelated interfaces... one must be a subtype of the other |
93 |
return one.returnType.isCompatibleWith(substituteTwo.returnType) |
94 |
|| substituteTwo.returnType.isCompatibleWith(one.returnType); |
95 |
} |
66 |
boolean areReturnTypesEqual(MethodBinding one, MethodBinding two) { |
96 |
boolean areReturnTypesEqual(MethodBinding one, MethodBinding two) { |
67 |
return areTypesEqual(one.returnType, two.returnType); |
97 |
if (areTypesEqual(one.returnType, two.returnType)) return true; |
|
|
98 |
|
99 |
// when sourceLevel < 1.5 but compliance >= 1.5, allow return types in binaries to be compatible instead of just equal |
100 |
if (this.allowCompatibleReturnTypes) |
101 |
if (one.declaringClass instanceof BinaryTypeBinding && two.declaringClass instanceof BinaryTypeBinding) |
102 |
if (areReturnTypesCompatible(one, two)) |
103 |
return true; |
104 |
return false; |
68 |
} |
105 |
} |
69 |
boolean areTypesEqual(TypeBinding one, TypeBinding two) { |
106 |
boolean areTypesEqual(TypeBinding one, TypeBinding two) { |
70 |
if (one == two) return true; |
107 |
if (one == two) return true; |