Skip to content

Commit

Permalink
The trivial recovery also recovers EnumConstants (#23).
Browse files Browse the repository at this point in the history
  • Loading branch information
HansMartinA committed Jul 31, 2023
1 parent 4ef98d5 commit e269a38
Showing 1 changed file with 20 additions and 0 deletions.
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,6 +184,10 @@ 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);
}
Expand Down

0 comments on commit e269a38

Please sign in to comment.