Search in sources :

Example 6 with CrossReference

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

the class Linker method ensureLinked.

private void ensureLinked(EObject obj, IDiagnosticProducer producer, ICompositeNode node, Set<EReference> handledReferences, boolean dontCheckParent) {
    for (INode abstractNode = node.getFirstChild(); abstractNode != null; abstractNode = abstractNode.getNextSibling()) {
        EObject grammarElement = abstractNode.getGrammarElement();
        if (grammarElement instanceof CrossReference) {
            CrossReference ref = (CrossReference) grammarElement;
            producer.setNode(abstractNode);
            ensureIsLinked(obj, abstractNode, ref, handledReferences, producer);
        } else if (grammarElement instanceof RuleCall && abstractNode instanceof ICompositeNode) {
            RuleCall ruleCall = (RuleCall) grammarElement;
            AbstractRule calledRule = ruleCall.getRule();
            if (calledRule instanceof ParserRule && ((ParserRule) calledRule).isFragment()) {
                ensureLinked(obj, producer, (ICompositeNode) abstractNode, handledReferences, true);
            }
        }
    }
    if (!dontCheckParent && shouldCheckParentNode(node)) {
        ensureLinked(obj, producer, node.getParent(), handledReferences, false);
    }
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) INode(org.eclipse.xtext.nodemodel.INode) EObject(org.eclipse.emf.ecore.EObject) CrossReference(org.eclipse.xtext.CrossReference) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) AbstractRule(org.eclipse.xtext.AbstractRule) RuleCall(org.eclipse.xtext.RuleCall)

Example 7 with CrossReference

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

the class AbstractFormattingConfig method getAbstractElements.

protected List<AbstractElement> getAbstractElements(EObject obj) {
    if (obj instanceof AbstractElement)
        return Collections.singletonList((AbstractElement) obj);
    if (obj instanceof AbstractRule) {
        AbstractRule rule = (AbstractRule) obj;
        if (rule.getType().getClassifier() instanceof EClass)
            return Collections.singletonList(rule.getAlternatives());
        List<AbstractElement> result = Lists.newArrayList();
        for (RuleCall rc : grammarAccess.findRuleCalls(rule)) {
            CrossReference cr = GrammarUtil.containingCrossReference(rc);
            result.add(cr == null ? rc : cr);
        }
        return result;
    }
    return null;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) AbstractElement(org.eclipse.xtext.AbstractElement) CrossReference(org.eclipse.xtext.CrossReference) AbstractRule(org.eclipse.xtext.AbstractRule) RuleCall(org.eclipse.xtext.RuleCall)

Example 8 with CrossReference

use of org.eclipse.xtext.CrossReference 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 CrossReference

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

the class GrammarUtilTest method testGetReference.

@Test
public void testGetReference() throws Exception {
    this.with(LangATestLanguageStandaloneSetup.class);
    XtextResource resource = this.getResourceFromStringAndExpect("type A extends B", 1);
    Assignment asExtends = this.<LangATestLanguageGrammarAccess>get(LangATestLanguageGrammarAccess.class).getTypeAccess().getExtendsAssignment_2_1();
    AbstractElement _terminal = asExtends.getTerminal();
    CrossReference xref = ((CrossReference) _terminal);
    EObject _model = this.getModel(resource);
    Main model = ((Main) _model);
    EObject typeA = model.getTypes().get(0);
    EReference ref = GrammarUtil.getReference(xref, typeA.eClass());
    Assert.assertNotNull(ref);
    Assert.assertEquals("extends", ref.getName());
    Assert.assertFalse(ref.isMany());
    Assert.assertEquals(typeA.eClass(), ref.getEReferenceType());
}
Also used : Assignment(org.eclipse.xtext.Assignment) AbstractElement(org.eclipse.xtext.AbstractElement) EObject(org.eclipse.emf.ecore.EObject) LangATestLanguageGrammarAccess(org.eclipse.xtext.linking.services.LangATestLanguageGrammarAccess) CrossReference(org.eclipse.xtext.CrossReference) XtextResource(org.eclipse.xtext.resource.XtextResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 10 with CrossReference

use of org.eclipse.xtext.CrossReference 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

CrossReference (org.eclipse.xtext.CrossReference)29 RuleCall (org.eclipse.xtext.RuleCall)13 EObject (org.eclipse.emf.ecore.EObject)12 AbstractRule (org.eclipse.xtext.AbstractRule)9 ParserRule (org.eclipse.xtext.ParserRule)8 EReference (org.eclipse.emf.ecore.EReference)7 Assignment (org.eclipse.xtext.Assignment)7 TypeRef (org.eclipse.xtext.TypeRef)7 Test (org.junit.Test)7 AbstractElement (org.eclipse.xtext.AbstractElement)6 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)6 INode (org.eclipse.xtext.nodemodel.INode)6 Action (org.eclipse.xtext.Action)5 EnumLiteralDeclaration (org.eclipse.xtext.EnumLiteralDeclaration)4 TerminalRule (org.eclipse.xtext.TerminalRule)4 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)4 ArrayList (java.util.ArrayList)3 EClass (org.eclipse.emf.ecore.EClass)3 EnumRule (org.eclipse.xtext.EnumRule)3 Keyword (org.eclipse.xtext.Keyword)3