1 19 package org.netbeans.modules.javacore.jmiimpl.javamodel; 20 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.Collections ; 24 import java.util.List ; 25 import org.netbeans.jmi.javamodel.GotoStatement; 26 import org.netbeans.lib.java.parser.ASTree; 27 import org.netbeans.mdr.storagemodel.StorableObject; 28 import org.netbeans.modules.javacore.parser.ASTProvider; 29 import org.netbeans.modules.javacore.parser.ASTUtil; 30 31 36 public abstract class GotoStatementImpl extends StatementImpl implements GotoStatement { 37 private String label = null; 38 39 40 public GotoStatementImpl(StorableObject o) { 41 super(o); 42 } 43 44 public void setLabel(String label) { 45 objectChanged(CHANGED_LABEL); 46 this.label = label; 47 } 48 49 public String getLabel() { 50 if (isChanged(CHANGED_LABEL)) { 51 return label; 52 } else { 53 return ASTUtil.getIdentifier(getASTree().getSubTrees()[0]); 54 } 55 } 56 57 protected abstract String getStatementName(); 58 59 String getRawText() { 60 StringBuffer buf = new StringBuffer (); 61 buf.append(getStatementName()); 62 String label = getLabel(); 63 if (label != null) { 64 buf.append(' '); 65 buf.append(label); 66 } 67 buf.append(';'); 68 return buf.toString(); 69 } 70 71 public void getDiff(List diff) { 72 ASTProvider parser = getParser(); 73 ASTree tree = getASTree(); 74 ASTree[] children = tree.getSubTrees(); 75 76 if (isChanged(CHANGED_LABEL)) { 77 replaceNode(diff, parser, children[0], getLabel(), parser.getToken(tree.getFirstToken()).getEndOffset(), " "); } 79 } 80 81 void setData(String label) { 82 this.label = label; 83 } 84 } 85 | Popular Tags |