1 /*******************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v0.5
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v05.html
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
14 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
15 import net.sourceforge.phpdt.internal.compiler.lookup.LocalVariableBinding;
16 import net.sourceforge.phpdt.internal.compiler.lookup.MethodScope;
17 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
19 public class Argument extends LocalDeclaration {
21 public Argument(char[] name, long posNom, TypeReference tr, int modifiers) {
23 super(null, name, (int) (posNom >>> 32), (int) posNom);
24 this.modifiers = modifiers;
26 this.bits |= IsLocalDeclarationReachableMASK;
29 public void bind(MethodScope scope, TypeBinding typeBinding, boolean used) {
31 if (this.type != null)
32 this.type.binding = typeBinding;
33 // record the resolved type into the type reference
34 int modifierFlag = this.modifiers;
35 if ((this.binding = scope.duplicateName(this.name)) != null) {
36 //the name already exist....may carry on with the first binding ....
37 scope.problemReporter().redefineArgument(this);
39 scope.addLocalVariable(
41 new LocalVariableBinding(this, typeBinding, modifierFlag, true));
42 //true stand for argument instead of just local
43 if (typeBinding != null && isTypeUseDeprecated(typeBinding, scope))
44 scope.problemReporter().deprecatedType(typeBinding, this.type);
45 this.binding.declaration = this;
46 this.binding.used = used;
50 public TypeBinding resolveForCatch(BlockScope scope) {
52 // resolution on an argument of a catch clause
53 // provide the scope with a side effect : insertion of a LOCAL
54 // that represents the argument. The type must be from JavaThrowable
56 TypeBinding tb = type.resolveTypeExpecting(scope, scope.getJavaLangThrowable());
59 if ((binding = scope.duplicateName(name)) != null) {
60 // the name already exists....may carry on with the first binding ....
61 scope.problemReporter().redefineArgument(this);
64 binding = new LocalVariableBinding(this, tb, modifiers, false); // argument decl, but local var (i.e. isArgument = false)
65 scope.addLocalVariable(binding);
66 binding.constant = NotAConstant;
70 public String toString(int tab) {
72 String s = ""; //$NON-NLS-1$
73 if (modifiers != AccDefault) {
74 s += modifiersString(modifiers);
77 s += "<no type> "; //$NON-NLS-1$
79 s += type.toString(tab) + " "; //$NON-NLS-1$
81 s += new String(name);
85 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope scope) {
87 if (visitor.visit(this, scope)) {
89 type.traverse(visitor, scope);
90 if (initialization != null)
91 initialization.traverse(visitor, scope);
93 visitor.endVisit(this, scope);