Search in sources :

Example 11 with Keyword

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

the class XtextLinkingService method getLinkedMetaModel.

private List<EObject> getLinkedMetaModel(TypeRef context, EReference ref, ILeafNode text) throws IllegalNodeException {
    final ICompositeNode parentNode = text.getParent();
    BidiIterator<INode> iterator = parentNode.getChildren().iterator();
    while (iterator.hasPrevious()) {
        INode child = iterator.previous();
        if (child instanceof ILeafNode) {
            ILeafNode leaf = (ILeafNode) child;
            if (text == leaf)
                return super.getLinkedObjects(context, ref, text);
            if (!(leaf.getGrammarElement() instanceof Keyword) && !leaf.isHidden()) {
                IScope scope = getScope(context, ref);
                return XtextMetamodelReferenceHelper.findBestMetamodelForType(context, text.getText(), leaf.getText(), scope);
            }
        }
    }
    return Collections.emptyList();
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) Keyword(org.eclipse.xtext.Keyword) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) IScope(org.eclipse.xtext.scoping.IScope)

Example 12 with Keyword

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

the class XtextValueConverters method GrammarID.

@ValueConverter(rule = "GrammarID")
public IValueConverter<String> GrammarID() {
    return new AbstractNullSafeConverter<String>() {

        @Override
        protected String internalToValue(String string, INode node) throws ValueConverterException {
            if (node != null) {
                StringBuilder result = new StringBuilder();
                for (ILeafNode leaf : node.getLeafNodes()) {
                    if (!leaf.isHidden()) {
                        if (leaf.getGrammarElement() instanceof Keyword)
                            result.append(leaf.getText());
                        else
                            result.append(ID().toValue(leaf.getText(), leaf));
                    }
                }
                return result.toString();
            } else {
                String[] splitted = string.split("\\.");
                StringBuilder result = new StringBuilder(string.length());
                for (int i = 0; i < splitted.length; i++) {
                    if (i != 0)
                        result.append('.');
                    result.append(ID().toValue(splitted[i], null));
                }
                return result.toString();
            }
        }

        @Override
        protected String internalToString(String value) {
            String[] splitted = value.split("\\.");
            StringBuilder result = new StringBuilder(value.length());
            for (int i = 0; i < splitted.length; i++) {
                if (i != 0)
                    result.append('.');
                result.append(ID().toString(splitted[i]));
            }
            return result.toString();
        }
    };
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) Keyword(org.eclipse.xtext.Keyword) AbstractNullSafeConverter(org.eclipse.xtext.conversion.impl.AbstractNullSafeConverter) IValueConverter(org.eclipse.xtext.conversion.IValueConverter) ValueConverter(org.eclipse.xtext.conversion.ValueConverter)

Example 13 with Keyword

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

the class XtextValueConverters method RuleID.

@ValueConverter(rule = "RuleID")
public IValueConverter<String> RuleID() {
    return new AbstractNullSafeConverter<String>() {

        @Override
        protected String internalToValue(String string, INode node) throws ValueConverterException {
            if (node != null) {
                StringBuilder result = new StringBuilder();
                for (ILeafNode leaf : node.getLeafNodes()) {
                    if (!leaf.isHidden()) {
                        if (leaf.getGrammarElement() instanceof Keyword)
                            result.append(".");
                        else
                            result.append(ID().toValue(leaf.getText(), leaf));
                    }
                }
                return result.toString();
            } else {
                String[] splitted = string.split("\\.");
                StringBuilder result = new StringBuilder(string.length());
                for (int i = 0; i < splitted.length; i++) {
                    if (i != 0)
                        result.append('.');
                    result.append(ID().toValue(splitted[i], null));
                }
                return result.toString();
            }
        }

        @Override
        protected String internalToString(String value) {
            String[] splitted = value.split("\\.");
            StringBuilder result = new StringBuilder(value.length());
            for (int i = 0; i < splitted.length; i++) {
                if (i != 0)
                    result.append("::");
                result.append(ID().toString(splitted[i]));
            }
            return result.toString();
        }
    };
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) Keyword(org.eclipse.xtext.Keyword) AbstractNullSafeConverter(org.eclipse.xtext.conversion.impl.AbstractNullSafeConverter) IValueConverter(org.eclipse.xtext.conversion.IValueConverter) ValueConverter(org.eclipse.xtext.conversion.ValueConverter)

Example 14 with Keyword

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

the class GrammarParserTest method testPrecedencies_05.

@Test
public void testPrecedencies_05() throws Exception {
    UnorderedGroup group = (UnorderedGroup) getModel("name=ID & 'keyword'");
    assertNotNull(group);
    assertEquals(2, group.getElements().size());
    assertTrue(group.getElements().get(0) instanceof Assignment);
    assertTrue(group.getElements().get(1) instanceof Keyword);
}
Also used : Assignment(org.eclipse.xtext.Assignment) Keyword(org.eclipse.xtext.Keyword) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) Test(org.junit.Test)

Example 15 with Keyword

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

the class GrammarParserTest method testPrecedencies_04.

@Test
public void testPrecedencies_04() throws Exception {
    Group group = (Group) getModel("'keyword' ('keyword' & 'keyword') 'keyword'");
    assertNotNull(group);
    assertEquals(3, group.getElements().size());
    assertTrue(group.getElements().get(0) instanceof Keyword);
    assertTrue(group.getElements().get(1) instanceof UnorderedGroup);
    assertTrue(group.getElements().get(2) instanceof Keyword);
}
Also used : Group(org.eclipse.xtext.Group) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) Keyword(org.eclipse.xtext.Keyword) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) Test(org.junit.Test)

Aggregations

Keyword (org.eclipse.xtext.Keyword)67 EObject (org.eclipse.emf.ecore.EObject)15 RuleCall (org.eclipse.xtext.RuleCall)15 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)14 INode (org.eclipse.xtext.nodemodel.INode)13 AbstractElement (org.eclipse.xtext.AbstractElement)9 AbstractRule (org.eclipse.xtext.AbstractRule)9 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)9 Test (org.junit.Test)9 Grammar (org.eclipse.xtext.Grammar)8 ParserRule (org.eclipse.xtext.ParserRule)8 Action (org.eclipse.xtext.Action)7 CrossReference (org.eclipse.xtext.CrossReference)7 Assignment (org.eclipse.xtext.Assignment)6 EnumLiteralDeclaration (org.eclipse.xtext.EnumLiteralDeclaration)6 EnumRule (org.eclipse.xtext.EnumRule)6 Alternatives (org.eclipse.xtext.Alternatives)5 ArrayList (java.util.ArrayList)4 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)4 TerminalRule (org.eclipse.xtext.TerminalRule)4