Java Code Examples for org.eclipse.xtext.util.EmfFormatter#objToStr()

The following examples show how to use org.eclipse.xtext.util.EmfFormatter#objToStr() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CondititionSimplifierTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void check(String expectation, String model) throws Exception {
	EObject parsedModel = getModel(model);
	EObject parsedExpectation = getModel(expectation);
	conditionSimplifier.simplify((IfCondition) parsedModel);
	String formattedModel = EmfFormatter.objToStr(parsedModel);
	String formattedExpectation = EmfFormatter.objToStr(parsedExpectation);
	assertEquals(formattedExpectation, formattedModel);
}
 
Example 2
Source File: SerializerTestHelper.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void assertEqualWithEmfFormatter(EObject semanticObject, EObject parsed) {
	String expected = EmfFormatter.objToStr(semanticObject);
	String actual = EmfFormatter.objToStr(parsed);
	Assert.assertEquals(expected, actual);
}
 
Example 3
Source File: SarlSkillBuilderImpl.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
@Pure
public String toString() {
	return EmfFormatter.objToStr(getSarlSkill());
}
 
Example 4
Source File: SarlArtifactBuilderImpl.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
@Pure
public String toString() {
	return EmfFormatter.objToStr(getSarlArtifact());
}
 
Example 5
Source File: SarlActionBuilderImpl.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
@Pure
public String toString() {
	return EmfFormatter.objToStr(getSarlAction());
}
 
Example 6
Source File: ScriptBuilderImpl.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
@Pure
public String toString() {
	return EmfFormatter.objToStr(this.script);
}
 
Example 7
Source File: SarlFieldBuilderImpl.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
@Pure
public String toString() {
	return EmfFormatter.objToStr(getSarlField());
}
 
Example 8
Source File: SarlSpaceBuilderImpl.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
@Pure
public String toString() {
	return EmfFormatter.objToStr(getSarlSpace());
}
 
Example 9
Source File: EmfAssert.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public static void assertEObjectsEqual(EObject expected, EObject actual,
		EStructuralFeature... ignoredFeatures) {
	String e = EmfFormatter.objToStr(expected, ignoredFeatures);
	String a = EmfFormatter.objToStr(actual, ignoredFeatures);
	assertEquals(e, a);
}
 
Example 10
Source File: SarlClassBuilderImpl.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
@Pure
public String toString() {
	return EmfFormatter.objToStr(getSarlClass());
}
 
Example 11
Source File: BuilderUtil.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/***/
public static String toString(IResourceDescription desc) {
	if (desc == null)
		return "null";
	return EmfFormatter.objToStr(desc, new EStructuralFeature[0]);
}
 
Example 12
Source File: URIsInEcoreFilesXtendTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
protected void doTestResource(String platformPath, String... packageNames) {
	Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true);
	assertNotNull(resource);
	assertEquals(1, resource.getContents().size());
	EObject obj = resource.getContents().get(0);
	if (obj instanceof EPackage) {
		assertEquals(packageNames[0], ((EPackage) obj).getName());
	} else if (obj instanceof GenModel) {
		GenModel model = (GenModel) obj;
		List<GenPackage> packages = Lists.newArrayList(model.getGenPackages());
		assertEquals(packageNames.length, packages.size());
		ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() {
			@Override
			public String apply(GenPackage p) {
				return p.getEcorePackage().getName();
			}
		});
		List<String> packageNamesList = Arrays.asList(packageNames);
		Collections.sort(packageNamesList);
		for(int i = 0; i < packageNamesList.size(); i++) {
			assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName());
		}
		IStatus status = model.validate();
		assertTrue(printLeafs(status), status.isOK());
		EObject orig = EcoreUtil.copy(obj);
		((GenModel) obj).reconcile();
		if (!EcoreUtil.equals(orig, obj)) {
			Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() {
				@Override
				public boolean apply(EStructuralFeature f) {
					if (f instanceof EReference) {
						EReference casted = (EReference) f;
						return !casted.isContainment();
					}
					return false;
				}
			};
			String origAsString = EmfFormatter.objToStr(orig, ignoreContainer);
			String newAsString = EmfFormatter.objToStr(obj, ignoreContainer);
			throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString);
		}
	} else {
		fail("Unexpected root element type: " + obj.eClass().getName());
	}
}
 
Example 13
Source File: SarlCapacityBuilderImpl.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
@Pure
public String toString() {
	return EmfFormatter.objToStr(getSarlCapacity());
}
 
