Просмотр исходного кода

Add and improve the documentation of the EMF frontend.

Timur Sağlam 4 лет назад
Родитель
Сommit
b5e416d3c0

+ 19 - 5
jplag.frontend.emf/src/main/java/de/jplag/emf/AbstractMetamodelVisitor.java

@@ -5,17 +5,20 @@ import java.util.List;
 import org.eclipse.emf.ecore.*;
 import org.eclipse.emf.ecore.*;
 import org.eclipse.emf.ecore.EAnnotation;
 import org.eclipse.emf.ecore.EAnnotation;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
 
 
+/**
+ * Visitor for the containment tree of an EMF Metamodel.
+ * @author Timur Saglam
+ */
 public abstract class AbstractMetamodelVisitor {
 public abstract class AbstractMetamodelVisitor {
 
 
     private int currentTreeDepth;
     private int currentTreeDepth;
 
 
+    /**
+     * Visits an EObject and all nodes in the containment tree below.
+     * @param eObject is the EObject to visit.
+     */
     public final void visit(EObject eObject) {
     public final void visit(EObject eObject) {
-        String name = "";
-        if (eObject instanceof ENamedElement el)
-            name += " " + el.getName();
-        System.out.println(eObject.eClass().getName() + name + " -> " + EcoreUtil.getURI(eObject));
         if (eObject instanceof EPackage ePackage) {
         if (eObject instanceof EPackage ePackage) {
             visitEPackage(ePackage);
             visitEPackage(ePackage);
         }
         }
@@ -64,10 +67,18 @@ public abstract class AbstractMetamodelVisitor {
         currentTreeDepth--;
         currentTreeDepth--;
     }
     }
 
 
+    /**
+     * Returns the current depth in the containment tree from the starting point.
+     * @return the depth in tree node levels.
+     */
     public int getCurrentTreeDepth() {
     public int getCurrentTreeDepth() {
         return currentTreeDepth;
         return currentTreeDepth;
     }
     }
 
 
+    /**
+     * Visit method that gets called for all annotation nodes.
+     * @param eAnnotation is the node that is visited.
+     */
     protected void visitEAnnotation(EAnnotation eAnnotation) {
     protected void visitEAnnotation(EAnnotation eAnnotation) {
     }
     }
 
 
@@ -107,6 +118,9 @@ public abstract class AbstractMetamodelVisitor {
     protected void visitEStructuralFeature(EStructuralFeature eStructuralFeature) {
     protected void visitEStructuralFeature(EStructuralFeature eStructuralFeature) {
     }
     }
 
 
+    /**
+     * TODO TS: Remove generator method.
+     */
     public static void main(String[] args) {
     public static void main(String[] args) {
         List<String> types = List.of("EPackage", "EAnnotation", "EClassifier", "EClass", "EDataType", "EStructuralFeature", "EAttribute",
         List<String> types = List.of("EPackage", "EAnnotation", "EClassifier", "EClass", "EDataType", "EStructuralFeature", "EAttribute",
                 "EReference", "EOperation", "EEnum", "EEnumLiteral", "EParameter");
                 "EReference", "EOperation", "EEnum", "EEnumLiteral", "EParameter");

+ 9 - 4
jplag.frontend.emf/src/main/java/de/jplag/emf/MetamodelToken.java

@@ -16,12 +16,9 @@ public class MetamodelToken extends Token implements MetamodelTokenConstants {
     private final Optional<EObject> eObject;
     private final Optional<EObject> eObject;
 
 
     /**
     /**
-     * Creates an Ecore metamodel token.
+     * Creates an Ecore metamodel token that corresponds to an EObject.
      * @param type is the corresponding ID of the {@link TokenConstants}.
      * @param type is the corresponding ID of the {@link TokenConstants}.
      * @param file is the name of the source model file.
      * @param file is the name of the source model file.
-     * @param line is the line index in the metamodel where the token resides. Cannot be smaller than 1.
-     * @param column is the column index, meaning where the token starts in the line.
-     * @param length is the length of the token in the metamodel.
      * @param eObject is the corresponding eObject from which this token was extracted.
      * @param eObject is the corresponding eObject from which this token was extracted.
      */
      */
     public MetamodelToken(int type, String file, EObject eObject) {
     public MetamodelToken(int type, String file, EObject eObject) {
@@ -29,11 +26,19 @@ public class MetamodelToken extends Token implements MetamodelTokenConstants {
         this.eObject = Optional.of(eObject);
         this.eObject = Optional.of(eObject);
     }
     }
 
 
+    /**
+     * Creates an Ecore metamodel token.
+     * @param type is the corresponding ID of the {@link TokenConstants}.
+     * @param file is the name of the source model file.
+     */
     public MetamodelToken(int type, String file) {
     public MetamodelToken(int type, String file) {
         super(type, file, -1);
         super(type, file, -1);
         this.eObject = Optional.empty();
         this.eObject = Optional.empty();
     }
     }
 
 
+    /**
+     * @return the optional corresponding EObject of the token.
+     */
     public Optional<EObject> getEObject() {
     public Optional<EObject> getEObject() {
         return eObject;
         return eObject;
     }
     }

+ 1 - 1
jplag.frontend.emf/src/main/java/de/jplag/emf/MetamodelTokenConstants.java

@@ -28,5 +28,5 @@ public interface MetamodelTokenConstants extends TokenConstants {
     /*
     /*
      * Number of token constants:
      * Number of token constants:
      */
      */
-    int NUM_DIFF_TOKENS = 14;
+    int NUM_DIFF_TOKENS = 19;
 }
 }

+ 18 - 0
jplag.frontend.emf/src/main/java/de/jplag/emf/MetamodelTreeView.java

@@ -9,6 +9,10 @@ import java.util.List;
 
 
 import org.eclipse.emf.ecore.ENamedElement;
 import org.eclipse.emf.ecore.ENamedElement;
 
 
+/**
+ * Simplcisitc tree view representation of an EMF metamodel.
+ * @author Timur Saglam
+ */
 public class MetamodelTreeView {
 public class MetamodelTreeView {
     private final String fileName;
     private final String fileName;
     private final List<MetamodelToken> tokens;
     private final List<MetamodelToken> tokens;
@@ -17,12 +21,21 @@ public class MetamodelTreeView {
     private final StringBuilder viewBuilder;
     private final StringBuilder viewBuilder;
     private final static String INDENTATION = "  ";
     private final static String INDENTATION = "  ";
 
 
+    /**
+     * Creates a tree view for a metamodel.
+     * @param fileName is the file where the metamodel is persisted.
+     */
     public MetamodelTreeView(String fileName) {
     public MetamodelTreeView(String fileName) {
         this.fileName = fileName;
         this.fileName = fileName;
         tokens = new ArrayList<>();
         tokens = new ArrayList<>();
         viewBuilder = new StringBuilder();
         viewBuilder = new StringBuilder();
     }
     }
 
 
+    /**
+     * Adds a token to the view, thus adding the index information to the token.
+     * @param token is the token to add.
+     * @param treeDepth is the current containment tree depth, required for the indentation.
+     */
     public void addToken(MetamodelToken token, int treeDepth) {
     public void addToken(MetamodelToken token, int treeDepth) {
         token.getEObject().ifPresent(it -> {
         token.getEObject().ifPresent(it -> {
             tokens.add(token);
             tokens.add(token);
@@ -55,6 +68,11 @@ public class MetamodelTreeView {
 
 
     }
     }
 
 
+    /**
+     * Writes the tree view into a file.
+     * @param directory is the output directory.
+     * @param suffix is the suffix of the file to be written.
+     */
     public void writeToFile(File directory, String suffix) {
     public void writeToFile(File directory, String suffix) {
         File treeViewFile = fileName.isEmpty() ? new File(directory.toString() + suffix) : new File(directory, fileName + suffix);
         File treeViewFile = fileName.isEmpty() ? new File(directory.toString() + suffix) : new File(directory, fileName + suffix);
         try (BufferedWriter writer = new BufferedWriter(new FileWriter(treeViewFile));) {
         try (BufferedWriter writer = new BufferedWriter(new FileWriter(treeViewFile));) {

+ 8 - 0
jplag.frontend.emf/src/main/java/de/jplag/emf/TokenGeneratingMetamodelVisitor.java

@@ -26,9 +26,17 @@ import org.eclipse.emf.ecore.EPackage;
 import org.eclipse.emf.ecore.EParameter;
 import org.eclipse.emf.ecore.EParameter;
 import org.eclipse.emf.ecore.EReference;
 import org.eclipse.emf.ecore.EReference;
 
 
+/**
+ * Visits a metamodel containment tree and extracts the relevant token.
+ * @author Timur Saglam
+ */
 public class TokenGeneratingMetamodelVisitor extends AbstractMetamodelVisitor {
 public class TokenGeneratingMetamodelVisitor extends AbstractMetamodelVisitor {
     private EcoreParser parser;
     private EcoreParser parser;
 
 
+    /**
+     * Creates the visitor.
+     * @param parser is the parser which receives the generated tokens.
+     */
     public TokenGeneratingMetamodelVisitor(EcoreParser parser) {
     public TokenGeneratingMetamodelVisitor(EcoreParser parser) {
         this.parser = parser;
         this.parser = parser;
     }
     }