Search in sources :

Example 16 with Procedure1

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

the class AnnotationReferenceProviderImpl method newAnnotationReference.

@Override
public AnnotationReference newAnnotationReference(final Type annotationTypeDelcaration, final Procedure1<AnnotationReferenceBuildContext> initializer) {
    Object _xblockexpression = null;
    {
        this.compilationUnit.checkCanceled();
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("annotationTypeDelcaration cannot be null");
        Preconditions.checkArgument((annotationTypeDelcaration != null), _builder);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("initializer cannot be null");
        Preconditions.checkArgument((initializer != null), _builder_1);
        JvmDeclaredType _switchResult = null;
        boolean _matched = false;
        if (annotationTypeDelcaration instanceof JvmAnnotationTypeDeclarationImpl) {
            _matched = true;
            _switchResult = ((JvmAnnotationTypeDeclarationImpl) annotationTypeDelcaration).getDelegate();
        }
        if (!_matched) {
            if (annotationTypeDelcaration instanceof XtendAnnotationTypeDeclarationImpl) {
                _matched = true;
                _switchResult = this.compilationUnit.getJvmModelAssociations().getInferredType(((XtendAnnotationTypeDeclarationImpl) annotationTypeDelcaration).getDelegate());
            }
        }
        if (!_matched) {
            throw new IllegalArgumentException(("couldn\'t construct type reference for type " + annotationTypeDelcaration));
        }
        final JvmDeclaredType type = _switchResult;
        if ((type instanceof JvmAnnotationType)) {
            final JvmAnnotationReference newJvmAnnotationReference = this.createJvmAnnotationReference(type);
            AnnotationReferenceBuildContextImpl _annotationReferenceBuildContextImpl = new AnnotationReferenceBuildContextImpl();
            final Procedure1<AnnotationReferenceBuildContextImpl> _function = (AnnotationReferenceBuildContextImpl it) -> {
                it.setDelegate(newJvmAnnotationReference);
                it.setCompilationUnit(this.compilationUnit);
            };
            final AnnotationReferenceBuildContextImpl buildContext = ObjectExtensions.<AnnotationReferenceBuildContextImpl>operator_doubleArrow(_annotationReferenceBuildContextImpl, _function);
            initializer.apply(buildContext);
            return this.compilationUnit.toAnnotationReference(newJvmAnnotationReference);
        }
        _xblockexpression = null;
    }
    return ((AnnotationReference) _xblockexpression);
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) AnnotationReferenceBuildContextImpl(org.eclipse.xtend.core.macro.declaration.AnnotationReferenceBuildContextImpl) JvmAnnotationTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmAnnotationTypeDeclarationImpl) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) XtendAnnotationTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendAnnotationTypeDeclarationImpl) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

Example 17 with Procedure1

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

the class CompilationUnitImpl method toTypeDeclaration.

