Search in sources :

Example 6 with JavaFileAccess

use of org.eclipse.xtext.xtext.generator.model.JavaFileAccess in project xtext-core by eclipse.

the class FileAccessFactory method createJavaFile.

public JavaFileAccess createJavaFile(final TypeReference typeRef, final StringConcatenationClient content) {
    final JavaFileAccess result = this.createJavaFile(typeRef);
    result.setContent(content);
    return result;
}
Also used : GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) JavaFileAccess(org.eclipse.xtext.xtext.generator.model.JavaFileAccess)

Example 7 with JavaFileAccess

use of org.eclipse.xtext.xtext.generator.model.JavaFileAccess in project xtext-core by eclipse.

the class SimpleProjectWizardFragment2 method generateWizardNewProjectCreationPage.

public void generateWizardNewProjectCreationPage() {
    final TypeReference mainPageClass = TypeReference.typeRef(this.getProjectWizardCreationPageClassName());
    final JavaFileAccess file = this.fileAccessFactory.createJavaFile(mainPageClass);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _simpleName = mainPageClass.getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _typeRef = TypeReference.typeRef("org.eclipse.ui.dialogs.WizardNewProjectCreationPage");
            _builder.append(_typeRef);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public ");
            String _simpleName_1 = mainPageClass.getSimpleName();
            _builder.append(_simpleName_1, "\t");
            _builder.append("(String pageName) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("super(pageName);");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    file.setContent(_client);
    file.writeTo(this.getProjectConfig().getEclipsePlugin().getSrc());
}
Also used : JavaFileAccess(org.eclipse.xtext.xtext.generator.model.JavaFileAccess) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 8 with JavaFileAccess

use of org.eclipse.xtext.xtext.generator.model.JavaFileAccess in project xtext-core by eclipse.

the class XtextAntlrGeneratorFragment2 method generateContentAssistTokenSource.

public JavaFileAccess generateContentAssistTokenSource() {
    JavaFileAccess _xblockexpression = null;
    {
        @Extension final ContentAssistGrammarNaming naming = this.contentAssistNaming;
        final JavaFileAccess file = this.fileFactory.createJavaFile(naming.getTokenSourceClass(this.getGrammar()));
        final Function1<TerminalRule, Boolean> _function = (TerminalRule it) -> {
            return Boolean.valueOf(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("BEGIN", "INDENT", "OPEN")).contains(it.getName().toUpperCase()));
        };
        final Iterable<TerminalRule> open = IterableExtensions.<TerminalRule>filter(GrammarUtil.allTerminalRules(this.getGrammar()), _function);
        final Function1<TerminalRule, Boolean> _function_1 = (TerminalRule it) -> {
            return Boolean.valueOf(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("END", "DEDENT", "CLOSE")).contains(it.getName().toUpperCase()));
        };
        final Iterable<TerminalRule> close = IterableExtensions.<TerminalRule>filter(GrammarUtil.allTerminalRules(this.getGrammar()), _function_1);
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("public class ");
                String _simpleName = naming.getTokenSourceClass(XtextAntlrGeneratorFragment2.this.getGrammar()).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                _builder.append(AbstractIndentationTokenSource.class);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                _builder.newLine();
                _builder.append("\t");
                _builder.append("public ");
                String _simpleName_1 = naming.getTokenSourceClass(XtextAntlrGeneratorFragment2.this.getGrammar()).getSimpleName();
                _builder.append(_simpleName_1, "\t");
                _builder.append("(");
                _builder.append(TokenSource.class, "\t");
                _builder.append(" delegate) {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append("super(delegate);");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@Override");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("protected boolean shouldSplitTokenImpl(");
                _builder.append(Token.class, "\t");
                _builder.append(" token) {");
                _builder.newLineIfNotEmpty();
                {
                    final Function1<TerminalRule, TerminalRule> _function = (TerminalRule it) -> {
                        return AntlrGrammarGenUtil.<TerminalRule>getOriginalElement(it);
                    };
                    final Function1<TerminalRule, Boolean> _function_1 = (TerminalRule it) -> {
                        String _upperCase = it.getName().toUpperCase();
                        return Boolean.valueOf(Objects.equal(_upperCase, "WS"));
                    };
                    boolean _exists = IterableExtensions.<TerminalRule>exists(ListExtensions.<TerminalRule, TerminalRule>map(GrammarUtil.allTerminalRules(XtextAntlrGeneratorFragment2.this.getGrammar()), _function), _function_1);
                    if (_exists) {
                        _builder.append("\t\t");
                        _builder.append("// TODO Review assumption");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("return token.getType() == ");
                        TypeReference _internalParserClass = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
                        _builder.append(_internalParserClass, "\t\t");
                        _builder.append(".RULE_WS;");
                        _builder.newLineIfNotEmpty();
                    } else {
                        _builder.append("\t\t");
                        _builder.append("// TODO Implement me");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("throw new UnsupportedOperationException(\"Implement me\");");
                        _builder.newLine();
                    }
                }
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@Override");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("protected int getBeginTokenType() {");
                _builder.newLine();
                {
                    int _size = IterableExtensions.size(open);
                    boolean _equals = (_size == 1);
                    if (_equals) {
                        _builder.append("\t\t");
                        _builder.append("// TODO Review assumption");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("return ");
                        TypeReference _internalParserClass_1 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
                        _builder.append(_internalParserClass_1, "\t\t");
                        _builder.append(".");
                        String _ruleName = XtextAntlrGeneratorFragment2.this.grammarUtil.ruleName(IterableExtensions.<TerminalRule>head(open));
                        _builder.append(_ruleName, "\t\t");
                        _builder.append(";");
                        _builder.newLineIfNotEmpty();
                    } else {
                        _builder.append("\t\t");
                        _builder.append("// TODO Implement me");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("throw new UnsupportedOperationException(\"Implement me\");");
                        _builder.newLine();
                    }
                }
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@Override");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("protected int getEndTokenType() {");
                _builder.newLine();
                {
                    int _size_1 = IterableExtensions.size(close);
                    boolean _equals_1 = (_size_1 == 1);
                    if (_equals_1) {
                        _builder.append("\t\t");
                        _builder.append("// TODO Review assumption");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("return ");
                        TypeReference _internalParserClass_2 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
                        _builder.append(_internalParserClass_2, "\t\t");
                        _builder.append(".");
                        String _ruleName_1 = XtextAntlrGeneratorFragment2.this.grammarUtil.ruleName(IterableExtensions.<TerminalRule>head(close));
                        _builder.append(_ruleName_1, "\t\t");
                        _builder.append(";");
                        _builder.newLineIfNotEmpty();
                    } else {
                        _builder.append("\t\t");
                        _builder.append("// TODO Implement me");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("throw new UnsupportedOperationException(\"Implement me\");");
                        _builder.newLine();
                    }
                }
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@Override");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("protected boolean shouldEmitPendingEndTokens() {");
                _builder.newLine();
                _builder.append("\t\t");
                _builder.append("return false;");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.append("}");
                _builder.newLine();
            }
        };
        file.setContent(_client);
        _xblockexpression = file;
    }
    return _xblockexpression;
}
Also used : TokenSource(org.antlr.runtime.TokenSource) AbstractIndentationTokenSource(org.eclipse.xtext.parser.antlr.AbstractIndentationTokenSource) AbstractIndentationTokenSource(org.eclipse.xtext.parser.antlr.AbstractIndentationTokenSource) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) ContentAssistGrammarNaming(org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Token(org.antlr.runtime.Token) JavaFileAccess(org.eclipse.xtext.xtext.generator.model.JavaFileAccess) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) TerminalRule(org.eclipse.xtext.TerminalRule)

