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) { |