|
Lines 14-19
Link Here
|
| 14 |
import java.util.Map; |
14 |
import java.util.Map; |
| 15 |
|
15 |
|
| 16 |
import org.eclipse.jdt.core.CompletionProposal; |
16 |
import org.eclipse.jdt.core.CompletionProposal; |
|
|
17 |
import org.eclipse.jdt.core.Flags; |
| 17 |
import org.eclipse.jdt.core.IJavaProject; |
18 |
import org.eclipse.jdt.core.IJavaProject; |
| 18 |
import org.eclipse.jdt.core.IMember; |
19 |
import org.eclipse.jdt.core.IMember; |
| 19 |
import org.eclipse.jdt.core.IMethod; |
20 |
import org.eclipse.jdt.core.IMethod; |
|
Lines 90-96
Link Here
|
| 90 |
*/ |
91 |
*/ |
| 91 |
private IMethod findMethod(String name, String[] paramTypes, boolean isConstructor, IType type) throws JavaModelException { |
92 |
private IMethod findMethod(String name, String[] paramTypes, boolean isConstructor, IType type) throws JavaModelException { |
| 92 |
Map<String, char[]> typeVariables= computeTypeVariables(type); |
93 |
Map<String, char[]> typeVariables= computeTypeVariables(type); |
| 93 |
return findMethod(name, paramTypes, isConstructor, type.getMethods(), typeVariables); |
94 |
return findMethod(name, paramTypes, isConstructor, type, typeVariables); |
| 94 |
} |
95 |
} |
| 95 |
|
96 |
|
| 96 |
/** |
97 |
/** |
|
Lines 142-155
Link Here
|
| 142 |
* @param paramTypes The type signatures of the parameters e.g. |
143 |
* @param paramTypes The type signatures of the parameters e.g. |
| 143 |
* <code>{"QString;","I"}</code> |
144 |
* <code>{"QString;","I"}</code> |
| 144 |
* @param isConstructor If the method is a constructor |
145 |
* @param isConstructor If the method is a constructor |
| 145 |
* @param methods The methods to search in |
146 |
* @param type the given type in which to search for methods |
| 146 |
* @param typeVariables a map from type variables to concretely used types |
147 |
* @param typeVariables a map from type variables to concretely used types |
| 147 |
* @return The found method or <code>null</code>, if nothing found |
148 |
* @return The found method or <code>null</code>, if nothing found |
| 148 |
* @throws JavaModelException if the method does not exist or if an exception occurs while accessing its corresponding resource |
149 |
* @throws JavaModelException if the method does not exist or if an exception occurs while accessing its corresponding resource |
| 149 |
*/ |
150 |
*/ |
| 150 |
private IMethod findMethod(String name, String[] paramTypes, boolean isConstructor, IMethod[] methods, Map<String, char[]> typeVariables) throws JavaModelException { |
151 |
private IMethod findMethod(String name, String[] paramTypes, boolean isConstructor, IType type, Map<String, char[]> typeVariables) throws JavaModelException { |
|
|
152 |
IMethod[] methods = type.getMethods(); |
| 151 |
for (int i= methods.length - 1; i >= 0; i--) { |
153 |
for (int i= methods.length - 1; i >= 0; i--) { |
| 152 |
if (isSameMethodSignature(name, paramTypes, isConstructor, methods[i], typeVariables)) { |
154 |
if (isSameMethodSignature(name, paramTypes, isConstructor, methods[i], typeVariables, type)) { |
| 153 |
return methods[i]; |
155 |
return methods[i]; |
| 154 |
} |
156 |
} |
| 155 |
} |
157 |
} |
|
Lines 167-191
Link Here
|
| 167 |
* @param isConstructor Specifies if the method is a constructor |
169 |
* @param isConstructor Specifies if the method is a constructor |
| 168 |
* @param method the method to be compared with this info's method |
170 |
* @param method the method to be compared with this info's method |
| 169 |
* @param typeVariables a map from type variables to types |
171 |
* @param typeVariables a map from type variables to types |
|
|
172 |
* @param type the given type that declares the method |
| 170 |
* @return Returns <code>true</code> if the method has the given name and |
173 |
* @return Returns <code>true</code> if the method has the given name and |
| 171 |
* parameter types and constructor state. |
174 |
* parameter types and constructor state. |
| 172 |
* @throws JavaModelException if the method does not exist or if an exception occurs while accessing its corresponding resource |
175 |
* @throws JavaModelException if the method does not exist or if an exception occurs while accessing its corresponding resource |
| 173 |
*/ |
176 |
*/ |
| 174 |
private boolean isSameMethodSignature(String name, String[] paramTypes, boolean isConstructor, IMethod method, Map<String, char[]> typeVariables) throws JavaModelException { |
177 |
private boolean isSameMethodSignature(String name, String[] paramTypes, boolean isConstructor, IMethod method, Map<String, char[]> typeVariables, IType type) throws JavaModelException { |
| 175 |
if (isConstructor || name.equals(method.getElementName())) { |
178 |
if (isConstructor || name.equals(method.getElementName())) { |
| 176 |
if (isConstructor == method.isConstructor()) { |
179 |
if (isConstructor == method.isConstructor()) { |
| 177 |
String[] otherParams= method.getParameterTypes(); // types may be type variables |
180 |
String[] otherParams= method.getParameterTypes(); // types may be type variables |
| 178 |
if (paramTypes.length == otherParams.length) { |
181 |
String[] paramTypesTemp= paramTypes; |
|
|
182 |
boolean isConstructorForNonStaticMemberClass= isConstructor && type.isMember() && !Flags.isStatic(type.getFlags()); |
| 183 |
if (isConstructorForNonStaticMemberClass) { |
| 184 |
paramTypesTemp= new String[paramTypes.length + 1]; |
| 185 |
System.arraycopy(paramTypes, 0, paramTypesTemp, 1, paramTypes.length); |
| 186 |
} |
| 187 |
if (paramTypesTemp.length == otherParams.length) { |
| 179 |
fFallbackMatch= method; |
188 |
fFallbackMatch= method; |
| 180 |
String signature= method.getSignature(); |
189 |
String signature= method.getSignature(); |
| 181 |
String[] otherParamsFromSignature= Signature.getParameterTypes(signature); // types are resolved / upper-bounded |
190 |
String[] otherParamsFromSignature= Signature.getParameterTypes(signature); // types are resolved / upper-bounded |
| 182 |
// no need to check method type variables since these are |
191 |
// no need to check method type variables since these are |
| 183 |
// not yet bound when proposing a method |
192 |
// not yet bound when proposing a method |
| 184 |
for (int i= 0; i < paramTypes.length; i++) { |
193 |
for (int i= 0; i < paramTypesTemp.length; i++) { |
| 185 |
String ourParamName= computeSimpleTypeName(paramTypes[i], typeVariables); |
194 |
if (isConstructorForNonStaticMemberClass && i == 0) { |
|
|
195 |
// skip this one |
| 196 |
continue; |
| 197 |
} |
| 198 |
String ourParamName= computeSimpleTypeName(paramTypesTemp[i], typeVariables); |
| 186 |
String otherParamName1= computeSimpleTypeName(otherParams[i], typeVariables); |
199 |
String otherParamName1= computeSimpleTypeName(otherParams[i], typeVariables); |
| 187 |
String otherParamName2= computeSimpleTypeName(otherParamsFromSignature[i], typeVariables); |
200 |
String otherParamName2= computeSimpleTypeName(otherParamsFromSignature[i], typeVariables); |
| 188 |
|
201 |
|
| 189 |
if (!ourParamName.equals(otherParamName1) && !ourParamName.equals(otherParamName2)) { |
202 |
if (!ourParamName.equals(otherParamName1) && !ourParamName.equals(otherParamName2)) { |
| 190 |
return false; |
203 |
return false; |
| 191 |
} |
204 |
} |