improved code formatter
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / internal / compiler / ast / Argument.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpeclipse.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.declarationSourceEnd = (int) posNom;
25                 this.modifiers = modifiers;
26                 type = tr;
27                 this.bits |= IsLocalDeclarationReachableMASK;
28         }
29
30         public void bind(MethodScope scope, TypeBinding typeBinding, boolean used) {
31
32                 if (this.type != null)
33                         this.type.resolvedType = typeBinding;
34                 // record the resolved type into the type reference
35                 int modifierFlag = this.modifiers;
36                 if ((this.binding = scope.duplicateName(this.name)) != null) {
37                         //the name already exist....may carry on with the first binding ....
38                         scope.problemReporter().redefineArgument(this);
39                 } else {
40                         scope.addLocalVariable(
41                                 this.binding =
42                                         new LocalVariableBinding(this, typeBinding, modifierFlag, true));
43                         //true stand for argument instead of just local
44                         if (typeBinding != null && isTypeUseDeprecated(typeBinding, scope))
45                                 scope.problemReporter().deprecatedType(typeBinding, this.type);
46                         this.binding.declaration = this;
47                         this.binding.useFlag = used ? LocalVariableBinding.USED : LocalVariableBinding.UNUSED;
48                 }
49         }
50
51         public TypeBinding resolveForCatch(BlockScope scope) {
52
53                 // resolution on an argument of a catch clause
54                 // provide the scope with a side effect : insertion of a LOCAL
55                 // that represents the argument. The type must be from JavaThrowable
56
57                 TypeBinding tb = type.resolveTypeExpecting(scope, scope.getJavaLangThrowable());
58                 if (tb == null)
59                         return null;
60                 if ((binding = scope.duplicateName(name)) != null) {
61                         // the name already exists....may carry on with the first binding ....
62                         scope.problemReporter().redefineArgument(this);
63                         return null;
64                 }
65                 binding = new LocalVariableBinding(this, tb, modifiers, false); // argument decl, but local var  (where isArgument = false)
66                 scope.addLocalVariable(binding);
67                 binding.constant = NotAConstant;
68                 return tb;
69         }
70
71         public String toString(int tab) {
72
73                 String s = ""; //$NON-NLS-1$
74                 if (modifiers != AccDefault) {
75                         s += modifiersString(modifiers);
76                 }
77                 if (type == null) {
78                         s += "<no type> "; //$NON-NLS-1$
79                 } else {
80                         s += type.toString(tab) + " "; //$NON-NLS-1$
81                 }
82                 s += new String(name);
83                 return s;
84         }
85
86         public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope scope) {
87                 
88                 if (visitor.visit(this, scope)) {
89                         if (type != null)
90                                 type.traverse(visitor, scope);
91                         if (initialization != null)
92                                 initialization.traverse(visitor, scope);
93                 }
94                 visitor.endVisit(this, scope);
95         }
96 }