KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > ast > AbstractVariableDeclaration


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-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.internal.compiler.flow.FlowContext;
14 import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
15 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
16 import org.eclipse.jdt.internal.compiler.lookup.InvocationSite;
17 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
18 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
19
20 public abstract class AbstractVariableDeclaration extends Statement implements InvocationSite {
21     public int declarationEnd;
22     public int declarationSourceEnd;
23     public int declarationSourceStart;
24     public int hiddenVariableDepth; // used to diagnose hiding scenarii
25
public Expression initialization;
26     public int modifiers;
27     public int modifiersSourceStart;
28     public Annotation[] annotations;
29
30     public char[] name;
31
32     public TypeReference type;
33     
34     public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
35         return flowInfo;
36     }
37     
38     public static final int FIELD = 1;
39     public static final int INITIALIZER = 2;
40     public static final int ENUM_CONSTANT = 3;
41     public static final int LOCAL_VARIABLE = 4;
42     public static final int PARAMETER = 5;
43     public static final int TYPE_PARAMETER = 6;
44     
45     
46     /**
47      * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#genericTypeArguments()
48      */

49     public TypeBinding[] genericTypeArguments() {
50         return null;
51     }
52     
53     /**
54      * Returns the constant kind of this variable declaration
55      */

56     public abstract int getKind();
57     
58     /* (non-Javadoc)
59      * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#isSuperAccess()
60      */

61     public boolean isSuperAccess() {
62         return false;
63     }
64
65     /* (non-Javadoc)
66      * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#isTypeAccess()
67      */

68     public boolean isTypeAccess() {
69         return false;
70     }
71
72     public StringBuffer JavaDoc printStatement(int indent, StringBuffer JavaDoc output) {
73         printAsExpression(indent, output);
74         switch(getKind()) {
75             case ENUM_CONSTANT:
76                 return output.append(',');
77             default:
78                 return output.append(';');
79         }
80     }
81     
82     public StringBuffer JavaDoc printAsExpression(int indent, StringBuffer JavaDoc output) {
83         printIndent(indent, output);
84         printModifiers(this.modifiers, output);
85         if (this.annotations != null) printAnnotations(this.annotations, output);
86         
87         if (type != null) {
88             type.print(0, output).append(' ');
89         }
90         output.append(this.name);
91         switch(getKind()) {
92             case ENUM_CONSTANT:
93                 if (initialization != null) {
94                     initialization.printExpression(indent, output);
95                 }
96                 break;
97             default:
98                 if (initialization != null) {
99                     output.append(" = "); //$NON-NLS-1$
100
initialization.printExpression(indent, output);
101                 }
102         }
103         return output;
104     }
105
106     public void resolve(BlockScope scope) {
107         // do nothing by default (redefined for local variables)
108
}
109
110     /* (non-Javadoc)
111      * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#setActualReceiverType(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding)
112      */

113     public void setActualReceiverType(ReferenceBinding receiverType) {
114         // do nothing by default
115
}
116
117     /* (non-Javadoc)
118      * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#setDepth(int)
119      */

120     public void setDepth(int depth) {
121
122         this.hiddenVariableDepth = depth;
123     }
124
125     /* (non-Javadoc)
126      * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#setFieldIndex(int)
127      */

128     public void setFieldIndex(int depth) {
129         // do nothing by default
130
}
131 }
132
Popular Tags