mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 16:28:56 +00:00
[479137]improved Misleading error message 'Cannot create datatype' for terminal rule #91
- added test - fixed broken test framework Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
This commit is contained in:
parent
1c5b2b0320
commit
7b2e23b94e
4 changed files with 67 additions and 5 deletions
|
@ -28,7 +28,12 @@ public class TestErrorAcceptor extends Assert implements ErrorAcceptor {
|
|||
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
return "toString".equals(method.getName()) ? "ANY_EOBJECT" : null;
|
||||
if ("toString".equals(method.getName())) {
|
||||
return "ANY_EOBJECT";
|
||||
} else if ("equals".equals(method.getName()) && args.length == 1) {
|
||||
return args[0] instanceof EObject;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -2123,5 +2123,21 @@ class Xtext2EcoreTransformerTest extends AbstractXtextTests {
|
|||
var featureB_a = clazzB.feature("a")
|
||||
assertEquals("Model", featureB_a.EType.name)
|
||||
}
|
||||
|
||||
@Test def void testIssue91() {
|
||||
var String grammar = '''
|
||||
grammar test.Test
|
||||
generate test 'http://test'
|
||||
Foo:
|
||||
bar = BAR
|
||||
;
|
||||
terminal BAR:
|
||||
'bar'
|
||||
;
|
||||
'''
|
||||
errorAcceptorMock.acceptError(TransformationErrorCode.NoSuchTypeAvailable,
|
||||
"Cannot create datatype BAR. Make sure you have imported 'http://www.eclipse.org/emf/2002/Ecore'", TestErrorAcceptor.ANY_EOBJECT)
|
||||
getEPackageFromGrammar(grammar, 1)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ import org.eclipse.xtext.tests.AbstractXtextTests;
|
|||
import org.eclipse.xtext.tests.TestErrorAcceptor;
|
||||
import org.eclipse.xtext.util.OnChangeEvictingCache;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xtext.XtextLinker;
|
||||
import org.eclipse.xtext.xtext.ecoreInference.EClassifierInfos;
|
||||
|
@ -2871,4 +2872,35 @@ public class Xtext2EcoreTransformerTest extends AbstractXtextTests {
|
|||
EStructuralFeature featureB_a = this.<EStructuralFeature>feature(clazzB, "a");
|
||||
Assert.assertEquals("Model", featureB_a.getEType().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIssue91() {
|
||||
try {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("grammar test.Test");
|
||||
_builder.newLine();
|
||||
_builder.append("generate test \'http://test\'");
|
||||
_builder.newLine();
|
||||
_builder.append("Foo:");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("bar = BAR");
|
||||
_builder.newLine();
|
||||
_builder.append(";");
|
||||
_builder.newLine();
|
||||
_builder.append("terminal BAR:");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("\'bar\'");
|
||||
_builder.newLine();
|
||||
_builder.append(";");
|
||||
_builder.newLine();
|
||||
String grammar = _builder.toString();
|
||||
this.errorAcceptorMock.acceptError(TransformationErrorCode.NoSuchTypeAvailable,
|
||||
"Cannot create datatype BAR. Make sure you have imported \'http://www.eclipse.org/emf/2002/Ecore\'", TestErrorAcceptor.ANY_EOBJECT);
|
||||
this.getEPackageFromGrammar(grammar, 1);
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.print.attribute.standard.Media;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EClass;
|
||||
|
@ -28,6 +30,7 @@ import org.eclipse.emf.ecore.EEnumLiteral;
|
|||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.EPackage;
|
||||
import org.eclipse.emf.ecore.EcoreFactory;
|
||||
import org.eclipse.emf.ecore.EcorePackage;
|
||||
import org.eclipse.emf.ecore.InternalEObject;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
|
@ -1016,12 +1019,18 @@ public class Xtext2EcoreTransformer {
|
|||
|
||||
EClassifier classifier = generatedEPackage.getEClassifier(classifierName);
|
||||
if (classifier == null) {
|
||||
if (GrammarUtil.containingParserRule(typeRef) != null)
|
||||
if (GrammarUtil.containingParserRule(typeRef) != null) {
|
||||
classifier = EcoreFactory.eINSTANCE.createEClass();
|
||||
else if (GrammarUtil.containingEnumRule(typeRef) != null)
|
||||
} else if (GrammarUtil.containingEnumRule(typeRef) != null) {
|
||||
classifier = EcoreFactory.eINSTANCE.createEEnum();
|
||||
else
|
||||
throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable, "Cannot create datatype " + classifierName, typeRef);
|
||||
} else {
|
||||
for (AbstractMetamodelDeclaration mmd : grammar.getMetamodelDeclarations()) {
|
||||
if (mmd instanceof ReferencedMetamodel && mmd.getEPackage() != null && mmd.getEPackage().getNsURI().equals(EcorePackage.eNS_URI)) {
|
||||
throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable, "Cannot create datatype " + classifierName, typeRef);
|
||||
}
|
||||
}
|
||||
throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable, "Cannot create datatype " + classifierName + ". Make sure you have imported '"+EcorePackage.eNS_URI+"'", typeRef);
|
||||
}
|
||||
classifier.setName(classifierName);
|
||||
generatedEPackage.getEClassifiers().add(classifier);
|
||||
typeRef.setClassifier(classifier);
|
||||
|
|
Loading…
Reference in a new issue