Added default preferences for outline options
[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.*;
15
16 public class Argument extends LocalDeclaration {
17         
18         public Argument(char[] name, long posNom, TypeReference tr, int modifiers) {
19
20                 super(null, name, (int) (posNom >>> 32), (int) posNom);
21                 this.modifiers = modifiers;
22                 type = tr;
23                 this.bits |= IsLocalDeclarationReachableMASK;
24         }
25
26         public void bind(MethodScope scope, TypeBinding typeBinding, boolean used) {
27
28                 if (this.type != null)
29                         this.type.binding = typeBinding;
30                 // record the resolved type into the type reference
31                 int modifierFlag = this.modifiers;
32                 if ((this.binding = scope.duplicateName(this.name)) != null) {
33                         //the name already exist....may carry on with the first binding ....
34                         scope.problemReporter().redefineArgument(this);
35                 } else {
36                         scope.addLocalVariable(
37                                 this.binding =
38                                         new LocalVariableBinding(this, typeBinding, modifierFlag, true));
39                         //true stand for argument instead of just local
40                         if (typeBinding != null && isTypeUseDeprecated(typeBinding, scope))
41                                 scope.problemReporter().deprecatedType(typeBinding, this.type);
42                         this.binding.declaration = this;
43                         this.binding.used = used;
44                 }
45         }
46
47         public TypeBinding resolveForCatch(BlockScope scope) {
48
49                 // resolution on an argument of a catch clause
50                 // provide the scope with a side effect : insertion of a LOCAL
51                 // that represents the argument. The type must be from JavaThrowable
52
53                 TypeBinding tb = type.resolveTypeExpecting(scope, scope.getJavaLangThrowable());
54                 if (tb == null)
55                         return null;
56                 if ((binding = scope.duplicateName(name)) != null) {
57                         // the name already exists....may carry on with the first binding ....
58                         scope.problemReporter().redefineArgument(this);
59                         return null;
60                 }
61                 binding = new LocalVariableBinding(this, tb, modifiers, false); // argument decl, but local var  (i.e. isArgument = false)
62                 scope.addLocalVariable(binding);
63                 binding.constant = NotAConstant;
64                 return tb;
65         }
66
67         public String toString(int tab) {
68
69                 String s = ""; //$NON-NLS-1$
70                 if (modifiers != AccDefault) {
71                         s += modifiersString(modifiers);
72                 }
73                 if (type == null) {
74                         s += "<no type> "; //$NON-NLS-1$
75                 } else {
76                         s += type.toString(tab) + " "; //$NON-NLS-1$
77                 }
78                 s += new String(name);
79                 return s;
80         }
81
82         public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope scope) {
83                 
84                 if (visitor.visit(this, scope)) {
85                         if (type != null)
86                                 type.traverse(visitor, scope);
87                         if (initialization != null)
88                                 initialization.traverse(visitor, scope);
89                 }
90                 visitor.endVisit(this, scope);
91         }
92 }