Search in sources :

Example 36 with TypeReference

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

the class ValidatorFragment2 method generateValidationToDeprecateRules.

protected StringConcatenationClient generateValidationToDeprecateRules() {
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            {
                if (ValidatorFragment2.this.generateDeprecationValidation) {
                    {
                        List<AbstractRule> _deprecatedRulesFromGrammar = ValidatorFragment2.this.getDeprecatedRulesFromGrammar();
                        for (final AbstractRule deprecatedRule : _deprecatedRulesFromGrammar) {
                            EClassifier _classifier = deprecatedRule.getType().getClassifier();
                            ResourceSet _resourceSet = ValidatorFragment2.this.getGrammar().eResource().getResourceSet();
                            final TypeReference elementType = new TypeReference(((EClass) _classifier), _resourceSet);
                            _builder.newLineIfNotEmpty();
                            _builder.newLine();
                            _builder.append("@");
                            _builder.append(Check.class);
                            _builder.newLineIfNotEmpty();
                            _builder.append("public void checkDeprecated");
                            String _simpleName = elementType.getSimpleName();
                            _builder.append(_simpleName);
                            _builder.append("(");
                            _builder.append(elementType);
                            _builder.append(" element) {");
                            _builder.newLineIfNotEmpty();
                            _builder.append("\t");
                            _builder.append("warning(\"This part of the language is marked as deprecated and might get removed in the future!\", element, null);");
                            _builder.newLine();
                            _builder.append("}");
                            _builder.newLine();
                        }
                    }
                }
            }
        }
    };
    return _client;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) EClassifier(org.eclipse.emf.ecore.EClassifier) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 37 with TypeReference

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

the class ValidatorFragment2 method generateGenValidator.

protected GeneratedJavaFileAccess generateGenValidator() {
    GeneratedJavaFileAccess _xblockexpression = null;
    {
        TypeReference _xifexpression = null;
        boolean _isGenerateStub = this.isGenerateStub();
        if (_isGenerateStub) {
            _xifexpression = this._validatorNaming.getAbstractValidatorClass(this.getGrammar());
        } else {
            _xifexpression = this._validatorNaming.getValidatorClass(this.getGrammar());
        }
        final TypeReference genClass = _xifexpression;
        final GeneratedJavaFileAccess javaFile = this.fileAccessFactory.createGeneratedJavaFile(genClass);
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                {
                    boolean _isEmpty = ValidatorFragment2.this.composedChecks.isEmpty();
                    boolean _not = (!_isEmpty);
                    if (_not) {
                        _builder.append("@");
                        _builder.append(ComposedChecks.class);
                        _builder.append("(validators = {");
                        {
                            boolean _hasElements = false;
                            for (final String validator : ValidatorFragment2.this.composedChecks) {
                                if (!_hasElements) {
                                    _hasElements = true;
                                } else {
                                    _builder.appendImmediate(", ", "");
                                }
                                TypeReference _typeRef = TypeReference.typeRef(validator);
                                _builder.append(_typeRef);
                                _builder.append(".class");
                            }
                        }
                        _builder.append("})");
                        _builder.newLineIfNotEmpty();
                    }
                }
                _builder.append("public ");
                {
                    boolean _isGenerateStub = ValidatorFragment2.this.isGenerateStub();
                    if (_isGenerateStub) {
                        _builder.append("abstract ");
                    }
                }
                _builder.append("class ");
                String _simpleName = genClass.getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                TypeReference _genValidatorSuperClass = ValidatorFragment2.this.getGenValidatorSuperClass(ValidatorFragment2.this.getGrammar());
                _builder.append(_genValidatorSuperClass);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@Override");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("protected ");
                _builder.append(List.class, "\t");
                _builder.append("<");
                _builder.append(EPackage.class, "\t");
                _builder.append("> getEPackages() {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append(List.class, "\t\t");
                _builder.append("<");
                _builder.append(EPackage.class, "\t\t");
                _builder.append("> result = new ");
                _builder.append(ArrayList.class, "\t\t");
                _builder.append("<");
                _builder.append(EPackage.class, "\t\t");
                _builder.append(">(");
                {
                    if ((ValidatorFragment2.this.isInheritImplementation() && (GrammarUtil2.getNonTerminalsSuperGrammar(ValidatorFragment2.this.getGrammar()) != null))) {
                        _builder.append("super.getEPackages()");
                    }
                }
                _builder.append(");");
                _builder.newLineIfNotEmpty();
                {
                    Iterable<EPackage> _generatedPackagesToValidate = ValidatorFragment2.this.getGeneratedPackagesToValidate();
                    for (final EPackage e : _generatedPackagesToValidate) {
                        _builder.append("\t\t");
                        _builder.append("result.add(");
                        String _generatedEPackageName = ValidatorFragment2.this.getGeneratedEPackageName(e);
                        _builder.append(_generatedEPackageName, "\t\t");
                        _builder.append(".eINSTANCE);");
                        _builder.newLineIfNotEmpty();
                    }
                }
                {
                    Collection<EPackage> _registryPackagesToValidate = ValidatorFragment2.this.getRegistryPackagesToValidate();
                    for (final EPackage e_1 : _registryPackagesToValidate) {
                        _builder.append("\t\t");
                        _builder.append("result.add(EPackage.Registry.INSTANCE.getEPackage(\"");
                        String _nsURI = e_1.getNsURI();
                        _builder.append(_nsURI, "\t\t");
                        _builder.append("\"));");
                        _builder.newLineIfNotEmpty();
                    }
                }
                _builder.append("\t\t");
                _builder.append("return result;");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.append("\t");
                StringConcatenationClient _generateValidationToDeprecateRules = ValidatorFragment2.this.generateValidationToDeprecateRules();
                _builder.append(_generateValidationToDeprecateRules, "\t");
                _builder.newLineIfNotEmpty();
                _builder.append("}");
                _builder.newLine();
            }
        };
        javaFile.setContent(_client);
        _xblockexpression = javaFile;
    }
    return _xblockexpression;
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) ArrayList(java.util.ArrayList) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) ArrayList(java.util.ArrayList) List(java.util.List) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) EPackage(org.eclipse.emf.ecore.EPackage)

