Change Eclipse-LazyStart: true to Bundle-ActivationPolicy: lazy (upgrade to The Equin...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / 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.phpdt.internal.compiler.ast;
12
13 import net.sourceforge.phpdt.internal.compiler.ASTVisitor;
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                         // ....
39                         scope.problemReporter().redefineArgument(this);
40                 } else {
41                         scope.addLocalVariable(this.binding = new LocalVariableBinding(
42                                         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
48                                         : LocalVariableBinding.UNUSED;
49                 }
50         }
51
52         public TypeBinding resolveForCatch(BlockScope scope) {
53
54                 // resolution on an argument of a catch clause
55                 // provide the scope with a side effect : insertion of a LOCAL
56                 // that represents the argument. The type must be from JavaThrowable
57
58                 TypeBinding tb = type.resolveTypeExpecting(scope, scope
59                                 .getJavaLangThrowable());
60                 if (tb == null)
61                         return null;
62                 if ((binding = scope.duplicateName(name)) != null) {
63                         // the name already exists....may carry on with the first binding
64                         // ....
65                         scope.problemReporter().redefineArgument(this);
66                         return null;
67                 }
68                 binding = new LocalVariableBinding(this, tb, modifiers, false); // argument
69                                                                                                                                                 // decl,
70                                                                                                                                                 // but
71                                                                                                                                                 // local
72                                                                                                                                                 // var
73                                                                                                                                                 // (where
74                                                                                                                                                 // isArgument
75                                                                                                                                                 // =
76                                                                                                                                                 // false)
77                 scope.addLocalVariable(binding);
78                 binding.constant = NotAConstant;
79                 return tb;
80         }
81
82         public String toString(int tab) {
83
84                 String s = ""; //$NON-NLS-1$
85                 if (modifiers != AccDefault) {
86                         s += modifiersString(modifiers);
87                 }
88                 if (type == null) {
89                         s += "<no type> "; //$NON-NLS-1$
90                 } else {
91                         s += type.toString(tab) + " "; //$NON-NLS-1$
92                 }
93                 s += new String(name);
94                 return s;
95         }
96
97         public void traverse(ASTVisitor visitor, BlockScope scope) {
98
99                 if (visitor.visit(this, scope)) {
100                         if (type != null)
101                                 type.traverse(visitor, scope);
102                         if (initialization != null)
103                                 initialization.traverse(visitor, scope);
104                 }
105                 visitor.endVisit(this, scope);
106         }
107 }