Package com.strobel.reflection

Examples of com.strobel.reflection.MethodInfo


        final String name,
        final Expression left,
        final Expression right,
        final LambdaExpression<?> conversion) {

        final MethodInfo method = getBinaryOperatorMethod(binaryType, left.getType(), right.getType(), name);

        if (method != null) {
            return new MethodBinaryExpression(binaryType, left, right, method.getReturnType(), method);
        }

        return null;
    }
View Full Code Here


        final Expression left,
        final MethodInfo method,
        final ExpressionType nodeType) {

        final Type interfaceType = conversion.getType();
        final MethodInfo invokeMethod = getInvokeMethod(conversion);
        final ParameterList parameters = invokeMethod.getParameters();

        if (parameters.size() != 1) {
            throw Error.incorrectNumberOfMethodCallArguments(invokeMethod);
        }

        if (!TypeUtils.hasIdentityPrimitiveOrBoxingConversion(invokeMethod.getReturnType(), left.getType())) {
            throw Error.operandTypesDoNotMatchParameters(nodeType, invokeMethod);
        }

        if (method != null) {
            if (!TypeUtils.hasIdentityPrimitiveOrBoxingConversion(
View Full Code Here

        if (!interfaceType.isInterface() || methods.size() != 1) {
            throw Error.lambdaTypeMustBeSingleMethodInterface();
        }

        final MethodInfo method = methods.get(0);
        final ParameterList methodParameters = method.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 = method.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

    @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

        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

            ),
            base,
            power
        );

        final MethodInfo powerMethod = powerLambda.compileToMethod(typeBuilder);

        final LambdaExpression<Runnable> runLambda = lambda(
            Type.of(Runnable.class),
            "run",
            call(
View Full Code Here

            p1,
            p2,
            p3
        );

        final MethodInfo invokeMethod = Expression.getInvokeMethod(e);
        final Type<?> returnType = invokeMethod.getReturnType();
        final TypeList parameterTypes = invokeMethod.getParameters().getParameterTypes();
        final Type delegateType = invokeMethod.getDeclaringType();

        assertTrue(delegateType.isGenericType());
        assertEquals(Types.String, delegateType.getTypeArguments().get(0));

        assertEquals(PrimitiveTypes.Boolean, returnType);
View Full Code Here

            throw Error.coalesceUsedOnNonNullableType();
        }

        final Type<?> delegateType = conversion.getType();

        final MethodInfo method = getInvokeMethod(conversion);

        if (method.getReturnType() == PrimitiveTypes.Void) {
            throw Error.operatorMethodMustNotReturnVoid(method);
        }

        final ParameterList parameters = method.getParameters();

        assert parameters.size() == conversion.getParameters().size();

        if (parameters.size() != 1) {
            throw Error.incorrectNumberOfMethodCallArguments(method);
        }

        //
        // The return type must match exactly.
        //
        if (!TypeUtils.areEquivalent(method.getReturnType(), right.getType())) {
            throw Error.operandTypesDoNotMatchParameters(ExpressionType.Coalesce, method);
        }

        //
        // The parameter of the conversion lambda must either be assignable from the erased
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.