Search in sources :

Example 11 with Extension

use of org.eclipse.xtext.xbase.lib.Extension in project xtext-core by eclipse.

the class XtextAntlrGeneratorFragment2 method generateContentAssistGrammar.

protected void generateContentAssistGrammar() {
    @Extension final ContentAssistGrammarNaming naming = this.contentAssistNaming;
    final IXtextGeneratorFileSystemAccess fsa = this.getProjectConfig().getGenericIde().getSrcGen();
    this.contentAssistGenerator.generate(this.getGrammar(), this.getOptions(), fsa);
    this.runAntlr(naming.getParserGrammar(this.getGrammar()), naming.getLexerGrammar(this.getGrammar()), fsa);
    this.simplifyUnorderedGroupPredicatesIfRequired(this.getGrammar(), fsa, naming.getInternalParserClass(this.getGrammar()));
    this.splitParserAndLexerIfEnabled(fsa, naming.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
    this.normalizeTokens(fsa, naming.getLexerGrammar(this.getGrammar()).getTokensFileName());
    this.suppressWarnings(fsa, naming.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
    this.normalizeLineDelimiters(fsa, naming.getLexerClass(this.getGrammar()), naming.getInternalParserClass(this.getGrammar()));
    if (this.removeBacktrackingGuards) {
        this.removeBackTrackingGuards(fsa, naming.getInternalParserClass(this.getGrammar()), this.lookaheadThreshold);
    }
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) ContentAssistGrammarNaming(org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming) IXtextGeneratorFileSystemAccess(org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess)

Example 12 with Extension

use of org.eclipse.xtext.xbase.lib.Extension in project xtext-core by eclipse.

the class XtextAntlrGeneratorFragment2 method generateContentAssistParser.

public JavaFileAccess generateContentAssistParser() {
    @Extension final ContentAssistGrammarNaming naming = this.contentAssistNaming;
    final GeneratedJavaFileAccess file = this.fileFactory.createGeneratedJavaFile(naming.getParserClass(this.getGrammar()));
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _simpleName = naming.getParserClass(XtextAntlrGeneratorFragment2.this.getGrammar()).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _parserSuperClass = naming.getParserSuperClass(XtextAntlrGeneratorFragment2.this.getGrammar(), XtextAntlrGeneratorFragment2.this.partialParsing);
            _builder.append(_parserSuperClass);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            StringConcatenationClient _initNameMappings = XtextAntlrGeneratorFragment2.this.initNameMappings(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_initNameMappings, "\t");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@");
            _builder.append(Inject.class, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("private ");
            TypeReference _grammarAccess = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_grammarAccess, "\t");
            _builder.append(" grammarAccess;");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected ");
            TypeReference _internalParserClass = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_internalParserClass, "\t");
            _builder.append(" createParser() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            TypeReference _internalParserClass_1 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_internalParserClass_1, "\t\t");
            _builder.append(" result = new ");
            TypeReference _internalParserClass_2 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_internalParserClass_2, "\t\t");
            _builder.append("(null);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("result.setGrammarAccess(grammarAccess);");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return result;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            {
                boolean _hasSyntheticTerminalRule = XtextAntlrGeneratorFragment2.this.hasSyntheticTerminalRule();
                if (_hasSyntheticTerminalRule) {
                    _builder.append("\t");
                    _builder.append("@Override");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("protected ");
                    _builder.append(TokenSource.class, "\t");
                    _builder.append(" createLexer(");
                    _builder.append(CharStream.class, "\t");
                    _builder.append(" stream) {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("return new ");
                    TypeReference _tokenSourceClass = naming.getTokenSourceClass(XtextAntlrGeneratorFragment2.this.getGrammar());
                    _builder.append(_tokenSourceClass, "\t\t");
                    _builder.append("(super.createLexer(stream));");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("}");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.newLine();
                }
            }
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected String getRuleName(");
            _builder.append(AbstractElement.class, "\t");
            _builder.append(" element) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("return nameMappings.getRuleName(element);");
            _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 String[] getInitialHiddenTokens() {");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return new String[] { ");
            {
                List<String> _initialHiddenTokens = XtextAntlrGeneratorFragment2.this.grammarUtil.initialHiddenTokens(XtextAntlrGeneratorFragment2.this.getGrammar());
                boolean _hasElements = false;
                for (final String hidden : _initialHiddenTokens) {
                    if (!_hasElements) {
                        _hasElements = true;
                    } else {
                        _builder.appendImmediate(", ", "\t\t");
                    }
                    _builder.append("\"");
                    _builder.append(hidden, "\t\t");
                    _builder.append("\"");
                }
            }
            _builder.append(" };");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public ");
            TypeReference _grammarAccess_1 = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_grammarAccess_1, "\t");
            _builder.append(" getGrammarAccess() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("return this.grammarAccess;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public void setGrammarAccess(");
            TypeReference _grammarAccess_2 = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_grammarAccess_2, "\t");
            _builder.append(" grammarAccess) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("this.grammarAccess = grammarAccess;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public NameMappings getNameMappings() {");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return nameMappings;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public void setNameMappings(NameMappings nameMappings) {");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("this.nameMappings = nameMappings;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    file.setContent(_client);
    return file;
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) TokenSource(org.antlr.runtime.TokenSource) AbstractIndentationTokenSource(org.eclipse.xtext.parser.antlr.AbstractIndentationTokenSource) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) ContentAssistGrammarNaming(org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) List(java.util.List) ArrayList(java.util.ArrayList) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) CharStream(org.antlr.runtime.CharStream)

Example 13 with Extension

use of org.eclipse.xtext.xbase.lib.Extension 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 14 with Extension

use of org.eclipse.xtext.xbase.lib.Extension in project xtext-core by eclipse.

the class DebugGraphGenerator method generateDebugGraphs.

public Iterable<Pair<String, String>> generateDebugGraphs() {
    final ArrayList<Pair<String, String>> result = CollectionLiterals.<Pair<String, String>>newArrayList();
    @Extension final NamedSerializationContextProvider names = new NamedSerializationContextProvider(this.grammar);
    final String dir_context = this.directory("context");
    final String dir_context_type = this.directory("context_type");
    final String dir_syntactic_sequencer = this.directory("syntactic_sequencer");
    final String dir_semantic_sequencer = this.directory("semantic_sequencer");
    List<NamedSerializationContexts<Pda<ISerState, RuleCall>>> _namedContexts = names.<Pda<ISerState, RuleCall>>getNamedContexts(this.contextPDAProvider.getContextPDAs(this.grammar));
    for (final NamedSerializationContexts<Pda<ISerState, RuleCall>> e : _namedContexts) {
        {
            String _name = e.getName();
            String _plus = (dir_context + _name);
            String _plus_1 = (_plus + ".dot");
            String _drawSafe = this.drawSafe(this.pdaToDot, e.getValue());
            Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
            result.add(_mappedTo);
            String _name_1 = e.getName();
            String _plus_2 = (dir_context + _name_1);
            String _plus_3 = (_plus_2 + ".txt");
            String _join = IterableExtensions.join(e.getContexts(), "\n");
            Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
            result.add(_mappedTo_1);
        }
    }
    List<NamedSerializationContexts<Pda<ISerState, RuleCall>>> _namedContexts_1 = names.<Pda<ISerState, RuleCall>>getNamedContexts(this.contextTypePDAProvider.getContextTypePDAs(this.grammar));
    for (final NamedSerializationContexts<Pda<ISerState, RuleCall>> e_1 : _namedContexts_1) {
        {
            String _name = e_1.getName();
            String _plus = (dir_context_type + _name);
            String _plus_1 = (_plus + ".dot");
            String _drawSafe = this.drawSafe(this.pdaToDot, e_1.getValue());
            Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
            result.add(_mappedTo);
            String _name_1 = e_1.getName();
            String _plus_2 = (dir_context_type + _name_1);
            String _plus_3 = (_plus_2 + ".txt");
            String _join = IterableExtensions.join(e_1.getContexts(), "\n");
            Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
            result.add(_mappedTo_1);
        }
    }
    List<NamedSerializationContexts<ISyntacticSequencerPDAProvider.ISynAbsorberState>> _namedContexts_2 = names.<ISyntacticSequencerPDAProvider.ISynAbsorberState>getNamedContexts(this.syntacticSequencerPDAProvider.getSyntacticSequencerPDAs(this.grammar));
    for (final NamedSerializationContexts<ISyntacticSequencerPDAProvider.ISynAbsorberState> e_2 : _namedContexts_2) {
        {
            String _name = e_2.getName();
            String _plus = (dir_syntactic_sequencer + _name);
            String _plus_1 = (_plus + ".dot");
            String _drawSafe = this.drawSafe(this.syntacticSequencerPDA2Dot, e_2.getValue());
            Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
            result.add(_mappedTo);
            String _name_1 = e_2.getName();
            String _plus_2 = (dir_syntactic_sequencer + _name_1);
            String _plus_3 = (_plus_2 + ".txt");
            String _join = IterableExtensions.join(e_2.getContexts(), "\n");
            Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
            result.add(_mappedTo_1);
        }
    }
    List<NamedSerializationContexts<Nfa<ISemanticSequencerNfaProvider.ISemState>>> _namedContexts_3 = names.<Nfa<ISemanticSequencerNfaProvider.ISemState>>getNamedContexts(this.semanticSequencerNFAProvider.getSemanticSequencerNFAs(this.grammar));
    for (final NamedSerializationContexts<Nfa<ISemanticSequencerNfaProvider.ISemState>> e_3 : _namedContexts_3) {
        {
            String _name = e_3.getName();
            String _plus = (dir_semantic_sequencer + _name);
            String _plus_1 = (_plus + ".dot");
            String _drawSafe = this.drawSafe(this.nfaToDot, e_3.getValue());
            Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
            result.add(_mappedTo);
            String _name_1 = e_3.getName();
            String _plus_2 = (dir_semantic_sequencer + _name_1);
            String _plus_3 = (_plus_2 + ".txt");
            String _join = IterableExtensions.join(e_3.getContexts(), "\n");
            Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
            result.add(_mappedTo_1);
        }
    }
    try {
        int i = 0;
        final HashMap<ISyntacticSequencerPDAProvider.ISynTransition, String> trans2id = CollectionLiterals.<ISyntacticSequencerPDAProvider.ISynTransition, String>newHashMap();
        Set<ISyntacticSequencerPDAProvider.ISynTransition> _allAmbiguousTransitions = this.syntacticSequencerUtil.getAllAmbiguousTransitions();
        for (final ISyntacticSequencerPDAProvider.ISynTransition transition : _allAmbiguousTransitions) {
            {
                final String name = ("ambiguity_" + Integer.valueOf(i));
                String _directory = this.directory("syntactic_sequencer");
                String _plus = (_directory + name);
                String _plus_1 = (_plus + ".dot");
                String _draw = this.nfaToDot.draw(transition.getAmbiguousNfa());
                Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _draw);
                result.add(_mappedTo);
                trans2id.put(transition, name);
                i = (i + 1);
            }
        }
        final StringBuffer ambiguities = new StringBuffer();
        List<EqualAmbiguousTransitions> _allAmbiguousTransitionsBySyntax = this.syntacticSequencerUtil.getAllAmbiguousTransitionsBySyntax();
        for (final EqualAmbiguousTransitions group : _allAmbiguousTransitionsBySyntax) {
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("id: ");
            String _identifier = group.getIdentifier();
            _builder.append(_identifier);
            _builder.newLineIfNotEmpty();
            _builder.append("    ");
            _builder.append("Ambiguous syntax:�:");
            _builder.newLine();
            _builder.append("        ");
            String _replace = group.getElementAlias().toString().replace("\n", "\n        ");
            _builder.append(_replace, "        ");
            _builder.newLineIfNotEmpty();
            _builder.append("    ");
            _builder.append("This ambiguous syntax occurs at:");
            _builder.newLine();
            {
                List<ISyntacticSequencerPDAProvider.ISynTransition> _transitions = group.getTransitions();
                for (final ISyntacticSequencerPDAProvider.ISynTransition trans : _transitions) {
                    _builder.append("\t");
                    String _get = trans2id.get(trans);
                    _builder.append(_get, "\t");
                    _builder.append(":");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("    ");
                    String _replace_1 = group.ambiguityInsideTransition(trans).replace("\n", "\n        ");
                    _builder.append(_replace_1, "\t    ");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t");
            _builder.newLine();
            _builder.newLine();
            ambiguities.append(_builder);
        }
        String _directory = this.directory("syntactic_sequencer");
        String _plus = (_directory + "ambiguities.txt");
        String _string = ambiguities.toString();
        Pair<String, String> _mappedTo = Pair.<String, String>of(_plus, _string);
        result.add(_mappedTo);
    } catch (final Throwable _t) {
        if (_t instanceof Exception) {
            final Exception e_4 = (Exception) _t;
            e_4.printStackTrace();
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
    return result;
}
Also used : Nfa(org.eclipse.xtext.util.formallang.Nfa) Pda(org.eclipse.xtext.util.formallang.Pda) RuleCall(org.eclipse.xtext.RuleCall) ISerState(org.eclipse.xtext.serializer.analysis.ISerState) ISyntacticSequencerPDAProvider(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider) ArrayList(java.util.ArrayList) List(java.util.List) Pair(org.eclipse.xtext.xbase.lib.Pair) NamedSerializationContextProvider(org.eclipse.xtext.xtext.generator.serializer.NamedSerializationContextProvider) NamedSerializationContexts(org.eclipse.xtext.xtext.generator.serializer.NamedSerializationContexts) EqualAmbiguousTransitions(org.eclipse.xtext.xtext.generator.serializer.EqualAmbiguousTransitions) Extension(org.eclipse.xtext.xbase.lib.Extension) ISemanticSequencerNfaProvider(org.eclipse.xtext.serializer.analysis.ISemanticSequencerNfaProvider) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 15 with Extension

use of org.eclipse.xtext.xbase.lib.Extension in project xtext-lib by eclipse.

the class DataProcessor method doTransform.

@Override
public void doTransform(final MutableClassDeclaration it, @Extension final TransformationContext context) {
    @Extension final DataProcessor.Util util = new DataProcessor.Util(context);
    @Extension final AccessorsProcessor.Util getterUtil = new AccessorsProcessor.Util(context);
    @Extension final EqualsHashCodeProcessor.Util ehUtil = new EqualsHashCodeProcessor.Util(context);
    @Extension final ToStringProcessor.Util toStringUtil = new ToStringProcessor.Util(context);
    @Extension final FinalFieldsConstructorProcessor.Util requiredArgsUtil = new FinalFieldsConstructorProcessor.Util(context);
    final Consumer<MutableFieldDeclaration> _function = (MutableFieldDeclaration it_1) -> {
        Element _primarySourceElement = context.getPrimarySourceElement(it_1);
        boolean _contains = ((FieldDeclaration) _primarySourceElement).getModifiers().contains(Modifier.VAR);
        if (_contains) {
            context.addError(it_1, "Cannot use the \'var\' keyword on a data field");
        }
        it_1.setFinal(true);
    };
    util.getDataFields(it).forEach(_function);
    if ((requiredArgsUtil.needsFinalFieldConstructor(it) || (it.findAnnotation(context.findTypeGlobally(FinalFieldsConstructor.class)) != null))) {
        requiredArgsUtil.addFinalFieldsConstructor(it);
    }
    boolean _hasHashCode = ehUtil.hasHashCode(it);
    boolean _not = (!_hasHashCode);
    if (_not) {
        ehUtil.addHashCode(it, util.getDataFields(it), ehUtil.hasSuperHashCode(it));
    }
    boolean _hasEquals = ehUtil.hasEquals(it);
    boolean _not_1 = (!_hasEquals);
    if (_not_1) {
        ehUtil.addEquals(it, util.getDataFields(it), ehUtil.hasSuperEquals(it));
    }
    boolean _hasToString = toStringUtil.hasToString(it);
    boolean _not_2 = (!_hasToString);
    if (_not_2) {
        ResolvedConstructor _superConstructor = requiredArgsUtil.getSuperConstructor(it);
        boolean _tripleEquals = (_superConstructor == null);
        if (_tripleEquals) {
            Iterable<? extends MutableFieldDeclaration> _dataFields = util.getDataFields(it);
            ToStringConfiguration _elvis = null;
            ToStringConfiguration _toStringConfig = toStringUtil.getToStringConfig(it);
            if (_toStringConfig != null) {
                _elvis = _toStringConfig;
            } else {
                ToStringConfiguration _toStringConfiguration = new ToStringConfiguration();
                _elvis = _toStringConfiguration;
            }
            toStringUtil.addToString(it, _dataFields, _elvis);
        } else {
            ToStringConfiguration _elvis_1 = null;
            ToStringConfiguration _toStringConfig_1 = toStringUtil.getToStringConfig(it);
            if (_toStringConfig_1 != null) {
                _elvis_1 = _toStringConfig_1;
            } else {
                ToStringConfiguration _toStringConfiguration_1 = new ToStringConfiguration();
                _elvis_1 = _toStringConfiguration_1;
            }
            toStringUtil.addReflectiveToString(it, _elvis_1);
        }
    }
    final Consumer<MutableFieldDeclaration> _function_1 = (MutableFieldDeclaration it_1) -> {
        boolean _shouldAddGetter = getterUtil.shouldAddGetter(it_1);
        if (_shouldAddGetter) {
            Visibility _elvis_2 = null;
            AccessorType _getterType = getterUtil.getGetterType(it_1);
            Visibility _visibility = null;
            if (_getterType != null) {
                _visibility = getterUtil.toVisibility(_getterType);
            }
            if (_visibility != null) {
                _elvis_2 = _visibility;
            } else {
                _elvis_2 = Visibility.PUBLIC;
            }
            getterUtil.addGetter(it_1, _elvis_2);
        }
    };
    util.getDataFields(it).forEach(_function_1);
}
Also used : MutableFieldDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration) AccessorsProcessor(org.eclipse.xtend.lib.annotations.AccessorsProcessor) Element(org.eclipse.xtend.lib.macro.declaration.Element) ToStringConfiguration(org.eclipse.xtend.lib.annotations.ToStringConfiguration) EqualsHashCodeProcessor(org.eclipse.xtend.lib.annotations.EqualsHashCodeProcessor) FinalFieldsConstructorProcessor(org.eclipse.xtend.lib.annotations.FinalFieldsConstructorProcessor) MutableFieldDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration) FieldDeclaration(org.eclipse.xtend.lib.macro.declaration.FieldDeclaration) ResolvedConstructor(org.eclipse.xtend.lib.macro.declaration.ResolvedConstructor) Extension(org.eclipse.xtext.xbase.lib.Extension) ToStringProcessor(org.eclipse.xtend.lib.annotations.ToStringProcessor) FinalFieldsConstructor(org.eclipse.xtend.lib.annotations.FinalFieldsConstructor) Visibility(org.eclipse.xtend.lib.macro.declaration.Visibility) AccessorType(org.eclipse.xtend.lib.annotations.AccessorType)

Aggregations

Extension (org.eclipse.xtext.xbase.lib.Extension)34 List (java.util.List)11 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)11 CompletionList (org.eclipse.lsp4j.CompletionList)9 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)8 Test (org.junit.Test)8 Position (org.eclipse.lsp4j.Position)6 ContentAssistGrammarNaming (org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming)6 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)4 MutableFieldDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration)4 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)4 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)4 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)4 TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)4 Set (java.util.Set)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 Data (org.eclipse.xtend.lib.annotations.Data)3 AnnotationReference (org.eclipse.xtend.lib.macro.declaration.AnnotationReference)3 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)3 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)3