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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java (-67 / +77 lines)
Lines 12-21 Link Here
12
12
13
import org.eclipse.jdt.internal.compiler.ASTVisitor;
13
import org.eclipse.jdt.internal.compiler.ASTVisitor;
14
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
14
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
15
import org.eclipse.jdt.internal.compiler.codegen.*;
15
import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
16
import org.eclipse.jdt.internal.compiler.flow.*;
16
import org.eclipse.jdt.internal.compiler.flow.FlowContext;
17
import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
17
import org.eclipse.jdt.internal.compiler.impl.Constant;
18
import org.eclipse.jdt.internal.compiler.impl.Constant;
18
import org.eclipse.jdt.internal.compiler.lookup.*;
19
import org.eclipse.jdt.internal.compiler.lookup.Binding;
20
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
21
import org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding;
22
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
23
import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
24
import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding;
25
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
26
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
27
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
28
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
19
29
20
/**
30
/**
21
 * Variation on allocation, where can optionally be specified any of:
31
 * Variation on allocation, where can optionally be specified any of:
Lines 45-52 Link Here
45
		FlowInfo flowInfo) {
55
		FlowInfo flowInfo) {
46
56
47
		// analyse the enclosing instance
57
		// analyse the enclosing instance
48
		if (enclosingInstance != null) {
58
		if (this.enclosingInstance != null) {
49
			flowInfo = enclosingInstance.analyseCode(currentScope, flowContext, flowInfo);
59
			flowInfo = this.enclosingInstance.analyseCode(currentScope, flowContext, flowInfo);
50
		}
60
		}
51
		
61
		
52
		// check captured variables are initialized in current context (26134)
62
		// check captured variables are initialized in current context (26134)
Lines 57-76 Link Here
57
			flowInfo);
67
			flowInfo);
58
		
68
		
59
		// process arguments
69
		// process arguments
60
		if (arguments != null) {
70
		if (this.arguments != null) {
61
			for (int i = 0, count = arguments.length; i < count; i++) {
71
			for (int i = 0, count = this.arguments.length; i < count; i++) {
62
				flowInfo = arguments[i].analyseCode(currentScope, flowContext, flowInfo);
72
				flowInfo = this.arguments[i].analyseCode(currentScope, flowContext, flowInfo);
63
			}
73
			}
64
		}
74
		}
65
75
66
		// analyse the anonymous nested type
76
		// analyse the anonymous nested type
67
		if (anonymousType != null) {
77
		if (this.anonymousType != null) {
68
			flowInfo = anonymousType.analyseCode(currentScope, flowContext, flowInfo);
78
			flowInfo = this.anonymousType.analyseCode(currentScope, flowContext, flowInfo);
69
		}
79
		}
70
80
71
		// record some dependency information for exception types
81
		// record some dependency information for exception types
72
		ReferenceBinding[] thrownExceptions;
82
		ReferenceBinding[] thrownExceptions;
73
		if (((thrownExceptions = binding.thrownExceptions).length) != 0) {
83
		if (((thrownExceptions = this.binding.thrownExceptions).length) != 0) {
74
			// check exception handling
84
			// check exception handling
75
			flowContext.checkExceptionHandlers(
85
			flowContext.checkExceptionHandlers(
76
				thrownExceptions,
86
				thrownExceptions,
Lines 85-91 Link Here
85
95
86
	public Expression enclosingInstance() {
96
	public Expression enclosingInstance() {
87
97
88
		return enclosingInstance;
98
		return this.enclosingInstance;
89
	}
99
	}
90
100
91
	public void generateCode(
101
	public void generateCode(
Lines 104-111 Link Here
104
			codeStream.recordPositionsFrom(pc, this.type.sourceStart);
114
			codeStream.recordPositionsFrom(pc, this.type.sourceStart);
105
		} else {
115
		} else {
106
			// push enum constant name and ordinal
116
			// push enum constant name and ordinal
107
			codeStream.ldc(String.valueOf(enumConstant.name));
117
			codeStream.ldc(String.valueOf(this.enumConstant.name));
108
			codeStream.generateInlinedValue(enumConstant.binding.id);
118
			codeStream.generateInlinedValue(this.enumConstant.binding.id);
109
		}
119
		}
110
		// handling innerclass instance allocation - enclosing instance arguments
120
		// handling innerclass instance allocation - enclosing instance arguments
111
		if (allocatedType.isNestedType()) {
121
		if (allocatedType.isNestedType()) {
Lines 116-122 Link Here
116
				this);
126
				this);
117
		}
127
		}
118
		// generate the arguments for constructor
128
		// generate the arguments for constructor
119
		generateArguments(binding, arguments, currentScope, codeStream);
129
		generateArguments(this.binding, this.arguments, currentScope, codeStream);
120
		// handling innerclass instance allocation - outer local arguments
130
		// handling innerclass instance allocation - outer local arguments
121
		if (allocatedType.isNestedType()) {
131
		if (allocatedType.isNestedType()) {
122
			codeStream.generateSyntheticOuterArgumentValues(
132
			codeStream.generateSyntheticOuterArgumentValues(
Lines 126-155 Link Here
126
		}
136
		}
127
		
137
		
128
		// invoke constructor
138
		// invoke constructor
129
		if (syntheticAccessor == null) {
139
		if (this.syntheticAccessor == null) {
130
			codeStream.invokespecial(this.codegenBinding);
140
			codeStream.invokespecial(this.codegenBinding);
131
		} else {
141
		} else {
132
			// synthetic accessor got some extra arguments appended to its signature, which need values
142
			// synthetic accessor got some extra arguments appended to its signature, which need values
133
			for (int i = 0,
143
			for (int i = 0,
134
				max = syntheticAccessor.parameters.length - this.codegenBinding.parameters.length;
144
				max = this.syntheticAccessor.parameters.length - this.codegenBinding.parameters.length;
135
				i < max;
145
				i < max;
136
				i++) {
146
				i++) {
137
				codeStream.aconst_null();
147
				codeStream.aconst_null();
138
			}
148
			}
139
			codeStream.invokespecial(syntheticAccessor);
149
			codeStream.invokespecial(this.syntheticAccessor);
140
		}
150
		}
141
		codeStream.generateImplicitConversion(this.implicitConversion);
151
		codeStream.generateImplicitConversion(this.implicitConversion);
142
		codeStream.recordPositionsFrom(pc, this.sourceStart);
152
		codeStream.recordPositionsFrom(pc, this.sourceStart);
143
153
144
		if (anonymousType != null) {
154
		if (this.anonymousType != null) {
145
			anonymousType.generateCode(currentScope, codeStream);
155
			this.anonymousType.generateCode(currentScope, codeStream);
146
		}
156
		}
147
	}
157
	}
148
	
158
	
149
	public boolean isSuperAccess() {
159
	public boolean isSuperAccess() {
150
160
151
		// necessary to lookup super constructor of anonymous type
161
		// necessary to lookup super constructor of anonymous type
152
		return anonymousType != null;
162
		return this.anonymousType != null;
153
	}
163
	}
154
	
164
	
155
	/* Inner emulation consists in either recording a dependency 
165
	/* Inner emulation consists in either recording a dependency 
Lines 162-178 Link Here
162
	public void manageEnclosingInstanceAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo) {
172
	public void manageEnclosingInstanceAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo) {
163
173
164
		if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0)	{
174
		if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0)	{
165
		ReferenceBinding allocatedTypeErasure = (ReferenceBinding) binding.declaringClass.erasure();
175
		ReferenceBinding allocatedTypeErasure = (ReferenceBinding) this.binding.declaringClass.erasure();
166
176
167
		// perform some extra emulation work in case there is some and we are inside a local type only
177
		// perform some extra emulation work in case there is some and we are inside a local type only
168
		if (allocatedTypeErasure.isNestedType()
178
		if (allocatedTypeErasure.isNestedType()
169
			&& currentScope.enclosingSourceType().isLocalType()) {
179
			&& currentScope.enclosingSourceType().isLocalType()) {
170
180
171
			if (allocatedTypeErasure.isLocalType()) {
181
			if (allocatedTypeErasure.isLocalType()) {
172
				((LocalTypeBinding) allocatedTypeErasure).addInnerEmulationDependent(currentScope, enclosingInstance != null);
182
				((LocalTypeBinding) allocatedTypeErasure).addInnerEmulationDependent(currentScope, this.enclosingInstance != null);
173
			} else {
183
			} else {
174
				// locally propagate, since we already now the desired shape for sure
184
				// locally propagate, since we already now the desired shape for sure
175
				currentScope.propagateInnerEmulation(allocatedTypeErasure, enclosingInstance != null);
185
				currentScope.propagateInnerEmulation(allocatedTypeErasure, this.enclosingInstance != null);
176
			}
186
			}
177
		}
187
		}
178
		}
188
		}
Lines 180-190 Link Here
180
190
181
	public StringBuffer printExpression(int indent, StringBuffer output) {
191
	public StringBuffer printExpression(int indent, StringBuffer output) {
182
192
183
		if (enclosingInstance != null)
193
		if (this.enclosingInstance != null)
184
			enclosingInstance.printExpression(0, output).append('.'); 
194
			this.enclosingInstance.printExpression(0, output).append('.'); 
185
		super.printExpression(0, output);
195
		super.printExpression(0, output);
186
		if (anonymousType != null) {
196
		if (this.anonymousType != null) {
187
			anonymousType.print(indent, output);
197
			this.anonymousType.print(indent, output);
188
		}
198
		}
189
		return output;
199
		return output;
190
	}
200
	}
Lines 200-231 Link Here
200
		// ClassInstanceCreationExpression ::= Primary '.' 'new' SimpleName '(' ArgumentListopt ')' ClassBodyopt
210
		// ClassInstanceCreationExpression ::= Primary '.' 'new' SimpleName '(' ArgumentListopt ')' ClassBodyopt
201
		// ClassInstanceCreationExpression ::= Name '.' 'new' SimpleName '(' ArgumentListopt ')' ClassBodyopt
211
		// ClassInstanceCreationExpression ::= Name '.' 'new' SimpleName '(' ArgumentListopt ')' ClassBodyopt
202
		
212
		
203
		constant = Constant.NotAConstant;
213
		this.constant = Constant.NotAConstant;
204
		TypeBinding enclosingInstanceType = null;
214
		TypeBinding enclosingInstanceType = null;
205
		TypeBinding receiverType = null;
215
		TypeBinding receiverType = null;
206
		boolean hasError = false;
216
		boolean hasError = false;
207
		boolean enclosingInstanceContainsCast = false;
217
		boolean enclosingInstanceContainsCast = false;
208
		boolean argsContainCast = false;
218
		boolean argsContainCast = false;
209
		
219
		
210
		if (enclosingInstance != null) {
220
		if (this.enclosingInstance != null) {
211
			if (enclosingInstance instanceof CastExpression) {
221
			if (this.enclosingInstance instanceof CastExpression) {
212
				enclosingInstance.bits |= DisableUnnecessaryCastCheck; // will check later on
222
				this.enclosingInstance.bits |= ASTNode.DisableUnnecessaryCastCheck; // will check later on
213
				enclosingInstanceContainsCast = true;
223
				enclosingInstanceContainsCast = true;
214
			}
224
			}
215
			if ((enclosingInstanceType = enclosingInstance.resolveType(scope)) == null){
225
			if ((enclosingInstanceType = this.enclosingInstance.resolveType(scope)) == null){
216
				hasError = true;
226
				hasError = true;
217
			} else if (enclosingInstanceType.isBaseType() || enclosingInstanceType.isArrayType()) {
227
			} else if (enclosingInstanceType.isBaseType() || enclosingInstanceType.isArrayType()) {
218
				scope.problemReporter().illegalPrimitiveOrArrayTypeForEnclosingInstance(
228
				scope.problemReporter().illegalPrimitiveOrArrayTypeForEnclosingInstance(
219
					enclosingInstanceType,
229
					enclosingInstanceType,
220
					enclosingInstance);
230
					this.enclosingInstance);
221
				hasError = true;
231
				hasError = true;
222
			} else if (type instanceof QualifiedTypeReference) {
232
			} else if (this.type instanceof QualifiedTypeReference) {
223
				scope.problemReporter().illegalUsageOfQualifiedTypeReference((QualifiedTypeReference)type);
233
				scope.problemReporter().illegalUsageOfQualifiedTypeReference((QualifiedTypeReference)this.type);
224
				hasError = true;
234
				hasError = true;
225
			} else {
235
			} else {
226
				receiverType = ((SingleTypeReference) type).resolveTypeEnclosing(scope, (ReferenceBinding) enclosingInstanceType);
236
				receiverType = ((SingleTypeReference) this.type).resolveTypeEnclosing(scope, (ReferenceBinding) enclosingInstanceType);
227
				if (receiverType != null && enclosingInstanceContainsCast) {
237
				if (receiverType != null && enclosingInstanceContainsCast) {
228
					CastExpression.checkNeedForEnclosingInstanceCast(scope, enclosingInstance, enclosingInstanceType, receiverType);
238
					CastExpression.checkNeedForEnclosingInstanceCast(scope, this.enclosingInstance, enclosingInstanceType, receiverType);
229
				}
239
				}
230
			}
240
			}
231
		} else {
241
		} else {
Lines 259-269 Link Here
259
		} else if (((ReferenceBinding) receiverType).isFinal()) {
269
		} else if (((ReferenceBinding) receiverType).isFinal()) {
260
			if (this.anonymousType != null) {
270
			if (this.anonymousType != null) {
261
				if (!receiverType.isEnum()) {
271
				if (!receiverType.isEnum()) {
262
					scope.problemReporter().anonymousClassCannotExtendFinalClass(type, receiverType);
272
					scope.problemReporter().anonymousClassCannotExtendFinalClass(this.type, receiverType);
263
					hasError = true;
273
					hasError = true;
264
				}
274
				}
265
			} else if (!receiverType.canBeInstantiated()) {
275
			} else if (!receiverType.canBeInstantiated()) {
266
				scope.problemReporter().cannotInstantiate(type, receiverType);
276
				scope.problemReporter().cannotInstantiate(this.type, receiverType);
267
				return this.resolvedType = receiverType;
277
				return this.resolvedType = receiverType;
268
			}
278
			}
269
		}
279
		}
Lines 286-298 Link Here
286
		
296
		
287
		// will check for null after args are resolved
297
		// will check for null after args are resolved
288
		TypeBinding[] argumentTypes = Binding.NO_PARAMETERS;
298
		TypeBinding[] argumentTypes = Binding.NO_PARAMETERS;
289
		if (arguments != null) {
299
		if (this.arguments != null) {
290
			int length = arguments.length;
300
			int length = this.arguments.length;
291
			argumentTypes = new TypeBinding[length];
301
			argumentTypes = new TypeBinding[length];
292
			for (int i = 0; i < length; i++) {
302
			for (int i = 0; i < length; i++) {
293
				Expression argument = this.arguments[i];
303
				Expression argument = this.arguments[i];
294
				if (argument instanceof CastExpression) {
304
				if (argument instanceof CastExpression) {
295
					argument.bits |= DisableUnnecessaryCastCheck; // will check later on
305
					argument.bits |= ASTNode.DisableUnnecessaryCastCheck; // will check later on
296
					argsContainCast = true;
306
					argsContainCast = true;
297
				}
307
				}
298
				if ((argumentTypes[i] = argument.resolveType(scope)) == null){
308
				if ((argumentTypes[i] = argument.resolveType(scope)) == null){
Lines 305-319 Link Here
305
		if (this.anonymousType == null) {
315
		if (this.anonymousType == null) {
306
			// qualified allocation with no anonymous type
316
			// qualified allocation with no anonymous type
307
			if (!receiverType.canBeInstantiated()) {
317
			if (!receiverType.canBeInstantiated()) {
308
				scope.problemReporter().cannotInstantiate(type, receiverType);
318
				scope.problemReporter().cannotInstantiate(this.type, receiverType);
309
				return this.resolvedType = receiverType;
319
				return this.resolvedType = receiverType;
310
			}
320
			}
311
			ReferenceBinding allocationType = (ReferenceBinding) receiverType;
321
			ReferenceBinding allocationType = (ReferenceBinding) receiverType;
312
			if ((this.binding = scope.getConstructor(allocationType, argumentTypes, this)).isValidBinding()) {
322
			if ((this.binding = scope.getConstructor(allocationType, argumentTypes, this)).isValidBinding()) {
313
				if (isMethodUseDeprecated(binding, scope, true)) {
323
				if (isMethodUseDeprecated(this.binding, scope, true)) {
314
					scope.problemReporter().deprecatedMethod(this.binding, this);
324
					scope.problemReporter().deprecatedMethod(this.binding, this);
315
				}
325
				}
316
				checkInvocationArguments(scope, null, allocationType, binding, this.arguments, argumentTypes, argsContainCast, this);
326
				checkInvocationArguments(scope, null, allocationType, this.binding, this.arguments, argumentTypes, argsContainCast, this);
317
			} else {
327
			} else {
318
				if (this.binding.declaringClass == null) {
328
				if (this.binding.declaringClass == null) {
319
					this.binding.declaringClass = allocationType;
329
					this.binding.declaringClass = allocationType;
Lines 327-333 Link Here
327
			if (expectedType != enclosingInstanceType) // must call before computeConversion() and typeMismatchError()
337
			if (expectedType != enclosingInstanceType) // must call before computeConversion() and typeMismatchError()
328
				scope.compilationUnitScope().recordTypeConversion(expectedType, enclosingInstanceType);
338
				scope.compilationUnitScope().recordTypeConversion(expectedType, enclosingInstanceType);
329
			if (enclosingInstanceType.isCompatibleWith(expectedType) || scope.isBoxingCompatibleWith(enclosingInstanceType, expectedType)) {
339
			if (enclosingInstanceType.isCompatibleWith(expectedType) || scope.isBoxingCompatibleWith(enclosingInstanceType, expectedType)) {
330
				enclosingInstance.computeConversion(scope, expectedType, enclosingInstanceType);
340
				this.enclosingInstance.computeConversion(scope, expectedType, enclosingInstanceType);
331
				return this.resolvedType = receiverType;
341
				return this.resolvedType = receiverType;
332
			}
342
			}
333
			scope.problemReporter().typeMismatchError(enclosingInstanceType, expectedType, this.enclosingInstance);
343
			scope.problemReporter().typeMismatchError(enclosingInstanceType, expectedType, this.enclosingInstance);
Lines 338-345 Link Here
338
			receiverType = new ProblemReferenceBinding(receiverType.sourceName(), (ReferenceBinding)receiverType, ProblemReasons.IllegalSuperTypeVariable);
348
			receiverType = new ProblemReferenceBinding(receiverType.sourceName(), (ReferenceBinding)receiverType, ProblemReasons.IllegalSuperTypeVariable);
339
			scope.problemReporter().invalidType(this, receiverType);
349
			scope.problemReporter().invalidType(this, receiverType);
340
			return null;
350
			return null;
341
		} else if (type != null && receiverType.isEnum()) { // tolerate enum constant body
351
		} else if (this.type != null && receiverType.isEnum()) { // tolerate enum constant body
342
			scope.problemReporter().cannotInstantiate(type, receiverType);
352
			scope.problemReporter().cannotInstantiate(this.type, receiverType);
343
			return this.resolvedType = receiverType;
353
			return this.resolvedType = receiverType;
344
		}
354
		}
345
		// anonymous type scenario
355
		// anonymous type scenario
Lines 348-359 Link Here
348
		// insert anonymous type in scope
358
		// insert anonymous type in scope
349
		scope.addAnonymousType(this.anonymousType, (ReferenceBinding) receiverType);
359
		scope.addAnonymousType(this.anonymousType, (ReferenceBinding) receiverType);
350
		this.anonymousType.resolve(scope);		
360
		this.anonymousType.resolve(scope);		
351
		if (this.superTypeBinding.erasure().id == T_JavaLangEnum) {
361
		if (this.superTypeBinding.erasure().id == TypeIds.T_JavaLangEnum) {
352
			scope.problemReporter().cannotExtendEnum(this.anonymousType.binding, this.type, this.superTypeBinding);
362
			scope.problemReporter().cannotExtendEnum(this.anonymousType.binding, this.type, this.superTypeBinding);
353
		}
363
		}
354
		
364
		
355
		if ((receiverType.tagBits & TagBits.HasDirectWildcard) != 0) {
365
		if ((receiverType.tagBits & TagBits.HasDirectWildcard) != 0) {
356
			scope.problemReporter().superTypeCannotUseWildcard(anonymousType.binding, this.type, receiverType);
366
			scope.problemReporter().superTypeCannotUseWildcard(this.anonymousType.binding, this.type, receiverType);
357
		}		
367
		}		
358
		// find anonymous super constructor
368
		// find anonymous super constructor
359
		MethodBinding inheritedBinding = scope.getConstructor(this.superTypeBinding, argumentTypes, this);
369
		MethodBinding inheritedBinding = scope.getConstructor(this.superTypeBinding, argumentTypes, this);
Lines 362-393 Link Here
362
				inheritedBinding.declaringClass = this.superTypeBinding;
372
				inheritedBinding.declaringClass = this.superTypeBinding;
363
			}
373
			}
364
			scope.problemReporter().invalidConstructor(this, inheritedBinding);
374
			scope.problemReporter().invalidConstructor(this, inheritedBinding);
365
			return this.resolvedType = anonymousType.binding;
375
			return this.resolvedType = this.anonymousType.binding;
366
		}
376
		}
367
		if (enclosingInstance != null) {
377
		if (this.enclosingInstance != null) {
368
			ReferenceBinding targetEnclosing = inheritedBinding.declaringClass.enclosingType();
378
			ReferenceBinding targetEnclosing = inheritedBinding.declaringClass.enclosingType();
369
			if (targetEnclosing == null) {
379
			if (targetEnclosing == null) {
370
				scope.problemReporter().unnecessaryEnclosingInstanceSpecification(enclosingInstance, (ReferenceBinding)receiverType);
380
				scope.problemReporter().unnecessaryEnclosingInstanceSpecification(this.enclosingInstance, (ReferenceBinding)receiverType);
371
				return this.resolvedType = anonymousType.binding;
381
				return this.resolvedType = this.anonymousType.binding;
372
			} else if (!enclosingInstanceType.isCompatibleWith(targetEnclosing) && !scope.isBoxingCompatibleWith(enclosingInstanceType, targetEnclosing)) {
382
			} else if (!enclosingInstanceType.isCompatibleWith(targetEnclosing) && !scope.isBoxingCompatibleWith(enclosingInstanceType, targetEnclosing)) {
373
				scope.problemReporter().typeMismatchError(enclosingInstanceType, targetEnclosing, enclosingInstance);
383
				scope.problemReporter().typeMismatchError(enclosingInstanceType, targetEnclosing, this.enclosingInstance);
374
				return this.resolvedType = anonymousType.binding;
384
				return this.resolvedType = this.anonymousType.binding;
375
			}
385
			}
376
			enclosingInstance.computeConversion(scope, targetEnclosing, enclosingInstanceType);
386
			this.enclosingInstance.computeConversion(scope, targetEnclosing, enclosingInstanceType);
377
		}
387
		}
378
		if (this.arguments != null)
388
		if (this.arguments != null)
379
			checkInvocationArguments(scope, null, this.superTypeBinding, inheritedBinding, this.arguments, argumentTypes, argsContainCast, this);
389
			checkInvocationArguments(scope, null, this.superTypeBinding, inheritedBinding, this.arguments, argumentTypes, argsContainCast, this);
380
390
381
		// Update the anonymous inner class : superclass, interface  
391
		// Update the anonymous inner class : superclass, interface  
382
		binding = anonymousType.createDefaultConstructorWithBinding(inheritedBinding);
392
		this.binding = this.anonymousType.createDefaultConstructorWithBinding(inheritedBinding);
383
		return this.resolvedType = anonymousType.binding; // 1.2 change
393
		return this.resolvedType = this.anonymousType.binding; // 1.2 change
384
	}
394
	}
385
	
395
	
386
	public void traverse(ASTVisitor visitor, BlockScope scope) {
396
	public void traverse(ASTVisitor visitor, BlockScope scope) {
387
397
388
		if (visitor.visit(this, scope)) {
398
		if (visitor.visit(this, scope)) {
389
			if (enclosingInstance != null)
399
			if (this.enclosingInstance != null)
390
				enclosingInstance.traverse(visitor, scope);
400
				this.enclosingInstance.traverse(visitor, scope);
391
			if (this.typeArguments != null) {
401
			if (this.typeArguments != null) {
392
				for (int i = 0, typeArgumentsLength = this.typeArguments.length; i < typeArgumentsLength; i++) {
402
				for (int i = 0, typeArgumentsLength = this.typeArguments.length; i < typeArgumentsLength; i++) {
393
					this.typeArguments[i].traverse(visitor, scope);
403
					this.typeArguments[i].traverse(visitor, scope);
Lines 395-407 Link Here
395
			}
405
			}
396
			if (this.type != null) // case of enum constant
406
			if (this.type != null) // case of enum constant
397
				this.type.traverse(visitor, scope);
407
				this.type.traverse(visitor, scope);
398
			if (arguments != null) {
408
			if (this.arguments != null) {
399
				int argumentsLength = arguments.length;
409
				int argumentsLength = this.arguments.length;
400
				for (int i = 0; i < argumentsLength; i++)
410
				for (int i = 0; i < argumentsLength; i++)
401
					arguments[i].traverse(visitor, scope);
411
					this.arguments[i].traverse(visitor, scope);
402
			}
412
			}
403
			if (anonymousType != null)
413
			if (this.anonymousType != null)
404
				anonymousType.traverse(visitor, scope);
414
				this.anonymousType.traverse(visitor, scope);
405
		}
415
		}
406
		visitor.endVisit(this, scope);
416
		visitor.endVisit(this, scope);
407
	}
417
	}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java (-5 / +8 lines)
Lines 120-126 Link Here
120
					: scope.environment().convertToParameterizedType(enclosingType);
120
					: scope.environment().convertToParameterizedType(enclosingType);
121
			}
121
			}
122
		} else { // resolving member type (relatively to enclosingType)
122
		} else { // resolving member type (relatively to enclosingType)
123
			this.resolvedType = scope.getMemberType(token, (ReferenceBinding)enclosingType.erasure());		    
123
			this.resolvedType = scope.getMemberType(token, enclosingType);		    
124
			if (!this.resolvedType.isValidBinding()) {
124
			if (!this.resolvedType.isValidBinding()) {
125
				scope.problemReporter().invalidEnclosingType(this, this.resolvedType, enclosingType);
125
				scope.problemReporter().invalidEnclosingType(this, this.resolvedType, enclosingType);
126
				return null;
126
				return null;
Lines 165-174 Link Here
165
		} else if (argLength != typeVariables.length) { // check arity
165
		} else if (argLength != typeVariables.length) { // check arity
166
			scope.problemReporter().incorrectArityForParameterizedType(this, currentType, argTypes);
166
			scope.problemReporter().incorrectArityForParameterizedType(this, currentType, argTypes);
167
			return null;
167
			return null;
168
		} else if (!currentType.isStatic() && enclosingType != null && enclosingType.isRawType()){
168
		} else if (!currentType.isStatic()) {
169
			scope.problemReporter().rawMemberTypeCannotBeParameterized(
169
			ReferenceBinding actualEnclosing = currentType.enclosingType();
170
					this, scope.environment().createRawType((ReferenceBinding)currentType.erasure(), enclosingType), argTypes);
170
			if (actualEnclosing != null && actualEnclosing.isRawType()){
171
			return null;
171
				scope.problemReporter().rawMemberTypeCannotBeParameterized(
172
						this, scope.environment().createRawType((ReferenceBinding)currentType.erasure(), actualEnclosing), argTypes);
173
				return null;
174
			}
172
		}
175
		}
173
176
174
    	ParameterizedTypeBinding parameterizedType = scope.environment().createParameterizedType((ReferenceBinding)currentType.erasure(), argTypes, enclosingType);
177
    	ParameterizedTypeBinding parameterizedType = scope.environment().createParameterizedType((ReferenceBinding)currentType.erasure(), argTypes, enclosingType);
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedQualifiedTypeReference.java (-6 / +10 lines)
Lines 218-228 Link Here
218
					return null;
218
					return null;
219
				}
219
				}
220
				// check parameterizing non-static member type of raw type
220
				// check parameterizing non-static member type of raw type
221
				if (typeIsConsistent && !currentType.isStatic() && qualifiedType != null && qualifiedType.isRawType()) {
221
				if (typeIsConsistent && !currentType.isStatic()) {
222
					scope.problemReporter().rawMemberTypeCannotBeParameterized(
222
					ReferenceBinding actualEnclosing = currentType.enclosingType();
223
							this, scope.environment().createRawType((ReferenceBinding)currentType.erasure(), qualifiedType), argTypes);
223
					if (actualEnclosing != null && actualEnclosing.isRawType()) {
224
					typeIsConsistent = false;				
224
						scope.problemReporter().rawMemberTypeCannotBeParameterized(
225
				}
225
								this, scope.environment().createRawType((ReferenceBinding)currentType.erasure(), actualEnclosing), argTypes);
226
						typeIsConsistent = false;				
227
					}
228
				}				
226
				ParameterizedTypeBinding parameterizedType = scope.environment().createParameterizedType((ReferenceBinding)currentType.erasure(), argTypes, qualifiedType);
229
				ParameterizedTypeBinding parameterizedType = scope.environment().createParameterizedType((ReferenceBinding)currentType.erasure(), argTypes, qualifiedType);
227
				// check argument type compatibility
230
				// check argument type compatibility
228
				if (checkBounds) // otherwise will do it in Scope.connectTypeVariables() or generic method resolution
231
				if (checkBounds) // otherwise will do it in Scope.connectTypeVariables() or generic method resolution
Lines 247-254 Link Here
247
			}
250
			}
248
			if (isTypeUseDeprecated(qualifiedType, scope))
251
			if (isTypeUseDeprecated(qualifiedType, scope))
249
				reportDeprecatedType(qualifiedType, scope);		    
252
				reportDeprecatedType(qualifiedType, scope);		    
253
			this.resolvedType = qualifiedType;
250
		}
254
		}
251
		this.resolvedType = qualifiedType;
255
//		this.resolvedType = qualifiedType;
252
		// array type ?
256
		// array type ?
253
		if (this.dimensions > 0) {
257
		if (this.dimensions > 0) {
254
			if (dimensions > 255)
258
			if (dimensions > 255)
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (+224 lines)
Lines 37384-37387 Link Here
37384
		"Type mismatch: cannot convert from element type Object to Map.Entry<String,String>\n" + 
37384
		"Type mismatch: cannot convert from element type Object to Map.Entry<String,String>\n" + 
37385
		"----------\n");
37385
		"----------\n");
37386
}
37386
}
37387
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=183216
37388
public void test1125() {
37389
	this.runNegativeTest(
37390
		new String[] {
37391
			"X.java",
37392
			"class A {\n" + 
37393
			"    class B<T> {\n" + 
37394
			"        T t;\n" + 
37395
			"        T getValue() {\n" + 
37396
			"            return t;\n" + 
37397
			"        }\n" + 
37398
			"    }\n" + 
37399
			"}\n" + 
37400
			"\n" + 
37401
			"class C<T> extends A {\n" + 
37402
			"	Zork z;\n" +
37403
			"}\n" + 
37404
			"\n" + 
37405
			"public class X {\n" + 
37406
			"    static C.B<Double> c = new C().new B<Double>();\n" + 
37407
			"\n" + 
37408
			"    public static void main(String[] args) {\n" + 
37409
			"        C.B<String> temp = new C().new B<String>();\n" + 
37410
			"        String s = temp.getValue();\n" + 
37411
			"        System.out.println(s);\n" + 
37412
			"        foo(bar());\n" + 
37413
			"    }\n" + 
37414
			"\n" + 
37415
			"    static C.B<? extends Number> bar() {\n" + 
37416
			"        return new C().new B<Integer>();\n" + 
37417
			"    }\n" + 
37418
			"\n" + 
37419
			"    static void foo(C.B<?> arg) {\n" + 
37420
			"        Object o = arg.getValue();\n" + 
37421
			"        Double d = c.getValue();\n" + 
37422
			"        System.out.println(o);\n" + 
37423
			"        System.out.println(d);\n" + 
37424
			"    }\n" + 
37425
			"}\n", // =================
37426
		},
37427
		"----------\n" + 
37428
		"1. ERROR in X.java (at line 11)\n" + 
37429
		"	Zork z;\n" + 
37430
		"	^^^^\n" + 
37431
		"Zork cannot be resolved to a type\n" + 
37432
		"----------\n" + 
37433
		"2. WARNING in X.java (at line 15)\n" + 
37434
		"	static C.B<Double> c = new C().new B<Double>();\n" + 
37435
		"	                           ^\n" + 
37436
		"C is a raw type. References to generic type C<T> should be parameterized\n" + 
37437
		"----------\n" + 
37438
		"3. WARNING in X.java (at line 18)\n" + 
37439
		"	C.B<String> temp = new C().new B<String>();\n" + 
37440
		"	                       ^\n" + 
37441
		"C is a raw type. References to generic type C<T> should be parameterized\n" + 
37442
		"----------\n" + 
37443
		"4. WARNING in X.java (at line 25)\n" + 
37444
		"	return new C().new B<Integer>();\n" + 
37445
		"	           ^\n" + 
37446
		"C is a raw type. References to generic type C<T> should be parameterized\n" + 
37447
		"----------\n");
37448
}
37449
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=183216 - variation
37450
public void test1126() {
37451
	this.runConformTest(
37452
		new String[] {
37453
			"X.java",
37454
			"class A {\n" + 
37455
			"    class B<T> {\n" + 
37456
			"        T t;\n" + 
37457
			"        T getValue() {\n" + 
37458
			"            return t;\n" + 
37459
			"        }\n" + 
37460
			"    }\n" + 
37461
			"}\n" + 
37462
			"\n" + 
37463
			"public class X {\n" + 
37464
			"    static A.B<Double> c = new A().new B<Double>();\n" + 
37465
			"\n" + 
37466
			"    public static void main(String[] args) {\n" + 
37467
			"        A.B<String> temp = new A().new B<String>();\n" + 
37468
			"        String s = temp.getValue();\n" + 
37469
			"        System.out.print(s);\n" + 
37470
			"        foo(bar());\n" + 
37471
			"    }\n" + 
37472
			"\n" + 
37473
			"    static A.B<? extends Number> bar() {\n" + 
37474
			"        return new A().new B<Integer>();\n" + 
37475
			"    }\n" + 
37476
			"\n" + 
37477
			"    static void foo(A.B<?> arg) {\n" + 
37478
			"        Object o = arg.getValue();\n" + 
37479
			"        Double d = c.getValue();\n" + 
37480
			"        System.out.print(o);\n" + 
37481
			"        System.out.print(d);\n" + 
37482
			"    }\n" + 
37483
			"}\n", // =================
37484
		},
37485
		"nullnullnull");
37486
}
37487
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=183216 - variation
37488
public void test1127() {
37489
	this.runNegativeTest(
37490
		new String[] {
37491
			"X.java",
37492
			"class A<E> {\n" + 
37493
			"    class B<T> {\n" + 
37494
			"        T t;\n" + 
37495
			"        T getValue() {\n" + 
37496
			"            return t;\n" + 
37497
			"        }\n" + 
37498
			"    }\n" + 
37499
			"}\n" + 
37500
			"\n" + 
37501
			"class C<T> extends A<T> {\n" + 
37502
			"}\n" + 
37503
			"\n" + 
37504
			"public class X {\n" + 
37505
			"    static C.B<Double> c = new C().new B<Double>();\n" + 
37506
			"\n" + 
37507
			"    public static void main(String[] args) {\n" + 
37508
			"        C.B<String> temp = new C().new B<String>();\n" + 
37509
			"        String s = temp.getValue();\n" + 
37510
			"        System.out.println(s);\n" + 
37511
			"        foo(bar());\n" + 
37512
			"    }\n" + 
37513
			"\n" + 
37514
			"    static C.B<? extends Number> bar() {\n" + 
37515
			"        return new C().new B<Integer>();\n" + 
37516
			"    }\n" + 
37517
			"\n" + 
37518
			"    static void foo(C.B<?> arg) {\n" + 
37519
			"        Object o = arg.getValue();\n" + 
37520
			"        Double d = c.getValue();\n" + 
37521
			"        System.out.println(o);\n" + 
37522
			"        System.out.println(d);\n" + 
37523
			"    }\n" + 
37524
			"}\n", // =================
37525
		},
37526
		"----------\n" + 
37527
		"1. ERROR in X.java (at line 14)\n" + 
37528
		"	static C.B<Double> c = new C().new B<Double>();\n" + 
37529
		"	       ^^^\n" + 
37530
		"The member type A.B<Double> must be qualified with a parameterized type, since it is not static\n" + 
37531
		"----------\n" + 
37532
		"2. WARNING in X.java (at line 14)\n" + 
37533
		"	static C.B<Double> c = new C().new B<Double>();\n" + 
37534
		"	                           ^\n" + 
37535
		"C is a raw type. References to generic type C<T> should be parameterized\n" + 
37536
		"----------\n" + 
37537
		"3. ERROR in X.java (at line 14)\n" + 
37538
		"	static C.B<Double> c = new C().new B<Double>();\n" + 
37539
		"	                                   ^\n" + 
37540
		"The member type A.B<Double> must be qualified with a parameterized type, since it is not static\n" + 
37541
		"----------\n" + 
37542
		"4. ERROR in X.java (at line 17)\n" + 
37543
		"	C.B<String> temp = new C().new B<String>();\n" + 
37544
		"	^^^\n" + 
37545
		"The member type A.B<String> must be qualified with a parameterized type, since it is not static\n" + 
37546
		"----------\n" + 
37547
		"5. WARNING in X.java (at line 17)\n" + 
37548
		"	C.B<String> temp = new C().new B<String>();\n" + 
37549
		"	                       ^\n" + 
37550
		"C is a raw type. References to generic type C<T> should be parameterized\n" + 
37551
		"----------\n" + 
37552
		"6. ERROR in X.java (at line 17)\n" + 
37553
		"	C.B<String> temp = new C().new B<String>();\n" + 
37554
		"	                               ^\n" + 
37555
		"The member type A.B<String> must be qualified with a parameterized type, since it is not static\n" + 
37556
		"----------\n" + 
37557
		"7. ERROR in X.java (at line 23)\n" + 
37558
		"	static C.B<? extends Number> bar() {\n" + 
37559
		"	       ^^^\n" + 
37560
		"The member type A.B<? extends Number> must be qualified with a parameterized type, since it is not static\n" + 
37561
		"----------\n" + 
37562
		"8. WARNING in X.java (at line 24)\n" + 
37563
		"	return new C().new B<Integer>();\n" + 
37564
		"	           ^\n" + 
37565
		"C is a raw type. References to generic type C<T> should be parameterized\n" + 
37566
		"----------\n" + 
37567
		"9. ERROR in X.java (at line 24)\n" + 
37568
		"	return new C().new B<Integer>();\n" + 
37569
		"	                   ^\n" + 
37570
		"The member type A.B<Integer> must be qualified with a parameterized type, since it is not static\n" + 
37571
		"----------\n" + 
37572
		"10. ERROR in X.java (at line 27)\n" + 
37573
		"	static void foo(C.B<?> arg) {\n" + 
37574
		"	                ^^^\n" + 
37575
		"The member type A.B<?> must be qualified with a parameterized type, since it is not static\n" + 
37576
		"----------\n");
37577
}
37578
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=183216 - variation
37579
public void test1128() {
37580
	this.runNegativeTest(
37581
		new String[] {
37582
			"X.java",
37583
			"class A<T> {\n" + 
37584
			"	class Member<U> {}\n" + 
37585
			"}\n" + 
37586
			"\n" + 
37587
			"public class X extends A {\n" + 
37588
			"	void foo() {\n" + 
37589
			"		new Member<String>();\n" + 
37590
			"		new X().new Member<String>();\n" + 
37591
			"	}\n" + 
37592
			"}\n", // =================
37593
		},
37594
		"----------\n" + 
37595
		"1. WARNING in X.java (at line 5)\n" + 
37596
		"	public class X extends A {\n" + 
37597
		"	                       ^\n" + 
37598
		"A is a raw type. References to generic type A<T> should be parameterized\n" + 
37599
		"----------\n" + 
37600
		"2. ERROR in X.java (at line 7)\n" + 
37601
		"	new Member<String>();\n" + 
37602
		"	    ^^^^^^\n" + 
37603
		"The member type A.Member<String> must be qualified with a parameterized type, since it is not static\n" + 
37604
		"----------\n" + 
37605
		"3. ERROR in X.java (at line 8)\n" + 
37606
		"	new X().new Member<String>();\n" + 
37607
		"	            ^^^^^^\n" + 
37608
		"The member type A.Member<String> must be qualified with a parameterized type, since it is not static\n" + 
37609
		"----------\n");
37610
}
37387
}
37611
}

Return to bug 183216