Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorssankaran2011-04-20 16:36:05 +0000
committerssankaran2011-04-20 16:36:05 +0000
commit6178750b1a6b39f0576bd371394e2760317f4f72 (patch)
tree73314446578cc25792018875142ca7ba46aa0953
parent27922bb339fa549614da43c624e28904aca70fa7 (diff)
downloadorg.eclipse.jdt.core-BETA_JAVA7.tar.gz
org.eclipse.jdt.core-BETA_JAVA7.tar.xz
org.eclipse.jdt.core-BETA_JAVA7.zip
BETA_JAVA7: Preparatory changes for <>BETA_JAVA7
-rw-r--r--compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java59
-rw-r--r--compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java51
2 files changed, 71 insertions, 39 deletions
diff --git a/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java b/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java
index bd515fef5..0e168df32 100644
--- a/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java
+++ b/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java
@@ -33,6 +33,7 @@ public class AllocationExpression extends Expression implements InvocationSite {
public TypeReference[] typeArguments;
public TypeBinding[] genericTypeArguments;
public FieldDeclaration enumConstant; // for enum constant initializations
+ private TypeBinding expectedTypeForInference; // for <> inference
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
// check captured variables are initialized in current context (26134)
@@ -259,25 +260,12 @@ public TypeBinding resolveType(BlockScope scope) {
// initialization of an enum constant
this.resolvedType = scope.enclosingReceiverType();
} else {
- this.resolvedType = this.type.resolveType(scope, true /* check bounds*/);
- checkParameterizedAllocation: {
- if (this.type instanceof ParameterizedQualifiedTypeReference) { // disallow new X<String>.Y<Integer>()
- ReferenceBinding currentType = (ReferenceBinding)this.resolvedType;
- if (currentType == null) return currentType;
- do {
- // isStatic() is answering true for toplevel types
- if ((currentType.modifiers & ClassFileConstants.AccStatic) != 0) break checkParameterizedAllocation;
- if (currentType.isRawType()) break checkParameterizedAllocation;
- } while ((currentType = currentType.enclosingType())!= null);
- ParameterizedQualifiedTypeReference qRef = (ParameterizedQualifiedTypeReference) this.type;
- for (int i = qRef.typeArguments.length - 2; i >= 0; i--) {
- if (qRef.typeArguments[i] != null) {
- scope.problemReporter().illegalQualifiedParameterizedTypeAllocation(this.type, this.resolvedType);
- break;
- }
- }
- }
+ if ((this.type.bits & ASTNode.IsDiamond) != 0) {
+ this.resolvedType = null; // can be done only after type arguments and method arguments resolution.
+ } else {
+ this.resolvedType = this.type.resolveType(scope, true /* check bounds*/);
}
+ // check for parameterized allocation deferred to below.
}
// will check for null after args are resolved
@@ -350,6 +338,28 @@ public TypeBinding resolveType(BlockScope scope) {
return this.resolvedType;
}
}
+ if (this.type != null && (this.type.bits & ASTNode.IsDiamond) != 0) {
+ // Perform diamond inference here. (Not done yet.)
+ this.resolvedType = this.type.resolveType(scope, true /* check bounds*/); // for now just do what we do for 1.6-
+ }
+ checkParameterizedAllocation: {
+ if (this.type instanceof ParameterizedQualifiedTypeReference) { // disallow new X<String>.Y<Integer>()
+ ReferenceBinding currentType = (ReferenceBinding)this.resolvedType;
+ if (currentType == null) return currentType;
+ do {
+ // isStatic() is answering true for toplevel types
+ if ((currentType.modifiers & ClassFileConstants.AccStatic) != 0) break checkParameterizedAllocation;
+ if (currentType.isRawType()) break checkParameterizedAllocation;
+ } while ((currentType = currentType.enclosingType())!= null);
+ ParameterizedQualifiedTypeReference qRef = (ParameterizedQualifiedTypeReference) this.type;
+ for (int i = qRef.typeArguments.length - 2; i >= 0; i--) {
+ if (qRef.typeArguments[i] != null) {
+ scope.problemReporter().illegalQualifiedParameterizedTypeAllocation(this.type, this.resolvedType);
+ break;
+ }
+ }
+ }
+ }
if (this.resolvedType == null || !this.resolvedType.isValidBinding()) {
return null;
}
@@ -413,4 +423,17 @@ public void traverse(ASTVisitor visitor, BlockScope scope) {
}
visitor.endVisit(this, scope);
}
+/**
+ * @see org.eclipse.jdt.internal.compiler.ast.Expression#setExpectedType(org.eclipse.jdt.internal.compiler.lookup.TypeBinding)
+ */
+public void setExpectedType(TypeBinding expectedType) {
+ this.expectedTypeForInference = expectedType;
+}
+/**
+ * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#expectedType()
+ */
+public TypeBinding expectedType() {
+ return this.expectedTypeForInference;
+}
+
}
diff --git a/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java b/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java
index 6818cbfce..b960702bb 100644
--- a/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java
+++ b/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java
@@ -275,30 +275,14 @@ public class QualifiedAllocationExpression extends AllocationExpression {
// initialization of an enum constant
receiverType = scope.enclosingSourceType();
} else {
- receiverType = this.type.resolveType(scope, true /* check bounds*/);
- checkParameterizedAllocation: {
- if (receiverType == null || !receiverType.isValidBinding()) break checkParameterizedAllocation;
- if (this.type instanceof ParameterizedQualifiedTypeReference) { // disallow new X<String>.Y<Integer>()
- ReferenceBinding currentType = (ReferenceBinding)receiverType;
- do {
- // isStatic() is answering true for toplevel types
- if ((currentType.modifiers & ClassFileConstants.AccStatic) != 0) break checkParameterizedAllocation;
- if (currentType.isRawType()) break checkParameterizedAllocation;
- } while ((currentType = currentType.enclosingType())!= null);
- ParameterizedQualifiedTypeReference qRef = (ParameterizedQualifiedTypeReference) this.type;
- for (int i = qRef.typeArguments.length - 2; i >= 0; i--) {
- if (qRef.typeArguments[i] != null) {
- scope.problemReporter().illegalQualifiedParameterizedTypeAllocation(this.type, receiverType);
- break;
- }
- }
- }
+ if ((this.type.bits & ASTNode.IsDiamond) == 0) {
+ receiverType = this.type.resolveType(scope, true /* check bounds*/);
+ } else {
+ // can be done only after type arguments and method arguments resolution
}
+ // check for parameterized allocation deferred to below.
}
}
- if (receiverType == null || !receiverType.isValidBinding()) {
- hasError = true;
- }
// resolve type arguments (for generic constructor call)
if (this.typeArguments != null) {
@@ -340,6 +324,31 @@ public class QualifiedAllocationExpression extends AllocationExpression {
}
}
}
+ if (this.type != null && (this.type.bits & ASTNode.IsDiamond) != 0) {
+ // Perform diamond inference here. (Not done yet.)
+ receiverType = this.type.resolveType(scope, true /* check bounds*/); // for now just do what we do for 1.6-
+ }
+ checkParameterizedAllocation: {
+ if (receiverType == null || !receiverType.isValidBinding()) break checkParameterizedAllocation;
+ if (this.type instanceof ParameterizedQualifiedTypeReference) { // disallow new X<String>.Y<Integer>()
+ ReferenceBinding currentType = (ReferenceBinding)receiverType;
+ do {
+ // isStatic() is answering true for toplevel types
+ if ((currentType.modifiers & ClassFileConstants.AccStatic) != 0) break checkParameterizedAllocation;
+ if (currentType.isRawType()) break checkParameterizedAllocation;
+ } while ((currentType = currentType.enclosingType())!= null);
+ ParameterizedQualifiedTypeReference qRef = (ParameterizedQualifiedTypeReference) this.type;
+ for (int i = qRef.typeArguments.length - 2; i >= 0; i--) {
+ if (qRef.typeArguments[i] != null) {
+ scope.problemReporter().illegalQualifiedParameterizedTypeAllocation(this.type, receiverType);
+ break;
+ }
+ }
+ }
+ }
+ if (receiverType == null || !receiverType.isValidBinding()) {
+ hasError = true;
+ }
// limit of fault-tolerance
if (hasError) {

Back to the top