View | Details | Raw Unified | Return to bug 210422 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java (-11 / +57 lines)
Lines 3583-3599 Link Here
3583
				"	\n" + 
3583
				"	\n" + 
3584
				"}\n",
3584
				"}\n",
3585
            },
3585
            },
3586
			"----------\n" + 
3586
    		"----------\n" + 
3587
			"1. ERROR in X.java (at line 4)\n" + 
3587
    		"1. ERROR in X.java (at line 4)\n" + 
3588
			"	@Annot( foo = new String(){} )\n" + 
3588
    		"	@Annot( foo = new String(){} )\n" + 
3589
			"	              ^^^^^^^^^^^^^^\n" + 
3589
    		"	                  ^^^^^^\n" + 
3590
			"The value for annotation attribute Annot.foo must be a constant expression\n" + 
3590
    		"An anonymous class cannot subclass the final class String\n" + 
3591
			"----------\n" + 
3591
    		"----------\n");
3592
			"2. ERROR in X.java (at line 4)\n" + 
3593
			"	@Annot( foo = new String(){} )\n" + 
3594
			"	                  ^^^^^^\n" + 
3595
			"An anonymous class cannot subclass the final class String\n" + 
3596
			"----------\n");
3597
    }     	
3592
    }     	
3598
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=86291 - variation
3593
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=86291 - variation
3599
    public void test114() {
3594
    public void test114() {
Lines 7996-7999 Link Here
7996
		options,
7991
		options,
7997
		null);
7992
		null);
7998
}
7993
}
7994
///https://bugs.eclipse.org/bugs/show_bug.cgi?id=210422 - variation
7995
public void test242() {
7996
	this.runNegativeTest(
7997
		new String[] {
7998
				"X.java",
7999
				"import java.io.Serializable;\n" + 
8000
				"public final class X implements Serializable {\n" + 
8001
				"    class SMember extends String {}  \n" + 
8002
				"    @Annot(value = new SMember())\n" + 
8003
				"     void bar() {}\n" + 
8004
				"    @Annot(value = \n" + 
8005
				"            new X(){\n" + 
8006
				"                    ZorkAnonymous1 z;\n" + 
8007
				"                    void foo() {\n" + 
8008
				"                            this.bar();\n" + 
8009
				"                            Zork2 z;\n" + 
8010
				"                    }\n" + 
8011
				"            })\n" + 
8012
				"	void foo() {}\n" + 
8013
				"}\n" + 
8014
				"@interface Annot {\n" + 
8015
				"        String value();\n" + 
8016
				"}\n",
8017
		},
8018
		"----------\n" + 
8019
		"1. WARNING in X.java (at line 2)\n" + 
8020
		"	public final class X implements Serializable {\n" + 
8021
		"	                   ^\n" + 
8022
		"The serializable class X does not declare a static final serialVersionUID field of type long\n" + 
8023
		"----------\n" + 
8024
		"2. ERROR in X.java (at line 3)\n" + 
8025
		"	class SMember extends String {}  \n" + 
8026
		"	                      ^^^^^^\n" + 
8027
		"The type SMember cannot subclass the final class String\n" + 
8028
		"----------\n" + 
8029
		"3. ERROR in X.java (at line 4)\n" + 
8030
		"	@Annot(value = new SMember())\n" + 
8031
		"	               ^^^^^^^^^^^^^\n" + 
8032
		"Type mismatch: cannot convert from X.SMember to String\n" + 
8033
		"----------\n" + 
8034
		"4. ERROR in X.java (at line 7)\n" + 
8035
		"	new X(){\n" + 
8036
		"	    ^\n" + 
8037
		"An anonymous class cannot subclass the final class X\n" + 
8038
		"----------\n" + 
8039
		"5. ERROR in X.java (at line 8)\n" + 
8040
		"	ZorkAnonymous1 z;\n" + 
8041
		"	^^^^^^^^^^^^^^\n" + 
8042
		"ZorkAnonymous1 cannot be resolved to a type\n" + 
8043
		"----------\n");
8044
}
7999
}
8045
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java (+118 lines)
Lines 5927-5932 Link Here
5927
		"     inner name: #56 Foo6, accessflags: 9 public static]\n";
5927
		"     inner name: #56 Foo6, accessflags: 9 public static]\n";
5928
	checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput);
5928
	checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput);
