Search in sources :

Example 16 with TypeReference

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

the class IdeaPluginGenerator method compilePsiParser.

public JavaFileAccess compilePsiParser(final Grammar grammar) {
    TypeReference _psiParser = this._ideaPluginClassNames.getPsiParser(grammar);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _simpleName = IdeaPluginGenerator.this._ideaPluginClassNames.getPsiParser(grammar).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.idea.parser.AbstractXtextPsiParser");
            _builder.append(_typeRef);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            {
                boolean _isEmpty = IdeaPluginGenerator.this._grammarAccessExtensions.initialHiddenTokens(grammar).isEmpty();
                boolean _not = (!_isEmpty);
                if (_not) {
                    _builder.append("\t");
                    _builder.append("private static final ");
                    _builder.append(Set.class, "\t");
                    _builder.append("<");
                    _builder.append(String.class, "\t");
                    _builder.append("> INITIAL_HIDDEN_TOKENS = new ");
                    _builder.append(HashSet.class, "\t");
                    _builder.append("<");
                    _builder.append(String.class, "\t");
                    _builder.append(">(");
                    _builder.append(Arrays.class, "\t");
                    _builder.append(".asList(");
                    {
                        List<String> _initialHiddenTokens = IdeaPluginGenerator.this._grammarAccessExtensions.initialHiddenTokens(grammar);
                        boolean _hasElements = false;
                        for (final String hidden : _initialHiddenTokens) {
                            if (!_hasElements) {
                                _hasElements = true;
                            } else {
                                _builder.appendImmediate(", ", "\t");
                            }
                            _builder.append("\"");
                            _builder.append(hidden, "\t");
                            _builder.append("\"");
                        }
                    }
                    _builder.append("));");
                    _builder.newLineIfNotEmpty();
                } else {
                    _builder.append("\t");
                    _builder.append("private static final ");
                    _builder.append(Set.class, "\t");
                    _builder.append("<");
                    _builder.append(String.class, "\t");
                    _builder.append("> INITIAL_HIDDEN_TOKENS = ");
                    _builder.append(Collections.class, "\t");
                    _builder.append(".emptySet();");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@");
            _builder.append(Inject.class, "\t");
            _builder.append(" ");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("private ");
            TypeReference _grammarAccess = IdeaPluginGenerator.this._grammarAccessExtensions.getGrammarAccess(grammar);
            _builder.append(_grammarAccess, "\t");
            _builder.append(" grammarAccess;");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@");
            _builder.append(Inject.class, "\t");
            _builder.append(" ");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("private ");
            TypeReference _elementTypeProvider = IdeaPluginGenerator.this._ideaPluginClassNames.getElementTypeProvider(grammar);
            _builder.append(_elementTypeProvider, "\t");
            _builder.append(" elementTypeProvider;");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@");
            _builder.append(Override.class, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("protected ");
            TypeReference _typeRef_1 = TypeReference.typeRef("org.eclipse.xtext.idea.parser.AbstractPsiAntlrParser");
            _builder.append(_typeRef_1, "\t");
            _builder.append(" createParser(");
            TypeReference _typeRef_2 = TypeReference.typeRef("com.intellij.lang.PsiBuilder");
            _builder.append(_typeRef_2, "\t");
            _builder.append(" builder, ");
            TypeReference _typeRef_3 = TypeReference.typeRef("org.antlr.runtime.TokenStream");
            _builder.append(_typeRef_3, "\t");
            _builder.append(" tokenStream) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("return new ");
            TypeReference _psiInternalParser = IdeaPluginGenerator.this._ideaPluginClassNames.getPsiInternalParser(grammar);
            _builder.append(_psiInternalParser, "\t\t");
            _builder.append("(builder, tokenStream, elementTypeProvider, grammarAccess);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@");
            _builder.append(Override.class, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("protected ");
            _builder.append(Set.class, "\t");
            _builder.append("<");
            _builder.append(String.class, "\t");
            _builder.append("> getInitialHiddenTokens() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("return INITIAL_HIDDEN_TOKENS;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    return this.fileAccessFactory.createJavaFile(_psiParser, _client);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) Arrays(java.util.Arrays) Collections(java.util.Collections) HashSet(java.util.HashSet)

Example 17 with TypeReference

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

the class IdeaPluginGenerator method compileStandaloneSetup.

public JavaFileAccess compileStandaloneSetup(final Grammar grammar) {
    JavaFileAccess _xifexpression = null;
    boolean _isGenerateXtendStub = this.isGenerateXtendStub();
    if (_isGenerateXtendStub) {
        TypeReference _ideaStandaloneSetup = this._xtextGeneratorNaming.getIdeaStandaloneSetup(grammar);
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("class ");
                String _simpleName = IdeaPluginGenerator.this._xtextGeneratorNaming.getIdeaStandaloneSetup(grammar).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                TypeReference _runtimeGenSetup = IdeaPluginGenerator.this._xtextGeneratorNaming.getRuntimeGenSetup(grammar);
                _builder.append(_runtimeGenSetup);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("override createInjector() {");
                _builder.newLine();
                _builder.append("\t\t");
                _builder.append("val runtimeModule = new ");
                TypeReference _runtimeModule = IdeaPluginGenerator.this._xtextGeneratorNaming.getRuntimeModule(grammar);
                _builder.append(_runtimeModule, "\t\t");
                _builder.append("()");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append("val ideaModule = new ");
                TypeReference _ideaModule = IdeaPluginGenerator.this._xtextGeneratorNaming.getIdeaModule(grammar);
                _builder.append(_ideaModule, "\t\t");
                _builder.append("()");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append("val mergedModule = ");
                _builder.append(Modules2.class, "\t\t");
                _builder.append(".mixin(runtimeModule, ideaModule)");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append("return ");
                _builder.append(Guice.class, "\t\t");
                _builder.append(".createInjector(mergedModule)");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.append("}");
                _builder.newLine();
            }
        };
        _xifexpression = this.fileAccessFactory.createXtendFile(_ideaStandaloneSetup, _client);
    } else {
        TypeReference _ideaStandaloneSetup_1 = this._xtextGeneratorNaming.getIdeaStandaloneSetup(grammar);
        StringConcatenationClient _client_1 = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("public class ");
                String _simpleName = IdeaPluginGenerator.this._xtextGeneratorNaming.getIdeaStandaloneSetup(grammar).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                TypeReference _runtimeGenSetup = IdeaPluginGenerator.this._xtextGeneratorNaming.getRuntimeGenSetup(grammar);
                _builder.append(_runtimeGenSetup);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("@Override");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("public ");
                _builder.append(Injector.class, "\t");
                _builder.append(" createInjector() {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                TypeReference _runtimeModule = IdeaPluginGenerator.this._xtextGeneratorNaming.getRuntimeModule(grammar);
                _builder.append(_runtimeModule, "\t\t");
                _builder.append(" runtimeModule = new ");
                TypeReference _runtimeModule_1 = IdeaPluginGenerator.this._xtextGeneratorNaming.getRuntimeModule(grammar);
                _builder.append(_runtimeModule_1, "\t\t");
                _builder.append("();");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                TypeReference _ideaModule = IdeaPluginGenerator.this._xtextGeneratorNaming.getIdeaModule(grammar);
                _builder.append(_ideaModule, "\t\t");
                _builder.append(" ideaModule = new ");
                TypeReference _ideaModule_1 = IdeaPluginGenerator.this._xtextGeneratorNaming.getIdeaModule(grammar);
                _builder.append(_ideaModule_1, "\t\t");
                _builder.append("();");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append(com.google.inject.Module.class, "\t\t");
                _builder.append(" mergedModule = ");
                _builder.append(Modules2.class, "\t\t");
                _builder.append(".mixin(runtimeModule, ideaModule);");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append("return ");
                _builder.append(Guice.class, "\t\t");
                _builder.append(".createInjector(mergedModule);");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.append("}");
                _builder.newLine();
            }
        };
        _xifexpression = this.fileAccessFactory.createJavaFile(_ideaStandaloneSetup_1, _client_1);
    }
    return _xifexpression;
}
Also used : JavaFileAccess(org.eclipse.xtext.xtext.generator.model.JavaFileAccess) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 18 with TypeReference

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

the class PsiAntlrGrammarGenerator method compileParserImports.

@Override
protected String compileParserImports(final Grammar it, final AntlrOptions options) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.newLine();
    _builder.append("import ");
    String _name = this.getGrammarNaming().getInternalParserSuperClass(it).getName();
    _builder.append(_name);
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.append("import ");
    TypeReference _elementTypeProvider = this._ideaPluginClassNames.getElementTypeProvider(GrammarUtil.getGrammar(it));
    _builder.append(_elementTypeProvider);
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.append("import org.eclipse.xtext.idea.parser.TokenTypeProvider;");
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.parser.antlr.XtextTokenStream;");
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.parser.antlr.XtextTokenStream.HiddenTokens;");
    _builder.newLine();
    {
        if (((!IterableExtensions.isEmpty(Iterables.<UnorderedGroup>filter(Iterables.<EObject>concat(ListExtensions.<ParserRule, List<EObject>>map(GrammarUtil.allParserRules(it), ((Function1<ParserRule, List<EObject>>) (ParserRule it_1) -> {
            return EcoreUtil2.eAllContentsAsList(it_1);
        }))), UnorderedGroup.class))) && options.isBacktrack())) {
            _builder.append("import org.eclipse.xtext.parser.antlr.IUnorderedGroupHelper.UnorderedGroupState;");
            _builder.newLine();
        }
    }
    _builder.append("import ");
    String _name_1 = this._grammarAccessExtensions.getGrammarAccess(it).getName();
    _builder.append(_name_1);
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("import com.intellij.lang.PsiBuilder;");
    _builder.newLine();
    return _builder.toString();
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) List(java.util.List) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 19 with TypeReference

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

the class AbstractAntlrGrammarGenerator method compileParserOptions.

protected CharSequence compileParserOptions(final Grammar it, final AntlrOptions options) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.newLine();
    _builder.append("options {");
    _builder.newLine();
    {
        boolean _isCombinedGrammar = this.isCombinedGrammar();
        boolean _not = (!_isCombinedGrammar);
        if (_not) {
            _builder.append("\t");
            _builder.append("tokenVocab=");
            String _simpleName = this.getGrammarNaming().getLexerGrammar(it).getSimpleName();
            _builder.append(_simpleName, "\t");
            _builder.append(";");
            _builder.newLineIfNotEmpty();
        }
    }
    {
        TypeReference _internalParserSuperClass = this.getGrammarNaming().getInternalParserSuperClass(it);
        boolean _tripleNotEquals = (_internalParserSuperClass != null);
        if (_tripleNotEquals) {
            _builder.append("\t");
            _builder.append("superClass=");
            String _simpleName_1 = this.getGrammarNaming().getInternalParserSuperClass(it).getSimpleName();
            _builder.append(_simpleName_1, "\t");
            _builder.append(";");
            _builder.newLineIfNotEmpty();
        }
    }
    {
        if (((this.isParserBackTracking(it, options) || options.isMemoize()) || (options.getK() >= 0))) {
            {
                boolean _isParserBackTracking = this.isParserBackTracking(it, options);
                if (_isParserBackTracking) {
                    _builder.append("\t");
                    _builder.append("backtrack=true;");
                    _builder.newLine();
                }
            }
            {
                boolean _isMemoize = options.isMemoize();
                if (_isMemoize) {
                    _builder.append("\t");
                    _builder.append("memoize=true;");
                    _builder.newLine();
                }
            }
            {
                int _k = options.getK();
                boolean _greaterEqualsThan = (_k >= 0);
                if (_greaterEqualsThan) {
                    _builder.append("\t");
                    _builder.append("memoize=");
                    int _k_1 = options.getK();
                    _builder.append(_k_1, "\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    _builder.append("}");
    _builder.newLine();
    return _builder;
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 20 with TypeReference

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

the class AbstractAntlrGrammarGenerator method compileLexerImports.

protected CharSequence compileLexerImports(final Grammar it, final AntlrOptions options) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.newLine();
    _builder.append("// Hack: Use our own Lexer superclass by means of import. ");
    _builder.newLine();
    _builder.append("// Currently there is no other way to specify the superclass for the lexer.");
    _builder.newLine();
    _builder.append("import ");
    TypeReference _lexerSuperClass = this.getGrammarNaming().getLexerSuperClass(it);
    _builder.append(_lexerSuperClass);
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    return _builder;
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Aggregations

TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)154 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)119 GuiceModuleAccess (org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess)27 GeneratedJavaFileAccess (org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess)24 Grammar (org.eclipse.xtext.Grammar)23 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)21 ManifestAccess (org.eclipse.xtext.xtext.generator.model.ManifestAccess)17 List (java.util.List)14 Set (java.util.Set)12 Test (org.junit.Test)12 JavaFileAccess (org.eclipse.xtext.xtext.generator.model.JavaFileAccess)11 PluginXmlAccess (org.eclipse.xtext.xtext.generator.model.PluginXmlAccess)11 IClassAnnotation (org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation)10 AbstractRule (org.eclipse.xtext.AbstractRule)9 SuppressWarningsAnnotation (org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation)8 IBundleProjectConfig (org.eclipse.xtext.xtext.generator.model.project.IBundleProjectConfig)8 ContentAssistGrammarNaming (org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming)7 EObject (org.eclipse.emf.ecore.EObject)6 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)6 ArrayList (java.util.ArrayList)5