SDA SE Wiki

Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
research:jtransformer:api:java:pefs:4.0:annotationt [2014/07/07 15:28]
127.0.0.1 external edit
research:jtransformer:api:java:pefs:4.0:annotationt [2018/05/09 01:59] (current)
Line 1: Line 1:
 +{{page>​prologast_bodypef_index&​fullpage&​nofooter}}
  
 +----
 +=== annotationT(#​id,​ #parent, #encl, #​annotationType,​ [#​keyValue_1,​..] )  ===
 +
 +
 +Represents an annotation (expression). ++ Java 5 Syntax Element | - supported since JTransformer 2.3.  ++
 +
 +=== Arguments ===
 +
 +==  ==
 +**#id:** id\\ 
 +the unique ID assigned to this fact.
 +
 +**#​parent:​** id\\ 
 +the ID of the fact that represents the parent of this fact in the prolog AST.
 +Either the ID of the annotated element or [[membervaluet|membervaluet]] fact in case of a nested annotation.
 +e.g. ''​@Ann2''​ in  ''​ @Ann(value = 1, ann1 = @Ann2(id=1))''​
 +
 +**#encl:** id\\ 
 +the enclosing annotated declaration,​ expression or statement. Here we extended the Java 5 annotation model.
 +
 +**annotationType:​** [[classt|classT]]\\ ​
 +the referenced annotation type.
 +
 +/*
 +**#​expression:​**[[literalt|literalT]],​[[newarrayt|newarrayT]],​[[identt|identT]],​ [[conditionalt|conditionalT]].
 +*/
 +
 +**[#​keyValue_1,​..] :​**[[annotationExpressionType]],​ [[membervaluet|memberValueT]]\\ ​
 +list of IDs of the member value pairs.
 +
 +=== Sample Java Source ===
 +==  ==
 +
 +<​Code>​
 +@ThisAnnotation("​Member"​) ​  //​case 1
 +private int aField; ​     ​
 +
 +@ThisAnnotation ​            //​case 2 : If the annotation is a marker annotation the expression is 
 +private int anotherField; ​  // ​        ​flagged by a markerAnnotationT(#​id) fact.
 +</​Code>​
 +
 +=== Its PEF Representation ===
 +==  ==
 +<Code lang-prolog>​
 +%case 1
 +fieldT(#​Field,​ _, #Fieldtype, '​aField',​ '​null'​),​
 +annotationT(#​Annotation,​ #Parent, #​EnclosingElement,​ #​AnnotationType,​ [#​KeyValue]),​
 +literalT(#​Literal,​ #KeyValue, #​EnclosingElement,​ #​Literaltype,​ '​Member'​).
 +
 +%case 2
 +fieldT(#​Field,​ _, #Fieldtype, '​anotherField',​ '​null'​),​
 +annotationT(#​Annotation,​ #Enclosing, #Enclosing, #​AnnotationType,​ []),
 +markerAnnotationT(#​Annotation).
 +
 +</​Code>​
 +
 +<​html>​
 +<!--
 +If the annotation is a //marker annotation//​ (see below) the expression is flagged by a [[markerannotationt|markerannotationt]](#​id) fact.
 +
 +  * For single member annotations the fifth argument is a annotation expression and the sixth is an empty list (////).To query for the following annotation<​Code>​ @ThisAnnotation("​Member"​)</​Code>​
 +use<​Code>​ fullQualifiedName(Type,'​package.name.ThisAnnotation'​),​
 +annotationT(Annotation,​_,​_,​Type,​LiteralID,​[]),​
 +literalT(LiteralID,​_,​_,​_,'​Member',​_)</​Code>​
 +
 +
 +  * For marker annotations the fifth argument is '​null'​ and the sixth is an empty list (////).To query for the following annotation(s)<​Code> ​ @ThisAnnotation ​ ( this is equivalent to the normal annotation @ThisAnnotation() </​Code>​
 +use<​Code>​ fullQualifiedName(Type,'​package.name.ThisAnnotation'​),​
 +annotationT(Annotation,​_,​_,​Type,'​null',​[]).</​Code>​
 +  * For normal annotations the fifth argument is '​null'​ and the sixth is a list of key value pairs:To query for the following annotation(s)<​Code>​ @ThisAnnotation(id = 1)  </​Code>​
 +use<​Code>​ fullQualifiedName(Type,'​package.name.ThisAnnotation'​),​
 +annotationT(Annotation,​_,​_,​Type,'​null',​[Id]),​
 +memberValueT(Id,​_,​_,'​id',​LiteralID,​_),​
 +literalT(LiteralID,​_,​_,​_,'​1',​_).</​Code>​
 +
 +-->
 +</​html>​
 +=== AST Specification ===
 +<​Code>​
 +ast_node_def('​Java',​annotationT,​[
 +     ​ast_arg(id, ​            ​mult(1,​1,​no ),  id, [id]),
 +     ​ast_arg(parent, ​        ​mult(1,​1,​no ),  id, [id]),
 +     ​ast_arg(encl, ​          ​mult(1,​1,​no ),  id, [id]),
 +     ​ast_arg(annotationType,​ mult(1,1,no ),  id, [classT]),
 +     ​ast_arg(values, ​        ​mult(0,​*,​ord ), id, [annotationExpressionType,​ memberValueT])
 +]).
 +</​Code>​
 +/*
 +=== //Rationale (For the review process!)// ===
 +
 +First - the id may surprise you, because you may have expected an attribute (without an own ID) here.
 +But, annotations are expressions which can optionally be nested. So we need a unique ID here, e.g. for ''​ @Ann(value = 1, ann1 = @Ann2(id=1)) ''​.
 +
 +My main concern with this solution is the parent link to the annotated PEF, which does not link back.
 +This is a unique property in the AST. annotationT builds up a subtree of a PEF, but is not referenced by its parent.
 +checkTreeLinks will be disappointed. ;-)\\ 
 +In the future this will not be an issue anymore once we get rid of this AST and use a pure graph of nodes and edges.
 +But by now, I don't like to introduce another specialty.\\ ​
 +Any suggestions?​
 +
 +
 +  * //To me this sound bearable as the "​problem"​ is something we want anyway in the long term. The special case in checkTreeLinks is not that tragic. I had the impression that checkTreeLinks isn't really used a lot (is it still used at all)? -- G?nter//
 +
 +
 +
 +
 +
 +The structure was chosen because I wanted to avoid adding different PEFs for the same
 +construct. The first idea was to use ''​annotationT(#​id,​ #parent, #encl, #​annotationType,​ '​null'​ | #​expression| [#​keyValue_1,​..] ) ''​
 +with '​null'​ for marker, #expression for simple and a list for the normal annotations.
 +But, this is not expressible in the chosen AST specification structure (ast_node_def),​ see the bottom of this page.
 +
 +
 +
 +Either an argument is a list (mult(0,​*,​ord) or its not a list, both alternatives are not expressible.
 +
 +
 +
 +Since the marker annotations are semantically equivalent to normal annotations with an empty list I thought
 +an attribute would be the most clean solution here since queries can ignore this detail here.
 +
 +
 +=== //End Rationale (For the review process!)// ===
 +*/
research/jtransformer/api/java/pefs/4.0/annotationt.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2019