001: package javaparser;
002:
003: import java.lang.annotation.*;
004: import tide.syntaxtree.*;
005: import javaparser.javacc_gen.JavaParserConstants;
006:
007: /** Top annotation node.
008: * Also creates the childs.
009: */
010: public class AnnotationDeclNode extends TypeNode //implements NodeWithMod
011: {
012: private String name = "";
013: private String typeName, fullName;
014: public int[] modifiers;
015: public String modifiersShort;
016:
017: public AnnotationDeclNode(SimplifiedSyntaxTree2 sst,
018: RAWParserTreeNode annotationTypeDeclarationNode,
019: RAWParserTreeNode modNode, TypeNode parentType) {
020: super ("annotation", sst, parentType,
021: annotationTypeDeclarationNode);
022:
023: this .modifiers = CCTreeUtils.getAllModifiers(modNode);
024: modifiersShort = Utils.getModifiersShortString(modifiers);
025:
026: if (modNode.getChildCount() > 0) {
027: this .setStartPosFrom(CCTreeUtils.getFirstSubchild(modNode));
028: } else {
029: this .setStartPosFrom(CCTreeUtils
030: .getFirstSubchild(annotationTypeDeclarationNode));
031: }
032:
033: this .setEndPosFrom(CCTreeUtils
034: .getLastSubchild(annotationTypeDeclarationNode));
035:
036: typeName = "" + annotationTypeDeclarationNode.getChildNodeAt(2);
037:
038: StringBuilder fn = new StringBuilder();
039: if (parentType != null) {
040: fn.append(parentType.getJavaFullName());
041: fn.append("$"); // inner classes
042: } else {
043: fn.append(sst.packageNode.toString());
044: if (fn.length() > 0)
045: fn.append("."); // may be the root package (no name)
046: }
047: fn.append(typeName);
048: fullName = fn.toString();
049:
050: // {@, interface, name, }
051: this .name = "@"
052: + annotationTypeDeclarationNode.getChildNodeAt(1) + " "
053: + typeName;
054:
055: // scan for childs, named annotationTypeMemberDeclaration
056: RAWParserTreeNode bodyNode = CCTreeUtils
057: .getFirstSubchildNamed_ONLYInDirectChilds(
058: annotationTypeDeclarationNode,
059: "AnnotationTypeBody");
060: // iterate over the childs
061: for (int i = 0; i < bodyNode.getChildCount(); i++) {
062: RAWParserTreeNode ci = bodyNode.getChildNodeAt(i);
063: if (ci.toString().equals("AnnotationTypeMemberDeclaration")) {
064: add(new AnnotationMemberNode(ci)); // sort ?
065: }
066: }
067: }
068:
069: @Override
070: public String toString() {
071: return "" + name;
072: }
073:
074: /** Without parent and package name.
075: */
076: @Override
077: public String getTypeSimpleName() {
078: return typeName;
079: }
080:
081: /** With the package name.
082: */
083: @Override
084: public String getJavaFullName() {
085: return fullName;
086: }
087:
088: //String getEnclosingType()
089: @Override
090: public int[] getModifiers() {
091: return this .modifiers;
092: }
093:
094: @Override
095: public boolean isPublic() {
096: return Utils.isPublic(modifiers);
097: }
098:
099: public boolean isPrivate() {
100: return Utils.isPrivate(modifiers);
101: }
102:
103: public boolean isProtected() {
104: return Utils.isProtected(modifiers);
105: }
106:
107: public boolean isStatic() {
108: return Utils.isStatic(modifiers);
109: }
110:
111: /** call this to help GC !
112: */
113: @Override
114: public void terminate() {
115: super.terminate();
116:
117: modifiers = null;
118: modifiersShort = null;
119: name = null;
120: fullName = null;
121: typeName = null;
122: }
123: }
|