Example 14
Source File: AbstractPortableURIsTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected void doTestResource(String platformPath, String... packageNames) {
	Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true);
	assertNotNull(resource);
	assertEquals(1, resource.getContents().size());
	EObject obj = resource.getContents().get(0);
	if (obj instanceof EPackage) {
		assertEquals(packageNames[0], ((EPackage) obj).getName());
	} else if (obj instanceof GenModel) {
		GenModel model = (GenModel) obj;
		List<GenPackage> packages = Lists.newArrayList(model.getGenPackages());
		assertEquals(packageNames.length, packages.size());
		ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() {
			@Override
			public String apply(GenPackage p) {
				return p.getEcorePackage().getName();
			}
		});
		List<String> packageNamesList = Arrays.asList(packageNames);
		Collections.sort(packageNamesList);
		for(int i = 0; i < packageNamesList.size(); i++) {
			assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName());
		}
		IStatus status = model.validate();
		assertTrue(printLeafs(status), status.isOK());
		EObject orig = EcoreUtil.copy(obj);
		((GenModel) obj).reconcile();
		if (!EcoreUtil.equals(orig, obj)) {
			Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() {
				@Override
				public boolean apply(EStructuralFeature f) {
					if (f instanceof EReference) {
						EReference casted = (EReference) f;
						return !casted.isContainment();
					}
					return false;
				}
			};
			String origAsString = EmfFormatter.objToStr(orig, ignoreContainer);
			String newAsString = EmfFormatter.objToStr(obj, ignoreContainer);
			throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString);
		}
	} else {
		fail("Unexpected root element type: " + obj.eClass().getName());
	}
}
 
Example 15
Source File: BuilderUtil.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public static String toString(IResourceDescription desc) {
	if (desc==null)
		return "null";
	return EmfFormatter.objToStr(desc, new EStructuralFeature[0]);
}
 
Example 16
Source File: EmfAssert.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public static void assertEObjectsEqual(EObject expected, EObject actual,
		EStructuralFeature... ignoredFeatures) {
	String e = EmfFormatter.objToStr(expected, ignoredFeatures);
	String a = EmfFormatter.objToStr(actual, ignoredFeatures);
	assertEquals(e, a);
}
 
Example 17
Source File: AbstractPortableURIsTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void doTestResource(String platformPath, String... packageNames) {
	Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true);
	assertNotNull(resource);
	assertEquals(1, resource.getContents().size());
	EObject obj = resource.getContents().get(0);
	if (obj instanceof EPackage) {
		assertEquals(packageNames[0], ((EPackage) obj).getName());
	} else if (obj instanceof GenModel) {
		GenModel model = (GenModel) obj;
		List<GenPackage> packages = Lists.newArrayList(model.getGenPackages());
		assertEquals(packageNames.length, packages.size());
		ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() {
			@Override
			public String apply(GenPackage p) {
				return p.getEcorePackage().getName();
			}
		});
		List<String> packageNamesList = Arrays.asList(packageNames);
		Collections.sort(packageNamesList);
		for(int i = 0; i < packageNamesList.size(); i++) {
			assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName());
		}
		IStatus status = model.validate();
		assertTrue(printLeafs(status), status.isOK());
		EObject orig = EcoreUtil.copy(obj);
		((GenModel) obj).reconcile();
		if (!EcoreUtil.equals(orig, obj)) {
			Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() {
				@Override
				public boolean apply(EStructuralFeature f) {
					if (f instanceof EReference) {
						EReference casted = (EReference) f;
						return !casted.isContainment();
					}
					return false;
				}
			};
			String origAsString = EmfFormatter.objToStr(orig, ignoreContainer);
			String newAsString = EmfFormatter.objToStr(obj, ignoreContainer);
			throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString);
		}
	} else {
		fail("Unexpected root element type: " + obj.eClass().getName());
	}
}
 
Example 18
Source File: SerializerTester.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.3
 */
protected void assertEqualWithEmfFormatter(EObject semanticObject, EObject parsed) {
	String expected = EmfFormatter.objToStr(semanticObject);
	String actual = EmfFormatter.objToStr(parsed);
	Assert.assertEquals(expected, actual);
}
 
Example 19
Source File: SarlEventBuilderImpl.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
@Pure
public String toString() {
	return EmfFormatter.objToStr(getSarlEvent());
}
 
Example 20
Source File: AbstractPortableURIsTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void doTestResource(String platformPath, String... packageNames) {
	Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true);
	assertNotNull(resource);
	assertEquals(1, resource.getContents().size());
	EObject obj = resource.getContents().get(0);
	if (obj instanceof EPackage) {
		assertEquals(packageNames[0], ((EPackage) obj).getName());
	} else if (obj instanceof GenModel) {
		GenModel model = (GenModel) obj;
		List<GenPackage> packages = Lists.newArrayList(model.getGenPackages());
		assertEquals(packageNames.length, packages.size());
		ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() {
			@Override
			public String apply(GenPackage p) {
				return p.getEcorePackage().getName();
			}
		});
		List<String> packageNamesList = Arrays.asList(packageNames);
		Collections.sort(packageNamesList);
		for(int i = 0; i < packageNamesList.size(); i++) {
			assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName());
		}
		IStatus status = model.validate();
		assertTrue(printLeafs(status), status.isOK());
		EObject orig = EcoreUtil.copy(obj);
		((GenModel) obj).reconcile();
		if (!EcoreUtil.equals(orig, obj)) {
			Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() {
				@Override
				public boolean apply(EStructuralFeature f) {
					if (f instanceof EReference) {
						EReference casted = (EReference) f;
						return !casted.isContainment();
					}
					return false;
				}
			};
			String origAsString = EmfFormatter.objToStr(orig, ignoreContainer);
			String newAsString = EmfFormatter.objToStr(obj, ignoreContainer);
			throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString);
		}
	} else {
		fail("Unexpected root element type: " + obj.eClass().getName());
	}
}