org.eclipse.xtext.xbase.lib.Functions.Function3 Java Examples

The following examples show how to use org.eclipse.xtext.xbase.lib.Functions.Function3. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LightweightTypeReferenceSerializerTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testFunctionType4() {
  FunctionTypeReference _newFunctionTypeReference = this.getOwner().newFunctionTypeReference(this.type(Function3.class));
  final Procedure1<FunctionTypeReference> _function = (FunctionTypeReference it) -> {
    it.setReturnType(this.typeRef(Object.class));
    it.addTypeArgument(this.typeRef(Object.class));
    it.addParameterType(this.typeRef(String.class));
    it.addTypeArgument(this.typeRef(String.class));
    ParameterizedTypeReference _typeRef = this.typeRef(List.class);
    final Procedure1<ParameterizedTypeReference> _function_1 = (ParameterizedTypeReference it_1) -> {
      WildcardTypeReference _newWildcardTypeReference = it_1.getOwner().newWildcardTypeReference();
      final Procedure1<WildcardTypeReference> _function_2 = (WildcardTypeReference it_2) -> {
        it_2.setLowerBound(this.typeRef(CharSequence.class));
      };
      WildcardTypeReference _doubleArrow = ObjectExtensions.<WildcardTypeReference>operator_doubleArrow(_newWildcardTypeReference, _function_2);
      it_1.addTypeArgument(_doubleArrow);
    };
    final ParameterizedTypeReference listOfCharSequence = ObjectExtensions.<ParameterizedTypeReference>operator_doubleArrow(_typeRef, _function_1);
    it.addParameterType(listOfCharSequence);
    it.addTypeArgument(listOfCharSequence);
    final ArrayTypeReference arrayOfObject = it.getOwner().newArrayTypeReference(this.typeRef(Object.class));
    it.addParameterType(arrayOfObject);
    it.addTypeArgument(arrayOfObject);
  };
  this.assertInJava(this.assertInXtend(ObjectExtensions.<FunctionTypeReference>operator_doubleArrow(_newFunctionTypeReference, _function), "(java.lang.String, java.util.List<? super java.lang.CharSequence>, java.lang.Object[])=>java.lang.Object"), "org.eclipse.xtext.xbase.lib.Functions$Function3<java.lang.Object, java.lang.String, java.util.List<? super java.lang.CharSequence>, java.lang.Object[]>");
}
 
Example #2
Source File: JvmTypesBuilderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testInitializeSafely_0() {
  final Runnable _function = () -> {
    final Function3<EObject, String, Procedure1<? super JvmGenericType>, EObject> _function_1 = (EObject expr, String name, Procedure1<? super JvmGenericType> init) -> {
      return this._jvmTypesBuilder.toClass(expr, name, init);
    };
    this.<JvmGenericType>genericTestInitializeSafely(_function_1);
  };
  this.expectErrorLogging(2, _function);
}
 
Example #3
Source File: JvmTypesBuilderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testInitializeSafely_1() {
  final Runnable _function = () -> {
    final Function3<EObject, String, Procedure1<? super JvmConstructor>, EObject> _function_1 = (EObject expr, String name, Procedure1<? super JvmConstructor> init) -> {
      return this._jvmTypesBuilder.toConstructor(expr, init);
    };
    this.<JvmConstructor>genericTestInitializeSafely(_function_1);
  };
  this.expectErrorLogging(2, _function);
}
 
Example #4
Source File: JvmTypesBuilderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testInitializeSafely_2() {
  final Runnable _function = () -> {
    final Function3<EObject, String, Procedure1<? super JvmField>, EObject> _function_1 = (EObject expr, String name, Procedure1<? super JvmField> init) -> {
      return this._jvmTypesBuilder.toField(expr, name, null, init);
    };
    this.<JvmField>genericTestInitializeSafely(_function_1);
  };
  this.expectErrorLogging(2, _function);
}
 
Example #5
Source File: JvmTypesBuilderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testInitializeSafely_3() {
  final Runnable _function = () -> {
    final Function3<EObject, String, Procedure1<? super JvmOperation>, EObject> _function_1 = (EObject expr, String name, Procedure1<? super JvmOperation> init) -> {
      return this._jvmTypesBuilder.toMethod(expr, name, null, init);
    };
    this.<JvmOperation>genericTestInitializeSafely(_function_1);
  };
  this.expectErrorLogging(2, _function);
}
 
