Package com.strobel.reflection

Examples of com.strobel.reflection.MethodInfo


        final ParameterExpressionList parameters) {

        VerifyArgument.notNull(interfaceType, "interfaceType");
        verifyCanRead(body, "body");

        final MethodInfo invokeMethod = getInvokeMethod(interfaceType, false);

        if (invokeMethod == null) {
            throw Error.lambdaTypeMustBeSingleMethodInterface();
        }

        final ParameterList methodParameters = invokeMethod.getParameters();

        if (methodParameters.size() > 0) {
            if (parameters.size() != methodParameters.size()) {
                throw Error.incorrectNumberOfLambdaArguments();
            }

            final Set<ParameterExpression> set = new HashSet<>(parameters.size());

            for (int i = 0, n = methodParameters.size(); i < n; i++) {
                final ParameterExpression pex = parameters.get(i);
                final ParameterInfo pi = methodParameters.get(i);

                verifyCanRead(pex, "parameters");

                final Type pType = pi.getParameterType();

                if (!TypeUtils.areEquivalent(pex.getType(), pType)) {
                    if (!pType.isGenericParameter() || !pType.isAssignableFrom(pex.getType())) {
                        throw Error.parameterExpressionNotValidForDelegate(pex.getType(), pType);
                    }
                }

                if (set.contains(pex)) {
                    throw Error.duplicateVariable(pex);
                }

                set.add(pex);
            }
        }
        else if (parameters.size() > 0) {
            throw Error.incorrectNumberOfLambdaDeclarationParameters();
        }

        final Type returnType = invokeMethod.getReturnType();

        if (returnType != PrimitiveTypes.Void &&
            !TypeUtils.areEquivalent(returnType, body.getType())) {
            if (/*!returnType.isGenericParameter() ||*/ !returnType.isAssignableFrom(body.getType())) {
                throw Error.expressionTypeDoesNotMatchReturn(body.getType(), returnType);
View Full Code Here


        }

        final ArrayList<MethodInfo> candidates = new ArrayList<>(members.size());

        for (int i = 0, n = members.size(); i < n; i++) {
            final MethodInfo appliedMethod = applyTypeArgs(
                (MethodInfo) members.get(i),
                typeArguments
            );

            if (appliedMethod != null)
                candidates.add(appliedMethod);
        }

        final Type[] parameterTypes = new Type[arguments.size()];

        for (int i = 0, n = arguments.size(); i < n; i++) {
            parameterTypes[i] = arguments.get(i).getType();
        }

        final MethodInfo result = (MethodInfo) Type.DefaultBinder.selectMethod(
            flags,
            candidates.toArray(new MethodBase[candidates.size()]),
            parameterTypes
        );
View Full Code Here

        final TypeList typeArgs,
        final ExpressionList<? extends Expression> arguments) {

        int count = 0;
        int bestMethodIndex = -1;
        MethodInfo bestMethod = null;

        for (int i = 0, n = methods.size(); i < n; i++) {
            final MethodInfo method = applyTypeArgs((MethodInfo)methods.get(i), typeArgs);
            if (method != null && isCompatible(method, arguments)) {
                // Favor public over non-public methods.
                if (bestMethod == null || (!bestMethod.isPublic() && method.isPublic())) {
                    bestMethodIndex = i;
                    bestMethod = method;
                    count = 1;
                }
                else {
                    // Only count it as additional method if they both public or both non-public.
                    if (bestMethod.isPublic() == method.isPublic()) {
                        count++;
                    }
                }
            }
        }
View Full Code Here

        code.emitLoadArgument(0);
        code.emitReturn(gp[0]);

        final Type<?> createdType = typeBuilder.createType();
        final Type<?> boundType = createdType.makeGenericType(Types.String);
        final MethodInfo boundMethod = boundType.getMethod("test");
        final Object instance = createdType.newInstance();
        final String parameter = "test";

        final Object result = boundMethod.invoke(instance, parameter);

        assertSame(parameter, result);

        final TestAnnotation createdTypeAnnotation = createdType.getErasedClass().getAnnotation(TestAnnotation.class);
View Full Code Here

                call(base(baseType), "toString"),
                constant(":Derived")
            )
        );

        final MethodInfo baseMethod = baseType.getMethod("toString");

        final MethodBuilder toString = derivedType.defineMethod(
            "toString",
            Modifier.PUBLIC|Modifier.FINAL,
            Types.String
View Full Code Here

        if (!destination.isPrimitive()) {
            return null;
        }
*/

        final MethodInfo method;

        if (destination == PrimitiveTypes.Integer) {
            method = source.getMethod("intValue", BindingFlags.PublicInstance);
        }
        else if (destination == PrimitiveTypes.Long) {
            method = source.getMethod("longValue", BindingFlags.PublicInstance);
        }
        else if (destination == PrimitiveTypes.Double) {
            method = source.getMethod("doubleValue", BindingFlags.PublicInstance);
        }
        else if (destination == PrimitiveTypes.Float) {
            method = source.getMethod("floatValue", BindingFlags.PublicInstance);
        }
        else if (destination == PrimitiveTypes.Short) {
            method = source.getMethod("shortValue", BindingFlags.PublicInstance);
        }
        else if (destination == PrimitiveTypes.Byte) {
            method = source.getMethod("byteValue", BindingFlags.PublicInstance);
        }
        else if (destination == PrimitiveTypes.Boolean) {
            method = source.getMethod("booleanValue", BindingFlags.PublicInstance);
        }
        else if (destination == PrimitiveTypes.Character) {
            method = source.getMethod("charValue", BindingFlags.PublicInstance);
        }
        else {
            method = destination.getMethod("valueOf", BindingFlags.PublicStatic, source);
        }

        if (method == null) {
            return null;
        }

        if (method.getReturnType() == unboxedDestinationType) {
            return method;
        }

        return null;
    }
