Search in sources :

Example 21 with TypeReference

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

the class ContentAssistFragment2 method generateGenJavaProposalProvider.

protected GeneratedJavaFileAccess generateGenJavaProposalProvider() {
    GeneratedJavaFileAccess _xblockexpression = null;
    {
        final Set<String> excludedFqnFeatureNames = this.getFQFeatureNamesToExclude(this.getGrammar());
        final HashSet<String> processedNames = CollectionLiterals.<String>newHashSet();
        final Function2<ArrayList<Assignment>, Assignment, ArrayList<Assignment>> _function = (ArrayList<Assignment> candidates, Assignment assignment) -> {
            ArrayList<Assignment> _xblockexpression_1 = null;
            {
                final String fqFeatureName = this.getFQFeatureName(assignment);
                if (((!processedNames.contains(fqFeatureName)) && (!excludedFqnFeatureNames.contains(fqFeatureName)))) {
                    processedNames.add(fqFeatureName);
                    candidates.add(assignment);
                }
                _xblockexpression_1 = candidates;
            }
            return _xblockexpression_1;
        };
        final ArrayList<Assignment> assignments = IterableExtensions.<Assignment, ArrayList<Assignment>>fold(GrammarUtil.containedAssignments(this.getGrammar()), CollectionLiterals.<Assignment>newArrayList(), _function);
        final Function2<ArrayList<AbstractRule>, AbstractRule, ArrayList<AbstractRule>> _function_1 = (ArrayList<AbstractRule> candidates, AbstractRule rule) -> {
            ArrayList<AbstractRule> _xblockexpression_1 = null;
            {
                final String fqnFeatureName = this.getFQFeatureName(rule);
                if (((!processedNames.contains(fqnFeatureName)) && (!excludedFqnFeatureNames.contains(fqnFeatureName)))) {
                    processedNames.add(fqnFeatureName);
                    candidates.add(rule);
                }
                _xblockexpression_1 = candidates;
            }
            return _xblockexpression_1;
        };
        final ArrayList<AbstractRule> remainingRules = IterableExtensions.<AbstractRule, ArrayList<AbstractRule>>fold(this.getGrammar().getRules(), CollectionLiterals.<AbstractRule>newArrayList(), _function_1);
        TypeReference _xifexpression = null;
        boolean _isGenerateStub = this.isGenerateStub();
        if (_isGenerateStub) {
            _xifexpression = this.getGenProposalProviderClass(this.getGrammar());
        } else {
            _xifexpression = this.getProposalProviderClass(this.getGrammar());
        }
        final TypeReference genClass = _xifexpression;
        GeneratedJavaFileAccess _createGeneratedJavaFile = this.fileAccessFactory.createGeneratedJavaFile(genClass);
        final Procedure1<GeneratedJavaFileAccess> _function_2 = (GeneratedJavaFileAccess it) -> {
            final TypeReference superClass = this.getGenProposalProviderSuperClass(this.getGrammar());
            StringConcatenationClient _client = new StringConcatenationClient() {

                @Override
                protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                    _builder.append("/**");
                    _builder.newLine();
                    _builder.append(" ");
                    _builder.append("* Represents a generated, default implementation of superclass {@link ");
                    _builder.append(superClass, " ");
                    _builder.append("}.");
                    _builder.newLineIfNotEmpty();
                    _builder.append(" ");
                    _builder.append("* Methods are dynamically dispatched on the first parameter, i.e., you can override them ");
                    _builder.newLine();
                    _builder.append(" ");
                    _builder.append("* with a more concrete subtype. ");
                    _builder.newLine();
                    _builder.append(" ");
                    _builder.append("*/");
                    _builder.newLine();
                }
            };
            it.setTypeComment(_client);
            StringConcatenationClient _client_1 = new StringConcatenationClient() {

                @Override
                protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                    _builder.append("public ");
                    {
                        boolean _isGenerateStub = ContentAssistFragment2.this.isGenerateStub();
                        if (_isGenerateStub) {
                            _builder.append("abstract ");
                        }
                    }
                    _builder.append("class ");
                    String _simpleName = genClass.getSimpleName();
                    _builder.append(_simpleName);
                    _builder.append(" extends ");
                    _builder.append(superClass);
                    _builder.append(" {");
                    _builder.newLineIfNotEmpty();
                    _builder.newLine();
                    {
                        boolean _isEmpty = assignments.isEmpty();
                        boolean _not = (!_isEmpty);
                        if (_not) {
                            {
                                for (final Assignment assignment : assignments) {
                                    _builder.append("\t");
                                    StringConcatenationClient _handleAssignment = ContentAssistFragment2.this.handleAssignment(assignment);
                                    _builder.append(_handleAssignment, "\t");
                                    _builder.newLineIfNotEmpty();
                                }
                            }
                            _builder.newLine();
                        }
                    }
                    {
                        for (final AbstractRule rule : remainingRules) {
                            _builder.append("\t");
                            _builder.append("public void complete");
                            String _fQFeatureName = ContentAssistFragment2.this.getFQFeatureName(rule);
                            _builder.append(_fQFeatureName, "\t");
                            _builder.append("(");
                            _builder.append(EObject.class, "\t");
                            _builder.append(" model, ");
                            _builder.append(RuleCall.class, "\t");
                            _builder.append(" ruleCall, ");
                            TypeReference _contentAssistContextClass = ContentAssistFragment2.this.getContentAssistContextClass();
                            _builder.append(_contentAssistContextClass, "\t");
                            _builder.append(" context, ");
                            TypeReference _iCompletionProposalAcceptorClass = ContentAssistFragment2.this.getICompletionProposalAcceptorClass();
                            _builder.append(_iCompletionProposalAcceptorClass, "\t");
                            _builder.append(" acceptor) {");
                            _builder.newLineIfNotEmpty();
                            _builder.append("\t");
                            _builder.append("\t");
                            _builder.append("// subclasses may override");
                            _builder.newLine();
                            _builder.append("\t");
                            _builder.append("}");
                            _builder.newLine();
                        }
                    }
                    _builder.append("}");
                    _builder.newLine();
                }
            };
            it.setContent(_client_1);
            it.writeTo(this.getProjectConfig().getEclipsePlugin().getSrcGen());
        };
        _xblockexpression = ObjectExtensions.<GeneratedJavaFileAccess>operator_doubleArrow(_createGeneratedJavaFile, _function_2);
    }
    return _xblockexpression;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) ArrayList(java.util.ArrayList) Function2(org.eclipse.xtext.xbase.lib.Functions.Function2) RuleCall(org.eclipse.xtext.RuleCall) Assignment(org.eclipse.xtext.Assignment) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) EObject(org.eclipse.emf.ecore.EObject) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) AbstractRule(org.eclipse.xtext.AbstractRule) HashSet(java.util.HashSet)

