org.eclipse.xtext.xbase.typesystem.references.FunctionTypeReference Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.typesystem.references.FunctionTypeReference.
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: RawTypeConformanceComputer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected int doIsConformant(FunctionTypeReference left, FunctionTypeReference right, int flags) { if (left.getType() == right.getType()) { return flags | SUCCESS; } if ((flags & ALLOW_FUNCTION_CONVERSION) == 0) return flags; // function types can be converted to native function types which will be raw assignable if their // number of parameters matches and the function type kind if (left.getParameterTypes().size() == right.getParameterTypes().size()) { LightweightTypeReference leftReturnType = left.getReturnType(); LightweightTypeReference rightReturnType = right.getReturnType(); if (leftReturnType == rightReturnType) { return flags | SUCCESS; } if (leftReturnType != null && rightReturnType != null && leftReturnType.isPrimitiveVoid() == rightReturnType.isPrimitiveVoid()) { return flags | SUCCESS; } } return flags; }
Example #2
Source File: BatchClosureTypeTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public List<Object> resolvesClosuresTo(String expression, String... types) { List<XClosure> closures = findClosures(expression); Assert.assertFalse(closures.isEmpty()); Assert.assertEquals(types.length, closures.size()); IResolvedTypes resolvedTypes = getTypeResolver().resolveTypes(Iterables.getFirst(closures, null)); List<Object> result = new ArrayList<>(); IterableExtensions.forEach(closures, (XClosure closure, Integer index) -> { LightweightTypeReference closureType = resolvedTypes.getActualType(closure); collector.checkSucceeds(() -> { Assert.assertTrue("failed for closure at " + index + ": " + closureType, closureType instanceof FunctionTypeReference); return null; }); collector.checkSucceeds(() -> { Assert.assertEquals("failed for closure at " + index, types[index], closureType.getSimpleName()); return null; }); result.add(closureType); }); return result; }
Example #3
Source File: ClosureTypeComputerUnitTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testHintsAfterPrepareComputation_01() throws Exception { JvmType iterableType = getTypeForName(Iterable.class, state); JvmTypeParameter typeParameter = createTypeParameter("ELEMENT", state); ParameterizedTypeReference iterableTypeReference = state.getReferenceOwner().newParameterizedTypeReference(iterableType); UnboundTypeReference elementReference = (UnboundTypeReference) createTypeReference(typeParameter, state); iterableTypeReference.addTypeArgument(elementReference); assertTrue(state.getResolvedTypes().getHints(elementReference.getHandle()).isEmpty()); TypeExpectation expectation = new TypeExpectation(iterableTypeReference, state, false); ClosureTypeComputer computer = new ClosureTypeComputer(closure("[|]", getContextResourceSet()), expectation, state); computer.selectStrategy(); FunctionTypeReference closureType = computer.getExpectedClosureType(); assertEquals("java.lang.Iterable.iterator()", computer.getOperation().getIdentifier()); assertEquals("Iterable<Unbound[T]>", getEquivalentSimpleName(closureType)); assertEquals("()=>Iterator<Unbound[T]>", closureType.getSimpleName()); assertEquals(1, state.getResolvedTypes().getHints(elementReference.getHandle()).size()); UnboundTypeReference closureTypeArgument = (UnboundTypeReference) closureType.getTypeArguments().get(0); assertEquals(1, state.getResolvedTypes().getHints(closureTypeArgument.getHandle()).size()); }
Example #4
Source File: ClosureTypeComputerUnitTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testHintsAfterPrepareComputation_02() throws Exception { JvmType iterableType = getTypeForName(Iterable.class, state); JvmType appendableType = getTypeForName(Appendable.class, state); JvmType charSequenceType = getTypeForName(CharSequence.class, state); ParameterizedTypeReference iterableTypeReference = state.getReferenceOwner().newParameterizedTypeReference(iterableType); CompoundTypeReference typeArgument = state.getReferenceOwner().newCompoundTypeReference(false); typeArgument.addComponent(state.getReferenceOwner().newParameterizedTypeReference(appendableType)); typeArgument.addComponent(state.getReferenceOwner().newParameterizedTypeReference(charSequenceType)); iterableTypeReference.addTypeArgument(typeArgument); TypeExpectation expectation = new TypeExpectation(iterableTypeReference, state, false); ClosureTypeComputer computer = new ClosureTypeComputer(closure("[|]", getContextResourceSet()), expectation, state); computer.selectStrategy(); FunctionTypeReference closureType = computer.getExpectedClosureType(); assertEquals("java.lang.Iterable.iterator()", computer.getOperation().getIdentifier()); assertEquals("Iterable<Unbound[T]>", getEquivalentSimpleName(closureType)); assertEquals("()=>Iterator<Unbound[T]>", closureType.getSimpleName()); UnboundTypeReference closureTypeArgument = (UnboundTypeReference) closureType.getTypeArguments().get(0); List<LightweightBoundTypeArgument> hints = state.getResolvedTypes().getHints(closureTypeArgument.getHandle()); assertEquals(hints.toString(), 1, hints.size()); }
Example #5
Source File: ClosureTypeComputerUnitTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testHintsAfterPrepareComputation_03() throws Exception { JvmType iterableType = getTypeForName(Iterable.class, state); JvmType appendableType = getTypeForName(Appendable.class, state); JvmType charSequenceType = getTypeForName(CharSequence.class, state); ParameterizedTypeReference iterableTypeReference = state.getReferenceOwner().newParameterizedTypeReference(iterableType); WildcardTypeReference typeArgument = state.getReferenceOwner().newWildcardTypeReference(); typeArgument.addUpperBound(state.getReferenceOwner().newParameterizedTypeReference(appendableType)); typeArgument.addUpperBound(state.getReferenceOwner().newParameterizedTypeReference(charSequenceType)); iterableTypeReference.addTypeArgument(typeArgument); TypeExpectation expectation = new TypeExpectation(iterableTypeReference, state, false); ClosureTypeComputer computer = new ClosureTypeComputer(closure("[|]", getContextResourceSet()), expectation, state); computer.selectStrategy(); FunctionTypeReference closureType = computer.getExpectedClosureType(); assertEquals("java.lang.Iterable.iterator()", computer.getOperation().getIdentifier()); assertEquals("Iterable<Unbound[T]>", getEquivalentSimpleName(closureType)); assertEquals("()=>Iterator<Unbound[T]>", closureType.getSimpleName()); UnboundTypeReference closureTypeArgument = (UnboundTypeReference) closureType.getTypeArguments().get(0); List<LightweightBoundTypeArgument> hints = state.getResolvedTypes().getHints(closureTypeArgument.getHandle()); assertEquals(hints.toString(), 2, hints.size()); }
Example #6
Source File: HumanReadableTypeNames.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override protected void doVisitFunctionTypeReference(FunctionTypeReference reference, StringBuilder param) { param.append("("); List<LightweightTypeReference> parameterTypes = reference.getParameterTypes(); for(int i = 0; i < parameterTypes.size(); i++) { if (i != 0) { param.append(", "); } parameterTypes.get(i).accept(this, param); } param.append(")=>"); if (reference.getReturnType() != null) { reference.getReturnType().accept(this, param); } else { param.append("./."); } }
Example #7
Source File: RawTypeConformanceComputer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected int doIsConformant(FunctionTypeReference left, ParameterizedTypeReference right, int flags) { if ((flags & ALLOW_FUNCTION_CONVERSION) == 0) return doIsConformant((ParameterizedTypeReference) left, right, flags); FunctionTypeReference convertedRight = right.getAsFunctionTypeReference(); if (convertedRight != null) { return doIsConformant(left, convertedRight, flags); } if (left.isFunctionType()) { convertedRight = right.tryConvertToFunctionTypeReference(false); if (convertedRight != null) { int result = doIsConformant(left, convertedRight, flags); if ((result & SUCCESS) != 0) { return result | DEMAND_CONVERSION; } } } return doIsConformant((ParameterizedTypeReference) left, right, flags); }
Example #8
Source File: RawTypeConformanceComputer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected int doIsConformant(ParameterizedTypeReference left, FunctionTypeReference right, int flags) { if ((flags & ALLOW_FUNCTION_CONVERSION) == 0) return doIsConformant(left, (ParameterizedTypeReference) right, flags); // TODO don't convert if not necessary: // right.getType == left.getType -> doIsConformant optimized to function types -> declarator == procedure, ignore return type etc // next: get function type kind and arity of right and check against left if it is a function type // afterwards, do optimized check of left against the argument types of right FunctionTypeReference convertedLeft = left.getAsFunctionTypeReference(); if (convertedLeft != null) { return doIsConformant(convertedLeft, right, flags); } if (right.isFunctionType()) { // todo optimize tryConvertToFunctionTypeReference convertedLeft = left.tryConvertToFunctionTypeReference(false); if (convertedLeft != null) { int result = doIsConformant(convertedLeft, right, flags); if ((result & SUCCESS) != 0) { return result | DEMAND_CONVERSION; } } } return doIsConformant(left, (ParameterizedTypeReference) right, flags); }
Example #9
Source File: TypeConformanceComputer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected LightweightTypeReference conformsToAll(LightweightTypeReference type, List<LightweightTypeReference> types) { LightweightTypeReference result = type; for (int i = 0; i < types.size(); i++) { LightweightTypeReference other = types.get(i); if (result != other) { // if we stumble across unbound references without any hints, assume they are compatible and add respective hints int conformance = isConformant(result, other, ALLOW_BOXING | ALLOW_PRIMITIVE_WIDENING | ALLOW_FUNCTION_CONVERSION | UNBOUND_COMPUTATION_ADDS_HINTS | ALLOW_RAW_TYPE_CONVERSION); if ((conformance & SUCCESS) != 0) { boolean resultIsFunctionType = result instanceof FunctionTypeReference; if (!resultIsFunctionType && (other instanceof FunctionTypeReference) && other.isAssignableFrom(result)) { result = other; } } else { return null; } } } return result; }
Example #10
Source File: TypeConformanceComputer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected LightweightTypeReference doGetTypeParametersForSuperType( final Multimap<JvmType, LightweightTypeReference> all, JvmGenericType rawType, ITypeReferenceOwner owner, List<LightweightTypeReference> types) { // if we do not declare any parameters it is safe to return the first candidate if (!hasTypeParameters(rawType)) { return getFirstForRawType(all, rawType); } ParameterizedTypeReference result = owner.newParameterizedTypeReference(rawType); pushRequestedTypes(types); if (!enhanceSuperType(Lists.newArrayList(all.get(rawType)), result)) { return null; } FunctionTypeReference resultAsFunctionType = result.getAsFunctionTypeReference(); if (resultAsFunctionType != null) return resultAsFunctionType; return result; }
Example #11
Source File: LightweightTypeReferenceSerializerTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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 #12
Source File: LightweightTypeReferenceSerializerTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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 #13
Source File: SourceAppenderWithTypeMapping.java From sarl with Apache License 2.0 | 6 votes |
@Override public ISourceAppender append(LightweightTypeReference typeRef) { if (typeRef.isFunctionType()) { final FunctionTypeReference functionReference = typeRef.getAsFunctionTypeReference(); this.source.append(this.keywords.getLeftParenthesisKeyword()); boolean first = true; for (final LightweightTypeReference parameter : functionReference.getParameterTypes()) { if (first) { first = false; } else { this.source.append(","); //$NON-NLS-1$ } append(parameter); } this.source.append(this.keywords.getRightParenthesisKeyword()); this.source.append(this.keywords.getEqualsSignGreaterThanSignKeyword()); append(functionReference.getReturnType()); return this; } this.source.append(typeRef); return this; }
Example #14
Source File: LightweightTypeReferenceSerializerTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@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 #15
Source File: XbaseCompiler.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
private LightweightTypeReference findRealReturnType(XExpression expression) { if (expression == null) return null; JvmIdentifiableElement logicalContainer = getLogicalContainerProvider().getLogicalContainer(expression); if (logicalContainer instanceof JvmOperation) { return getLightweightType(logicalContainer); } if (expression instanceof XClosure) { IResolvedTypes resolvedTypes = batchTypeResolver.resolveTypes(expression); LightweightTypeReference type = resolvedTypes.getExpectedType(expression); if (type == null) { type = resolvedTypes.getActualType(expression); } if (type == null) { return null; } FunctionTypeReference functionType = type.tryConvertToFunctionTypeReference(false); if (functionType != null) { return functionType.getReturnType(); } return null; } XExpression containerExpression = EcoreUtil2.getContainerOfType(expression.eContainer(), XExpression.class); if (containerExpression == null) { LightweightTypeReference returnType = getLightweightReturnType(expression); return returnType; } return findRealReturnType(containerExpression); }
Example #16
Source File: LightweightTypeReferenceSerializerTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@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 #17
Source File: LightweightTypeReferenceSerializerTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@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 #18
Source File: LightweightTypeReferenceSerializerTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testFunctionType1() { FunctionTypeReference _newFunctionTypeReference = this.getOwner().newFunctionTypeReference(this.type(Function0.class)); final Procedure1<FunctionTypeReference> _function = (FunctionTypeReference it) -> { it.setReturnType(this.typeRef(String.class)); it.addTypeArgument(this.typeRef(String.class)); }; this.assertInJava(this.assertInXtend(ObjectExtensions.<FunctionTypeReference>operator_doubleArrow(_newFunctionTypeReference, _function), "()=>java.lang.String"), "org.eclipse.xtext.xbase.lib.Functions$Function0<java.lang.String>"); }
Example #19
Source File: AbstractClosureTypeTest2.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public void withEquivalents(final List<Object> references, final String... types) { final Procedure2<Object, Integer> _function = (Object reference, Integer index) -> { final Callable<Object> _function_1 = () -> { Assert.assertTrue((reference instanceof FunctionTypeReference)); return null; }; this.collector.<Object>checkSucceeds(_function_1); final Callable<Object> _function_2 = () -> { Assert.assertEquals(types[(index).intValue()], this.getEquivalent(((FunctionTypeReference) reference))); return null; }; this.collector.<Object>checkSucceeds(_function_2); }; IterableExtensions.<Object>forEach(references, _function); }
Example #20
Source File: LightweightTypeReferenceSerializerTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@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"); }
Example #21
Source File: ClosureTypeComputerUnitTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected String getEquivalentSimpleName(LightweightTypeReference type) { assertTrue("Expected FunctionTypeRef but was: " + type.getSimpleName(), type instanceof FunctionTypeReference); // NPE would be ok here since the test would fail String typeSimpleName = type.getType().getSimpleName(); List<LightweightTypeReference> typeArguments = ((ParameterizedTypeReference) type).getTypeArguments(); if (typeArguments.isEmpty()) return typeSimpleName; return typeSimpleName + "<" + Joiner.on(", ").join(Iterables.transform(typeArguments, LightweightTypeReference.SimpleNameFunction.INSTANCE)) + ">"; }
Example #22
Source File: LightweightTypeReferenceSerializerTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testFunctionType10() { FunctionTypeReference _newFunctionTypeReference = this.getOwner().newFunctionTypeReference(this.type(Iterable.class)); final Procedure1<FunctionTypeReference> _function = (FunctionTypeReference it) -> { it.addTypeArgument(this.typeRef(String.class)); ParameterizedTypeReference _typeRef = this.typeRef(Iterator.class); final Procedure1<ParameterizedTypeReference> _function_1 = (ParameterizedTypeReference it_1) -> { it_1.addTypeArgument(this.typeRef(String.class)); }; ParameterizedTypeReference _doubleArrow = ObjectExtensions.<ParameterizedTypeReference>operator_doubleArrow(_typeRef, _function_1); it.setReturnType(_doubleArrow); }; this.assertInJava(this.assertInXtend(ObjectExtensions.<FunctionTypeReference>operator_doubleArrow(_newFunctionTypeReference, _function), "()=>java.util.Iterator<java.lang.String>"), "java.lang.Iterable<java.lang.String>"); }
Example #23
Source File: XtypeProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected LightweightTypeReferenceFactory getTypeConverter(XtextResource context) { return new LightweightTypeReferenceFactory(new StandardTypeReferenceOwner(services, context)) { @Override public LightweightTypeReference doVisitParameterizedTypeReference(JvmParameterizedTypeReference reference) { LightweightTypeReference result = super.doVisitParameterizedTypeReference(reference); if (result.isFunctionType()) { FunctionTypeReference functionTypeReference = result.tryConvertToFunctionTypeReference(false); return functionTypeReference; } return result; } }; }
Example #24
Source File: ExtensionAwareClosureTypeComputer.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override protected ClosureWithoutExpectationHelper createClosureWithoutExpectationHelper() { return new ClosureWithoutExpectationHelper(getClosure(), getExpectation(), getState()) { @Override protected ITypeComputationState assignParameters(ITypeAssigner typeAssigner, FunctionTypeReference incompleteClosureType) { ITypeComputationState result = super.assignParameters(typeAssigner, incompleteClosureType); addExtensions(result); return result; } }; }
Example #25
Source File: ClosureWithoutExpectationHelper.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected void computeTypes() { FunctionTypeReference incompleteClosureType = getFunctionTypeReference(true); ITypeAssigner typeAssigner = getState().withoutRootExpectation().assignTypes(); ITypeComputationState closureBodyTypeComputationState = getClosureBodyTypeComputationState(typeAssigner, incompleteClosureType); ITypeComputationResult expressionResult = closureBodyTypeComputationState.computeTypes(getClosure().getExpression()); FunctionTypeReference resultClosureType = processExpressionType(incompleteClosureType, expressionResult); getExpectation().acceptActualType(resultClosureType, ConformanceFlags.UNCHECKED); }
Example #26
Source File: TypeParameterSubstitutor.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
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 #27
Source File: TypeParameterSubstitutor.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected LightweightTypeReference doVisitFunctionTypeReference(FunctionTypeReference reference, Visiting visiting) { if (reference.isResolved() && reference.isOwnedBy(getOwner())) return reference; FunctionTypeReference result = getOwner().newFunctionTypeReference(reference.getType()); enhanceFunctionType(reference, result, visiting); return result; }
Example #28
Source File: ClosureWithoutExpectationHelper.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
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 #29
Source File: ClosureTypeComputer.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * This method is only public for testing purpose. * * @noreference This method is not intended to be referenced by clients. */ /* @Nullable */ public FunctionTypeReference getExpectedClosureType() { if (strategy == null) selectStrategy(); return strategy.getExpectedClosureType(); }
Example #30
Source File: BatchClosureTypeTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public void withEquivalents(List<Object> references, String... types) { IterableExtensions.forEach(references, (Object reference, Integer index) -> { collector.checkSucceeds(() -> { Assert.assertTrue(reference instanceof FunctionTypeReference); return null; }); collector.checkSucceeds(() -> { Assert.assertEquals(types[index], getEquivalent((FunctionTypeReference) reference)); return null; }); }); }