public TypeDeclaration toTypeDeclaration(final JvmDeclaredType delegate) {
    final Function1<JvmDeclaredType, TypeDeclaration> _function = (JvmDeclaredType it) -> {
        JvmTypeDeclarationImpl<? extends JvmDeclaredType> _switchResult = null;
        boolean _matched = false;
        if (delegate instanceof JvmGenericType) {
            boolean _isInterface = ((JvmGenericType) delegate).isInterface();
            if (_isInterface) {
                _matched = true;
                JvmInterfaceDeclarationImpl _xifexpression = null;
                boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
                if (_isBelongedToCompilationUnit) {
                    MutableJvmInterfaceDeclarationImpl _mutableJvmInterfaceDeclarationImpl = new MutableJvmInterfaceDeclarationImpl();
                    final Procedure1<MutableJvmInterfaceDeclarationImpl> _function_1 = (MutableJvmInterfaceDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmGenericType) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<MutableJvmInterfaceDeclarationImpl>operator_doubleArrow(_mutableJvmInterfaceDeclarationImpl, _function_1);
                } else {
                    JvmInterfaceDeclarationImpl _jvmInterfaceDeclarationImpl = new JvmInterfaceDeclarationImpl();
                    final Procedure1<JvmInterfaceDeclarationImpl> _function_2 = (JvmInterfaceDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmGenericType) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<JvmInterfaceDeclarationImpl>operator_doubleArrow(_jvmInterfaceDeclarationImpl, _function_2);
                }
                _switchResult = _xifexpression;
            }
        }
        if (!_matched) {
            if (delegate instanceof JvmGenericType) {
                _matched = true;
                JvmClassDeclarationImpl _xifexpression = null;
                boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
                if (_isBelongedToCompilationUnit) {
                    MutableJvmClassDeclarationImpl _mutableJvmClassDeclarationImpl = new MutableJvmClassDeclarationImpl();
                    final Procedure1<MutableJvmClassDeclarationImpl> _function_1 = (MutableJvmClassDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmGenericType) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<MutableJvmClassDeclarationImpl>operator_doubleArrow(_mutableJvmClassDeclarationImpl, _function_1);
                } else {
                    JvmClassDeclarationImpl _jvmClassDeclarationImpl = new JvmClassDeclarationImpl();
                    final Procedure1<JvmClassDeclarationImpl> _function_2 = (JvmClassDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmGenericType) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<JvmClassDeclarationImpl>operator_doubleArrow(_jvmClassDeclarationImpl, _function_2);
                }
                _switchResult = _xifexpression;
            }
        }
        if (!_matched) {
            if (delegate instanceof JvmAnnotationType) {
                _matched = true;
                JvmAnnotationTypeDeclarationImpl _xifexpression = null;
                boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
                if (_isBelongedToCompilationUnit) {
                    MutableJvmAnnotationTypeDeclarationImpl _mutableJvmAnnotationTypeDeclarationImpl = new MutableJvmAnnotationTypeDeclarationImpl();
                    final Procedure1<MutableJvmAnnotationTypeDeclarationImpl> _function_1 = (MutableJvmAnnotationTypeDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmAnnotationType) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<MutableJvmAnnotationTypeDeclarationImpl>operator_doubleArrow(_mutableJvmAnnotationTypeDeclarationImpl, _function_1);
                } else {
                    JvmAnnotationTypeDeclarationImpl _jvmAnnotationTypeDeclarationImpl = new JvmAnnotationTypeDeclarationImpl();
                    final Procedure1<JvmAnnotationTypeDeclarationImpl> _function_2 = (JvmAnnotationTypeDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmAnnotationType) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<JvmAnnotationTypeDeclarationImpl>operator_doubleArrow(_jvmAnnotationTypeDeclarationImpl, _function_2);
                }
                _switchResult = _xifexpression;
            }
        }
        if (!_matched) {
            if (delegate instanceof JvmEnumerationType) {
                _matched = true;
                JvmEnumerationTypeDeclarationImpl _xifexpression = null;
                boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
                if (_isBelongedToCompilationUnit) {
                    MutableJvmEnumerationTypeDeclarationImpl _mutableJvmEnumerationTypeDeclarationImpl = new MutableJvmEnumerationTypeDeclarationImpl();
                    final Procedure1<MutableJvmEnumerationTypeDeclarationImpl> _function_1 = (MutableJvmEnumerationTypeDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmEnumerationType) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<MutableJvmEnumerationTypeDeclarationImpl>operator_doubleArrow(_mutableJvmEnumerationTypeDeclarationImpl, _function_1);
                } else {
                    JvmEnumerationTypeDeclarationImpl _jvmEnumerationTypeDeclarationImpl = new JvmEnumerationTypeDeclarationImpl();
                    final Procedure1<JvmEnumerationTypeDeclarationImpl> _function_2 = (JvmEnumerationTypeDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmEnumerationType) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<JvmEnumerationTypeDeclarationImpl>operator_doubleArrow(_jvmEnumerationTypeDeclarationImpl, _function_2);
                }
                _switchResult = _xifexpression;
            }
        }
        return ((TypeDeclaration) _switchResult);
    };
    return this.<JvmDeclaredType, TypeDeclaration>getOrCreate(delegate, _function);
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) JvmAnnotationTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmAnnotationTypeDeclarationImpl) MutableJvmAnnotationTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmAnnotationTypeDeclarationImpl) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) MutableJvmInterfaceDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmInterfaceDeclarationImpl) MutableJvmAnnotationTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmAnnotationTypeDeclarationImpl) JvmTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmTypeDeclarationImpl) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) JvmClassDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmClassDeclarationImpl) MutableJvmClassDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmClassDeclarationImpl) MutableJvmInterfaceDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmInterfaceDeclarationImpl) JvmInterfaceDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmInterfaceDeclarationImpl) MutableJvmClassDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmClassDeclarationImpl) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) TypeDeclaration(org.eclipse.xtend.lib.macro.declaration.TypeDeclaration) MutableJvmEnumerationTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmEnumerationTypeDeclarationImpl) MutableJvmEnumerationTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmEnumerationTypeDeclarationImpl) JvmEnumerationTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmEnumerationTypeDeclarationImpl)

