1 46 package groovy.lang; 47 48 import org.codehaus.groovy.ast.ASTNode; 49 import org.codehaus.groovy.ast.ModuleNode; 50 51 57 public class GroovyRuntimeException extends RuntimeException { 58 59 private ModuleNode module; 60 private ASTNode node; 61 62 public GroovyRuntimeException(String message) { 63 super(message); 64 } 65 66 public GroovyRuntimeException(String message, ASTNode node) { 67 super(message); 68 this.node = node; 69 } 70 71 public GroovyRuntimeException(String message, Throwable cause) { 72 super(message, cause); 73 } 74 75 public void setModule(ModuleNode module) { 76 this.module = module; 77 } 78 79 public ModuleNode getModule() { 80 return module; 81 } 82 83 public String getMessage() { 84 return super.getMessage() + getLocationText(); 85 } 86 87 public ASTNode getNode() { 88 return node; 89 } 90 91 protected String getLocationText() { 92 String answer = ". "; 93 if (node != null) { 94 answer += "At [" + node.getLineNumber() + ":" + node.getColumnNumber() + "] "; 95 } 96 if (module != null) { 97 answer += module.getDescription(); 98 } 99 if (answer.equals(". ")) { 100 return ""; 101 } 102 return answer; 103 } 104 } 105 | Popular Tags |