org.eclipse.xtext.xbase.lib.Procedures.Procedure3 Java Examples

The following examples show how to use org.eclipse.xtext.xbase.lib.Procedures.Procedure3. 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 testFunctionType7() {
  FunctionTypeReference _newFunctionTypeReference = this.getOwner().newFunctionTypeReference(this.type(Procedure3.class));
  final Procedure1<FunctionTypeReference> _function = (FunctionTypeReference it) -> {
    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[])=>void"), "org.eclipse.xtext.xbase.lib.Procedures$Procedure3<java.lang.String, java.util.List<? super java.lang.CharSequence>, java.lang.Object[]>");
}
 
Example #2
Source File: ProcedureExtensions.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Curries a procedure that takes three arguments.
 * 
 * @param procedure
 *            the original procedure. May not be <code>null</code>.
 * @param argument
 *            the fixed first argument of {@code procedure}.
 * @return a procedure that takes two arguments. Never <code>null</code>.
 */
@Pure
public static <P1, P2, P3> Procedure2<P2, P3> curry(final Procedure3<? super P1, ? super P2, ? super P3> procedure, final P1 argument) {
	if (procedure == null)
		throw new NullPointerException("procedure");
	return new Procedure2<P2, P3>() {
		@Override
		public void apply(P2 p2, P3 p3) {
			procedure.apply(argument, p2, p3);
		}
	};
}
 
Example #3
Source File: ProcedureExtensions.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Curries a procedure that takes four arguments.
 * 
 * @param procedure
 *            the original procedure. May not be <code>null</code>.
 * @param argument
 *            the fixed first argument of {@code procedure}.
 * @return a procedure that takes three arguments. Never <code>null</code>.
 */
@Pure
public static <P1, P2, P3, P4> Procedure3<P2, P3, P4> curry(final Procedure4<? super P1, ? super P2, ? super P3, ? super P4> procedure,
		final P1 argument) {
	if (procedure == null)
		throw new NullPointerException("procedure");
	return new Procedure3<P2, P3, P4>() {
		@Override
		public void apply(P2 p2, P3 p3, P4 p4) {
			procedure.apply(argument, p2, p3, p4);
		}
	};
}
 
Example #4
Source File: MapExtensions.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Applies the given {@code procedure} for each {@link java.util.Map.Entry key value pair} of the given {@code map}. 
 * The procedure takes the key, the value and a loop counter. If the counter would overflow, {@link Integer#MAX_VALUE}
 * is returned for all subsequent pairs. The first pair is at index zero.
 * 
 * @param map
 *            the map. May not be <code>null</code>.
 * @param procedure
 *            the procedure. May not be <code>null</code>.
 */
public static <K, V> void forEach(Map<K, V> map, Procedure3<? super K, ? super V, ? super Integer> procedure) {
	if (procedure == null)
		throw new NullPointerException("procedure");
	int i = 0;
	for (Map.Entry<K, V> entry : map.entrySet()) {
		procedure.apply(entry.getKey(), entry.getValue(), i);
		if (i != Integer.MAX_VALUE)
			i++;
	}
}
 
Example #5
Source File: AbstractExtraLanguageValidator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Do a type mapping check.
 *
 * @param source the source of the type.
 * @param type the type to check.
 * @param errorHandler the error handler.
 * @return {@code true} if a type mapping is defined.
 */
protected boolean doTypeMappingCheck(EObject source, JvmType type, Procedure3<? super EObject, ? super JvmType, ? super String> errorHandler) {
	if (source != null && type != null) {
		final ExtraLanguageTypeConverter converter = getTypeConverter();
		final String qn = type.getQualifiedName();
		if (converter != null && !converter.hasConversion(qn)) {
			if (errorHandler != null) {
				errorHandler.apply(source, type, qn);
			}
			return false;
		}
	}
	return true;
}
 
Example #6
Source File: AbstractExtraLanguageValidator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Check if the feature call could be translated to the extra-language.
 *
 * @param featureCall the feature call.
 * @param typeErrorHandler the error handler for the type conversion.
 * @param featureErrorHandler the error handler for the feature call conversion.
 */
protected void doCheckMemberFeatureCallMapping(XAbstractFeatureCall featureCall,
		Procedure3<? super EObject, ? super JvmType, ? super String> typeErrorHandler,
		Function2<? super EObject, ? super JvmIdentifiableElement, ? extends Boolean> featureErrorHandler) {
	final XAbstractFeatureCall rootFeatureCall = Utils.getRootFeatureCall(featureCall);
	final Map<Object, Object> context = getContext().getContext();
	if (isCheckedFeatureCall(context, rootFeatureCall)) {
		// One of the containing expressions was already checked.
		return;
	}
	// Mark the root container as validated.
	setCheckedFeatureCall(context, rootFeatureCall);
	// Validate the current call.
	internalCheckMemberFeaturCallMapping(rootFeatureCall, typeErrorHandler, featureErrorHandler);
}
 
Example #7
Source File: AbstractExtraLanguageValidator.java    From sarl with Apache License 2.0 5 votes vote down vote up
private boolean internalCheckMemberFeaturCallMapping(XAbstractFeatureCall featureCall,
		Procedure3<? super EObject, ? super JvmType, ? super String> typeErrorHandler,
		Function2<? super EObject, ? super JvmIdentifiableElement, ? extends Boolean> featureErrorHandler) {
	final ExtraLanguageFeatureNameConverter converter = getFeatureNameConverter();
	if (converter != null) {
		final ConversionType conversionType = converter.getConversionTypeFor(featureCall);
		switch (conversionType) {
		case EXPLICIT:
			return true;
		case IMPLICIT:
			final JvmIdentifiableElement element = featureCall.getFeature();
			if (element instanceof JvmType) {
				return doTypeMappingCheck(featureCall, (JvmType) element, typeErrorHandler);
			}
			if (featureCall instanceof XMemberFeatureCall) {
				final XMemberFeatureCall memberFeatureCall = (XMemberFeatureCall) featureCall;
				final XExpression receiver = memberFeatureCall.getMemberCallTarget();
				if (receiver instanceof XMemberFeatureCall || receiver instanceof XFeatureCall) {
					internalCheckMemberFeaturCallMapping(
							(XAbstractFeatureCall) receiver,
							typeErrorHandler,
							featureErrorHandler);
				}
			}
			break;
		case FORBIDDEN_CONVERSION:
		default:
			if (featureErrorHandler != null) {
				return !featureErrorHandler.apply(featureCall, featureCall.getFeature());
			}
			return false;
		}
	}
	return true;
}
 
Example #8
Source File: IExtraLanguageConversionInitializer.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Initialize the conversions mapping.
 *
 * @param result the function to invoke for initializing the element.
 *     The first formal parameter is the simple name of the source.
 *     The second formal parameter is the full name of source of the conversion.
 *     The third formal parameter is the target of the conversion.
 */
void initializeConversions(Procedure3<? super String, ? super String, ? super String> result);