Example 18 with Procedure1

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

the class CompilationUnitImpl method toResolvedConstructor.

public ResolvedConstructor toResolvedConstructor(final IResolvedConstructor delegate) {
    final Function1<IResolvedConstructor, ResolvedConstructorImpl> _function = (IResolvedConstructor it) -> {
        ResolvedConstructorImpl _resolvedConstructorImpl = new ResolvedConstructorImpl();
        final Procedure1<ResolvedConstructorImpl> _function_1 = (ResolvedConstructorImpl it_1) -> {
            it_1.setDelegate(delegate);
            it_1.setCompilationUnit(this);
        };
        return ObjectExtensions.<ResolvedConstructorImpl>operator_doubleArrow(_resolvedConstructorImpl, _function_1);
    };
    return this.<IResolvedConstructor, ResolvedConstructorImpl>getOrCreate(delegate, _function);
}
Also used : Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) ResolvedConstructorImpl(org.eclipse.xtend.core.macro.declaration.ResolvedConstructorImpl) IResolvedConstructor(org.eclipse.xtext.xbase.typesystem.override.IResolvedConstructor)

Example 19 with Procedure1

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

the class CompilationUnitImpl method getMessageWithStackTrace.

protected String getMessageWithStackTrace(final Throwable t) {
    final Function1<Throwable, String> _function = (Throwable it) -> {
        String _xblockexpression = null;
        {
            StringWriter _stringWriter = new StringWriter();
            final Procedure1<StringWriter> _function_1 = (StringWriter it_1) -> {
                PrintWriter _printWriter = new PrintWriter(it_1);
                final Procedure1<PrintWriter> _function_2 = (PrintWriter it_2) -> {
                    it_2.println(this.getMessageWithoutStackTrace(t));
                    t.printStackTrace(it_2);
                    it_2.flush();
                };
                ObjectExtensions.<PrintWriter>operator_doubleArrow(_printWriter, _function_2);
            };
            final StringWriter writer = ObjectExtensions.<StringWriter>operator_doubleArrow(_stringWriter, _function_1);
            _xblockexpression = writer.toString();
        }
        return _xblockexpression;
    };
    return this.getMessageWithReducedStackTrace(t, _function);
}
Also used : StringWriter(java.io.StringWriter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) PrintWriter(java.io.PrintWriter)

Example 20 with Procedure1

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

the class CompilationUnitImpl method toTypeReference.

public TypeReference toTypeReference(final JvmTypeReference delegate) {
    TypeReference _xblockexpression = null;
    {
        if ((delegate == null)) {
            return null;
        }
        TypeReference _switchResult = null;
        boolean _matched = false;
        if (delegate instanceof XComputedTypeReferenceImplCustom) {
            boolean _isEquivalentComputed = ((XComputedTypeReferenceImplCustom) delegate).isEquivalentComputed();
            boolean _not = (!_isEquivalentComputed);
            if (_not) {
                _matched = true;
                InferredTypeReferenceImpl _inferredTypeReferenceImpl = new InferredTypeReferenceImpl();
                final Procedure1<InferredTypeReferenceImpl> _function = (InferredTypeReferenceImpl it) -> {
                    it.setDelegate(((XComputedTypeReferenceImplCustom) delegate));
                    it.setCompilationUnit(this);
                };
                _switchResult = ObjectExtensions.<InferredTypeReferenceImpl>operator_doubleArrow(_inferredTypeReferenceImpl, _function);
            }
        }
        if (!_matched) {
            _switchResult = this.toTypeReference(this.typeRefFactory.toLightweightReference(delegate), delegate);
        }
        _xblockexpression = _switchResult;
    }
    return _xblockexpression;
}
Also used : InferredTypeReferenceImpl(org.eclipse.xtend.core.macro.declaration.InferredTypeReferenceImpl) XComputedTypeReferenceImplCustom(org.eclipse.xtext.xtype.impl.XComputedTypeReferenceImplCustom) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference)

Aggregations

Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)188 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)101 Test (org.junit.Test)100 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)32 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)20 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)20 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)20 EList (org.eclipse.emf.common.util.EList)18 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 MapBasedPreferenceValues (org.eclipse.xtext.preferences.MapBasedPreferenceValues)15 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)14 EObject (org.eclipse.emf.ecore.EObject)13 IDList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList)13 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)11 Method (java.lang.reflect.Method)10 Resource (org.eclipse.emf.ecore.resource.Resource)10 AbstractBuilderTest (org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)10 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)10