Another 5 lines of code for a main() method and it can probably Run As->Java Application.
public static void main(String[] args) { StandaloneApplication standaloneApplication = new StandaloneApplication(); standaloneApplication.execute(args); }
let result : Integer = Person.allInstances()->select(a | a.coactors->exists(areCoupleCoactors(a)))->size()
Library library = getLibrary(resourceSet); // get library from a hypothetical source // use the constraints defined in the OCL document // use getBooks() from the document in another query to find a book ExpressionInOCL expression = ocl.createQuery(EXTLibraryPackage.Literals.LIBRARY, "getBooks('Bleak House')->asSequence()->first()"); Book book = (Book) ocl.evaluate(library, expression); debugPrintf("Got book: %s%n\n", book);
URI uri = getInputURI("/models/documentation/parsingDocumentsExample.ocl");
final Resource scriptResource = ocl.parse(org.eclipse.emf.common.util.URI.createURI(script.toUri().toString())); for (EObject eObj : (Iterable<EObject>) scriptResource::getAllContents) { if (eObj instanceof Operation) { Operation op = (Operation) eObj; if ("QUERY".equals(op.getName())) { EObject contextElement = null; // What should this be? ExpressionInOCL asQuery = ocl.createQuery(contextElement, op.getBodyExpression().getBody()); System.out.println(ocl.evaluate(contextElement, asQuery)); } } }
def: QUERY() : Integer = Person.allInstances()->select(a | a.coactors->exists(areCoupleCoactors(a)))->size()
org.eclipse.ocl.pivot.utilities.SemanticException: The «unknown» '«null»' is invalid: 'Person.allInstances()->select(a | a.coactors->exists(areCoupleCoactors(a)))->size()' 1:1: Unresolved Property '::Person' 1:37: Unresolved Property 'OclInvalid::coactors'
String typeName = "Actor"; EClass targetType = metamodelPackage.eContents().stream().map(EObject::eClass).filter(e -> e.getName().equals(typeName)).findAny().orElse(null); EObject contextElement = modelResource.getContents().stream().filter(e -> e.eClass().equals(targetType)).findAny().orElse(null);
Exception in thread "main" org.eclipse.ocl.pivot.utilities.SemanticException: The «unknown» '«null»' is invalid: 'Person.allInstances()->select(a | a.coactors->exists(areCoupleCoactors(a)))->size()' 1: Unresolved Iteration '::select(a| a.coactors->exists(areCoupleCoactors(a)))' 1: No implicit source at org.eclipse.ocl.pivot.utilities.PivotUtil.checkResourceErrors(PivotUtil.java:210) at org.eclipse.ocl.pivot.internal.context.AbstractParserContext.parse(AbstractParserContext.java:233) at org.eclipse.ocl.pivot.internal.helper.OCLHelperImpl.createQuery(OCLHelperImpl.java:133) at org.eclipse.ocl.pivot.utilities.OCL.createQuery(OCL.java:281) at Minimal.main(Minimal.java:51)
public static void main(String... args) throws Exception { CompleteOCLStandaloneSetup.doSetup(); OCL ocl = OCL.newInstance(); ResourceSet resourceSet = ocl.getResourceSet(); resourceSet.getPackageRegistry().put(MoviesPackage.eNS_URI, MoviesPackage.eINSTANCE); //metamodelPackage); // Model String modelFilePath = "model/imdb-small.xmi"; URI modelUri = URI.createURI(modelFilePath); Resource modelResource = resourceSet.getResource(modelUri, true); // Script String scriptFilePath = "model/script.ocl"; ASResource scriptResource = ocl.parse(URI.createURI(scriptFilePath)); EObject contextElement = modelResource.getContents().get(0); ExpressionInOCL asQuery = ocl.createQuery(contextElement.eClass(), "Person.allInstances()->select(a | a.coactors->exists(areCoupleCoactors(a)))->size()"); System.out.println(ocl.evaluate(contextElement, asQuery)); ocl.dispose(); }
"/path/to/script.ocl" "/path/to/imdb-0.5.xmi" "/path/to/movies.ecore" -profile -results
public @NonNull List<CollectionLiteralPart> getOwnedParts() { if (ownedParts == null) { ownedParts = new EObjectContainmentEList<CollectionLiteralPart>(CollectionLiteralPart.class, this, 10); } return ownedParts; }
though intuitively I don't see why in principle a flat model with just two element types is so much "worse" in performance terms
I was toying with raising an EMF bug