public void bind(MethodScope scope, TypeBinding typeBinding, boolean used) { // record the resolved type into the type reference Binding existingVariable = scope.getBinding(this.name, Binding.VARIABLE, this, false /*do not resolve hidden field*/); if (existingVariable != null && existingVariable.isValidBinding()) { if (existingVariable instanceof LocalVariableBinding && this.hiddenVariableDepth == 0) { scope.problemReporter().redefineArgument(this); } else { boolean isSpecialArgument = false; if (existingVariable instanceof FieldBinding) { if (scope.isInsideConstructor()) { isSpecialArgument = true; // constructor argument } else { AbstractMethodDeclaration methodDecl = scope.referenceMethod(); if (methodDecl != null && CharOperation.prefixEquals(SET, methodDecl.selector)) { isSpecialArgument = true; // setter argument } } } scope.problemReporter().localVariableHiding(this, existingVariable, isSpecialArgument); } } if (this.binding == null) { this.binding = new LocalVariableBinding(this, typeBinding, this.modifiers, true); } else if (!this.binding.type.isValidBinding()) { AbstractMethodDeclaration methodDecl = scope.referenceMethod(); if (methodDecl != null) { MethodBinding methodBinding = methodDecl.binding; if (methodBinding != null) { methodBinding.tagBits |= TagBits.HasUnresolvedArguments; } } } scope.addLocalVariable(this.binding); resolveAnnotations(scope, this.annotations, this.binding); // true stand for argument instead of just local this.binding.declaration = this; this.binding.useFlag = used ? LocalVariableBinding.USED : LocalVariableBinding.UNUSED; }
public TypeBinding resolveForCatch(BlockScope scope) { // resolution on an argument of a catch clause // provide the scope with a side effect : insertion of a LOCAL // that represents the argument. The type must be from JavaThrowable TypeBinding exceptionType = this.type.resolveType(scope, true /* check bounds*/); boolean hasError; if (exceptionType == null) { hasError = true; } else { hasError = false; switch (exceptionType.kind()) { case Binding.PARAMETERIZED_TYPE: if (exceptionType.isBoundParameterizedType()) { hasError = true; scope.problemReporter().invalidParameterizedExceptionType(exceptionType, this); // fall thru to create the variable - avoids additional errors because the variable is // missing } break; case Binding.TYPE_PARAMETER: scope.problemReporter().invalidTypeVariableAsException(exceptionType, this); hasError = true; // fall thru to create the variable - avoids additional errors because the variable is // missing break; } if (exceptionType.findSuperTypeOriginatingFrom(TypeIds.T_JavaLangThrowable, true) == null && exceptionType.isValidBinding()) { scope.problemReporter().cannotThrowType(this.type, exceptionType); hasError = true; // fall thru to create the variable - avoids additional errors because the variable is // missing } } Binding existingVariable = scope.getBinding(this.name, Binding.VARIABLE, this, false /*do not resolve hidden field*/); if (existingVariable != null && existingVariable.isValidBinding()) { if (existingVariable instanceof LocalVariableBinding && this.hiddenVariableDepth == 0) { scope.problemReporter().redefineArgument(this); } else { scope.problemReporter().localVariableHiding(this, existingVariable, false); } } if ((this.type.bits & ASTNode.IsUnionType) != 0) { this.binding = new CatchParameterBinding( this, exceptionType, this.modifiers | ClassFileConstants.AccFinal, false); // argument decl, but local var (where isArgument = false) this.binding.tagBits |= TagBits.MultiCatchParameter; } else { this.binding = new CatchParameterBinding( this, exceptionType, this.modifiers, false); // argument decl, but local var (where isArgument = false) } resolveAnnotations(scope, this.annotations, this.binding); scope.addLocalVariable(this.binding); this.binding.setConstant(Constant.NotAConstant); if (hasError) return null; return exceptionType; }