5929
}
5929
}
5930
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210422
5931
public void test150() {
5932
	this.runNegativeTest(
5933
			new String[] {
5934
				"X.java",
5935
				"import java.io.Serializable;\n" + 
5936
				"\n" + 
5937
				"public final class X implements Serializable {\n" + 
5938
				"\n" + 
5939
				"        void bar() {}\n" + 
5940
				"\n" + 
5941
				"        interface IM {}\n" + 
5942
				"        class SMember extends String {}\n" + 
5943
				"\n" + 
5944
				"        class Member extends X {  \n" + 
5945
				"                ZorkMember z;\n" + 
5946
				"                void foo() {\n" + 
5947
				"                        this.bar();\n" + 
5948
				"                        Zork1 z;\n" + 
5949
				"                } \n" + 
5950
				"        }\n" + 
5951
				"\n" + 
5952
				"        void foo() {\n" + 
5953
				"                new X().new IM();\n" + 
5954
				"                class Local extends X { \n" + 
5955
				"                        ZorkLocal z;\n" + 
5956
				"                        void foo() {\n" + 
5957
				"                                this.bar();\n" + 
5958
				"                                Zork3 z;\n" + 
5959
				"                        }\n" + 
5960
				"                }\n" + 
5961
				"                new X() {\n" + 
5962
				"                        ZorkAnonymous2 z;                       \n" + 
5963
				"                        void foo() {\n" + 
5964
				"                                this.bar();\n" + 
5965
				"                                Zork4 z;\n" + 
5966
				"                        }\n" + 
5967
				"                };\n" + 
5968
				"        }\n" + 
5969
				"}\n"
5970
			},
5971
			"----------\n" + 
5972
			"1. WARNING in X.java (at line 3)\n" + 
5973
			"	public final class X implements Serializable {\n" + 
5974
			"	                   ^\n" + 
5975
			"The serializable class X does not declare a static final serialVersionUID field of type long\n" + 
5976
			"----------\n" + 
5977
			"2. ERROR in X.java (at line 8)\n" + 
5978
			"	class SMember extends String {}\n" + 
5979
			"	                      ^^^^^^\n" + 
5980
			"The type SMember cannot subclass the final class String\n" + 
5981
			"----------\n" + 
5982
			"3. ERROR in X.java (at line 10)\n" + 
5983
			"	class Member extends X {  \n" + 
5984
			"	                     ^\n" + 
5985
			"The type Member cannot subclass the final class X\n" + 
5986
			"----------\n" + 
5987
			"4. ERROR in X.java (at line 11)\n" + 
5988
			"	ZorkMember z;\n" + 
5989
			"	^^^^^^^^^^\n" + 
5990
			"ZorkMember cannot be resolved to a type\n" + 
5991
			"----------\n" + 
5992
			"5. ERROR in X.java (at line 13)\n" + 
5993
			"	this.bar();\n" + 
5994
			"	     ^^^\n" + 
5995
			"The method bar() is undefined for the type X.Member\n" + 
5996
			"----------\n" + 
5997
			"6. ERROR in X.java (at line 14)\n" + 
5998
			"	Zork1 z;\n" + 
5999
			"	^^^^^\n" + 
6000
			"Zork1 cannot be resolved to a type\n" + 
6001
			"----------\n" + 
6002
			"7. ERROR in X.java (at line 19)\n" + 
6003
			"	new X().new IM();\n" + 
6004
			"	            ^^\n" + 
6005
			"Cannot instantiate the type X.IM\n" + 
6006
			"----------\n" + 
6007
			"8. ERROR in X.java (at line 20)\n" + 
6008
			"	class Local extends X { \n" + 
6009
			"	                    ^\n" + 
6010
			"The type Local cannot subclass the final class X\n" + 
6011
			"----------\n" + 
6012
			"9. ERROR in X.java (at line 21)\n" + 
6013
			"	ZorkLocal z;\n" + 
6014
			"	^^^^^^^^^\n" + 
6015
			"ZorkLocal cannot be resolved to a type\n" + 
6016
			"----------\n" + 
6017
			"10. ERROR in X.java (at line 23)\n" + 
6018
			"	this.bar();\n" + 
6019
			"	     ^^^\n" + 
6020
			"The method bar() is undefined for the type Local\n" + 
6021
			"----------\n" + 
6022
			"11. ERROR in X.java (at line 24)\n" + 
6023
			"	Zork3 z;\n" + 
6024
			"	^^^^^\n" + 
6025
			"Zork3 cannot be resolved to a type\n" + 
6026
			"----------\n" + 
6027
			"12. ERROR in X.java (at line 27)\n" + 
6028
			"	new X() {\n" + 
6029
			"	    ^\n" + 
6030
			"An anonymous class cannot subclass the final class X\n" + 
6031
			"----------\n" + 
6032
			"13. ERROR in X.java (at line 28)\n" + 
6033
			"	ZorkAnonymous2 z;                       \n" + 
6034
			"	^^^^^^^^^^^^^^\n" + 
6035
			"ZorkAnonymous2 cannot be resolved to a type\n" + 
6036
			"----------\n" + 
6037
			"14. ERROR in X.java (at line 30)\n" + 
6038
			"	this.bar();\n" + 
6039
			"	     ^^^\n" + 
6040
			"The method bar() is undefined for the type new X(){}\n" + 
6041
			"----------\n" + 
6042
			"15. ERROR in X.java (at line 31)\n" + 
6043
			"	Zork4 z;\n" + 
6044
			"	^^^^^\n" + 
6045
			"Zork4 cannot be resolved to a type\n" + 
6046
			"----------\n");	
6047
}
5930
public static Class testClass() {
6048
public static Class testClass() {
5931
	return InnerEmulationTest.class;
6049
	return InnerEmulationTest.class;
5932
}
6050
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/LocalTypeBinding.java (-21 / +16 lines)
Lines 11-18 Link Here
11
package org.eclipse.jdt.internal.compiler.lookup;
11
package org.eclipse.jdt.internal.compiler.lookup;
12
12
13
import org.eclipse.jdt.core.compiler.CharOperation;
13
import org.eclipse.jdt.core.compiler.CharOperation;
14
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
14
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
15
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
15
import org.eclipse.jdt.internal.compiler.ast.CaseStatement;
16
import org.eclipse.jdt.internal.compiler.ast.CaseStatement;
17
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
16
18
17
public final class LocalTypeBinding extends NestedTypeBinding {
19
public final class LocalTypeBinding extends NestedTypeBinding {
18
	final static char[] LocalTypePrefix = { '$', 'L', 'o', 'c', 'a', 'l', '$' };
20
	final static char[] LocalTypePrefix = { '$', 'L', 'o', 'c', 'a', 'l', '$' };
Lines 22-44 Link Here
22
	public CaseStatement enclosingCase; // from 1.4 on, local types should not be accessed across switch case blocks (52221)
24
	public CaseStatement enclosingCase; // from 1.4 on, local types should not be accessed across switch case blocks (52221)
23
	public int sourceStart; // used by computeUniqueKey to uniquely identify this binding
25
	public int sourceStart; // used by computeUniqueKey to uniquely identify this binding
24
	public MethodBinding enclosingMethod;
26
	public MethodBinding enclosingMethod;
27
	public ReferenceBinding anonymousOriginalSuperType;
25
	
28
	
26
public LocalTypeBinding(ClassScope scope, SourceTypeBinding enclosingType, CaseStatement switchCase) {
29
public LocalTypeBinding(ClassScope scope, SourceTypeBinding enclosingType, CaseStatement switchCase, ReferenceBinding anonymousOriginalSuperType) {
27
	super(
30
	super(
28
		new char[][] {CharOperation.concat(LocalTypePrefix, scope.referenceContext.name)},
31
		new char[][] {CharOperation.concat(LocalTypePrefix, scope.referenceContext.name)},
29
		scope,
32
		scope,
30
		enclosingType);
33
		enclosingType);
31
	
34
	TypeDeclaration typeDeclaration = scope.referenceContext;
32
	if (this.sourceName == CharOperation.NO_CHAR)
35
	if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) {
33
		this.tagBits |= TagBits.AnonymousTypeMask;
36
		this.tagBits |= TagBits.AnonymousTypeMask;
34
	else
37
		this.anonymousOriginalSuperType = anonymousOriginalSuperType;
38
	} else {
35
		this.tagBits |= TagBits.LocalTypeMask;
39
		this.tagBits |= TagBits.LocalTypeMask;
40
	}
36
	this.enclosingCase = switchCase;
41
	this.enclosingCase = switchCase;
37
	this.sourceStart = scope.referenceContext.sourceStart;
42
	this.sourceStart = typeDeclaration.sourceStart;
38
	MethodScope methodScope = scope.enclosingMethodScope();
43
	MethodScope methodScope = scope.enclosingMethodScope();
39
	AbstractMethodDeclaration declaration = methodScope.referenceMethod();
44
	AbstractMethodDeclaration methodDeclaration = methodScope.referenceMethod();
40
	if (declaration != null) {
45
	if (methodDeclaration != null) {
41
		this.enclosingMethod = declaration.binding;
46
		this.enclosingMethod = methodDeclaration.binding;
42
	}
47
	}
43
}
48
}
44
/* Record a dependency onto a source target type which may be altered
49
/* Record a dependency onto a source target type which may be altered
Lines 126-135 Link Here
126
public char[] readableName() /*java.lang.Object,  p.X<T> */ {
131
public char[] readableName() /*java.lang.Object,  p.X<T> */ {
127
    char[] readableName;
132
    char[] readableName;
128
	if (isAnonymousType()) {
133
	if (isAnonymousType()) {
129
		if (superInterfaces == Binding.NO_SUPERINTERFACES)
134
		readableName = CharOperation.concat(TypeConstants.ANONYM_PREFIX, anonymousOriginalSuperType.readableName(), TypeConstants.ANONYM_SUFFIX);
130
			readableName = CharOperation.concat(TypeConstants.ANONYM_PREFIX, superclass.readableName(), TypeConstants.ANONYM_SUFFIX);
131
		else
132
			readableName = CharOperation.concat(TypeConstants.ANONYM_PREFIX, superInterfaces[0].readableName(), TypeConstants.ANONYM_SUFFIX);
133
	} else if (isMemberType()) {
135
	} else if (isMemberType()) {
134
		readableName = CharOperation.concat(enclosingType().readableName(), this.sourceName, '.');
136
		readableName = CharOperation.concat(enclosingType().readableName(), this.sourceName, '.');
135
	} else {
137
	} else {
Lines 154-163 Link Here
154
public char[] shortReadableName() /*Object*/ {
156
public char[] shortReadableName() /*Object*/ {
155
    char[] shortReadableName;
157
    char[] shortReadableName;
156
	if (isAnonymousType()) {
158
	if (isAnonymousType()) {
157
		if (superInterfaces == Binding.NO_SUPERINTERFACES)
159
		shortReadableName = CharOperation.concat(TypeConstants.ANONYM_PREFIX, anonymousOriginalSuperType.shortReadableName(), TypeConstants.ANONYM_SUFFIX);
158
			shortReadableName = CharOperation.concat(TypeConstants.ANONYM_PREFIX, superclass.shortReadableName(), TypeConstants.ANONYM_SUFFIX);
159
		else
160
			shortReadableName = CharOperation.concat(TypeConstants.ANONYM_PREFIX, superInterfaces[0].shortReadableName(), TypeConstants.ANONYM_SUFFIX);
161
	} else if (isMemberType()) {
160
	} else if (isMemberType()) {
162
		shortReadableName = CharOperation.concat(enclosingType().shortReadableName(), sourceName, '.');
161
		shortReadableName = CharOperation.concat(enclosingType().shortReadableName(), sourceName, '.');
163
	} else {
162
	} else {
Lines 203-213 Link Here
203
}
202
}
204
public char[] sourceName() {
203
public char[] sourceName() {
205
	if (isAnonymousType()) {
204
	if (isAnonymousType()) {
206
		if (superInterfaces == Binding.NO_SUPERINTERFACES)
205
		return CharOperation.concat(TypeConstants.ANONYM_PREFIX, anonymousOriginalSuperType.sourceName(), TypeConstants.ANONYM_SUFFIX);
207
			return CharOperation.concat(TypeConstants.ANONYM_PREFIX, superclass.sourceName(), TypeConstants.ANONYM_SUFFIX);
208
		else
209
			return CharOperation.concat(TypeConstants.ANONYM_PREFIX, superInterfaces[0].sourceName(), TypeConstants.ANONYM_SUFFIX);
210
			
211
	} else
206
	} else
212
		return sourceName;
207
		return sourceName;
213
}
208
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java (-5 / +21 lines)
Lines 38-44 Link Here
38
	}
38
	}
39
	
39
	
40
	void buildAnonymousTypeBinding(SourceTypeBinding enclosingType, ReferenceBinding supertype) {
40
	void buildAnonymousTypeBinding(SourceTypeBinding enclosingType, ReferenceBinding supertype) {
41
		LocalTypeBinding anonymousType = buildLocalType(enclosingType, enclosingType.fPackage);
41
		LocalTypeBinding anonymousType = buildLocalType(enclosingType, supertype, enclosingType.fPackage);
42
		SourceTypeBinding sourceType = referenceContext.binding;
42
		SourceTypeBinding sourceType = referenceContext.binding;
43
		if (supertype.isInterface()) {
43
		if (supertype.isInterface()) {
44
			sourceType.superclass = getJavaLangObject();
44
			sourceType.superclass = getJavaLangObject();
Lines 46-51 Link Here
46
		} else {
46
		} else {
47
			sourceType.superclass = supertype;
47
			sourceType.superclass = supertype;
48
			sourceType.superInterfaces = Binding.NO_SUPERINTERFACES;
48
			sourceType.superInterfaces = Binding.NO_SUPERINTERFACES;
49
			TypeReference typeReference = referenceContext.allocation.type;
50
			if (typeReference != null) { // no check for enum constant body
51
				if (supertype.erasure().id == TypeIds.T_JavaLangEnum) {
52
					problemReporter().cannotExtendEnum(anonymousType, typeReference, supertype);
53
					sourceType.tagBits |= TagBits.HierarchyHasProblems;		
54
					sourceType.superclass = getJavaLangObject();
55
				} else if (supertype.isFinal()) {
56
					problemReporter().anonymousClassCannotExtendFinalClass(typeReference, supertype);
57
					sourceType.tagBits |= TagBits.HierarchyHasProblems;		
58
					sourceType.superclass = getJavaLangObject();
59
				} else if ((supertype.tagBits & TagBits.HasDirectWildcard) != 0) {
60
					problemReporter().superTypeCannotUseWildcard(anonymousType, typeReference, supertype);
61
					sourceType.tagBits |= TagBits.HierarchyHasProblems;		
62
					sourceType.superclass = getJavaLangObject();
63
				}
64
			} 
49
		}
65
		}
50
		connectMemberTypes();
66
		connectMemberTypes();
51
		buildFieldsAndMethods();
67
		buildFieldsAndMethods();
Lines 144-157 Link Here
144
			 ((SourceTypeBinding) memberTypes[i]).scope.buildFieldsAndMethods();
160
			 ((SourceTypeBinding) memberTypes[i]).scope.buildFieldsAndMethods();
145
	}
161
	}
146
	
162
	
147
	private LocalTypeBinding buildLocalType(SourceTypeBinding enclosingType, PackageBinding packageBinding) {
163
	private LocalTypeBinding buildLocalType(SourceTypeBinding enclosingType, ReferenceBinding anonymousOriginalSuperType, PackageBinding packageBinding) {
148
	    
164
	    
149
		referenceContext.scope = this;
165
		referenceContext.scope = this;
150
		referenceContext.staticInitializerScope = new MethodScope(this, referenceContext, true);
166
		referenceContext.staticInitializerScope = new MethodScope(this, referenceContext, true);
151
		referenceContext.initializerScope = new MethodScope(this, referenceContext, false);
167
		referenceContext.initializerScope = new MethodScope(this, referenceContext, false);
152
168
153
		// build the binding or the local type
169
		// build the binding or the local type
154
		LocalTypeBinding localType = new LocalTypeBinding(this, enclosingType, this.innermostSwitchCase());
170
		LocalTypeBinding localType = new LocalTypeBinding(this, enclosingType, this.innermostSwitchCase(), anonymousOriginalSuperType);
155
		referenceContext.binding = localType;
171
		referenceContext.binding = localType;
156
		checkAndSetModifiers();
172
		checkAndSetModifiers();
157
		buildTypeVariables();
173
		buildTypeVariables();
Lines 187-193 Link Here
187
					}
203
					}
188
				}
204
				}
189
				ClassScope memberScope = new ClassScope(this, referenceContext.memberTypes[i]);
205
				ClassScope memberScope = new ClassScope(this, referenceContext.memberTypes[i]);
190
				LocalTypeBinding memberBinding = memberScope.buildLocalType(localType, packageBinding);
206
				LocalTypeBinding memberBinding = memberScope.buildLocalType(localType, null /* anonymous super type*/, packageBinding);
191
				memberBinding.setAsMemberType();
207
				memberBinding.setAsMemberType();
192
				memberTypeBindings[count++] = memberBinding;
208
				memberTypeBindings[count++] = memberBinding;
193
			}
209
			}
Lines 200-206 Link Here
200
	
216
	
201
	void buildLocalTypeBinding(SourceTypeBinding enclosingType) {
217
	void buildLocalTypeBinding(SourceTypeBinding enclosingType) {
202
218
203
		LocalTypeBinding localType = buildLocalType(enclosingType, enclosingType.fPackage);
219
		LocalTypeBinding localType = buildLocalType(enclosingType, null /* anonymous super type*/, enclosingType.fPackage);
204
		connectTypeHierarchy();
220
		connectTypeHierarchy();
205
		buildFieldsAndMethods();
221
		buildFieldsAndMethods();
206
		localType.faultInTypesForFieldsAndMethods();
222
		localType.faultInTypesForFieldsAndMethods();
(-)compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java (-41 / +36 lines)
Lines 42-48 Link Here
42
	//qualification may be on both side
42
	//qualification may be on both side
43
	public Expression enclosingInstance;
43
	public Expression enclosingInstance;
44
	public TypeDeclaration anonymousType;
44
	public TypeDeclaration anonymousType;
45
	public ReferenceBinding superTypeBinding;
45
	public ReferenceBinding superclassBinding;
46
	
46
	
47
	public QualifiedAllocationExpression() {
47
	public QualifiedAllocationExpression() {
48
		// for subtypes
48
		// for subtypes
Lines 64-70 Link Here
64
		}
64
		}
65
		
65
		
66
		// check captured variables are initialized in current context (26134)
66
		// check captured variables are initialized in current context (26134)
67
		ReferenceBinding allocatedType = this.superTypeBinding == null ? this.binding.declaringClass : this.superTypeBinding;
67
		ReferenceBinding allocatedType = this.superclassBinding == null ? this.binding.declaringClass : this.superclassBinding; // TODO shouldn't it be #resolvedType ?
68
		checkCapturedLocalInitializationIfNecessary(
68
		checkCapturedLocalInitializationIfNecessary(
69
			(ReferenceBinding) allocatedType.erasure(),
69
			(ReferenceBinding) allocatedType.erasure(),
70
			currentScope, 
70
			currentScope, 
Lines 284-299 Link Here
284
		}
284
		}
285
		if (receiverType == null) {
285
		if (receiverType == null) {
286
			hasError = true;
286
			hasError = true;
287
		} else if (((ReferenceBinding) receiverType).isFinal()) {
288
			if (this.anonymousType != null) {
289
				if (!receiverType.isEnum()) {
290
					scope.problemReporter().anonymousClassCannotExtendFinalClass(this.type, receiverType);
291
					hasError = true;
292
				}
293
			} else if (!receiverType.canBeInstantiated()) {
294
				scope.problemReporter().cannotInstantiate(this.type, receiverType);
295
				return this.resolvedType = receiverType;
296
			}
297
		}
287
		}
298
		// resolve type arguments (for generic constructor call)
288
		// resolve type arguments (for generic constructor call)
299
		if (this.typeArguments != null) {
289
		if (this.typeArguments != null) {
Lines 331-343 Link Here
331
		// limit of fault-tolerance
321
		// limit of fault-tolerance
332
		if (hasError) {
322
		if (hasError) {
333
			if (receiverType instanceof ReferenceBinding) {
323
			if (receiverType instanceof ReferenceBinding) {
324
				ReferenceBinding referenceReceiver = (ReferenceBinding) receiverType;
334
				// record a best guess, for clients who need hint about possible contructor match
325
				// record a best guess, for clients who need hint about possible contructor match
335
				int length = this.arguments  == null ? 0 : this.arguments.length;
326
				int length = this.arguments  == null ? 0 : this.arguments.length;
336
				TypeBinding[] pseudoArgs = new TypeBinding[length];
327
				TypeBinding[] pseudoArgs = new TypeBinding[length];
337
				for (int i = length; --i >= 0;) {
328
				for (int i = length; --i >= 0;) {
338
					pseudoArgs[i] = argumentTypes[i] == null ? TypeBinding.NULL : argumentTypes[i]; // replace args with errors with null type
329
					pseudoArgs[i] = argumentTypes[i] == null ? TypeBinding.NULL : argumentTypes[i]; // replace args with errors with null type
339
				}
330
				}
340
				this.binding = scope.findMethod((ReferenceBinding) receiverType, TypeConstants.INIT, pseudoArgs, this);
331
				this.binding = scope.findMethod(referenceReceiver, TypeConstants.INIT, pseudoArgs, this);
341
				if (this.binding != null && !this.binding.isValidBinding()) {
332
				if (this.binding != null && !this.binding.isValidBinding()) {
342
					MethodBinding closestMatch = ((ProblemMethodBinding)this.binding).closestMatch;
333
					MethodBinding closestMatch = ((ProblemMethodBinding)this.binding).closestMatch;
343
					// record the closest match, for clients who may still need hint about possible method match
334
					// record the closest match, for clients who may still need hint about possible method match
Lines 354-360 Link Here
354
						}
345
						}
355
					}
346
					}
356
				}
347
				}
357
				
348
				if (this.anonymousType != null) {
349
					// insert anonymous type in scope (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=210070)
350
					scope.addAnonymousType(this.anonymousType, referenceReceiver);
351
					this.anonymousType.resolve(scope);
352
					return this.resolvedType = this.anonymousType.binding;
353
				}
358
			}
354
			}
359
			return this.resolvedType = receiverType;
355
			return this.resolvedType = receiverType;
360
		}
356
		}
Lines 392-448 Link Here
392
			scope.problemReporter().typeMismatchError(enclosingInstanceType, expectedType, this.enclosingInstance);
388
			scope.problemReporter().typeMismatchError(enclosingInstanceType, expectedType, this.enclosingInstance);
393
			return this.resolvedType = receiverType;
389
			return this.resolvedType = receiverType;
394
		}
390
		}
395
391
		ReferenceBinding superType = (ReferenceBinding) receiverType;
396
		if (receiverType.isTypeVariable()) {
392
		if (superType.isTypeVariable()) {
397
			receiverType = new ProblemReferenceBinding(receiverType.sourceName(), (ReferenceBinding)receiverType, ProblemReasons.IllegalSuperTypeVariable);
393
			superType = new ProblemReferenceBinding(superType.sourceName(), superType, ProblemReasons.IllegalSuperTypeVariable);
398
			scope.problemReporter().invalidType(this, receiverType);
394
			scope.problemReporter().invalidType(this, superType);
399
			return null;
395
			return null;
400
		} else if (this.type != null && receiverType.isEnum()) { // tolerate enum constant body
396
		} else if (this.type != null && superType.isEnum()) { // tolerate enum constant body
401
			scope.problemReporter().cannotInstantiate(this.type, receiverType);
397
			scope.problemReporter().cannotInstantiate(this.type, superType);
402
			return this.resolvedType = receiverType;
398
			return this.resolvedType = superType;
403
		}
399
		}
404
		// anonymous type scenario
400
		// anonymous type scenario
405
		// an anonymous class inherits from java.lang.Object when declared "after" an interface
401
		// an anonymous class inherits from java.lang.Object when declared "after" an interface
406
		this.superTypeBinding = receiverType.isInterface() ? scope.getJavaLangObject() : (ReferenceBinding) receiverType;
402
		this.superclassBinding = superType.isInterface() ? scope.getJavaLangObject() : superType;
407
		// insert anonymous type in scope
403
		// insert anonymous type in scope
408
		scope.addAnonymousType(this.anonymousType, (ReferenceBinding) receiverType);
404
		scope.addAnonymousType(this.anonymousType, superType);
409
		this.anonymousType.resolve(scope);		
405
		this.anonymousType.resolve(scope);	
410
		if (this.superTypeBinding.erasure().id == TypeIds.T_JavaLangEnum) {
406
			
411
			scope.problemReporter().cannotExtendEnum(this.anonymousType.binding, this.type, this.superTypeBinding);
412
		}
413
		
414
		if ((receiverType.tagBits & TagBits.HasDirectWildcard) != 0) {
415
			scope.problemReporter().superTypeCannotUseWildcard(this.anonymousType.binding, this.type, receiverType);
416
		}		
417
		// find anonymous super constructor
407
		// find anonymous super constructor
418
		MethodBinding inheritedBinding = scope.getConstructor(this.superTypeBinding, argumentTypes, this);
408
		this.resolvedType = this.anonymousType.binding; // 1.2 change
409
		if ((this.resolvedType.tagBits & TagBits.HierarchyHasProblems) != 0) {
410
			return null; // stop secondary errors
411
		}
412
		MethodBinding inheritedBinding = scope.getConstructor(this.superclassBinding, argumentTypes, this);
419
		if (!inheritedBinding.isValidBinding()) {
413
		if (!inheritedBinding.isValidBinding()) {
420
			if (inheritedBinding.declaringClass == null) {
414
			if (inheritedBinding.declaringClass == null) {
421
				inheritedBinding.declaringClass = this.superTypeBinding;
415
				inheritedBinding.declaringClass = this.superclassBinding;
422
			}
416
			}
423
			scope.problemReporter().invalidConstructor(this, inheritedBinding);
417
			scope.problemReporter().invalidConstructor(this, inheritedBinding);
424
			return this.resolvedType = this.anonymousType.binding;
418
			return this.resolvedType;
425
		}
419
		}
426
		if (this.enclosingInstance != null) {
420
		if (this.enclosingInstance != null) {
427
			ReferenceBinding targetEnclosing = inheritedBinding.declaringClass.enclosingType();
421
			ReferenceBinding targetEnclosing = inheritedBinding.declaringClass.enclosingType();
428
			if (targetEnclosing == null) {
422
			if (targetEnclosing == null) {
429
				scope.problemReporter().unnecessaryEnclosingInstanceSpecification(this.enclosingInstance, (ReferenceBinding)receiverType);
423
				scope.problemReporter().unnecessaryEnclosingInstanceSpecification(this.enclosingInstance, superType);
430
				return this.resolvedType = this.anonymousType.binding;
424
				return this.resolvedType;
431
			} else if (!enclosingInstanceType.isCompatibleWith(targetEnclosing) && !scope.isBoxingCompatibleWith(enclosingInstanceType, targetEnclosing)) {
425
			} else if (!enclosingInstanceType.isCompatibleWith(targetEnclosing) && !scope.isBoxingCompatibleWith(enclosingInstanceType, targetEnclosing)) {
432
				scope.problemReporter().typeMismatchError(enclosingInstanceType, targetEnclosing, this.enclosingInstance);
426
				scope.problemReporter().typeMismatchError(enclosingInstanceType, targetEnclosing, this.enclosingInstance);
433
				return this.resolvedType = this.anonymousType.binding;
427
				return this.resolvedType;
434
			}
428
			}
435
			this.enclosingInstance.computeConversion(scope, targetEnclosing, enclosingInstanceType);
429
			this.enclosingInstance.computeConversion(scope, targetEnclosing, enclosingInstanceType);
436
		}
430
		}
437
		if (this.arguments != null)
431
		if (this.arguments != null) {
438
			checkInvocationArguments(scope, null, this.superTypeBinding, inheritedBinding, this.arguments, argumentTypes, argsContainCast, this);
432
			// TODO shouldn't this.superclassBinding be replaced with superType ?
439
433
			checkInvocationArguments(scope, null, this.superclassBinding, inheritedBinding, this.arguments, argumentTypes, argsContainCast, this);
434
		}
440
		if (this.typeArguments != null && inheritedBinding.original().typeVariables == Binding.NO_TYPE_VARIABLES) {
435
		if (this.typeArguments != null && inheritedBinding.original().typeVariables == Binding.NO_TYPE_VARIABLES) {
441
			scope.problemReporter().unnecessaryTypeArgumentsForMethodInvocation(inheritedBinding, this.genericTypeArguments, this.typeArguments);
436
			scope.problemReporter().unnecessaryTypeArgumentsForMethodInvocation(inheritedBinding, this.genericTypeArguments, this.typeArguments);
442
		}		
437
		}		
443
		// Update the anonymous inner class : superclass, interface  
438
		// Update the anonymous inner class : superclass, interface  
444
		this.binding = this.anonymousType.createDefaultConstructorWithBinding(inheritedBinding);
439
		this.binding = this.anonymousType.createDefaultConstructorWithBinding(inheritedBinding);
445
		return this.resolvedType = this.anonymousType.binding; // 1.2 change
440
		return this.resolvedType;
446
	}
