SDA SE WikiSoftware Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering
Represents a comment. The commentT fact just gives information about the existence and the type of the comment, not about the content (the comment itself). The content of a comment is represented by the sourceT fact, which can be enabled in the JTransformer Preferences.
#id: id
the unique ID assigned to this comment.
#parent: id
the ID of the fact that represents the element this comment is referring to. The parent element is
determined based on a set of Parent Identification Heuristics.
#type: atom
One of these atoms:
javaDoc: Indicates that this comment is a JavaDoc comment
/**
* This is a JavaDoc comment.
*/
blockComment: Indicates that this comment is a block comment
/*
* This is a block comment.
*/
lineComment: Indicates that this comment is a line comment
// This is a line comment.
// This is another one. Both refer to the next line of code.
anobject.aMessage();
Because comments are abundant and often very long, two “optimisations” are performed:
commentT/3 fact if they can be identified with a single contiguous text block that is not interrupted by statements
or declarations. See the parent identification heuristics below. - commentT/3 facts do not include the comment text. Instead, for each commentT fact there is a [[slT|slT]] (sl = Source Location) fact with the same id. It represents the text range of the comment in the source code. slT/3 facts let you extract the comment text from the original source code, when needed.
In order to decide to which declaration or statement a comment refers, JTransformer uses a set of heuristics derived from common best practice:
For examples, see the comments in the sample Java source below.
/**
* This is a JavaDoc comment whose parent is the hello() method.
*/
public void hello(){
/*
* This is a block comment whose parent is the variable declaration.
*/
int variable;
// These two line comments will be grouped together into a single
// commentT fact whose parent is the following declaration:
int var2 = hello2(); // This one and the one below will also be grouped
// and will also refer to the declaration of var2
}
In the following, commentT facts are nested below the AST elements to which they refer. This is just for readability and has no semantic implications:
methodT(#method, #class, 'hello', [], type(basic, void, 0), [], #block). commentT(#comment1, #method, 'javaDoc'). // The JavaDoc comment associated to the method declaration modifierT(#method, 'public'). blockT(#block, #method, #method, [#localdvar, V5]). localT(#localvar, #block, #method, type(basic, int, 0), 'variable', 'null'). commentT(#comment2, #localvar, 'blockComment'). // The block comment associated to the declaration of 'variable' localT(#localvar2, #block, #method, type(basic, int, 0), 'var2', #call). commentT(#comment3, #localvar2, 'lineComment'). // The first two line comments grouped together in a single commentT fact commentT(#comment4, #localvar2, 'lineComment'). // The last two line comments grouped together in a single commentT fact callT(#call, #parent, #method, 'null', 'hello2', [], V7).
ast_node_def('Java',commentT,[
ast_arg(id, mult(1,1,no ), id, [commentT]),
ast_arg(parent, mult(1,1,no), id, [id]),
ast_arg(kind, mult(1,1,no ), attr, [atom])
]).