Search in sources :

Example 21 with Procedure0

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

the class CheckMutableFieldDeclarationProcessor method doTransform.

@Override
public void doTransform(final MutableFieldDeclaration annotatedField, @Extension final TransformationContext context) {
    final Procedure0 _function = () -> {
        annotatedField.setInitializer(((CompilationStrategy) null));
    };
    MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "initializer cannot be null", _function);
    final Procedure0 _function_1 = () -> {
        annotatedField.setType(null);
    };
    MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "type cannot be null", _function_1);
}
Also used : Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0)

Example 22 with Procedure0

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

the class CheckMutableInterfaceDeclarationProcessor method doTransform.

@Override
public void doTransform(final List<? extends MutableInterfaceDeclaration> annotatedTargetElements, @Extension final TransformationContext context) {
    for (final MutableInterfaceDeclaration annotatedTargetElement : annotatedTargetElements) {
        {
            final Procedure1<String> _function = (String identifier) -> {
                annotatedTargetElement.addTypeParameter(identifier).remove();
            };
            MutableAssert.assertValidJavaIdentifier("name", _function);
            final Procedure0 _function_1 = () -> {
                annotatedTargetElement.addTypeParameter("T", ((TypeReference[]) null));
            };
            MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "upperBounds cannot be null", _function_1);
            final Procedure0 _function_2 = () -> {
                annotatedTargetElement.addTypeParameter("T", new TypeReference[] { null });
            };
            MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "upperBounds cannot contain null", _function_2);
            annotatedTargetElement.addTypeParameter("T", ((TypeReference[]) Conversions.unwrapArray(CollectionLiterals.<TypeReference>emptyList(), TypeReference.class))).remove();
            final Procedure0 _function_3 = () -> {
                annotatedTargetElement.setExtendedInterfaces(null);
            };
            MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "superinterfaces cannot be null", _function_3);
            final Procedure0 _function_4 = () -> {
                annotatedTargetElement.setExtendedInterfaces(Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList((TypeReference) null)));
            };
            MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "superinterfaces cannot contain null", _function_4);
            annotatedTargetElement.setExtendedInterfaces(CollectionLiterals.<TypeReference>emptyList());
            final Procedure1<AnnotationReferenceBuildContext> _function_5 = (AnnotationReferenceBuildContext it) -> {
                final Procedure0 _function_6 = () -> {
                    it.set(null, null);
                };
                MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "name has to be a valid java identifier", _function_6);
                final Procedure0 _function_7 = () -> {
                    it.set(null, "foo");
                };
                MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "name has to be a valid java identifier", _function_7);
                final Procedure0 _function_8 = () -> {
                    String[] _xblockexpression = null;
                    {
                        final String[] array = { "foo" };
                        _xblockexpression = array;
                    }
                    it.set(null, _xblockexpression);
                };
                MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "name has to be a valid java identifier", _function_8);
                final Procedure0 _function_9 = () -> {
                    it.set(null, Boolean.valueOf(true));
                };
                MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "name has to be a valid java identifier", _function_9);
                final Procedure0 _function_10 = () -> {
                    it.set(null, ((boolean[]) ((boolean[]) Conversions.unwrapArray(Collections.<Boolean>unmodifiableList(CollectionLiterals.<Boolean>newArrayList(Boolean.valueOf(true))), boolean.class))));
                };
                MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "name has to be a valid java identifier", _function_10);
                final Procedure0 _function_11 = () -> {
                    it.set(null, Integer.valueOf(0));
                };
                MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "name has to be a valid java identifier", _function_11);
                final Procedure0 _function_12 = () -> {
                    it.set(null, ((int[]) ((int[]) Conversions.unwrapArray(Collections.<Integer>unmodifiableList(CollectionLiterals.<Integer>newArrayList(Integer.valueOf(0))), int.class))));
                };
                MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "name has to be a valid java identifier", _function_12);
                final Procedure0 _function_13 = () -> {
                    String[] _xblockexpression = null;
                    {
                        final String[] array = { "foo" };
                        _xblockexpression = array;
                    }
                    it.set("doesNotExist", _xblockexpression);
                };
                MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "The annotation property \'doesNotExist\' is not declared on the annotation type \'java.lang.Deprecated\'.", _function_13);
            };
            final AnnotationReference annotationReference = annotatedTargetElement.addAnnotation(context.newAnnotationReference(Deprecated.class, _function_5));
            annotatedTargetElement.removeAnnotation(annotationReference);
            final Procedure1<AnnotationReferenceBuildContext> _function_6 = (AnnotationReferenceBuildContext it) -> {
                String[] _xblockexpression = null;
                {
                    final String[] array = { "foo" };
                    _xblockexpression = array;
                }
                it.set("value", _xblockexpression);
                final Procedure0 _function_7 = () -> {
                    int[] _xblockexpression_1 = null;
                    {
                        final int[] array = { 1 };
                        _xblockexpression_1 = array;
                    }
                    it.set("value", _xblockexpression_1);
                };
                MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "int[] is not applicable at this location. Expected java.lang.String[]", _function_7);
            };
            final AnnotationReference otherAnnotationReference = annotatedTargetElement.addAnnotation(context.newAnnotationReference(SuppressWarnings.class, _function_6));
            annotatedTargetElement.removeAnnotation(otherAnnotationReference);
            final Procedure1<AnnotationReferenceBuildContext> _function_7 = (AnnotationReferenceBuildContext it) -> {
                it.set("validators", new TypeReference[0]);
                it.set("validators", context.newTypeReference(String.class));
                final Procedure0 _function_8 = () -> {
                    it.set("validators", new String[0]);
                };
                MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "java.lang.String[] is not applicable at this location. Expected org.eclipse.xtend.lib.macro.declaration.TypeReference[]", _function_8);
                final Procedure0 _function_9 = () -> {
                    it.set("validators", new Object[0]);
                };
                MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot set annotation values of type java.lang.Object[]", _function_9);
            };
            final AnnotationReference composedChecksReference = annotatedTargetElement.addAnnotation(context.newAnnotationReference(ComposedChecks.class, _function_7));
            annotatedTargetElement.removeAnnotation(composedChecksReference);
        }
    }
}
Also used : MutableInterfaceDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableInterfaceDeclaration) Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) AnnotationReferenceBuildContext(org.eclipse.xtend.lib.macro.services.AnnotationReferenceBuildContext) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference)

