Java Code Examples for java.lang.reflect.Method#toGenericString()

The following examples show how to use java.lang.reflect.Method#toGenericString() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: breeze   File: SpringComponent.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the bean invocation return value.
 */
protected Object invoke(Method method, Object[] arguments)
throws InvocationTargetException, IllegalAccessException {
	logger.trace("Lookup for call {}", method);
	Object bean = spring.getBean(beanType);

	try {
		return method.invoke(bean, arguments);
	} catch (IllegalArgumentException e) {
		StringBuilder msg = new StringBuilder(method.toGenericString());
		msg.append(" invoked with incompatible arguments:");
		for (Object a : arguments) {
			msg.append(' ');
			if (a == null)
				msg.append("null");
			else
				msg.append(a.getClass().getName());
		}
		logger.error(msg.toString());
		throw e;
	}
}
 
Example 2
Source Project: AgentWebX5   File: AgentWebX5Utils.java    License: Apache License 2.0 6 votes vote down vote up
public static boolean isOverriedMethod(Object currentObject, String methodName, String method, Class... clazzs) {
    LogUtils.i("Info", "currentObject:" + currentObject + "  methodName:" + methodName + "   method:" + method);
    boolean tag = false;
    if (currentObject == null)
        return tag;

    try {

        Class clazz = currentObject.getClass();
        Method mMethod = clazz.getMethod(methodName, clazzs);
        String gStr = mMethod.toGenericString();


        tag = !gStr.contains(method);
    } catch (Exception igonre) {
        igonre.printStackTrace();
    }

    LogUtils.i("Info", "isOverriedMethod:" + tag);
    return tag;
}
 
Example 3
void set(Method method) {
    if (method == null) {
        this.signature = null;
        this.methodRef = null;
        this.typeRef = null;
    }
    else {
        this.signature = method.toGenericString();
        this.methodRef = new SoftReference<>(method);
        this.typeRef = new WeakReference<Class<?>>(method.getDeclaringClass());
    }
}
 
Example 4
void set(Method method) {
    if (method == null) {
        this.signature = null;
        this.methodRef = null;
        this.typeRef = null;
    }
    else {
        this.signature = method.toGenericString();
        this.methodRef = new SoftReference<>(method);
        this.typeRef = new WeakReference<Class<?>>(method.getDeclaringClass());
    }
}
 
Example 5
Source Project: tomee   File: CheckRestMethodArePublic.java    License: Apache License 2.0 5 votes vote down vote up
private void valid(final ValidationContext validation, final ClassLoader classLoader, final String classname) {
    Class<?> clazz;
    try {
        clazz = classLoader.loadClass(classname);
    } catch (final ClassNotFoundException e) {
        return; // managed elsewhere
    }

    int publicMethodNumber = 0;
    int nonPublicMethods = 0;
    while (!Object.class.equals(clazz) && clazz != null) {
        for (final Method mtd : clazz.getDeclaredMethods()) {
            final boolean isPublic = Modifier.isPublic(mtd.getModifiers());
            if (mtd.getAnnotation(Path.class) != null && !isPublic) {
                final String name = mtd.toGenericString();
                validation.warn(name, "rest.method.visibility", name);
            }
            if (isPublic) {
                publicMethodNumber++;
            } else {
                nonPublicMethods++;
            }
        }
        clazz = clazz.getSuperclass();
    }

    if (publicMethodNumber == 0 && nonPublicMethods > 0) {
        validation.warn(classname, "no.method.in.rest.class", classname);
    } else if (publicMethodNumber == 0 && nonPublicMethods == 0) {
        validation.warn(classname, "no.rest.resource.method", classname);
    }
}
 
Example 6
Source Project: vertx-codegen   File: Helper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link Method } corresponding to the {@literal methodElt} parameter. Obviously this work
 * only when the corresponding method is available on the classpath using java lang reflection.
 *
 * @param modelMethod the model method element
 * @return the method or null if not found
 */
