Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

- Trivial recovery strategy to generate model elements for unresolved proxy objects
- Parser: `TextBlock`s are converted to `TextBockReference`s so that model elements are generated for text blocks
- Performance Test:
- Performs trivial recovery
- Measures model storage

### Changed

Expand All @@ -34,6 +37,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
### Fixed

- First variant: always returns an empty model (temporary fix to not end in an endless loop)
- Class file parser: creates bodies for methods and constructors

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import tools.mdsd.jamopp.model.java.modifiers.ModifiersFactory;
import tools.mdsd.jamopp.model.java.parameters.Parameter;
import tools.mdsd.jamopp.model.java.parameters.ParametersFactory;
import tools.mdsd.jamopp.model.java.statements.StatementsFactory;
import tools.mdsd.jamopp.model.java.types.ClassifierReference;
import tools.mdsd.jamopp.model.java.types.TypeReference;
import tools.mdsd.jamopp.model.java.types.TypedElement;
Expand Down Expand Up @@ -215,6 +216,10 @@ private Member constructMethod(org.apache.bcel.classfile.Method method,
emfMethod = membersFactory.createClassMethod();
}
emfMethod.setName(method.getName());

var block = StatementsFactory.eINSTANCE.createBlock();
block.setName("");
emfMethod.setStatement(block);

