Lines 98-103
Link Here
|
98 |
int expectedTypesPtr = -1; |
98 |
int expectedTypesPtr = -1; |
99 |
TypeBinding[] expectedTypes = new TypeBinding[1]; |
99 |
TypeBinding[] expectedTypes = new TypeBinding[1]; |
100 |
int expectedTypesFilter; |
100 |
int expectedTypesFilter; |
|
|
101 |
boolean hasJavaLangObjectAsExpectedType = false; |
101 |
int uninterestingBindingsPtr = -1; |
102 |
int uninterestingBindingsPtr = -1; |
102 |
Binding[] uninterestingBindings = new Binding[1]; |
103 |
Binding[] uninterestingBindings = new Binding[1]; |
103 |
int forbbidenBindingsPtr = -1; |
104 |
int forbbidenBindingsPtr = -1; |
Lines 4228-4233
Link Here
|
4228 |
return R_EXACT_EXPECTED_TYPE; |
4229 |
return R_EXACT_EXPECTED_TYPE; |
4229 |
} |
4230 |
} |
4230 |
} |
4231 |
} |
|
|
4232 |
if(this.hasJavaLangObjectAsExpectedType) { |
4233 |
return R_EXPECTED_TYPE; |
4234 |
} |
4231 |
} |
4235 |
} |
4232 |
return 0; |
4236 |
return 0; |
4233 |
} |
4237 |
} |
Lines 5829-5834
Link Here
|
5829 |
|
5833 |
|
5830 |
// default filter |
5834 |
// default filter |
5831 |
this.expectedTypesFilter = SUBTYPE; |
5835 |
this.expectedTypesFilter = SUBTYPE; |
|
|
5836 |
this.hasJavaLangObjectAsExpectedType = false; |
5832 |
|
5837 |
|
5833 |
// find types from parent |
5838 |
// find types from parent |
5834 |
if(parent instanceof AbstractVariableDeclaration) { |
5839 |
if(parent instanceof AbstractVariableDeclaration) { |
Lines 5836-5862
Link Here
|
5836 |
TypeBinding binding = variable.type.resolvedType; |
5841 |
TypeBinding binding = variable.type.resolvedType; |
5837 |
if(binding != null) { |
5842 |
if(binding != null) { |
5838 |
if(!(variable.initialization instanceof ArrayInitializer)) { |
5843 |
if(!(variable.initialization instanceof ArrayInitializer)) { |
5839 |
addExpectedType(binding); |
5844 |
addExpectedType(binding, scope); |
5840 |
} |
5845 |
} |
5841 |
} |
5846 |
} |
5842 |
} else if(parent instanceof Assignment) { |
5847 |
} else if(parent instanceof Assignment) { |
5843 |
TypeBinding binding = ((Assignment)parent).lhs.resolvedType; |
5848 |
TypeBinding binding = ((Assignment)parent).lhs.resolvedType; |
5844 |
if(binding != null) { |
5849 |
if(binding != null) { |
5845 |
addExpectedType(binding); |
5850 |
addExpectedType(binding, scope); |
5846 |
} |
5851 |
} |
5847 |
} else if(parent instanceof ReturnStatement) { |
5852 |
} else if(parent instanceof ReturnStatement) { |
5848 |
if(scope.methodScope().referenceContext instanceof AbstractMethodDeclaration) { |
5853 |
if(scope.methodScope().referenceContext instanceof AbstractMethodDeclaration) { |
5849 |
MethodBinding methodBinding = ((AbstractMethodDeclaration) scope.methodScope().referenceContext).binding; |
5854 |
MethodBinding methodBinding = ((AbstractMethodDeclaration) scope.methodScope().referenceContext).binding; |
5850 |
TypeBinding binding = methodBinding == null ? null : methodBinding.returnType; |
5855 |
TypeBinding binding = methodBinding == null ? null : methodBinding.returnType; |
5851 |
if(binding != null) { |
5856 |
if(binding != null) { |
5852 |
addExpectedType(binding); |
5857 |
addExpectedType(binding, scope); |
5853 |
} |
5858 |
} |
5854 |
} |
5859 |
} |
5855 |
} else if(parent instanceof CastExpression) { |
5860 |
} else if(parent instanceof CastExpression) { |
5856 |
Expression e = ((CastExpression)parent).type; |
5861 |
Expression e = ((CastExpression)parent).type; |
5857 |
TypeBinding binding = e.resolvedType; |
5862 |
TypeBinding binding = e.resolvedType; |
5858 |
if(binding != null){ |
5863 |
if(binding != null){ |
5859 |
addExpectedType(binding); |
5864 |
addExpectedType(binding, scope); |
5860 |
this.expectedTypesFilter = SUBTYPE | SUPERTYPE; |
5865 |
this.expectedTypesFilter = SUBTYPE | SUPERTYPE; |
5861 |
} |
5866 |
} |
5862 |
} else if(parent instanceof MessageSend) { |
5867 |
} else if(parent instanceof MessageSend) { |
Lines 5906-5939
Link Here
|
5906 |
InstanceOfExpression e = (InstanceOfExpression) parent; |
5911 |
InstanceOfExpression e = (InstanceOfExpression) parent; |
5907 |
TypeBinding binding = e.expression.resolvedType; |
5912 |
TypeBinding binding = e.expression.resolvedType; |
5908 |
if(binding != null){ |
5913 |
if(binding != null){ |
5909 |
addExpectedType(binding); |
5914 |
addExpectedType(binding, scope); |
5910 |
this.expectedTypesFilter = SUBTYPE | SUPERTYPE; |
5915 |
this.expectedTypesFilter = SUBTYPE | SUPERTYPE; |
5911 |
} |
5916 |
} |
5912 |
} else if(parent instanceof BinaryExpression) { |
5917 |
} else if(parent instanceof BinaryExpression) { |
5913 |
switch(operator) { |
5918 |
switch(operator) { |
5914 |
case OperatorIds.PLUS : |
5919 |
case OperatorIds.PLUS : |
5915 |
addExpectedType(TypeBinding.SHORT); |
5920 |
addExpectedType(TypeBinding.SHORT, scope); |
5916 |
addExpectedType(TypeBinding.INT); |
5921 |
addExpectedType(TypeBinding.INT, scope); |
5917 |
addExpectedType(TypeBinding.LONG); |
5922 |
addExpectedType(TypeBinding.LONG, scope); |
5918 |
addExpectedType(TypeBinding.FLOAT); |
5923 |
addExpectedType(TypeBinding.FLOAT, scope); |
5919 |
addExpectedType(TypeBinding.DOUBLE); |
5924 |
addExpectedType(TypeBinding.DOUBLE, scope); |
5920 |
addExpectedType(TypeBinding.CHAR); |
5925 |
addExpectedType(TypeBinding.CHAR, scope); |
5921 |
addExpectedType(TypeBinding.BYTE); |
5926 |
addExpectedType(TypeBinding.BYTE, scope); |
5922 |
addExpectedType(scope.getJavaLangString()); |
5927 |
addExpectedType(scope.getJavaLangString(), scope); |
5923 |
break; |
5928 |
break; |
5924 |
case OperatorIds.AND_AND : |
5929 |
case OperatorIds.AND_AND : |
5925 |
case OperatorIds.OR_OR : |
5930 |
case OperatorIds.OR_OR : |
5926 |
case OperatorIds.XOR : |
5931 |
case OperatorIds.XOR : |
5927 |
addExpectedType(TypeBinding.BOOLEAN); |
5932 |
addExpectedType(TypeBinding.BOOLEAN, scope); |
5928 |
break; |
5933 |
break; |
5929 |
default : |
5934 |
default : |
5930 |
addExpectedType(TypeBinding.SHORT); |
5935 |
addExpectedType(TypeBinding.SHORT, scope); |
5931 |
addExpectedType(TypeBinding.INT); |
5936 |
addExpectedType(TypeBinding.INT, scope); |
5932 |
addExpectedType(TypeBinding.LONG); |
5937 |
addExpectedType(TypeBinding.LONG, scope); |
5933 |
addExpectedType(TypeBinding.FLOAT); |
5938 |
addExpectedType(TypeBinding.FLOAT, scope); |
5934 |
addExpectedType(TypeBinding.DOUBLE); |
5939 |
addExpectedType(TypeBinding.DOUBLE, scope); |
5935 |
addExpectedType(TypeBinding.CHAR); |
5940 |
addExpectedType(TypeBinding.CHAR, scope); |
5936 |
addExpectedType(TypeBinding.BYTE); |
5941 |
addExpectedType(TypeBinding.BYTE, scope); |
5937 |
break; |
5942 |
break; |
5938 |
} |
5943 |
} |
5939 |
BinaryExpression binaryExpression = (BinaryExpression) parent; |
5944 |
BinaryExpression binaryExpression = (BinaryExpression) parent; |
Lines 5944-5950
Link Here
|
5944 |
if(b instanceof ReferenceBinding) { |
5949 |
if(b instanceof ReferenceBinding) { |
5945 |
TypeVariableBinding[] typeVariableBindings =((ReferenceBinding)b).typeVariables(); |
5950 |
TypeVariableBinding[] typeVariableBindings =((ReferenceBinding)b).typeVariables(); |
5946 |
if(typeVariableBindings != null && typeVariableBindings.length > 0) { |
5951 |
if(typeVariableBindings != null && typeVariableBindings.length > 0) { |
5947 |
addExpectedType(typeVariableBindings[0].firstBound); |
5952 |
addExpectedType(typeVariableBindings[0].firstBound, scope); |
5948 |
} |
5953 |
} |
5949 |
|
5954 |
|
5950 |
} |
5955 |
} |
Lines 5953-5985
Link Here
|
5953 |
} else if(parent instanceof UnaryExpression) { |
5958 |
} else if(parent instanceof UnaryExpression) { |
5954 |
switch(operator) { |
5959 |
switch(operator) { |
5955 |
case OperatorIds.NOT : |
5960 |
case OperatorIds.NOT : |
5956 |
addExpectedType(TypeBinding.BOOLEAN); |
5961 |
addExpectedType(TypeBinding.BOOLEAN, scope); |
5957 |
break; |
5962 |
break; |
5958 |
case OperatorIds.TWIDDLE : |
5963 |
case OperatorIds.TWIDDLE : |
5959 |
addExpectedType(TypeBinding.SHORT); |
5964 |
addExpectedType(TypeBinding.SHORT, scope); |
5960 |
addExpectedType(TypeBinding.INT); |
5965 |
addExpectedType(TypeBinding.INT, scope); |
5961 |
addExpectedType(TypeBinding.LONG); |
5966 |
addExpectedType(TypeBinding.LONG, scope); |
5962 |
addExpectedType(TypeBinding.CHAR); |
5967 |
addExpectedType(TypeBinding.CHAR, scope); |
5963 |
addExpectedType(TypeBinding.BYTE); |
5968 |
addExpectedType(TypeBinding.BYTE, scope); |
5964 |
break; |
5969 |
break; |
5965 |
case OperatorIds.PLUS : |
5970 |
case OperatorIds.PLUS : |
5966 |
case OperatorIds.MINUS : |
5971 |
case OperatorIds.MINUS : |
5967 |
case OperatorIds.PLUS_PLUS : |
5972 |
case OperatorIds.PLUS_PLUS : |
5968 |
case OperatorIds.MINUS_MINUS : |
5973 |
case OperatorIds.MINUS_MINUS : |
5969 |
addExpectedType(TypeBinding.SHORT); |
5974 |
addExpectedType(TypeBinding.SHORT, scope); |
5970 |
addExpectedType(TypeBinding.INT); |
5975 |
addExpectedType(TypeBinding.INT, scope); |
5971 |
addExpectedType(TypeBinding.LONG); |
5976 |
addExpectedType(TypeBinding.LONG, scope); |
5972 |
addExpectedType(TypeBinding.FLOAT); |
5977 |
addExpectedType(TypeBinding.FLOAT, scope); |
5973 |
addExpectedType(TypeBinding.DOUBLE); |
5978 |
addExpectedType(TypeBinding.DOUBLE, scope); |
5974 |
addExpectedType(TypeBinding.CHAR); |
5979 |
addExpectedType(TypeBinding.CHAR, scope); |
5975 |
addExpectedType(TypeBinding.BYTE); |
5980 |
addExpectedType(TypeBinding.BYTE, scope); |
5976 |
break; |
5981 |
break; |
5977 |
} |
5982 |
} |
5978 |
} |
5983 |
} |
5979 |
} else if(parent instanceof ArrayReference) { |
5984 |
} else if(parent instanceof ArrayReference) { |
5980 |
addExpectedType(TypeBinding.SHORT); |
5985 |
addExpectedType(TypeBinding.SHORT, scope); |
5981 |
addExpectedType(TypeBinding.INT); |
5986 |
addExpectedType(TypeBinding.INT, scope); |
5982 |
addExpectedType(TypeBinding.LONG); |
5987 |
addExpectedType(TypeBinding.LONG, scope); |
5983 |
} else if(parent instanceof ParameterizedSingleTypeReference) { |
5988 |
} else if(parent instanceof ParameterizedSingleTypeReference) { |
5984 |
ParameterizedSingleTypeReference ref = (ParameterizedSingleTypeReference) parent; |
5989 |
ParameterizedSingleTypeReference ref = (ParameterizedSingleTypeReference) parent; |
5985 |
TypeVariableBinding[] typeVariables = ((ReferenceBinding)ref.resolvedType).typeVariables(); |
5990 |
TypeVariableBinding[] typeVariables = ((ReferenceBinding)ref.resolvedType).typeVariables(); |
Lines 5987-5993
Link Here
|
5987 |
if(typeVariables != null && typeVariables.length >= length) { |
5992 |
if(typeVariables != null && typeVariables.length >= length) { |
5988 |
int index = length - 1; |
5993 |
int index = length - 1; |
5989 |
while(index > -1 && ref.typeArguments[index] != node) index--; |
5994 |
while(index > -1 && ref.typeArguments[index] != node) index--; |
5990 |
addExpectedType(typeVariables[index].firstBound); |
5995 |
|
|
|
5996 |
TypeBinding bound = typeVariables[index].firstBound; |
5997 |
addExpectedType(bound == null ? scope.getJavaLangObject() : bound, scope); |
5991 |
} |
5998 |
} |
5992 |
} else if(parent instanceof ParameterizedQualifiedTypeReference) { |
5999 |
} else if(parent instanceof ParameterizedQualifiedTypeReference) { |
5993 |
ParameterizedQualifiedTypeReference ref = (ParameterizedQualifiedTypeReference) parent; |
6000 |
ParameterizedQualifiedTypeReference ref = (ParameterizedQualifiedTypeReference) parent; |
Lines 5999-6005
Link Here
|
5999 |
int jLength = arguments[i] == null ? 0 : arguments[i].length; |
6006 |
int jLength = arguments[i] == null ? 0 : arguments[i].length; |
6000 |
for (int j = 0; j < jLength; j++) { |
6007 |
for (int j = 0; j < jLength; j++) { |
6001 |
if(arguments[i][j] == node && typeVariables.length > j) { |
6008 |
if(arguments[i][j] == node && typeVariables.length > j) { |
6002 |
addExpectedType(typeVariables[j].firstBound); |
6009 |
TypeBinding bound = typeVariables[j].firstBound; |
|
|
6010 |
addExpectedType(bound == null ? scope.getJavaLangObject() : bound, scope); |
6003 |
break done; |
6011 |
break done; |
6004 |
} |
6012 |
} |
6005 |
} |
6013 |
} |
Lines 6008-6014
Link Here
|
6008 |
} else if(parent instanceof MemberValuePair) { |
6016 |
} else if(parent instanceof MemberValuePair) { |
6009 |
MemberValuePair memberValuePair = (MemberValuePair) parent; |
6017 |
MemberValuePair memberValuePair = (MemberValuePair) parent; |
6010 |
if(memberValuePair.binding != null) { |
6018 |
if(memberValuePair.binding != null) { |
6011 |
addExpectedType(memberValuePair.binding.returnType); |
6019 |
addExpectedType(memberValuePair.binding.returnType, scope); |
6012 |
} |
6020 |
} |
6013 |
} else if (parent instanceof NormalAnnotation) { |
6021 |
} else if (parent instanceof NormalAnnotation) { |
6014 |
NormalAnnotation annotation = (NormalAnnotation) parent; |
6022 |
NormalAnnotation annotation = (NormalAnnotation) parent; |
Lines 6020-6026
Link Here
|
6020 |
if(methodBindings != null && |
6028 |
if(methodBindings != null && |
6021 |
methodBindings.length == 1 && |
6029 |
methodBindings.length == 1 && |
6022 |
CharOperation.equals(methodBindings[0].selector, VALUE)) { |
6030 |
CharOperation.equals(methodBindings[0].selector, VALUE)) { |
6023 |
addExpectedType(methodBindings[0].returnType); |
6031 |
addExpectedType(methodBindings[0].returnType, scope); |
6024 |
} |
6032 |
} |
6025 |
} |
6033 |
} |
6026 |
} |
6034 |
} |
Lines 6033-6039
Link Here
|
6033 |
ReferenceBinding[] exceptions = methodDecl.binding.thrownExceptions; |
6041 |
ReferenceBinding[] exceptions = methodDecl.binding.thrownExceptions; |
6034 |
if (exceptions != null) { |
6042 |
if (exceptions != null) { |
6035 |
for (int i = 0; i < exceptions.length; i++) { |
6043 |
for (int i = 0; i < exceptions.length; i++) { |
6036 |
addExpectedType(exceptions[i]); |
6044 |
addExpectedType(exceptions[i], scope); |
6037 |
} |
6045 |
} |
6038 |
} |
6046 |
} |
6039 |
} |
6047 |
} |
Lines 6076-6082
Link Here
|
6076 |
|
6084 |
|
6077 |
TypeBinding expectedType = method.parameters[arguments.length - 1]; |
6085 |
TypeBinding expectedType = method.parameters[arguments.length - 1]; |
6078 |
if(expectedType != null) { |
6086 |
if(expectedType != null) { |
6079 |
addExpectedType(expectedType); |
6087 |
addExpectedType(expectedType, scope); |
6080 |
} |
6088 |
} |
6081 |
} |
6089 |
} |
6082 |
} |
6090 |
} |
Lines 6182-6198
Link Here
|
6182 |
|
6190 |
|
6183 |
TypeBinding expectedType = method.parameters[arguments.length - 1]; |
6191 |
TypeBinding expectedType = method.parameters[arguments.length - 1]; |
6184 |
if(expectedType != null) { |
6192 |
if(expectedType != null) { |
6185 |
addExpectedType(expectedType); |
6193 |
addExpectedType(expectedType, scope); |
6186 |
} |
6194 |
} |
6187 |
} |
6195 |
} |
6188 |
} |
6196 |
} |
6189 |
private void addExpectedType(TypeBinding type){ |
6197 |
private void addExpectedType(TypeBinding type, Scope scope){ |
6190 |
if (type == null || !type.isValidBinding()) return; |
6198 |
if (type == null || !type.isValidBinding()) return; |
6191 |
|
6199 |
|
6192 |
int length = this.expectedTypes.length; |
6200 |
int length = this.expectedTypes.length; |
6193 |
if (++this.expectedTypesPtr >= length) |
6201 |
if (++this.expectedTypesPtr >= length) |
6194 |
System.arraycopy(this.expectedTypes, 0, this.expectedTypes = new TypeBinding[length * 2], 0, length); |
6202 |
System.arraycopy(this.expectedTypes, 0, this.expectedTypes = new TypeBinding[length * 2], 0, length); |
6195 |
this.expectedTypes[this.expectedTypesPtr] = type; |
6203 |
this.expectedTypes[this.expectedTypesPtr] = type; |
|
|
6204 |
|
6205 |
if(type == scope.getJavaLangObject()) { |
6206 |
this.hasJavaLangObjectAsExpectedType = true; |
6207 |
} |
6196 |
} |
6208 |
} |
6197 |
private void addForbiddenBindings(Binding binding){ |
6209 |
private void addForbiddenBindings(Binding binding){ |
6198 |
if (binding == null) return; |
6210 |
if (binding == null) return; |