removed Makefile; lifted repo/org.ibex.tool/src/ to src/
[org.ibex.tool.git] / src / org / eclipse / jdt / internal / compiler / ast / Initializer.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.internal.compiler.ASTVisitor;
14 import org.eclipse.jdt.internal.compiler.codegen.*;
15 import org.eclipse.jdt.internal.compiler.flow.*;
16 import org.eclipse.jdt.internal.compiler.lookup.*;
17 import org.eclipse.jdt.internal.compiler.parser.*;
18
19 public class Initializer extends FieldDeclaration {
20         
21         public Block block;
22         public int lastVisibleFieldID;
23         public int bodyStart;
24         public int bodyEnd;
25         
26         public boolean errorInSignature = false; 
27         
28         public Initializer(Block block, int modifiers) {
29                 this.block = block;
30                 this.modifiers = modifiers;
31
32                 declarationSourceStart = sourceStart = block.sourceStart;
33         }
34
35         public FlowInfo analyseCode(
36                 MethodScope currentScope,
37                 FlowContext flowContext,
38                 FlowInfo flowInfo) {
39
40                 return block.analyseCode(currentScope, flowContext, flowInfo);
41         }
42
43         /**
44          * Code generation for a non-static initializer: 
45          *    standard block code gen
46          *
47          * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
48          * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
49          */
50         public void generateCode(BlockScope currentScope, CodeStream codeStream) {
51
52                 if ((bits & IsReachableMASK) == 0) {
53                         return;
54                 }
55                 int pc = codeStream.position;
56                 block.generateCode(currentScope, codeStream);
57                 codeStream.recordPositionsFrom(pc, this.sourceStart);
58         }
59
60         public boolean isField() {
61
62                 return false;
63         }
64
65         public boolean isStatic() {
66
67                 return (modifiers & AccStatic) != 0;
68         }
69
70         public void parseStatements(
71                 Parser parser,
72                 TypeDeclaration typeDeclaration,
73                 CompilationUnitDeclaration unit) {
74
75                 //fill up the method body with statement
76                 parser.parse(this, typeDeclaration, unit);
77         }
78
79         public StringBuffer printStatement(int indent, StringBuffer output) {
80
81                 if (modifiers != 0) {
82                         printIndent(indent, output);
83                         printModifiers(modifiers, output).append("{\n"); //$NON-NLS-1$
84                         block.printBody(indent, output);
85                         printIndent(indent, output).append('}'); 
86                         return output;
87                 } else {
88                         return block.printStatement(indent, output);
89                 }
90         }
91         
92         public void resolve(MethodScope scope) {
93
94             FieldBinding previousField = scope.initializedField;
95                 int previousFieldID = scope.lastVisibleFieldID;
96                 try {
97                     scope.initializedField = null;
98                         scope.lastVisibleFieldID = lastVisibleFieldID;
99                         if (isStatic()) {
100                                 ReferenceBinding declaringType = scope.enclosingSourceType();
101                                 if (declaringType.isNestedType() && !declaringType.isStatic())
102                                         scope.problemReporter().innerTypesCannotDeclareStaticInitializers(
103                                                 declaringType,
104                                                 this);
105                         }
106                         block.resolve(scope);
107                 } finally {
108                     scope.initializedField = previousField;
109                         scope.lastVisibleFieldID = previousFieldID;
110                 }
111         }
112
113         public void traverse(ASTVisitor visitor, MethodScope scope) {
114
115                 if (visitor.visit(this, scope)) {
116                         block.traverse(visitor, scope);
117                 }
118                 visitor.endVisit(this, scope);
119         }
120 }