Search in sources :

Example 66 with TypeReference

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

the class ImportNamespacesScopingFragment2 method getDelegateScopeProvider.

protected TypeReference getDelegateScopeProvider() {
    TypeReference _xifexpression = null;
    boolean _inheritsXbase = this._xbaseUsageDetector.inheritsXbase(this.getLanguage().getGrammar());
    if (_inheritsXbase) {
        _xifexpression = TypeReference.typeRef("org.eclipse.xtext.xbase.scoping.XImportSectionNamespaceScopeProvider");
    } else {
        _xifexpression = TypeReference.typeRef(ImportedNamespaceAwareLocalScopeProvider.class);
    }
    return _xifexpression;
}
Also used : ImportedNamespaceAwareLocalScopeProvider(org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 67 with TypeReference

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

the class ImportNamespacesScopingFragment2 method getDefaultScopeProviderSuperClass.

protected TypeReference getDefaultScopeProviderSuperClass() {
    TypeReference _xifexpression = null;
    boolean _inheritsXbase = this._xbaseUsageDetector.inheritsXbase(this.getLanguage().getGrammar());
    if (_inheritsXbase) {
        _xifexpression = TypeReference.typeRef("org.eclipse.xtext.xbase.scoping.batch.XbaseBatchScopeProvider");
    } else {
        _xifexpression = TypeReference.typeRef(DelegatingScopeProvider.class);
    }
    return _xifexpression;
}
Also used : TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) DelegatingScopeProvider(org.eclipse.xtext.scoping.impl.DelegatingScopeProvider)

Example 68 with TypeReference

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

the class ImportNamespacesScopingFragment2 method generateGenScopeProvider.

protected void generateGenScopeProvider() {
    TypeReference _xifexpression = null;
    boolean _isGenerateStub = this.isGenerateStub();
    if (_isGenerateStub) {
        _xifexpression = this.getAbstractScopeProviderClass(this.getGrammar());
    } else {
        _xifexpression = this.getScopeProviderClass(this.getGrammar());
    }
    final TypeReference genClass = _xifexpression;
    final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(genClass);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public ");
            {
                boolean _isGenerateStub = ImportNamespacesScopingFragment2.this.isGenerateStub();
                if (_isGenerateStub) {
                    _builder.append("abstract ");
                }
            }
            _builder.append("class ");
            String _simpleName = genClass.getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _scopeProviderSuperClass = ImportNamespacesScopingFragment2.this.getScopeProviderSuperClass(ImportNamespacesScopingFragment2.this.getGrammar());
            _builder.append(_scopeProviderSuperClass);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.append("}");
            _builder.newLine();
        }
    };
    file.setContent(_client);
    file.writeTo(this.getProjectConfig().getRuntime().getSrcGen());
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 69 with TypeReference

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

the class SerializerFragment2 method generateSyntacticSequencer.

