0
|
1 package nabble.naml.compiler;
|
|
2
|
|
3 import java.lang.reflect.Method;
|
|
4 import fschmidt.util.java.Interner;
|
|
5 import nabble.naml.dom.Element;
|
|
6
|
|
7
|
|
8 public final class StackTraceElement {
|
|
9
|
|
10 private static final Interner<StackTraceElement> interner = new Interner<StackTraceElement>();
|
|
11
|
|
12 public final Source source;
|
|
13 private final int lineNumber;
|
|
14 private final Element element;
|
|
15 private final String commandName;
|
|
16 private Method method;
|
|
17
|
|
18 StackTraceElement(Source source,int lineNumber) {
|
|
19 this.source = source;
|
|
20 this.lineNumber = lineNumber;
|
|
21 this.element = null;
|
|
22 this.commandName = null;
|
|
23 }
|
|
24
|
|
25 public StackTraceElement(Source source,Element element) {
|
|
26 this(source,element,(String)null);
|
|
27 }
|
|
28
|
|
29 StackTraceElement(Macro macro) {
|
|
30 this(macro.source,macro.element);
|
|
31 }
|
|
32
|
|
33 StackTraceElement(Source source,Element element,String commandName) {
|
|
34 this.source = source;
|
|
35 this.lineNumber = element.lineNumber();
|
|
36 this.element = element;
|
|
37 this.commandName = commandName==null ? null : commandName.intern();
|
|
38 }
|
|
39
|
|
40 StackTraceElement(Source source,Element element,JavaCommand javaCommand) {
|
|
41 this(source,element,javaCommand.name);
|
|
42 setMethod(javaCommand.method);
|
|
43 }
|
|
44
|
|
45 void setMethod(Method method) {
|
|
46 this.method = method;
|
|
47 }
|
|
48
|
|
49 @Override public boolean equals(Object obj) {
|
|
50 if( !(obj instanceof StackTraceElement) )
|
|
51 return false;
|
|
52 StackTraceElement ste = (StackTraceElement)obj;
|
|
53 return ste.source == source
|
|
54 && ste.lineNumber == lineNumber
|
|
55 && ste.element == element
|
|
56 && ste.commandName == commandName
|
|
57 ;
|
|
58 }
|
|
59
|
|
60 @Override public int hashCode() {
|
|
61 int hash = source.id.hashCode();
|
|
62 hash = 31*hash + lineNumber;
|
|
63 if( element != null )
|
|
64 hash = 31*hash + element.hashCode();
|
|
65 if( commandName != null )
|
|
66 hash = 31*hash + commandName.hashCode();
|
|
67 return hash;
|
|
68 }
|
|
69
|
|
70 StackTraceElement intern() {
|
|
71 return interner.intern(this);
|
|
72 }
|
|
73
|
|
74 public String toString() {
|
|
75 if( element == null )
|
|
76 return source + ":" + (lineNumber+1);
|
|
77 StringBuilder sb = new StringBuilder();
|
|
78 if( commandName != null )
|
|
79 sb.append( commandName );
|
|
80 sb
|
|
81 .append( "(" )
|
|
82 .append( source )
|
|
83 .append( ":" )
|
|
84 .append( lineNumber+1 )
|
|
85 .append( ") - " )
|
|
86 .append( element.openingTag() )
|
|
87 ;
|
|
88 if( method != null )
|
|
89 sb.append( " - " ).append( method );
|
|
90 return sb.toString();
|
|
91 }
|
|
92
|
|
93 String commandName() {
|
|
94 return commandName;
|
|
95 }
|
|
96 }
|