public void testTwo() throws Exception { new TestHelper() { Resource ecoreResource; @Override void loadResources(ResourceSet resourceSet) { ecoreResource = resourceSet.getResource(URI.createURI("platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore"), true); } @Override void makeChanges() { EPackage ePackage = (EPackage) ecoreResource.getContents().get(0); EClass eClass = EcoreFactory.eINSTANCE.createEClass(); ePackage.getEClassifiers().add(5, eClass); eClass.setName("NewClass"); EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation(); eClass.getEAnnotations().add(eAnnotation); eAnnotation.getContents().add(0, ePackage.getEClassifiers().get(2)); } }.doit(); }
private EEnum createEnumerationType(EnumerationType type) { EEnum eenum = EcoreFactory.eINSTANCE.createEEnum(); eenum.setName(type.getName()); int value = 0; for (EnumerationLiteral literal : type.getLiterals()) { EEnumLiteral eenumliteral = EcoreFactory.eINSTANCE.createEEnumLiteral(); eenum.getELiterals().add(eenumliteral); eenumliteral.setName(literal.getName()); eenumliteral.setLiteral(literal.getName()); eenumliteral.setValue(value); value++; if (literal.getDocumentation() != null) { attachInfo(eenumliteral, literal.getDocumentation()); } } if (type.getDocumentation() != null) { attachInfo(eenum, type.getDocumentation()); } return eenum; }
private EDataType createStringType(StringType type) { EDataType edatatype = EcoreFactory.eINSTANCE.createEDataType(); edatatype.setName(type.getName()); edatatype.setInstanceTypeName("java.lang.String"); if (type.getDocumentation() != null) { attachInfo(edatatype, type.getDocumentation()); } if (type.isSetLength() || type.isSetMaxLength() || type.isSetMinLength() || type.getPattern() != null) { EAnnotation eannotation = EcoreFactory.eINSTANCE.createEAnnotation(); edatatype.getEAnnotations().add(eannotation); eannotation.setSource("http:///org/eclipse/emf/ecore/util/ExtendedMetaData"); if (type.isSetLength()) eannotation.getDetails().put("length", Integer.toString(type.getLength())); if (type.isSetMaxLength()) eannotation.getDetails().put("maxLength", Integer.toString(type.getMaxLength())); if (type.isSetMinLength()) eannotation.getDetails().put("minLength", Integer.toString(type.getMinLength())); if (type.getPattern() != null) { if (type.getPattern() != "") eannotation.getDetails().put("pattern", type.getPattern()); } } return edatatype; }
protected void convertConstraints(EClass eClass, Type type) { if (type.getConstraints().size() > 0) { // EMF Annotation EAnnotation annotation_emf = EcoreFactory.eINSTANCE.createEAnnotation(); annotation_emf.setSource("http://www.eclipse.org/emf/2002/Ecore"); String value = ""; // OCL Annotation EAnnotation annotation_ocl = EcoreFactory.eINSTANCE.createEAnnotation(); annotation_ocl.setSource("http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot"); for (Constraint constraint : type.getConstraints()) { annotation_ocl.getDetails().put(constraint.getName(), convertbody(constraint.getBody(), (Extension) type.eContainer())); if (value.equals("")) { value += constraint.getName(); } else { value += " "; value += constraint.getName(); } // convertbody(constraint.getBody(), (Extension) // type.eContainer()); } annotation_emf.getDetails().put("constraints", value); eClass.getEAnnotations().add(annotation_emf); eClass.getEAnnotations().add(annotation_ocl); } }
/** * Convert an OCCI action to an Ecore operation. * * @param action * the OCCI action to convert. * @return the resulting Ecore operation. */ protected EOperation convertAction(Action action) { // Create the Ecore operation. EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation(); // Set the name of the Ecore operation. eOperation.setName(ConverterUtils.formatName(action.getTerm())); // Convert all attributes of the OCCI action. for (Attribute attribute : action.getAttributes()) { // Each OCCI attribute of the OCCI action is converted to an Ecore // parameter of the Ecore operation. EParameter convertParameter = convertParameter(attribute); if (convertParameter != null) { // Add the Ecore parameter to the Ecore operation. eOperation.getEParameters().add(convertParameter); } } attachInfo(eOperation, action.getTitle()); return eOperation; }
/** * Convert an OCCI action's attribute to an Ecore operation parameter. * * @param attribute * the OCCI attribute to convert. * @return the resulting Ecore operation parameter. */ protected EParameter convertParameter(Attribute attribute) { // Create an Ecore parameter. EParameter eParam = EcoreFactory.eINSTANCE.createEParameter(); // Set the name of the Ecore parameter. eParam.setName(Occi2Ecore.convertOcciAttributeName2EcoreAttributeName(attribute.getName())); // Set the type of the Ecore parameter. eParam.setEType(getMappedType(attribute.getType())); // If the OCCI attribute is required then the Ecore parameter is also // required. if (attribute.isRequired()) { eParam.setLowerBound(1); } attachInfo(eParam, attribute.getDescription()); return eParam; }
public void setBirthdayOfFatherBart(PersonRegister register) { Calendar cal = Calendar.getInstance(); Date date; // Person bart = getFromRegister("Simpson, Bart", register); // cal.set(2013, Calendar.MARCH, 9, 10, 11, 12); // date = cal.getTime(); // bart.setBirthday(date); List<Person> barts = getAllFromRegister("Simpson, Bart", register); Date defaultDate = (Date) EcoreFactory.eINSTANCE.createFromString(EcorePackage.eINSTANCE.getEDate(), "0000-1-1"); for (Person bart : barts) { if (bart.getBirthday().equals(defaultDate)) { cal.set(2013, Calendar.MARCH, 9, 10, 11, 12); date = cal.getTime(); bart.setBirthday(date); return; } } }
@Test public void testNestedPackage() throws Exception { Resource resource = new XMIResourceImpl(); EPackage parent = EcoreFactory.eINSTANCE.createEPackage(); parent.setName("parent"); parent.setNsURI("http://parent"); EPackage child = EcoreFactory.eINSTANCE.createEPackage(); child.setName("child"); child.setNsURI("http://child"); EClass eClass = EcoreFactory.eINSTANCE.createEClass(); eClass.setName("Test"); child.getEClassifiers().add(eClass); parent.getESubpackages().add(child); resource.getContents().add(parent); Map<QualifiedName, IEObjectDescription> index = createIndex(resource); checkEntry(index, parent, false, "parent"); checkEntry(index, child, false, "parent", "child"); checkEntry(index, eClass, false, "parent", "child", "Test"); checkEntry(index, parent, true, "http://parent"); checkEntry(index, child, true, "http://child"); checkEntry(index, eClass, true, "http://child", "Test"); assertEquals(6,index.size()); }
@Test public void testMissingMiddleName() { Resource resource = new XMIResourceImpl(); EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage(); ePackage.setName("test"); ePackage.setNsURI("http://test"); EClass unnamedEClass = EcoreFactory.eINSTANCE.createEClass(); EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute(); eAttribute.setName("test"); unnamedEClass.getEStructuralFeatures().add(eAttribute); ePackage.getEClassifiers().add(unnamedEClass); resource.getContents().add(ePackage); Map<QualifiedName, IEObjectDescription> index = createIndex(resource); checkEntry(index, ePackage, false, "test"); checkEntry(index, ePackage, true, "http://test"); assertEquals(2,index.size()); unnamedEClass.setName("Test"); index = createIndex(resource); checkEntry(index, ePackage, false, "test"); checkEntry(index, ePackage, true, "http://test"); checkEntry(index, unnamedEClass, false, "test", "Test"); checkEntry(index, unnamedEClass, true, "http://test", "Test"); checkEntry(index, eAttribute, false, "test", "Test", "test"); checkEntry(index, eAttribute, true, "http://test", "Test", "test"); assertEquals(6,index.size()); }
private EStructuralFeature createFeatureWith(String featureName, EClassifier featureClassifier, boolean isMultivalue, boolean isContainment) { EStructuralFeature newFeature; if (featureClassifier instanceof EClass) { EReference reference = EcoreFactory.eINSTANCE.createEReference(); reference.setContainment(isContainment); newFeature = reference; } else { newFeature = EcoreFactory.eINSTANCE.createEAttribute(); } newFeature.setName(featureName); newFeature.setEType(featureClassifier); newFeature.setLowerBound(0); newFeature.setUpperBound(isMultivalue ? -1 : 1); newFeature.setUnique(!isMultivalue || (isContainment && featureClassifier instanceof EClass)); if (newFeature.getEType() instanceof EEnum) { newFeature.setDefaultValue(null); } return newFeature; }
private List<EObject> createPackage(GeneratedMetamodel generatedMetamodel, ILeafNode text) { final String nsURI = getMetamodelNsURI(text); final URI uri = URI.createURI(nsURI); if (uri == null || isReferencedByUsedGrammar(generatedMetamodel, nsURI)) return Collections.emptyList(); EPackage pack = ((GeneratedMetamodelImpl)generatedMetamodel).basicGetEPackage(); if (pack != null && !pack.eIsProxy()) return singletonList((EObject)pack); final EPackage generatedEPackage = EcoreFactory.eINSTANCE.createEPackage(); generatedEPackage.setName(generatedMetamodel.getName()); generatedEPackage.setNsPrefix(generatedMetamodel.getName()); generatedEPackage.setNsURI(nsURI); final Resource generatedPackageResource = new EcoreResourceFactoryImpl().createResource(uri); XtextResourceSet resourceSet = (XtextResourceSet) generatedMetamodel.eResource().getResourceSet(); if (!resourceSet.getURIResourceMap().containsKey(generatedPackageResource.getURI())) { generatedMetamodel.eResource().getResourceSet().getResources().add(generatedPackageResource); } else { generatedPackageResource.setURI(URI.createURI(nsURI+"_"+generatedMetamodel.hashCode())); generatedMetamodel.eResource().getResourceSet().getResources().add(generatedPackageResource); } generatedPackageResource.getContents().add(generatedEPackage); return Collections.<EObject>singletonList(generatedEPackage); }
@Test public void testFillIdToEObjectMap() { EPackage pack = EcoreFactory.eINSTANCE.createEPackage(); EClass root = createEClass(pack, "Root"); EClass someType = createEClass(pack, "SomeType"); EReference ref1 = addEReference(root, someType, "ref1", false); EReference ref2 = addEReference(root, someType, "ref2", true); EFactory factory = pack.getEFactoryInstance(); EObject rootObject = factory.create(root); EObject someTypeObject1 = factory.create(someType); EObject someTypeObject2 = factory.create(someType); rootObject.eSet(ref1, someTypeObject1); rootObject.eSet(ref2, someTypeObject2); List<EObject> map = new ArrayList<>(); SerializationUtil.fillIdToEObjectMap(rootObject, map); assertTrue(map.contains(rootObject)); assertTrue(map.contains(someTypeObject1)); assertFalse(map.contains(someTypeObject2)); assertEquals(2, map.size()); }
/** Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=396726 */ @Test public void testNoShortCircuiting() { CompositeEValidator compositeValidator = new CompositeEValidator(); compositeValidator.setEqualitySupportProvider(new Provider<CompositeEValidator.EValidatorEqualitySupport>() { @Override public EValidatorEqualitySupport get() { return new CompositeEValidator.EValidatorEqualitySupport(); } }); assertEquals(1, compositeValidator.getContents().size()); compositeValidator.addValidator(EcoreValidator.INSTANCE); assertEquals(2, compositeValidator.getContents().size()); TestEcoreValidator testValidator = new TestEcoreValidator(); compositeValidator.addValidator(testValidator); assertEquals(3, compositeValidator.getContents().size()); compositeValidator.validate(EcoreFactory.eINSTANCE.createEClass(), new BasicDiagnostic(), null); assertTrue(testValidator.wasCalled()); }
@Test public void testCreatedErrors_07() { maxCallCount = 0; ImmutableList<ENamedElement> elements = ImmutableList.of( createEPackage(), createEDataType(), EcoreFactory.eINSTANCE.createEEnumLiteral() ); for(ENamedElement classifier: elements) { classifier.setName("Same"); } expected.add(elements.get(0)); expected.add(elements.get(2)); helper.checkUniqueNames( Scopes.scopedElementsFor(elements), this, this); assertEquals(elements.size(), callCount); assertTrue(expected.isEmpty()); }
@Test public void testConvertNullInput() throws Exception { EClass eClass = EcoreFactory.eINSTANCE.createEClass(); Function2<String, INode, Object> toValueImpl = new Function2<String, INode, Object>() { @Override public Object apply(String lexerRule, INode node) { if ("foo".equals(lexerRule) ) { return "FOO"; } return null; } }; DefaultEcoreElementFactory factory = new DefaultEcoreElementFactory(); factory.setConverterService(new MockedConverterService(toValueImpl)); factory.set(eClass, "name", null, "foo", null); assertEquals("FOO", eClass.getName()); }
@Test public void testGetAllReferencedObjects() { EClass a = createEClass("a"); EClass b = createEClass("b"); EPackage pack = EcoreFactory.eINSTANCE.createEPackage(); pack.setName("empty"); pack.setNsPrefix("empty"); pack.setNsURI("empty"); pack.getEClassifiers().add(a); pack.getEClassifiers().add(b); EReference ref = EcoreFactory.eINSTANCE.createEReference(); a.getEStructuralFeatures().add(ref); ref.setUpperBound(1); ref.setEType(b); EObject objA = pack.getEFactoryInstance().create(a); EObject objB = pack.getEFactoryInstance().create(b); List<EObject> res = EcoreUtil2.getAllReferencedObjects(objA, ref); assertNotNull(res); assertTrue(res.isEmpty()); res = EcoreUtil2.getAllReferencedObjects(objA, ref); assertNotNull(res); objA.eSet(ref, objB); }
@Test public void testPathFragment() { EClass foo = EcoreFactory.eINSTANCE.createEClass(); foo.setName("foo"); EClass bar = EcoreFactory.eINSTANCE.createEClass(); foo.setName("bar"); EPackage p = EcoreFactory.eINSTANCE.createEPackage(); bar.setName("p"); p.getEClassifiers().add(foo); p.getEClassifiers().add(bar); assertEquals("/-1", EcoreUtil2.getFragmentPath(foo)); assertEquals("/-1", EcoreUtil2.getFragmentPath(bar)); assertEquals("/-1", EcoreUtil2.getFragmentPath(p)); Resource resource = new ResourceImpl(URI.createURI("platform:/resource/res")); resource.getContents().add(p); assertEquals(URI.createURI("platform:/resource/res#//@eClassifiers.0"), EcoreUtil2.getFragmentPathURI(foo)); assertEquals(URI.createURI("platform:/resource/res#//@eClassifiers.1"), EcoreUtil2.getFragmentPathURI(bar)); assertEquals(URI.createURI("platform:/resource/res#/"), EcoreUtil2.getFragmentPathURI(p)); assertEquals(resource.getEObject("//@eClassifiers.0"), foo); assertEquals(resource.getEObject("//@eClassifiers.1"), bar); assertEquals(resource.getEObject("/"), p); }
@Test public void testWithNull() throws Exception { EAttribute attr = EcoreFactory.eINSTANCE.createEAttribute(); attr.setName("Foo"); EAttribute attr2 = EcoreFactory.eINSTANCE.createEAttribute(); attr2.setName("Bar"); ArrayList<EAttribute> list = new ArrayList<EAttribute>(); list.add(attr); list.add(EcoreFactory.eINSTANCE.createEAttribute()); list.add(attr2); Iterable<IEObjectDescription> iterable = Scopes.scopedElementsFor(list); Iterator<IEObjectDescription> iterator = iterable.iterator(); assertEquals(FOO, iterator.next().getName()); assertEquals(BAR, iterator.next().getName()); assertFalse(iterator.hasNext()); }
@Test public void testWithDifferentElements() throws Exception { EAttribute attr = EcoreFactory.eINSTANCE.createEAttribute(); attr.setName("Foo"); EDataType datatype = EcoreFactory.eINSTANCE.createEDataType(); datatype.setName("Bar"); ArrayList<EObject> list = new ArrayList<EObject>(); list.add(attr); list.add(EcoreFactory.eINSTANCE.createEObject()); list.add(datatype); Iterable<IEObjectDescription> iterable = Scopes.scopedElementsFor(list); Iterator<IEObjectDescription> iterator = iterable.iterator(); IEObjectDescription next = iterator.next(); assertEquals(FOO, next.getName()); assertEquals(attr,next.getEObjectOrProxy()); next = iterator.next(); assertEquals(BAR, next.getName()); assertEquals(datatype,next.getEObjectOrProxy()); assertFalse(iterator.hasNext()); }
@Test public void testAdapterIsCleared() throws Exception { EcoreFactory factory = EcoreFactory.eINSTANCE; EClass eClass = factory.createEClass(); Resource resource = new ResourceImpl(); resource.getContents().add(eClass); CacheAdapter ca = new OnChangeEvictingCache().getOrCreate(resource); setValue(ca); EAttribute attribute = factory.createEAttribute(); assertIsSet(ca); eClass.getEStructuralFeatures().add(attribute); assertIsNull(ca); setValue(ca); attribute.setName("Foo"); assertIsNull(ca); setValue(ca); }
@Before public void initialize() { EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE; testClass = ecoreFactory.createEClass(); testReference = ecoreFactory.createEReference(); testReference.setEType(testClass); testReference.setContainment(true); testClass.getEStructuralFeatures().add(testReference); testReference2 = ecoreFactory.createEReference(); testReference2.setEType(testClass); testReference2.setContainment(true); testClass.getEStructuralFeatures().add(testReference2); testPackage = ecoreFactory.createEPackage(); testPackage.getEClassifiers().add(testClass); testPackage.setNsURI("http:///com.avaloq.tools.ddk.xtext.test"); EPackage.Registry.INSTANCE.put(testPackage.getNsURI(), testPackage); }
@Before public void init() { EcoreFactory modelFactory = EcoreFactory.eINSTANCE; testModelPackage = modelFactory.createEPackage(); testModelPackage.setName("TypeProviderTestEPackage"); testModelPackage.setNsPrefix("typeprovidertestpackage"); testModelPackage.setNsURI("http://testabstracttype"); EFactory instanceFactory = testModelPackage.getEFactoryInstance(); EClass clazz = createEClass("ExpressionContainer"); expressionContainerReference = modelFactory.createEReference(); clazz.getEStructuralFeatures().add(expressionContainerReference); expressionContainerReference.setName("expression"); expressionContainerReference.setEType(typeModelPackage.getIExpression()); expressionContainerReference.setContainment(true); expression1Container = instanceFactory.create(clazz); expression1Container.eSet(expressionContainerReference, expression1); expression2Container = instanceFactory.create(clazz); expression2Container.eSet(expressionContainerReference, expression2); expression3Container = instanceFactory.create(clazz); expression3Container.eSet(expressionContainerReference, expression3); }
/** * Adds the given reference to the contents. * * @param referenceDescription * reference to add */ private void addReference(final IReferenceDescription referenceDescription) { URI containerEObjectURI = referenceDescription.getContainerEObjectURI(); final URI eObjectURI = (containerEObjectURI == null) ? referenceDescription.getSourceEObjectUri() : containerEObjectURI; IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(eObjectURI.trimFragment()); if (resourceDescription != null) { ReferenceSearchViewTreeNode resourceNode = resourceNode(resourceDescription); new DynamicReferenceSearchViewTreeNode(resourceNode, referenceDescription, new Supplier<Object>() { @Override public Object get() { InternalEObject dummyProxy = (InternalEObject) EcoreFactory.eINSTANCE.createEObject(); dummyProxy.eSetProxyURI(eObjectURI); Iterator<IEObjectDescription> sourceObjects = resourceDescriptions.getExportedObjectsByObject(dummyProxy).iterator(); return sourceObjects.hasNext() ? sourceObjects.next() : referenceDescription; } }); } }
public static EPackage createTEPackage(String nsPrefix, String nsURI) { // create the EPackage of the temporary metamodel if it does not exist already if(!Package_Map.containsKey(nsURI)) { EPackage tPackage = EcoreFactory.eINSTANCE.createEPackage(); tPackage.setNsPrefix(nsPrefix); tPackage.setNsURI(nsURI); // create the document root to which the temporary EReferences are added EClass documentRoot = EcoreFactory.eINSTANCE.createEClass(); documentRoot.setName("DocumentRoot"); // add the document root to the created package and add the package to the global map tPackage.getEClassifiers().add(documentRoot); Package_Map.put(nsURI, tPackage); return tPackage; } else { return Package_Map.get(nsURI); } }
public static void setTreeNodesPositionAnnotation(List<View> viewElements) { if (viewElements != null) { for (int index = 0; index < viewElements.size(); index++) { final View view = viewElements.get(index); EAnnotation xmiIdAnnotation = view .getEAnnotation(TREE_LAYOUT_ANNOTATION); if (xmiIdAnnotation == null) { xmiIdAnnotation = EcoreFactory.eINSTANCE .createEAnnotation(); xmiIdAnnotation.setSource(TREE_LAYOUT_ANNOTATION); } xmiIdAnnotation.getDetails().put(TREE_NODE_POSITION, Integer.toString(index)); xmiIdAnnotation.setEModelElement(view); } } }
public void testEObjectScriptable() { Context cx = Context.enter(); Scriptable scope = cx.initStandardObjects(); EClass eClass = EcoreFactory.eINSTANCE.createEClass(); ScriptableEObject scriptable = new ScriptableEObject(eClass); scope.setParentScope(scriptable); cx.evaluateString(scope, "name = \"junit\"", "<cmd>", 1, null); assertEquals("junit", eClass.getName()); Object value = cx.evaluateString(scope, "ePackage", "<cmd>", 1, null); assertEquals(value, eClass.getEPackage()); Context.exit(); }
@Test public void inAndOutOfString() { EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage(); ePackage.setName("Package"); EClass eClass0 = EcoreFactory.eINSTANCE.createEClass(); eClass0.setName("EClass0"); ePackage.getEClassifiers().add(eClass0); EClass eClass1 = EcoreFactory.eINSTANCE.createEClass(); eClass1.setName("EClass1"); ePackage.getEClassifiers().add(eClass1); String stringified = EMFUtils.convertToXML(ePackage); Logger logger = Logger.getLogger(TestEMFUtils.class); logger.debug("STRING: " + stringified); EObject object = EMFUtils.createFromXML(stringified); assertTrue(object instanceof EPackage); ePackage = (EPackage)object; assertEquals(2, ePackage.getEClassifiers().size()); assertEquals("EClass0", ePackage.getEClassifiers().get(0).getName()); assertEquals("EClass1", ePackage.getEClassifiers().get(1).getName()); }
@Test public void filter() { final List<EObject> list = new ArrayList<EObject>(); final EObject o1 = EcoreFactory.eINSTANCE.createEObject(); final EObject o2 = EcoreFactory.eINSTANCE.createEObject(); list.add(o1); list.add(o2); final List<EObject> filtered = EMFUtils.filter(list, new Object() { @SuppressWarnings("unused") public boolean doSwitch(EObject obj) { if (obj == o1) return true; return false; } }); assertEquals(Collections.singletonList(o1), filtered); }
@Test public void map() { final List<EObject> list = new ArrayList<EObject>(); final EObject o1 = EcoreFactory.eINSTANCE.createEObject(); final EObject o2 = EcoreFactory.eINSTANCE.createEObject(); list.add(o1); list.add(o2); final List<String> mapped = EMFUtils.map(list, new Object() { @SuppressWarnings("unused") public String doSwitch(EObject obj) { return obj.toString(); } }); final List<String> stringified = new ArrayList<String>(); stringified.add(o1.toString()); stringified.add(o2.toString()); assertEquals(stringified, mapped); }
@Test public void filterMap() { final List<EObject> list = new ArrayList<EObject>(); final EObject o1 = EcoreFactory.eINSTANCE.createEObject(); final EObject o2 = EcoreFactory.eINSTANCE.createEObject(); list.add(o1); list.add(o2); final List<String> mapped = EMFUtils.filterMap(list, new Object() { @SuppressWarnings("unused") public String doSwitch(EObject obj) { if (obj == o1) return obj.toString(); return null; } }); assertEquals(Collections.singletonList(o1.toString()), mapped); }
@Override public Object deserialize(EObject target, EStructuralFeature feature, String value) { if (isDeserializer(target, feature)) { String v = value.substring(value.indexOf("[")+1, value.lastIndexOf("]")); // White-space varies if its numeric or enum int delim = v.lastIndexOf(','); String dateString = v.substring(0, delim).trim(); String valueString = v.substring(delim + 1).trim(); Profile profile = (Profile) target; EDataType dataType = profile.getDataType(); Date date = (Date)EcoreFactory.eINSTANCE.createFromString(EcorePackage.Literals.EDATE, dateString); Object object = null; if (valueString != null && !valueString.isEmpty() && !valueString.equals("null")) { object = EcoreUtil.createFromString(dataType, valueString); } DataPoint<Object> dataPoint = JScienceFactory.eINSTANCE.createEDataPoint(date, object); return dataPoint; } return null; }
@Test public void testSaveWithUriMapping() throws IOException { resourceSet.getURIConverter().getURIMap().put( URI.createURI("http://resources/"), URI.createURI("mongodb://localhost:27017/emfjson-test/models/")); Resource resource = resourceSet.createResource(URI.createURI("http://resources/model1")); EPackage p = EcoreFactory.eINSTANCE.createEPackage(); p.setName("p"); EClass c = EcoreFactory.eINSTANCE.createEClass(); c.setName("A"); p.getEClassifiers().add(c); resource.getContents().add(p); resource.save(null); checkDocument(testURI); }
public USESolverMemory(EPackage metamodel, List<String> constraints) throws transException { super(); this.metamodel = metamodel; root = (EClass) metamodel.getEClassifier("AuxiliaryClass4USE"); if ( root == null ) { root = EcoreFactory.eINSTANCE.createEClass(); root.setName ("AuxiliaryClass4USE"); metamodel.getEClassifiers().add(root); } try { StringWriter writer1 = new StringWriter(); transformEcore2use(metamodel, writer1); writer1.append("\n\n"); writeOCLexpression(metamodel, constraints, root, writer1); this.useSpecification = writer1.toString(); writer1.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Override public QuickfixApplication getQuickfixApplication() throws CoreException { OclModelElement me = (OclModelElement) getProblematicElement(); String mmName = me.getModel().getName(); QuickfixApplication qfa = new QuickfixApplication(this); Set<EPackage> packages = getAnalysisResult().getNamespace().getNamespace(mmName).getLoadedPackages(); EPackage aPackage = packages.stream().filter(p -> p.getESuperPackage() == null ).findAny().orElse(null); if ( aPackage != null ) { qfa.mmModify(aPackage, mmName, (pkg) -> { EClass newClass = EcoreFactory.eINSTANCE.createEClass(); newClass.setName(me.getName()); pkg.getEClassifiers().add(newClass); }); } return qfa; }
public EPackage extractSource(Resource r, String name, String conceptURI, String conceptPrefix, String info) { conceptPkg = EcoreFactory.eINSTANCE.createEPackage(); conceptPkg.setName(name); conceptPkg.setNsURI(conceptURI); conceptPkg.setNsPrefix(conceptPrefix); EAnnotation ann = EcoreFactory.eINSTANCE.createEAnnotation(); //ann.getDetails().put("error", name); ann.setSource(info); conceptPkg.getEAnnotations().add(ann); r.getContents().add(conceptPkg); //copyClasses(directUsedTypes); //copyClasses(indirectUsedTypes); for(EAnnotation extra : data.getPackageAnnotations()) { conceptPkg.getEAnnotations().add(extra); } transform(this); // fillFeatures(directUsedTypes); return conceptPkg; }
/** * @generated */ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { for (Iterator it = myDescriptors.iterator(); it.hasNext();) { CreateViewRequest.ViewDescriptor nextDescriptor = (CreateViewRequest.ViewDescriptor) it .next(); View view = (View) nextDescriptor.getAdapter(View.class); if (view != null && view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ EAnnotation shortcutAnnotation = EcoreFactory.eINSTANCE .createEAnnotation(); shortcutAnnotation.setSource("Shortcut"); //$NON-NLS-1$ shortcutAnnotation .getDetails() .put("modelID", SimpleBPMN.diagram.edit.parts.BusinessProcessDiagramEditPart.MODEL_ID); //$NON-NLS-1$ view.getEAnnotations().add(shortcutAnnotation); } } return CommandResult.newOKCommandResult(); }
public static void setDocumentation(EModelElement eModelElement, String documentation) { EAnnotation eAnnotation = eModelElement.getEAnnotation(GEN_MODEL_PACKAGE_NS_URI); if (documentation == null) { if (eAnnotation != null) { eAnnotation.getDetails().removeKey("documentation"); } } else { if (eAnnotation == null) { eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation(); eAnnotation.setSource(GEN_MODEL_PACKAGE_NS_URI); eModelElement.getEAnnotations().add(eAnnotation); } eAnnotation.getDetails().put("documentation", documentation); } }
public static void setAnnotation(EModelElement eModelElement, String sourceURI, String key, String value) { EAnnotation eAnnotation = eModelElement.getEAnnotation(sourceURI); if (value == null) { if (eAnnotation != null) { eAnnotation.getDetails().removeKey(key); } } else { if (eAnnotation == null) { eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation(); eAnnotation.setSource(sourceURI); eModelElement.getEAnnotations().add(eAnnotation); } eAnnotation.getDetails().put(key, value); } }
/** * Sets or removes annotations on the given structural feature to prevent generation of accessor methods in its interface. * @param eStructuralFeature the structural feature * @param accessor the type of accessor method, one of {@link #GET}, {@link #SET}, {@link #IS_SET}, or {@link #UNSET} * @param suppress whether the specified accessor's visibility should be suppressed * @since 2.1 */ public static void setSuppressedVisibility(EStructuralFeature eStructuralFeature, int accessor, boolean suppress) { if (accessor < GET || accessor > UNSET) throw new IllegalArgumentException("Invalid accessor identifier: " + accessor); EAnnotation eAnnotation = eStructuralFeature.getEAnnotation(GEN_MODEL_PACKAGE_NS_URI); if (!suppress) { if (eAnnotation != null) { eAnnotation.getDetails().removeKey(ACCESSOR_KEYS[accessor]); } } else { if (eAnnotation == null) { eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation(); eAnnotation.setSource(GEN_MODEL_PACKAGE_NS_URI); eStructuralFeature.getEAnnotations().add(eAnnotation); } eAnnotation.getDetails().put(ACCESSOR_KEYS[accessor], TRUE); } }
/** * Sets or removes the annotation on the given operation to prevent generation of a method declaration in its interface. * @param eOperation the operation. * @param suppress whether the visibility should be suppressed * @since 2.4 */ public static void setSuppressedVisibility(EOperation eOperation, boolean suppress) { EAnnotation eAnnotation = eOperation.getEAnnotation(GEN_MODEL_PACKAGE_NS_URI); if (!suppress) { if (eAnnotation != null) { eAnnotation.getDetails().removeKey(OPERATION_VISIBILITY_KEY); } } else { if (eAnnotation == null) { eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation(); eAnnotation.setSource(GEN_MODEL_PACKAGE_NS_URI); eOperation.getEAnnotations().add(eAnnotation); } eAnnotation.getDetails().put(OPERATION_VISIBILITY_KEY, TRUE); } }