Example 22 with TypeReference

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

the class LabelProviderFragment2 method getDescriptionLabelProviderSuperClass.

protected TypeReference getDescriptionLabelProviderSuperClass(final Grammar g) {
    TypeReference _xifexpression = null;
    boolean _inheritsXbase = this._xbaseUsageDetector.inheritsXbase(g);
    if (_inheritsXbase) {
        _xifexpression = new TypeReference(LabelProviderFragment2.XBASE_DESCRIPTION_LABEL_PROVIDER);
    } else {
        _xifexpression = this.getDefaultDescriptionLabelProviderSuperClass();
    }
    return _xifexpression;
}
Also used : TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 23 with TypeReference

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

the class LabelProviderFragment2 method generateJavaEObjectLabelProvider.

protected void generateJavaEObjectLabelProvider() {
    TypeReference _eObjectLabelProviderClass = this.getEObjectLabelProviderClass(this.getGrammar());
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("/**");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* Provides labels for EObjects.");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* ");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* See https://www.eclipse.org/Xtext/documentation/304_ide_concepts.html#label-provider");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
            _builder.append("public class ");
            String _simpleName = LabelProviderFragment2.this.getEObjectLabelProviderClass(LabelProviderFragment2.this.getGrammar()).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _eObjectLabelProviderSuperClass = LabelProviderFragment2.this.getEObjectLabelProviderSuperClass(LabelProviderFragment2.this.getGrammar());
            _builder.append(_eObjectLabelProviderSuperClass);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@");
            _builder.append(Inject.class, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("public ");
            String _simpleName_1 = LabelProviderFragment2.this.getEObjectLabelProviderClass(LabelProviderFragment2.this.getGrammar()).getSimpleName();
            _builder.append(_simpleName_1, "\t");
            _builder.append("(");
            TypeReference _typeReference = new TypeReference("org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider");
            _builder.append(_typeReference, "\t");
            _builder.append(" delegate) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("super(delegate);");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("// Labels and icons can be computed like this:");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("//\tString text(Greeting ele) {");
            _builder.newLine();
            _builder.append("//\t\treturn \"A greeting to \" + ele.getName();");
            _builder.newLine();
            _builder.append("//\t}");
            _builder.newLine();
            _builder.append("//");
            _builder.newLine();
            _builder.append("//\tString image(Greeting ele) {");
            _builder.newLine();
            _builder.append("//\t\treturn \"Greeting.gif\";");
            _builder.newLine();
            _builder.append("//\t}");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    this.fileAccessFactory.createJavaFile(_eObjectLabelProviderClass, _client).writeTo(this.getProjectConfig().getEclipsePlugin().getSrc());
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 24 with TypeReference

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

the class LabelProviderFragment2 method generateXtendDescriptionLabelProvider.

protected void generateXtendDescriptionLabelProvider() {
    TypeReference _descriptionLabelProviderClass = this.getDescriptionLabelProviderClass(this.getGrammar());
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("/**");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* Provides labels for IEObjectDescriptions and IResourceDescriptions.");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* ");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* See https://www.eclipse.org/Xtext/documentation/304_ide_concepts.html#label-provider");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
            _builder.append("class ");
            String _simpleName = LabelProviderFragment2.this.getDescriptionLabelProviderClass(LabelProviderFragment2.this.getGrammar()).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _descriptionLabelProviderSuperClass = LabelProviderFragment2.this.getDescriptionLabelProviderSuperClass(LabelProviderFragment2.this.getGrammar());
            _builder.append(_descriptionLabelProviderSuperClass);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("// Labels and icons can be computed like this:");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("//\toverride text(IEObjectDescription ele) {");
            _builder.newLine();
            _builder.append("//\t\tele.name.toString");
            _builder.newLine();
            _builder.append("//\t}");
            _builder.newLine();
            _builder.append("//\t ");
            _builder.newLine();
            _builder.append("//\toverride image(IEObjectDescription ele) {");
            _builder.newLine();
            _builder.append("//\t\tele.EClass.name + \'.gif\'");
            _builder.newLine();
            _builder.append("//\t}");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    this.fileAccessFactory.createXtendFile(_descriptionLabelProviderClass, _client).writeTo(this.getProjectConfig().getEclipsePlugin().getSrc());
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 25 with TypeReference

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

the class LabelProviderFragment2 method getEObjectLabelProviderSuperClass.

protected TypeReference getEObjectLabelProviderSuperClass(final Grammar g) {
    TypeReference _xifexpression = null;
    boolean _inheritsXbase = this._xbaseUsageDetector.inheritsXbase(g);
    if (_inheritsXbase) {
        _xifexpression = new TypeReference(LabelProviderFragment2.XBASE_LABEL_PROVIDER);
    } else {
        _xifexpression = this.getDefaultEObjectLabelProviderSuperClass();
    }
    return _xifexpression;
}
Also used : 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