001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.compiler.ast;
011:
012: import org.eclipse.jdt.internal.compiler.flow.FlowContext;
013: import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
014: import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
015: import org.eclipse.jdt.internal.compiler.lookup.InvocationSite;
016: import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
017: import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
018:
019: public abstract class AbstractVariableDeclaration extends Statement
020: implements InvocationSite {
021: public int declarationEnd;
022: public int declarationSourceEnd;
023: public int declarationSourceStart;
024: public int hiddenVariableDepth; // used to diagnose hiding scenarii
025: public Expression initialization;
026: public int modifiers;
027: public int modifiersSourceStart;
028: public Annotation[] annotations;
029:
030: public char[] name;
031:
032: public TypeReference type;
033:
034: public FlowInfo analyseCode(BlockScope currentScope,
035: FlowContext flowContext, FlowInfo flowInfo) {
036: return flowInfo;
037: }
038:
039: public static final int FIELD = 1;
040: public static final int INITIALIZER = 2;
041: public static final int ENUM_CONSTANT = 3;
042: public static final int LOCAL_VARIABLE = 4;
043: public static final int PARAMETER = 5;
044: public static final int TYPE_PARAMETER = 6;
045:
046: /**
047: * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#genericTypeArguments()
048: */
049: public TypeBinding[] genericTypeArguments() {
050: return null;
051: }
052:
053: /**
054: * Returns the constant kind of this variable declaration
055: */
056: public abstract int getKind();
057:
058: /* (non-Javadoc)
059: * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#isSuperAccess()
060: */
061: public boolean isSuperAccess() {
062: return false;
063: }
064:
065: /* (non-Javadoc)
066: * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#isTypeAccess()
067: */
068: public boolean isTypeAccess() {
069: return false;
070: }
071:
072: public StringBuffer printStatement(int indent, StringBuffer output) {
073: printAsExpression(indent, output);
074: switch (getKind()) {
075: case ENUM_CONSTANT:
076: return output.append(',');
077: default:
078: return output.append(';');
079: }
080: }
081:
082: public StringBuffer printAsExpression(int indent,
083: StringBuffer output) {
084: printIndent(indent, output);
085: printModifiers(this .modifiers, output);
086: if (this .annotations != null)
087: printAnnotations(this .annotations, output);
088:
089: if (type != null) {
090: type.print(0, output).append(' ');
091: }
092: output.append(this .name);
093: switch (getKind()) {
094: case ENUM_CONSTANT:
095: if (initialization != null) {
096: initialization.printExpression(indent, output);
097: }
098: break;
099: default:
100: if (initialization != null) {
101: output.append(" = "); //$NON-NLS-1$
102: initialization.printExpression(indent, output);
103: }
104: }
105: return output;
106: }
107:
108: public void resolve(BlockScope scope) {
109: // do nothing by default (redefined for local variables)
110: }
111:
112: /* (non-Javadoc)
113: * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#setActualReceiverType(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding)
114: */
115: public void setActualReceiverType(ReferenceBinding receiverType) {
116: // do nothing by default
117: }
118:
119: /* (non-Javadoc)
120: * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#setDepth(int)
121: */
122: public void setDepth(int depth) {
123:
124: this .hiddenVariableDepth = depth;
125: }
126:
127: /* (non-Javadoc)
128: * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#setFieldIndex(int)
129: */
130: public void setFieldIndex(int depth) {
131: // do nothing by default
132: }
133: }
|