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();
}
java类org.eclipse.emf.ecore.EcoreFactory的实例源码
TestChangeDescriptionReverse.java 文件源码
项目:OpenSPIFe
阅读 15
收藏 0
点赞 0
评论 0
OCCIExtension2Ecore.java 文件源码
项目:OCCI-Studio
阅读 17
收藏 0
点赞 0
评论 0
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;
}
OCCIExtension2Ecore.java 文件源码
项目:OCCI-Studio
阅读 16
收藏 0
点赞 0
评论 0
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;
}
OCCIExtension2Ecore.java 文件源码
项目:OCCI-Studio
阅读 18
收藏 0
点赞 0
评论 0
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);
}
}
OCCIExtension2Ecore.java 文件源码
项目:OCCI-Studio
阅读 18
收藏 0
点赞 0
评论 0
/**
* 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;
}
OCCIExtension2Ecore.java 文件源码
项目:OCCI-Studio
阅读 18
收藏 0
点赞 0
评论 0
/**
* 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;
}
PersonHelper.java 文件源码
项目:benchmarx
阅读 16
收藏 0
点赞 0
评论 0
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;
}
}
}
EcoreResourceDescriptionManagerTest.java 文件源码
项目:xtext-extras
阅读 17
收藏 0
点赞 0
评论 0
@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());
}
EcoreResourceDescriptionManagerTest.java 文件源码
项目:xtext-extras
阅读 14
收藏 0
点赞 0
评论 0
@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());
}
EClassifierInfo.java 文件源码
项目:xtext-core
阅读 14
收藏 0
点赞 0
评论 0
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;
}
XtextLinkingService.java 文件源码
项目:xtext-core
阅读 21
收藏 0
点赞 0
评论 0
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);
}
SerializationUtilTest.java 文件源码
项目:xtext-core
阅读 17
收藏 0
点赞 0
评论 0
@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());
}
CompositeEValidatorTest.java 文件源码
项目:xtext-core
阅读 17
收藏 0
点赞 0
评论 0
/** 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());
}
NamesAreUniqueValidationHelperTest.java 文件源码
项目:xtext-core
阅读 18
收藏 0
点赞 0
评论 0
@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());
}
DefaultEcoreElementFactoryTest.java 文件源码
项目:xtext-core
阅读 19
收藏 0
点赞 0
评论 0
@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());
}
EcoreUtil2Test.java 文件源码
项目:xtext-core
阅读 22
收藏 0
点赞 0
评论 0
@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);
}
EcoreUtil2Test.java 文件源码
项目:xtext-core
阅读 18
收藏 0
点赞 0
评论 0
@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);
}
ScopesTest.java 文件源码
项目:xtext-core
阅读 20
收藏 0
点赞 0
评论 0
@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());
}
ScopesTest.java 文件源码
项目:xtext-core
阅读 24
收藏 0
点赞 0
评论 0
@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());
}
OnChangeEvictingCacheAdapterTest.java 文件源码
项目:xtext-core
阅读 17
收藏 0
点赞 0
评论 0
@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);
}
ShortFragmentProviderTest.java 文件源码
项目:dsl-devkit
阅读 15
收藏 0
点赞 0
评论 0
@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);
}
AbstractTypeProviderTest.java 文件源码
项目:dsl-devkit
阅读 21
收藏 0
点赞 0
评论 0
@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);
}
FastReferenceSearchResultContentProvider.java 文件源码
项目:dsl-devkit
阅读 23
收藏 0
点赞 0
评论 0
/**
* 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;
}
});
}
}
ToscaUtil.java 文件源码
项目:caml2tosca
阅读 19
收藏 0
点赞 0
评论 0
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);
}
}
TreeLayoutUtil.java 文件源码
项目:statecharts
阅读 15
收藏 0
点赞 0
评论 0
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);
}
}
}
TestJavaScript.java 文件源码
项目:OpenSPIFe
阅读 17
收藏 0
点赞 0
评论 0
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();
}
TestEMFUtils.java 文件源码
项目:OpenSPIFe
阅读 14
收藏 0
点赞 0
评论 0
@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());
}
TestEMFUtils.java 文件源码
项目:OpenSPIFe
阅读 15
收藏 0
点赞 0
评论 0
@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);
}
TestEMFUtils.java 文件源码
项目:OpenSPIFe
阅读 14
收藏 0
点赞 0
评论 0
@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);
}
TestEMFUtils.java 文件源码
项目:OpenSPIFe
阅读 14
收藏 0
点赞 0
评论 0
@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);
}