Search in sources :

Example 6 with TypeReference

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

the class IdeaPluginGenerator method compilePomDeclarationSearcher.

public JavaFileAccess compilePomDeclarationSearcher(final Grammar it) {
    TypeReference _pomDeclarationSearcher = this._ideaPluginClassNames.getPomDeclarationSearcher(it);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _simpleName = IdeaPluginGenerator.this._ideaPluginClassNames.getPomDeclarationSearcher(it).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.idea.pom.AbstractXtextPomDeclarationSearcher");
            _builder.append(_typeRef);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public ");
            String _simpleName_1 = IdeaPluginGenerator.this._ideaPluginClassNames.getPomDeclarationSearcher(it).getSimpleName();
            _builder.append(_simpleName_1, "\t");
            _builder.append("() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("super(");
            TypeReference _ideaLanguage = IdeaPluginGenerator.this._ideaPluginClassNames.getIdeaLanguage(IdeaPluginGenerator.this.getGrammar());
            _builder.append(_ideaLanguage, "\t\t");
            _builder.append(".INSTANCE);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    return this.fileAccessFactory.createJavaFile(_pomDeclarationSearcher, _client);
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 7 with TypeReference

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

the class IdeaPluginGenerator method compileFileTypeFactory.

public JavaFileAccess compileFileTypeFactory(final Grammar grammar) {
    TypeReference _fileTypeFactory = this._ideaPluginClassNames.getFileTypeFactory(grammar);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _simpleName = IdeaPluginGenerator.this._ideaPluginClassNames.getFileTypeFactory(grammar).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _typeRef = TypeReference.typeRef("com.intellij.openapi.fileTypes.FileTypeFactory");
            _builder.append(_typeRef);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public void createFileTypes(@");
            TypeReference _typeRef_1 = TypeReference.typeRef("org.jetbrains.annotations.NotNull");
            _builder.append(_typeRef_1, "\t");
            _builder.append(" ");
            TypeReference _typeRef_2 = TypeReference.typeRef("com.intellij.openapi.fileTypes.FileTypeConsumer");
            _builder.append(_typeRef_2, "\t");
            _builder.append(" consumer) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("consumer.consume(");
            TypeReference _fileType = IdeaPluginGenerator.this._ideaPluginClassNames.getFileType(grammar);
            _builder.append(_fileType, "\t\t");
            _builder.append(".INSTANCE, ");
            TypeReference _abstractFileType = IdeaPluginGenerator.this._ideaPluginClassNames.getAbstractFileType(grammar);
            _builder.append(_abstractFileType, "\t\t");
            _builder.append(".DEFAULT_EXTENSION);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    return this.fileAccessFactory.createJavaFile(_fileTypeFactory, _client);
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 8 with TypeReference

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

the class IdeaPluginGenerator method compileExtension.

public CharSequence compileExtension(final Grammar grammar, final String extensionPointId, final TypeReference implementationClass) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("<");
    _builder.append(extensionPointId);
    _builder.append(" ");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("language=\"");
    String _languageID = this._ideaPluginExtension.getLanguageID(grammar);
    _builder.append(_languageID, "\t");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("factoryClass=\"");
    TypeReference _extensionFactory = this._ideaPluginClassNames.getExtensionFactory(grammar);
    _builder.append(_extensionFactory, "\t");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("implementationClass=\"");
    _builder.append(implementationClass, "\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 9 with TypeReference

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

the class IdeaPluginGenerator method generate.

@Override
public void generate() {
    boolean _isEnabled = this.getProjectConfig().getIdeaPlugin().isEnabled();
    boolean _not = (!_isEnabled);
    if (_not) {
        return;
    }
    final String fileExtension = IterableExtensions.<String>head(this.getLanguage().getFileExtensions());
    final Grammar grammar = this.getLanguage().getGrammar();
    final GuiceModuleAccess.BindingFactory bindFactory = new GuiceModuleAccess.BindingFactory();
    bindFactory.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.parser.antlr.IAntlrTokenFileProvider"), this._ideaPluginClassNames.getAntlrTokenFileProvider(grammar));
    bindFactory.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.parser.antlr.Lexer"), this._ideaPluginClassNames.getPsiInternalLexer(grammar));
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("binder.bind(");
            _builder.append(Lexer.class);
            _builder.append(".class)");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(".annotatedWith(");
            _builder.append(Names.class, "\t");
            _builder.append(".named(");
            _builder.append(LexerBindings.class, "\t");
            _builder.append(".RUNTIME))");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(".to(");
            TypeReference _psiInternalLexer = IdeaPluginGenerator.this._ideaPluginClassNames.getPsiInternalLexer(grammar);
            _builder.append(_psiInternalLexer, "\t");
            _builder.append(".class);");
            _builder.newLineIfNotEmpty();
        }
    };
    bindFactory.addConfiguredBinding("RuntimeLexer", _client);
    bindFactory.addTypeToType(TypeReference.typeRef("com.intellij.lang.PsiParser"), this._ideaPluginClassNames.getPsiParser(grammar));
    bindFactory.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.idea.parser.TokenTypeProvider"), this._ideaPluginClassNames.getTokenTypeProvider(grammar));
    bindFactory.addTypeToType(TypeReference.typeRef("com.intellij.lang.ParserDefinition"), this._ideaPluginClassNames.getParserDefinition(grammar));
    bindFactory.addTypeToTypeSingleton(TypeReference.typeRef("org.eclipse.xtext.idea.lang.IElementTypeProvider"), this._ideaPluginClassNames.getElementTypeProvider(grammar));
    bindFactory.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.idea.facet.AbstractFacetConfiguration"), this._ideaPluginClassNames.getFacetConfiguration(grammar));
    TypeReference _typeRef = TypeReference.typeRef("com.intellij.facet.FacetTypeId");
    StringConcatenationClient _client_1 = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            TypeReference _facetType = IdeaPluginGenerator.this._ideaPluginClassNames.getFacetType(grammar);
            _builder.append(_facetType);
            _builder.append(".TYPEID");
        }
    };
    bindFactory.addTypeToInstance(_typeRef, _client_1);
    bindFactory.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.antlr.IContentAssistParser"), this.caNaming.getParserClass(grammar));
    StringConcatenationClient _client_2 = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("binder.bind(");
            TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.antlr.internal.Lexer");
            _builder.append(_typeRef);
            _builder.append(".class).annotatedWith(");
            _builder.append(Names.class);
            _builder.append(".named(");
            TypeReference _typeRef_1 = TypeReference.typeRef("org.eclipse.xtext.ide.LexerIdeBindings");
            _builder.append(_typeRef_1);
            _builder.append(".CONTENT_ASSIST)).to(");
            TypeReference _lexerClass = IdeaPluginGenerator.this.caNaming.getLexerClass(grammar);
            _builder.append(_lexerClass);
            _builder.append(".class);");
        }
    };
    bindFactory.addConfiguredBinding("ContentAssistLexer", _client_2);
    boolean _inheritsXbase = this._xbaseUsageDetector.inheritsXbase(grammar);
    if (_inheritsXbase) {
        bindFactory.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.common.types.xtext.AbstractTypeScopeProvider"), TypeReference.typeRef("org.eclipse.xtext.idea.common.types.StubBasedTypeScopeProvider"));
        TypeReference _typeReference = new TypeReference("org.eclipse.xtext.xbase.typesystem.internal", "IFeatureScopeTracker.Provider");
        bindFactory.addTypeToType(_typeReference, TypeReference.typeRef("org.eclipse.xtext.xbase.typesystem.internal.OptimizingFeatureScopeTrackerProvider"));
        StringConcatenationClient _client_3 = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("binder.bind(");
                TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.psi.IPsiModelAssociations");
                _builder.append(_typeRef);
                _builder.append(".class)");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append(".annotatedWith(");
                _builder.append(LanguageSpecific.class, "\t");
                _builder.append(".class)");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append(".to(");
                TypeReference _typeRef_1 = TypeReference.typeRef("org.eclipse.xtext.idea.common.types.DerivedMemberAwarePsiModelAssociations");
                _builder.append(_typeRef_1, "\t");
                _builder.append(".class);");
                _builder.newLineIfNotEmpty();
            }
        };
        bindFactory.addConfiguredBinding("LanguageSpecificPsiModelAssociations", _client_3);
        bindFactory.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.idea.highlighting.IHighlightingConfiguration"), TypeReference.typeRef("org.eclipse.xtext.xbase.idea.highlighting.XbaseHighlightingConfiguration"));
        bindFactory.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.idea.formatting.BlockFactory"), TypeReference.typeRef("org.eclipse.xtext.xbase.idea.formatting.XbaseBlockFactory"));
        bindFactory.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.idea.formatting.ChildAttributesProvider"), TypeReference.typeRef("org.eclipse.xtext.xbase.idea.formatting.XbaseChildAttributesProvider"));
        bindFactory.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ide.editor.bracketmatching.IBracePairProvider"), TypeReference.typeRef("org.eclipse.xtext.xbase.idea.bracketmatching.XbaseBracePairProvider"));
        bindFactory.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.idea.findusages.IReferenceSearcher"), TypeReference.typeRef("org.eclipse.xtext.xbase.idea.findusages.JvmElementAwareReferenceSearcher"));
        bindFactory.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.xbase.compiler.IGeneratorConfigProvider"), TypeReference.typeRef("org.eclipse.xtext.xbase.idea.facet.XbaseGeneratorConfigProvider"));
        TypeReference _typeRef_1 = TypeReference.typeRef("org.eclipse.xtext.idea.findusages.WordsScannerProvider");
        TypeReference _typeReference_1 = new TypeReference("org.eclipse.xtext.xbase.idea.findusages", "XbaseWordsScanner.XbaseWordsScannerProvider");
        bindFactory.addTypeToType(_typeRef_1, _typeReference_1);
    }
    bindFactory.contributeTo(this.getLanguage().getIdeaGenModule());
    JavaFileAccess _compileStandaloneSetup = this.compileStandaloneSetup(grammar);
    JavaFileAccess _compileIdeaSetup = this.compileIdeaSetup(grammar);
    JavaFileAccess _compileCompletionContributor = this.compileCompletionContributor(grammar);
    JavaFileAccess _compileFileType = this.compileFileType(grammar);
    JavaFileAccess _compileFacetConfiguration = this.compileFacetConfiguration(grammar);
    JavaFileAccess _compileColorSettingsPage = this.compileColorSettingsPage(grammar);
    final Consumer<JavaFileAccess> _function = (JavaFileAccess it) -> {
        it.writeTo(this.getProjectConfig().getIdeaPlugin().getSrc());
    };
    Collections.<JavaFileAccess>unmodifiableList(CollectionLiterals.<JavaFileAccess>newArrayList(_compileStandaloneSetup, _compileIdeaSetup, _compileCompletionContributor, _compileFileType, _compileFacetConfiguration, _compileColorSettingsPage)).forEach(_function);
    TextFileAccess _compileServicesISetup = this.compileServicesISetup(grammar);
    JavaFileAccess _compileAbstractCompletionContributor = this.compileAbstractCompletionContributor(grammar);
    JavaFileAccess _compileLanguage = this.compileLanguage(grammar);
    JavaFileAccess _compileAbstractFileType = this.compileAbstractFileType(grammar, fileExtension);
    JavaFileAccess _compileFileTypeFactory = this.compileFileTypeFactory(grammar);
    JavaFileAccess _compileFileImpl = this.compileFileImpl(grammar);
    JavaFileAccess _compileTokenTypeProvider = this.compileTokenTypeProvider(grammar);
    JavaFileAccess _compileElementTypeProvider = this.compileElementTypeProvider(grammar);
    JavaFileAccess _compileParserDefinition = this.compileParserDefinition(grammar);
    JavaFileAccess _compileSyntaxHighlighterFactory = this.compileSyntaxHighlighterFactory(grammar);
    JavaFileAccess _compileSemanticHighlightVisitor = this.compileSemanticHighlightVisitor(grammar);
    JavaFileAccess _compileExtensionFactory = this.compileExtensionFactory(grammar);
    JavaFileAccess _compileCodeBlockModificationListener = this.compileCodeBlockModificationListener(grammar);
    JavaFileAccess _compilePsiParser = this.compilePsiParser(grammar);
    JavaFileAccess _compileAntlrTokenFileProvider = this.compileAntlrTokenFileProvider(grammar);
    JavaFileAccess _compilePomDeclarationSearcher = this.compilePomDeclarationSearcher(grammar);
    JavaFileAccess _compileFacetType = this.compileFacetType(grammar);
    JavaFileAccess _compileBaseColorSettingsPage = this.compileBaseColorSettingsPage(grammar);
    final Consumer<TextFileAccess> _function_1 = (TextFileAccess it) -> {
        it.writeTo(this.getProjectConfig().getIdeaPlugin().getSrcGen());
    };
    Collections.<TextFileAccess>unmodifiableList(CollectionLiterals.<TextFileAccess>newArrayList(_compileServicesISetup, _compileAbstractCompletionContributor, _compileLanguage, _compileAbstractFileType, _compileFileTypeFactory, _compileFileImpl, _compileTokenTypeProvider, _compileElementTypeProvider, _compileParserDefinition, _compileSyntaxHighlighterFactory, _compileSemanticHighlightVisitor, _compileExtensionFactory, _compileCodeBlockModificationListener, _compilePsiParser, _compileAntlrTokenFileProvider, _compilePomDeclarationSearcher, _compileFacetType, _compileBaseColorSettingsPage)).forEach(_function_1);
    if (this.deployable) {
        final TextFileAccess pluginXml = this.compilePluginXml(grammar);
        boolean _isFile = this.getProjectConfig().getIdeaPlugin().getMetaInf().isFile(pluginXml.getPath());
        boolean _not_1 = (!_isFile);
        if (_not_1) {
            pluginXml.writeTo(this.getProjectConfig().getIdeaPlugin().getMetaInf());
        }
        this.compilePluginGenXml(grammar).writeTo(this.getProjectConfig().getIdeaPlugin().getMetaInf());
    }
}
Also used : GuiceModuleAccess(org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TextFileAccess(org.eclipse.xtext.xtext.generator.model.TextFileAccess) Grammar(org.eclipse.xtext.Grammar) JavaFileAccess(org.eclipse.xtext.xtext.generator.model.JavaFileAccess) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 10 with TypeReference

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

the class IdeaPluginGenerator method compileFileImpl.

public JavaFileAccess compileFileImpl(final Grammar grammar) {
    TypeReference _fileImpl = this._ideaPluginClassNames.getFileImpl(grammar);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public final class ");
            String _simpleName = IdeaPluginGenerator.this._ideaPluginClassNames.getFileImpl(grammar).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.psi.impl.BaseXtextFile");
            _builder.append(_typeRef);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public ");
            String _simpleName_1 = IdeaPluginGenerator.this._ideaPluginClassNames.getFileImpl(grammar).getSimpleName();
            _builder.append(_simpleName_1, "\t");
            _builder.append("(");
            TypeReference _typeRef_1 = TypeReference.typeRef("com.intellij.psi.FileViewProvider");
            _builder.append(_typeRef_1, "\t");
            _builder.append(" viewProvider) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("super(viewProvider, ");
            TypeReference _ideaLanguage = IdeaPluginGenerator.this._ideaPluginClassNames.getIdeaLanguage(grammar);
            _builder.append(_ideaLanguage, "\t\t");
            _builder.append(".INSTANCE);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public ");
            TypeReference _typeRef_2 = TypeReference.typeRef("com.intellij.openapi.fileTypes.FileType");
            _builder.append(_typeRef_2, "\t");
            _builder.append(" getFileType() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("return ");
            TypeReference _fileType = IdeaPluginGenerator.this._ideaPluginClassNames.getFileType(grammar);
            _builder.append(_fileType, "\t\t");
            _builder.append(".INSTANCE;");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    return this.fileAccessFactory.createJavaFile(_fileImpl, _client);
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) 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