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.flow.FlowContext;
15 import net.sourceforge.phpdt.internal.compiler.flow.FlowInfo;
16 import net.sourceforge.phpdt.internal.compiler.lookup.MethodScope;
17 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
18 import net.sourceforge.phpdt.internal.compiler.parser.UnitParser;
20 public class Initializer extends FieldDeclaration {
24 public int lastFieldID;
28 public Initializer(Block block, int modifiers) {
30 this.modifiers = modifiers;
32 declarationSourceStart = sourceStart = bodyStart = block.sourceStart;
35 public FlowInfo analyseCode(MethodScope currentScope,
36 FlowContext flowContext, FlowInfo flowInfo) {
38 return block.analyseCode(currentScope, flowContext, flowInfo);
42 * Code generation for a non-static initializer: standard block code gen
45 * net.sourceforge.phpdt.internal.compiler.lookup.BlockScope
47 * net.sourceforge.phpdt.internal.compiler.codegen.CodeStream
49 // public void generateCode(BlockScope currentScope, CodeStream codeStream)
52 // if ((bits & IsReachableMASK) == 0) {
55 // int pc = codeStream.position;
56 // block.generateCode(currentScope, codeStream);
57 // codeStream.recordPositionsFrom(pc, this.sourceStart);
59 public boolean isField() {
64 public boolean isStatic() {
66 return (modifiers & AccStatic) != 0;
69 public void parseStatements(UnitParser parser, TypeDeclaration type,
70 CompilationUnitDeclaration unit) {
72 // fill up the method body with statement
73 parser.parse(this, type, unit);
76 public void resolve(MethodScope scope) {
78 int previous = scope.fieldDeclarationIndex;
80 scope.fieldDeclarationIndex = lastFieldID;
82 ReferenceBinding declaringType = scope.enclosingSourceType();
83 if (declaringType.isNestedType() && !declaringType.isStatic())
84 scope.problemReporter()
85 .innerTypesCannotDeclareStaticInitializers(
90 scope.fieldDeclarationIndex = previous;
94 public String toString(int tab) {
97 StringBuffer buffer = new StringBuffer();
98 buffer.append(tabString(tab));
99 buffer.append(modifiersString(modifiers));
100 buffer.append("{\n"); //$NON-NLS-1$
101 buffer.append(block.toStringStatements(tab));
102 buffer.append(tabString(tab));
103 buffer.append("}"); //$NON-NLS-1$
104 return buffer.toString();
106 return block.toString(tab);
110 public void traverse(ASTVisitor visitor, MethodScope scope) {
112 if (visitor.visit(this, scope)) {
113 block.traverse(visitor, scope);
115 visitor.endVisit(this, scope);