aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormeysholdt2009-03-11 13:44:52 (EDT)
committersefftinge2009-03-11 13:44:52 (EDT)
commit50e590c2c804b931176d870b254a0ec59cc90bfc (patch)
tree446e98ef77c9c408a32488f5ad095b93a099d3a6
parent5bc997dd7ab9ac17d8ed3f3343c0ea1a50979e2c (diff)
downloadorg.eclipse.xtext-50e590c2c804b931176d870b254a0ec59cc90bfc.zip
org.eclipse.xtext-50e590c2c804b931176d870b254a0ec59cc90bfc.tar.gz
org.eclipse.xtext-50e590c2c804b931176d870b254a0ec59cc90bfc.tar.bz2
removed dependency on EMF Compare and fixed spelling of the EmfFormat!t!er
-rw-r--r--tests/org.eclipse.xtext.generator.tests/META-INF/MANIFEST.MF3
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/AbstractParserComparingTest.java10
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/OffsetInformationTest.java6
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/packrat/PerformanceTestXtextGrammar.java5
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parsetree/reconstr/ComplexReconstrTest.java11
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parsetree/reconstr/SimpleReconstrTest.java8
-rwxr-xr-xtests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/tests/EcoreModelComparator.java141
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/tests/EmfAssert.java165
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/parser/packrat/XtextPackratParserTest.java6
9 files changed, 186 insertions, 169 deletions
diff --git a/tests/org.eclipse.xtext.generator.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.xtext.generator.tests/META-INF/MANIFEST.MF
index 57cd46b..fde1553 100644
--- a/tests/org.eclipse.xtext.generator.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.xtext.generator.tests/META-INF/MANIFEST.MF
@@ -8,9 +8,6 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.xtext,
org.eclipse.xtext.generator,
org.junit,
- org.eclipse.emf.compare,
- org.eclipse.emf.compare.diff,
- org.eclipse.emf.compare.match,
org.eclipse.xtext.log4j;bundle-version="1.2.15",
org.eclipse.xtend,
org.eclipse.xtend.typesystem.emf,
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/AbstractParserComparingTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/AbstractParserComparingTest.java
index af6c769..ca7a164 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/AbstractParserComparingTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/AbstractParserComparingTest.java
@@ -12,7 +12,7 @@ import org.eclipse.xtext.ISetup;
import org.eclipse.xtext.parsetree.ParsetreePackage;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.tests.AbstractGeneratorTest;
-import org.eclipse.xtext.util.EmfFormater;
+import org.eclipse.xtext.util.EmfFormatter;
import org.eclipse.xtext.util.EmfStructureComparator;
import org.eclipse.xtext.util.Pair;
import org.eclipse.xtext.util.StringInputStream;
@@ -61,12 +61,12 @@ public abstract class AbstractParserComparingTest extends AbstractGeneratorTest
checkResource(pair.getFirst() + " - " + getFirstParserName(), firstResult);
checkResource(pair.getFirst() + " - " + getSecondParserName(), secondResult);
- String firstNodeResultAsString = EmfFormater.objToStr(firstResult.getParseResult().getRootNode(), getIgnoredFeatures());
- String secondNodeResultAsString = EmfFormater.objToStr(secondResult.getParseResult().getRootNode(), getIgnoredFeatures());
+ String firstNodeResultAsString = EmfFormatter.objToStr(firstResult.getParseResult().getRootNode(), getIgnoredFeatures());
+ String secondNodeResultAsString = EmfFormatter.objToStr(secondResult.getParseResult().getRootNode(), getIgnoredFeatures());
assertEquals(modelName.get(), firstNodeResultAsString, secondNodeResultAsString);
- String firstResultAsString = EmfFormater.objToStr(firstResult.getParseResult().getRootASTElement());
- String secondResultAsString = EmfFormater.objToStr(secondResult.getParseResult().getRootASTElement());
+ String firstResultAsString = EmfFormatter.objToStr(firstResult.getParseResult().getRootASTElement());
+ String secondResultAsString = EmfFormatter.objToStr(secondResult.getParseResult().getRootASTElement());
assertEquals(modelName.get(), firstResultAsString, secondResultAsString);
comparator.assertSameStructure(firstResult.getParseResult().getRootASTElement(), secondResult.getParseResult().getRootASTElement());
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/OffsetInformationTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/OffsetInformationTest.java
index 9a1c192..4226b01 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/OffsetInformationTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/OffsetInformationTest.java
@@ -6,7 +6,7 @@ import org.eclipse.xtext.parsetree.ParsetreePackage;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.testlanguages.ReferenceGrammarTestLanguageStandaloneSetup;
import org.eclipse.xtext.tests.AbstractGeneratorTest;
-import org.eclipse.xtext.tests.EcoreModelComparator;
+import org.eclipse.xtext.tests.EmfAssert;
import org.eclipse.xtext.util.StringInputStream;
public class OffsetInformationTest extends AbstractGeneratorTest {
@@ -33,10 +33,8 @@ public class OffsetInformationTest extends AbstractGeneratorTest {
String substring = string.substring(i, string.length()-i);
resource.update(i, substring.length(), substring);
CompositeNode model = resource.getParseResult().getRootNode();
- EcoreModelComparator comparator = new EcoreModelComparator();
- comparator.addIgnoredFeature(ParsetreePackage.eINSTANCE.getAbstractNode_Element());
NodeUtil.checkOffsetConsistency(model);
- assertFalse(comparator.modelsDiffer(rootNode, model));
+ EmfAssert.assertEObjectsEqual(rootNode, model,ParsetreePackage.eINSTANCE.getAbstractNode_Element());
}
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/packrat/PerformanceTestXtextGrammar.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/packrat/PerformanceTestXtextGrammar.java
index fb8b1f3..743f698 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/packrat/PerformanceTestXtextGrammar.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/packrat/PerformanceTestXtextGrammar.java
@@ -11,7 +11,7 @@ import org.eclipse.xtext.parser.IParseResult;
import org.eclipse.xtext.parser.terminalrules.XtextTerminalsTestLanguageStandaloneSetup;
import org.eclipse.xtext.parser.terminalrules.parser.packrat.XtextTerminalsTestLanguagePackratParser;
import org.eclipse.xtext.tests.AbstractGeneratorTest;
-import org.eclipse.xtext.tests.EcoreModelComparator;
+import org.eclipse.xtext.tests.EmfAssert;
import org.eclipse.xtext.util.StringInputStream;
/**
@@ -45,8 +45,7 @@ public class PerformanceTestXtextGrammar extends AbstractGeneratorTest {
assertNotNull(antlrResult);
assertNotNull(antlrResult.getRootASTElement());
assertNotNull(antlrResult.getRootNode());
- EcoreModelComparator comparator = new EcoreModelComparator();
- assertFalse(comparator.modelsDiffer(antlrResult.getRootASTElement(), packratResult.getRootASTElement()));
+ EmfAssert.assertEObjectsEqual(antlrResult.getRootASTElement(), packratResult.getRootASTElement());
}
public void testAntlr() {
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parsetree/reconstr/ComplexReconstrTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parsetree/reconstr/ComplexReconstrTest.java
index 954ffa1..777baf6 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parsetree/reconstr/ComplexReconstrTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parsetree/reconstr/ComplexReconstrTest.java
@@ -14,8 +14,8 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.ParserRule;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.tests.AbstractGeneratorTest;
-import org.eclipse.xtext.tests.EcoreModelComparator;
-import org.eclipse.xtext.util.EmfFormater;
+import org.eclipse.xtext.tests.EmfAssert;
+import org.eclipse.xtext.util.EmfFormatter;
public class ComplexReconstrTest extends AbstractGeneratorTest {
@@ -37,7 +37,7 @@ public class ComplexReconstrTest extends AbstractGeneratorTest {
ParserRule pr = (ParserRule) x;
if (pr.getName().toLowerCase().contains("tricky")) {
if (logger.isTraceEnabled())
- logger.trace(EmfFormater.objToStr(pr));
+ logger.trace(EmfFormatter.objToStr(pr));
}
}
}
@@ -55,7 +55,7 @@ public class ComplexReconstrTest extends AbstractGeneratorTest {
private String parseAndSerialize(String model) throws Exception {
EObject result = getModel(model);
if (logger.isTraceEnabled())
- logger.trace(EmfFormater.objToStr(result));
+ logger.trace(EmfFormatter.objToStr(result));
return serialize(result);
}
@@ -83,8 +83,7 @@ public class ComplexReconstrTest extends AbstractGeneratorTest {
InterruptedException {
EObject model = getModel(mymodel);
EObject model2 = getModel(parseAndSerialize(mymodel));
- EcoreModelComparator ecoreModelComparator = new EcoreModelComparator();
- assertFalse(ecoreModelComparator.modelsDiffer(model, model2));
+ EmfAssert.assertEObjectsEqual(model, model2);
}
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parsetree/reconstr/SimpleReconstrTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parsetree/reconstr/SimpleReconstrTest.java
index b496785..feadc66 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parsetree/reconstr/SimpleReconstrTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parsetree/reconstr/SimpleReconstrTest.java
@@ -13,7 +13,7 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.parsetree.NodeUtil;
import org.eclipse.xtext.testlanguages.SimpleExpressionsTestLanguageStandaloneSetup;
import org.eclipse.xtext.tests.AbstractGeneratorTest;
-import org.eclipse.xtext.util.EmfFormater;
+import org.eclipse.xtext.util.EmfFormatter;
public class SimpleReconstrTest extends AbstractGeneratorTest {
@@ -42,9 +42,9 @@ public class SimpleReconstrTest extends AbstractGeneratorTest {
private String parseAndSerialize(String model) throws Exception {
EObject result = getModel(model);
if (logger.isTraceEnabled()) {
- logger.trace(EmfFormater.objToStr(result));
- logger.trace(EmfFormater.objToStr(NodeUtil.getRootNode(result)));
- logger.trace(EmfFormater.objToStr(NodeUtil.getRootNode(result).getLeafNodes()));
+ logger.trace(EmfFormatter.objToStr(result));
+ logger.trace(EmfFormatter.objToStr(NodeUtil.getRootNode(result)));
+ logger.trace(EmfFormatter.objToStr(NodeUtil.getRootNode(result).getLeafNodes()));
}
return serialize(result);
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/tests/EcoreModelComparator.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/tests/EcoreModelComparator.java
deleted file mode 100755
index 2660c37..0000000
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/tests/EcoreModelComparator.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 itemis AG and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * committers of openArchitectureWare - initial API and implementation
- *******************************************************************************/
-package org.eclipse.xtext.tests;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.eclipse.emf.compare.diff.metamodel.AttributeChange;
-import org.eclipse.emf.compare.diff.metamodel.DiffElement;
-import org.eclipse.emf.compare.diff.metamodel.DiffGroup;
-import org.eclipse.emf.compare.diff.metamodel.DiffModel;
-import org.eclipse.emf.compare.diff.metamodel.ReferenceChange;
-import org.eclipse.emf.compare.diff.service.DiffService;
-import org.eclipse.emf.compare.match.api.IMatchEngine;
-import org.eclipse.emf.compare.match.api.MatchOptions;
-import org.eclipse.emf.compare.match.engine.GenericMatchEngine;
-import org.eclipse.emf.compare.match.metamodel.MatchModel;
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-
-/**
- * @author Jan Köhnlein
- *
- */
-public class EcoreModelComparator {
-
- private static final Logger logger = Logger.getLogger(EcoreModelComparator.class);
- private Map<String, Object> options;
- private IMatchEngine matchEngine;
- private List<EStructuralFeature> ignoredFeatures = new ArrayList<EStructuralFeature>();
-
- public EcoreModelComparator() {
- options = new HashMap<String, Object>();
- options.put(MatchOptions.OPTION_DISTINCT_METAMODELS, Boolean.TRUE);
- matchEngine = new GenericMatchEngine();
- }
-
- public boolean modelsDiffer(Resource left, Resource right) throws InterruptedException {
- MatchModel matchModel = matchEngine.resourceMatch(left, right, options);
- return modelsDiffer(matchModel);
- }
-
- public boolean modelsDiffer(EObject left, EObject right) throws InterruptedException {
- try {
- addSyntheticResource(left);
- addSyntheticResource(right);
- MatchModel matchModel = matchEngine.modelMatch(left, right, options);
- return modelsDiffer(matchModel);
- } finally {
- removeSyntheticResource(left);
- removeSyntheticResource(right);
- }
- }
-
- private class SyntheticResource extends ResourceImpl {
-
- }
-
- private void removeSyntheticResource(EObject o) {
- if (o.eResource() instanceof SyntheticResource) {
- o.eResource().getContents().clear();
- }
- }
-
- private void addSyntheticResource(EObject o) {
- if (o.eResource() == null) {
- new SyntheticResource().getContents().add(EcoreUtil.getRootContainer(o));
- }
- }
-
- private boolean modelsDiffer(MatchModel matchModel) {
- boolean modelsDiffer = false;
- DiffModel diffModel = DiffService.doDiff(matchModel);
- if (diffModel != null) {
- for (DiffElement diffElement : diffModel.getOwnedElements()) {
- modelsDiffer |= checkDiff(diffElement);
- }
- }
- return modelsDiffer;
- }
-
- public void addIgnoredFeature(EStructuralFeature feature) {
- ignoredFeatures.add(feature);
- }
-
- private boolean checkDiff(DiffElement diffElement) {
- boolean hasDiff = false;
- if (!ignoreDiff(diffElement)) {
- printDiff(diffElement);
- hasDiff = true;
- }
- for (DiffElement childDiffElement : diffElement.getSubDiffElements()) {
- hasDiff |= checkDiff(childDiffElement);
- }
- return hasDiff;
- }
-
- private boolean ignoreDiff(DiffElement diffElement) {
- if (diffElement instanceof AttributeChange) {
- return ignoredFeatures.contains(((AttributeChange) diffElement).getAttribute());
- } else if (diffElement instanceof ReferenceChange) {
- return ignoredFeatures.contains(((ReferenceChange) diffElement).getReference());
- }
- return diffElement instanceof DiffGroup;
- }
-
- private void printDiff(DiffElement diffElement) {
- if (diffElement instanceof AttributeChange) {
- AttributeChange change = (AttributeChange) diffElement;
- EAttribute attribute = change.getAttribute();
- logger.error("Detected attribute difference: " + attribute.getName());
- logger.error("\t" + change.getLeftElement());
- logger.error("\t" + change.getRightElement());
- } else if (diffElement instanceof ReferenceChange) {
- ReferenceChange change = (ReferenceChange) diffElement;
- EReference reference = change.getReference();
- logger.error("Detected reference difference: " + reference.getName());
- logger.error("\t" + change.getLeftElement() +" "+reference.getName()+" = "+change.getLeftElement().eGet(reference));
- logger.error("\t" + change.getRightElement()+" "+reference.getName()+" = "+change.getRightElement().eGet(reference));
- } else {
- // TODO: add more logging here...
- logger.error(diffElement.toString());
- }
- }
-}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/tests/EmfAssert.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/tests/EmfAssert.java
new file mode 100644
index 0000000..9172518
--- /dev/null
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/tests/EmfAssert.java
@@ -0,0 +1,165 @@
+/*******************************************************************************
+ * Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.xtext.tests;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.fail;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import junit.framework.ComparisonFailure;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.xtext.util.EmfFormatter;
+
+/**
+ * @author Moritz Eysholdt - Initial contribution and API
+ */
+public class EmfAssert {
+
+ static final Pattern SPACE = Pattern.compile("[\\s\\n\\r]+");
+
+ public static void assertTokensEqual(String msg, String expected,
+ String actual) {
+ if (expected == null)
+ fail("expected is null");
+ if (actual == null)
+ fail("actual is null");
+ expected = expected.trim();
+ actual = actual.trim();
+ Matcher expM = SPACE.matcher(expected);
+ Matcher actM = SPACE.matcher(actual);
+ int expS = 0, actS = 0;
+ boolean equal = true;
+ StringBuffer merged = new StringBuffer();
+ while (expM.find() && actM.find()) {
+ String expToken = expected.substring(expS, expM.start());
+ String actToken = actual.substring(actS, actM.start());
+ if (!expToken.equals(actToken)) {
+ equal = false;
+ break;
+ }
+ expS = expM.end();
+ actS = actM.end();
+
+ merged.append(expToken);
+ if (actM.group().length() > expM.group().length())
+ merged.append(actM.group());
+ else
+ merged.append(expM.group());
+ }
+ if (equal) {
+ String expToken = expected.substring(expS);
+ String actToken = actual.substring(actS);
+ equal = expToken.equals(actToken);
+ }
+ if (!equal) {
+ String exp = merged + expected.substring(expS);
+ String act = merged + actual.substring(actS);
+ throw new ComparisonFailure(msg, exp, act);
+ }
+ }
+
+ 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);
+ }
+
+ private static Resource findResource(ResourceSet resources,
+ String matchURIpart) {
+ for (Resource r : resources.getResources())
+ if (r.getURI() != null
+ && r.getURI().toString().contains(matchURIpart))
+ return r;
+ throw new RuntimeException("No Resource with '" + matchURIpart
+ + "' in it's URI found in ResourceSet.");
+ }
+
+ public static void assertResourcesEqual(ResourceSet expected,
+ ResourceSet actual, String matchURIpart,
+ EStructuralFeature... ignoredFeatures) {
+ assertResourcesEqual(findResource(expected, matchURIpart),
+ findResource(actual, matchURIpart), ignoredFeatures);
+ }
+
+ public static void assertResourcesEqual(Resource expected, Resource actual,
+ EStructuralFeature... ignoredFeatures) {
+ assertEquals("Resources have different ammounts of root objects.",
+ expected.getContents().size(), actual.getContents().size());
+ for (int i = 0; i < expected.getContents().size(); i++)
+ assertEObjectsEqual(expected.getContents().get(i), actual
+ .getContents().get(i), ignoredFeatures);
+ }
+
+ public static void assertResourceSetsEqual(ResourceSet expected,
+ ResourceSet actual, EStructuralFeature... ignoredFeatures) {
+ assertEquals("Resources have different ammounts of root objects.",
+ expected.getResources().size(), actual.getResources().size());
+ for (int i = 0; i < expected.getResources().size(); i++)
+ assertResourcesEqual(expected.getResources().get(i), actual
+ .getResources().get(i), ignoredFeatures);
+ }
+
+ public static void assertNoCrossRefsLeaveReources(EObject model,
+ Resource... allowedResources) {
+ assertNoCrossRefsLeaveReources(model, new HashSet<Resource>(Arrays
+ .asList(allowedResources)));
+ }
+
+ private static void assertObjectResource(EObject parent, EReference ref,
+ EObject model, Set<Resource> allowedResources) {
+ String id = parent.eClass().getName() + "("
+ + ref.getEContainingClass().getName() + ")." + ref.getName();
+ assertNotNull("Has no Resource " + id + ": " + model, model.eResource());
+ assertTrue("Resource not Allowed: " + model.eResource().getURI() + "\n"
+ + id + " -> " + model.eClass().getName() + " "
+ + model.eResource().getURIFragment(model), allowedResources
+ .contains(model.eResource()));
+ }
+
+ @SuppressWarnings("unchecked")
+ public static void assertNoCrossRefsLeaveReources(EObject model,
+ Set<Resource> allowedResources) {
+ assertNotNull(model);
+ for (EReference ref : model.eClass().getEAllReferences()) {
+ if (ref.isTransient() || !model.eIsSet(ref))
+ continue;
+ if (ref.isContainment()) {
+ if (ref.isMany())
+ for (Object o : (EList<Object>) model.eGet(ref))
+ assertNoCrossRefsLeaveReources((EObject) o,
+ allowedResources);
+ else
+ assertNoCrossRefsLeaveReources((EObject) model.eGet(ref),
+ allowedResources);
+ } else {
+ if (ref.isMany())
+ for (Object o : (EList<Object>) model.eGet(ref))
+ assertObjectResource(model, ref, (EObject) o,
+ allowedResources);
+ else
+ assertObjectResource(model, ref, (EObject) model.eGet(ref),
+ allowedResources);
+ }
+ }
+ }
+
+}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/parser/packrat/XtextPackratParserTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/parser/packrat/XtextPackratParserTest.java
index 4ac911c..145d528 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/parser/packrat/XtextPackratParserTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/parser/packrat/XtextPackratParserTest.java
@@ -11,7 +11,7 @@ import org.eclipse.xtext.XtextStandaloneSetup;
import org.eclipse.xtext.parser.IParseResult;
import org.eclipse.xtext.parser.packrat.XtextPackratParser;
import org.eclipse.xtext.tests.AbstractGeneratorTest;
-import org.eclipse.xtext.util.EmfFormater;
+import org.eclipse.xtext.util.EmfFormatter;
import org.eclipse.xtext.util.StringInputStream;
/**
@@ -37,10 +37,10 @@ public class XtextPackratParserTest extends AbstractGeneratorTest {
assertNotNull(parseResult);
assertNotNull(parseResult.getRootNode());
assertNotNull(parseResult.getRootASTElement());
- String rootNode = EmfFormater.objToStr(parseResult.getRootASTElement());
+ String rootNode = EmfFormatter.objToStr(parseResult.getRootASTElement());
// printParseResult(parseResult);
IParseResult orig = getParser().parse(new StringInputStream(model));
- String origRootNode = EmfFormater.objToStr(orig.getRootASTElement());
+ String origRootNode = EmfFormatter.objToStr(orig.getRootASTElement());
assertEquals("Model: '" + model + "'", origRootNode, rootNode);
}