Example #6
Source File: JvmTypesBuilderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testInitializeSafely_4() {
  final Runnable _function = () -> {
    final Function3<EObject, String, Procedure1<? super JvmAnnotationType>, EObject> _function_1 = (EObject expr, String name, Procedure1<? super JvmAnnotationType> init) -> {
      return this._jvmTypesBuilder.toAnnotationType(expr, name, init);
    };
    this.<JvmAnnotationType>genericTestInitializeSafely(_function_1);
  };
  this.expectErrorLogging(2, _function);
}
 
Example #7
Source File: JvmTypesBuilderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testInitializeSafely_5() {
  final Runnable _function = () -> {
    final Function3<EObject, String, Procedure1<? super JvmEnumerationType>, EObject> _function_1 = (EObject expr, String name, Procedure1<? super JvmEnumerationType> init) -> {
      return this._jvmTypesBuilder.toEnumerationType(expr, name, init);
    };
    this.<JvmEnumerationType>genericTestInitializeSafely(_function_1);
  };
  this.expectErrorLogging(2, _function);
}
 
Example #8
Source File: JvmTypesBuilderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected <T extends Object> void genericTestInitializeSafely(final Function3<? super EObject, ? super String, ? super Procedure1<? super T>, ? extends EObject> create) {
  final XNullLiteral expr = XbaseFactory.eINSTANCE.createXNullLiteral();
  final Wrapper<Boolean> initialized = new Wrapper<Boolean>(Boolean.valueOf(false));
  final Procedure1<T> _function = (T it) -> {
    initialized.set(Boolean.valueOf(true));
    throw new RuntimeException();
  };
  final EObject element = create.apply(expr, "foo", _function);
  Assert.assertTrue((initialized.get()).booleanValue());
  Assert.assertNotNull(element);
}
 
Example #9
Source File: FunctionExtensions.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Curries a function that takes three arguments.
 * 
 * @param function
 *            the original function. May not be <code>null</code>.
 * @param argument
 *            the fixed first argument of {@code function}.
 * @return a function that takes two arguments. Never <code>null</code>.
 */
@Pure
public static <P1, P2, P3, RESULT> Function2<P2, P3, RESULT> curry(final Function3<? super P1, ? super P2, ? super P3, ? extends RESULT> function,
		final P1 argument) {
	if (function == null)
		throw new NullPointerException("function");
	return new Function2<P2, P3, RESULT>() {
		@Override
		public RESULT apply(P2 p2, P3 p3) {
			return function.apply(argument, p2, p3);
		}
	};
}
 
Example #10
Source File: FunctionExtensions.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Curries a function that takes four arguments.
 * 
 * @param function
 *            the original function. May not be <code>null</code>.
 * @param argument
 *            the fixed first argument of {@code function}.
 * @return a function that takes three arguments. Never <code>null</code>.
 */
@Pure
public static <P1, P2, P3, P4, RESULT> Function3<P2, P3, P4, RESULT> curry(
		final Function4<? super P1, ? super P2, ? super P3, ? super P4, ? extends RESULT> function, final P1 argument) {
	if (function == null)
		throw new NullPointerException("function");
	return new Function3<P2, P3, P4, RESULT>() {
		@Override
		public RESULT apply(P2 p2, P3 p3, P4 p4) {
			return function.apply(argument, p2, p3, p4);
		}
	};
}
 
Example #11
Source File: FactExtensions.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the first declared field matching with the given marcher.
 *
 * @param type the type to check.
 * @param matcher the matcher.
 * @return the validation status.
 */
public static Field findField(Class<?> type, Function3<Class<?>, Field, Boolean, Boolean> matcher) {
	if (matcher != null) {
		for (final Field field : type.getDeclaredFields()) {
			final Deprecated deprecatedAnnotation = field.getAnnotation(Deprecated.class);
			final boolean deprecated = deprecatedAnnotation != null;
			if (matcher.apply(type, field, deprecated)) {
				return field;
			}
		}
	}
	return null;
}
 
Example #12
Source File: FactExtensions.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Success if each of the declared fields is matching with the given marcher.
 *
 * @param type the type to check.
 * @param matcher the matcher.
 * @return the validation status.
 */
public static boolean allFields(Class<?> type, Function3<Class<?>, Field, Boolean, Boolean> matcher) {
	if (matcher != null) {
		for (final Field field : type.getDeclaredFields()) {
			final Deprecated deprecatedAnnotation = field.getAnnotation(Deprecated.class);
			final boolean deprecated = deprecatedAnnotation != null;
			if (!matcher.apply(type, field, deprecated)) {
				return false;
			}
		}
	}
	return true;
}