コード例 #1
0
ファイル: Ecore2AS.java プロジェクト: eclipse/ocl
 public @NonNull Model importObjects(
     @NonNull Collection<EObject> ecoreContents, @NonNull URI pivotURI) {
   EPackage libraryEPackage = isLibrary(ecoreContents);
   if (libraryEPackage != null) {
     newCreateMap = new HashMap<@NonNull EObject, @NonNull Element>();
     org.eclipse.ocl.pivot.Package asLibrary = standardLibrary.getPackage();
     newCreateMap.put(libraryEPackage, asLibrary);
     List<org.eclipse.ocl.pivot.Class> ownedType = asLibrary.getOwnedClasses();
     //			int prefix = LibraryConstants.ECORE_STDLIB_PREFIX.length();
     for (@SuppressWarnings("null") @NonNull
     EClassifier eClassifier : libraryEPackage.getEClassifiers()) {
       String name =
           environmentFactory.getTechnology().getOriginalName(eClassifier); // .substring(prefix);
       Type asType = NameUtil.getNameable(ownedType, name);
       if (asType != null) {
         newCreateMap.put(eClassifier, asType);
       }
     }
     Model containingRoot = PivotUtil.getContainingModel(asLibrary);
     return ClassUtil.nonNullModel(containingRoot);
   }
   @NonNull
   ASResource asResource = metamodelManager.getResource(pivotURI, ASResource.ECORE_CONTENT_TYPE);
   //		try {
   if ((metamodelManager.getLibraryResource() == null) && isPivot(ecoreContents)) {
     String nsURI = ((EPackage) ecoreContents.iterator().next()).getNsURI();
     if (nsURI != null) {
       String stdlibASUri = LibraryConstants.STDLIB_URI + PivotConstants.DOT_OCL_AS_FILE_EXTENSION;
       OCLstdlib library = OCLstdlib.create(stdlibASUri);
       metamodelManager.installResource(library);
       //					metamodelManager.installAs(nsURI, OCLstdlibTables.PACKAGE);
     }
   }
   URI uri = ecoreURI != null ? ecoreURI : ecoreResource.getURI();
   Model pivotModel2 = null;
   if (asResource.getContents().size() > 0) {
     EObject eObject = asResource.getContents().get(0);
     if (eObject instanceof Model) {
       pivotModel2 = (Model) eObject;
     }
   }
   if (pivotModel2 == null) {
     pivotModel2 = pivotModel = PivotUtil.createModel(uri.toString());
   }
   pivotModel = pivotModel2;
   //			installImports();
   update(asResource, ecoreContents);
   //		}
   //		catch (Exception e) {
   //			if (errors == null) {
   //				errors = new ArrayList<Resource.Diagnostic>();
   //			}
   //			errors.add(new XMIException("Failed to load '" + pivotURI + "'", e));
   //		}
   List<Diagnostic> errors2 = errors;
   if (errors2 != null) {
     asResource.getErrors().addAll(ClassUtil.nullFree(errors2));
   }
   return pivotModel2;
 }
コード例 #2
0
 /**
  * Tests construction of a type instance with property values
  *
  * @throws ParserException
  */
 @Test
 public void test_uml_primitives_399378() throws ParserException {
   TestOCL ocl = createOCL();
   ResourceSet resourceSet = ocl.getResourceSet();
   UML2AS.initialize(resourceSet);
   MetamodelManagerInternal metamodelManager = ocl.getMetamodelManager();
   URI uri = getTestModelURI("model/Fruit.uml");
   Element element = metamodelManager.loadResource(uri, null, resourceSet);
   org.eclipse.ocl.pivot.Package fruitPackage = ((Model) element).getOwnedPackages().get(0);
   org.eclipse.ocl.pivot.Class treeClass =
       NameUtil.getNameable(fruitPackage.getOwnedClasses(), "Tree");
   ExpressionInOCL query = ocl.createQuery(treeClass, "self.height>20");
   assertNotNull(query);
   ocl.dispose();
 }
