private static void verifyMethodCallExpression( MethodCallExpression expr ) { if( expr.getFunctionType() != null && expr.getFunctionType().getMethodInfo() != null ) { verifyMethodInvocation( expr, expr.getFunctionType().getMethodInfo() ); } }
IType[] types = funType.getParameterTypes(); for( IType param : types ) return isParameterizedWith( funType.getReturnType(), typeVar );
public static String buildFunctionIntellisenseString( boolean bFeatureLiteralCompletion, IFunctionType functionType ) { StringBuilder sb = new StringBuilder(); String rawName = functionType.getDisplayName(); sb.append( rawName ); sb.append( "()" ); return sb.toString(); }
static String getStaticParamSignatureText( IFunctionType type ) { IType[] argTypes = type.getParameterTypes(); if( argTypes == null || argTypes.length == 0 ) { return "()"; } String[] names = type.getParameterNames(); String strParams = "("; for( int i = 0; i < argTypes.length; i++ ) { String name = ""; if( names != null && names.length > 0 && names[i] != null ) { name = names[i] + ": "; } strParams += (i == 0 ? "" : ", ") + name + getTypeDisplayText( argTypes[i] ); } strParams += ")"; return strParams; }
private void verifyArgCount( ParsedElement element, int iArgs, IFunctionType funcType ) { int expectedArgs = funcType.getParameterTypes().length; if( iArgs != expectedArgs ) { ParseException pe = new WrongNumberOfArgsException( makeFullParserState(), Res.MSG_WRONG_NUMBER_OF_ARGS_TO_FUNCTION, funcType.getParamSignature(), expectedArgs, iArgs ); pe.setParamTypesExpected( funcType.getParameterTypes() ); pe.setCausedByArgumentList( true ); element.addParseException( pe ); } }
private static void buildArgListFromType( IFunctionType functionType, StringBuilder sb, boolean topLevel, boolean bFeatureLiteralCompletion ) IType[] parameters = functionType.getParameterTypes(); HashSet<String> generatedNames = new HashSet<String>(); for( int i = 0; i < parameters.length; i++ ) if( functionType.getMethodInfo() != null ) IParameterInfo info = functionType.getMethodInfo().getParameters()[i]; name = info.getName();
boolean bNoArgsProvided; if( !(bNoArgsProvided = match( null, ')' )) || (listFunctionTypes.size() == 1 && listFunctionTypes.get( 0 ).hasOptionalParams()) ) e.setType( (!bExpansion || funcType.getReturnType().isArray() || funcType.getReturnType() == JavaTypes.pVOID()) ? funcType.getReturnType() : funcType.getReturnType().getArrayType() ); e.setFunctionType( funcType ); IType[] argTypes = funcType.getParameterTypes(); e.setArgTypes( argTypes ); IFunctionType rawFunctionType = (IFunctionType)methodScore.getRawFunctionType(); md = rawFunctionType.getMethodInfo(); if( !md.isVisible( getVisibilityConstraint() ) ) e.setMemberAccessKind( kind ); e.setNamedArgOrder( methodScore.getNamedArgOrder() ); verifyCase( e, strMemberName, funcType.getName(), state, Res.MSG_FUNCTION_CASE_MISMATCH, false ); verifySuperAccess( rootExpression, e, funcType.getMethodInfo(), strMemberName ); IFunctionType parameterizedFuncType = (IFunctionType)funcType.getParameterizedType( typeParameters ); if( verify( e, parameterizedFuncType != null, Res.MSG_COULD_NOT_PARAMETERIZE ) ) e.setType( (!bExpansion || funcType.getReturnType().isArray() || funcType.getReturnType() == JavaTypes.pVOID()) ? boundType.getReturnType() : boundType.getReturnType().getArrayType() ); e.setFunctionType( funcType ); IType[] argTypes = funcType.getParameterTypes(); e.setArgTypes( argTypes ); e.setAccessPath( strMemberName );
boolean bNoArgsProvided; if( !(bNoArgsProvided = match( null, ')' )) || ((listFunctionTypes = getFunctionTypesForName( strFunction )).size() == 1 && listFunctionTypes.get( 0 ).hasOptionalParams()) ) verifyCase( e, strFunction, rawFunctionType.getName(), state, Res.MSG_FUNCTION_CASE_MISMATCH, false ); final IType[] parameterTypes1 = rawFunctionType.getParameterTypes(); isRecursiveConstructorCall = parameterTypes0.length == parameterTypes1.length && Arrays.equals( parameterTypes0, parameterTypes1 ); if( inferredFunctionType instanceof FunctionType ) ((FunctionType)inferredFunctionType).setScriptPart( rawFunctionType.getScriptPart() ); e.setType( inferredFunctionType.getReturnType() ); e.setFunctionType( inferredFunctionType ); IFunctionType parameterizedFuncType = (IFunctionType)funcType.getParameterizedType( typeParameters ); if( verify( e, parameterizedFuncType != null, Res.MSG_COULD_NOT_PARAMETERIZE ) ) e.setType( boundFuncType.getReturnType() ); e.setFunctionType( boundFuncType );
private IFunctionType findFunction( List<IFunctionType> listFunctionTypes, boolean bNoArgsProvided ) { if( listFunctionTypes.isEmpty() ) { return null; } for( IFunctionType funcType: listFunctionTypes ) { if( funcType.getParameterTypes().length == 0 == bNoArgsProvided ) { return funcType; } } return listFunctionTypes.get( 0 ); }
args.add( pushConstant(funcType.getName() ) ); args.add( pushType( funcType.getReturnType() ) ); args.add( pushArrayOfTypes( funcType.getParameterTypes() ) ); return buildNewExpression( getDescriptor( FunctionType.class ), Arrays.asList(IRTypeConstants.STRING(), IRTypeConstants.ITYPE(), getDescriptor( IType[].class ) ),
private IType extractReturnTypeFromInterface( IType target ) { IFunctionType funcType = target.getFunctionalInterface(); return funcType == null ? null : funcType.getReturnType(); }
if( funcType.getMethodInfo() != null ) return new IParameterInfo[][]{funcType.getMethodInfo().getParameters()}; else if( funcType.getScriptPart() != null && funcType.getScriptPart().getContainingType() instanceof IGosuClass ) IGosuClass type = (IGosuClass)funcType.getScriptPart().getContainingType(); String strName = funcType.getName(); List methods = type.getTypeInfo().getMethods( type ); for( Object method : methods ) List<IFunctionSymbol> dynamicFunctionSymbols = dfsDecls.get( funcType.getName() ); if( dynamicFunctionSymbols != null )
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 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 ); }
if( lhsFunctionType != null ) if( lhsFunctionType.isAssignableFrom( rhsFunctionType ) ) if( lhsFunctionType.areParamsCompatible( rhsFunctionType ) ) ICoercer coercer = findCoercer( lhsFunctionType.getReturnType(), rhsFunctionType.getReturnType(), runtime ); if( coercer != null )
existing.getEnclosingType() + "#" + existing.getParamSignature(), dft.getEnclosingType() + "#" + dft.getParamSignature()); continue; mi = iface.getTypeInfo().getMethod( strMethodName, ((IFunctionType)dfs.getType()).getParameterTypes() ); if( mi == null ) mi = iface.getTypeInfo().getCallableMethod( strMethodName, ((IFunctionType)dfs.getType()).getParameterTypes() );
private void ensureAbstractMethodsImpledAndNoDiamonds( IGosuClassInternal gsClass ) { List<IFunctionType> unimpled = gsClass.getUnimplementedMethods(); for( Iterator<IFunctionType> iter = unimpled.iterator(); iter.hasNext(); ) { IFunctionType funcType = iter.next(); final IMethodInfo mi = funcType.getMethodInfo(); if( mi.isDefaultImpl() ) { // mi is a default interface method the class (or interface) does not override, // check for a duplicate, not-overridden method that comes from an interface that // is unrelated to mi's declaring interface // i.e., prohibit "diamond" patterns directly interface-inherited from the class (or interface). if( conflictsWithUnrelatedIfaceMethod( gsClass, funcType, unimpled ) ) { iter.remove(); } } else if( !gsClass.isInterface() && !gsClass.isAbstract() ) { // mi is abstract, the non-abstract class failed to implement it... String strClass = funcType.getEnclosingType().getName(); strClass = IGosuClass.ProxyUtil.getNameSansProxy( strClass ); getClassStatement().addParseException( new NotImplementedParseException( makeFullParserState(), gsClass, strClass, funcType ) ); } } }
@Override public String getFunctionName() { return getType().getName(); }
private static boolean areTypeVariablesEquivalent( TypeVariableType possible, TypeVariableType inferred ) { boolean match = false; if( GosuObjectUtil.equals( possible.getName(), inferred.getName() ) ) { IType enclosingType1 = possible.getEnclosingType(); IType enclosingType2 = inferred.getEnclosingType(); if( enclosingType1 instanceof IFunctionType && enclosingType2 instanceof IFunctionType ) { IFunctionType funType1 = (IFunctionType)enclosingType1; IFunctionType funType2 = (IFunctionType)enclosingType2; IScriptPartId id1 = funType1.getScriptPart(); IScriptPartId id2 = funType2.getScriptPart(); String typeName1 = id1 == null ? null : id1.getContainingTypeName(); String typeName2 = id2 == null ? null : id2.getContainingTypeName(); if( GosuObjectUtil.equals( typeName1, typeName2 ) && GosuObjectUtil.equals( funType1.getParamSignature(), funType2.getParamSignature() ) ) { match = true; } } } return match; }
if( equivalentTypes( funcType.getScriptPart().getContainingType(), getGosuClass() ) ) IGenericTypeVariable[] genTypeVars = funcType.getGenericTypeVariables(); for( int i = 0; i < genTypeVars.length; i++ )