Search in sources :

Example 96 with AbstractElement

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

the class AssignmentImpl method basicSetTerminal.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetTerminal(AbstractElement newTerminal, NotificationChain msgs) {
    AbstractElement oldTerminal = terminal;
    terminal = newTerminal;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XtextPackage.ASSIGNMENT__TERMINAL, oldTerminal, newTerminal);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 97 with AbstractElement

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

the class KeywordBasedValueConverter method setRule.

/**
 * @throws IllegalArgumentException if the rule is not a datatype rule or does not fulfill
 *   the pattern <pre>RuleName: 'keyword' | 'other';</pre>
 */
@Override
public void setRule(AbstractRule rule) {
    this.rule = rule;
    if (!GrammarUtil.isDatatypeRule(rule))
        throw new IllegalArgumentException(rule.getName() + " is not a data type rule");
    if (!(rule.getAlternatives() instanceof Alternatives) && !(rule.getAlternatives() instanceof Keyword)) {
        throw new IllegalArgumentException(rule.getName() + " is not a simple keyword nor an alternative");
    }
    if (rule.getAlternatives() instanceof Keyword) {
        keywords = ImmutableSet.of(keywordToString((Keyword) rule.getAlternatives()));
    } else {
        Alternatives alternatives = (Alternatives) rule.getAlternatives();
        ImmutableSet.Builder<String> builder = ImmutableSet.builder();
        for (AbstractElement element : alternatives.getElements()) {
            if (!(element instanceof Keyword)) {
                throw new IllegalArgumentException(rule.getName() + "'s body does not contain an alternative of keywords");
            }
            builder.add(keywordToString((Keyword) element));
        }
        keywords = builder.build();
    }
}
Also used : Keyword(org.eclipse.xtext.Keyword) ImmutableSet(com.google.common.collect.ImmutableSet) AbstractElement(org.eclipse.xtext.AbstractElement) Alternatives(org.eclipse.xtext.Alternatives)

Example 98 with AbstractElement

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

the class TextRegionAccessToString method toString.

protected String toString(IEObjectRegion region) {
    EObject obj = region.getSemanticElement();
    StringBuilder builder = new StringBuilder(Strings.padEnd(toClassWithName(obj), textWidth, ' ') + " ");
    EObject element = region.getGrammarElement();
    if (element instanceof AbstractElement)
        builder.append(grammarToString.apply((AbstractElement) element));
    else if (element instanceof AbstractRule)
        builder.append(((AbstractRule) element).getName());
    else
        builder.append(": ERROR: No grammar element.");
    List<String> segments = Lists.newArrayList();
    EObject current = obj;
    while (current.eContainer() != null) {
        EObject container = current.eContainer();
        EStructuralFeature containingFeature = current.eContainingFeature();
        StringBuilder segment = new StringBuilder();
        segment.append(toClassWithName(container));
        segment.append("/");
        segment.append(containingFeature.getName());
        if (containingFeature.isMany()) {
            int index = ((List<?>) container.eGet(containingFeature)).indexOf(current);
            segment.append("[" + index + "]");
        }
        current = container;
        segments.add(segment.toString());
    }
    if (!segments.isEmpty()) {
        builder.append(" path:");
        builder.append(Joiner.on("=").join(segments));
    }
    return builder.toString();
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) EObject(org.eclipse.emf.ecore.EObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) List(java.util.List) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 99 with AbstractElement

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

the class GrammarAccessExtensions method getElementDescription.

private List<String> getElementDescription(final AbstractElement element) {
    final ArrayList<String> result = new ArrayList<String>();
    AbstractElement container = element;
    while ((container != null)) {
        {
            result.addAll(0, this.getSingleElementDescription(container));
            final EObject eContainer = container.eContainer();
            AbstractElement _xifexpression = null;
            if ((eContainer instanceof AbstractElement)) {
                _xifexpression = ((AbstractElement) eContainer);
            } else {
                _xifexpression = null;
            }
            container = _xifexpression;
        }
    }
    return result;
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList)

Example 100 with AbstractElement

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

the class GrammarAccessFragment2 method parserRuleClasses.

