public boolean resolveMethod( String methodName, List<IType> typesList ) { IType[] argTypes = typesList.toArray( new IType[typesList.size()] ); IType typeToResolveAgainst = getRootTypeToResolveFeaturesAgainst(); ITypeInfo typeInfo = typeToResolveAgainst.getTypeInfo(); IMethodInfo methodInfo; if( typeInfo instanceof IRelativeTypeInfo ) { methodInfo = ITypeInfo.FIND.callableMethod(((IRelativeTypeInfo)typeInfo).getMethods( typeToResolveAgainst), methodName, argTypes ); } else { methodInfo = ITypeInfo.FIND.callableMethod( typeInfo.getMethods(), methodName, argTypes ); } methodInfo = ensureExactMatch( methodInfo, argTypes ); if( methodInfo == null && argTypes.length == 0 ) { methodInfo = getSingleMethodWithName( methodName, typeToResolveAgainst, typeInfo ); } boolean foundMethod = methodInfo != null; methodInfo = foundMethod ? methodInfo : ErrorType.getInstance().getTypeInfo().getMethod( methodName, argTypes ); setFeature( methodInfo, null ); return foundMethod; }
List<MethodScore> list = scoreMethods( new ArrayList<IInvocableType>( mis.keySet() ), Arrays.asList( params ), Collections.EMPTY_LIST ); if( list.size() == 0 ) if( strict && !areParamsCompatible( rawFunctionType.getParameterTypes(), params ) )
public static IMethodInfo method( MethodList methodList, CharSequence method, IType... params ) { params = params == null ? EMPTY_TYPES : params; DynamicArray<? extends IMethodInfo> methods = methodList.getMethods( method.toString() ); for( int i = 0; i < methods.size; i++ ) { IMethodInfo methodInfo = (IMethodInfo) methods.data[i]; if( methodInfo.getDisplayName().equals( method.toString() ) ) { IParameterInfo[] paramInfos = methodInfo.getParameters(); if (areParamsEqual( paramInfos, params )) { return methodInfo; } } } //System.out.println( "#Missed: " + ii++ ); return null; }
else if( typeVarsAreFromDifferentMethods( methodParamType, testParamType ) ) methodParamType = getConcreteBoundingType( methodParamType ); testParamType = getConcreteBoundingType( testParamType ); for( int i = 0; i < methodTypeParameters.length; i++ ) if( !getConcreteBoundingType( methodTypeParameters[i] ).isAssignableFrom( testTypeParameters[i] ) )
else if( typeVarsAreFromDifferentMethods( methodParamType, testParamType ) ) methodParamType = getConcreteBoundingType( methodParamType ); testParamType = getConcreteBoundingType( testParamType ); for( int i = 0; i < methodTypeParameters.length; i++ ) if( !getConcreteBoundingType( methodTypeParameters[i] ).isAssignableFrom( testTypeParameters[i] ) )
if( strict && !areParamsCompatible( rawFunctionType.getParameterTypes(), params ) )
private static IConstructorInfo callableConstructorImpl( List<? extends IConstructorInfo> constructors, boolean strict, IType... params ) { Map<IConstructorType, IConstructorInfo> cis = new HashMap<IConstructorType, IConstructorInfo>(); params = params == null ? EMPTY_TYPES : params; for( IConstructorInfo constructorInfo : constructors ) { if( params.length == constructorInfo.getParameters().length ) { cis.put( GosuShop.getConstructorInfoFactory().makeConstructorType( constructorInfo ), constructorInfo ); } } List<MethodScore> list = scoreMethods( new ArrayList<IInvocableType>( cis.keySet() ), Arrays.asList( params ), Collections.EMPTY_LIST ); if( list.size() == 0 ) { return null; } else if( list.size() > 1 && list.get( 0 ).getScore() == list.get( 1 ).getScore() ) { throw new IllegalArgumentException( "Ambiguous constructors: There is more than one constructor that accepts args " + Arrays.asList( params ) ); } IInvocableType rawFunctionType = list.get( 0 ).getRawFunctionType(); if( strict && !areParamsCompatible( rawFunctionType.getParameterTypes(), params ) ) { return null; } return cis.get( rawFunctionType ); }
private static IConstructorInfo callableConstructorImpl( List<? extends IConstructorInfo> constructors, boolean strict, IType... params ) { Map<IConstructorType, IConstructorInfo> cis = new HashMap<IConstructorType, IConstructorInfo>(); params = params == null ? EMPTY_TYPES : params; for( IConstructorInfo constructorInfo : constructors ) { if( params.length == constructorInfo.getParameters().length ) { cis.put( GosuShop.getConstructorInfoFactory().makeConstructorType( constructorInfo ), constructorInfo ); } } List<MethodScore> list = MethodScorer.instance().scoreMethods( new ArrayList<IInvocableType>( cis.keySet() ), Arrays.asList( params ) ); if( list.size() == 0 ) { return null; } else if( list.size() > 1 && list.get( 0 ).getScore() == list.get( 1 ).getScore() ) { throw new IllegalArgumentException( "Ambiguous constructors: There is more than one constructor that accepts args " + Arrays.asList( params ) ); } IInvocableType rawFunctionType = list.get( 0 ).getRawFunctionType(); if( strict && !areParamsCompatible( rawFunctionType.getParameterTypes(), params ) ) { return null; } return cis.get( rawFunctionType ); }
private static IType getConcreteBoundingType( IType type ) { if( type instanceof ITypeVariableType ) { IType boundingType = ((ITypeVariableType)type).getBoundingType(); if( boundingType == null ) { // ## todo: boundingType should really not be null, but it can be when it comes from java e.g., // B extends Comparable<? super B>, where <? super B> is WILD_CONTRAVARIANT and caught in a // chick-n-egg where the first B's bounding type is not yet assigned because <? super B> is // its bounding type. So we just return B here, which is for all-ish intents and purposes ok. return type; } return getConcreteBoundingType( boundingType ); } else if( type instanceof ITypeVariableArrayType ) { return getConcreteBoundingType( type.getComponentType() ); } return type; } }
public static IMethodInfo method( MethodList methods, CharSequence method, IType... params ) { params = params == null ? EMPTY_TYPES : params; for( int i = 0; i < methods.size; i++ ) { IMethodInfo methodInfo = (IMethodInfo) methods.data[i]; if( methodInfo.getDisplayName().equals( method.toString() ) ) { IParameterInfo[] paramInfos = methodInfo.getParameters(); if (areParamsEqual( paramInfos, params )) { return methodInfo; } } } return null; }
public IConstructorInfo getConstructor( IType... params ) { return FIND.constructor( getConstructors(), params ); }
public IConstructorInfo getConstructor( IType... params ) { return FIND.constructor( getConstructors(), params ); }
public IConstructorInfo getCallableConstructor( IType... params ) { return FIND.callableConstructor( getConstructors(), params ); }
public IMethodInfo getCallableMethod( CharSequence strMethod, IType... params ) { return FIND.callableMethod( getMethods(), strMethod, params ); }
public IConstructorInfo getCallableConstructor( IType... params ) { return FIND.callableConstructor( getConstructors(), params ); }
public IMethodInfo getCallableMethod( CharSequence strMethod, IType... params ) { return FIND.callableMethod( getMethods(), strMethod, params ); }
public IConstructorInfo getCallableConstructor( IType... params ) { return FIND.callableConstructor( getConstructors(), params ); }
public IMethodInfo getCallableMethod( CharSequence strMethod, IType... params ) { return FIND.callableMethod( getMethods(), strMethod, params ); }
@Override public IMethodInfo getCallableMethod(CharSequence strMethod, IType... params) { return FIND.callableMethod(getMethods(), strMethod, params); }
public IConstructorInfo getCallableConstructor( IType... params ) { return FIND.callableConstructor( getConstructors(), params ); }