deleted: export="true"
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / RecoveredLocalVariable.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.parser;
12
13 /**
14  * Internal local variable structure for parsing recovery 
15  */
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;
20
21 public class RecoveredLocalVariable extends RecoveredStatement {
22
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;
29 }
30 /* 
31  * Answer the associated parsed structure
32  */
33 public AstNode parseTree(){
34         return localDeclaration;
35 }
36 /*
37  * Answer the very source end of the corresponding parse node
38  */
39 public int sourceEnd(){
40         return this.localDeclaration.declarationSourceEnd;
41 }
42 public String toString(int tab) {
43         return tabString(tab) + "Recovered local variable:\n" + localDeclaration.toString(tab + 1); //$NON-NLS-1$
44 }
45 public Statement updatedStatement(){
46         return localDeclaration;
47 }
48 /*
49  * A closing brace got consumed, might have closed the current element,
50  * in which case both the currentElement is exited.
51  *
52  * Fields have no associated braces, thus if matches, then update parent.
53  */
54 public RecoveredElement updateOnClosingBrace(int braceStart, int braceEnd){
55         if (bracketBalance > 0){ // was an array initializer
56                 bracketBalance--;
57                 if (bracketBalance == 0) alreadyCompletedLocalInitialization = true;
58                 return this;
59         }
60         if (parent != null){
61                 return parent.updateOnClosingBrace(braceStart, braceEnd);
62         }
63         return this;
64 }
65 /*
66  * An opening brace got consumed, might be the expected opening one of the current element,
67  * in which case the bodyStart is updated.
68  */
69 public RecoveredElement updateOnOpeningBrace(int currentPosition){
70         if (localDeclaration.declarationSourceEnd == 0 
71                 && localDeclaration.type instanceof ArrayTypeReference
72                 && !alreadyCompletedLocalInitialization){
73                 bracketBalance++;
74                 return null; // no update is necessary  (array initializer)
75         }
76         // might be an array initializer
77         this.updateSourceEndIfNecessary(currentPosition - 1);   
78         return this.parent.updateOnOpeningBrace(currentPosition);       
79 }
80 public void updateParseTree(){
81         this.updatedStatement();
82 }
83 /*
84  * Update the declarationSourceEnd of the corresponding parse node
85  */
86 public void updateSourceEndIfNecessary(int sourceEnd){
87         if (this.localDeclaration.declarationSourceEnd == 0) {
88                 this.localDeclaration.declarationSourceEnd = sourceEnd;
89                 this.localDeclaration.declarationEnd = sourceEnd;       
90         }
91 }
92 }