01: package javaparser;
02:
03: import javaparser.javacc_gen.*;
04: import javax.swing.tree.*;
05: import java.util.*;
06:
07: /** As for example in
08:
09: new ActionListener()
10: {
11: // body
12: }
13:
14: parsed from raw syntax during completion.
15: */
16: public class AnonymousType implements TypeInterface {
17: public Token start, end;
18: private String name;
19: public TypeNode parent;
20:
21: public AnonymousType(String name, Token start, Token end,
22: TypeNode parent) {
23: this .start = start;
24: this .end = end;
25: this .name = name;
26: this .parent = parent;
27: }
28:
29: public String getTypeSimpleName() {
30: return name;
31: }
32:
33: /** @return null if not found.
34: */
35: @edu.umd.cs.findbugs.annotations.CheckForNull
36: public static AnonymousType parse(
37: RAWParserTreeNode classOrInterfaceBodyNode, TypeNode parent) {
38:
39: RAWParserTreeNode tnc = classOrInterfaceBodyNode.parent;
40: RAWParserTreeNode tncs = CCTreeUtils
41: .getFirstSubchildNamed_ONLYInDirectChilds(tnc,
42: "ClassOrInterfaceType");
43: if (tncs == null) {
44: return null;
45: }
46:
47: String name = CCTreeUtils.getImageOfAllSubElements(tncs); // with full decl and type params
48:
49: // the bounds must exist
50: Token tstart = CCTreeUtils
51: .getFirstSubchild(classOrInterfaceBodyNode);
52: Token tend = CCTreeUtils
53: .getLastSubchild(classOrInterfaceBodyNode);
54:
55: return new AnonymousType(name, tstart, tend, parent);
56: }
57:
58: /** Call this to help GC !
59: *NOT CALLED !!
60: */
61: //@Override
62: public void terminate() {
63: //super.terminate();
64:
65: start = null;
66: end = null;
67: name = null;
68: parent = null;
69: }
70:
71: }
|