private IType extractReturnTypeFromInterface( IType target ) { IFunctionType funcType = target.getFunctionalInterface(); return funcType == null ? null : funcType.getReturnType(); }
public Object coerceValue( IType typeToCoerceTo, Object value ) { return BlockWrapper.toBlock( (FeatureReference)value, ((IFunctionType)typeToCoerceTo).getReturnType() != JavaTypes.pVOID() ); }
@Override public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { if( IBlockClass.INVOKE_METHOD_NAME.equals( method.getName() ) ) { Object val = finalInvoke.invoke( blk, args ); return CommonServices.getCoercionManager().convertValue( val, funType.getReturnType() ); } else if( IBlockClass.INVOKE_WITH_ARGS_METHOD_NAME.equals( method.getName() ) ) { Object val = blk.invokeWithArgs( (Object[]) args[0] ); return CommonServices.getCoercionManager().convertValue( val, funType.getReturnType() ); } else { return method.invoke( blk, args ); } } } );
@Override public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { if( IBlockClass.INVOKE_METHOD_NAME.equals( method.getName() ) ) { Object val = finalInvoke.invoke( blk, args ); return CommonServices.getCoercionManager().convertValue( val, funType.getReturnType() ); } else if( IBlockClass.INVOKE_WITH_ARGS_METHOD_NAME.equals( method.getName() ) ) { Object val = blk.invokeWithArgs( (Object[]) args[0] ); return CommonServices.getCoercionManager().convertValue( val, funType.getReturnType() ); } else { return method.invoke( blk, args ); } } } );
private List<? extends IInvocableType> maybeAvoidNestedMethodScoring( List<? extends IInvocableType> listFunctionTypes ) { if( listFunctionTypes.size() < 2 ) { return listFunctionTypes; } if( !getContextType().isMethodScoring() ) { // Not nested in a method score return listFunctionTypes; } IType retType = null; for( IInvocableType funcType: listFunctionTypes ) { if( !(funcType instanceof IFunctionType) ) { return listFunctionTypes; } IType csr = ((IFunctionType)funcType).getReturnType(); if( retType != null && csr != retType ) { // functions have different return types, must score methods here to find correct type for enclosing method score return listFunctionTypes; } retType = csr; } // Return types are all the same, no need to perform nested method scoring, so only parse against one of them return Collections.singletonList( listFunctionTypes.get( 0 ) ); }
private IType getReturnType() { IType retType = ((IFunctionType)getType()).getReturnType(); if( retType != JavaTypes.pVOID() && _mi instanceof IJavaMethodInfo ) { retType = _mi.getReturnType(); } return retType; }
private IType getReturnType() { IType retType = ((IFunctionType)getType()).getReturnType(); if( retType != JavaTypes.pVOID() && _mi instanceof IJavaMethodInfo ) { retType = _mi.getReturnType(); } return retType; }
public static String getMethodSignature( IMethodInfo mi ) { IFunctionType type = TypeSystem.getOrCreateFunctionType( mi ); return mi.getDisplayName() + getParameterDisplay( mi ) + " : " + getTypeName( type.getReturnType() ); }
public static String getMethodSignature( IMethodInfo mi ) { IFunctionType type = TypeSystem.getOrCreateFunctionType( mi ); return mi.getDisplayName() + getParameterDisplay( mi ) + " : " + getTypeName( type.getReturnType() ); }
public IType resolveType( IType target, IType source ) { IFunctionType sourceFun = (IFunctionType)source; IType returnType = sourceFun.getReturnType(); IType methodReturnType = extractReturnTypeFromInterface( target ); if( methodReturnType instanceof ITypeVariableType ) { IGenericTypeVariable[] typeVariables = target.getGenericTypeVariables(); IType[] parameterizationTypes = new IType[typeVariables.length]; for( int i = 0; i < typeVariables.length; i++ ) { IGenericTypeVariable typeVariable = typeVariables[i]; if( typeVariable.getName().equals( methodReturnType.getName() ) ) { parameterizationTypes[i] = returnType; } else { parameterizationTypes[i] = target.getTypeParameters()[i]; } } return target.getParameterizedType( parameterizationTypes ); } else { return target; } }
static String getDisplayText( ISymbol symbol ) { if( symbol.getType() instanceof IFunctionType ) { IFunctionType type = (IFunctionType)symbol.getType(); return type.getName() + getParamSignatureText( symbol ) + " : " + getReturnTypeText( type.getReturnType() ); } else { return symbol.getName() + " : " + getTypeDisplayText( symbol.getType() ); } }
static String getDisplayText( ISymbol symbol ) { if( symbol.getType() instanceof IFunctionType ) { IFunctionType type = (IFunctionType)symbol.getType(); return type.getName() + getParamSignatureText( symbol ) + " : " + getReturnTypeText( type.getReturnType() ); } else { return symbol.getName() + " : " + getTypeDisplayText( symbol.getType() ); } }
private boolean isExectedTypeAssignableFrom( BeanTree beanTree ) { return _expectedType.isAssignableFrom( beanTree.getBeanNode().getType() ) || (beanTree.getBeanNode().getType() instanceof IFunctionType && _expectedType.isAssignableFrom( ((IFunctionType)beanTree.getBeanNode().getType()).getReturnType() )); }
private String getDisplayText( ISymbol symbol ) { if( symbol.getType() instanceof IFunctionType ) { IFunctionType type = (IFunctionType)symbol.getType(); return type.getName() + getParamSignatureText( symbol ) + " : " + getReturnTypeText( type.getReturnType() ); } else { return symbol.getName() + " : " + getTypeDisplayText( symbol.getType() ); } }
private String getDisplayText( ISymbol symbol ) { if( symbol.getType() instanceof IFunctionType ) { IFunctionType type = (IFunctionType)symbol.getType(); return type.getName() + getParamSignatureText( symbol ) + " : " + getReturnTypeText( type.getReturnType() ); } else { return symbol.getName() + " : " + getTypeDisplayText( symbol.getType() ); } }
IType returnType = sourceFun.getReturnType(); IType methodReturnType = extractReturnTypeFromInterface( target ); if( methodReturnType instanceof ITypeVariableType )
private void maybeInferFunctionTypeVarsFromReturnType( IInvocableType invType, TypeVarToTypeMap inferenceMap ) { if( !(invType instanceof IFunctionType) ) { return; } IFunctionType funcType = (IFunctionType)invType; if( funcType.isGenericType() && TypeLord.hasTypeVariable( funcType.getReturnType() ) && !getContextType().isMethodScoring() && getContextType().getType() != null && getContextType() != ContextType.EMPTY && (getContextType().getUnboundType() == null || !boundCtxType( getContextType().getUnboundType() ).equals( getContextType().getType() )) ) // no sense in inferring type OUT from default type { if( isParenthesisTerminalExpression() ) { // Note we must infer in "reverse" because the context type flows INTO the return type // For example, // var list: List<String> = Lists.newArrayList( FooJava.filter( {""}, FooJava.not( \ r -> r.Alpha ) ) ) // The context type, List<String>, can infer type var of Lists.newArrayList() by way of its return type, ArrayList<E>. // But the inference relationship is reversed, instead of infering from right-to-left, we infer left-to-right, hence the "Reverse" call here: TypeLord.inferTypeVariableTypesFromGenParamTypeAndConcreteType_Reverse( funcType.getReturnType(), getContextType().getType(), inferenceMap ); } } }
private void parsePlainFunction( IFunctionSymbol functionSymbol ) { MethodCallExpression e = new MethodCallExpression(); e.setFunctionSymbol( functionSymbol ); IFunctionType funcType = (IFunctionType)functionSymbol.getType(); e.setType( funcType.getReturnType() ); IType[] argTypes = funcType.getParameterTypes(); boolean bNoArgsProvided; if( !(bNoArgsProvided = match( null, ')' )) || funcType.hasOptionalParams() ) { verify( e, argTypes != null && argTypes.length > 0, Res.MSG_NO_ARGUMENTS, functionSymbol.getName() ); MethodScore score = parseArgumentList( getGosuClass(), e, Collections.singletonList( funcType ), null, true, bNoArgsProvided ); if( score.isValid() ) { List<IExpression> scoreArgs = score.getArguments(); verifyArgCount( e, scoreArgs.size(), funcType ); //noinspection SuspiciousToArrayCall e.setArgs( scoreArgs.toArray( new Expression[scoreArgs.size()] ) ); e.setNamedArgOrder( score.getNamedArgOrder() ); } verify( e, bNoArgsProvided || match( null, ')' ), Res.MSG_EXPECTING_FUNCTION_CLOSE ); } else { verify( e, argTypes == null || argTypes.length == 0, Res.MSG_EXPECTING_ARGS, functionSymbol.getName() ); e.setArgs( null ); } pushExpression( e ); }
private IRExpression callExternalProgramSymbol(IFunctionSymbol symbol) { List<IRExpression> argValues = new ArrayList<IRExpression>(); Expression[] args = _expr().getArgs(); if (args != null) { for( int i = 0; i < args.length; i++ ) { IExpression arg = args[i]; IRExpression irArg = ExpressionTransformer.compile( arg, _cc() ); if( arg.getType().isPrimitive() ) { irArg = boxValue( arg.getType(), irArg ); } argValues.add( irArg ); } } IRExpression methodCall = callMethod( IExternalSymbolMap.class, "invoke", new Class[]{String.class, Object[].class}, pushExternalSymbolsMap(), exprList( pushConstant( symbol.getName() ), buildInitializedArray(IRTypeConstants.OBJECT(), argValues ) ) ); IType returnType = ((IFunctionType)symbol.getType()).getReturnType(); if( returnType != JavaTypes.pVOID() ) { return unboxValueToType( returnType, methodCall ); } else { return methodCall; } }
addReferencedTypeVarsThatAreNotInMap( funType.getReturnType(), map );