protected StringConcatenationClient parserRuleClasses(final ParserRule it) {
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _gaRuleAccessorClassName = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessorClassName(it);
            _builder.append(_gaRuleAccessorClassName);
            _builder.append(" extends AbstractParserRuleElementFinder {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("private final ");
            _builder.append(ParserRule.class, "\t");
            _builder.append(" rule = (");
            _builder.append(ParserRule.class, "\t");
            _builder.append(") ");
            _builder.append(GrammarUtil.class, "\t");
            _builder.append(".findRuleForName(getGrammar(), \"");
            String _qualifiedName = GrammarAccessFragment2.this.getQualifiedName(it);
            _builder.append(_qualifiedName, "\t");
            _builder.append("\");");
            _builder.newLineIfNotEmpty();
            {
                List<AbstractElement> _containedAbstractElements = GrammarUtil.containedAbstractElements(it);
                for (final AbstractElement e : _containedAbstractElements) {
                    _builder.append("\t");
                    _builder.append("private final ");
                    TypeReference _typeRef = TypeReference.typeRef(e.eClass(), GrammarAccessFragment2.this.getLanguage());
                    _builder.append(_typeRef, "\t");
                    _builder.append(" ");
                    String _gaElementAccessorLocalVarName = GrammarAccessFragment2.this.gaElementAccessorLocalVarName(e);
                    _builder.append(_gaElementAccessorLocalVarName, "\t");
                    _builder.append(" = ");
                    StringConcatenationClient _loadElementStatement = GrammarAccessFragment2.this.loadElementStatement(e);
                    _builder.append(_loadElementStatement, "\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            String _grammarFragmentToString = GrammarAccessFragment2.this._grammarAccessExtensions.grammarFragmentToString(it, "//");
            _builder.append(_grammarFragmentToString, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("@Override public ");
            _builder.append(ParserRule.class, "\t");
            _builder.append(" getRule() { return rule; }");
            _builder.newLineIfNotEmpty();
            {
                List<AbstractElement> _containedAbstractElements_1 = GrammarUtil.containedAbstractElements(it);
                for (final AbstractElement e_1 : _containedAbstractElements_1) {
                    _builder.append("\t");
                    _builder.newLine();
                    _builder.append("\t");
                    String _grammarFragmentToString_1 = GrammarAccessFragment2.this._grammarAccessExtensions.grammarFragmentToString(e_1, "//");
                    _builder.append(_grammarFragmentToString_1, "\t");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("public ");
                    TypeReference _typeRef_1 = TypeReference.typeRef(e_1.eClass(), GrammarAccessFragment2.this.getLanguage());
                    _builder.append(_typeRef_1, "\t");
                    _builder.append(" ");
                    String _gaElementAccessMethodName = GrammarAccessFragment2.this._grammarAccessExtensions.gaElementAccessMethodName(e_1);
                    _builder.append(_gaElementAccessMethodName, "\t");
                    _builder.append("() { return ");
                    String _gaElementAccessorLocalVarName_1 = GrammarAccessFragment2.this.gaElementAccessorLocalVarName(e_1);
                    _builder.append(_gaElementAccessorLocalVarName_1, "\t");
                    _builder.append("; }");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("}");
            _builder.newLine();
        }
    };
    return _client;
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) List(java.util.List) EList(org.eclipse.emf.common.util.EList) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Aggregations

AbstractElement (org.eclipse.xtext.AbstractElement)126 EObject (org.eclipse.emf.ecore.EObject)39 AbstractRule (org.eclipse.xtext.AbstractRule)34 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)31 RuleCall (org.eclipse.xtext.RuleCall)26 ParserRule (org.eclipse.xtext.ParserRule)18 Grammar (org.eclipse.xtext.Grammar)17 EList (org.eclipse.emf.common.util.EList)15 Assignment (org.eclipse.xtext.Assignment)15 Test (org.junit.Test)14 Group (org.eclipse.xtext.Group)13 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)13 List (java.util.List)12 ArrayList (java.util.ArrayList)11 XtextResource (org.eclipse.xtext.resource.XtextResource)11 Action (org.eclipse.xtext.Action)10 TerminalRule (org.eclipse.xtext.TerminalRule)10 Alternatives (org.eclipse.xtext.Alternatives)9 EClassifier (org.eclipse.emf.ecore.EClassifier)8 InternalEObject (org.eclipse.emf.ecore.InternalEObject)8