public static Method getReflectMethod(ClassLoader loader, ExecutableElement modelMethod) {
  TypeElement typeElt = (TypeElement) modelMethod.getEnclosingElement();
  Method method = null;
  try {
    Class<?> clazz = loader.loadClass(typeElt.getQualifiedName().toString());
    StringBuilder sb = new StringBuilder(modelMethod.getSimpleName());
    sb.append("(");
    List<? extends VariableElement> params = modelMethod.getParameters();
    for (int i = 0;i < params.size();i++) {
      if (i > 0) {
        sb.append(",");
      }
      VariableElement param = params.get(i);
      toString(param.asType(), sb);
    }
    sb.append(")");
    String s = sb.toString();
    for (Method m : clazz.getMethods()) {
      String sign = m.toGenericString();
      int pos = sign.indexOf('(');
      pos = sign.lastIndexOf('.', pos) + 1;
      sign = sign.substring(pos);
      sign = sign.replace(", ", ","); // Remove space between arguments
      if (sign.equals(s)) {
        // Test this case
        if (method != null) {
          if (method.getReturnType().isAssignableFrom(m.getReturnType())) {
            method = m;
          }
        } else {
          method = m;
        }
      }
    }
  } catch (ClassNotFoundException e) {
  }
  return method;
}
 
Example 7
Source Project: Java8CN   File: MethodRef.java    License: Apache License 2.0 5 votes vote down vote up
void set(Method method) {
    if (method == null) {
        this.signature = null;
        this.methodRef = null;
        this.typeRef = null;
    }
    else {
        this.signature = method.toGenericString();
        this.methodRef = new SoftReference<>(method);
        this.typeRef = new WeakReference<Class<?>>(method.getDeclaringClass());
    }
}
 
Example 8
void set(Method method) {
    if (method == null) {
        this.signature = null;
        this.methodRef = null;
        this.typeRef = null;
    }
    else {
        this.signature = method.toGenericString();
        this.methodRef = new SoftReference<>(method);
        this.typeRef = new WeakReference<Class<?>>(method.getDeclaringClass());
    }
}
 
Example 9
void set(Method method) {
    if (method == null) {
        this.signature = null;
        this.methodRef = null;
        this.typeRef = null;
    }
    else {
        this.signature = method.toGenericString();
        this.methodRef = new SoftReference<>(method);
        this.typeRef = new WeakReference<Class<?>>(method.getDeclaringClass());
    }
}
 
Example 10
void set(Method method) {
    if (method == null) {
        this.signature = null;
        this.methodRef = null;
        this.typeRef = null;
    }
    else {
        this.signature = method.toGenericString();
        this.methodRef = new SoftReference<>(method);
        this.typeRef = new WeakReference<Class<?>>(method.getDeclaringClass());
    }
}
 
Example 11
Source Project: anno4j   File: RoleMapper.java    License: Apache License 2.0 5 votes vote down vote up
public void addAnnotation(Method annotation) {
	if (!annotation.isAnnotationPresent(Iri.class))
		throw new IllegalArgumentException("@" + Iri.class.getSimpleName()
				+ " annotation required in " + annotation.toGenericString());
	String uri = annotation.getAnnotation(Iri.class).value();
	addAnnotation(annotation, new URIImpl(uri));
}
 
Example 12
private static String getMethodRequestMapping(Method method) {
	Assert.notNull(method, "'method' must not be null");
	RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
	if (requestMapping == null) {
		throw new IllegalArgumentException("No @RequestMapping on: " + method.toGenericString());
	}
	String[] paths = requestMapping.path();
	if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) {
		return "/";
	}
	if (paths.length > 1 && logger.isWarnEnabled()) {
		logger.warn("Multiple paths on method {}, using first one", method.toGenericString());
	}
	return paths[0];
}
 
Example 13
Source Project: Bytecoder   File: MethodRef.java    License: Apache License 2.0 5 votes vote down vote up
void set(Method method) {
    if (method == null) {
        this.signature = null;
        this.methodRef = null;
        this.typeRef = null;
    }
    else {
        this.signature = method.toGenericString();
        this.methodRef = new SoftReference<>(method);
        this.typeRef = new WeakReference<Class<?>>(method.getDeclaringClass());
    }
}
 
Example 14
void set(Method method) {
    if (method == null) {
        this.signature = null;
        this.methodRef = null;
        this.typeRef = null;
    }
    else {
        this.signature = method.toGenericString();
        this.methodRef = new SoftReference<>(method);
        this.typeRef = new WeakReference<Class<?>>(method.getDeclaringClass());
    }
}
 
Example 15
Source Project: development   File: AbstractVOConverter.java    License: Apache License 2.0 5 votes vote down vote up
private void setSetField(Object newVO, Object oldVO, Method method)
        throws IllegalAccessException, InvocationTargetException,
        ClassNotFoundException, NoSuchMethodException {
    String className = method.toGenericString();
    className = className.substring(className.indexOf('<') + 1,
            className.indexOf('>'));
    final Set<?> set = convertSet((Set<?>) method.invoke(oldVO),
            Class.forName(getNewClassName(Class.forName(className))));
    newVO.getClass().getMethod(getSetter(method), method.getReturnType())
            .invoke(newVO, set);
}
 