Example 23 with Procedure0

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

the class CheckMutableMethodDeclarationProcessor method doTransform.

@Override
public void doTransform(final MutableMethodDeclaration annotatedMethod, @Extension final TransformationContext context) {
    final Procedure1<String> _function = (String identifier) -> {
        annotatedMethod.addTypeParameter(identifier).remove();
    };
    MutableAssert.assertValidJavaIdentifier("name", _function);
    final Procedure0 _function_1 = () -> {
        annotatedMethod.addTypeParameter("T", ((TypeReference[]) null));
    };
    MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "upperBounds cannot be null", _function_1);
    final Procedure0 _function_2 = () -> {
        annotatedMethod.addTypeParameter("T", new TypeReference[] { null });
    };
    MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "upperBounds cannot contain null", _function_2);
    annotatedMethod.addTypeParameter("T", ((TypeReference[]) Conversions.unwrapArray(CollectionLiterals.<TypeReference>emptyList(), TypeReference.class))).remove();
    final Procedure1<String> _function_3 = (String identifier) -> {
        annotatedMethod.addParameter(identifier, context.newTypeReference(String.class)).remove();
    };
    MutableAssert.assertValidJavaIdentifier("name", _function_3);
    final Procedure0 _function_4 = () -> {
        annotatedMethod.addParameter("foo", null);
    };
    MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "type cannot be null", _function_4);
    final Procedure0 _function_5 = () -> {
        annotatedMethod.setReturnType(null);
    };
    MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "returnType cannot be null", _function_5);
    final Procedure1<String> _function_6 = (String identifier) -> {
        annotatedMethod.setSimpleName(identifier);
    };
    MutableAssert.assertValidJavaIdentifier("name", _function_6);
    final Procedure0 _function_7 = () -> {
        annotatedMethod.setExceptions(null);
    };
    MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "exceptions cannot be null", _function_7);
    final Procedure0 _function_8 = () -> {
        annotatedMethod.setExceptions(new TypeReference[] { null });
    };
    MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "exceptions cannot contain null", _function_8);
    annotatedMethod.setExceptions(((TypeReference[]) Conversions.unwrapArray(CollectionLiterals.<TypeReference>emptyList(), TypeReference.class)));
}
Also used : Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference)

Example 24 with Procedure0

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

the class InferredTypeReferencesCheckProcessor method doTransform.

