public TypeBinding resolveType(BlockScope scope) { // field and/or local are done before type lookups // the only available value for the restrictiveFlag BEFORE // the TC is Flag_Type Flag_LocalField and Flag_TypeLocalField this.actualReceiverType = scope.enclosingReceiverType(); this.constant = Constant.NotAConstant; if (( /*this.codegenBinding =*/ this.binding = scope.getBinding( this.tokens, this.bits & ASTNode.RestrictiveFlagMASK, this, true /*resolve*/)) .isValidBinding()) { switch (this.bits & ASTNode.RestrictiveFlagMASK) { case Binding.VARIABLE: // ============only variable=========== case Binding.TYPE | Binding.VARIABLE: if (this.binding instanceof LocalVariableBinding) { this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits this.bits |= Binding.LOCAL; return this.resolvedType = getOtherFieldBindings(scope); } if (this.binding instanceof FieldBinding) { FieldBinding fieldBinding = (FieldBinding) this.binding; MethodScope methodScope = scope.methodScope(); // check for forward references if (this.indexOfFirstFieldBinding == 1 && methodScope.enclosingSourceType() == fieldBinding.original().declaringClass && methodScope.lastVisibleFieldID >= 0 && fieldBinding.id >= methodScope.lastVisibleFieldID && (!fieldBinding.isStatic() || methodScope.isStatic)) { scope.problemReporter().forwardReference(this, 0, methodScope.enclosingSourceType()); } this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits this.bits |= Binding.FIELD; // // check for deprecated receiver type // // deprecation check for receiver type if not first token // if (indexOfFirstFieldBinding > 1) { // if (isTypeUseDeprecated(this.actualReceiverType, scope)) // scope.problemReporter().deprecatedType(this.actualReceiverType, this); // } return this.resolvedType = getOtherFieldBindings(scope); } // thus it was a type this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits this.bits |= Binding.TYPE; case Binding.TYPE: // =============only type ============== TypeBinding type = (TypeBinding) this.binding; // if (isTypeUseDeprecated(type, scope)) // scope.problemReporter().deprecatedType(type, this); return this.resolvedType = type; } } // ========error cases=============== return this.resolvedType = this.reportError(scope); }
public TypeBinding resolveType(BlockScope scope) { // Propagate the type checking to the arguments, and check if the constructor is defined. constant = Constant.NotAConstant; if (this.member != null) { this.resolvedType = this.member.resolveForAllocation(scope, this); if (this.resolvedType != null && !this.resolvedType.isValidBinding()) { scope.problemReporter().invalidType(this, this.resolvedType); } } else if (this.type == null) { // initialization of an enum constant this.resolvedType = scope.enclosingReceiverType(); } else { this.resolvedType = this.type.resolveType(scope, true /* check bounds*/); } // will check for null after args are resolved // buffering the arguments' types boolean argsContainCast = false; TypeBinding[] argumentTypes = Binding.NO_PARAMETERS; if (arguments != null) { boolean argHasError = false; int length = arguments.length; argumentTypes = new TypeBinding[length]; for (int i = 0; i < length; i++) { Expression argument = this.arguments[i]; if ((argumentTypes[i] = argument.resolveType(scope)) == null) { argHasError = true; argumentTypes[i] = TypeBinding.UNKNOWN; } } if (argHasError) { // if (this.resolvedType instanceof ReferenceBinding) { // // 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 ? this.resolvedType : argumentTypes[i]; // // replace args with errors with receiver // this.binding = scope.findMethod((ReferenceBinding) this.resolvedType, // TypeConstants.INIT, pseudoArgs, this); // } // return this.resolvedType; } } if (this.resolvedType == null || this.resolvedType.isAnyType() || this.resolvedType instanceof ProblemReferenceBinding) { this.binding = new ProblemMethodBinding( TypeConstants.INIT, Binding.NO_PARAMETERS, ProblemReasons.NotFound); this.resolvedType = TypeBinding.UNKNOWN; return this.resolvedType; } if (!this.resolvedType.isValidBinding()) return null; if (this.resolvedType instanceof ReferenceBinding) { ReferenceBinding allocationType = (ReferenceBinding) this.resolvedType; if (!(binding = scope.getConstructor(allocationType, argumentTypes, this)).isValidBinding()) { if (binding.declaringClass == null) binding.declaringClass = allocationType; scope.problemReporter().invalidConstructor(this, binding); return this.resolvedType; } if (argumentTypes.length != binding.parameters.length) scope.problemReporter().wrongNumberOfArguments(this, binding); if (isMethodUseDeprecated(binding, scope, true)) scope.problemReporter().deprecatedMethod(binding, this); checkInvocationArguments( scope, null, allocationType, this.binding, this.arguments, argumentTypes, argsContainCast, this); } return this.resolvedType; }