Example 16
Source Project: breeze   File: FunctionSignature.java    License: Apache License 2.0 5 votes vote down vote up
private static ReflectiveOperationException ambiguity(Method a, Method b)
throws ReflectiveOperationException {
	String[] readable = { a.toGenericString(), b.toGenericString() };
	Arrays.sort(readable);
	String msg = format("Ambiguity between %s and %s",
			readable[0], readable[1]);
	return new ReflectiveOperationException(msg);
}
 
Example 17
Source Project: brooklyn-server   File: Reflections.java    License: Apache License 2.0 4 votes vote down vote up
private static String getIllegalArgumentsErrorMessage(Method method, Object[] argValues) {
    return method.toGenericString() + " not applicable for the parameters of type " + argumentTypesToString(argValues);
}
 
Example 18
public Object invoke( MixinsInstance mixins,
                          Object proxy,
                          Method method,
                          Object[] args,
                          ModuleDescriptor moduleInstance
                        )
        throws Throwable
    {
        CompositeMethodModel compositeMethod = methods.get( method );

        if( compositeMethod == null )
        {
            Class<?> declaringClass = method.getDeclaringClass();
            if( declaringClass.equals( Object.class ) )
            {
                return mixins.invokeObject( proxy, args, method );
            }

            // TODO: Figure out what was the intention of this code block, added by Rickard in 2009. It doesn't do anything useful.
            // Update (niclas): My guess is that this is preparation for mixins in Objects.
            if( !declaringClass.isInterface() )
            {
                compositeMethod = mixinsModel.mixinTypes().map( aClass ->
                                                                {
                                                                    try
                                                                    {
                                                                        Method realMethod = aClass.getMethod( method.getName(), method.getParameterTypes() );
                                                                        return methods.get( realMethod );
                                                                    }
                                                                    catch( NoSuchMethodException | SecurityException e )
                                                                    {

                                                                    }
                                                                    return null;
                                                                } ).filter( Objects::nonNull ).findFirst().orElse( null );
                return compositeMethod.invoke( proxy, args, mixins, moduleInstance );
            }
            if( method.isDefault() )
            {
                if( proxy instanceof Composite )
                {
                    throw new InternalError( "This shouldn't happen!" );
                }
                // Does this next line actually make any sense? Can we have a default method on an interface where the instance is not a Composite? Maybe... Let's try to trap a usecase by disallowing it.
//                return method.invoke( proxy, args );
                String message = "We have detected a default method on an interface that is not backed by a Composite. "
                                 + "Please report this to [email protected] together with the information below, "
                                 + "that/those class(es) and the relevant assembly information. Thank you"
                                 + NL + "Method:"
                                 + method.toGenericString()
                                 + NL + "Declaring Class:"
                                 + method.getDeclaringClass().toGenericString()
                                 + NL + "Types:"
                                 + mixinsModel.mixinTypes()
                                              .map( Class::toGenericString )
                                              .collect( Collectors.joining( NL ) );
                throw new UnsupportedOperationException( message );
            }
            throw new MissingMethodException( "Method '" + method + "' is not implemented" );
        }
        else
        {
            return compositeMethod.invoke( proxy, args, mixins, moduleInstance );
        }
    }
 
Example 19
protected String getFieldDescriptionFromMethod(Method method) {
    return "Autogenerated from j.l.r.Method [" + method.toGenericString() + "]";
}
 
Example 20
/**
 * Evaluates a method if an annotation is present and if true adds to the map of
 * life cycle methods.
 *
 * @param listener
 *            The listener instance.
 * @param annotation
 *            The annotation to check for.
 * @param method
 *            The method to evaluate.
 * @param methods
 *            The map of methods.
 */
private void evaluateMethod(Object listener, Class<? extends Annotation> annotation, Method method, Map<Object, Set<Method>> methods) {
    if (method.isAnnotationPresent(annotation)) {
        if (method.getParameterTypes().length != 1) {
            throw new XOException("Life cycle method '" + method.toGenericString() + "' annotated with '" + annotation.getName()
                    + "' must declare exactly one parameter but declares " + method.getParameterTypes().length + ".");
        }
        Set<Method> listenerMethods = methods.computeIfAbsent(listener, k -> new HashSet<>());
        listenerMethods.add(method);
    }
}