Search in sources :

Example 1 with AbstractElement

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

the class IdeaPluginGenerator method compileElementTypeProvider.

public CharSequence compileElementTypeProvider(final Grammar grammar) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package ");
    String _packageName = this._ideaPluginClassNames.toPackageName(this._ideaPluginClassNames.getElementTypeProviderName(grammar));
    _builder.append(_packageName);
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("import java.util.HashMap;");
    _builder.newLine();
    _builder.append("import java.util.Map;");
    _builder.newLine();
    _builder.newLine();
    _builder.append("import org.eclipse.emf.ecore.EObject;");
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.idea.lang.IElementTypeProvider;");
    _builder.newLine();
    _builder.append("import ");
    String _fileImplName = this._ideaPluginClassNames.getFileImplName(grammar);
    _builder.append(_fileImplName);
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.append("import ");
    String _grammarAccessName = this._ideaPluginClassNames.getGrammarAccessName(grammar);
    _builder.append(_grammarAccessName);
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.append("import org.eclipse.xtext.psi.stubs.XtextFileElementType;");
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.psi.stubs.XtextFileStub;");
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.psi.tree.IGrammarAwareElementType;");
    _builder.newLine();
    _builder.newLine();
    _builder.append("import com.intellij.psi.tree.IFileElementType;");
    _builder.newLine();
    _builder.newLine();
    _builder.append("public class ");
    String _simpleName = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getElementTypeProviderName(grammar));
    _builder.append(_simpleName);
    _builder.append(" implements IElementTypeProvider {");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public static final IFileElementType FILE_TYPE = new XtextFileElementType<XtextFileStub<");
    String _simpleName_1 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getFileImplName(grammar));
    _builder.append(_simpleName_1, "\t");
    _builder.append(">>(");
    String _simpleName_2 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getLanguageName(grammar));
    _builder.append(_simpleName_2, "\t");
    _builder.append(".INSTANCE);");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private static final Map<EObject, IGrammarAwareElementType> GRAMMAR_ELEMENT_TYPE = new HashMap<EObject, IGrammarAwareElementType>();");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private static IGrammarAwareElementType associate(IGrammarAwareElementType grammarAwareElementType) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("GRAMMAR_ELEMENT_TYPE.put(grammarAwareElementType.getGrammarElement(), grammarAwareElementType);");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return grammarAwareElementType;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private static final ");
    String _simpleName_3 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getGrammarAccessName(grammar));
    _builder.append(_simpleName_3, "\t");
    _builder.append(" GRAMMAR_ACCESS = ");
    String _simpleName_4 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getLanguageName(grammar));
    _builder.append(_simpleName_4, "\t");
    _builder.append(".INSTANCE.getInstance(");
    String _simpleName_5 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getGrammarAccessName(grammar));
    _builder.append(_simpleName_5, "\t");
    _builder.append(".class);");
    _builder.newLineIfNotEmpty();
    {
        Iterable<AbstractRule> _allNonTerminalRules = this._ideaPluginExtension.getAllNonTerminalRules(grammar);
        for (final AbstractRule rule : _allNonTerminalRules) {
            _builder.newLine();
            _builder.append("\t");
            _builder.append("private static class ");
            String _grammarElementIdentifier = this._grammarAccessExtensions.grammarElementIdentifier(rule);
            _builder.append(_grammarElementIdentifier, "\t");
            _builder.append("Factory {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t");
            _builder.append("public static IGrammarAwareElementType create");
            String _grammarElementIdentifier_1 = this._grammarAccessExtensions.grammarElementIdentifier(rule);
            _builder.append(_grammarElementIdentifier_1, "\t\t");
            _builder.append("ElementType() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t\t");
            _builder.append("return new IGrammarAwareElementType(\"");
            String _grammarElementIdentifier_2 = this._grammarAccessExtensions.grammarElementIdentifier(rule);
            _builder.append(_grammarElementIdentifier_2, "\t\t\t");
            _builder.append("_ELEMENT_TYPE\", ");
            String _simpleName_6 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getLanguageName(grammar));
            _builder.append(_simpleName_6, "\t\t\t");
            _builder.append(".INSTANCE, GRAMMAR_ACCESS.");
            String _gaRuleAccessor = this._grammarAccess.gaRuleAccessor(rule);
            _builder.append(_gaRuleAccessor, "\t\t\t");
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            {
                Iterable<AbstractElement> _iterable = IteratorExtensions.<AbstractElement>toIterable(Iterators.<AbstractElement>filter(rule.eAllContents(), AbstractElement.class));
                for (final AbstractElement element : _iterable) {
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("public static IGrammarAwareElementType create");
                    String _grammarElementIdentifier_3 = this._grammarAccessExtensions.grammarElementIdentifier(element);
                    _builder.append(_grammarElementIdentifier_3, "\t\t");
                    _builder.append("ElementType() {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("return new IGrammarAwareElementType(\"");
                    String _grammarElementIdentifier_4 = this._grammarAccessExtensions.grammarElementIdentifier(element);
                    _builder.append(_grammarElementIdentifier_4, "\t\t\t");
                    _builder.append("_ELEMENT_TYPE\", ");
                    String _simpleName_7 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getLanguageName(grammar));
                    _builder.append(_simpleName_7, "\t\t\t");
                    _builder.append(".INSTANCE, GRAMMAR_ACCESS.");
                    String _gaElementsAccessor = this._grammarAccess.gaElementsAccessor(rule);
                    _builder.append(_gaElementsAccessor, "\t\t\t");
                    _builder.append(".");
                    String _gaElementAccessor = this._grammarAccess.gaElementAccessor(element);
                    _builder.append(_gaElementAccessor, "\t\t\t");
                    _builder.append(");");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("}");
                    _builder.newLine();
                }
            }
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public static final IGrammarAwareElementType ");
            String _grammarElementIdentifier_5 = this._grammarAccessExtensions.grammarElementIdentifier(rule);
            _builder.append(_grammarElementIdentifier_5, "\t");
            _builder.append("_ELEMENT_TYPE = associate(");
            String _grammarElementIdentifier_6 = this._grammarAccessExtensions.grammarElementIdentifier(rule);
            _builder.append(_grammarElementIdentifier_6, "\t");
            _builder.append("Factory.create");
            String _grammarElementIdentifier_7 = this._grammarAccessExtensions.grammarElementIdentifier(rule);
            _builder.append(_grammarElementIdentifier_7, "\t");
            _builder.append("ElementType());");
            _builder.newLineIfNotEmpty();
            {
                Iterable<AbstractElement> _iterable_1 = IteratorExtensions.<AbstractElement>toIterable(Iterators.<AbstractElement>filter(rule.eAllContents(), AbstractElement.class));
                for (final AbstractElement element_1 : _iterable_1) {
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("public static final IGrammarAwareElementType ");
                    String _grammarElementIdentifier_8 = this._grammarAccessExtensions.grammarElementIdentifier(element_1);
                    _builder.append(_grammarElementIdentifier_8, "\t");
                    _builder.append("_ELEMENT_TYPE = associate(");
                    String _grammarElementIdentifier_9 = this._grammarAccessExtensions.grammarElementIdentifier(rule);
                    _builder.append(_grammarElementIdentifier_9, "\t");
                    _builder.append("Factory.create");
                    String _grammarElementIdentifier_10 = this._grammarAccessExtensions.grammarElementIdentifier(element_1);
                    _builder.append(_grammarElementIdentifier_10, "\t");
                    _builder.append("ElementType());");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public IFileElementType getFileType() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return FILE_TYPE;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public IGrammarAwareElementType findElementType(EObject grammarElement) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return GRAMMAR_ELEMENT_TYPE.get(grammarElement);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    {
        Iterable<AbstractRule> _allNonTerminalRules_1 = this._ideaPluginExtension.getAllNonTerminalRules(grammar);
        for (final AbstractRule rule_1 : _allNonTerminalRules_1) {
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public IGrammarAwareElementType get");
            String _grammarElementIdentifier_11 = this._grammarAccessExtensions.grammarElementIdentifier(rule_1);
            _builder.append(_grammarElementIdentifier_11, "\t");
            _builder.append("ElementType() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("\t");
            _builder.append("return ");
            String _grammarElementIdentifier_12 = this._grammarAccessExtensions.grammarElementIdentifier(rule_1);
            _builder.append(_grammarElementIdentifier_12, "\t\t");
            _builder.append("_ELEMENT_TYPE;");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            {
                Iterable<AbstractElement> _iterable_2 = IteratorExtensions.<AbstractElement>toIterable(Iterators.<AbstractElement>filter(rule_1.eAllContents(), AbstractElement.class));
                for (final AbstractElement element_2 : _iterable_2) {
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("public IGrammarAwareElementType get");
                    String _grammarElementIdentifier_13 = this._grammarAccessExtensions.grammarElementIdentifier(element_2);
                    _builder.append(_grammarElementIdentifier_13, "\t");
                    _builder.append("ElementType() {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("return ");
                    String _grammarElementIdentifier_14 = this._grammarAccessExtensions.grammarElementIdentifier(element_2);
                    _builder.append(_grammarElementIdentifier_14, "\t\t");
                    _builder.append("_ELEMENT_TYPE;");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("}");
                    _builder.newLine();
                }
            }
        }
    }
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 2 with AbstractElement

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

the class DefaultAntlrGrammarGenerator method _ebnf2.

protected String _ebnf2(final Alternatives it, final AntlrOptions options, final boolean supportActions) {
    StringConcatenation _builder = new StringConcatenation();
    {
        EList<AbstractElement> _elements = it.getElements();
        boolean _hasElements = false;
        for (final AbstractElement element : _elements) {
            if (!_hasElements) {
                _hasElements = true;
            } else {
                _builder.appendImmediate("\n    |", "");
            }
            String _ebnf = this.ebnf(element, options, supportActions);
            _builder.append(_ebnf);
        }
    }
    _builder.newLineIfNotEmpty();
    return _builder.toString();
}
Also used : EList(org.eclipse.emf.common.util.EList) AbstractElement(org.eclipse.xtext.AbstractElement) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 3 with AbstractElement

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

the class DefaultAntlrGrammarGenerator method _dataTypeEbnf2.

protected String _dataTypeEbnf2(final Alternatives it, final boolean supportActions) {
    StringConcatenation _builder = new StringConcatenation();
    {
        EList<AbstractElement> _elements = it.getElements();
        boolean _hasElements = false;
        for (final AbstractElement e : _elements) {
            if (!_hasElements) {
                _hasElements = true;
            } else {
                _builder.appendImmediate("\n    |", "");
            }
            String _dataTypeEbnf = this.dataTypeEbnf(e, supportActions);
            _builder.append(_dataTypeEbnf);
        }
    }
    _builder.newLineIfNotEmpty();
    return _builder.toString();
}
Also used : EList(org.eclipse.emf.common.util.EList) AbstractElement(org.eclipse.xtext.AbstractElement) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 4 with AbstractElement

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

the class DefaultAntlrGrammarGenerator method dataTypeEbnfPredicate.

protected String dataTypeEbnfPredicate(final AbstractElement it) {
    StringConcatenation _builder = new StringConcatenation();
    {
        if ((this._grammarAccessExtensions.predicated(it) || it.isFirstSetPredicated())) {
            _builder.append("(");
            {
                boolean _predicated = this._grammarAccessExtensions.predicated(it);
                if (_predicated) {
                    String _dataTypeEbnf2 = this.dataTypeEbnf2(this._grammarAccessExtensions.predicatedElement(it), false);
                    _builder.append(_dataTypeEbnf2);
                } else {
                    {
                        List<AbstractElement> _firstSet = AntlrGrammarGenUtil.getFirstSet(it);
                        boolean _hasElements = false;
                        for (final AbstractElement e : _firstSet) {
                            if (!_hasElements) {
                                _hasElements = true;
                            } else {
                                _builder.appendImmediate(" | ", "");
                            }
                            String _dataTypeEbnf2_1 = this.dataTypeEbnf2(e, false);
                            _builder.append(_dataTypeEbnf2_1);
                        }
                    }
                }
            }
            _builder.append(")=>");
        }
    }
    _builder.newLineIfNotEmpty();
    return _builder.toString();
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EList(org.eclipse.emf.common.util.EList) List(java.util.List)

Example 5 with AbstractElement

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

the class DefaultAntlrGrammarGenerator method _dataTypeEbnf2.

protected String _dataTypeEbnf2(final UnorderedGroup it, final boolean supportActions) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("(");
    {
        EList<AbstractElement> _elements = it.getElements();
        boolean _hasElements = false;
        for (final AbstractElement e : _elements) {
            if (!_hasElements) {
                _hasElements = true;
            } else {
                _builder.appendImmediate("\n    |", "");
            }
            String _dataTypeEbnf2 = this.dataTypeEbnf2(e, supportActions);
            _builder.append(_dataTypeEbnf2);
        }
    }
    _builder.append(")*");
    _builder.newLineIfNotEmpty();
    return _builder.toString();
}
Also used : EList(org.eclipse.emf.common.util.EList) AbstractElement(org.eclipse.xtext.AbstractElement) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Aggregations

AbstractElement (org.eclipse.xtext.AbstractElement)150 EObject (org.eclipse.emf.ecore.EObject)33 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)31 AbstractRule (org.eclipse.xtext.AbstractRule)31 RuleCall (org.eclipse.xtext.RuleCall)30 EList (org.eclipse.emf.common.util.EList)25 ParserRule (org.eclipse.xtext.ParserRule)21 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)18 List (java.util.List)17 Assignment (org.eclipse.xtext.Assignment)16 Group (org.eclipse.xtext.Group)16 ArrayList (java.util.ArrayList)14 Action (org.eclipse.xtext.Action)11 Alternatives (org.eclipse.xtext.Alternatives)11 CrossReference (org.eclipse.xtext.CrossReference)10 Keyword (org.eclipse.xtext.Keyword)10 Collection (java.util.Collection)9 EClass (org.eclipse.emf.ecore.EClass)9 Grammar (org.eclipse.xtext.Grammar)9 TerminalRule (org.eclipse.xtext.TerminalRule)9