String signature = method.getReturnType().getSignature();
String plainSignature = "";
Expand Down Expand Up @@ -302,6 +307,7 @@ private Member constructMethod(org.apache.bcel.classfile.Method method,
constructor.getTypeParameters().addAll(emfMethod.getTypeParameters());
constructor.getParameters().addAll(emfMethod.getParameters());
constructor.setName(emfClassifier.getName());
constructor.setBlock(block);
return constructor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private void setUpResourceSet() {

private ASTParser setUpParser() {
ASTParser parser = ASTParser.newParser(AST.JLS15);
parser.setResolveBindings(true);
parser.setResolveBindings(ParserOptions.RESOLVE_BINDINGS.isTrue());
parser.setStatementsRecovery(true);
Map<String, String> compilerOptions = new HashMap<>();
compilerOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_15);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@

import tools.mdsd.jamopp.model.java.classifiers.Annotation;
import tools.mdsd.jamopp.model.java.classifiers.ClassifiersFactory;
import tools.mdsd.jamopp.model.java.classifiers.Enumeration;
import tools.mdsd.jamopp.model.java.containers.CompilationUnit;
import tools.mdsd.jamopp.model.java.containers.ContainersFactory;
import tools.mdsd.jamopp.model.java.members.ClassMethod;
import tools.mdsd.jamopp.model.java.members.EnumConstant;
import tools.mdsd.jamopp.model.java.members.Field;
import tools.mdsd.jamopp.model.java.members.InterfaceMethod;
import tools.mdsd.jamopp.model.java.members.MembersFactory;
Expand All @@ -42,13 +44,15 @@ public class TrivialRecovery {
private ResourceSet set;
private Resource artificialResource;
private CompilationUnit artificialCU;
private Enumeration artificialEnum;
private tools.mdsd.jamopp.model.java.classifiers.Class artificialClass;
private tools.mdsd.jamopp.model.java.classifiers.Class objectClass;
private HashMap<String, tools.mdsd.jamopp.model.java.classifiers.Class> artClasses = new HashMap<>();
private HashMap<String, Annotation> artAnnotations = new HashMap<>();
private HashMap<String, Field> artFields = new HashMap<>();
private HashMap<String, ClassMethod> artClassMethods = new HashMap<>();
private HashMap<String, InterfaceMethod> artInterfaceMethods = new HashMap<>();
private HashMap<String, EnumConstant> artEnumConstants = new HashMap<>();
private HashMap<String, tools.mdsd.jamopp.model.java.containers.Package> artPackages = new HashMap<>();
private HashMap<String, tools.mdsd.jamopp.model.java.containers.Module> artModules = new HashMap<>();

Expand All @@ -66,6 +70,9 @@ public void recover() {
EList<EObject> list = (EList<EObject>) setting.getEObject()
.eGet(setting.getEStructuralFeature());
var idx = list.indexOf(proxy);
if (idx == -1) {
continue;
}
list.set(idx, actualElement);
} else {
setting.getEObject().eSet(setting.getEStructuralFeature(), actualElement);
Expand Down Expand Up @@ -152,6 +159,15 @@ private EObject recoverActualElement(EObject obj) {
this.artificialResource.getContents().add(result);
this.artModules.put(name, result);
return result;
} else if (obj instanceof EnumConstant) {
if (this.artEnumConstants.containsKey(name)) {
return this.artEnumConstants.get(name);
}
var result = MembersFactory.eINSTANCE.createEnumConstant();
result.setName(name);
this.artificialEnum.getConstants().add(result);
this.artEnumConstants.put(name, result);
return result;
}
return null;
}
Expand All @@ -168,17 +184,28 @@ private void initArtificialResource() {
this.artificialClass.setName("SyntheticClass");
this.artificialCU.getClassifiers().add(this.artificialClass);

this.artificialEnum = ClassifiersFactory.eINSTANCE.createEnumeration();
this.artificialEnum.setName("SyntheticEnum");
this.artificialCU.getClassifiers().add(this.artificialEnum);

this.objectClass = findObjectClass();
this.artClasses.put("Object", objectClass);
}
}

private tools.mdsd.jamopp.model.java.classifiers.Class findObjectClass() {
return this.set.getResources().stream().filter(resource -> !resource.getContents().isEmpty()
var optionalResult = this.set.getResources().stream().filter(resource -> !resource.getContents().isEmpty()
&& resource.getContents().get(0) instanceof CompilationUnit)
.map(resource -> (CompilationUnit) resource.getContents().get(0))
.filter(cu -> cu.getNamespaces().size() == 2 && cu.getNamespaces().get(0).equals("java")
&& cu.getNamespaces().get(1).equals("lang") && cu.getName().equals("Object"))
.map(cu -> (tools.mdsd.jamopp.model.java.classifiers.Class) cu.getClassifiers().get(0)).findFirst().get();
.map(cu -> (tools.mdsd.jamopp.model.java.classifiers.Class) cu.getClassifiers().get(0)).findFirst();
if (optionalResult.isPresent()) {
return optionalResult.get();
}
tools.mdsd.jamopp.model.java.classifiers.Class ownObjectClass = ClassifiersFactory.eINSTANCE.createClass();
ownObjectClass.setName("Object");
this.artificialCU.getClassifiers().add(ownObjectClass);
return ownObjectClass;
}
}
8 changes: 8 additions & 0 deletions jamopp.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,13 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.emfcloud</groupId>
<artifactId>emfjson-jackson</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package tools.mdsd.jamopp.test;

import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.XMIResource;

import tools.mdsd.jamopp.model.java.containers.CompilationUnit;
import tools.mdsd.jamopp.model.java.containers.JavaRoot;
import tools.mdsd.jamopp.model.java.containers.Package;

public class OutputUtility {
public record TransferResult(ResourceSet targetSet, Map<Resource, Resource> sourceTargetMapping) {};

public static TransferResult transferToOutput(ResourceSet sourceSet, String outputFolder, String fileExtension, boolean includeAllResources) {
int emptyFileName = 0;

ResourceSet targetSet = new ResourceSetImpl();
HashMap<Resource, Resource> srcTrgMap = new HashMap<>();

for (Resource javaResource : new ArrayList<>(sourceSet.getResources())) {
if (javaResource.getContents().isEmpty()) {
System.out.println("WARNING: Emtpy Resource: " + javaResource.getURI());
continue;
}
if (!includeAllResources && !javaResource.getURI().isFile()) {
continue;
}

JavaRoot root = (JavaRoot) javaResource.getContents().get(0);
String outputFileName = "ERROR";
if (root instanceof CompilationUnit cu) {
outputFileName = cu.getNamespacesAsString().replace(".", File.separator) + File.separator;
if (cu.getClassifiers().size() > 0) {
outputFileName += cu.getClassifiers().get(0).getName();
} else {
outputFileName += emptyFileName++;
}
} else if (root instanceof Package) {
outputFileName = root.getNamespacesAsString()
.replace(".", File.separator) + File.separator + "package-info";
if (outputFileName.startsWith(File.separator)) {
outputFileName = outputFileName.substring(1);
}
} else if (root instanceof tools.mdsd.jamopp.model.java.containers.Module) {
outputFileName = root.getNamespacesAsString()
.replace(".", File.separator) + File.separator + "module-info";
} else {
fail();
}

File outputFile = new File("." + File.separator + outputFolder
+ File.separator + outputFileName);
URI fileURI = URI.createFileURI(outputFile.getAbsolutePath()).appendFileExtension(fileExtension);

Resource targetResource = targetSet.createResource(fileURI);
if (targetResource instanceof XMIResource xmiResource) {
xmiResource.setEncoding(StandardCharsets.UTF_8.toString());
}
targetResource.getContents().addAll(javaResource.getContents());
srcTrgMap.put(javaResource, targetResource);
}

for (Resource targetResource : new ArrayList<>(targetSet.getResources())) {
try {
targetResource.save(targetSet.getLoadOptions());
} catch (Exception e) {
e.printStackTrace();
}
}

return new TransferResult(targetSet, srcTrgMap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import com.google.gson.Gson;

Expand All @@ -27,13 +28,28 @@
*/
public class PerformanceData {
private ArrayList<PerformanceDataPoint> points = new ArrayList<>();
private ArrayList<StoragePerformance> storage = new ArrayList<>();

public ArrayList<PerformanceDataPoint> getPoints() {
return points;
public List<PerformanceDataPoint> getPoints() {
return (List<PerformanceDataPoint>) points.clone();
}

public void addPoint(PerformanceDataPoint newPoint) {
this.points.add(newPoint);
}

public void setPoints(ArrayList<PerformanceDataPoint> points) {
this.points = points;
public void setPoints(List<PerformanceDataPoint> points) {
this.points.clear();
this.points.addAll(points);
}

public List<StoragePerformance> getStorage() {
return (List<StoragePerformance>) storage.clone();
}

public void setStorage(List<StoragePerformance> storage) {
this.storage.clear();
this.storage.addAll(storage);
}

public double getAverageParseTime() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
public class PerformanceDataPoint {
private long parseTime;
private long resolutionTime;
private long recoverTime;

public long getParseTime() {
return parseTime;
Expand All @@ -35,4 +36,12 @@ public long getResolutionTime() {
public void setResolutionTime(long resolutionTime) {
this.resolutionTime = resolutionTime;
}

public long getRecoverTime() {
return recoverTime;
}

public void setRecoverTime(long recoverTime) {
this.recoverTime = recoverTime;
}
}
Loading