All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.st.p2012.mind.adl.parser.JTBProcessor Maven / Gradle / Ivy

The newest version!
/**
   \file com/st/p2012/mind/parser/JTBProcessor.java
   \brief A JTBProcessor extension for adding documentation comments in semantic AST nodes.


   
   \n
   This file is part of the Platform 2012 program,
   a cooperation between STMicroelectronics and CEA.\n
   Redistribution of this file to outside parties is
   strictly prohibited without the written consent
   of the module owner indicated below.\n
   

   \par  Module owner: [email protected]


   \par  Copyright (C) 2009 STMicroelectronics

   \par  Authors: [email protected]

   \par  Id: $Id$
   \par  Date: $Date$
   \par  Revision: $Rev$

 */

package com.st.p2012.mind.adl.parser;

import static com.st.p2012.mind.ast.CommentDecoration.setComment;
import org.objectweb.fractal.adl.Node;
import org.objectweb.fractal.adl.xml.XMLNodeFactory;
import org.objectweb.fractal.mind.adl.jtb.syntaxtree.Annotation;
import org.objectweb.fractal.mind.adl.jtb.syntaxtree.Annotations;
import org.objectweb.fractal.mind.adl.jtb.syntaxtree.AttributeDefinition;
import org.objectweb.fractal.mind.adl.jtb.syntaxtree.BindingDefinition;
import org.objectweb.fractal.mind.adl.jtb.syntaxtree.CompositeDefinition;
import org.objectweb.fractal.mind.adl.jtb.syntaxtree.DataDefinition;
import org.objectweb.fractal.mind.adl.jtb.syntaxtree.DataFileDefinition;
import org.objectweb.fractal.mind.adl.jtb.syntaxtree.ImplementationDefinition;
import org.objectweb.fractal.mind.adl.jtb.syntaxtree.InterfaceDefinition;
import org.objectweb.fractal.mind.adl.jtb.syntaxtree.NoDataDefinition;
import org.objectweb.fractal.mind.adl.jtb.syntaxtree.NodeToken;
import org.objectweb.fractal.mind.adl.jtb.syntaxtree.PrimitiveDefinition;
import org.objectweb.fractal.mind.adl.jtb.syntaxtree.SubComponentDefinition;
import org.objectweb.fractal.mind.adl.jtb.syntaxtree.TypeDefinition;

public class JTBProcessor
    extends
      org.objectweb.fractal.mind.adl.parser.JTBProcessor {

  public JTBProcessor(final XMLNodeFactory nodeFactory, final String adlDtd,
      final String filename) {
    super(nodeFactory, adlDtd, filename);
  }

  private NodeToken getCommentFromAnnotation(final Annotations annotation) {
    NodeToken commentToken = null;
    if(annotation.f0.present()) {
      commentToken = ((Annotation)annotation.f0.elementAt(0)).f0;
    }
    return commentToken;
  }

  /**
   * Gets the comment from a NodeToken.
   *
   * @param token
   * @return null if there is no comment associated to this token.
   */
  private String getComment(final NodeToken token) {
    if (token.specialTokens != null) {
      return CommentProcessor.processComment(token.getSpecialAt(0).tokenImage);
    }
    return null;
  }

  @Override
  public Node visit(final TypeDefinition n, final Node argu) {
    final Node result = super.visit(n, argu);

    NodeToken commentToken = getCommentFromAnnotation(n.f0);
    if(commentToken == null)
      commentToken = n.f1;
    setComment(result, getComment(commentToken));

    return result;
  }

  @Override
  public Node visit(final PrimitiveDefinition n, final Node argu) {
    final Node result = super.visit(n, argu);
    NodeToken commentToken = getCommentFromAnnotation(n.f0);
    if(commentToken == null) {
      if (n.f1.present()) {
        commentToken = (NodeToken) n.f1.node;
      } else {
        commentToken = n.f2;
      }
    }

    setComment(result, getComment(commentToken));
    return result;
  }

  @Override
  public Node visit(final CompositeDefinition n, final Node argu) {
    final Node result = super.visit(n, argu);

    NodeToken commentToken = getCommentFromAnnotation(n.f0);
    if(commentToken == null)
      commentToken = n.f1;
    setComment(result, getComment(commentToken));
    return result;
  }

  @Override
  public Node visit(final SubComponentDefinition n, final Node argu) {
    final Node result = super.visit(n, argu);
    NodeToken commentToken = getCommentFromAnnotation(n.f0);
    if(commentToken == null)
      commentToken = n.f1;
    setComment(result, getComment(commentToken));
    return result;
  }

  @Override
  public Node visit(final BindingDefinition n, final Node argu) {
    final Node result = super.visit(n, argu);
    NodeToken commentToken = getCommentFromAnnotation(n.f0);
    if(commentToken == null)
      commentToken = n.f1;
    setComment(result, getComment(commentToken));
    return result;
  }

  @Override
  public Node visit(final InterfaceDefinition n, final Node argu) {
    final Node result = super.visit(n, argu);
    NodeToken commentToken = getCommentFromAnnotation(n.f0);
    if(commentToken == null)
      commentToken = (NodeToken) n.f1.choice;
    setComment(result, getComment(commentToken));
    return result;
  }

  @Override
  public Node visit(final AttributeDefinition n, final Node argu) {
    final Node result = super.visit(n, argu);
    NodeToken commentToken = getCommentFromAnnotation(n.f0);
    if(commentToken == null)
      commentToken = n.f1;
    setComment(result, getComment(commentToken));
    return result;
  }

  @Override
  public Node visit(final DataDefinition n, final Node argu) {
    final Node result = super.visit(n, argu);
    NodeToken commentToken = getCommentFromAnnotation(n.f0);
    if(commentToken == null) {
      if (n.f1.choice instanceof DataFileDefinition)
        commentToken = ((DataFileDefinition) n.f1.choice).f0;
      if (n.f1.choice instanceof NoDataDefinition)
        commentToken = ((NoDataDefinition) n.f1.choice).f0;

    }
    setComment(result, getComment(commentToken));
    return result;
  }

  @Override
  public Node visit(final ImplementationDefinition n, final Node argu) {
    final Node result = super.visit(n, argu);
    NodeToken commentToken = getCommentFromAnnotation(n.f0);
    if(commentToken == null)
      commentToken = n.f1;
    setComment(result, getComment(commentToken));
    return result;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy