Search in sources :

Example 61 with TypeReference

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

the class XtextAntlrGeneratorFragment2 method generateProductionTokenSource.

public JavaFileAccess generateProductionTokenSource() {
    JavaFileAccess _xblockexpression = null;
    {
        @Extension final GrammarNaming naming = this.productionNaming;
        final JavaFileAccess file = this.fileFactory.createJavaFile(naming.getTokenSourceClass(this.getGrammar()));
        final Function1<TerminalRule, Boolean> _function = (TerminalRule it) -> {
            return Boolean.valueOf(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("BEGIN", "INDENT", "OPEN")).contains(it.getName().toUpperCase()));
        };
        final Iterable<TerminalRule> open = IterableExtensions.<TerminalRule>filter(GrammarUtil.allTerminalRules(this.getGrammar()), _function);
        final Function1<TerminalRule, Boolean> _function_1 = (TerminalRule it) -> {
            return Boolean.valueOf(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("END", "DEDENT", "CLOSE")).contains(it.getName().toUpperCase()));
        };
        final Iterable<TerminalRule> close = IterableExtensions.<TerminalRule>filter(GrammarUtil.allTerminalRules(this.getGrammar()), _function_1);
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("public class ");
                String _simpleName = naming.getTokenSourceClass(XtextAntlrGeneratorFragment2.this.getGrammar()).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                _builder.append(AbstractIndentationTokenSource.class);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                _builder.newLine();
                _builder.append("\t");
                _builder.append("public ");
                String _simpleName_1 = naming.getTokenSourceClass(XtextAntlrGeneratorFragment2.this.getGrammar()).getSimpleName();
                _builder.append(_simpleName_1, "\t");
                _builder.append("(");
                _builder.append(TokenSource.class, "\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("@Override");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("protected boolean shouldSplitTokenImpl(");
                _builder.append(Token.class, "\t");
                _builder.append(" token) {");
                _builder.newLineIfNotEmpty();
                {
                    final Function1<TerminalRule, TerminalRule> _function = (TerminalRule it) -> {
                        return AntlrGrammarGenUtil.<TerminalRule>getOriginalElement(it);
                    };
                    final Function1<TerminalRule, Boolean> _function_1 = (TerminalRule it) -> {
                        String _upperCase = it.getName().toUpperCase();
                        return Boolean.valueOf(Objects.equal(_upperCase, "WS"));
                    };
                    boolean _exists = IterableExtensions.<TerminalRule>exists(ListExtensions.<TerminalRule, TerminalRule>map(GrammarUtil.allTerminalRules(XtextAntlrGeneratorFragment2.this.getGrammar()), _function), _function_1);
                    if (_exists) {
                        _builder.append("\t\t");
                        _builder.append("// TODO Review assumption");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("return token.getType() == ");
                        TypeReference _internalParserClass = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
                        _builder.append(_internalParserClass, "\t\t");
                        _builder.append(".RULE_WS;");
                        _builder.newLineIfNotEmpty();
                    } else {
                        _builder.append("\t\t");
                        _builder.append("// TODO Implement me");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("throw new UnsupportedOperationException(\"Implement me\");");
                        _builder.newLine();
                    }
                }
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@Override");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("protected int getBeginTokenType() {");
                _builder.newLine();
                {
                    int _size = IterableExtensions.size(open);
                    boolean _equals = (_size == 1);
                    if (_equals) {
                        _builder.append("\t\t");
                        _builder.append("// TODO Review assumption");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("return ");
                        TypeReference _internalParserClass_1 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
                        _builder.append(_internalParserClass_1, "\t\t");
                        _builder.append(".");
                        String _ruleName = XtextAntlrGeneratorFragment2.this.grammarUtil.ruleName(IterableExtensions.<TerminalRule>head(open));
                        _builder.append(_ruleName, "\t\t");
                        _builder.append(";");
                        _builder.newLineIfNotEmpty();
                    } else {
                        _builder.append("\t\t");
                        _builder.append("// TODO Implement me");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("throw new UnsupportedOperationException(\"Implement me\");");
                        _builder.newLine();
                    }
                }
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@Override");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("protected int getEndTokenType() {");
                _builder.newLine();
                {
                    int _size_1 = IterableExtensions.size(close);
                    boolean _equals_1 = (_size_1 == 1);
                    if (_equals_1) {
                        _builder.append("\t\t");
                        _builder.append("// TODO Review assumption");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("return ");
                        TypeReference _internalParserClass_2 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
                        _builder.append(_internalParserClass_2, "\t\t");
                        _builder.append(".");
                        String _ruleName_1 = XtextAntlrGeneratorFragment2.this.grammarUtil.ruleName(IterableExtensions.<TerminalRule>head(close));
                        _builder.append(_ruleName_1, "\t\t");
                        _builder.append(";");
                        _builder.newLineIfNotEmpty();
                    } else {
                        _builder.append("\t\t");
                        _builder.append("// TODO Implement me");
                        _builder.newLine();
                        _builder.append("\t\t");
                        _builder.append("throw new UnsupportedOperationException(\"Implement me\");");
                        _builder.newLine();
                    }
                }
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.newLine();
                _builder.append("}");
                _builder.newLine();
            }
        };
        file.setContent(_client);
        _xblockexpression = file;
    }
    return _xblockexpression;
}
Also used : TokenSource(org.antlr.runtime.TokenSource) AbstractIndentationTokenSource(org.eclipse.xtext.parser.antlr.AbstractIndentationTokenSource) AbstractIndentationTokenSource(org.eclipse.xtext.parser.antlr.AbstractIndentationTokenSource) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Token(org.antlr.runtime.Token) ContentAssistGrammarNaming(org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming) GrammarNaming(org.eclipse.xtext.xtext.generator.parser.antlr.GrammarNaming) JavaFileAccess(org.eclipse.xtext.xtext.generator.model.JavaFileAccess) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) TerminalRule(org.eclipse.xtext.TerminalRule)

Example 62 with TypeReference

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

the class XtextAntlrGeneratorFragment2 method addRuntimeBindingsAndImports.

protected void addRuntimeBindingsAndImports() {
    @Extension final GrammarNaming naming = this.productionNaming;
    ManifestAccess _manifest = this.getProjectConfig().getRuntime().getManifest();
    boolean _tripleNotEquals = (_manifest != null);
    if (_tripleNotEquals) {
        ManifestAccess _manifest_1 = this.getProjectConfig().getRuntime().getManifest();
        final Procedure1<ManifestAccess> _function = (ManifestAccess it) -> {
            Set<String> _exportedPackages = it.getExportedPackages();
            String _packageName = naming.getLexerClass(this.getGrammar()).getPackageName();
            String _packageName_1 = naming.getParserClass(this.getGrammar()).getPackageName();
            String _packageName_2 = naming.getInternalParserClass(this.getGrammar()).getPackageName();
            Iterables.<String>addAll(_exportedPackages, Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(_packageName, _packageName_1, _packageName_2)));
            Set<String> _requiredBundles = it.getRequiredBundles();
            _requiredBundles.add("org.antlr.runtime");
        };
        ObjectExtensions.<ManifestAccess>operator_doubleArrow(_manifest_1, _function);
    }
    GuiceModuleAccess.BindingFactory _addTypeToType = new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef(IParser.class), naming.getParserClass(this.getGrammar())).addTypeToType(TypeReference.typeRef(ITokenToStringConverter.class), TypeReference.typeRef(AntlrTokenToStringConverter.class)).addTypeToType(TypeReference.typeRef(IAntlrTokenFileProvider.class), naming.getAntlrTokenFileProviderClass(this.getGrammar())).addTypeToType(naming.getLexerSuperClass(this.getGrammar()), naming.getLexerClass(this.getGrammar())).addTypeToType(TypeReference.typeRef(ITokenDefProvider.class), TypeReference.typeRef(AntlrTokenDefProvider.class));
    TypeReference _lexerClass = naming.getLexerClass(this.getGrammar());
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append(LexerProvider.class);
            _builder.append(".create(");
            TypeReference _lexerClass = naming.getLexerClass(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_lexerClass);
            _builder.append(".class)");
        }
    };
    GuiceModuleAccess.BindingFactory _addTypeToProviderInstance = _addTypeToType.addTypeToProviderInstance(_lexerClass, _client);
    StringConcatenationClient _client_1 = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("binder.bind(");
            _builder.append(Lexer.class);
            _builder.append(".class)");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(".annotatedWith(");
            _builder.append(Names.class, "\t");
            _builder.append(".named(");
            _builder.append(LexerBindings.class, "\t");
            _builder.append(".RUNTIME))");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(".to(");
            TypeReference _lexerClass = naming.getLexerClass(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_lexerClass, "\t");
            _builder.append(".class);");
            _builder.newLineIfNotEmpty();
        }
    };
    final GuiceModuleAccess.BindingFactory rtBindings = _addTypeToProviderInstance.addConfiguredBinding("RuntimeLexer", _client_1);
    boolean _containsUnorderedGroup = this.containsUnorderedGroup(this.getGrammar());
    if (_containsUnorderedGroup) {
        rtBindings.addTypeToType(TypeReference.typeRef(IUnorderedGroupHelper.class), TypeReference.typeRef(UnorderedGroupHelper.class));
    }
    boolean _isIgnoreCase = this.getOptions().isIgnoreCase();
    if (_isIgnoreCase) {
        rtBindings.addTypeToType(TypeReference.typeRef(ITokenSerializer.IKeywordSerializer.class), TypeReference.typeRef(IgnoreCaseKeywordSerializer.class)).addTypeToType(TypeReference.typeRef(IKeywordSerializer.class), TypeReference.typeRef(org.eclipse.xtext.serializer.tokens.IgnoreCaseKeywordSerializer.class)).addTypeToType(TypeReference.typeRef(AbstractIDValueConverter.class), TypeReference.typeRef(IgnoreCaseIDValueConverter.class));
    }
    rtBindings.contributeTo(this.getLanguage().getRuntimeGenModule());
}
Also used : Set(java.util.Set) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) IUnorderedGroupHelper(org.eclipse.xtext.parser.antlr.IUnorderedGroupHelper) ContentAssistGrammarNaming(org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming) GrammarNaming(org.eclipse.xtext.xtext.generator.parser.antlr.GrammarNaming) ManifestAccess(org.eclipse.xtext.xtext.generator.model.ManifestAccess) UnorderedGroupHelper(org.eclipse.xtext.parser.antlr.UnorderedGroupHelper) IUnorderedGroupHelper(org.eclipse.xtext.parser.antlr.IUnorderedGroupHelper) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) GuiceModuleAccess(org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess) ITokenDefProvider(org.eclipse.xtext.parser.antlr.ITokenDefProvider) IgnoreCaseIDValueConverter(org.eclipse.xtext.conversion.impl.IgnoreCaseIDValueConverter) IgnoreCaseKeywordSerializer(org.eclipse.xtext.parsetree.reconstr.impl.IgnoreCaseKeywordSerializer) Extension(org.eclipse.xtext.xbase.lib.Extension) AntlrTokenDefProvider(org.eclipse.xtext.parser.antlr.AntlrTokenDefProvider) IKeywordSerializer(org.eclipse.xtext.serializer.tokens.IKeywordSerializer) AbstractIDValueConverter(org.eclipse.xtext.conversion.impl.AbstractIDValueConverter) IAntlrTokenFileProvider(org.eclipse.xtext.parser.antlr.IAntlrTokenFileProvider) IParser(org.eclipse.xtext.parser.IParser)

Example 63 with TypeReference

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

the class XtextAntlrGeneratorFragment2 method initNameMappings.

/**
 * @since 2.14
 */
protected StringConcatenationClient initNameMappings(final Grammar it) {
    StringConcatenationClient _xblockexpression = null;
    {
        final RuleFilter filter = new RuleFilter();
        filter.setDiscardUnreachableRules(this.getOptions().isSkipUnusedRules());
        final RuleNames ruleNames = RuleNames.getRuleNames(it, true);
        final Grammar flattened = new FlattenedGrammarAccess(ruleNames, filter).getFlattenedGrammar();
        final Set<AbstractElement> seenElements = CollectionLiterals.<AbstractElement>newHashSet();
        Collection<? extends AbstractElement> _allAlternatives = GrammarUtil.getAllAlternatives(flattened);
        Collection<? extends AbstractElement> _allGroups = GrammarUtil.getAllGroups(flattened);
        Iterable<AbstractElement> _plus = Iterables.<AbstractElement>concat(_allAlternatives, _allGroups);
        Collection<? extends AbstractElement> _allAssignments = GrammarUtil.getAllAssignments(flattened);
        Iterable<AbstractElement> _plus_1 = Iterables.<AbstractElement>concat(_plus, _allAssignments);
        Collection<? extends AbstractElement> _allUnorderedGroups = GrammarUtil.getAllUnorderedGroups(flattened);
        final Function1<AbstractElement, Boolean> _function = (AbstractElement it_1) -> {
            return Boolean.valueOf(seenElements.add(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(it_1)));
        };
        final List<AbstractElement> elements = IterableExtensions.<AbstractElement>toList(IterableExtensions.<AbstractElement>filter(Iterables.<AbstractElement>filter(Iterables.<AbstractElement>concat(_plus_1, _allUnorderedGroups), AbstractElement.class), _function));
        final List<List<AbstractElement>> partitions = Lists.<AbstractElement>partition(elements, 2500);
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("@");
                _builder.append(Singleton.class);
                _builder.newLineIfNotEmpty();
                _builder.append("public static final class NameMappings {");
                _builder.newLine();
                _builder.append("\t");
                _builder.newLine();
                {
                    int _size = partitions.size();
                    boolean _greaterThan = (_size > 1);
                    if (_greaterThan) {
                        {
                            Iterable<Pair<Integer, List<AbstractElement>>> _indexed = IterableExtensions.<List<AbstractElement>>indexed(partitions);
                            for (final Pair<Integer, List<AbstractElement>> partition : _indexed) {
                                _builder.append("\t");
                                _builder.append("private static final class Init");
                                Integer _key = partition.getKey();
                                _builder.append(_key, "\t");
                                _builder.append(" {");
                                _builder.newLineIfNotEmpty();
                                _builder.append("\t");
                                _builder.append("\t");
                                _builder.append("private static void doInit(");
                                _builder.append(ImmutableMap.class, "\t\t");
                                _builder.append(".Builder<");
                                _builder.append(AbstractElement.class, "\t\t");
                                _builder.append(", ");
                                _builder.append(String.class, "\t\t");
                                _builder.append("> builder, ");
                                TypeReference _grammarAccess = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
                                _builder.append(_grammarAccess, "\t\t");
                                _builder.append(" grammarAccess) {");
                                _builder.newLineIfNotEmpty();
                                _builder.append("\t");
                                _builder.append("\t\t");
                                StringConcatenationClient _initNameMappings = XtextAntlrGeneratorFragment2.this.initNameMappings(partition.getValue());
                                _builder.append(_initNameMappings, "\t\t\t");
                                _builder.newLineIfNotEmpty();
                                _builder.append("\t");
                                _builder.append("\t");
                                _builder.append("}");
                                _builder.newLine();
                                _builder.append("\t");
                                _builder.append("}");
                                _builder.newLine();
                                _builder.append("\t");
                                _builder.newLine();
                            }
                        }
                    }
                }
                _builder.append("\t");
                _builder.append("private final ");
                _builder.append(Map.class, "\t");
                _builder.append("<");
                _builder.append(AbstractElement.class, "\t");
                _builder.append(", ");
                _builder.append(String.class, "\t");
                _builder.append("> mappings;");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@");
                _builder.append(Inject.class, "\t");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("public NameMappings(");
                TypeReference _grammarAccess_1 = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
                _builder.append(_grammarAccess_1, "\t");
                _builder.append(" grammarAccess) {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append(ImmutableMap.class, "\t\t");
                _builder.append(".Builder<");
                _builder.append(AbstractElement.class, "\t\t");
                _builder.append(", ");
                _builder.append(String.class, "\t\t");
                _builder.append("> builder = ");
                _builder.append(ImmutableMap.class, "\t\t");
                _builder.append(".builder();");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append("init(builder, grammarAccess);");
                _builder.newLine();
                _builder.append("\t\t");
                _builder.append("this.mappings = builder.build();");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.append("\t");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("public ");
                _builder.append(String.class, "\t");
                _builder.append(" getRuleName(");
                _builder.append(AbstractElement.class, "\t");
                _builder.append(" element) {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append("return mappings.get(element);");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.append("\t");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("private static void init(");
                _builder.append(ImmutableMap.class, "\t");
                _builder.append(".Builder<");
                _builder.append(AbstractElement.class, "\t");
                _builder.append(", ");
                _builder.append(String.class, "\t");
                _builder.append("> builder, ");
                TypeReference _grammarAccess_2 = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
                _builder.append(_grammarAccess_2, "\t");
                _builder.append(" grammarAccess) {");
                _builder.newLineIfNotEmpty();
                {
                    int _size_1 = partitions.size();
                    boolean _greaterThan_1 = (_size_1 > 1);
                    if (_greaterThan_1) {
                        {
                            Iterable<Pair<Integer, List<AbstractElement>>> _indexed_1 = IterableExtensions.<List<AbstractElement>>indexed(partitions);
                            for (final Pair<Integer, List<AbstractElement>> partition_1 : _indexed_1) {
                                _builder.append("\t\t");
                                _builder.append("Init");
                                Integer _key_1 = partition_1.getKey();
                                _builder.append(_key_1, "\t\t");
                                _builder.append(".doInit(builder, grammarAccess);");
                                _builder.newLineIfNotEmpty();
                            }
                        }
                    } else {
                        {
                            for (final List<AbstractElement> partition_2 : partitions) {
                                _builder.append("\t\t");
                                StringConcatenationClient _initNameMappings_1 = XtextAntlrGeneratorFragment2.this.initNameMappings(partition_2);
                                _builder.append(_initNameMappings_1, "\t\t");
                                _builder.newLineIfNotEmpty();
                            }
                        }
                    }
                }
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.append("}");
                _builder.newLine();
                _builder.newLine();
                _builder.append("@");
                _builder.append(Inject.class);
                _builder.newLineIfNotEmpty();
                _builder.append("private NameMappings nameMappings;");
                _builder.newLine();
            }
        };
        _xblockexpression = _client;
    }
    return _xblockexpression;
}
Also used : Inject(com.google.inject.Inject) Set(java.util.Set) RuleNames(org.eclipse.xtext.xtext.RuleNames) AbstractElement(org.eclipse.xtext.AbstractElement) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Grammar(org.eclipse.xtext.Grammar) AntlrGrammar(org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammar) FlattenedGrammarAccess(org.eclipse.xtext.xtext.FlattenedGrammarAccess) ImmutableMap(com.google.common.collect.ImmutableMap) Singleton(com.google.inject.Singleton) Collection(java.util.Collection) RuleFilter(org.eclipse.xtext.xtext.RuleFilter) List(java.util.List) ArrayList(java.util.ArrayList) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 64 with TypeReference

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

the class ResourceFactoryFragment2 method generate.

@Override
public void generate() {
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append(IResourceFactory.class);
            _builder.append(" resourceFactory = injector.getInstance(");
            _builder.append(IResourceFactory.class);
            _builder.append(".class);");
            _builder.newLineIfNotEmpty();
            _builder.append(IResourceServiceProvider.class);
            _builder.append(" serviceProvider = injector.getInstance(");
            _builder.append(IResourceServiceProvider.class);
            _builder.append(".class);");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            {
                List<String> _fileExtensions = ResourceFactoryFragment2.this.getLanguage().getFileExtensions();
                for (final String fileExtension : _fileExtensions) {
                    _builder.append(Resource.class);
                    _builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(\"");
                    _builder.append(fileExtension);
                    _builder.append("\", resourceFactory);");
                    _builder.newLineIfNotEmpty();
                    _builder.append(IResourceServiceProvider.class);
                    _builder.append(".Registry.INSTANCE.getExtensionToFactoryMap().put(\"");
                    _builder.append(fileExtension);
                    _builder.append("\", serviceProvider);");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    };
    this.getLanguage().getRuntimeGenSetup().getRegistrations().add(_client);
    IBundleProjectConfig _eclipsePlugin = this.getProjectConfig().getEclipsePlugin();
    PluginXmlAccess _pluginXml = null;
    if (_eclipsePlugin != null) {
        _pluginXml = _eclipsePlugin.getPluginXml();
    }
    boolean _tripleNotEquals = (_pluginXml != null);
    if (_tripleNotEquals) {
        List<CharSequence> _entries = this.getProjectConfig().getEclipsePlugin().getPluginXml().getEntries();
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("<!-- adding resource factories -->");
        _builder.newLine();
        {
            List<String> _fileExtensions = this.getLanguage().getFileExtensions();
            for (final String fileExtension : _fileExtensions) {
                _builder.append("<extension");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("point=\"org.eclipse.emf.ecore.extension_parser\">");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("<parser");
                _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.resource.IResourceFactory\"");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append("type=\"");
                _builder.append(fileExtension, "\t\t");
                _builder.append("\">");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("</parser>");
                _builder.newLine();
                _builder.append("</extension>");
                _builder.newLine();
                _builder.append("<extension point=\"org.eclipse.xtext.extension_resourceServiceProvider\">");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("<resourceServiceProvider");
                _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.ui.resource.IResourceUIServiceProvider\"");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append("uriExtension=\"");
                _builder.append(fileExtension, "\t\t");
                _builder.append("\">");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("</resourceServiceProvider>");
                _builder.newLine();
                _builder.append("</extension>");
                _builder.newLine();
            }
        }
        _entries.add(_builder.toString());
    }
}
Also used : IBundleProjectConfig(org.eclipse.xtext.xtext.generator.model.project.IBundleProjectConfig) PluginXmlAccess(org.eclipse.xtext.xtext.generator.model.PluginXmlAccess) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Resource(org.eclipse.emf.ecore.resource.Resource) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) List(java.util.List) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 65 with TypeReference

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

