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

Next revision
Previous revision
research:jtransformer:api:java:pefs:2.9:compilationunitt [2010/12/18 07:13]
127.0.0.1 external edit
research:jtransformer:api:java:pefs:2.9:compilationunitt [2018/05/09 01:59] (current)
Line 1: Line 1:
 +{{page>​prologast_bodypef_index&​fullpage&​nofooter}}
 +----
 +
 +=== compilationUnitT(#​id,​ #package, #fileS, [#import_1, ...], [#def_1, ...] )  ===
 +
 +
 +Represents a Java compilation unit, that is a file that contains a set of import and type declarations that are compiled together and
 +belong to the same package. The import and type declarations are children of the compilation unit. The package is the parent of the compilation unit. The file is a reference to an element that is not part of the Java AST. This is specified by:
 +
 +
 +=== Arguments ===
 +==  ==
 +**#id:** id\\ 
 +the unique ID assigned to this fact.
 +
 +**#​package:​** [[packageT|packageT]],​ '​defaultPackage'​ \\ 
 +Id of the containing package or '​defaultPackage'​.
 +
 +**#file:** [[..:​..:​..:​meta:​pefs:​fileS|fileS]],​ '​dummyFile'​ \\ 
 +Id of the file that contains this compilation unit or '​dummyFile'​ for Bytecode classes.
 +
 +**[#​import_1,​...]:​** [[importT|importT]]\\
 +List of IDs of import declarations contained in the compilation unit. The order in the list corresponds to the textual order in the file.
 +
 +**[#​def_1,​...]:​** [[classT|classT]]\\
 +List of IDs of type declarations contained in the compilation unit. The order in the list corresponds to the textual order in the file.
 +
 +/**
 +The above structure of a compilationUnitT node is specified by the following meta-model description:​
 +
 +<code Prolog>
 +ast_node_def('​Java',​compilationUnitT,​[
 +     ​ast_arg(id, ​    ​mult(1,​1,​no ), id,    [compilationUnitT]), ​
 +     ​ast_arg(parent,​ mult(0,​1,​no), ​ id,    [packageT]),​
 +     ​ast_arg(file, ​  ​mult(1,​1,​no ), id,    [fileS]), ​    
 +     ​ast_arg(imports,​mult(0,​*,​ord),​ id,    [importT]), ​  
 +     ​ast_arg(defs, ​  ​mult(0,​*,​ord),​ id,    [classDefT])  ​
 +]).
 +
 +ast_ref_tree('​Java',​file). ​    % The '​file'​ argument references an AST element that is neither a child nor a parent of the compilation unit.
 +
 +ast_sub_tree('​Java',​imports). ​ % The '​imports'​ argumentis a reference to children.
 +ast_sub_tree('​Java',​defs). ​    % The '​defs'​ argument is a reference to children.
 +</​Code>​
 +
 +=== Migration ===
 +Notes about the migration from code that uses the Java metamodel before JT 2.6.0.
 +
 +==  ==
 +
 +[[compilationUnitT|compilationUnitT]] evolved from ''​[[fileT|fileT]]'',​ whose third argument was a file name instead of a reference to a ''​[[fileS|fileS]]''​ fact. Migrating to the new representation requires replacing any 
 +<code Prolog>
 +  fileT(Id, Package, Filename, Definitions) ​
 +</​Code>​
 +by 
 +<code Prolog>
 +  separate_imports_from_types(Definitions,​ Imports, Types),
 +  compilationUnitT(Id,​ Package, FileId, Imports, Types),
 +  fileS(FileId,​ SourceFolder,​ Filename).
 +</​Code>​
 +
 +In addition, classDefT now does not reference a package as a parent but refers instead to a compilation unit. So any 
 +<code Prolog>
 +  classDefT(Id,​ Package, Classname, Definitions) ​
 +</​Code>​
 +must be checked manually. In cases where
 +the existing code does not use the package reference (that is, the package reference is an anonymous or singleton variable)
 +one does not need to change anything, except singleton variable names: ​
 +<code Prolog>
 +  classDefT(Id,​ __CompilationUnit,​ Classname, Definitions)
 +</​Code>​
 +If the package reference is relevant, one must write
 +<code Prolog>
 +  classDefT(Id,​ CompilationUnit,​ Classname, Definitions)
 +  compilationUnitT(CompilationUnit,​ Package, _, _, _)
 +</​Code>​
 +
 +<​note>​ Note that byte-code classes refer to a dummy compilation unit that refers to a dummy file with the ID '​dummyFile',​ the correct package, an empty list of imports and a type definition list that only contains the respective byte-code class. For each class #C for which "​externT(#​C)"​ is true, we have the following representation:​
 +
 +<code Prolog>
 +  externT(#​C).
 +  classDefT(#​C,​ #​CompilationUnit,​ Classname, Definitions).
 +  compilationUnitT(#​CompilationUnit,​ #Package, '​dummyFile',​ [], [#C]).
 +</​Code>​
 +
 +FIXME This note must be integrated in the documentation of [[classDefT]]. Please don't overwrite the old documentation but move it
 +to a separate page that is referenced from the official classDefT page, mentioning in which version the change occurred and what is to be done for migration!. FIXME 
 +</​note>​ **/
 +=== Sample Java Source ===
 +
 + ​== ​ ==
 +<Code lang-java>​
 +package packaged;
 +
 +import java.util.List;​
 +
 +public class DummyClass {
 + List list;
 +}
 +</​Code>​
 +
 +
 +=== Its PEF Representation ===
 +==  ==
 +<Code lang-prolog>​
 +packageT(#​Package,​ '​packaged'​),​
 +compilationUnitT(#​CompilationUnit,​ #Package, #File, [#Import], [#Class]),
 +importT(#​Import,​ #​CompilationUnit,​ #Imported),
 +classT(#​Class,​ #​CompilationUnit,​ '​DummyClass',​ [#Field]),
 +fieldT(...
 +</​Code>​
 +
 +=== AST Specification ===
 +== ==
 +<​Code>​
 +ast_node_def('​Java',​compilationUnitT,​[
 +     ​ast_arg(id, ​    ​mult(1,​1,​no ), id,    [compilationUnitT]),​
 +     ​ast_arg(parent,​ mult(0,​1,​no), ​ id,    [packageT,'​defaultPackage'​]),​
 +     ​ast_arg(file, ​  ​mult(1,​1,​no ), id,    [fileS,'​dummyFile'​]), ​ %dummyFile for byteCode classes.
 +     ​ast_arg(imports,​mult(0,​*,​ord),​ id,    [importT]),
 +     ​ast_arg(defs, ​  ​mult(0,​*,​ord),​ id,    [classT])
 +]).
 +</​Code>​
  
research/jtransformer/api/java/pefs/2.9/compilationunitt.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2019