Search in sources :

Example 11 with IClassAnnotation

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

the class XtextGeneratorTemplates method createIdeaGenModule.

public JavaFileAccess createIdeaGenModule(final IXtextGeneratorLanguage langConfig) {
    final Grammar it = langConfig.getGrammar();
    TypeReference _elvis = null;
    TypeReference _superClass = langConfig.getIdeaGenModule().getSuperClass();
    if (_superClass != null) {
        _elvis = _superClass;
    } else {
        TypeReference _ideaDefaultModule = this.naming.getIdeaDefaultModule(it);
        _elvis = _ideaDefaultModule;
    }
    final TypeReference superClass = _elvis;
    final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(this.naming.getIdeaGenModule(it));
    file.setImportNestedTypeThreshold(JavaFileAccess.DONT_IMPORT_NESTED_TYPES);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("/**");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* Manual modifications go to {@link ");
            String _simpleName = XtextGeneratorTemplates.this.naming.getIdeaModule(it).getSimpleName();
            _builder.append(_simpleName, " ");
            _builder.append("}.");
            _builder.newLineIfNotEmpty();
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
        }
    };
    file.setTypeComment(_client);
    List<IClassAnnotation> _annotations = file.getAnnotations();
    SuppressWarningsAnnotation _suppressWarningsAnnotation = new SuppressWarningsAnnotation();
    _annotations.add(_suppressWarningsAnnotation);
    StringConcatenationClient _client_1 = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public abstract class ");
            String _simpleName = XtextGeneratorTemplates.this.naming.getIdeaGenModule(it).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            _builder.append(superClass);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.newLine();
            {
                Set<GuiceModuleAccess.Binding> _bindings = langConfig.getIdeaGenModule().getBindings();
                for (final GuiceModuleAccess.Binding binding : _bindings) {
                    _builder.append("\t");
                    StringConcatenationClient _createBindingMethod = XtextGeneratorTemplates.this.createBindingMethod(binding);
                    _builder.append(_createBindingMethod, "\t");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.newLine();
                }
            }
            _builder.append("}");
            _builder.newLine();
        }
    };
    file.setContent(_client_1);
    return file;
}
Also used : SingletonBinding(org.eclipse.xtext.service.SingletonBinding) GuiceModuleAccess(org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess) Set(java.util.Set) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) IClassAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) Grammar(org.eclipse.xtext.Grammar) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) SuppressWarningsAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation)

Example 12 with IClassAnnotation

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

the class SerializerFragment2 method generateAbstractSemanticSequencer.

