|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2009 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2011 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 39-62
Link Here
|
| 39 |
|
39 |
|
| 40 |
public class CompletionOnQualifiedAllocationExpression extends QualifiedAllocationExpression { |
40 |
public class CompletionOnQualifiedAllocationExpression extends QualifiedAllocationExpression { |
| 41 |
public TypeBinding resolveType(BlockScope scope) { |
41 |
public TypeBinding resolveType(BlockScope scope) { |
|
|
42 |
TypeBinding[] argumentTypes = Binding.NO_PARAMETERS; |
| 42 |
if (this.arguments != null) { |
43 |
if (this.arguments != null) { |
| 43 |
int argsLength = this.arguments.length; |
44 |
int argsLength = this.arguments.length; |
| 44 |
for (int a = argsLength; --a >= 0;) |
45 |
int length = this.arguments.length; |
| 45 |
this.arguments[a].resolveType(scope); |
46 |
argumentTypes = new TypeBinding[length]; |
|
|
47 |
for (int a = argsLength; --a >= 0;) { |
| 48 |
argumentTypes[a] = this.arguments[a].resolveType(scope); |
| 49 |
} |
| 46 |
} |
50 |
} |
| 47 |
|
51 |
final boolean isDiamond = this.type != null && (this.type.bits & ASTNode.IsDiamond) != 0; |
| 48 |
if (this.enclosingInstance != null) { |
52 |
if (this.enclosingInstance != null) { |
| 49 |
TypeBinding enclosingType = this.enclosingInstance.resolveType(scope); |
53 |
TypeBinding enclosingType = this.enclosingInstance.resolveType(scope); |
|
|
54 |
if (enclosingType == null) { |
| 55 |
// try to propose something even if enclosing type cannot be resolved. |
| 56 |
// Eg.: new Test<>().new Test<>(#cursor# |
| 57 |
if (this.enclosingInstance instanceof AllocationExpression) { |
| 58 |
TypeReference enclosingInstanceType = ((AllocationExpression) this.enclosingInstance).type; |
| 59 |
if (enclosingInstanceType != null) { |
| 60 |
enclosingType = enclosingInstanceType.resolvedType; |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 50 |
if (enclosingType == null || !(enclosingType instanceof ReferenceBinding)) { |
64 |
if (enclosingType == null || !(enclosingType instanceof ReferenceBinding)) { |
| 51 |
throw new CompletionNodeFound(); |
65 |
throw new CompletionNodeFound(); |
| 52 |
} |
66 |
} |
| 53 |
this.resolvedType = ((SingleTypeReference) this.type).resolveTypeEnclosing(scope, (ReferenceBinding) enclosingType); |
67 |
this.resolvedType = ((SingleTypeReference) this.type).resolveTypeEnclosing(scope, (ReferenceBinding) enclosingType); |
|
|
68 |
if (isDiamond && (this.resolvedType instanceof ParameterizedTypeBinding)) { |
| 69 |
TypeBinding [] inferredTypes = inferElidedTypes(((ParameterizedTypeBinding) this.resolvedType).genericType(), null, argumentTypes, scope); |
| 70 |
if (inferredTypes != null) { |
| 71 |
this.resolvedType = this.type.resolvedType = scope.environment().createParameterizedType(((ParameterizedTypeBinding) this.resolvedType).genericType(), inferredTypes, ((ParameterizedTypeBinding) this.resolvedType).enclosingType()); |
| 72 |
} else { |
| 73 |
// inference failed. Resolved type will be of the form Test<> |
| 74 |
this.bits |= ASTNode.IsDiamond; |
| 75 |
} |
| 76 |
} |
| 54 |
if (!(this.resolvedType instanceof ReferenceBinding)) |
77 |
if (!(this.resolvedType instanceof ReferenceBinding)) |
| 55 |
throw new CompletionNodeFound(); // no need to continue if its an array or base type |
78 |
throw new CompletionNodeFound(); // no need to continue if its an array or base type |
| 56 |
if (this.resolvedType.isInterface()) // handle the anonymous class definition case |
79 |
if (this.resolvedType.isInterface()) // handle the anonymous class definition case |
| 57 |
this.resolvedType = scope.getJavaLangObject(); |
80 |
this.resolvedType = scope.getJavaLangObject(); |
| 58 |
} else { |
81 |
} else { |
| 59 |
this.resolvedType = this.type.resolveType(scope, true /* check bounds*/); |
82 |
this.resolvedType = this.type.resolveType(scope, true /* check bounds*/); |
|
|
83 |
if (isDiamond && (this.resolvedType instanceof ParameterizedTypeBinding)) { |
| 84 |
TypeBinding [] inferredTypes = inferElidedTypes(((ParameterizedTypeBinding) this.resolvedType).genericType(), null, argumentTypes, scope); |
| 85 |
if (inferredTypes != null) { |
| 86 |
this.resolvedType = this.type.resolvedType = scope.environment().createParameterizedType(((ParameterizedTypeBinding) this.resolvedType).genericType(), inferredTypes, ((ParameterizedTypeBinding) this.resolvedType).enclosingType()); |
| 87 |
} else { |
| 88 |
// inference failed. Resolved type will be of the form Test<> |
| 89 |
this.bits |= ASTNode.IsDiamond; |
| 90 |
} |
| 91 |
} |
| 60 |
if (!(this.resolvedType instanceof ReferenceBinding)) |
92 |
if (!(this.resolvedType instanceof ReferenceBinding)) |
| 61 |
throw new CompletionNodeFound(); // no need to continue if its an array or base type |
93 |
throw new CompletionNodeFound(); // no need to continue if its an array or base type |
| 62 |
} |
94 |
} |