// the return type should be void for a constructor.
// the test is made into getConstructor
// mark the fact that we are in a constructor call.....
// unmark at all returns
MethodScope methodScope = scope.methodScope();
try {
AbstractMethodDeclaration methodDeclaration = methodScope.referenceMethod();
if (methodDeclaration == null
|| !methodDeclaration.isConstructor()
|| ((ConstructorDeclaration) methodDeclaration).constructorCall != this) {
scope.problemReporter().invalidExplicitConstructorCall(this);
// fault-tolerance
if (this.qualification != null) {
this.qualification.resolveType(scope);
}
if (this.typeArguments != null) {
for (int i = 0, max = this.typeArguments.length; i < max; i++) {
this.typeArguments[i].resolveType(scope, true /* check bounds*/);
}
}
if (this.arguments != null) {
for (int i = 0, max = this.arguments.length; i < max; i++) {
this.arguments[i].resolveType(scope);
}
}
return;
}
methodScope.isConstructorCall = true;
ReferenceBinding receiverType = scope.enclosingReceiverType();
boolean rcvHasError = false;
if (this.accessMode != ExplicitConstructorCall.This) {
receiverType = receiverType.superclass();
TypeReference superclassRef = scope.referenceType().superclass;
if (superclassRef != null && superclassRef.resolvedType != null && !superclassRef.resolvedType.isValidBinding()) {
rcvHasError = true;
}
}
if (receiverType != null) {
// prevent (explicit) super constructor invocation from within enum
if (this.accessMode == ExplicitConstructorCall.Super && receiverType.erasure().id == TypeIds.T_JavaLangEnum) {
scope.problemReporter().cannotInvokeSuperConstructorInEnum(this, methodScope.referenceMethod().binding);
}
// qualification should be from the type of the enclosingType
if (this.qualification != null) {
if (this.accessMode != ExplicitConstructorCall.Super) {
scope.problemReporter().unnecessaryEnclosingInstanceSpecification(
this.qualification,
receiverType);
}
if (!rcvHasError) {
ReferenceBinding enclosingType = receiverType.enclosingType();
if (enclosingType == null) {
scope.problemReporter().unnecessaryEnclosingInstanceSpecification(this.qualification, receiverType);
this.bits |= ASTNode.DiscardEnclosingInstance;
} else {
TypeBinding qTb = this.qualification.resolveTypeExpecting(scope, enclosingType);
this.qualification.computeConversion(scope, qTb, qTb);
}
}
}
}
// resolve type arguments (for generic constructor call)
long sourceLevel = scope.compilerOptions().sourceLevel;
if (this.typeArguments != null) {
boolean argHasError = sourceLevel < ClassFileConstants.JDK1_5;
int length = this.typeArguments.length;
this.genericTypeArguments = new TypeBinding[length];
for (int i = 0; i < length; i++) {
TypeReference typeReference = this.typeArguments[i];
if ((this.genericTypeArguments[i] = typeReference.resolveType(scope, true /* check bounds*/)) == null) {
argHasError = true;
}
if (argHasError && typeReference instanceof Wildcard) {
scope.problemReporter().illegalUsageOfWildcard(typeReference);
}
}
if (argHasError) {
if (this.arguments != null) { // still attempt to resolve arguments
for (int i = 0, max = this.arguments.length; i < max; i++) {
this.arguments[i].resolveType(scope);
}
}
return;
}
}
// arguments buffering for the method lookup
TypeBinding[] argumentTypes = Binding.NO_PARAMETERS;
boolean argsContainCast = false;
if (this.arguments != null) {
boolean argHasError = false; // typeChecks all arguments
int length = this.arguments.length;
argumentTypes = new TypeBinding[length];
for (int i = 0; i < length; i++) {
Expression argument = this.arguments[i];
if (argument instanceof CastExpression) {
argument.bits |= ASTNode.DisableUnnecessaryCastCheck; // will check later on
argsContainCast = true;
}
argument.setExpressionContext(INVOCATION_CONTEXT);
if ((argumentTypes[i] = argument.resolveType(scope)) == null) {
argHasError = true;
}
if (sourceLevel >= ClassFileConstants.JDK1_8 && argument.isPolyExpression()) {
if (this.innerInferenceHelper == null)
this.innerInferenceHelper = new InnerInferenceHelper();
}
}
if (argHasError) {
if (receiverType == null) {
return;
}
// record a best guess, for clients who need hint about possible contructor match
TypeBinding[] pseudoArgs = new TypeBinding[length];
for (int i = length; --i >= 0;) {
pseudoArgs[i] = argumentTypes[i] == null ? TypeBinding.NULL : argumentTypes[i]; // replace args with errors with null type
}
this.binding = scope.findMethod(receiverType, TypeConstants.INIT, pseudoArgs, this, false);
if (this.binding != null && !this.binding.isValidBinding()) {
MethodBinding closestMatch = ((ProblemMethodBinding)this.binding).closestMatch;
// record the closest match, for clients who may still need hint about possible method match
if (closestMatch != null) {
if (closestMatch.original().typeVariables != Binding.NO_TYPE_VARIABLES) { // generic method
// shouldn't return generic method outside its context, rather convert it to raw method (175409)
closestMatch = scope.environment().createParameterizedGenericMethod(closestMatch.original(), (RawTypeBinding)null);
}
this.binding = closestMatch;
MethodBinding closestMatchOriginal = closestMatch.original();
if (closestMatchOriginal.isOrEnclosedByPrivateType() && !scope.isDefinedInMethod(closestMatchOriginal)) {
// ignore cases where method is used from within inside itself (e.g. direct recursions)
closestMatchOriginal.modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
}
}
}
return;
}
} else if (receiverType.erasure().id == TypeIds.T_JavaLangEnum) {
// TODO (philippe) get rid of once well-known binding is available
argumentTypes = new TypeBinding[] { scope.getJavaLangString(), TypeBinding.INT };
}
if (receiverType == null) {
return;
}
this.binding = findConstructorBinding(scope, this, receiverType, argumentTypes);
if (this.binding.isValidBinding()) {
if ((this.binding.tagBits & TagBits.HasMissingType) != 0) {
if (!methodScope.enclosingSourceType().isAnonymousType()) {
scope.problemReporter().missingTypeInConstructor(this, this.binding);
}
}
if (isMethodUseDeprecated(this.binding, scope, this.accessMode != ExplicitConstructorCall.ImplicitSuper)) {
scope.problemReporter().deprecatedMethod(this.binding, this);