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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
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;
19 public class Argument extends LocalDeclaration {
21 public Argument(char[] name, long posNom, TypeReference tr, int modifiers) {
23 super(null, name, (int) (posNom >>> 32), (int) posNom);
24 this.declarationSourceEnd = (int) posNom;
25 this.modifiers = modifiers;
27 this.bits |= IsLocalDeclarationReachableMASK;
30 public void bind(MethodScope scope, TypeBinding typeBinding, boolean used) {
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
39 scope.problemReporter().redefineArgument(this);
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;
52 public TypeBinding resolveForCatch(BlockScope scope) {
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
58 TypeBinding tb = type.resolveTypeExpecting(scope, scope
59 .getJavaLangThrowable());
62 if ((binding = scope.duplicateName(name)) != null) {
63 // the name already exists....may carry on with the first binding
65 scope.problemReporter().redefineArgument(this);
68 binding = new LocalVariableBinding(this, tb, modifiers, false); // argument
77 scope.addLocalVariable(binding);
78 binding.constant = NotAConstant;
82 public String toString(int tab) {
84 String s = ""; //$NON-NLS-1$
85 if (modifiers != AccDefault) {
86 s += modifiersString(modifiers);
89 s += "<no type> "; //$NON-NLS-1$
91 s += type.toString(tab) + " "; //$NON-NLS-1$
93 s += new String(name);
97 public void traverse(ASTVisitor visitor, BlockScope scope) {
99 if (visitor.visit(this, scope)) {
101 type.traverse(visitor, scope);
102 if (initialization != null)
103 initialization.traverse(visitor, scope);
105 visitor.endVisit(this, scope);