Search in sources :

Example 16 with Keyword

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

the class GrammarParserTest method testKeyword.

@Test
public void testKeyword() throws Exception {
    Keyword keyword = (Keyword) getModel("'keyword'");
    assertNotNull(keyword);
    assertEquals("keyword", keyword.getValue());
}
Also used : Keyword(org.eclipse.xtext.Keyword) Test(org.junit.Test)

Example 17 with Keyword

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

the class XtextValidationTest method testCheckCrossReferenceTerminal_05.

@Test
public void testCheckCrossReferenceTerminal_05() throws Exception {
    XtextValidator validator = get(XtextValidator.class);
    CrossReference reference = XtextFactory.eINSTANCE.createCrossReference();
    Keyword keyword = XtextFactory.eINSTANCE.createKeyword();
    reference.setTerminal(keyword);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkCrossReferenceTerminal(reference);
    messageAcceptor.validate();
}
Also used : Keyword(org.eclipse.xtext.Keyword) CrossReference(org.eclipse.xtext.CrossReference) Test(org.junit.Test)

Example 18 with Keyword

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

the class EnumLiteralSerializer method serializeAssignedEnumLiteral.

@Override
public String serializeAssignedEnumLiteral(EObject context, RuleCall ruleCall, Object value, INode node) {
    Keyword nodeLit = getLiteral(node);
    Keyword modelLit = getLiteral(context, ruleCall, value);
    if (nodeLit != null && nodeLit.equals(modelLit))
        return ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL;
    return modelLit.getValue();
}
Also used : Keyword(org.eclipse.xtext.Keyword)

Example 19 with Keyword

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

the class DefaultLocationInFileProvider method getLocationNodes.

protected List<INode> getLocationNodes(EObject obj) {
    final EStructuralFeature nameFeature = getIdentifierFeature(obj);
    if (nameFeature != null) {
        List<INode> result = NodeModelUtils.findNodesForFeature(obj, nameFeature);
        if (!result.isEmpty())
            return result;
    }
    List<INode> resultNodes = Lists.newArrayList();
    final ICompositeNode startNode = findNodeFor(obj);
    INode keywordNode = null;
    // use LeafNodes instead of children?
    for (INode child : startNode.getChildren()) {
        EObject grammarElement = child.getGrammarElement();
        if (grammarElement instanceof RuleCall) {
            RuleCall ruleCall = (RuleCall) grammarElement;
            String ruleName = ruleCall.getRule().getName();
            if (ruleName.equals("ID")) {
                resultNodes.add(child);
            }
        } else if (grammarElement instanceof Keyword) {
            // TODO use only keywords, that aren't symbols like '=' ?
            if (keywordNode == null && useKeyword((Keyword) grammarElement, obj)) {
                keywordNode = child;
            }
        }
    }
    if (resultNodes.isEmpty() && keywordNode != null)
        resultNodes.add(keywordNode);
    return resultNodes;
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) Keyword(org.eclipse.xtext.Keyword) EObject(org.eclipse.emf.ecore.EObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) RuleCall(org.eclipse.xtext.RuleCall)

Example 20 with Keyword

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

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