Example 9 with JavaFileAccess

use of org.eclipse.xtext.xtext.generator.model.JavaFileAccess in project xtext-core by eclipse.

the class XtextAntlrGeneratorFragment2 method generateProductionTokenSource.

public JavaFileAccess generateProductionTokenSource() {
    JavaFileAccess _xblockexpression = null;
    {
        @Extension final GrammarNaming naming = this.productionNaming;
        final JavaFileAccess file = this.fileFactory.createJavaFile(naming.getTokenSourceClass(this.getGrammar()));
        final Function1<TerminalRule, Boolean> _function = (TerminalRule it) -> {
            return Boolean.valueOf(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("BEGIN", "INDENT", "OPEN")).contains(it.getName().toUpperCase()));
        };
        final Iterable<TerminalRule> open = IterableExtensions.<TerminalRule>filter(GrammarUtil.allTerminalRules(this.getGrammar()), _function);
        final Function1<TerminalRule, Boolean> _function_1 = (TerminalRule it) -> {
            return Boolean.valueOf(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("END", "DEDENT", "CLOSE")).contains(it.getName().toUpperCase()));
        };
        final Iterable<TerminalRule> close = IterableExtensions.<TerminalRule>filter(GrammarUtil.allTerminalRules(this.getGrammar()), _function_1);
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("public class ");
                String _simpleName = naming.getTokenSourceClass(XtextAntlrGeneratorFragment2.this.getGrammar()).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                _builder.append(AbstractIndentationTokenSource.class);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                _builder.newLine();
                _builder.append("\t");
                _builder.append("public ");
                String _simpleName_1 = naming.getTokenSourceClass(XtextAntlrGeneratorFragment2.this.getGrammar()).getSimpleName();
                _builder.append(_simpleName_1, "\t");
                _builder.append("(");
                _builder.append(TokenSource.class, "\t");
                _builder.append(" delegate) {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append("super(delegate);");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@Override");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("protected boolean shouldSplitTokenImpl(");
                _builder.append(Token.class, "\t");
                _builder.append(" token) {");
                _builder.newLineIfNotEmpty();
                {
                    final Function1<TerminalRule, TerminalRule> _function = (TerminalRule it) -> {
                        return AntlrGrammarGenUtil.<TerminalRule>getOriginalElement(it);
                    };
                    final Function1<TerminalRule, Boolean> _function_1 = (TerminalRule it) -> {
                        String _upperCase = it.getName().toUpperCase();
                        return Boolean.valueOf(Objects.equal(_upperCase, "WS"));
                    };
                    boolean _exists = IterableExtensions.<TerminalRule>exists(ListExtensions.<TerminalRule, TerminalRule>map(GrammarUtil.allTerminalRules(XtextAntlrGeneratorFragment2.this.getGrammar()), _function), _function_1);
                    if (_exists) {
                        _builder.append("\t\t");
                        _builder.append("// TODO Review assumption");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("return token.getType() == ");
                        TypeReference _internalParserClass = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
                        _builder.append(_internalParserClass, "\t\t");
                        _builder.append(".RULE_WS;");
                        _builder.newLineIfNotEmpty();
                    } else {
                        _builder.append("\t\t");
                        _builder.append("// TODO Implement me");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("throw new UnsupportedOperationException(\"Implement me\");");
                        _builder.newLine();
                    }
                }
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@Override");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("protected int getBeginTokenType() {");
                _builder.newLine();
                {
                    int _size = IterableExtensions.size(open);
                    boolean _equals = (_size == 1);
                    if (_equals) {
                        _builder.append("\t\t");
                        _builder.append("// TODO Review assumption");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("return ");
                        TypeReference _internalParserClass_1 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
                        _builder.append(_internalParserClass_1, "\t\t");
                        _builder.append(".");
                        String _ruleName = XtextAntlrGeneratorFragment2.this.grammarUtil.ruleName(IterableExtensions.<TerminalRule>head(open));
                        _builder.append(_ruleName, "\t\t");
                        _builder.append(";");
                        _builder.newLineIfNotEmpty();
                    } else {
                        _builder.append("\t\t");
                        _builder.append("// TODO Implement me");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("throw new UnsupportedOperationException(\"Implement me\");");
                        _builder.newLine();
                    }
                }
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@Override");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("protected int getEndTokenType() {");
                _builder.newLine();
                {
                    int _size_1 = IterableExtensions.size(close);
                    boolean _equals_1 = (_size_1 == 1);
                    if (_equals_1) {
                        _builder.append("\t\t");
                        _builder.append("// TODO Review assumption");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("return ");
                        TypeReference _internalParserClass_2 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
                        _builder.append(_internalParserClass_2, "\t\t");
                        _builder.append(".");
                        String _ruleName_1 = XtextAntlrGeneratorFragment2.this.grammarUtil.ruleName(IterableExtensions.<TerminalRule>head(close));
                        _builder.append(_ruleName_1, "\t\t");
                        _builder.append(";");
                        _builder.newLineIfNotEmpty();
                    } else {
                        _builder.append("\t\t");
                        _builder.append("// TODO Implement me");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("throw new UnsupportedOperationException(\"Implement me\");");
                        _builder.newLine();
                    }
                }
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.newLine();
                _builder.append("}");
                _builder.newLine();
            }
        };
        file.setContent(_client);
        _xblockexpression = file;
    }
    return _xblockexpression;
}
Also used : TokenSource(org.antlr.runtime.TokenSource) AbstractIndentationTokenSource(org.eclipse.xtext.parser.antlr.AbstractIndentationTokenSource) AbstractIndentationTokenSource(org.eclipse.xtext.parser.antlr.AbstractIndentationTokenSource) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Token(org.antlr.runtime.Token) ContentAssistGrammarNaming(org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming) GrammarNaming(org.eclipse.xtext.xtext.generator.parser.antlr.GrammarNaming) JavaFileAccess(org.eclipse.xtext.xtext.generator.model.JavaFileAccess) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) TerminalRule(org.eclipse.xtext.TerminalRule)

