Java Code Examples for org.eclipse.xtext.xbase.typesystem.references.FunctionTypeReference#addParameterType()

The following examples show how to use org.eclipse.xtext.xbase.typesystem.references.FunctionTypeReference#addParameterType() . 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: 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 3
Source File: ClosureWithoutExpectationHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected FunctionTypeReference processExpressionType(FunctionTypeReference incompleteClosureType, ITypeComputationResult expressionResult) {
	LightweightTypeReference expressionResultType = expressionResult.getReturnType();
	if (expressionResultType == null || !expressionResultType.isPrimitiveVoid()) {
		FunctionTypeReference result = getFunctionTypeReference(false);
		LightweightTypeReference expectedReturnType = result.getTypeArguments().get(result.getTypeArguments().size() - 1);
		if (expressionResultType != null && !expressionResultType.isAny()) {
			result.setReturnType(expressionResultType);
			deferredBindTypeArgument(expectedReturnType, expressionResultType, BoundTypeArgumentSource.INFERRED);
		} else {
			LightweightTypeReference objectTypeReference = incompleteClosureType.getOwner().newReferenceToObject();
			result.setReturnType(objectTypeReference);
			deferredBindTypeArgument(expectedReturnType, objectTypeReference, BoundTypeArgumentSource.INFERRED);
		}
		List<LightweightTypeReference> incompleteParameterTypes = incompleteClosureType.getParameterTypes();
		for(int i = 0; i < incompleteParameterTypes.size(); i++) {
			result.addParameterType(incompleteParameterTypes.get(i));
		}
		List<LightweightTypeReference> incompleteTypeArguments = incompleteClosureType.getTypeArguments();
		List<LightweightTypeReference> resultTypeArguments = result.getTypeArguments();
		for(int i = 0; i < incompleteTypeArguments.size(); i++) {
			deferredBindTypeArgument(resultTypeArguments.get(i), incompleteTypeArguments.get(i), BoundTypeArgumentSource.INFERRED);
		}
		return result;
	} else {
		incompleteClosureType.setReturnType(expressionResultType);
		return incompleteClosureType;
	}
}
 
Example 4
Source File: TypeParameterSubstitutor.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void enhanceFunctionType(FunctionTypeReference reference, FunctionTypeReference result, Visiting visiting) {
	for(LightweightTypeReference parameterType: reference.getParameterTypes()) {
		result.addParameterType(visitTypeArgument(parameterType, visiting, true));
	}
	for(LightweightTypeReference typeArgument: reference.getTypeArguments()) {
		result.addTypeArgument(visitTypeArgument(typeArgument, visiting));
	}
	LightweightTypeReference returnType = reference.getReturnType();
	if (returnType != null) {
		result.setReturnType(visitTypeArgument(returnType, visiting));
	}
}
 
Example 5
Source File: LightweightTypeReferenceSerializerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testFunctionType2() {
  FunctionTypeReference _newFunctionTypeReference = this.getOwner().newFunctionTypeReference(this.type(Function1.class));
  final Procedure1<FunctionTypeReference> _function = (FunctionTypeReference it) -> {
    it.addParameterType(this.typeRef(String.class));
    it.addTypeArgument(this.typeRef(Void.class));
    it.addTypeArgument(this.typeRef(String.class));
  };
  this.assertInJava(this.assertInXtend(ObjectExtensions.<FunctionTypeReference>operator_doubleArrow(_newFunctionTypeReference, _function), "(java.lang.String)=>void"), "org.eclipse.xtext.xbase.lib.Functions$Function1<java.lang.Void, java.lang.String>");
}
 
Example 6
Source File: LightweightTypeReferenceSerializerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testFunctionType3() {
  FunctionTypeReference _newFunctionTypeReference = this.getOwner().newFunctionTypeReference(this.type(Function1.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));
  };
  this.assertInJava(this.assertInXtend(ObjectExtensions.<FunctionTypeReference>operator_doubleArrow(_newFunctionTypeReference, _function), "(java.lang.String)=>java.lang.Object"), "org.eclipse.xtext.xbase.lib.Functions$Function1<java.lang.Object, java.lang.String>");
}
 
Example 7
Source File: LightweightTypeReferenceSerializerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testFunctionType6() {
  FunctionTypeReference _newFunctionTypeReference = this.getOwner().newFunctionTypeReference(this.type(Procedure1.class));
  final Procedure1<FunctionTypeReference> _function = (FunctionTypeReference it) -> {
    it.addParameterType(this.typeRef(String.class));
    it.addTypeArgument(this.typeRef(String.class));
  };
  this.assertInJava(this.assertInXtend(ObjectExtensions.<FunctionTypeReference>operator_doubleArrow(_newFunctionTypeReference, _function), "(java.lang.String)=>void"), "org.eclipse.xtext.xbase.lib.Procedures$Procedure1<java.lang.String>");
}
 
Example 8
Source File: LightweightTypeReferenceSerializerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testFunctionType9() {
  FunctionTypeReference _newFunctionTypeReference = this.getOwner().newFunctionTypeReference(this.type(Readable.class));
  final Procedure1<FunctionTypeReference> _function = (FunctionTypeReference it) -> {
    it.addParameterType(this.typeRef(CharBuffer.class));
    it.setReturnType(this.typeRef(Integer.TYPE));
  };
  this.assertInJava(this.assertInXtend(ObjectExtensions.<FunctionTypeReference>operator_doubleArrow(_newFunctionTypeReference, _function), "(java.nio.CharBuffer)=>int"), "java.lang.Readable");
}