View Full Code Here

            return null;
        }

        primitiveType = TypeUtils.getUnderlyingPrimitive(boxedType);

        final MethodInfo boxMethod = boxedType.getMethod(
            "valueOf",
            BindingFlags.PublicStatic,
            primitiveType
        );

        if (boxMethod == null || !areEquivalent(boxMethod.getReturnType(), boxedType)) {
            return null;
        }

        return boxMethod;
    }
View Full Code Here

        primitiveType = TypeUtils.getUnderlyingPrimitive(boxedType);

        final Set<BindingFlags> bindingFlags = BindingFlags.PublicInstance;

        final MethodInfo unboxMethod;

        switch (primitiveType.getKind()) {
            case BOOLEAN:
                unboxMethod = boxedType.getMethod("booleanValue", bindingFlags);
                break;

            case BYTE:
                unboxMethod = boxedType.getMethod("byteValue", bindingFlags);
                break;

            case SHORT:
                unboxMethod = boxedType.getMethod("shortValue", bindingFlags);
                break;

            case INT:
                unboxMethod = boxedType.getMethod("intValue", bindingFlags);
                break;

            case LONG:
                unboxMethod = boxedType.getMethod("longValue", bindingFlags);
                break;

            case CHAR:
                unboxMethod = boxedType.getMethod("charValue", bindingFlags);
                break;

            case FLOAT:
                unboxMethod = boxedType.getMethod("floatValue", bindingFlags);
                break;

            case DOUBLE:
                unboxMethod = boxedType.getMethod("doubleValue", bindingFlags);
                break;

            default:
                unboxMethod = null;
                break;
        }

        if (unboxMethod == null || !areEquivalent(unboxMethod.getReturnType(), primitiveType)) {
            return null;
        }

        return unboxMethod;
    }
View Full Code Here

        final int modifiers) {

        VerifyArgument.notNull(typeBuilder, "typeBuilder");
        VerifyArgument.notNullOrWhitespace(name, "name");

        final MethodInfo invokeMethod = Expression.getInvokeMethod(this);

        final MethodBuilder methodBuilder = typeBuilder.defineMethod(
            name,
            modifiers,
            invokeMethod.getReturnType(),
            invokeMethod.getParameters().getParameterTypes()
        );

        LambdaCompiler.compile(this, methodBuilder, DebugInfoGenerator.empty());

        return methodBuilder;
View Full Code Here

    @Override
    protected Expression visitExtension(final Expression node) {
        // Prefer a toString override, if available.
        final Set<BindingFlags> flags = BindingFlags.PublicInstanceExact;
        final MethodInfo toString = node.getType().getMethod("toString", flags, CallingConvention.Standard, Type.EmptyTypes);

        if (toString != null && toString.getDeclaringType() != Type.of(Expression.class)) {
            out(node.toString());
            return node;
        }

        out("[");
View Full Code Here

TOP

Related Classes of com.strobel.reflection.MethodInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.