public ResourceSet createResourceSet() { Environment.Registry.INSTANCE.registerEnvironment( new UMLEnvironmentFactory().createEnvironment()); ResourceSet resourceSet = new ResourceSetImpl(); OCL.initialize(resourceSet); // Make sure that the UML metamodel and primitive types // libraries are loaded umlMetamodel = (Package) resourceSet .getResource(URI.createURI(UMLResource.UML_METAMODEL_URI), true) .getContents() .get(0); umlPrimitiveTypes = (Package) resourceSet .getResource(URI.createURI(UMLResource.UML_PRIMITIVE_TYPES_LIBRARY_URI), true) .getContents() .get(0); ecorePrimitiveTypes = (Package) resourceSet .getResource(URI.createURI(UMLResource.ECORE_PRIMITIVE_TYPES_LIBRARY_URI), true) .getContents() .get(0); return resourceSet; }
public OCL createOCL(ResourceSet resourceSet) { return OCL.newInstance(resourceSet); }
/** Tests the definition of additional attributes on an OCL pre-defined type. */ public void test_defOperationOnPredefinedType_172782() { // context is the predefined OCL String type helper.setContext(ocl.getEnvironment().getOCLStandardLibrary().getString()); try { Operation feature = helper.defineOperation( "reversed() : String = " + "Sequence{1..size()}->sortedBy(i | -i)->iterate(i; s : String = '' |" + " s.concat(self.substring(i, i)))"); // the other representation of 'String' helper.setContext(getUMLString()); Collection<Choice> choices = helper.getSyntaxHelp(ConstraintKind.INVARIANT, "self."); assertChoice(choices, ChoiceKind.OPERATION, "reversed"); OCLExpression<Classifier> expr = helper.createQuery("self.reversed()"); assertEquals("ablE was i ere I saw elbA", ocl.evaluate("Able was I ere i saw Elba", expr)); // verify that TypeUtil produces the correct result assertTrue( TypeUtil.getOperations( ocl.getEnvironment(), ocl.getEnvironment().getOCLStandardLibrary().getString()) .contains(feature)); assertTrue(TypeUtil.getOperations(ocl.getEnvironment(), getUMLString()).contains(feature)); } catch (Exception e) { fail("Failed to parse or evaluate: " + e.getLocalizedMessage()); } // now, make sure that this definition was local to the OCL that // parsed it (that it is not shared via the standard library package) OCL localOCL = OCL.newInstance(); OCL.Helper localHelper = localOCL.createOCLHelper(); localHelper.setContext(ocl.getEnvironment().getOCLStandardLibrary().getString()); try { Collection<Choice> choices = localHelper.getSyntaxHelp(ConstraintKind.INVARIANT, "self."); assertNotChoice(choices, ChoiceKind.OPERATION, "reversed"); localHelper.createQuery("self.reversed()"); fail("Should have failed to parse the undefined operation"); } catch (ParserException e) { // success! System.out.println("Got the expected exception: " + e.getLocalizedMessage()); } }
public static OCL createOCL(ResourceSet resourceSet) { OCL newInstance = OCL.newInstance(resourceSet); String repairs = System.getProperty(PLUGIN_ID + ".repairs"); if (repairs != null) newInstance.setParserRepairCount(Integer.parseInt(repairs)); return newInstance; }