Makefile fixup
[org.ibex.tool.git] / repo / org.ibex.tool / src / org / eclipse / jdt / internal / compiler / ast / Argument.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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 org.eclipse.jdt.internal.compiler.ast;
12
13 import org.eclipse.jdt.core.compiler.CharOperation;
14 import org.eclipse.jdt.internal.compiler.ASTVisitor;
15 import org.eclipse.jdt.internal.compiler.lookup.*;
16
17 public class Argument extends LocalDeclaration {
18         
19         // prefix for setter method (to recognize special hiding argument)
20         private final static char[] SET = "set".toCharArray(); //$NON-NLS-1$
21
22         public Argument(char[] name, long posNom, TypeReference tr, int modifiers) {
23
24                 super(name, (int) (posNom >>> 32), (int) posNom);
25                 this.declarationSourceEnd = (int) posNom;
26                 this.modifiers = modifiers;
27                 type = tr;
28                 this.bits |= IsLocalDeclarationReachableMASK;
29         }
30
31         public void bind(MethodScope scope, TypeBinding typeBinding, boolean used) {
32
33                 if (this.type != null)
34                         this.type.resolvedType = typeBinding;
35                 // record the resolved type into the type reference
36                 int modifierFlag = this.modifiers;
37
38                 Binding existingVariable = scope.getBinding(name, BindingIds.VARIABLE, this, false /*do not resolve hidden field*/);
39                 if (existingVariable != null && existingVariable.isValidBinding()){
40                         if (existingVariable instanceof LocalVariableBinding && this.hiddenVariableDepth == 0) {
41                                 scope.problemReporter().redefineArgument(this);
42                                 return;
43                         }
44                         boolean isSpecialArgument = false;
45                         if (existingVariable instanceof FieldBinding) {
46                                 if (scope.isInsideConstructor()) {
47                                         isSpecialArgument = true; // constructor argument
48                                 } else {
49                                         AbstractMethodDeclaration methodDecl = scope.referenceMethod();
50                                         if (methodDecl != null && CharOperation.prefixEquals(SET, methodDecl.selector)) {
51                                                 isSpecialArgument = true; // setter argument
52                                         }
53                                 }
54                         }
55                         scope.problemReporter().localVariableHiding(this, existingVariable, isSpecialArgument);
56                 }
57
58                 scope.addLocalVariable(
59                         this.binding =
60                                 new LocalVariableBinding(this, typeBinding, modifierFlag, true));
61                 //true stand for argument instead of just local
62                 if (typeBinding != null && isTypeUseDeprecated(typeBinding, scope))
63                         scope.problemReporter().deprecatedType(typeBinding, this.type);
64                 this.binding.declaration = this;
65                 this.binding.useFlag = used ? LocalVariableBinding.USED : LocalVariableBinding.UNUSED;
66         }
67
68         public StringBuffer print(int indent, StringBuffer output) {
69
70                 printIndent(indent, output);
71                 printModifiers(this.modifiers, output);
72                 if (type == null) {
73                         output.append("<no type> "); //$NON-NLS-1$
74                 } else {
75                         type.print(0, output).append(' '); 
76                 }
77                 return output.append(this.name);
78         }
79
80         public StringBuffer printStatement(int indent, StringBuffer output) {
81
82                 return print(indent, output).append(';');
83         }       
84
85         public TypeBinding resolveForCatch(BlockScope scope) {
86
87                 // resolution on an argument of a catch clause
88                 // provide the scope with a side effect : insertion of a LOCAL
89                 // that represents the argument. The type must be from JavaThrowable
90
91                 TypeBinding tb = type.resolveTypeExpecting(scope, scope.getJavaLangThrowable());
92                 if (tb == null)
93                         return null;
94
95                 Binding existingVariable = scope.getBinding(name, BindingIds.VARIABLE, this, false /*do not resolve hidden field*/);
96                 if (existingVariable != null && existingVariable.isValidBinding()){
97                         if (existingVariable instanceof LocalVariableBinding && this.hiddenVariableDepth == 0) {
98                                 scope.problemReporter().redefineArgument(this);
99                                 return null;
100                         }
101                         scope.problemReporter().localVariableHiding(this, existingVariable, false);
102                 }
103
104                 binding = new LocalVariableBinding(this, tb, modifiers, false); // argument decl, but local var  (where isArgument = false)
105                 scope.addLocalVariable(binding);
106                 binding.constant = NotAConstant;
107                 return tb;
108         }
109
110         public void traverse(ASTVisitor visitor, BlockScope scope) {
111                 
112                 if (visitor.visit(this, scope)) {
113                         if (type != null)
114                                 type.traverse(visitor, scope);
115                         if (initialization != null)
116                                 initialization.traverse(visitor, scope);
117                 }
118                 visitor.endVisit(this, scope);
119         }
120 }