Search in sources :

Example 56 with Action

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

the class NodeModelBasedRegionAccessBuilder method process.

protected void process(INode node, NodeModelBasedRegionAccess access) {
    NodeEObjectRegion tokens = stack.peek();
    boolean creator = isEObjectRoot(node);
    if (creator || tokens == null) {
        tokens = createTokens(access, node);
        tokens.setLeadingHiddenRegion(lastHidden);
        NodeEObjectRegion parent = stack.peek();
        if (parent != null) {
            parent.addChild(tokens);
        }
        stack.push(tokens);
    }
    if (tokens.getSemanticElement() == null) {
        if (node.getParent() == null) {
            tokens.setSemanticElement(resource.getContents().get(0));
            EObject element = node.getGrammarElement();
            if (element instanceof Action)
                element = ((ICompositeNode) node).getFirstChild().getGrammarElement();
            tokens.setGrammarElement(element);
        } else if (node.hasDirectSemanticElement()) {
            tokens.setSemanticElement(node.getSemanticElement());
            tokens.setGrammarElement(findGrammarElement(node, tokens.getSemanticElement()));
        }
    }
    if (include(node)) {
        if (node instanceof ICompositeNode) {
            for (ILeafNode leaf : node.getLeafNodes()) if (leaf.isHidden())
                this.add(access, leaf);
            else
                break;
        }
        this.add(access, node);
    } else if (node instanceof ICompositeNode) {
        for (INode child : ((ICompositeNode) node).getChildren()) process(child, access);
    }
    if (creator) {
        NodeEObjectRegion popped = stack.pop();
        popped.setTrailingHiddenRegion(lastHidden);
        EObject semanticElement = popped.getSemanticElement();
        if (semanticElement == null)
            throw new IllegalStateException();
        if (!stack.isEmpty() && semanticElement.eContainer() != stack.peek().getSemanticElement())
            throw new IllegalStateException();
        EObject grammarElement = popped.getGrammarElement();
        if (grammarElement == null) {
            throw new IllegalStateException();
        }
        NodeEObjectRegion old = eObjToTokens.put(semanticElement, popped);
        if (old != null)
            throw new IllegalStateException();
    }
}
Also used : Action(org.eclipse.xtext.Action) INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 57 with Action

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

the class TerminalsSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage)

Example 58 with Action

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

the class XtextValidationTest method testCheckActionInUnorderedGroup_01.

@Test
public void testCheckActionInUnorderedGroup_01() throws Exception {
    XtextValidator validator = get(XtextValidator.class);
    UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup();
    Action action = XtextFactory.eINSTANCE.createAction();
    unorderedGroup.getElements().add(action);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(action, true, false);
    configureValidator(validator, messageAcceptor, action);
    validator.checkActionInUnorderedGroup(action);
    messageAcceptor.validate();
}
Also used : Action(org.eclipse.xtext.Action) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) Test(org.junit.Test)

Example 59 with Action

use of org.eclipse.xtext.Action 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 60 with Action

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

Action (org.eclipse.xtext.Action)161 ParserRule (org.eclipse.xtext.ParserRule)145 Parameter (org.eclipse.xtext.Parameter)128 EPackage (org.eclipse.emf.ecore.EPackage)124 EObject (org.eclipse.emf.ecore.EObject)17 RuleCall (org.eclipse.xtext.RuleCall)17 Assignment (org.eclipse.xtext.Assignment)13 AbstractElement (org.eclipse.xtext.AbstractElement)10 EClass (org.eclipse.emf.ecore.EClass)8 INode (org.eclipse.xtext.nodemodel.INode)8 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)7 AbstractRule (org.eclipse.xtext.AbstractRule)6 Alternatives (org.eclipse.xtext.Alternatives)6 Group (org.eclipse.xtext.Group)6 Keyword (org.eclipse.xtext.Keyword)6 TerminalRule (org.eclipse.xtext.TerminalRule)6 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)6 TypeRef (org.eclipse.xtext.TypeRef)5 CrossReference (org.eclipse.xtext.CrossReference)4 ParserRuleParameters (org.eclipse.xtext.parser.parameters.parametersTestLanguage.ParserRuleParameters)4