441
	}
447
	
442
	
448
	public void traverse(ASTVisitor visitor, BlockScope scope) {
443
	public void traverse(ASTVisitor visitor, BlockScope scope) {
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (-3 / +3 lines)
Lines 680-692 Link Here
680
    		value.sourceEnd);
680
    		value.sourceEnd);
681
    }
681
    }
682
}
682
}
683
public void anonymousClassCannotExtendFinalClass(Expression expression, TypeBinding type) {
683
public void anonymousClassCannotExtendFinalClass(TypeReference reference, TypeBinding type) {
684
	this.handle(
684
	this.handle(
685
		IProblem.AnonymousClassCannotExtendFinalClass,
685
		IProblem.AnonymousClassCannotExtendFinalClass,
686
		new String[] {new String(type.readableName())},
686
		new String[] {new String(type.readableName())},
687
		new String[] {new String(type.shortReadableName())},
687
		new String[] {new String(type.shortReadableName())},
688
		expression.sourceStart,
688
		reference.sourceStart,
689
		expression.sourceEnd);
689
		reference.sourceEnd);
690
}
690
}
691
public void argumentTypeCannotBeVoid(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg) {
691
public void argumentTypeCannotBeVoid(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg) {
692
	String[] arguments = new String[] {new String(methodDecl.selector), new String(arg.name)};
692
	String[] arguments = new String[] {new String(methodDecl.selector), new String(arg.name)};
(-)codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionOnQualifiedAllocationExpression.java (-5 / +9 lines)
Lines 36-41 Link Here
36
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
36
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
37
import org.eclipse.jdt.internal.compiler.lookup.Binding;
37
import org.eclipse.jdt.internal.compiler.lookup.Binding;
38
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
38
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
39
import org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding;
39
import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
40
import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
40
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
41
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
41
 
42
 
Lines 88-101 Link Here
88
		// find its target super constructor (if extending a class) or its target 
89
		// find its target super constructor (if extending a class) or its target 
89
		// super interface (if extending an interface)
90
		// super interface (if extending an interface)
90
		if (anonymousType.binding != null) {
91
		if (anonymousType.binding != null) {
91
			if (anonymousType.binding.superInterfaces == Binding.NO_SUPERINTERFACES) {
92
			LocalTypeBinding localType = (LocalTypeBinding) anonymousType.binding;
93
			if (localType.superInterfaces == Binding.NO_SUPERINTERFACES) {
92
				// find the constructor binding inside the super constructor call
94
				// find the constructor binding inside the super constructor call
93
				ConstructorDeclaration constructor = (ConstructorDeclaration) anonymousType.declarationOf(binding.original());
95
				ConstructorDeclaration constructor = (ConstructorDeclaration) anonymousType.declarationOf(binding.original());
94
				throw new SelectionNodeFound(constructor.constructorCall.binding);
96
				if (constructor != null) {
95
			} else {
97
					throw new SelectionNodeFound(constructor.constructorCall.binding);
96
				// open on the only superinterface
98
				}
97
				throw new SelectionNodeFound(anonymousType.binding.superInterfaces[0]);
99
				throw new SelectionNodeFound(binding);
98
			}
100
			}
101
			// open on the only super interface
102
			throw new SelectionNodeFound(localType.superInterfaces[0]);
99
		} else {
103
		} else {
100
			if (this.resolvedType.isInterface()) {
104
			if (this.resolvedType.isInterface()) {
101
				throw new SelectionNodeFound(resolvedType);
105
				throw new SelectionNodeFound(resolvedType);

Return to bug 210422