Search in sources :

Example 81 with Procedure1

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project applause by applause.

the class DataAccessCompiler method doGenerate.

public void doGenerate(final Resource resource, final IFileSystemAccess fsa) {
    TreeIterator<EObject> _allContents = resource.getAllContents();
    Iterable<EObject> _iterable = IteratorExtensions.<EObject>toIterable(_allContents);
    Iterable<DataSource> _filter = Iterables.<DataSource>filter(_iterable, DataSource.class);
    final Procedure1<DataSource> _function = new Procedure1<DataSource>() {

        public void apply(final DataSource it) {
            Entity _resourceType = it.getResourceType();
            String _entityDataAccessCategoryHeaderFileName = DataAccessCompiler.this._dataAccessClassExtensions.entityDataAccessCategoryHeaderFileName(_resourceType);
            CharSequence _compileHeaderFile = DataAccessCompiler.this._entityDataAccessHeaderFileCompiler.compileHeaderFile(it);
            fsa.generateFile(_entityDataAccessCategoryHeaderFileName, IosOutputConfigurationProvider.IOS_OUTPUT_DATAACCESS, _compileHeaderFile);
            Entity _resourceType_1 = it.getResourceType();
            String _entityDataAccessCategoryModuleFileName = DataAccessCompiler.this._dataAccessClassExtensions.entityDataAccessCategoryModuleFileName(_resourceType_1);
            CharSequence _compileModuleFile = DataAccessCompiler.this._entityDataAccessModuleFileCompiler.compileModuleFile(it);
            fsa.generateFile(_entityDataAccessCategoryModuleFileName, IosOutputConfigurationProvider.IOS_OUTPUT_DATAACCESS, _compileModuleFile);
        }
    };
    IterableExtensions.<DataSource>forEach(_filter, _function);
}
Also used : Entity(org.applause.lang.applauseDsl.Entity) EObject(org.eclipse.emf.ecore.EObject) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) DataSource(org.applause.lang.applauseDsl.DataSource)

Example 82 with Procedure1

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-xtend by eclipse.

the class XtendGenerator method compileLocalTypeStubs.

