1 /*******************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v0.5
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v05.html
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.parser;
14 * Internal local variable structure for parsing recovery
16 import net.sourceforge.phpdt.internal.compiler.ast.ArrayTypeReference;
17 import net.sourceforge.phpdt.internal.compiler.ast.AstNode;
18 import net.sourceforge.phpdt.internal.compiler.ast.LocalDeclaration;
19 import net.sourceforge.phpdt.internal.compiler.ast.Statement;
21 public class RecoveredLocalVariable extends RecoveredStatement {
23 public LocalDeclaration localDeclaration;
24 boolean alreadyCompletedLocalInitialization;
25 public RecoveredLocalVariable(LocalDeclaration localDeclaration, RecoveredElement parent, int bracketBalance){
26 super(localDeclaration, parent, bracketBalance);
27 this.localDeclaration = localDeclaration;
28 this.alreadyCompletedLocalInitialization = localDeclaration.initialization != null;
31 * Answer the associated parsed structure
33 public AstNode parseTree(){
34 return localDeclaration;
37 * Answer the very source end of the corresponding parse node
39 public int sourceEnd(){
40 return this.localDeclaration.declarationSourceEnd;
42 public String toString(int tab) {
43 return tabString(tab) + "Recovered local variable:\n" + localDeclaration.toString(tab + 1); //$NON-NLS-1$
45 public Statement updatedStatement(){
46 return localDeclaration;
49 * A closing brace got consumed, might have closed the current element,
50 * in which case both the currentElement is exited.
52 * Fields have no associated braces, thus if matches, then update parent.
54 public RecoveredElement updateOnClosingBrace(int braceStart, int braceEnd){
55 if (bracketBalance > 0){ // was an array initializer
57 if (bracketBalance == 0) alreadyCompletedLocalInitialization = true;
61 return parent.updateOnClosingBrace(braceStart, braceEnd);
66 * An opening brace got consumed, might be the expected opening one of the current element,
67 * in which case the bodyStart is updated.
69 public RecoveredElement updateOnOpeningBrace(int currentPosition){
70 if (localDeclaration.declarationSourceEnd == 0
71 && localDeclaration.type instanceof ArrayTypeReference
72 && !alreadyCompletedLocalInitialization){
74 return null; // no update is necessary (array initializer)
76 // might be an array initializer
77 this.updateSourceEndIfNecessary(currentPosition - 1);
78 return this.parent.updateOnOpeningBrace(currentPosition);
80 public void updateParseTree(){
81 this.updatedStatement();
84 * Update the declarationSourceEnd of the corresponding parse node
86 public void updateSourceEndIfNecessary(int sourceEnd){
87 if (this.localDeclaration.declarationSourceEnd == 0) {
88 this.localDeclaration.declarationSourceEnd = sourceEnd;
89 this.localDeclaration.declarationEnd = sourceEnd;