From 1d43c802f853b08f03c4b3954af242ad005c8afd Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Fri, 29 Jul 2022 21:58:47 +0200 Subject: refactor: simplify language project * Move all utilities for language-model to language, since they do not make sense on their own * Convert xtend code into java --- subprojects/language-model/build.gradle | 1 - .../refinery/language/model/ProblemEMFSetup.java | 34 ---- .../src/main/resources/model/builtin.problem_xmi | 67 ------- .../language/model/tests/ProblemTestUtil.java | 197 --------------------- 4 files changed, 299 deletions(-) delete mode 100644 subprojects/language-model/src/main/java/tools/refinery/language/model/ProblemEMFSetup.java delete mode 100644 subprojects/language-model/src/main/resources/model/builtin.problem_xmi delete mode 100644 subprojects/language-model/src/testFixtures/java/tools/refinery/language/model/tests/ProblemTestUtil.java (limited to 'subprojects/language-model') diff --git a/subprojects/language-model/build.gradle b/subprojects/language-model/build.gradle index 67883a3d..275db188 100644 --- a/subprojects/language-model/build.gradle +++ b/subprojects/language-model/build.gradle @@ -1,6 +1,5 @@ plugins { id 'refinery-java-library' - id 'refinery-java-test-fixtures' id 'refinery-mwe2' id 'refinery-sonarqube' } diff --git a/subprojects/language-model/src/main/java/tools/refinery/language/model/ProblemEMFSetup.java b/subprojects/language-model/src/main/java/tools/refinery/language/model/ProblemEMFSetup.java deleted file mode 100644 index 9383098b..00000000 --- a/subprojects/language-model/src/main/java/tools/refinery/language/model/ProblemEMFSetup.java +++ /dev/null @@ -1,34 +0,0 @@ -package tools.refinery.language.model; - -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.resource.Resource; - -import tools.refinery.language.model.problem.ProblemPackage; -import tools.refinery.language.model.problem.impl.ProblemFactoryImpl; - -public class ProblemEMFSetup { - public static final String XMI_RESOURCE_EXTENSION = "problem_xmi"; - - private ProblemEMFSetup() { - throw new IllegalStateException("This is a static utility class and should not be instantiated directly"); - } - - // Here we can't rely on java.util.HashMap#putIfAbsent, because - // org.eclipse.emf.ecore.impl.EPackageRegistryImpl#containsKey is overridden - // without also overriding putIfAbsent. We must make sure to call the - // overridden containsKey implementation. - @SuppressWarnings("squid:S3824") - public static void doEMFRegistration() { - if (!EPackage.Registry.INSTANCE.containsKey(ProblemPackage.eNS_URI)) { - EPackage.Registry.INSTANCE.put(ProblemPackage.eNS_URI, ProblemPackage.eINSTANCE); - } - - // This Resource.Factory is not actually used once - // tools.refinery.language.ProblemStandaloneSetup.createInjectorAndDoEMFRegistration() - // is called, because if will be replaced by - // tools.refinery.language.resource.ProblemXmiResourceFactory, which implements - // org.eclipse.xtext.resource.IResourceFactory as required by Xtext. - Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().putIfAbsent(XMI_RESOURCE_EXTENSION, - new ProblemFactoryImpl()); - } -} diff --git a/subprojects/language-model/src/main/resources/model/builtin.problem_xmi b/subprojects/language-model/src/main/resources/model/builtin.problem_xmi deleted file mode 100644 index 9255ab66..00000000 --- a/subprojects/language-model/src/main/resources/model/builtin.problem_xmi +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/subprojects/language-model/src/testFixtures/java/tools/refinery/language/model/tests/ProblemTestUtil.java b/subprojects/language-model/src/testFixtures/java/tools/refinery/language/model/tests/ProblemTestUtil.java deleted file mode 100644 index d0990dc0..00000000 --- a/subprojects/language-model/src/testFixtures/java/tools/refinery/language/model/tests/ProblemTestUtil.java +++ /dev/null @@ -1,197 +0,0 @@ -package tools.refinery.language.model.tests; - -import java.util.List; -import java.util.stream.Stream; - -import org.eclipse.emf.ecore.resource.Resource.Diagnostic; -import org.eclipse.emf.ecore.util.EcoreUtil; - -import tools.refinery.language.model.ProblemUtil; -import tools.refinery.language.model.problem.ActionLiteral; -import tools.refinery.language.model.problem.Argument; -import tools.refinery.language.model.problem.Assertion; -import tools.refinery.language.model.problem.AssertionArgument; -import tools.refinery.language.model.problem.Atom; -import tools.refinery.language.model.problem.ClassDeclaration; -import tools.refinery.language.model.problem.Conjunction; -import tools.refinery.language.model.problem.DeleteActionLiteral; -import tools.refinery.language.model.problem.EnumDeclaration; -import tools.refinery.language.model.problem.IndividualDeclaration; -import tools.refinery.language.model.problem.Literal; -import tools.refinery.language.model.problem.NamedElement; -import tools.refinery.language.model.problem.NegativeLiteral; -import tools.refinery.language.model.problem.NewActionLiteral; -import tools.refinery.language.model.problem.Node; -import tools.refinery.language.model.problem.NodeAssertionArgument; -import tools.refinery.language.model.problem.NodeValueAssertion; -import tools.refinery.language.model.problem.Parameter; -import tools.refinery.language.model.problem.ParametricDefinition; -import tools.refinery.language.model.problem.PredicateDefinition; -import tools.refinery.language.model.problem.Problem; -import tools.refinery.language.model.problem.ReferenceDeclaration; -import tools.refinery.language.model.problem.Relation; -import tools.refinery.language.model.problem.RuleDefinition; -import tools.refinery.language.model.problem.Statement; -import tools.refinery.language.model.problem.ValueActionLiteral; -import tools.refinery.language.model.problem.ValueLiteral; -import tools.refinery.language.model.problem.Variable; -import tools.refinery.language.model.problem.VariableOrNode; -import tools.refinery.language.model.problem.VariableOrNodeArgument; - -public class ProblemTestUtil { - public Problem builtin(Problem problem) { - return ProblemUtil.getBuiltInLibrary(problem).get(); - } - - public List errors(Problem problem) { - EcoreUtil.resolveAll(problem); - return problem.eResource().getErrors(); - } - - public List nodeNames(Problem problem) { - return problem.getNodes().stream().map(node -> node.getName()).toList(); - } - - public PredicateDefinition pred(Problem problem, String name) { - return namedStatementOfType(problem, PredicateDefinition.class, name); - } - - public RuleDefinition rule(Problem problem, String name) { - return namedStatementOfType(problem, RuleDefinition.class, name); - } - - public Parameter param(ParametricDefinition definition, int i) { - return definition.getParameters().get(i); - } - - public Conjunction conj(ParametricDefinition definition, int i) { - return definition.getBodies().get(i); - } - - public Literal lit(Conjunction conjunction, int i) { - return conjunction.getLiterals().get(i); - } - - public ActionLiteral actionLit(RuleDefinition rule, int i) { - return rule.getAction().getActionLiterals().get(i); - } - - public Atom valueAtom(Literal literal) { - return ((ValueLiteral) literal).getAtom(); - } - - public Atom negated(Literal literal) { - return ((NegativeLiteral) literal).getAtom(); - } - - public Relation relation(Literal literal) { - return ((Atom) literal).getRelation(); - } - - public Argument arg(Atom atom, int i) { - return atom.getArguments().get(i); - } - - public Argument arg(Literal literal, int i) { - return arg((Atom) literal, i); - } - - public VariableOrNode variableOrNode(Argument argument) { - return ((VariableOrNodeArgument) argument).getVariableOrNode(); - } - - public Variable variable(Argument argument) { - return (Variable) variableOrNode(argument); - } - - public Variable variable(ValueActionLiteral valueActionLiteral, int i) { - return variable(arg(valueActionLiteral.getAtom(), i)); - } - - public Variable variable(NewActionLiteral newActionLiteral) { - return newActionLiteral.getVariable(); - } - - public VariableOrNode deleteVar(ActionLiteral actionLiteral) { - return ((DeleteActionLiteral) actionLiteral).getVariableOrNode(); - } - - public VariableOrNode newVar(ActionLiteral actionLiteral) { - return ((NewActionLiteral) actionLiteral).getVariable(); - } - - public Atom valueAtom(ActionLiteral actionLiteral) { - return ((ValueActionLiteral) actionLiteral).getAtom(); - } - - public Variable variable(DeleteActionLiteral deleteActionLiteral) { - return (Variable) deleteActionLiteral.getVariableOrNode(); - } - - public Node node(Argument argument) { - return (Node) variableOrNode(argument); - } - - public Assertion assertion(Problem problem, int i) { - return nthStatementOfType(problem, Assertion.class, i); - } - - public AssertionArgument arg(Assertion assertion, int i) { - return assertion.getArguments().get(i); - } - - public Node node(AssertionArgument argument) { - return ((NodeAssertionArgument) argument).getNode(); - } - - public Node node(Problem problem, String name) { - return named(problem.getNodes(), name); - } - - public Node individualNode(Problem problem, String name) { - var uniqueNodes = statementsOfType(problem, IndividualDeclaration.class) - .flatMap(declaration -> declaration.getNodes().stream()); - return named(uniqueNodes, name); - } - - public NodeValueAssertion nodeValueAssertion(Problem problem, int i) { - return nthStatementOfType(problem, NodeValueAssertion.class, i); - } - - public ClassDeclaration findClass(Problem problem, String name) { - return namedStatementOfType(problem, ClassDeclaration.class, name); - } - - public ReferenceDeclaration reference(ClassDeclaration declaration, String name) { - return named(declaration.getReferenceDeclarations(), name); - } - - public EnumDeclaration findEnum(Problem problem, String name) { - return namedStatementOfType(problem, EnumDeclaration.class, name); - } - - public Node literal(EnumDeclaration declaration, String name) { - return named(declaration.getLiterals(), name); - } - - private T named(Stream stream, String name) { - return stream.filter(statement -> name.equals(statement.getName())).findAny().get(); - } - - private T named(List list, String name) { - return named(list.stream(), name); - } - - private Stream statementsOfType(Problem problem, Class type) { - return problem.getStatements().stream().filter(type::isInstance).map(type::cast); - } - - private T namedStatementOfType(Problem problem, Class type, - String name) { - return named(statementsOfType(problem, type), name); - } - - private T nthStatementOfType(Problem problem, Class type, int n) { - return statementsOfType(problem, type).skip(n).findFirst().get(); - } -} -- cgit v1.2.3-54-g00ecf