Search in sources :

Example 96 with StringConcatenationClient

use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.

the class IdeaPluginGenerator method compileSemanticHighlightVisitor.

public JavaFileAccess compileSemanticHighlightVisitor(final Grammar grammar) {
    TypeReference _semanticHighlightVisitor = this._ideaPluginClassNames.getSemanticHighlightVisitor(grammar);
    StringConcatenationClient _client = new StringConcatenationClient() {

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

Example 97 with StringConcatenationClient

use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.

the class IdeaPluginGenerator method compileExtensionFactory.

public JavaFileAccess compileExtensionFactory(final Grammar grammar) {
    TypeReference _extensionFactory = this._ideaPluginClassNames.getExtensionFactory(grammar);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _simpleName = IdeaPluginGenerator.this._ideaPluginClassNames.getExtensionFactory(grammar).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" implements ");
            TypeReference _typeRef = TypeReference.typeRef("com.intellij.openapi.extensions.ExtensionFactory");
            _builder.append(_typeRef);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public Object createInstance(");
            _builder.append(String.class, "\t");
            _builder.append(" factoryArgument, ");
            _builder.append(String.class, "\t");
            _builder.append(" implementationClass) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append(Class.class, "\t\t");
            _builder.append("<?> clazz;");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("try {");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("clazz = ");
            _builder.append(Class.class, "\t\t\t");
            _builder.append(".forName(implementationClass);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("} catch (");
            _builder.append(ClassNotFoundException.class, "\t\t");
            _builder.append(" e) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t");
            _builder.append("throw new ");
            _builder.append(IllegalArgumentException.class, "\t\t\t");
            _builder.append("(\"Couldn\'t load \"+implementationClass, e);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return ");
            TypeReference _ideaLanguage = IdeaPluginGenerator.this._ideaPluginClassNames.getIdeaLanguage(grammar);
            _builder.append(_ideaLanguage, "\t\t");
            _builder.append(".INSTANCE.<Object> getInstance(clazz);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    return this.fileAccessFactory.createJavaFile(_extensionFactory, _client);
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 98 with StringConcatenationClient

use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.

the class IdeaPluginGenerator method compileBaseColorSettingsPage.

public JavaFileAccess compileBaseColorSettingsPage(final Grammar grammar) {
    TypeReference _baseColorSettingsPage = this._ideaPluginClassNames.baseColorSettingsPage(grammar);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _simpleName = IdeaPluginGenerator.this._ideaPluginClassNames.baseColorSettingsPage(grammar).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.idea.highlighting.AbstractColorSettingsPage");
            _builder.append(_typeRef);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public ");
            String _simpleName_1 = IdeaPluginGenerator.this._ideaPluginClassNames.baseColorSettingsPage(grammar).getSimpleName();
            _builder.append(_simpleName_1, "\t");
            _builder.append("() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            TypeReference _ideaLanguage = IdeaPluginGenerator.this._ideaPluginClassNames.getIdeaLanguage(grammar);
            _builder.append(_ideaLanguage, "\t\t");
            _builder.append(".INSTANCE.injectMembers(this);");
            _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 String getDisplayName() {");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return ");
            TypeReference _ideaLanguage_1 = IdeaPluginGenerator.this._ideaPluginClassNames.getIdeaLanguage(grammar);
            _builder.append(_ideaLanguage_1, "\t\t");
            _builder.append(".INSTANCE.getDisplayName();");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    return this.fileAccessFactory.createJavaFile(_baseColorSettingsPage, _client);
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 99 with StringConcatenationClient

use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.

the class IdeaPluginGenerator method compileParserDefinition.

public JavaFileAccess compileParserDefinition(final Grammar grammar) {
    final Function1<AbstractRule, Boolean> _function = (AbstractRule it) -> {
        return Boolean.valueOf(GrammarUtil.isEObjectRule(it));
    };
    final Iterable<AbstractRule> EObjectRules = IterableExtensions.<AbstractRule>filter(GrammarUtil.allRules(grammar), _function);
    TypeReference _parserDefinition = this._ideaPluginClassNames.getParserDefinition(grammar);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _simpleName = IdeaPluginGenerator.this._ideaPluginClassNames.getParserDefinition(grammar).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _superParserDefinition = IdeaPluginGenerator.this._ideaPluginClassNames.getSuperParserDefinition(grammar);
            _builder.append(_superParserDefinition);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            {
                boolean _isEmpty = IterableExtensions.isEmpty(EObjectRules);
                boolean _not = (!_isEmpty);
                if (_not) {
                    _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("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public ");
            TypeReference _typeRef = TypeReference.typeRef("com.intellij.psi.PsiFile");
            _builder.append(_typeRef, "\t");
            _builder.append(" createFile(");
            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("return new ");
            TypeReference _fileImpl = IdeaPluginGenerator.this._ideaPluginClassNames.getFileImpl(grammar);
            _builder.append(_fileImpl, "\t\t");
            _builder.append("(viewProvider);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            {
                boolean _isEmpty_1 = IterableExtensions.isEmpty(EObjectRules);
                boolean _not_1 = (!_isEmpty_1);
                if (_not_1) {
                    _builder.append("\t");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("@Override");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("@SuppressWarnings(\"rawtypes\")");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("public ");
                    TypeReference _typeRef_2 = TypeReference.typeRef("com.intellij.psi.PsiElement");
                    _builder.append(_typeRef_2, "\t");
                    _builder.append(" createElement(");
                    TypeReference _typeRef_3 = TypeReference.typeRef("com.intellij.lang.ASTNode");
                    _builder.append(_typeRef_3, "\t");
                    _builder.append(" node) {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("Boolean hasSemanticElement = node.getUserData(");
                    TypeReference _typeRef_4 = TypeReference.typeRef("org.eclipse.xtext.idea.nodemodel.IASTNodeAwareNodeModelBuilder");
                    _builder.append(_typeRef_4, "\t\t");
                    _builder.append(".HAS_SEMANTIC_ELEMENT_KEY);");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("if (hasSemanticElement != null && hasSemanticElement) {");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t");
                    TypeReference _typeRef_5 = TypeReference.typeRef("com.intellij.psi.tree.IElementType");
                    _builder.append(_typeRef_5, "\t\t\t");
                    _builder.append(" elementType = node.getElementType();");
                    _builder.newLineIfNotEmpty();
                    {
                        for (final AbstractRule rule : EObjectRules) {
                            _builder.append("\t");
                            _builder.append("\t\t");
                            _builder.append("if (elementType == elementTypeProvider.get");
                            String _grammarElementIdentifier = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(rule);
                            _builder.append(_grammarElementIdentifier, "\t\t\t");
                            _builder.append("ElementType()) {");
                            _builder.newLineIfNotEmpty();
                            {
                                boolean _isNamed = IdeaPluginGenerator.this.isNamed(rule);
                                if (_isNamed) {
                                    _builder.append("\t");
                                    _builder.append("\t\t");
                                    _builder.append("\t");
                                    _builder.append("return new ");
                                    TypeReference _typeRef_6 = TypeReference.typeRef("org.eclipse.xtext.psi.impl.PsiNamedEObjectImpl");
                                    _builder.append(_typeRef_6, "\t\t\t\t");
                                    _builder.append("(node) {};");
                                    _builder.newLineIfNotEmpty();
                                } else {
                                    _builder.append("\t");
                                    _builder.append("\t\t");
                                    _builder.append("\t");
                                    _builder.append("return new ");
                                    TypeReference _typeRef_7 = TypeReference.typeRef("org.eclipse.xtext.psi.impl.PsiEObjectImpl");
                                    _builder.append(_typeRef_7, "\t\t\t\t");
                                    _builder.append("(node) {};");
                                    _builder.newLineIfNotEmpty();
                                }
                            }
                            _builder.append("\t");
                            _builder.append("\t\t");
                            _builder.append("}");
                            _builder.newLine();
                            {
                                Iterable<AbstractElement> _eObjectElements = IdeaPluginGenerator.this.getEObjectElements(rule);
                                for (final AbstractElement element : _eObjectElements) {
                                    _builder.append("\t");
                                    _builder.append("\t\t");
                                    _builder.append("if (elementType == elementTypeProvider.get");
                                    String _grammarElementIdentifier_1 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(element);
                                    _builder.append(_grammarElementIdentifier_1, "\t\t\t");
                                    _builder.append("ElementType()) {");
                                    _builder.newLineIfNotEmpty();
                                    {
                                        boolean _isNamed_1 = IdeaPluginGenerator.this.isNamed(element);
                                        if (_isNamed_1) {
                                            _builder.append("\t");
                                            _builder.append("\t\t");
                                            _builder.append("\t");
                                            _builder.append("return new ");
                                            TypeReference _typeRef_8 = TypeReference.typeRef("org.eclipse.xtext.psi.impl.PsiNamedEObjectImpl");
                                            _builder.append(_typeRef_8, "\t\t\t\t");
                                            _builder.append("(node) {};");
                                            _builder.newLineIfNotEmpty();
                                        } else {
                                            _builder.append("\t");
                                            _builder.append("\t\t");
                                            _builder.append("\t");
                                            _builder.append("return new ");
                                            TypeReference _typeRef_9 = TypeReference.typeRef("org.eclipse.xtext.psi.impl.PsiEObjectImpl");
                                            _builder.append(_typeRef_9, "\t\t\t\t");
                                            _builder.append("(node) {};");
                                            _builder.newLineIfNotEmpty();
                                        }
                                    }
                                    _builder.append("\t");
                                    _builder.append("\t\t");
                                    _builder.append("}");
                                    _builder.newLine();
                                }
                            }
                        }
                    }
                    _builder.append("\t");
                    _builder.append("\t\t");
                    _builder.append("throw new ");
                    TypeReference _typeRef_10 = TypeReference.typeRef("java.lang.IllegalStateException");
                    _builder.append(_typeRef_10, "\t\t\t");
                    _builder.append("(\"Unexpected element type: \" + elementType);");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("}");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("return super.createElement(node);");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("}");
                    _builder.newLine();
                }
            }
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    return this.fileAccessFactory.createJavaFile(_parserDefinition, _client);
}
Also used : Inject(com.google.inject.Inject) AbstractElement(org.eclipse.xtext.AbstractElement) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 100 with StringConcatenationClient

use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.

the class IdeaPluginGenerator method compileAbstractFileType.

public JavaFileAccess compileAbstractFileType(final Grammar grammar, final String fileExtension) {
    TypeReference _abstractFileType = this._ideaPluginClassNames.getAbstractFileType(grammar);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _simpleName = IdeaPluginGenerator.this._ideaPluginClassNames.getAbstractFileType(grammar).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _typeRef = TypeReference.typeRef("com.intellij.openapi.fileTypes.LanguageFileType");
            _builder.append(_typeRef);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@");
            TypeReference _typeRef_1 = TypeReference.typeRef("org.jetbrains.annotations.NonNls");
            _builder.append(_typeRef_1, "\t");
            _builder.append(" ");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("public static final String DEFAULT_EXTENSION = \"");
            _builder.append(fileExtension, "\t");
            _builder.append("\";");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected ");
            String _simpleName_1 = IdeaPluginGenerator.this._ideaPluginClassNames.getAbstractFileType(grammar).getSimpleName();
            _builder.append(_simpleName_1, "\t");
            _builder.append("(final ");
            TypeReference _typeRef_2 = TypeReference.typeRef("com.intellij.lang.Language");
            _builder.append(_typeRef_2, "\t");
            _builder.append(" language) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("super(language);");
            _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 String getDefaultExtension() {");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return DEFAULT_EXTENSION;");
            _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 String getDescription() {");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return \"");
            String _simpleName_2 = IdeaPluginGenerator.this._ideaPluginExtension.getSimpleName(grammar);
            _builder.append(_simpleName_2, "\t\t");
            _builder.append(" files\";");
            _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_3 = TypeReference.typeRef("javax.swing.Icon");
            _builder.append(_typeRef_3, "\t");
            _builder.append(" getIcon() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("return ");
            TypeReference _typeRef_4 = TypeReference.typeRef("org.eclipse.xtext.idea.Icons");
            _builder.append(_typeRef_4, "\t\t");
            _builder.append(".DSL_FILE_TYPE;");
            _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 String getName() {");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return \"");
            String _simpleName_3 = IdeaPluginGenerator.this._ideaPluginExtension.getSimpleName(grammar);
            _builder.append(_simpleName_3, "\t\t");
            _builder.append("\";");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    return this.fileAccessFactory.createJavaFile(_abstractFileType, _client);
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Aggregations

StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)194 TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)119 GeneratedJavaFileAccess (org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess)24 GuiceModuleAccess (org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess)24 Grammar (org.eclipse.xtext.Grammar)23 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)19 List (java.util.List)18 Test (org.junit.Test)18 Set (java.util.Set)14 JavaFileAccess (org.eclipse.xtext.xtext.generator.model.JavaFileAccess)12 ManifestAccess (org.eclipse.xtext.xtext.generator.model.ManifestAccess)12 EClass (org.eclipse.emf.ecore.EClass)11 EList (org.eclipse.emf.common.util.EList)10 AbstractRule (org.eclipse.xtext.AbstractRule)10 IGeneratorNode (org.eclipse.xtext.generator.trace.node.IGeneratorNode)10 EObject (org.eclipse.emf.ecore.EObject)9 IClassAnnotation (org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation)9 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)8 SuppressWarningsAnnotation (org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation)8 ArrayList (java.util.ArrayList)7