Example 10 with JavaFileAccess

use of org.eclipse.xtext.xtext.generator.model.JavaFileAccess in project xtext-core by eclipse.

the class IdeaPluginGenerator method compileElementTypeProvider.

public JavaFileAccess compileElementTypeProvider(final Grammar grammar) {
    final JavaFileAccess file = this.fileAccessFactory.createJavaFile(this._ideaPluginClassNames.getElementTypeProvider(grammar));
    file.importType(TypeReference.typeRef("org.eclipse.xtext.idea.lang.IElementTypeProvider"));
    file.importType(TypeReference.typeRef("org.eclipse.xtext.psi.stubs.XtextFileElementType"));
    file.importType(TypeReference.typeRef("org.eclipse.xtext.psi.stubs.XtextFileStub"));
    file.importType(TypeReference.typeRef("org.eclipse.xtext.psi.tree.IGrammarAwareElementType"));
    file.importType(TypeReference.typeRef("com.intellij.psi.tree.IFileElementType"));
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _simpleName = IdeaPluginGenerator.this._ideaPluginClassNames.getElementTypeProvider(grammar).getSimpleName();
            _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<");
            TypeReference _fileImpl = IdeaPluginGenerator.this._ideaPluginClassNames.getFileImpl(grammar);
            _builder.append(_fileImpl, "\t");
            _builder.append(">>(");
            TypeReference _ideaLanguage = IdeaPluginGenerator.this._ideaPluginClassNames.getIdeaLanguage(grammar);
            _builder.append(_ideaLanguage, "\t");
            _builder.append(".INSTANCE);");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("private static final ");
            _builder.append(Map.class, "\t");
            _builder.append("<");
            _builder.append(EObject.class, "\t");
            _builder.append(", IGrammarAwareElementType> GRAMMAR_ELEMENT_TYPE = new ");
            _builder.append(HashMap.class, "\t");
            _builder.append("<");
            _builder.append(EObject.class, "\t");
            _builder.append(", IGrammarAwareElementType>();");
            _builder.newLineIfNotEmpty();
            _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 ");
            TypeReference _grammarAccess = IdeaPluginGenerator.this._grammarAccessExtensions.getGrammarAccess(grammar);
            _builder.append(_grammarAccess, "\t");
            _builder.append(" GRAMMAR_ACCESS = ");
            TypeReference _ideaLanguage_1 = IdeaPluginGenerator.this._ideaPluginClassNames.getIdeaLanguage(grammar);
            _builder.append(_ideaLanguage_1, "\t");
            _builder.append(".INSTANCE.getInstance(");
            TypeReference _grammarAccess_1 = IdeaPluginGenerator.this._grammarAccessExtensions.getGrammarAccess(grammar);
            _builder.append(_grammarAccess_1, "\t");
            _builder.append(".class);");
            _builder.newLineIfNotEmpty();
            {
                Iterable<AbstractRule> _allNonTerminalRules = IdeaPluginGenerator.this._ideaPluginExtension.getAllNonTerminalRules(grammar);
                for (final AbstractRule rule : _allNonTerminalRules) {
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("private static class ");
                    String _grammarElementIdentifier = IdeaPluginGenerator.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 = IdeaPluginGenerator.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 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(rule);
                    _builder.append(_grammarElementIdentifier_2, "\t\t\t");
                    _builder.append("_ELEMENT_TYPE\", ");
                    TypeReference _ideaLanguage_2 = IdeaPluginGenerator.this._ideaPluginClassNames.getIdeaLanguage(grammar);
                    _builder.append(_ideaLanguage_2, "\t\t\t");
                    _builder.append(".INSTANCE, GRAMMAR_ACCESS.");
                    String _gaRuleAccessor = IdeaPluginGenerator.this._grammarAccessExtensions.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 = IdeaPluginGenerator.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 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(element);
                            _builder.append(_grammarElementIdentifier_4, "\t\t\t");
                            _builder.append("_ELEMENT_TYPE\", ");
                            TypeReference _ideaLanguage_3 = IdeaPluginGenerator.this._ideaPluginClassNames.getIdeaLanguage(grammar);
                            _builder.append(_ideaLanguage_3, "\t\t\t");
                            _builder.append(".INSTANCE, GRAMMAR_ACCESS.");
                            String _gaElementsAccessor = IdeaPluginGenerator.this._grammarAccessExtensions.gaElementsAccessor(rule);
                            _builder.append(_gaElementsAccessor, "\t\t\t");
                            _builder.append(".");
                            String _gaElementAccessor = IdeaPluginGenerator.this._grammarAccessExtensions.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 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(rule);
                    _builder.append(_grammarElementIdentifier_5, "\t");
                    _builder.append("_ELEMENT_TYPE = associate(");
                    String _grammarElementIdentifier_6 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(rule);
                    _builder.append(_grammarElementIdentifier_6, "\t");
                    _builder.append("Factory.create");
                    String _grammarElementIdentifier_7 = IdeaPluginGenerator.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 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(element_1);
                            _builder.append(_grammarElementIdentifier_8, "\t");
                            _builder.append("_ELEMENT_TYPE = associate(");
                            String _grammarElementIdentifier_9 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(rule);
                            _builder.append(_grammarElementIdentifier_9, "\t");
                            _builder.append("Factory.create");
                            String _grammarElementIdentifier_10 = IdeaPluginGenerator.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(");
            _builder.append(EObject.class, "\t");
            _builder.append(" grammarElement) {");
            _builder.newLineIfNotEmpty();
            _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 = IdeaPluginGenerator.this._ideaPluginExtension.getAllNonTerminalRules(grammar);
                for (final AbstractRule rule_1 : _allNonTerminalRules_1) {
                    _builder.append("\t");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("public IGrammarAwareElementType get");
                    String _grammarElementIdentifier_11 = IdeaPluginGenerator.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 = IdeaPluginGenerator.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.append("\t");
                            _builder.newLine();
                            _builder.append("\t");
                            _builder.append("public IGrammarAwareElementType get");
                            String _grammarElementIdentifier_13 = IdeaPluginGenerator.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 = IdeaPluginGenerator.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();
        }
    };
    file.setContent(_client);
    return file;
}
Also used : JavaFileAccess(org.eclipse.xtext.xtext.generator.model.JavaFileAccess) AbstractElement(org.eclipse.xtext.AbstractElement) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) AbstractRule(org.eclipse.xtext.AbstractRule)

Aggregations

JavaFileAccess (org.eclipse.xtext.xtext.generator.model.JavaFileAccess)13 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)12 TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)11 GeneratedJavaFileAccess (org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess)5 Token (org.antlr.runtime.Token)2 TokenSource (org.antlr.runtime.TokenSource)2 TerminalRule (org.eclipse.xtext.TerminalRule)2 AbstractIndentationTokenSource (org.eclipse.xtext.parser.antlr.AbstractIndentationTokenSource)2 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)2 ContentAssistGrammarNaming (org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming)2 AbstractElement (org.eclipse.xtext.AbstractElement)1 AbstractRule (org.eclipse.xtext.AbstractRule)1 Grammar (org.eclipse.xtext.Grammar)1 GuiceModuleAccess (org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess)1 TextFileAccess (org.eclipse.xtext.xtext.generator.model.TextFileAccess)1 GrammarNaming (org.eclipse.xtext.xtext.generator.parser.antlr.GrammarNaming)1