Example 38 with TypeReference

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

the class ValidatorFragment2 method generateJavaValidatorStub.

protected void generateJavaValidatorStub() {
    TypeReference _validatorClass = this._validatorNaming.getValidatorClass(this.getGrammar());
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("/**");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* This class contains custom validation rules. ");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("*");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
            _builder.append("public class ");
            String _simpleName = ValidatorFragment2.this._validatorNaming.getValidatorClass(ValidatorFragment2.this.getGrammar()).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _abstractValidatorClass = ValidatorFragment2.this._validatorNaming.getAbstractValidatorClass(ValidatorFragment2.this.getGrammar());
            _builder.append(_abstractValidatorClass);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("//\tpublic static final INVALID_NAME = \'invalidName\'");
            _builder.newLine();
            _builder.append("//");
            _builder.newLine();
            _builder.append("//\t@Check");
            _builder.newLine();
            _builder.append("//\tpublic void checkGreetingStartsWithCapital(Greeting greeting) {");
            _builder.newLine();
            _builder.append("//\t\tif (!Character.isUpperCase(greeting.getName().charAt(0))) {");
            _builder.newLine();
            _builder.append("//\t\t\twarning(\"Name should start with a capital\",");
            _builder.newLine();
            _builder.append("//\t\t\t\t\t");
            String _simpleName_1 = GrammarUtil.getSimpleName(ValidatorFragment2.this.getGrammar());
            _builder.append(_simpleName_1);
            _builder.append("Package.Literals.GREETING__NAME,");
            _builder.newLineIfNotEmpty();
            _builder.append("//\t\t\t\t\tINVALID_NAME);");
            _builder.newLine();
            _builder.append("//\t\t}");
            _builder.newLine();
            _builder.append("//\t}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    this.fileAccessFactory.createJavaFile(_validatorClass, _client).writeTo(this.getProjectConfig().getRuntime().getSrc());
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 39 with TypeReference

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

the class XbaseGeneratorFragment2 method contributeEclipsePluginExtensions.

protected boolean contributeEclipsePluginExtensions() {
    boolean _xblockexpression = false;
    {
        final String name = this.getLanguage().getGrammar().getName();
        if (this.jdtTypeHierarchy) {
            List<CharSequence> _entries = this.getProjectConfig().getEclipsePlugin().getPluginXml().getEntries();
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("<!-- Type Hierarchy  -->");
            _builder.newLine();
            _builder.append("<extension point=\"org.eclipse.ui.handlers\">");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("<handler ");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("class=\"");
            TypeReference _eclipsePluginExecutableExtensionFactory = this._xtextGeneratorNaming.getEclipsePluginExecutableExtensionFactory(this.getGrammar());
            _builder.append(_eclipsePluginExecutableExtensionFactory, "\t\t");
            _builder.append(":org.eclipse.xtext.xbase.ui.hierarchy.OpenTypeHierarchyHandler\"");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("commandId=\"org.eclipse.xtext.xbase.ui.hierarchy.OpenTypeHierarchy\">");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("<activeWhen>");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("<reference");
            _builder.newLine();
            _builder.append("\t\t\t\t");
            _builder.append("definitionId=\"");
            _builder.append(name, "\t\t\t\t");
            _builder.append(".Editor.opened\">");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t");
            _builder.append("</reference>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("</activeWhen>");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("</handler>");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("<handler ");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("class=\"");
            TypeReference _eclipsePluginExecutableExtensionFactory_1 = this._xtextGeneratorNaming.getEclipsePluginExecutableExtensionFactory(this.getGrammar());
            _builder.append(_eclipsePluginExecutableExtensionFactory_1, "\t\t");
            _builder.append(":org.eclipse.xtext.xbase.ui.hierarchy.QuickTypeHierarchyHandler\"");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("commandId=\"org.eclipse.jdt.ui.edit.text.java.open.hierarchy\">");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("<activeWhen>");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("<reference");
            _builder.newLine();
            _builder.append("\t\t\t\t");
            _builder.append("definitionId=\"");
            _builder.append(name, "\t\t\t\t");
            _builder.append(".Editor.opened\">");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t");
            _builder.append("</reference>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("</activeWhen>");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("</handler>");
            _builder.newLine();
            {
                boolean _usesXImportSection = this._xbaseUsageDetector.usesXImportSection(this.getLanguage().getGrammar());
                if (_usesXImportSection) {
                    _builder.append("\t");
                    _builder.append("<handler");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("class=\"");
                    TypeReference _eclipsePluginExecutableExtensionFactory_2 = this._xtextGeneratorNaming.getEclipsePluginExecutableExtensionFactory(this.getGrammar());
                    _builder.append(_eclipsePluginExecutableExtensionFactory_2, "\t\t");
                    _builder.append(":org.eclipse.xtext.xbase.ui.imports.OrganizeImportsHandler\"");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("commandId=\"org.eclipse.xtext.xbase.ui.organizeImports\">");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("<activeWhen>");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t");
                    _builder.append("<reference");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t\t");
                    _builder.append("definitionId=\"");
                    _builder.append(name, "\t\t\t\t");
                    _builder.append(".Editor.opened\">");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t\t");
                    _builder.append("</reference>");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("</activeWhen>");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("</handler>");
                    _builder.newLine();
                }
            }
            _builder.append("</extension>");
            _builder.newLine();
            _builder.append("<extension point=\"org.eclipse.ui.menus\">");
            _builder.newLine();
            {
                boolean _usesXImportSection_1 = this._xbaseUsageDetector.usesXImportSection(this.getLanguage().getGrammar());
                if (_usesXImportSection_1) {
                    _builder.append("\t");
                    _builder.append("<menuContribution");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("locationURI=\"popup:#TextEditorContext?after=group.edit\">");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t ");
                    _builder.append("<command");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t ");
                    _builder.append("commandId=\"org.eclipse.xtext.xbase.ui.organizeImports\"");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t ");
                    _builder.append("style=\"push\"");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t ");
                    _builder.append("tooltip=\"Organize Imports\">");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t");
                    _builder.append("<visibleWhen checkEnabled=\"false\">");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t\t");
                    _builder.append("<reference");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t\t\t");
                    _builder.append("definitionId=\"");
                    _builder.append(name, "\t\t\t\t\t");
                    _builder.append(".Editor.opened\">");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t\t\t");
                    _builder.append("</reference>");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t\t");
                    _builder.append("</visibleWhen>");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("</command>");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("</menuContribution>");
                    _builder.newLine();
                }
            }
            _builder.append("\t");
            _builder.append("<menuContribution");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("locationURI=\"popup:#TextEditorContext?after=group.open\">");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("<command commandId=\"org.eclipse.xtext.xbase.ui.hierarchy.OpenTypeHierarchy\"");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("style=\"push\"");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("tooltip=\"Open Type Hierarchy\">");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("<visibleWhen checkEnabled=\"false\">");
            _builder.newLine();
            _builder.append("\t\t\t\t");
            _builder.append("<reference definitionId=\"");
            _builder.append(name, "\t\t\t\t");
            _builder.append(".Editor.opened\"/>");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t");
            _builder.append("</visibleWhen>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("</command>");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("</menuContribution>");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("<menuContribution");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("locationURI=\"popup:#TextEditorContext?after=group.open\">");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("<command commandId=\"org.eclipse.jdt.ui.edit.text.java.open.hierarchy\"");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("style=\"push\"");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("tooltip=\"Quick Type Hierarchy\">");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("<visibleWhen checkEnabled=\"false\">");
            _builder.newLine();
            _builder.append("\t\t\t\t");
            _builder.append("<reference definitionId=\"");
            _builder.append(name, "\t\t\t\t");
            _builder.append(".Editor.opened\"/>");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t");
            _builder.append("</visibleWhen>");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("</command>");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("</menuContribution>");
            _builder.newLine();
            _builder.append("</extension>");
            _builder.newLine();
            _entries.add(_builder.toString());
        }
        if (this.jdtCallHierarchy) {
            List<CharSequence> _entries_1 = this.getProjectConfig().getEclipsePlugin().getPluginXml().getEntries();
            StringConcatenation _builder_1 = new StringConcatenation();
            _builder_1.append("<!-- Call Hierachy -->");
            _builder_1.newLine();
            _builder_1.append("<extension point=\"org.eclipse.ui.handlers\">");
            _builder_1.newLine();
            _builder_1.append("\t");
            _builder_1.append("<handler ");
            _builder_1.newLine();
            _builder_1.append("\t\t");
            _builder_1.append("class=\"");
            TypeReference _eclipsePluginExecutableExtensionFactory_3 = this._xtextGeneratorNaming.getEclipsePluginExecutableExtensionFactory(this.getGrammar());
            _builder_1.append(_eclipsePluginExecutableExtensionFactory_3, "\t\t");
            _builder_1.append(":org.eclipse.xtext.xbase.ui.hierarchy.OpenCallHierachyHandler\"");
            _builder_1.newLineIfNotEmpty();
            _builder_1.append("\t\t");
            _builder_1.append("commandId=\"org.eclipse.xtext.xbase.ui.hierarchy.OpenCallHierarchy\">");
            _builder_1.newLine();
            _builder_1.append("\t\t");
            _builder_1.append("<activeWhen>");
            _builder_1.newLine();
            _builder_1.append("\t\t\t");
            _builder_1.append("<reference");
            _builder_1.newLine();
            _builder_1.append("\t\t\t\t");
            _builder_1.append("definitionId=\"");
            _builder_1.append(name, "\t\t\t\t");
            _builder_1.append(".Editor.opened\">");
            _builder_1.newLineIfNotEmpty();
            _builder_1.append("\t\t\t");
            _builder_1.append("</reference>");
            _builder_1.newLine();
            _builder_1.append("\t\t");
            _builder_1.append("</activeWhen>");
            _builder_1.newLine();
            _builder_1.append("\t");
            _builder_1.append("</handler>");
            _builder_1.newLine();
            _builder_1.append("</extension>");
            _builder_1.newLine();
            _builder_1.append("<extension point=\"org.eclipse.ui.menus\">");
            _builder_1.newLine();
            _builder_1.append("\t");
            _builder_1.append("<menuContribution");
            _builder_1.newLine();
            _builder_1.append("\t\t");
            _builder_1.append("locationURI=\"popup:#TextEditorContext?after=group.open\">");
            _builder_1.newLine();
            _builder_1.append("\t\t");
            _builder_1.append("<command commandId=\"org.eclipse.xtext.xbase.ui.hierarchy.OpenCallHierarchy\"");
            _builder_1.newLine();
            _builder_1.append("\t\t\t");
            _builder_1.append("style=\"push\"");
            _builder_1.newLine();
            _builder_1.append("\t\t\t");
            _builder_1.append("tooltip=\"Open Call Hierarchy\">");
            _builder_1.newLine();
            _builder_1.append("\t\t\t");
            _builder_1.append("<visibleWhen checkEnabled=\"false\">");
            _builder_1.newLine();
            _builder_1.append("\t\t\t\t");
            _builder_1.append("<reference definitionId=\"");
            _builder_1.append(name, "\t\t\t\t");
            _builder_1.append(".Editor.opened\"/>");
            _builder_1.newLineIfNotEmpty();
            _builder_1.append("\t\t\t");
            _builder_1.append("</visibleWhen>");
            _builder_1.newLine();
            _builder_1.append("\t\t");
            _builder_1.append("</command>");
            _builder_1.newLine();
            _builder_1.append("\t");
            _builder_1.append("</menuContribution>");
            _builder_1.newLine();
            _builder_1.append("</extension>");
            _builder_1.newLine();
            _entries_1.add(_builder_1.toString());
        }
        List<CharSequence> _entries_2 = this.getProjectConfig().getEclipsePlugin().getPluginXml().getEntries();
        StringConcatenation _builder_2 = new StringConcatenation();
        _builder_2.append("<extension point=\"org.eclipse.core.runtime.adapters\">");
        _builder_2.newLine();
        _builder_2.append("\t");
        _builder_2.append("<factory class=\"");
        TypeReference _eclipsePluginExecutableExtensionFactory_4 = this._xtextGeneratorNaming.getEclipsePluginExecutableExtensionFactory(this.getGrammar());
        _builder_2.append(_eclipsePluginExecutableExtensionFactory_4, "\t");
        _builder_2.append(":org.eclipse.xtext.builder.smap.StratumBreakpointAdapterFactory\"");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t");
        _builder_2.append("adaptableType=\"");
        String _name = this._xtextGeneratorNaming.getEclipsePluginEditor(this.getGrammar()).getName();
        _builder_2.append(_name, "\t\t");
        _builder_2.append("\">");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t");
        _builder_2.append("<adapter type=\"org.eclipse.debug.ui.actions.IToggleBreakpointsTarget\"/>");
        _builder_2.newLine();
        _builder_2.append("\t");
        _builder_2.append("</factory> ");
        _builder_2.newLine();
        _builder_2.append("</extension>");
        _builder_2.newLine();
        _builder_2.append("<extension point=\"org.eclipse.ui.editorActions\">");
        _builder_2.newLine();
        _builder_2.append("\t");
        _builder_2.append("<editorContribution targetID=\"");
        _builder_2.append(name, "\t");
        _builder_2.append("\" ");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t");
        _builder_2.append("id=\"");
        _builder_2.append(name, "\t\t");
        _builder_2.append(".rulerActions\">");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t");
        _builder_2.append("<action");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("label=\"Not Used\"");
        _builder_2.newLine();
        _builder_2.append(" \t\t\t");
        _builder_2.append("class=\"");
        TypeReference _eclipsePluginExecutableExtensionFactory_5 = this._xtextGeneratorNaming.getEclipsePluginExecutableExtensionFactory(this.getGrammar());
        _builder_2.append(_eclipsePluginExecutableExtensionFactory_5, " \t\t\t");
        _builder_2.append(":org.eclipse.debug.ui.actions.RulerToggleBreakpointActionDelegate\"");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t\t");
        _builder_2.append("style=\"push\"");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("actionID=\"RulerDoubleClick\"");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("id=\"");
        _builder_2.append(name, "\t\t\t");
        _builder_2.append(".doubleClickBreakpointAction\"/>");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t");
        _builder_2.append("</editorContribution>");
        _builder_2.newLine();
        _builder_2.append("</extension>");
        _builder_2.newLine();
        _builder_2.append("<extension point=\"org.eclipse.ui.popupMenus\">");
        _builder_2.newLine();
        _builder_2.append("\t");
        _builder_2.append("<viewerContribution");
        _builder_2.newLine();
        _builder_2.append("\t\t");
        _builder_2.append("targetID=\"");
        _builder_2.append(name, "\t\t");
        _builder_2.append(".RulerContext\"");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t");
        _builder_2.append("id=\"");
        _builder_2.append(name, "\t\t");
        _builder_2.append(".RulerPopupActions\">");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t");
        _builder_2.append("<action");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("label=\"Toggle Breakpoint\"");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("class=\"");
        TypeReference _eclipsePluginExecutableExtensionFactory_6 = this._xtextGeneratorNaming.getEclipsePluginExecutableExtensionFactory(this.getGrammar());
        _builder_2.append(_eclipsePluginExecutableExtensionFactory_6, "\t\t\t");
        _builder_2.append(":org.eclipse.debug.ui.actions.RulerToggleBreakpointActionDelegate\"");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t\t");
        _builder_2.append("menubarPath=\"debug\"");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("id=\"");
        _builder_2.append(name, "\t\t\t");
        _builder_2.append(".rulerContextMenu.toggleBreakpointAction\">");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t");
        _builder_2.append("</action>");
        _builder_2.newLine();
        _builder_2.append("\t\t");
        _builder_2.append("<action");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("label=\"Not used\"");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("class=\"");
        TypeReference _eclipsePluginExecutableExtensionFactory_7 = this._xtextGeneratorNaming.getEclipsePluginExecutableExtensionFactory(this.getGrammar());
        _builder_2.append(_eclipsePluginExecutableExtensionFactory_7, "\t\t\t");
        _builder_2.append(":org.eclipse.debug.ui.actions.RulerEnableDisableBreakpointActionDelegate\"");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t\t");
        _builder_2.append("menubarPath=\"debug\"");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("id=\"");
        _builder_2.append(name, "\t\t\t");
        _builder_2.append(".rulerContextMenu.enableDisableBreakpointAction\">");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t");
        _builder_2.append("</action>");
        _builder_2.newLine();
        _builder_2.append("\t\t");
        _builder_2.append("<action");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("label=\"Breakpoint Properties\"");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("helpContextId=\"breakpoint_properties_action_context\"");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("class=\"");
        TypeReference _eclipsePluginExecutableExtensionFactory_8 = this._xtextGeneratorNaming.getEclipsePluginExecutableExtensionFactory(this.getGrammar());
        _builder_2.append(_eclipsePluginExecutableExtensionFactory_8, "\t\t\t");
        _builder_2.append(":org.eclipse.jdt.debug.ui.actions.JavaBreakpointPropertiesRulerActionDelegate\"");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t\t");
        _builder_2.append("menubarPath=\"group.properties\"");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("id=\"");
        _builder_2.append(name, "\t\t\t");
        _builder_2.append(".rulerContextMenu.openBreapointPropertiesAction\">");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t");
        _builder_2.append("</action>");
        _builder_2.newLine();
        _builder_2.append("\t");
        _builder_2.append("</viewerContribution>");
        _builder_2.newLine();
        _builder_2.append("</extension>");
        _builder_2.newLine();
        _builder_2.append("<!-- Introduce Local Variable Refactoring -->");
        _builder_2.newLine();
        _builder_2.append("<extension point=\"org.eclipse.ui.handlers\">");
        _builder_2.newLine();
        _builder_2.append("\t");
        _builder_2.append("<handler ");
        _builder_2.newLine();
        _builder_2.append("\t\t");
        _builder_2.append("class=\"");
        TypeReference _eclipsePluginExecutableExtensionFactory_9 = this._xtextGeneratorNaming.getEclipsePluginExecutableExtensionFactory(this.getGrammar());
        _builder_2.append(_eclipsePluginExecutableExtensionFactory_9, "\t\t");
        _builder_2.append(":org.eclipse.xtext.xbase.ui.refactoring.ExtractVariableHandler\"");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t");
        _builder_2.append("commandId=\"org.eclipse.xtext.xbase.ui.refactoring.ExtractLocalVariable\">");
        _builder_2.newLine();
        _builder_2.append("\t\t");
        _builder_2.append("<activeWhen>");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("<reference");
        _builder_2.newLine();
        _builder_2.append("\t\t\t\t");
        _builder_2.append("definitionId=\"");
        _builder_2.append(name, "\t\t\t\t");
        _builder_2.append(".Editor.opened\">");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t\t");
        _builder_2.append("</reference>");
        _builder_2.newLine();
        _builder_2.append("\t\t");
        _builder_2.append("</activeWhen>");
        _builder_2.newLine();
        _builder_2.append("\t");
        _builder_2.append("</handler>");
        _builder_2.newLine();
        _builder_2.append("</extension>");
        _builder_2.newLine();
        _builder_2.append("<extension point=\"org.eclipse.ui.menus\">");
        _builder_2.newLine();
        _builder_2.append("\t");
        _builder_2.append("<menuContribution");
        _builder_2.newLine();
        _builder_2.append("\t\t");
        _builder_2.append("locationURI=\"popup:#TextEditorContext?after=group.edit\">");
        _builder_2.newLine();
        _builder_2.append("\t\t");
        _builder_2.append("<command commandId=\"org.eclipse.xtext.xbase.ui.refactoring.ExtractLocalVariable\"");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("style=\"push\">");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("<visibleWhen checkEnabled=\"false\">");
        _builder_2.newLine();
        _builder_2.append("\t\t\t\t");
        _builder_2.append("<reference");
        _builder_2.newLine();
        _builder_2.append("\t\t\t\t\t");
        _builder_2.append("definitionId=\"");
        _builder_2.append(name, "\t\t\t\t\t");
        _builder_2.append(".Editor.opened\">");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t\t\t");
        _builder_2.append("</reference>");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("</visibleWhen>");
        _builder_2.newLine();
        _builder_2.append("\t\t");
        _builder_2.append("</command>");
        _builder_2.newLine();
        _builder_2.append("\t");
        _builder_2.append("</menuContribution>");
        _builder_2.newLine();
        _builder_2.append("</extension>");
        _builder_2.newLine();
        _builder_2.append("<!-- Open implementation -->");
        _builder_2.newLine();
        _builder_2.append("<extension point=\"org.eclipse.ui.handlers\">");
        _builder_2.newLine();
        _builder_2.append("\t");
        _builder_2.append("<handler");
        _builder_2.newLine();
        _builder_2.append("\t\t");
        _builder_2.append("class=\"");
        TypeReference _eclipsePluginExecutableExtensionFactory_10 = this._xtextGeneratorNaming.getEclipsePluginExecutableExtensionFactory(this.getGrammar());
        _builder_2.append(_eclipsePluginExecutableExtensionFactory_10, "\t\t");
        _builder_2.append(":org.eclipse.xtext.xbase.ui.navigation.OpenImplementationHandler\"");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t");
        _builder_2.append("commandId=\"org.eclipse.xtext.xbase.ui.OpenImplementationCommand\">");
        _builder_2.newLine();
        _builder_2.append("\t\t");
        _builder_2.append("<activeWhen>");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("<reference");
        _builder_2.newLine();
        _builder_2.append("\t\t\t\t");
        _builder_2.append("definitionId=\"");
        _builder_2.append(name, "\t\t\t\t");
        _builder_2.append(".Editor.opened\">");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t\t");
        _builder_2.append("</reference>");
        _builder_2.newLine();
        _builder_2.append("\t\t");
        _builder_2.append("</activeWhen>");
        _builder_2.newLine();
        _builder_2.append("\t");
        _builder_2.append("</handler>");
        _builder_2.newLine();
        _builder_2.append("</extension>");
        _builder_2.newLine();
        _builder_2.append("<extension point=\"org.eclipse.ui.menus\">");
        _builder_2.newLine();
        _builder_2.append("\t");
        _builder_2.append("<menuContribution");
        _builder_2.newLine();
        _builder_2.append("\t\t");
        _builder_2.append("locationURI=\"menu:navigate?after=open.ext4\">");
        _builder_2.newLine();
        _builder_2.append("\t\t");
        _builder_2.append("<command commandId=\"org.eclipse.xtext.xbase.ui.OpenImplementationCommand\">");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("<visibleWhen checkEnabled=\"false\">");
        _builder_2.newLine();
        _builder_2.append("\t\t\t\t");
        _builder_2.append("<reference");
        _builder_2.newLine();
        _builder_2.append("\t\t\t\t\t");
        _builder_2.append("definitionId=\"");
        _builder_2.append(name, "\t\t\t\t\t");
        _builder_2.append(".Editor.opened\">");
        _builder_2.newLineIfNotEmpty();
        _builder_2.append("\t\t\t\t");
        _builder_2.append("</reference>");
        _builder_2.newLine();
        _builder_2.append("\t\t\t");
        _builder_2.append("</visibleWhen>");
        _builder_2.newLine();
        _builder_2.append("\t\t");
        _builder_2.append("</command>");
        _builder_2.newLine();
        _builder_2.append("\t");
        _builder_2.append("</menuContribution>");
        _builder_2.newLine();
        _builder_2.append("</extension>");
        _builder_2.newLine();
        _xblockexpression = _entries_2.add(_builder_2.toString());
    }
    return _xblockexpression;
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) List(java.util.List) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 40 with TypeReference

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

the class XbaseGeneratorFragment2 method doGenerateXtendInferrer.

protected void doGenerateXtendInferrer() {
    final TypeReference firstRuleType = TypeReference.typeRef(GenModelUtil2.getJavaTypeName(IterableExtensions.<AbstractRule>head(this.getLanguage().getGrammar().getRules()).getType().getClassifier(), this.getLanguage().getGrammar().eResource().getResourceSet()));
    TypeReference _jvmModelInferrer = this.getJvmModelInferrer();
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("/**");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* <p>Infers a JVM model from the source model.</p> ");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("*");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* <p>The JVM model should contain all elements that would appear in the Java code ");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* which is generated from the source model. Other models link against the JVM model rather than the source model.</p>     ");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
            _builder.append("class ");
            String _simpleName = XbaseGeneratorFragment2.this.getJvmModelInferrer().getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.xbase.jvmmodel.AbstractModelInferrer");
            _builder.append(_typeRef);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("/**");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("* convenience API to build and initialize JVM types and their members.");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("*/");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@");
            _builder.append(Inject.class, "\t");
            _builder.append(" extension ");
            TypeReference _typeRef_1 = TypeReference.typeRef("org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder");
            _builder.append(_typeRef_1, "\t");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("/**");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("* The dispatch method {@code infer} is called for each instance of the");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("* given element\'s type that is contained in a resource.");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("* ");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("* @param element");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("*            the model to create one or more");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("*            {@link org.eclipse.xtext.common.types.JvmDeclaredType declared");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("*            types} from.");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("* @param acceptor");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("*            each created");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("*            {@link org.eclipse.xtext.common.types.JvmDeclaredType type}");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("*            without a container should be passed to the acceptor in order");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("*            get attached to the current resource. The acceptor\'s");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("*            {@link IJvmDeclaredTypeAcceptor#accept(org.eclipse.xtext.common.types.JvmDeclaredType)");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("*            accept(..)} method takes the constructed empty type for the");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("*            pre-indexing phase. This one is further initialized in the");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("*            indexing phase using the lambda you pass as the last argument.");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("* @param isPreIndexingPhase");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("*            whether the method is called in a pre-indexing phase, i.e.");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("*            when the global index is not yet fully updated. You must not");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("*            rely on linking using the index if isPreIndexingPhase is");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("*            <code>true</code>.");
            _builder.newLine();
            _builder.append("\t ");
            _builder.append("*/");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("def dispatch void infer(");
            _builder.append(firstRuleType, "\t");
            _builder.append(" element, ");
            TypeReference _typeRef_2 = TypeReference.typeRef("org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor");
            _builder.append(_typeRef_2, "\t");
            _builder.append(" acceptor, boolean isPreIndexingPhase) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("// Here you explain how your model is mapped to Java elements, by writing the actual translation code.");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("// An implementation for the initial hello world example could look like this:");
            _builder.newLine();
            _builder.append("// \t\tacceptor.accept(element.toClass(\"my.company.greeting.MyGreetings\")) [");
            _builder.newLine();
            _builder.append("// \t\t\tfor (greeting : element.greetings) {");
            _builder.newLine();
            _builder.append("// \t\t\t\tmembers += greeting.toMethod(\"hello\" + greeting.name, typeRef(String)) [");
            _builder.newLine();
            _builder.append("// \t\t\t\t\tbody = ");
            _builder.append("\'\'\'");
            _builder.newLineIfNotEmpty();
            _builder.append("//\t\t\t\t\t\treturn \"Hello ");
            _builder.append("�");
            _builder.append("greeting.name");
            _builder.append("�");
            _builder.append("\";");
            _builder.newLineIfNotEmpty();
            _builder.append("//\t\t\t\t\t");
            _builder.append("\'\'\'");
            _builder.newLineIfNotEmpty();
            _builder.append("//\t\t\t\t]");
            _builder.newLine();
            _builder.append("//\t\t\t}");
            _builder.newLine();
            _builder.append("//\t\t]");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    this.fileAccessFactory.createXtendFile(_jvmModelInferrer, _client).writeTo(this.getProjectConfig().getRuntime().getSrc());
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) AbstractRule(org.eclipse.xtext.AbstractRule)

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