the class ImportNamespacesScopingFragment2 method generateJavaScopeProvider.

protected void generateJavaScopeProvider() {
    TypeReference _scopeProviderClass = this.getScopeProviderClass(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 scoping description.");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* ");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* on how and when to use it.");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
            _builder.append("public class ");
            String _simpleName = ImportNamespacesScopingFragment2.this.getScopeProviderClass(ImportNamespacesScopingFragment2.this.getGrammar()).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _abstractScopeProviderClass = ImportNamespacesScopingFragment2.this.getAbstractScopeProviderClass(ImportNamespacesScopingFragment2.this.getGrammar());
            _builder.append(_abstractScopeProviderClass);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    this.fileAccessFactory.createJavaFile(_scopeProviderClass, _client).writeTo(this.getProjectConfig().getRuntime().getSrc());
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Aggregations

TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)154 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)119 GuiceModuleAccess (org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess)27 GeneratedJavaFileAccess (org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess)24 Grammar (org.eclipse.xtext.Grammar)23 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)21 ManifestAccess (org.eclipse.xtext.xtext.generator.model.ManifestAccess)17 List (java.util.List)14 Set (java.util.Set)12 Test (org.junit.Test)12 JavaFileAccess (org.eclipse.xtext.xtext.generator.model.JavaFileAccess)11 PluginXmlAccess (org.eclipse.xtext.xtext.generator.model.PluginXmlAccess)11 IClassAnnotation (org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation)10 AbstractRule (org.eclipse.xtext.AbstractRule)9 SuppressWarningsAnnotation (org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation)8 IBundleProjectConfig (org.eclipse.xtext.xtext.generator.model.project.IBundleProjectConfig)8 ContentAssistGrammarNaming (org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming)7 EObject (org.eclipse.emf.ecore.EObject)6 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)6 ArrayList (java.util.ArrayList)5