Java Code Examples for org.eclipse.emf.codegen.ecore.genmodel.GenModel#validate()

The following examples show how to use org.eclipse.emf.codegen.ecore.genmodel.GenModel#validate() . 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: 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 2
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 3
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 4
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 5
Source File: AbstractPortableURIsTest.java    From xtext-core 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());
	}
}