protected void generateSyntacticSequencer() {
    boolean _isGenerateXtendStub = this.isGenerateXtendStub();
    if (_isGenerateXtendStub) {
        TypeReference _syntacticSequencerClass = this.getSyntacticSequencerClass(this.getGrammar());
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("class ");
                String _simpleName = SerializerFragment2.this.getSyntacticSequencerClass(SerializerFragment2.this.getGrammar()).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                TypeReference _abstractSyntacticSequencerClass = SerializerFragment2.this.getAbstractSyntacticSequencerClass(SerializerFragment2.this.getGrammar());
                _builder.append(_abstractSyntacticSequencerClass);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                {
                    if (SerializerFragment2.this.detectSyntheticTerminals) {
                        {
                            final Function1<TerminalRule, Boolean> _function = (TerminalRule it) -> {
                                return Boolean.valueOf(SerializerFragment2.this.syntheticTerminalDetector.isSyntheticTerminalRule(it));
                            };
                            Iterable<TerminalRule> _filter = IterableExtensions.<TerminalRule>filter(GrammarUtil.allTerminalRules(SerializerFragment2.this.getGrammar()), _function);
                            for (final TerminalRule rule : _filter) {
                                _builder.append("\t");
                                _builder.newLine();
                                _builder.append("\t");
                                _builder.append("/**");
                                _builder.newLine();
                                _builder.append("\t");
                                _builder.append(" ");
                                _builder.append("* Stub implementation for a synthetic terminal rule. Defaults to the empty string.");
                                _builder.newLine();
                                _builder.append("\t");
                                _builder.append(" ");
                                _builder.append("*/");
                                _builder.newLine();
                                _builder.append("\t");
                                _builder.append("// TODO review the concrete syntax for the terminal");
                                _builder.newLine();
                                _builder.append("\t");
                                _builder.append("override ");
                                CharSequence _unassignedCalledTokenRuleName = SerializerFragment2.this.unassignedCalledTokenRuleName(rule);
                                _builder.append(_unassignedCalledTokenRuleName, "\t");
                                _builder.append("(");
                                _builder.append(EObject.class, "\t");
                                _builder.append(" semanticObject, ");
                                _builder.append(RuleCall.class, "\t");
                                _builder.append(" ruleCall, ");
                                _builder.append(INode.class, "\t");
                                _builder.append(" node) {");
                                _builder.newLineIfNotEmpty();
                                _builder.append("\t");
                                _builder.append("\t");
                                _builder.append("return \'\'");
                                _builder.newLine();
                                _builder.append("\t");
                                _builder.append("}");
                                _builder.newLine();
                            }
                        }
                    }
                }
                _builder.append("}");
                _builder.newLine();
            }
        };
        this.fileAccessFactory.createXtendFile(_syntacticSequencerClass, _client).writeTo(this.getProjectConfig().getRuntime().getSrc());
    } else {
        TypeReference _syntacticSequencerClass_1 = this.getSyntacticSequencerClass(this.getGrammar());
        StringConcatenationClient _client_1 = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("public class ");
                String _simpleName = SerializerFragment2.this.getSyntacticSequencerClass(SerializerFragment2.this.getGrammar()).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                TypeReference _abstractSyntacticSequencerClass = SerializerFragment2.this.getAbstractSyntacticSequencerClass(SerializerFragment2.this.getGrammar());
                _builder.append(_abstractSyntacticSequencerClass);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                {
                    if (SerializerFragment2.this.detectSyntheticTerminals) {
                        {
                            final Function1<TerminalRule, Boolean> _function = (TerminalRule it) -> {
                                return Boolean.valueOf(SerializerFragment2.this.syntheticTerminalDetector.isSyntheticTerminalRule(it));
                            };
                            Iterable<TerminalRule> _filter = IterableExtensions.<TerminalRule>filter(GrammarUtil.allTerminalRules(SerializerFragment2.this.getGrammar()), _function);
                            for (final TerminalRule rule : _filter) {
                                _builder.append("\t");
                                _builder.newLine();
                                _builder.append("\t");
                                _builder.append("/**");
                                _builder.newLine();
                                _builder.append("\t");
                                _builder.append(" ");
                                _builder.append("* Stub implementation for a synthetic terminal rule. Defaults to the empty string.");
                                _builder.newLine();
                                _builder.append("\t");
                                _builder.append(" ");
                                _builder.append("*/");
                                _builder.newLine();
                                _builder.append("\t");
                                _builder.append("// TODO review the concrete syntax for the terminal");
                                _builder.newLine();
                                _builder.append("\t");
                                _builder.append("@Override");
                                _builder.newLine();
                                _builder.append("\t");
                                _builder.append("public String ");
                                CharSequence _unassignedCalledTokenRuleName = SerializerFragment2.this.unassignedCalledTokenRuleName(rule);
                                _builder.append(_unassignedCalledTokenRuleName, "\t");
                                _builder.append("(");
                                _builder.append(EObject.class, "\t");
                                _builder.append(" semanticObject, ");
                                _builder.append(RuleCall.class, "\t");
                                _builder.append(" ruleCall, ");
                                _builder.append(INode.class, "\t");
                                _builder.append(" node) {");
                                _builder.newLineIfNotEmpty();
                                _builder.append("\t");
                                _builder.append("\t");
                                _builder.append("return \"\";");
                                _builder.newLine();
                                _builder.append("\t");
                                _builder.append("}");
                                _builder.newLine();
                            }
                        }
                    }
                }
                _builder.append("}");
                _builder.newLine();
            }
        };
        this.fileAccessFactory.createJavaFile(_syntacticSequencerClass_1, _client_1).writeTo(this.getProjectConfig().getRuntime().getSrc());
    }
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) TerminalRule(org.eclipse.xtext.TerminalRule)

