changed name of Scanner tokens to names similar in the JDT
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / Argument.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
12
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;
18
19 public class Argument extends LocalDeclaration {
20         
21         public Argument(char[] name, long posNom, TypeReference tr, int modifiers) {
22
23                 super(null, name, (int) (posNom >>> 32), (int) posNom);
24                 this.modifiers = modifiers;
25                 type = tr;
26                 this.bits |= IsLocalDeclarationReachableMASK;
27         }
28
29         public void bind(MethodScope scope, TypeBinding typeBinding, boolean used) {
30
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);
38                 } else {
39                         scope.addLocalVariable(
40                                 this.binding =
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;
47                 }
48         }
49
50         public TypeBinding resolveForCatch(BlockScope scope) {
51
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
55
56                 TypeBinding tb = type.resolveTypeExpecting(scope, scope.getJavaLangThrowable());
57                 if (tb == null)
58                         return null;
59                 if ((binding = scope.duplicateName(name)) != null) {
60                         // the name already exists....may carry on with the first binding ....
61                         scope.problemReporter().redefineArgument(this);
62                         return null;
63                 }
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;
67                 return tb;
68         }
69
70         public String toString(int tab) {
71
72                 String s = ""; //$NON-NLS-1$
73                 if (modifiers != AccDefault) {
74                         s += modifiersString(modifiers);
75                 }
76                 if (type == null) {
77                         s += "<no type> "; //$NON-NLS-1$
78                 } else {
79                         s += type.toString(tab) + " "; //$NON-NLS-1$
80                 }
81                 s += new String(name);
82                 return s;
83         }
84
85         public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope scope) {
86                 
87                 if (visitor.visit(this, scope)) {
88                         if (type != null)
89                                 type.traverse(visitor, scope);
90                         if (initialization != null)
91                                 initialization.traverse(visitor, scope);
92                 }
93                 visitor.endVisit(this, scope);
94         }
95 }