Search in sources :

Example 6 with TypeRef

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

the class TreeConstState method getTypesToCheck.

public Collection<TypeRef> getTypesToCheck() {
    Map<EClassifier, TypeRef> localTypes = Maps.newLinkedHashMap();
    for (TypeRef t : sortTypes(getTypes())) if (t != null)
        localTypes.put(t.getClassifier(), t);
    List<TreeConstTransition> incomming = getIncommingWithoutRuleCalls();
    if (incomming.isEmpty())
        return localTypes.values();
    for (TreeConstTransition t : incomming) for (TypeRef r : t.getSource().getTypes()) if (r != null && !localTypes.containsKey(r.getClassifier()))
        return localTypes.values();
    return Collections.emptyList();
}
Also used : TypeRef(org.eclipse.xtext.TypeRef) EClassifier(org.eclipse.emf.ecore.EClassifier)

Example 7 with TypeRef

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

the class XtextValidationTest method testCheckRuleCallInUnorderedGroup_02.

@Test
public void testCheckRuleCallInUnorderedGroup_02() throws Exception {
    XtextValidator validator = get(XtextValidator.class);
    UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup();
    RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
    TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef();
    typeRef.setClassifier(EcorePackage.Literals.EBIG_DECIMAL);
    ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
    parserRule.setType(typeRef);
    ruleCall.setRule(parserRule);
    unorderedGroup.getElements().add(ruleCall);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkRuleCallInUnorderedGroup(ruleCall);
    messageAcceptor.validate();
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) TypeRef(org.eclipse.xtext.TypeRef) RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Example 8 with TypeRef

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

the class XtextValidationTest method testBug318424_01.

@Test
public void testBug318424_01() throws Exception {
    XtextValidator validator = get(XtextValidator.class);
    CrossReference reference = XtextFactory.eINSTANCE.createCrossReference();
    TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef();
    reference.setType(typeRef);
    typeRef.setClassifier(EcorePackage.Literals.EBOOLEAN);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(typeRef, true, false);
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkCrossReferenceType(reference);
    messageAcceptor.validate();
}
Also used : TypeRef(org.eclipse.xtext.TypeRef) CrossReference(org.eclipse.xtext.CrossReference) Test(org.junit.Test)

Example 9 with TypeRef

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

the class XtextValidationTest method testBug318424_02.

@Test
public void testBug318424_02() throws Exception {
    XtextValidator validator = get(XtextValidator.class);
    Action action = XtextFactory.eINSTANCE.createAction();
    TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef();
    action.setType(typeRef);
    typeRef.setClassifier(EcorePackage.Literals.EBOOLEAN);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(typeRef, true, false);
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkInstantiatedType(action);
    messageAcceptor.validate();
}
Also used : Action(org.eclipse.xtext.Action) TypeRef(org.eclipse.xtext.TypeRef) Test(org.junit.Test)

Example 10 with TypeRef

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

the class GrammarAccessExtensions method getSingleElementDescription.

private List<String> getSingleElementDescription(final AbstractElement ele) {
    final ArrayList<String> r = new ArrayList<String>(2);
    boolean _matched = false;
    if (ele instanceof Keyword) {
        _matched = true;
        String _value = ((Keyword) ele).getValue();
        r.add(_value);
    }
    if (!_matched) {
        if (ele instanceof Assignment) {
            _matched = true;
            String _feature = ((Assignment) ele).getFeature();
            r.add(_feature);
        }
    }
    if (!_matched) {
        if (ele instanceof RuleCall) {
            _matched = true;
            String _name = ((RuleCall) ele).getRule().getName();
            r.add(_name);
        }
    }
    if (!_matched) {
        if (ele instanceof Action) {
            _matched = true;
            TypeRef _type = ((Action) ele).getType();
            EClassifier _classifier = null;
            if (_type != null) {
                _classifier = _type.getClassifier();
            }
            boolean _tripleNotEquals = (_classifier != null);
            if (_tripleNotEquals) {
                String _name = ((Action) ele).getType().getClassifier().getName();
                r.add(_name);
            }
            boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(((Action) ele).getFeature());
            boolean _not = (!_isNullOrEmpty);
            if (_not) {
                String _feature = ((Action) ele).getFeature();
                r.add(_feature);
            }
        }
    }
    if (!_matched) {
        if (ele instanceof CrossReference) {
            _matched = true;
            TypeRef _type = ((CrossReference) ele).getType();
            EClassifier _classifier = null;
            if (_type != null) {
                _classifier = _type.getClassifier();
            }
            boolean _tripleNotEquals = (_classifier != null);
            if (_tripleNotEquals) {
                String _name = ((CrossReference) ele).getType().getClassifier().getName();
                r.add(_name);
            }
        }
    }
    if (!_matched) {
        if (ele instanceof EnumLiteralDeclaration) {
            _matched = true;
            String _name = ((EnumLiteralDeclaration) ele).getEnumLiteral().getName();
            r.add(_name);
        }
    }
    return r;
}
Also used : Assignment(org.eclipse.xtext.Assignment) Action(org.eclipse.xtext.Action) Keyword(org.eclipse.xtext.Keyword) EnumLiteralDeclaration(org.eclipse.xtext.EnumLiteralDeclaration) TypeRef(org.eclipse.xtext.TypeRef) ArrayList(java.util.ArrayList) EClassifier(org.eclipse.emf.ecore.EClassifier) CrossReference(org.eclipse.xtext.CrossReference) RuleCall(org.eclipse.xtext.RuleCall)

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