Class VisitorComments

java.lang.Object
org.eclipse.jdt.core.dom.ASTVisitor
fr.inria.verveine.extractor.java.visitors.GetVisitedEntityAbstractVisitor
fr.inria.verveine.extractor.java.visitors.defvisitors.VisitorComments

public class VisitorComments extends GetVisitedEntityAbstractVisitor
A class to collect all comments. Some important details on comments in JDT:
  • only JavaDoc comment are associated to any entity node in the AST (the entity immediately after the javadoc)
  • The startPosition of a node with a JavaDoc is actually the startPosition of the JavaDoc (ie. the JavaDoc is considered to be part of the entity declaration)
  • line and block comment are recorded in a list, but we have to decide to what entity they will be associated. We put them in the method containing them or in the method or attribute immediately after them if they are outside a method
  • content (text) of block or line comments is not stored, only their position and length. We have to recover them from the source file
This class assumes the AST is visited in the file position order of the nodes (nodes appearing first in the file are visited first). It visit the AST in parallel with "visiting" the list of comments and for each comment,
  • if it is a JavaDoc, gets its associated node
  • if not javadoc, finds out if it is in a method or not
    • if not, it find the class, method, or attribute that comes immediately after the comment
    • if in a method, it associates the comment to this method
  • Field Details

    • allComments

      protected List<org.eclipse.jdt.core.dom.Comment> allComments
      list of all comments in the compilation unit
    • nextComment

      protected int nextComment
      Indice in allComments of next comment to deal with (ie. associate with a Famix entity).
    • classMemberDeclarations

      protected boolean classMemberDeclarations
      Whether we are defining a class member or not
      Used to differentiate attribute declarations from other variable declarations
    • currentFilename

      protected String currentFilename
    • openedFile

      protected BufferedReader openedFile
    • lastPositionRead

      protected int lastPositionRead
  • Constructor Details

  • Method Details

    • visit

      public boolean visit(org.eclipse.jdt.core.dom.CompilationUnit node)
      Overrides:
      visit in class org.eclipse.jdt.core.dom.ASTVisitor
    • endVisit

      public void endVisit(org.eclipse.jdt.core.dom.CompilationUnit node)
      Overrides:
      endVisit in class org.eclipse.jdt.core.dom.ASTVisitor
    • visit

      public boolean visit(org.eclipse.jdt.core.dom.TypeDeclaration node)
      Overrides:
      visit in class org.eclipse.jdt.core.dom.ASTVisitor
    • endVisit

      public void endVisit(org.eclipse.jdt.core.dom.TypeDeclaration node)
      Overrides:
      endVisit in class org.eclipse.jdt.core.dom.ASTVisitor
    • visit

      public boolean visit(org.eclipse.jdt.core.dom.ImplicitTypeDeclaration node)
      Overrides:
      visit in class org.eclipse.jdt.core.dom.ASTVisitor
    • endVisit

      public void endVisit(org.eclipse.jdt.core.dom.ImplicitTypeDeclaration node)
      Overrides:
      endVisit in class org.eclipse.jdt.core.dom.ASTVisitor
    • visit

      public boolean visit(org.eclipse.jdt.core.dom.RecordDeclaration node)
      Overrides:
      visit in class org.eclipse.jdt.core.dom.ASTVisitor
    • endVisit

      public void endVisit(org.eclipse.jdt.core.dom.RecordDeclaration node)
      Overrides:
      endVisit in class org.eclipse.jdt.core.dom.ASTVisitor
    • visit

      public boolean visit(org.eclipse.jdt.core.dom.AnonymousClassDeclaration node)
      AnonymousClassDeclaration appear within a method, we deal first with all "pending" comments that appear before the AnonymousClassDeclaration and should be associated with the method and not anonymous class
      Overrides:
      visit in class org.eclipse.jdt.core.dom.ASTVisitor
    • endVisit

      public void endVisit(org.eclipse.jdt.core.dom.AnonymousClassDeclaration node)
      Overrides:
      endVisit in class org.eclipse.jdt.core.dom.ASTVisitor
    • visit

      public boolean visit(org.eclipse.jdt.core.dom.EnumDeclaration node)
      Overrides:
      visit in class org.eclipse.jdt.core.dom.ASTVisitor
    • endVisit

      public void endVisit(org.eclipse.jdt.core.dom.EnumDeclaration node)
      Overrides:
      endVisit in class org.eclipse.jdt.core.dom.ASTVisitor
    • visit

      public boolean visit(org.eclipse.jdt.core.dom.AnnotationTypeDeclaration node)
      Overrides:
      visit in class org.eclipse.jdt.core.dom.ASTVisitor
    • endVisit

      public void endVisit(org.eclipse.jdt.core.dom.AnnotationTypeDeclaration node)
      Overrides:
      endVisit in class org.eclipse.jdt.core.dom.ASTVisitor
    • visit

      public boolean visit(org.eclipse.jdt.core.dom.MethodDeclaration node)
      Overrides:
      visit in class org.eclipse.jdt.core.dom.ASTVisitor
    • endVisit

      public void endVisit(org.eclipse.jdt.core.dom.MethodDeclaration node)
      Overrides:
      endVisit in class org.eclipse.jdt.core.dom.ASTVisitor
    • visit

      public boolean visit(org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration node)
      Overrides:
      visit in class org.eclipse.jdt.core.dom.ASTVisitor
    • endVisit

      public void endVisit(org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration node)
      Overrides:
      endVisit in class org.eclipse.jdt.core.dom.ASTVisitor
    • visit

      public boolean visit(org.eclipse.jdt.core.dom.Initializer node)
      Overrides:
      visit in class org.eclipse.jdt.core.dom.ASTVisitor
    • endVisit

      public void endVisit(org.eclipse.jdt.core.dom.Initializer node)
      Overrides:
      endVisit in class org.eclipse.jdt.core.dom.ASTVisitor
    • visit

      public boolean visit(org.eclipse.jdt.core.dom.VariableDeclarationFragment node)
      Overrides:
      visit in class org.eclipse.jdt.core.dom.ASTVisitor
    • assignCommentsBefore

      protected void assignCommentsBefore(org.eclipse.jdt.core.dom.ASTNode node, org.eclipse.jdt.core.dom.Javadoc optionalJavadoc, TWithComments fmx)
      Assigns all "pending" comments to the Famix entity.
      Pending comments are those not treated that appear before the node associated with the Famix entity.
      optionalJavadoc is an optional Javadoc comment (!) that could be associated to the node. If this is the case, the real startPosition of the node must be incremented of the length of the javadoc because this one is considered part of the node.
    • assignCommentsInside

      protected void assignCommentsInside(org.eclipse.jdt.core.dom.ASTNode node, TWithComments fmx)
      Assigns all "pending" comments that appear with the Famix entity (actually within the node associated to it)
    • assignCommentsInInterval

      protected void assignCommentsInInterval(int start, int end, TWithComments fmx)
      Assigns to the Famix entity all "pending" comments that appear within the interval [start ; stop]
    • pendingComments

      protected boolean pendingComments()
      Whether there is still some "pending" comments
    • commentIsInside

      protected boolean commentIsInside(org.eclipse.jdt.core.dom.Comment cmt, int start, int end)
      whether cmt appears inside interval [ start ; end ]
    • initializeCommentsReader

      protected void initializeCommentsReader(org.eclipse.jdt.core.dom.CompilationUnit node)
    • getFileContent

      protected String getFileContent(int start, int lenghtToRead)
    • closeFile

      protected void closeFile()