@Override
public void doTransform(final MutableClassDeclaration it, @Extension final TransformationContext context) {
    final TypeReference type = it.findDeclaredField("foo").getType();
    Assert.assertTrue(type.isInferred());
    final Procedure0 _function = () -> {
        it.setExtendedClass(type);
    };
    MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as extended class.", _function);
    final Procedure0 _function_1 = () -> {
        Iterable<? extends TypeReference> _implementedInterfaces = it.getImplementedInterfaces();
        Iterable<TypeReference> _plus = Iterables.<TypeReference>concat(_implementedInterfaces, Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList(type)));
        it.setImplementedInterfaces(_plus);
    };
    MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as implemented interface.", _function_1);
    final Procedure1<MutableMethodDeclaration> _function_2 = (MutableMethodDeclaration it_1) -> {
        it_1.setReturnType(type);
        final Procedure0 _function_3 = () -> {
            it_1.addParameter("bar", type);
        };
        MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as parameter type.", _function_3);
        final Procedure0 _function_4 = () -> {
            it_1.setExceptions(type);
        };
        MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as exception type.", _function_4);
        final Procedure0 _function_5 = () -> {
            it_1.addTypeParameter("T", type);
        };
        MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as parameter type.", _function_5);
        MutableTypeParameterDeclaration _addTypeParameter = it_1.addTypeParameter("T");
        final Procedure1<MutableTypeParameterDeclaration> _function_6 = (MutableTypeParameterDeclaration it_2) -> {
            final Procedure0 _function_7 = () -> {
                Iterable<? extends TypeReference> _upperBounds = it_2.getUpperBounds();
                Iterable<TypeReference> _plus = Iterables.<TypeReference>concat(_upperBounds, Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList(type)));
                it_2.setUpperBounds(_plus);
            };
            MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as parameter type.", _function_7);
        };
        ObjectExtensions.<MutableTypeParameterDeclaration>operator_doubleArrow(_addTypeParameter, _function_6);
    };
    it.addMethod("bar", _function_2);
    final Procedure1<MutableFieldDeclaration> _function_3 = (MutableFieldDeclaration field) -> {
        field.setType(type);
    };
    it.addField("bar2", _function_3);
    MutableInterfaceDeclaration _findInterface = context.findInterface("Bar");
    final Procedure1<MutableInterfaceDeclaration> _function_4 = (MutableInterfaceDeclaration it_1) -> {
        final Procedure0 _function_5 = () -> {
            Iterable<? extends TypeReference> _extendedInterfaces = it_1.getExtendedInterfaces();
            Iterable<TypeReference> _plus = Iterables.<TypeReference>concat(_extendedInterfaces, Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList(type)));
            it_1.setExtendedInterfaces(_plus);
        };
        MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as extended interface.", _function_5);
        final Procedure0 _function_6 = () -> {
            it_1.addTypeParameter("T", type);
        };
        MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as parameter type.", _function_6);
        MutableTypeParameterDeclaration _addTypeParameter = it_1.addTypeParameter("T");
        final Procedure1<MutableTypeParameterDeclaration> _function_7 = (MutableTypeParameterDeclaration it_2) -> {
            final Procedure0 _function_8 = () -> {
                Iterable<? extends TypeReference> _upperBounds = it_2.getUpperBounds();
                Iterable<TypeReference> _plus = Iterables.<TypeReference>concat(_upperBounds, Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList(type)));
                it_2.setUpperBounds(_plus);
            };
            MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as parameter type.", _function_8);
        };
        ObjectExtensions.<MutableTypeParameterDeclaration>operator_doubleArrow(_addTypeParameter, _function_7);
    };
    ObjectExtensions.<MutableInterfaceDeclaration>operator_doubleArrow(_findInterface, _function_4);
    final Procedure0 _function_5 = () -> {
        it.addTypeParameter("T", type);
    };
    MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as parameter type.", _function_5);
    MutableTypeParameterDeclaration _addTypeParameter = it.addTypeParameter("T");
    final Procedure1<MutableTypeParameterDeclaration> _function_6 = (MutableTypeParameterDeclaration it_1) -> {
        final Procedure0 _function_7 = () -> {
            Iterable<? extends TypeReference> _upperBounds = it_1.getUpperBounds();
            Iterable<TypeReference> _plus = Iterables.<TypeReference>concat(_upperBounds, Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList(type)));
            it_1.setUpperBounds(_plus);
        };
        MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, "Cannot use inferred type as parameter type.", _function_7);
    };
    ObjectExtensions.<MutableTypeParameterDeclaration>operator_doubleArrow(_addTypeParameter, _function_6);
}
Also used : MutableFieldDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration) MutableMethodDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableMethodDeclaration) MutableTypeParameterDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableTypeParameterDeclaration) MutableInterfaceDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableInterfaceDeclaration) Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference)

Example 25 with Procedure0

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

the class MutableAssert method assertValidJavaIdentifier.

public static void assertValidJavaIdentifier(final String name, final Procedure1<? super String> codeToTest) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append(name);
    _builder.append(" has to be a valid java identifier");
    final String message = _builder.toString();
    final Procedure0 _function = () -> {
        codeToTest.apply(null);
    };
    MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, message, _function);
    final Procedure0 _function_1 = () -> {
        codeToTest.apply("  ");
    };
    MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, message, _function_1);
    final Procedure0 _function_2 = () -> {
        codeToTest.apply("456");
    };
    MutableAssert.<IllegalArgumentException>assertThrowable(IllegalArgumentException.class, message, _function_2);
    codeToTest.apply("foo");
}
Also used : Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Aggregations

Procedure0 (org.eclipse.xtext.xbase.lib.Procedures.Procedure0)102 Test (org.junit.Test)79 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)53 AbstractQueuedBuildDataTest (org.eclipse.xtend.ide.tests.builder.AbstractQueuedBuildDataTest)50 AbstractBuilderParticipantTest (org.eclipse.xtext.builder.impl.AbstractBuilderParticipantTest)13 OutputConfiguration (org.eclipse.xtext.generator.OutputConfiguration)13 BadLocationException (org.eclipse.jface.text.BadLocationException)11 IFile (org.eclipse.core.resources.IFile)6 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)6 LocalArgumentsVariable (org.eclipse.n4js.n4JS.LocalArgumentsVariable)5 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)5 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)5 List (java.util.List)4 TypeReference (org.eclipse.xtend.lib.macro.declaration.TypeReference)4 File (java.io.File)3 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)3 Matcher (java.util.regex.Matcher)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 MutableFieldDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration)2 MutableInterfaceDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableInterfaceDeclaration)2