protected void generateAbstractSemanticSequencer() {
    final Collection<IGrammarConstraintProvider.IConstraint> localConstraints = this._semanticSequencerExtensions.getGrammarConstraints(this.getGrammar());
    final Collection<IGrammarConstraintProvider.IConstraint> superConstraints = this._semanticSequencerExtensions.getGrammarConstraints(this._semanticSequencerExtensions.getSuperGrammar(this.getGrammar()));
    final Function1<IGrammarConstraintProvider.IConstraint, Boolean> _function = (IGrammarConstraintProvider.IConstraint it) -> {
        return Boolean.valueOf(((it.getType() != null) && (!superConstraints.contains(it))));
    };
    final Set<IGrammarConstraintProvider.IConstraint> newLocalConstraints = IterableExtensions.<IGrammarConstraintProvider.IConstraint>toSet(IterableExtensions.<IGrammarConstraintProvider.IConstraint>filter(localConstraints, _function));
    TypeReference _xifexpression = null;
    boolean _isGenerateStub = this.isGenerateStub();
    if (_isGenerateStub) {
        _xifexpression = this.getAbstractSemanticSequencerClass(this.getGrammar());
    } else {
        _xifexpression = this.getSemanticSequencerClass(this.getGrammar());
    }
    final TypeReference clazz = _xifexpression;
    TypeReference _xifexpression_1 = null;
    final Function1<IGrammarConstraintProvider.IConstraint, Boolean> _function_1 = (IGrammarConstraintProvider.IConstraint it) -> {
        return Boolean.valueOf(superConstraints.contains(it));
    };
    boolean _exists = IterableExtensions.<IGrammarConstraintProvider.IConstraint>exists(localConstraints, _function_1);
    if (_exists) {
        _xifexpression_1 = this.getSemanticSequencerClass(IterableExtensions.<Grammar>head(this.getGrammar().getUsedGrammars()));
    } else {
        _xifexpression_1 = TypeReference.typeRef(AbstractDelegatingSemanticSequencer.class);
    }
    final TypeReference superClazz = _xifexpression_1;
    final GeneratedJavaFileAccess javaFile = this.fileAccessFactory.createGeneratedJavaFile(clazz);
    javaFile.setResourceSet(this.getLanguage().getResourceSet());
    final HashSet<Pair<String, EClass>> methodSignatures = CollectionLiterals.<Pair<String, EClass>>newHashSet();
    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(superClazz);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@");
            _builder.append(Inject.class, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("private ");
            TypeReference _grammarAccess = SerializerFragment2.this._grammarAccessExtensions.getGrammarAccess(SerializerFragment2.this.getGrammar());
            _builder.append(_grammarAccess, "\t");
            _builder.append(" grammarAccess;");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            StringConcatenationClient _genMethodCreateSequence = SerializerFragment2.this.genMethodCreateSequence();
            _builder.append(_genMethodCreateSequence, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.newLine();
            {
                List<IGrammarConstraintProvider.IConstraint> _sort = IterableExtensions.<IGrammarConstraintProvider.IConstraint>sort(newLocalConstraints);
                for (final IGrammarConstraintProvider.IConstraint c : _sort) {
                    {
                        String _simpleName_1 = c.getSimpleName();
                        EClass _type = c.getType();
                        Pair<String, EClass> _mappedTo = Pair.<String, EClass>of(_simpleName_1, _type);
                        boolean _add = methodSignatures.add(_mappedTo);
                        if (_add) {
                            _builder.append("\t");
                            StringConcatenationClient _genMethodSequence = SerializerFragment2.this.genMethodSequence(c);
                            _builder.append(_genMethodSequence, "\t");
                            _builder.newLineIfNotEmpty();
                        } else {
                            _builder.append("\t");
                            String _simpleName_2 = clazz.getSimpleName();
                            String _plus = ("Skipped generating duplicate method in " + _simpleName_2);
                            SerializerFragment2.LOG.warn(_plus);
                            _builder.newLineIfNotEmpty();
                            _builder.append("\t");
                            StringConcatenationClient _genMethodSequenceComment = SerializerFragment2.this.genMethodSequenceComment(c);
                            _builder.append(_genMethodSequenceComment, "\t");
                            _builder.newLineIfNotEmpty();
                        }
                    }
                    _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 : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) AbstractDelegatingSemanticSequencer(org.eclipse.xtext.serializer.sequencer.AbstractDelegatingSemanticSequencer) Grammar(org.eclipse.xtext.Grammar) SuppressWarningsAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation) EClass(org.eclipse.emf.ecore.EClass) IClassAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation) IGrammarConstraintProvider(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) List(java.util.List) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) Pair(org.eclipse.xtext.xbase.lib.Pair)

Aggregations

IClassAnnotation (org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation)12 TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)10 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)9 GeneratedJavaFileAccess (org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess)9 Grammar (org.eclipse.xtext.Grammar)8 SuppressWarningsAnnotation (org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation)8 Set (java.util.Set)6 SingletonBinding (org.eclipse.xtext.service.SingletonBinding)5 GuiceModuleAccess (org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess)5 List (java.util.List)4 EList (org.eclipse.emf.common.util.EList)2 AbstractRule (org.eclipse.xtext.AbstractRule)2 EClass (org.eclipse.emf.ecore.EClass)1 EObject (org.eclipse.emf.ecore.EObject)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 EnumRule (org.eclipse.xtext.EnumRule)1 ParserRule (org.eclipse.xtext.ParserRule)1 XtextPackage (org.eclipse.xtext.XtextPackage)1 INode (org.eclipse.xtext.nodemodel.INode)1 BinaryGrammarResourceFactoryImpl (org.eclipse.xtext.resource.impl.BinaryGrammarResourceFactoryImpl)1