Lines 1099-1105
Link Here
|
1099 |
|
1099 |
|
1100 |
// find & report collision cases |
1100 |
// find & report collision cases |
1101 |
boolean complyTo15 = this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5; |
1101 |
boolean complyTo15 = this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5; |
1102 |
boolean complyTo17 = this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_7; |
|
|
1103 |
for (int i = 0, length = this.methods.length; i < length; i++) { |
1102 |
for (int i = 0, length = this.methods.length; i < length; i++) { |
1104 |
MethodBinding method = resolvedMethods[i]; |
1103 |
MethodBinding method = resolvedMethods[i]; |
1105 |
if (method == null) |
1104 |
if (method == null) |
Lines 1113-1176
Link Here
|
1113 |
if (!CharOperation.equals(selector, method2.selector)) |
1112 |
if (!CharOperation.equals(selector, method2.selector)) |
1114 |
break nextSibling; // methods with same selector are contiguous |
1113 |
break nextSibling; // methods with same selector are contiguous |
1115 |
|
1114 |
|
1116 |
if (complyTo15 && method.returnType != null && method2.returnType != null) { |
1115 |
if (complyTo15 ? !method.areParameterErasuresEqual(method2) : !method.areParametersEqual(method2)) |
1117 |
// 8.4.2, for collision to be detected between m1 and m2: |
1116 |
continue nextSibling; // otherwise duplicates / name clash |
1118 |
// signature(m1) == signature(m2) i.e. same arity, same type parameter count, can be substituted |
|
|
1119 |
// signature(m1) == erasure(signature(m2)) or erasure(signature(m1)) == signature(m2) |
1120 |
TypeBinding[] params1 = method.parameters; |
1121 |
TypeBinding[] params2 = method2.parameters; |
1122 |
int pLength = params1.length; |
1123 |
if (pLength != params2.length) |
1124 |
continue nextSibling; |
1125 |
|
1126 |
TypeVariableBinding[] vars = method.typeVariables; |
1127 |
TypeVariableBinding[] vars2 = method2.typeVariables; |
1128 |
boolean equalTypeVars = vars == vars2; |
1129 |
MethodBinding subMethod = method2; |
1130 |
if (!equalTypeVars) { |
1131 |
MethodBinding temp = method.computeSubstitutedMethod(method2, this.scope.environment()); |
1132 |
if (temp != null) { |
1133 |
equalTypeVars = true; |
1134 |
subMethod = temp; |
1135 |
} |
1136 |
} |
1137 |
boolean equalParams = method.areParametersEqual(subMethod); |
1138 |
if (equalParams && equalTypeVars) { |
1139 |
// duplicates regardless of return types |
1140 |
} else if ((complyTo17 || method.returnType.erasure() == subMethod.returnType.erasure()) |
1141 |
&& (equalParams || method.areParameterErasuresEqual(method2))) { |
1142 |
// with fix for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 |
1143 |
// we now ignore return types when detecting duplicates, just as we did before 1.5 |
1144 |
// name clash for sure if not duplicates, report as duplicates |
1145 |
// FYI for now we will only make this change when compliance is set to 1.7 or higher |
1146 |
} else if (!equalTypeVars && vars != Binding.NO_TYPE_VARIABLES && vars2 != Binding.NO_TYPE_VARIABLES) { |
1147 |
// type variables are different so we can distinguish between methods |
1148 |
continue nextSibling; |
1149 |
} else if (pLength > 0) { |
1150 |
// check to see if the erasure of either method is equal to the other |
1151 |
int index = pLength; |
1152 |
for (; --index >= 0;) { |
1153 |
if (params1[index] != params2[index].erasure()) |
1154 |
break; |
1155 |
if (params1[index] == params2[index]) { |
1156 |
TypeBinding type = params1[index].leafComponentType(); |
1157 |
if (type instanceof SourceTypeBinding && type.typeVariables() != Binding.NO_TYPE_VARIABLES) { |
1158 |
index = pLength; // handle comparing identical source types like X<T>... its erasure is itself BUT we need to answer false |
1159 |
break; |
1160 |
} |
1161 |
} |
1162 |
} |
1163 |
if (index >= 0 && index < pLength) { |
1164 |
for (index = pLength; --index >= 0;) |
1165 |
if (params1[index].erasure() != params2[index]) |
1166 |
break; |
1167 |
} |
1168 |
if (index >= 0) |
1169 |
continue nextSibling; |
1170 |
} |
1171 |
} else if (!method.areParametersEqual(method2)) { // prior to 1.5, parameter identity meant a collision case |
1172 |
continue nextSibling; |
1173 |
} |
1174 |
boolean isEnumSpecialMethod = isEnum() && (CharOperation.equals(selector,TypeConstants.VALUEOF) || CharOperation.equals(selector,TypeConstants.VALUES)); |
1117 |
boolean isEnumSpecialMethod = isEnum() && (CharOperation.equals(selector,TypeConstants.VALUEOF) || CharOperation.equals(selector,TypeConstants.VALUES)); |
1175 |
// report duplicate |
1118 |
// report duplicate |
1176 |
boolean removeMethod2 = true; |
1119 |
boolean removeMethod2 = true; |