コード例 #3
0
 @Test
 public void test_dynamic_dispatch_411154() throws ParserException, IOException {
   if (useCodeGen) return;
   TestOCL ocl = createOCL();
   if (!EMFPlugin.IS_ECLIPSE_RUNNING) {
     OCLinEcoreStandaloneSetup.doSetup();
     //			OCLDelegateDomain.initialize(null);
   }
   MetamodelManager metamodelManager = ocl.getMetamodelManager();
   String metamodelText =
       "package Bug411154 : pfx = 'Bug411154.ecore'\n"
           + "{\n"
           + "	class Domain {\n"
           + "		property types : T1[*] { ordered composes };\n"
           + "		property t1_2a : T1;\n"
           + "		property t1_3a : T1;\n"
           + "		property t1_3b : T1;\n"
           + "		property t1_4 : T1;\n"
           + "		property t2a_2a : T2a;\n"
           + "		property t2a_3a : T2a;\n"
           + "		property t2b_2b : T2b;\n"
           + "		property t3a : T3a;\n"
           + "	}\n"
           + "	abstract class T1 {\n"
           + "		operation op1() : String { body: 'T1::op1'; }\n"
           + "		operation op4() : String { body: 'T1::op4'; }\n"
           + "		operation op5() : String { body: 'T1::op5'; }\n"
           + "		operation op6() : String { body: 'T1::op6'; }\n"
           + "	}\n"
           + "	class T2a extends T1 {\n"
           + "		operation op1() : String { body: 'T2a::op1'; }\n"
           + "		operation op2() : String { body: 'T2a::op2'; }\n"
           + "		operation op4() : String { body: 'T2a::op4'; }\n"
           + "		operation op6() : String { body: 'T2a::op6'; }\n"
           + "		operation op7() : String { body: 'T2a::op7'; }\n"
           + "		operation op9() : String { body: 'T2a::op9'; }\n"
           + "	}\n"
           + "	class T2b extends T1 {\n"
           + "		operation op6() : String { body: 'T2b::op6'; }\n"
           + "		operation op7() : String { body: 'T2b::op7'; }\n"
           + "		operation op9() : String { body: 'T2b::op9'; }\n"
           + "	}\n"
           + "	class T3a extends T2a,T2b {\n"
           + "		operation op1() : String { body: 'T3a::op1'; }\n"
           + "		operation op2() : String { body: 'T3a::op2'; }\n"
           + "		operation op3() : String { body: 'T3a::op3'; }\n"
           + "		operation op6() : String { body: 'T3a::op6'; }\n"
           + "		operation op7() : String { body: 'T3a::op7'; }\n"
           + "	}\n"
           + "	class T3b extends T2a,T2b {\n"
           + "	}\n"
           + "	class T4 extends T3a,T3b {\n"
           + "		operation op6() : String { body: 'T4::op6'; }\n"
           + "		operation op7() : String { body: 'T4::op7'; }\n"
           + "	}\n"
           + "}\n";
   Resource metamodel = cs2as(ocl, metamodelText);
   Model pivotModel = (Model) metamodel.getContents().get(0);
   org.eclipse.ocl.pivot.Package pivotPackage = pivotModel.getOwnedPackages().get(0);
   org.eclipse.ocl.pivot.Class pivotTypeDomain =
       NameUtil.getNameable(pivotPackage.getOwnedClasses(), "Domain");
   //		org.eclipse.ocl.pivot.Class pivotTypeT1 =
   // ClassUtil.getNamedElement(pivotPackage.getOwnedType(), "T1");
   org.eclipse.ocl.pivot.Class pivotTypeT2a =
       NameUtil.getNameable(pivotPackage.getOwnedClasses(), "T2a");
   org.eclipse.ocl.pivot.Class pivotTypeT2b =
       NameUtil.getNameable(pivotPackage.getOwnedClasses(), "T2b");
   org.eclipse.ocl.pivot.Class pivotTypeT3a =
       NameUtil.getNameable(pivotPackage.getOwnedClasses(), "T3a");
   org.eclipse.ocl.pivot.Class pivotTypeT3b =
       NameUtil.getNameable(pivotPackage.getOwnedClasses(), "T3b");
   org.eclipse.ocl.pivot.Class pivotTypeT4 =
       NameUtil.getNameable(pivotPackage.getOwnedClasses(), "T4");
   EPackage ePackage = metamodelManager.getEcoreOfPivot(EPackage.class, pivotPackage);
   EClass eClassDomain = metamodelManager.getEcoreOfPivot(EClass.class, pivotTypeDomain);
   //		EClass eClassT1 = metamodelManager.getEcoreOfPivot(EClass.class, pivotTypeT1);
   EClass eClassT2a = metamodelManager.getEcoreOfPivot(EClass.class, pivotTypeT2a);
   EClass eClassT2b = metamodelManager.getEcoreOfPivot(EClass.class, pivotTypeT2b);
   EClass eClassT3a = metamodelManager.getEcoreOfPivot(EClass.class, pivotTypeT3a);
   EClass eClassT3b = metamodelManager.getEcoreOfPivot(EClass.class, pivotTypeT3b);
   EClass eClassT4 = metamodelManager.getEcoreOfPivot(EClass.class, pivotTypeT4);
   EReference eReferenceDomain_types =
       metamodelManager.getEcoreOfPivot(
           EReference.class, NameUtil.getNameable(pivotTypeDomain.getOwnedProperties(), "types"));
   EReference eReferenceDomain_t1_2a =
       metamodelManager.getEcoreOfPivot(
           EReference.class, NameUtil.getNameable(pivotTypeDomain.getOwnedProperties(), "t1_2a"));
   EReference eReferenceDomain_t1_3a =
       metamodelManager.getEcoreOfPivot(
           EReference.class, NameUtil.getNameable(pivotTypeDomain.getOwnedProperties(), "t1_3a"));
   EReference eReferenceDomain_t1_3b =
       metamodelManager.getEcoreOfPivot(
           EReference.class, NameUtil.getNameable(pivotTypeDomain.getOwnedProperties(), "t1_3b"));
   EReference eReferenceDomain_t1_4 =
       metamodelManager.getEcoreOfPivot(
           EReference.class, NameUtil.getNameable(pivotTypeDomain.getOwnedProperties(), "t1_4"));
   EReference eReferenceDomain_t2a_2a =
       metamodelManager.getEcoreOfPivot(
           EReference.class, NameUtil.getNameable(pivotTypeDomain.getOwnedProperties(), "t2a_2a"));
   EReference eReferenceDomain_t2a_3a =
       metamodelManager.getEcoreOfPivot(
           EReference.class, NameUtil.getNameable(pivotTypeDomain.getOwnedProperties(), "t2a_3a"));
   EReference eReferenceDomain_t2b_2b =
       metamodelManager.getEcoreOfPivot(
           EReference.class, NameUtil.getNameable(pivotTypeDomain.getOwnedProperties(), "t2b_2b"));
   EReference eReferenceDomain_t3a =
       metamodelManager.getEcoreOfPivot(
           EReference.class, NameUtil.getNameable(pivotTypeDomain.getOwnedProperties(), "t3a"));
   EFactory eFactory = ePackage.getEFactoryInstance();
   Resource resource = new ResourceImpl();
   EObject testObjectDomain = eFactory.create(eClassDomain);
   resource.getContents().add(testObjectDomain);
   EObject testObjectT2a = eFactory.create(eClassT2a);
   EObject testObjectT2b = eFactory.create(eClassT2b);
   EObject testObjectT3a = eFactory.create(eClassT3a);
   EObject testObjectT3b = eFactory.create(eClassT3b);
   EObject testObjectT4 = eFactory.create(eClassT4);
   @SuppressWarnings("unchecked")
   List<EObject> list = (List<EObject>) testObjectDomain.eGet(eReferenceDomain_types);
   list.add(testObjectT2a);
   list.add(testObjectT2b);
   list.add(testObjectT3a);
   list.add(testObjectT3b);
   list.add(testObjectT4);
   testObjectDomain.eSet(eReferenceDomain_t1_2a, testObjectT2a);
   testObjectDomain.eSet(eReferenceDomain_t1_3a, testObjectT3a);
   testObjectDomain.eSet(eReferenceDomain_t1_3b, testObjectT3b);
   testObjectDomain.eSet(eReferenceDomain_t1_4, testObjectT4);
   testObjectDomain.eSet(eReferenceDomain_t2a_2a, testObjectT2a);
   testObjectDomain.eSet(eReferenceDomain_t2a_3a, testObjectT3a);
   testObjectDomain.eSet(eReferenceDomain_t2b_2b, testObjectT2b);
   testObjectDomain.eSet(eReferenceDomain_t3a, testObjectT3a);
   //
   ocl.assertQueryEquals(testObjectT2a, "T2a::op1", "self.op1()");
   ocl.assertQueryEquals(testObjectT2a, "T2a::op2", "self.op2()");
   ocl.assertSemanticErrorQuery(
       pivotTypeT2a,
       "self.op3()",
       PivotMessagesInternal.UnresolvedOperation_ERROR_,
       "Bug411154",
       "T2a::op3");
   ocl.assertQueryEquals(testObjectT2a, "T2a::op4", "self.op4()");
   ocl.assertQueryEquals(testObjectT2a, "T1::op5", "self.op5()");
   ocl.assertQueryEquals(testObjectT2a, "T2a::op6", "self.op6()");
   ocl.assertQueryEquals(testObjectT2a, "T2a::op7", "self.op7()");
   ocl.assertSemanticErrorQuery(
       pivotTypeT2a,
       "self.op8()",
       PivotMessagesInternal.UnresolvedOperation_ERROR_,
       "Bug411154",
       "T2a::op8");
   ocl.assertQueryEquals(testObjectT2a, "T2a::op9", "self.op9()");
   //
   ocl.assertQueryEquals(testObjectT3a, "T3a::op1", "self.op1()");
   ocl.assertQueryEquals(testObjectT3a, "T3a::op2", "self.op2()");
   ocl.assertQueryEquals(testObjectT3a, "T3a::op3", "self.op3()");
   ocl.assertQueryEquals(testObjectT3a, "T2a::op4", "self.op4()");
   ocl.assertQueryEquals(testObjectT3a, "T1::op5", "self.op5()");
   ocl.assertQueryEquals(testObjectT3a, "T3a::op6", "self.op6()");
   ocl.assertQueryEquals(testObjectT3a, "T3a::op7", "self.op7()");
   ocl.assertSemanticErrorQuery(
       pivotTypeT3a,
       "self.op8()",
       PivotMessagesInternal.UnresolvedOperation_ERROR_,
       "Bug411154",
       "T3a::op8");
   ocl.assertSemanticErrorQuery(
       pivotTypeT3a,
       "self.op9()",
       "Ambiguous resolution:\n"
           + "\tOperation : Bug411154::T2a::op9() : String[?]\n"
           + "\tOperation : Bug411154::T2b::op9() : String[?]");
   //
   ocl.assertQueryEquals(testObjectDomain, "T2a::op1", "t1_2a.op1()");
   ocl.assertSemanticErrorQuery(
       pivotTypeDomain,
       "t1_2a.op2()",
       PivotMessagesInternal.UnresolvedOperation_ERROR_,
       "Bug411154",
       "T1::op2");
   ocl.assertSemanticErrorQuery(
       pivotTypeDomain,
       "t1_2a.op3()",
       PivotMessagesInternal.UnresolvedOperation_ERROR_,
       "Bug411154",
       "T1::op3");
   ocl.assertQueryEquals(testObjectDomain, "T2a::op4", "t1_2a.op4()");
   ocl.assertQueryEquals(testObjectDomain, "T1::op5", "t1_2a.op5()");
   //
   ocl.assertQueryEquals(testObjectDomain, "T3a::op1", "t1_3a.op1()");
   ocl.assertSemanticErrorQuery(
       pivotTypeDomain,
       "t1_3a.op2()",
       PivotMessagesInternal.UnresolvedOperation_ERROR_,
       "Bug411154",
       "T1::op2");
   ocl.assertSemanticErrorQuery(
       pivotTypeDomain,
       "t1_3a.op3()",
       PivotMessagesInternal.UnresolvedOperation_ERROR_,
       "Bug411154",
       "T1::op3");
   ocl.assertQueryEquals(testObjectDomain, "T2a::op4", "t1_3a.op4()");
   ocl.assertQueryEquals(testObjectDomain, "T1::op5", "t1_3a.op5()");
   //
   ocl.assertQueryEquals(testObjectDomain, "T2a::op1", "t1_3b.op1()");
   ocl.assertSemanticErrorQuery(
       pivotTypeDomain,
       "t1_3b.op2()",
       PivotMessagesInternal.UnresolvedOperation_ERROR_,
       "Bug411154",
       "T1::op2");
   ocl.assertSemanticErrorQuery(
       pivotTypeDomain,
       "t1_3b.op3()",
       PivotMessagesInternal.UnresolvedOperation_ERROR_,
       "Bug411154",
       "T1::op3");
   ocl.assertQueryEquals(testObjectDomain, "T2a::op4", "t1_3b.op4()");
   ocl.assertQueryEquals(testObjectDomain, "T1::op5", "t1_3b.op5()");
   ocl.assertQueryInvalid(
       testObjectDomain,
       "t1_3b.op6()",
       NLS.bind(
           PivotMessages.AmbiguousOperation, "Bug411154::T1::op6() : String[?]", "Bug411154::T3b"),
       InvalidValueException.class);
   ocl.assertSemanticErrorQuery(
       pivotTypeDomain,
       "t1_3b.op7()",
       PivotMessagesInternal.UnresolvedOperation_ERROR_,
       "Bug411154",
       "T1::op7");
   //
   ocl.assertQueryEquals(testObjectDomain, "T3a::op1", "t1_4.op1()");
   ocl.assertSemanticErrorQuery(
       pivotTypeDomain,
       "t1_4.op2()",
       PivotMessagesInternal.UnresolvedOperation_ERROR_,
       "Bug411154",
       "T1::op2");
   ocl.assertSemanticErrorQuery(
       pivotTypeDomain,
       "t1_4.op3()",
       PivotMessagesInternal.UnresolvedOperation_ERROR_,
       "Bug411154",
       "T1::op3");
   ocl.assertQueryEquals(testObjectDomain, "T2a::op4", "t1_4.op4()");
   ocl.assertQueryEquals(testObjectDomain, "T1::op5", "t1_4.op5()");
   ocl.assertQueryEquals(testObjectDomain, "T4::op6", "t1_4.op6()");
   ocl.assertSemanticErrorQuery(
       pivotTypeDomain,
       "t1_4.op7()",
       PivotMessagesInternal.UnresolvedOperation_ERROR_,
       "Bug411154",
       "T1::op7");
   //
   ocl.assertQueryEquals(testObjectDomain, "T2a::op1", "t2a_2a.op1()");
   ocl.assertQueryEquals(testObjectDomain, "T2a::op2", "t2a_2a.op2()");
   ocl.assertSemanticErrorQuery(
       pivotTypeDomain,
       "t2a_2a.op3()",
       PivotMessagesInternal.UnresolvedOperation_ERROR_,
       "Bug411154",
       "T2a::op3");
   ocl.assertQueryEquals(testObjectDomain, "T2a::op4", "t2a_2a.op4()");
   ocl.assertQueryEquals(testObjectDomain, "T1::op5", "t2a_2a.op5()");
   ocl.assertQueryEquals(testObjectDomain, "T2a::op6", "t2a_2a.op6()");
   ocl.assertQueryEquals(testObjectDomain, "T2a::op7", "t2a_2a.op7()");
   //
   ocl.assertQueryEquals(testObjectDomain, "T2b::op6", "t2b_2b.op6()");
   //
   ocl.assertQueryEquals(testObjectDomain, "T3a::op1", "t2a_3a.op1()");
   ocl.assertQueryEquals(testObjectDomain, "T3a::op2", "t2a_3a.op2()");
   ocl.assertSemanticErrorQuery(
       pivotTypeDomain,
       "t2a_3a.op3()",
       PivotMessagesInternal.UnresolvedOperation_ERROR_,
       "Bug411154",
       "T2a::op3");
   ocl.assertQueryEquals(testObjectDomain, "T2a::op4", "t2a_3a.op4()");
   ocl.assertQueryEquals(testObjectDomain, "T1::op5", "t2a_3a.op5()");
   //
   ocl.assertQueryEquals(testObjectDomain, "T3a::op1", "t3a.op1()");
   ocl.assertQueryEquals(testObjectDomain, "T3a::op2", "t3a.op2()");
   ocl.assertQueryEquals(testObjectDomain, "T3a::op3", "t3a.op3()");
   ocl.assertQueryEquals(testObjectDomain, "T2a::op4", "t3a.op4()");
   ocl.assertQueryEquals(testObjectDomain, "T1::op5", "t3a.op5()");
   ocl.dispose();
 }
