Search in sources :

Example 26 with TypeRef

use of org.eclipse.xtext.TypeRef in project xtext-core by eclipse.

the class XtextValidationTest method testCheckCrossReferenceTerminal_01.

@Test
public void testCheckCrossReferenceTerminal_01() throws Exception {
    XtextValidator validator = get(XtextValidator.class);
    CrossReference reference = XtextFactory.eINSTANCE.createCrossReference();
    RuleCall call = XtextFactory.eINSTANCE.createRuleCall();
    reference.setTerminal(call);
    ParserRule rule = XtextFactory.eINSTANCE.createParserRule();
    call.setRule(rule);
    TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef();
    rule.setType(typeRef);
    typeRef.setClassifier(EcorePackage.Literals.ESTRING);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkCrossReferenceTerminal(reference);
    messageAcceptor.validate();
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) TypeRef(org.eclipse.xtext.TypeRef) CrossReference(org.eclipse.xtext.CrossReference) RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Example 27 with TypeRef

use of org.eclipse.xtext.TypeRef in project xtext-core by eclipse.

the class TreeConstTest method assertTypes.

private void assertTypes(Collection<TypeRef> actual, String... expected) {
    Set<String> refs = Sets.newHashSet();
    for (TypeRef t : actual) refs.add(t == null ? "null" : t.getClassifier().getName());
    Set<String> actual2 = Sets.newHashSet(refs);
    for (String e : expected) {
        if (refs.contains(e))
            refs.remove(e);
        else
            fail("Type '" + e + "' not found. Actual:" + actual2 + " Expected: " + Joiner.on(", ").join(expected));
    }
    if (!refs.isEmpty())
        fail("Types '" + refs + "' are not expected. Actual:" + actual2 + " Expected: " + Joiner.on(", ").join(expected));
}
Also used : TypeRef(org.eclipse.xtext.TypeRef)

Aggregations

TypeRef (org.eclipse.xtext.TypeRef)27 RuleCall (org.eclipse.xtext.RuleCall)13 ParserRule (org.eclipse.xtext.ParserRule)11 Test (org.junit.Test)9 AbstractRule (org.eclipse.xtext.AbstractRule)8 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)7 CrossReference (org.eclipse.xtext.CrossReference)7 Action (org.eclipse.xtext.Action)5 EObject (org.eclipse.emf.ecore.EObject)4 Assignment (org.eclipse.xtext.Assignment)4 EnumLiteralDeclaration (org.eclipse.xtext.EnumLiteralDeclaration)4 EnumRule (org.eclipse.xtext.EnumRule)4 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)4 EClassifier (org.eclipse.emf.ecore.EClassifier)3 EPackage (org.eclipse.emf.ecore.EPackage)3 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)3 Keyword (org.eclipse.xtext.Keyword)3 NamedArgument (org.eclipse.xtext.NamedArgument)3 ReferencedMetamodel (org.eclipse.xtext.ReferencedMetamodel)3 TerminalRule (org.eclipse.xtext.TerminalRule)3