public void compileLocalTypeStubs(final JvmFeature feature, final ITreeAppendable appendable, final GeneratorConfig config) {
    final Function1<JvmGenericType, Boolean> _function = (JvmGenericType it) -> {
        boolean _isAnonymous = it.isAnonymous();
        return Boolean.valueOf((!_isAnonymous));
    };
    final Consumer<JvmGenericType> _function_1 = (JvmGenericType it) -> {
        appendable.newLine();
        EObject _head = IterableExtensions.<EObject>head(this.getSourceElements(it));
        final AnonymousClass anonymousClass = ((AnonymousClass) _head);
        final ITreeAppendable childAppendable = appendable.trace(anonymousClass);
        childAppendable.append("abstract class ");
        this._treeAppendableUtil.traceSignificant(childAppendable, anonymousClass).append(it.getSimpleName());
        boolean _isEmpty = it.getTypeParameters().isEmpty();
        if (_isEmpty) {
            childAppendable.append(" ");
        }
        this.generateExtendsClause(it, childAppendable, null);
        childAppendable.append("{").increaseIndentation();
        boolean _needSyntheticThisVariable = this.needSyntheticThisVariable(anonymousClass, it);
        if (_needSyntheticThisVariable) {
            Pair<String, JvmGenericType> _mappedTo = Pair.<String, JvmGenericType>of("this", it);
            String _simpleName = it.getSimpleName();
            String _plus = ("_this" + _simpleName);
            final String thisName = childAppendable.declareSyntheticVariable(_mappedTo, _plus);
            childAppendable.newLine().append("final ").append(it.getSimpleName()).append(" ").append(thisName).append(" = this;").newLine();
        }
        final Procedure1<LoopParams> _function_2 = (LoopParams it_1) -> {
            final Function1<ITreeAppendable, ITreeAppendable> _function_3 = (ITreeAppendable it_2) -> {
                return it_2.newLine();
            };
            it_1.setSeparator(_function_3);
        };
        final Procedure1<JvmMember> _function_3 = (JvmMember it_1) -> {
            final ITreeAppendable memberAppendable = this._treeAppendableUtil.traceWithComments(childAppendable, it_1);
            memberAppendable.openScope();
            if ((it_1 instanceof JvmOperation)) {
                final ITreeAppendable tracedAppendable = childAppendable.trace(it_1);
                tracedAppendable.newLine();
                this.generateJavaDoc(it_1, tracedAppendable, config);
                this.generateVisibilityModifier(it_1, tracedAppendable);
                tracedAppendable.append("abstract ");
                this.generateTypeParameterDeclaration(((JvmTypeParameterDeclarator) it_1), tracedAppendable, null);
                JvmTypeReference _returnType = ((JvmOperation) it_1).getReturnType();
                boolean _tripleEquals = (_returnType == null);
                if (_tripleEquals) {
                    tracedAppendable.append("void");
                } else {
                    this._errorSafeExtensions.serializeSafely(((JvmOperation) it_1).getReturnType(), "Object", tracedAppendable);
                }
                tracedAppendable.append(" ");
                this._treeAppendableUtil.traceSignificant(tracedAppendable, it_1).append(((JvmOperation) it_1).getSimpleName());
                tracedAppendable.append("(");
                this.generateParameters(((JvmExecutable) it_1), tracedAppendable, null);
                tracedAppendable.append(")");
                this.generateThrowsClause(((JvmExecutable) it_1), tracedAppendable, null);
                tracedAppendable.append(";");
            } else {
                if ((it_1 instanceof JvmField)) {
                    final ITreeAppendable tracedAppendable_1 = childAppendable.trace(it_1);
                    tracedAppendable_1.newLine();
                    this.generateJavaDoc(it_1, tracedAppendable_1, config);
                    this.generateAnnotations(((JvmField) it_1).getAnnotations(), tracedAppendable_1, true, config);
                    if ((((JvmField) it_1).isFinal() && ((JvmField) it_1).isStatic())) {
                        tracedAppendable_1.append("final ");
                    }
                    boolean _isStatic = ((JvmField) it_1).isStatic();
                    if (_isStatic) {
                        tracedAppendable_1.append("static ");
                    }
                    boolean _isTransient = ((JvmField) it_1).isTransient();
                    if (_isTransient) {
                        tracedAppendable_1.append("transient ");
                    }
                    boolean _isVolatile = ((JvmField) it_1).isVolatile();
                    if (_isVolatile) {
                        tracedAppendable_1.append("volatile ");
                    }
                    this._errorSafeExtensions.serializeSafely(((JvmField) it_1).getType(), "Object", tracedAppendable_1);
                    tracedAppendable_1.append(" ");
                    this._treeAppendableUtil.traceSignificant(tracedAppendable_1, it_1).append(((JvmField) it_1).getSimpleName());
                    if ((((JvmField) it_1).isFinal() && ((JvmField) it_1).isStatic())) {
                        Object _constantValue = ((JvmField) it_1).getConstantValue();
                        boolean _tripleNotEquals = (_constantValue != null);
                        if (_tripleNotEquals) {
                            tracedAppendable_1.append(" = ");
                            this.generateJavaConstant(((JvmField) it_1).getConstantValue(), tracedAppendable_1);
                        } else {
                            this.generateInitialization(((JvmField) it_1), tracedAppendable_1, config);
                        }
                    }
                    tracedAppendable_1.append(";");
                } else {
                    this.generateMember(it_1, memberAppendable, config);
                }
            }
            memberAppendable.closeScope();
        };
        this._loopExtensions.<JvmMember>forEach(childAppendable, this.getAddedDeclarations(it, anonymousClass), _function_2, _function_3);
        childAppendable.decreaseIndentation().newLine().append("}");
        appendable.newLine();
    };
    IterableExtensions.<JvmGenericType>filter(feature.getLocalClasses(), _function).forEach(_function_1);
}
Also used : JvmTypeParameterDeclarator(org.eclipse.xtext.common.types.JvmTypeParameterDeclarator) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) ITreeAppendable(org.eclipse.xtext.xbase.compiler.output.ITreeAppendable) LoopParams(org.eclipse.xtext.xbase.compiler.LoopParams) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) EObject(org.eclipse.emf.ecore.EObject) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) JvmMember(org.eclipse.xtext.common.types.JvmMember) EObject(org.eclipse.emf.ecore.EObject) JvmField(org.eclipse.xtext.common.types.JvmField) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 83 with Procedure1

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-xtend by eclipse.

the class XtendFormatter method _format.

protected void _format(final XtendConstructor func, @Extension final IFormattableDocument format) {
    this.formatAnnotations(func, format, XbaseFormatterPreferenceKeys.newLineAfterConstructorAnnotations);
    this.formatModifiers(func, format);
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.noSpace();
    };
    format.append(this.textRegionExtensions.regionFor(func).keyword("new"), _function);
    boolean _isEmpty = func.getTypeParameters().isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
            it.noSpace();
        };
        format.append(this.textRegionExtensions.regionFor(func).keyword("<"), _function_1);
        EList<JvmTypeParameter> _typeParameters = func.getTypeParameters();
        for (final JvmTypeParameter arg : _typeParameters) {
            {
                format.<JvmTypeParameter>format(arg);
                final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
                    it.noSpace();
                };
                final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
                    it.oneSpace();
                };
                format.append(format.prepend(this.textRegionExtensions.immediatelyFollowing(arg).keyword(","), _function_2), _function_3);
            }
        }
        final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
            it.noSpace();
        };
        format.surround(this.textRegionExtensions.regionFor(func).keyword(">"), _function_2);
    }
    final ISemanticRegion open = this.textRegionExtensions.regionFor(func).keyword("(");
    final ISemanticRegion close = this.textRegionExtensions.regionFor(func).keyword(")");
    format.append(close, XbaseFormatterPreferenceKeys.bracesInNewLine);
    this.formatCommaSeparatedList(func.getParameters(), open, close, format);
    format.<XExpression>format(func.getExpression());
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) XExpression(org.eclipse.xtext.xbase.XExpression) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 84 with Procedure1

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-xtend by eclipse.

the class XtendFormatter method formatTypeParameters.

protected ISemanticRegion formatTypeParameters(final XtendMember member, final List<? extends JvmTypeParameter> typeParameters, @Extension final IFormattableDocument format) {
    ISemanticRegion _xifexpression = null;
    boolean _isEmpty = typeParameters.isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        ISemanticRegion _xblockexpression = null;
        {
            final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
                it.noSpace();
            };
            format.surround(this.textRegionExtensions.regionFor(member).keyword("<"), _function);
            for (final JvmTypeParameter arg : typeParameters) {
                {
                    format.<JvmTypeParameter>format(arg);
                    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
                        it.noSpace();
                    };
                    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
                        it.oneSpace();
                    };
                    format.append(format.prepend(this.textRegionExtensions.immediatelyFollowing(arg).keyword(","), _function_1), _function_2);
                }
            }
            final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
                it.noSpace();
            };
            _xblockexpression = format.prepend(this.textRegionExtensions.regionFor(member).keyword(">"), _function_1);
        }
        _xifexpression = _xblockexpression;
    }
    return _xifexpression;
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 85 with Procedure1

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-xtend by eclipse.

the class MemberFromSuperImplementor method getImplementedInterface.

private Procedure1<? super ISourceAppender> getImplementedInterface(final JvmDeclaredType subType, final JvmDeclaredType superInterface) {
    if (((superInterface instanceof JvmGenericType) && ((JvmGenericType) superInterface).isInterface())) {
        final Function1<JvmTypeReference, Boolean> _function = (JvmTypeReference it) -> {
            JvmType _type = it.getType();
            return Boolean.valueOf(Objects.equal(_type, superInterface));
        };
        boolean _exists = IterableExtensions.<JvmTypeReference>exists(subType.getSuperTypes(), _function);
        if (_exists) {
            final Procedure1<ISourceAppender> _function_1 = (ISourceAppender it) -> {
                it.append(superInterface).append(".");
            };
            return _function_1;
        }
        final Function1<JvmTypeReference, Boolean> _function_2 = (JvmTypeReference it) -> {
            return Boolean.valueOf(this.isInterface(it.getType()));
        };
        final Function1<JvmTypeReference, JvmDeclaredType> _function_3 = (JvmTypeReference it) -> {
            JvmType _type = it.getType();
            return ((JvmDeclaredType) _type);
        };
        final Function1<JvmDeclaredType, Boolean> _function_4 = (JvmDeclaredType it) -> {
            Procedure1<? super ISourceAppender> _implementedInterface = this.getImplementedInterface(it, superInterface);
            return Boolean.valueOf((_implementedInterface != null));
        };
        final JvmDeclaredType interfaze = IterableExtensions.<JvmDeclaredType>findFirst(IterableExtensions.<JvmTypeReference, JvmDeclaredType>map(IterableExtensions.<JvmTypeReference>filter(subType.getSuperTypes(), _function_2), _function_3), _function_4);
        if ((interfaze != null)) {
            final Procedure1<ISourceAppender> _function_5 = (ISourceAppender it) -> {
                it.append(interfaze).append(".");
            };
            return _function_5;
        }
    }
    return null;
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmType(org.eclipse.xtext.common.types.JvmType) ISourceAppender(org.eclipse.xtext.xbase.compiler.ISourceAppender)

Aggregations

Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)173 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)99 Test (org.junit.Test)98 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)28 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)20 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)20 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)20 GenericFormatterTestRequest (org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest)18 AbstractXtendCompilerTest (org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest)16 CompilationTestHelper (org.eclipse.xtext.xbase.testing.CompilationTestHelper)16 EList (org.eclipse.emf.common.util.EList)14 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)14 MapBasedPreferenceValues (org.eclipse.xtext.preferences.MapBasedPreferenceValues)14 IDList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList)13 EObject (org.eclipse.emf.ecore.EObject)11 Method (java.lang.reflect.Method)10 AbstractBuilderTest (org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)10 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)10 MandatoryValue (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue)10 Field (java.lang.reflect.Field)9