コード例 #4
0
 @Test
 public void test_cg_name_occlusion_401692() throws ParserException, IOException {
   TestOCL ocl = createOCL();
   if (!EMFPlugin.IS_ECLIPSE_RUNNING) {
     OCLinEcoreStandaloneSetup.doSetup();
     //			OCLDelegateDomain.initialize(null);
   }
   MetamodelManager metamodelManager = ocl.getMetamodelManager();
   String metamodelText =
       "package scope = 'abc'\n"
           + "{\n"
           + "	class A\n"
           + "	{\n"
           + "		attribute d : String;\n"
           + "		attribute e : String;\n"
           + "	}\n"
           + "	class B\n"
           + "	{\n"
           + "		operation findA(e : String) : A[?]\n"
           + "		{\n"
           + "			body:\n"
           + "				let found : OrderedSet(A) = as?->select(a : A | a.d = e) in if found->size() > 0 then found->first() else null endif;\n"
           + "		}\n"
           + "		property as : A[*] { ordered composes };\n"
           + "	}\n"
           + "}\n";
   Resource metamodel = cs2as(ocl, metamodelText);
   Model pivotModel = (Model) metamodel.getContents().get(0);
   org.eclipse.ocl.pivot.Package pivotPackage = pivotModel.getOwnedPackages().get(0);
   org.eclipse.ocl.pivot.Class pivotTypeA =
       NameUtil.getNameable(pivotPackage.getOwnedClasses(), "A");
   org.eclipse.ocl.pivot.Class pivotTypeB =
       NameUtil.getNameable(pivotPackage.getOwnedClasses(), "B");
   EPackage ePackage = metamodelManager.getEcoreOfPivot(EPackage.class, pivotPackage);
   EClass eClassA = metamodelManager.getEcoreOfPivot(EClass.class, pivotTypeA);
   EClass eClassB = metamodelManager.getEcoreOfPivot(EClass.class, pivotTypeB);
   EAttribute eAttributeAd =
       metamodelManager.getEcoreOfPivot(
           EAttribute.class, NameUtil.getNameable(pivotTypeA.getOwnedProperties(), "d"));
   EAttribute eAttributeAe =
       metamodelManager.getEcoreOfPivot(
           EAttribute.class, NameUtil.getNameable(pivotTypeA.getOwnedProperties(), "e"));
   EReference eReferenceBas =
       metamodelManager.getEcoreOfPivot(
           EReference.class, NameUtil.getNameable(pivotTypeB.getOwnedProperties(), "as"));
   EFactory eFactory = ePackage.getEFactoryInstance();
   Resource resource = new ResourceImpl();
   EObject testObjectA1 = eFactory.create(eClassA);
   testObjectA1.eSet(eAttributeAd, "d1");
   testObjectA1.eSet(eAttributeAe, "e1");
   EObject testObjectA2 = eFactory.create(eClassA);
   testObjectA2.eSet(eAttributeAd, "d2");
   testObjectA2.eSet(eAttributeAe, "e2");
   EObject testObjectB = eFactory.create(eClassB);
   resource.getContents().add(testObjectB);
   @SuppressWarnings("unchecked")
   List<EObject> as = (List<EObject>) testObjectB.eGet(eReferenceBas);
   as.add(testObjectA1);
   as.add(testObjectA2);
   //
   ocl.assertQueryEquals(testObjectB, testObjectA1, "self.findA('d1')");
   ocl.assertQueryEquals(testObjectB, null, "self.findA('e2')");
   ocl.dispose();
 }