1 11 package org.eclipse.jdt.internal.compiler.parser; 12 13 16 import org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference; 17 import org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference; 18 import org.eclipse.jdt.internal.compiler.ast.ASTNode; 19 import org.eclipse.jdt.internal.compiler.ast.Expression; 20 import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; 21 import org.eclipse.jdt.internal.compiler.ast.Statement; 22 23 public class RecoveredLocalVariable extends RecoveredStatement { 24 25 public LocalDeclaration localDeclaration; 26 boolean alreadyCompletedLocalInitialization; 27 public RecoveredLocalVariable(LocalDeclaration localDeclaration, RecoveredElement parent, int bracketBalance){ 28 super(localDeclaration, parent, bracketBalance); 29 this.localDeclaration = localDeclaration; 30 this.alreadyCompletedLocalInitialization = localDeclaration.initialization != null; 31 } 32 35 public RecoveredElement add(Statement stmt, int bracketBalanceValue) { 36 37 if (this.alreadyCompletedLocalInitialization || !(stmt instanceof Expression)) { 38 return super.add(stmt, bracketBalanceValue); 39 } else { 40 this.alreadyCompletedLocalInitialization = true; 41 this.localDeclaration.initialization = (Expression)stmt; 42 this.localDeclaration.declarationSourceEnd = stmt.sourceEnd; 43 this.localDeclaration.declarationEnd = stmt.sourceEnd; 44 return this; 45 } 46 } 47 50 public ASTNode parseTree(){ 51 return localDeclaration; 52 } 53 56 public int sourceEnd(){ 57 return this.localDeclaration.declarationSourceEnd; 58 } 59 public String toString(int tab) { 60 return tabString(tab) + "Recovered local variable:\n" + localDeclaration.print(tab + 1, new StringBuffer (10)); } 62 public Statement updatedStatement(){ 63 return localDeclaration; 64 } 65 71 public RecoveredElement updateOnClosingBrace(int braceStart, int braceEnd){ 72 if (bracketBalance > 0){ bracketBalance--; 74 if (bracketBalance == 0) alreadyCompletedLocalInitialization = true; 75 return this; 76 } 77 if (parent != null){ 78 return parent.updateOnClosingBrace(braceStart, braceEnd); 79 } 80 return this; 81 } 82 86 public RecoveredElement updateOnOpeningBrace(int braceStart, int braceEnd){ 87 if (localDeclaration.declarationSourceEnd == 0 88 && (localDeclaration.type instanceof ArrayTypeReference || localDeclaration.type instanceof ArrayQualifiedTypeReference) 89 && !alreadyCompletedLocalInitialization){ 90 bracketBalance++; 91 return null; } 93 this.updateSourceEndIfNecessary(braceStart - 1, braceEnd - 1); 95 return this.parent.updateOnOpeningBrace(braceStart, braceEnd); 96 } 97 public void updateParseTree(){ 98 this.updatedStatement(); 99 } 100 103 public void updateSourceEndIfNecessary(int bodyStart, int bodyEnd){ 104 if (this.localDeclaration.declarationSourceEnd == 0) { 105 this.localDeclaration.declarationSourceEnd = bodyEnd; 106 this.localDeclaration.declarationEnd = bodyEnd; 107 } 108 } 109 } 110 | Popular Tags |