FlowAstNode.java

/*
** Module   : FlowAstNode.java
** Abstract : Encodes a single node in the flow chart, associated with an AST node.
**
** Copyright (c) 2018, Golden Code Development Corporation.
**
** -#- -I- --Date-- ---------------------------------Description----------------------------------
** 001 CA  20181003 First version.
*/

/*
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 of the
** License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Affero General Public License for more details.
**
** You may find a copy of the GNU Affero GPL version 3 at the following
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
** 
** Additional terms under GNU Affero GPL version 3 section 7:
** 
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
**   terms apply to the works covered under the License.  These additional terms
**   are non-permissive additional terms allowed under Section 7 of the GNU
**   Affero GPL version 3 and may not be removed by you.
** 
**   0. Attribution Requirement.
** 
**     You must preserve all legal notices or author attributions in the covered
**     work or Appropriate Legal Notices displayed by works containing the covered
**     work.  You may not remove from the covered work any author or developer
**     credit already included within the covered work.
** 
**   1. No License To Use Trademarks.
** 
**     This license does not grant any license or rights to use the trademarks
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
**     of Golden Code Development Corporation. You are not authorized to use the
**     name Golden Code, FWD, or the names of any author or contributor, for
**     publicity purposes without written authorization.
** 
**   2. No Misrepresentation of Affiliation.
** 
**     You may not represent yourself as Golden Code Development Corporation or FWD.
** 
**     You may not represent yourself for publicity purposes as associated with
**     Golden Code Development Corporation, FWD, or any author or contributor to
**     the covered work, without written authorization.
** 
**   3. No Misrepresentation of Source or Origin.
** 
**     You may not represent the covered work as solely your work.  All modified
**     versions of the covered work must be marked in a reasonable way to make it
**     clear that the modified work is not originating from Golden Code Development
**     Corporation or FWD.  All modified versions must contain the notices of
**     attribution required in this license.
*/

package com.goldencode.p2j.report.server;

import com.goldencode.ast.*;

/**
 * Defines a node associated with a parsed AST.
 */
public class FlowAstNode
extends FlowNode
{
   /** The associated AST's ID. */
   private long astId;
   
   /** The line location of this code. */
   private int line;
   
   /** The column location of this code. */
   private int column;

   /**
    * For branch or block ASTs, defines the index of the first element in this block. In other 
    * words, the sub-tree (if you ignore the loops) rooted at this node will have the first node 
    * on the {@link #begin} index. 
    */
   private Integer begin;
   
   /**
    * For branch or block ASTs, defines the index of the last element in this block. In other 
    * words, the sub-tree (if you ignore the loops) rooted at this node will have the last node 
    * on the {@link #end} index. 
    */
   private Integer end;
   
   /**
    * For call-sites nodes targeting a callgraph node (associated with an AST node), this will
    * encode the details about the call-site's target.
    */
   private CallSite callSite;
   
   /** The associated AST - used internally only. */
   Aast ast;

   /**
    * Create an instance.
    * 
    * @param    id
    *           The node's ID.
    * @param    ast
    *           The associated AST.
    * @param    type
    *           The node's type.
    * @param    text
    *           The node's text.
    * @param    line
    *           The node's line.
    * @param    column
    *           The node's column.
    */
   public FlowAstNode(int id, Aast ast, String type, String text, int line, int column)
   {
      super(id, type);
      
      this.ast = ast;
      this.astId = ast.getId();
      this.line = line;
      this.column = column;

      setText(text);
   }
   
   /**
    * Get the node's {@link #astId}.
    * 
    * @return   See above.
    */
   public long getAstId()
   {
      return astId;
   }

   /**
    * Set the node's {@link #astId}.
    * 
    * @param    astId
    *           The AST ID.
    */
  public void setAstId(long astId)
   {
      this.astId = astId;
   }

  /**
   * Get the node's {@link #line}.
   * 
   * @return   See above.
   */
   public int getLine()
   {
      return line;
   }

   /**
    * Set the node's {@link #line}.
    * 
    * @param    line
    *           The line value.
    */
   public void setLine(int line)
   {
      this.line = line;
   }

   /**
    * Get the node's {@link #column}.
    * 
    * @return   See above.
    */
   public int getColumn()
   {
      return column;
   }

   /**
    * Set the node's {@link #column}.
    * 
    * @param    column
    *           The column value.
    */
   public void setColumn(int column)
   {
      this.column = column;
   }

   /**
    * Get the node's {@link #callSite}.  May be <code>null</code>.
    * 
    * @return   See above.
    */
   public CallSite getCallSite()
   {
      return callSite;
   }

   /**
    * Set the node's {@link #callSite}.  May be <code>null</code>.
    * 
    * @param    callSite
    *           The node's callSite.
    */
   public void setCallSite(CallSite callSite)
   {
      this.callSite = callSite;
   }

   /**
    * Get the node's {@link #begin} index.  May be <code>null</code>.
    * 
    * @return   See above.
    */
   public Integer getBegin()
   {
      return begin;
   }

   /**
    * Set the node's {@link #begin} index.  May be <code>null</code>.
    * 
    * @param    begin
    *           The node's begin index.
    */
   public void setBegin(Integer begin)
   {
      this.begin = begin;
   }

   /**
    * Get the node's {@link #end} index.  May be <code>null</code>.
    * 
    * @return   See above.
    */
   public Integer getEnd()
   {
      return end;
   }

   /**
    * Set the node's {@link #end} index.  May be <code>null</code>.
    * 
    * @param    end
    *           The node's end index.
    */
   public void setEnd(Integer end)
   {
      this.end = end;
   }
}