1 46 package org.codehaus.groovy.ast; 47 48 import org.codehaus.groovy.syntax.CSTNode; 49 import org.codehaus.groovy.syntax.Token; 50 51 57 public class ASTNode { 58 59 protected static final String [] EMPTY_STRING_ARRAY = { 60 }; 61 62 private int lineNumber = -1; 63 private int columnNumber = -1; 64 65 public void visit(GroovyCodeVisitor visitor) { 66 throw new RuntimeException ("No visit() method implemented for class: " + getClass().getName()); 67 } 68 69 public String getText() { 70 return "<not implemented yet for class: " + getClass().getName() + ">"; 71 } 72 73 public int getLineNumber() { 74 return lineNumber; 75 } 76 77 public void setLineNumber(int lineNumber) { 78 this.lineNumber = lineNumber; 79 } 80 81 public int getColumnNumber() { 82 return columnNumber; 83 } 84 85 public void setColumnNumber(int columnNumber) { 86 this.columnNumber = columnNumber; 87 } 88 89 public void setCSTNode(CSTNode node) { 90 Token token = node.getRoot(); 91 if (token != null) { 92 setColumnNumber(token.getStartColumn()); 93 setLineNumber(token.getStartLine()); 94 } 95 if (getLineNumber() < 0) { 96 if (node.children() > 0) { 98 for (int i = 1; i < node.size(); i++) { 99 CSTNode child = node.get(i); 100 if (child != null) { 101 setCSTNode(child); 102 if (getLineNumber() >= 0) { 103 break; 104 } 105 } 106 } 107 } 108 } 109 } 110 } 111 | Popular Tags |