001: package javaparser;
002:
003: import java.util.*;
004: import javaparser.javacc_gen.*;
005:
006: public class ConstructorNode extends ParserTreeNode implements
007: NodeWithMod {
008: public int[] modifiers;
009: public String modifiersShort;
010: String name = "";
011: String paramsS = "";
012: String typeParameters = null;
013: public final List<Parameter> params;
014:
015: public Token blokStart, blokEnd;
016:
017: public ConstructorNode(
018: RAWParserTreeNode constructorDeclarationNode,
019: RAWParserTreeNode modNode) {
020: super ("constructor");
021:
022: this .sortPriority = 2;
023:
024: this .modifiers = CCTreeUtils.getAllModifiers(modNode);
025: modifiersShort = Utils.getModifiersShortString(this .modifiers);
026:
027: if (modNode.getChildCount() > 0) {
028: this .setStartPosFrom(CCTreeUtils.getFirstSubchild(modNode));
029: } else {
030: this .setStartPosFrom(CCTreeUtils
031: .getFirstSubchild(constructorDeclarationNode));
032: }
033: this .setEndPosFrom(CCTreeUtils
034: .getLastSubchild(constructorDeclarationNode));
035:
036: // childs: {Name, FormalParameters, {, }} [Nov2007]
037: // OR // childs: {TypeParameters, Name, FormalParameters, {, }}
038: RAWParserTreeNode nameNode = constructorDeclarationNode.childs
039: .get(0);
040: if (nameNode.getTokenKind() == JavaParserConstants.IDENTIFIER) //76
041: {
042: this .name = nameNode.toString();
043: } else {
044: nameNode = constructorDeclarationNode.childs.get(1);
045: this .name = nameNode.toString();
046:
047: typeParameters = CCTreeUtils
048: .getImageOfAllSubElements(constructorDeclarationNode.childs
049: .get(0));
050: }
051:
052: // TODO: name maybe preceeded by TypeParameters
053:
054: // not the same as for methods. Here we have no block node but { and } are directly in the constructorDeclarationNode
055: for (int i = 1; i < constructorDeclarationNode.getChildCount(); i++) {
056: RAWParserTreeNode ci = constructorDeclarationNode
057: .getChildNodeAt(i);
058: if (ci.getTokenKind() == JavaParserConstants.LBRACE) {
059: blokStart = ci.t;
060: } else if (ci.getTokenKind() == JavaParserConstants.RBRACE) {
061: blokEnd = ci.t;
062: }
063: }
064:
065: RAWParserTreeNode fp = CCTreeUtils
066: .getFirstSubchildNamed_ONLYInDirectChilds(
067: constructorDeclarationNode, "FormalParameters");
068: this .params = CCTreeUtils.getParameters(fp);
069: this .paramsS = Utils.toStringWithoutBraces(params);
070:
071: } // Constructor
072:
073: /** Call this to help GC !
074: */
075: @Override
076: public void terminate() {
077: super .terminate();
078:
079: if (params != null)
080: params.clear();
081:
082: modifiersShort = null;
083: modifiers = null;
084: blokEnd = null;
085: blokStart = null;
086: name = null;
087: paramsS = null;
088: }
089:
090: @Override
091: public String toString() {
092: return name + "(" + paramsS + ")"
093: + (typeParameters != null ? " " + typeParameters : "");
094: }
095:
096: public final int[] getModifiers() {
097: return modifiers;
098: }
099:
100: public boolean isStatic() {
101: return false;
102: } // never
103:
104: public boolean isPublic() {
105: return Utils.isPublic(modifiers);
106: }
107:
108: public boolean isPrivate() {
109: return Utils.isPrivate(modifiers);
110: }
111:
112: public boolean isProtected() {
113: return Utils.isProtected(modifiers);
114: }
115:
116: }
|