1 11 package org.eclipse.jdt.internal.compiler.ast; 12 13 import org.eclipse.jdt.core.compiler.CharOperation; 14 import org.eclipse.jdt.internal.compiler.ASTVisitor; 15 import org.eclipse.jdt.internal.compiler.impl.Constant; 16 import org.eclipse.jdt.internal.compiler.lookup.*; 17 18 public class Argument extends LocalDeclaration { 19 20 private final static char[] SET = "set".toCharArray(); 23 public Argument(char[] name, long posNom, TypeReference tr, int modifiers) { 24 25 super(name, (int) (posNom >>> 32), (int) posNom); 26 this.declarationSourceEnd = (int) posNom; 27 this.modifiers = modifiers; 28 type = tr; 29 this.bits |= IsLocalDeclarationReachable; 30 } 31 32 public void bind(MethodScope scope, TypeBinding typeBinding, boolean used) { 33 34 Binding existingVariable = scope.getBinding(name, Binding.VARIABLE, this, false ); 36 if (existingVariable != null && existingVariable.isValidBinding()){ 37 if (existingVariable instanceof LocalVariableBinding && this.hiddenVariableDepth == 0) { 38 scope.problemReporter().redefineArgument(this); 39 } else { 40 boolean isSpecialArgument = false; 41 if (existingVariable instanceof FieldBinding) { 42 if (scope.isInsideConstructor()) { 43 isSpecialArgument = true; } else { 45 AbstractMethodDeclaration methodDecl = scope.referenceMethod(); 46 if (methodDecl != null && CharOperation.prefixEquals(SET, methodDecl.selector)) { 47 isSpecialArgument = true; } 49 } 50 } 51 scope.problemReporter().localVariableHiding(this, existingVariable, isSpecialArgument); 52 } 53 } 54 55 if (this.binding == null) { 56 this.binding = new LocalVariableBinding(this, typeBinding, this.modifiers, true); 57 } 58 scope.addLocalVariable(this.binding); 59 resolveAnnotations(scope, this.annotations, this.binding); 60 this.binding.declaration = this; 62 this.binding.useFlag = used ? LocalVariableBinding.USED : LocalVariableBinding.UNUSED; 63 } 64 65 68 public int getKind() { 69 return PARAMETER; 70 } 71 72 public boolean isVarArgs() { 73 return this.type != null && (this.type.bits & IsVarArgs) != 0; 74 } 75 76 public StringBuffer print(int indent, StringBuffer output) { 77 78 printIndent(indent, output); 79 printModifiers(this.modifiers, output); 80 if (this.annotations != null) printAnnotations(this.annotations, output); 81 82 if (type == null) { 83 output.append("<no type> "); } else { 85 type.print(0, output).append(' '); 86 } 87 return output.append(this.name); 88 } 89 90 public StringBuffer printStatement(int indent, StringBuffer output) { 91 92 return print(indent, output).append(';'); 93 } 94 95 public TypeBinding resolveForCatch(BlockScope scope) { 96 97 101 TypeBinding exceptionType = this.type.resolveType(scope, true ); 102 if (exceptionType == null) return null; 103 boolean hasError = false; 104 if (exceptionType.isBoundParameterizedType()) { 105 scope.problemReporter().invalidParameterizedExceptionType(exceptionType, this); 106 hasError = true; 107 } 109 if (exceptionType.isTypeVariable()) { 110 scope.problemReporter().invalidTypeVariableAsException(exceptionType, this); 111 hasError = true; 112 } 114 if (exceptionType.isArrayType() && ((ArrayBinding) exceptionType).leafComponentType == TypeBinding.VOID) { 115 scope.problemReporter().variableTypeCannotBeVoidArray(this); 116 hasError = true; 117 } 119 if (exceptionType.findSuperTypeErasingTo(TypeIds.T_JavaLangThrowable, true) == null) { 120 scope.problemReporter().cannotThrowType(this.type, exceptionType); 121 hasError = true; 122 } 124 125 Binding existingVariable = scope.getBinding(name, Binding.VARIABLE, this, false ); 126 if (existingVariable != null && existingVariable.isValidBinding()){ 127 if (existingVariable instanceof LocalVariableBinding && this.hiddenVariableDepth == 0) { 128 scope.problemReporter().redefineArgument(this); 129 } else { 130 scope.problemReporter().localVariableHiding(this, existingVariable, false); 131 } 132 } 133 134 this.binding = new LocalVariableBinding(this, exceptionType, modifiers, false); resolveAnnotations(scope, this.annotations, this.binding); 136 137 scope.addLocalVariable(binding); 138 binding.setConstant(Constant.NotAConstant); 139 if (hasError) return null; 140 return exceptionType; 141 } 142 143 public void traverse(ASTVisitor visitor, BlockScope scope) { 144 145 if (visitor.visit(this, scope)) { 146 if (this.annotations != null) { 147 int annotationsLength = this.annotations.length; 148 for (int i = 0; i < annotationsLength; i++) 149 this.annotations[i].traverse(visitor, scope); 150 } 151 if (type != null) 152 type.traverse(visitor, scope); 153 } 154 visitor.endVisit(this, scope); 155 } 156 public void traverse(ASTVisitor visitor, ClassScope scope) { 157 158 if (visitor.visit(this, scope)) { 159 if (this.annotations != null) { 160 int annotationsLength = this.annotations.length; 161 for (int i = 0; i < annotationsLength; i++) 162 this.annotations[i].traverse(visitor, scope); 163 } 164 if (type != null) 165 type.traverse(visitor, scope); 166 } 167 visitor.endVisit(this, scope); 168 } 169 } 170 | Popular Tags |