Example 70 with TypeReference

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

the class SerializerFragment2 method generateAbstractSyntacticSequencer.

protected void generateAbstractSyntacticSequencer() {
    TypeReference _xifexpression = null;
    boolean _isGenerateStub = this.isGenerateStub();
    if (_isGenerateStub) {
        _xifexpression = this.getAbstractSyntacticSequencerClass(this.getGrammar());
    } else {
        _xifexpression = this.getSyntacticSequencerClass(this.getGrammar());
    }
    final TypeReference clazz = _xifexpression;
    final GeneratedJavaFileAccess javaFile = this.fileAccessFactory.createGeneratedJavaFile(clazz);
    javaFile.setResourceSet(this.getLanguage().getResourceSet());
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public ");
            {
                boolean _isGenerateStub = SerializerFragment2.this.isGenerateStub();
                if (_isGenerateStub) {
                    _builder.append("abstract ");
                }
            }
            _builder.append("class ");
            String _simpleName = clazz.getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            _builder.append(AbstractSyntacticSequencer.class);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected ");
            TypeReference _grammarAccess = SerializerFragment2.this._grammarAccessExtensions.getGrammarAccess(SerializerFragment2.this.getGrammar());
            _builder.append(_grammarAccess, "\t");
            _builder.append(" grammarAccess;");
            _builder.newLineIfNotEmpty();
            {
                List<EqualAmbiguousTransitions> _allAmbiguousTransitionsBySyntax = SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax();
                for (final EqualAmbiguousTransitions group : _allAmbiguousTransitionsBySyntax) {
                    _builder.append("\t");
                    _builder.append("protected ");
                    TypeReference _typeReference = new TypeReference("org.eclipse.xtext.serializer.analysis", "GrammarAlias.AbstractElementAlias");
                    _builder.append(_typeReference, "\t");
                    _builder.append(" match_");
                    String _identifier = group.getIdentifier();
                    _builder.append(_identifier, "\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@");
            _builder.append(Inject.class, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("protected void init(");
            _builder.append(IGrammarAccess.class, "\t");
            _builder.append(" access) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("grammarAccess = (");
            TypeReference _grammarAccess_1 = SerializerFragment2.this._grammarAccessExtensions.getGrammarAccess(SerializerFragment2.this.getGrammar());
            _builder.append(_grammarAccess_1, "\t\t");
            _builder.append(") access;");
            _builder.newLineIfNotEmpty();
            {
                List<EqualAmbiguousTransitions> _allAmbiguousTransitionsBySyntax_1 = SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax();
                for (final EqualAmbiguousTransitions group_1 : _allAmbiguousTransitionsBySyntax_1) {
                    _builder.append("\t\t");
                    _builder.append("match_");
                    String _identifier_1 = group_1.getIdentifier();
                    _builder.append(_identifier_1, "\t\t");
                    _builder.append(" = ");
                    StringConcatenationClient _elementAliasToConstructor = SerializerFragment2.this._syntacticSequencerExtensions.elementAliasToConstructor(group_1.getElementAlias());
                    _builder.append(_elementAliasToConstructor, "\t\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            StringConcatenationClient _genGetUnassignedRuleCallTokens = SerializerFragment2.this.genGetUnassignedRuleCallTokens();
            _builder.append(_genGetUnassignedRuleCallTokens, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.newLine();
            {
                List<AbstractRule> _unassignedCalledTokenRules = SerializerFragment2.this.unassignedCalledTokenRules();
                boolean _hasElements = false;
                for (final AbstractRule rule : _unassignedCalledTokenRules) {
                    if (!_hasElements) {
                        _hasElements = true;
                    } else {
                        _builder.appendImmediate("\n", "\t");
                    }
                    _builder.append("\t");
                    StringConcatenationClient _genGetUnassignedRuleCallToken = SerializerFragment2.this.genGetUnassignedRuleCallToken(rule);
                    _builder.append(_genGetUnassignedRuleCallToken, "\t");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            StringConcatenationClient _genEmitUnassignedTokens = SerializerFragment2.this.genEmitUnassignedTokens();
            _builder.append(_genEmitUnassignedTokens, "\t");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            {
                List<EqualAmbiguousTransitions> _allAmbiguousTransitionsBySyntax_2 = SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax();
                for (final EqualAmbiguousTransitions group_2 : _allAmbiguousTransitionsBySyntax_2) {
                    _builder.append("\t");
                    _builder.append("/**");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append(" ");
                    _builder.append("* Ambiguous syntax:");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append(" ");
                    _builder.append("*     ");
                    String _replace = group_2.getElementAlias().toString().replace("\n", "\n *     ");
                    _builder.append(_replace, "\t ");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append(" ");
                    _builder.append("*");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append(" ");
                    _builder.append("* This ambiguous syntax occurs at:");
                    _builder.newLine();
                    {
                        final Function1<ISyntacticSequencerPDAProvider.ISynTransition, String> _function = (ISyntacticSequencerPDAProvider.ISynTransition it) -> {
                            return group_2.ambiguityInsideTransition(it).trim();
                        };
                        List<String> _sort = IterableExtensions.<String>sort(IterableExtensions.<String>toSet(ListExtensions.<ISyntacticSequencerPDAProvider.ISynTransition, String>map(group_2.getTransitions(), _function)));
                        for (final String trans : _sort) {
                            _builder.append("\t");
                            _builder.append(" ");
                            _builder.append("*     ");
                            String _replace_1 = trans.toString().replace("\n", "\n*     ");
                            _builder.append(_replace_1, "\t ");
                            _builder.newLineIfNotEmpty();
                        }
                    }
                    _builder.append("\t");
                    _builder.append(" ");
                    _builder.append("*/");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("protected void emit_");
                    String _identifier_2 = group_2.getIdentifier();
                    _builder.append(_identifier_2, "\t");
                    _builder.append("(");
                    _builder.append(EObject.class, "\t");
                    _builder.append(" semanticObject, ");
                    _builder.append(ISyntacticSequencerPDAProvider.ISynNavigable.class, "\t");
                    _builder.append(" transition, ");
                    _builder.append(List.class, "\t");
                    _builder.append("<");
                    _builder.append(INode.class, "\t");
                    _builder.append("> nodes) {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("acceptNodes(transition, nodes);");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("}");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.newLine();
                }
            }
            _builder.append("}");
            _builder.newLine();
        }
    };
    javaFile.setContent(_client);
    List<IClassAnnotation> _annotations = javaFile.getAnnotations();
    SuppressWarningsAnnotation _suppressWarningsAnnotation = new SuppressWarningsAnnotation();
    _annotations.add(_suppressWarningsAnnotation);
    javaFile.writeTo(this.getProjectConfig().getRuntime().getSrcGen());
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) SuppressWarningsAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation) EqualAmbiguousTransitions(org.eclipse.xtext.xtext.generator.serializer.EqualAmbiguousTransitions) ISyntacticSequencerPDAProvider(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider) EObject(org.eclipse.emf.ecore.EObject) IClassAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) List(java.util.List) 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