ConstructorNode.java :  » IDE » tIDE » javaparser » Java Open Source

Java Open Source » IDE » tIDE 
tIDE » javaparser » ConstructorNode.java
package javaparser;

import java.util.*;
import javaparser.javacc_gen.*;

public class ConstructorNode extends ParserTreeNode implements NodeWithMod
{
  public int[] modifiers;
  public String modifiersShort;
  String name = "";
  String paramsS = "";
  String typeParameters = null;
  public final List<Parameter> params;

  public Token blokStart, blokEnd;

  public ConstructorNode(RAWParserTreeNode constructorDeclarationNode, RAWParserTreeNode modNode)
  {
     super("constructor");

     this.sortPriority = 2;

     this.modifiers = CCTreeUtils.getAllModifiers(modNode);
     modifiersShort = Utils.getModifiersShortString(this.modifiers);

     if(modNode.getChildCount()>0)
     {
       this.setStartPosFrom( CCTreeUtils.getFirstSubchild(modNode) );
     }
     else
     {
       this.setStartPosFrom( CCTreeUtils.getFirstSubchild(constructorDeclarationNode) );
     }
     this.setEndPosFrom( CCTreeUtils.getLastSubchild(constructorDeclarationNode) );

     // childs: {Name, FormalParameters, {, }}  [Nov2007]
     //  OR // childs: {TypeParameters, Name, FormalParameters, {, }}
     RAWParserTreeNode nameNode = constructorDeclarationNode.childs.get(0);
     if(nameNode.getTokenKind()==JavaParserConstants.IDENTIFIER) //76
     {
        this.name =  nameNode.toString();
     }
     else
     {
        nameNode = constructorDeclarationNode.childs.get(1);
        this.name =  nameNode.toString();

        typeParameters = CCTreeUtils.getImageOfAllSubElements(constructorDeclarationNode.childs.get(0));
     }

     // TODO: name maybe preceeded by TypeParameters


     // not the same as for methods. Here we have no block node but { and } are directly in the constructorDeclarationNode
     for(int i=1; i<constructorDeclarationNode.getChildCount(); i++)
     {
        RAWParserTreeNode ci = constructorDeclarationNode.getChildNodeAt(i);
        if(ci.getTokenKind()==JavaParserConstants.LBRACE)
        {
           blokStart = ci.t;
        }
        else if(ci.getTokenKind()==JavaParserConstants.RBRACE)
        {
           blokEnd = ci.t;
        }
     }

     RAWParserTreeNode fp = CCTreeUtils.getFirstSubchildNamed_ONLYInDirectChilds(constructorDeclarationNode, "FormalParameters");
     this.params = CCTreeUtils.getParameters(fp);
     this.paramsS = Utils.toStringWithoutBraces(params);

  } // Constructor

  /** Call this to help GC !
  */
@Override
  public void terminate()
  {
    super.terminate();

    if(params!=null) params.clear();

    modifiersShort = null;
    modifiers = null;
    blokEnd = null;
    blokStart = null;
    name = null;
    paramsS = null;
  }

  @Override
  public String toString()
  {
    return name+"("+paramsS+")"+(typeParameters!=null ? " "+typeParameters:"");
  }

  public final int[] getModifiers() { return modifiers; }
  public boolean isStatic() { return false; }  // never
  public boolean isPublic() { return Utils.isPublic( modifiers); }
  public boolean isPrivate() { return Utils.isPrivate( modifiers); }
  public boolean isProtected() { return Utils.isProtected( modifiers); }


}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.