1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.compiler.ast;
13 import org.eclipse.jdt.core.compiler.CharOperation;
14 import org.eclipse.jdt.internal.compiler.ASTVisitor;
15 import org.eclipse.jdt.internal.compiler.lookup.*;
17 public class Argument extends LocalDeclaration {
19 // prefix for setter method (to recognize special hiding argument)
20 private final static char[] SET = "set".toCharArray(); //$NON-NLS-1$
22 public Argument(char[] name, long posNom, TypeReference tr, int modifiers) {
24 super(name, (int) (posNom >>> 32), (int) posNom);
25 this.declarationSourceEnd = (int) posNom;
26 this.modifiers = modifiers;
28 this.bits |= IsLocalDeclarationReachableMASK;
31 public void bind(MethodScope scope, TypeBinding typeBinding, boolean used) {
33 if (this.type != null)
34 this.type.resolvedType = typeBinding;
35 // record the resolved type into the type reference
36 int modifierFlag = this.modifiers;
38 Binding existingVariable = scope.getBinding(name, BindingIds.VARIABLE, this, false /*do not resolve hidden field*/);
39 if (existingVariable != null && existingVariable.isValidBinding()){
40 if (existingVariable instanceof LocalVariableBinding && this.hiddenVariableDepth == 0) {
41 scope.problemReporter().redefineArgument(this);
44 boolean isSpecialArgument = false;
45 if (existingVariable instanceof FieldBinding) {
46 if (scope.isInsideConstructor()) {
47 isSpecialArgument = true; // constructor argument
49 AbstractMethodDeclaration methodDecl = scope.referenceMethod();
50 if (methodDecl != null && CharOperation.prefixEquals(SET, methodDecl.selector)) {
51 isSpecialArgument = true; // setter argument
55 scope.problemReporter().localVariableHiding(this, existingVariable, isSpecialArgument);
58 scope.addLocalVariable(
60 new LocalVariableBinding(this, typeBinding, modifierFlag, true));
61 //true stand for argument instead of just local
62 if (typeBinding != null && isTypeUseDeprecated(typeBinding, scope))
63 scope.problemReporter().deprecatedType(typeBinding, this.type);
64 this.binding.declaration = this;
65 this.binding.useFlag = used ? LocalVariableBinding.USED : LocalVariableBinding.UNUSED;
68 public StringBuffer print(int indent, StringBuffer output) {
70 printIndent(indent, output);
71 printModifiers(this.modifiers, output);
73 output.append("<no type> "); //$NON-NLS-1$
75 type.print(0, output).append(' ');
77 return output.append(this.name);
80 public StringBuffer printStatement(int indent, StringBuffer output) {
82 return print(indent, output).append(';');
85 public TypeBinding resolveForCatch(BlockScope scope) {
87 // resolution on an argument of a catch clause
88 // provide the scope with a side effect : insertion of a LOCAL
89 // that represents the argument. The type must be from JavaThrowable
91 TypeBinding tb = type.resolveTypeExpecting(scope, scope.getJavaLangThrowable());
95 Binding existingVariable = scope.getBinding(name, BindingIds.VARIABLE, this, false /*do not resolve hidden field*/);
96 if (existingVariable != null && existingVariable.isValidBinding()){
97 if (existingVariable instanceof LocalVariableBinding && this.hiddenVariableDepth == 0) {
98 scope.problemReporter().redefineArgument(this);
101 scope.problemReporter().localVariableHiding(this, existingVariable, false);
104 binding = new LocalVariableBinding(this, tb, modifiers, false); // argument decl, but local var (where isArgument = false)
105 scope.addLocalVariable(binding);
106 binding.constant = NotAConstant;
110 public void traverse(ASTVisitor visitor, BlockScope scope) {
112 if (visitor.visit(this, scope)) {
114 type.traverse(visitor, scope);
115 if (initialization != null)
116 initialization.traverse(visitor, scope);
118 visitor.endVisit(this, scope);