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

The following are Jave code examples for showing how to use toGenericString() of the java.lang.reflect.Method class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: AgentWeb   File: AgentWebUtils.java   View Source Code Vote up 6 votes
static boolean isOverriedMethod(Object currentObject, String methodName, String method, Class... clazzs) {
    LogUtils.i(TAG, "  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) {
        if (LogUtils.isDebug()) {
            igonre.printStackTrace();
        }
    }

    LogUtils.i(TAG, "isOverriedMethod:" + tag);
    return tag;
}
 
Example 2
Project: AgentWebX5   File: AgentWebX5Utils.java   View Source Code Vote up 6 votes
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
Project: goodees   File: ProxiedSyncEventSourcingRuntime.java   View Source Code Vote up 6 votes
private void checkAsyncInterface() {
    for (Method m : asyncRequestHandlerClass.getMethods()) {
        try {
            if (!m.getReturnType().isAssignableFrom(CompletableFuture.class) || m.getReturnType().equals(Object.class)) {
                throw new IllegalArgumentException("All methods of async request handler must return CompletableFuture. "
                        + "Offending method: "+m.toGenericString());
            }
            //CompletableFuture<T>
            Class<?> targetType = (Class<?>)((ParameterizedType) m.getGenericReturnType()).getActualTypeArguments()[0];
            Method originalMethod = requestHandlerClass.getMethod(m.getName(), m.getParameterTypes());
            if (originalMethod.getReturnType().equals(void.class) ? !targetType.equals(Void.class) // more primitive handling needed
                    : !targetType.isAssignableFrom(originalMethod.getReturnType())) {
                throw new IllegalArgumentException("Return type is not compatible for "+m.toGenericString()+
                        ". Original method returns "+originalMethod.getGenericReturnType().getTypeName());
            }
            mapping.put(m, originalMethod);
        } catch (NoSuchMethodException | SecurityException ex) {
            throw new IllegalStateException("Cannot inspect request handler classes", ex);
        }
    }
}
 
Example 4
Project: BRjLibs   File: EventBus.java   View Source Code Vote up 6 votes
/**
 * Registers a new listener.
 *
 * @param listener The listener to register
 */
public void register(Object listener) {
    if(listener == null) throw new NullPointerException("listener");
    Class<?> listenerClass = listener.getClass();
    if(Modifier.isPublic(listenerClass.getModifiers())) {
        for(ASMEventHandler h : handlers(listener)) {
            getHandlers(h.getEventClass(), Listener.Priority.MEDIUM).add(new Pair<>(listener, h));
        }
    } else {//Cannot access the class, reflection is the only option
        for(Method m : listenerClass.getMethods()) {
            Listener list = m.getAnnotation(Listener.class);
            if(list == null) continue;
            Class<?>[] params = m.getParameterTypes();
            if(params.length != 1)
                throw new IllegalArgumentException("parameterTypes.length != 1: " + m.toGenericString());
            getHandlers(params[0], Listener.Priority.MEDIUM).add(new Pair<>(listener, new ReflectionEventHandler(listener, m)));
        }
    }
}
 
Example 5
Project: oscm   File: AbstractVOConverter.java   View Source Code Vote up 5 votes
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 6
Project: oscm   File: AbstractVOConverter.java   View Source Code Vote up 5 votes
private void setListField(Object newVO, Object oldVO, Method method)
        throws IllegalAccessException, InvocationTargetException,
        NoSuchMethodException, ClassNotFoundException {
    String className = method.toGenericString();
    className = className.substring(className.indexOf('<') + 1,
            className.indexOf('>'));
    final List<?> list = convertList((List<?>) method.invoke(oldVO),
            Class.forName(getNewClassName(Class.forName(className))));
    newVO.getClass().getMethod(getSetter(method), method.getReturnType())
            .invoke(newVO, list);
}
 
Example 7
Project: jkami   File: MapperProxy.java   View Source Code Vote up 5 votes
/**
 * 获取注解参数
 * 
 * @param method
 * @param args
 * @return
 */
@SuppressWarnings("unchecked")
private Map<String, Object> getParamMap(Method method, Object[] args) {
    Map<String, Object> paramMap = new HashMap<>();
    if (args == null) {
        return paramMap;
    }
    Annotation[][] parameterAnnotations = method.getParameterAnnotations();
    if ((parameterAnnotations == null || parameterAnnotations.length < args.length) && args.length > 0) {
        throw new JkException(this.getMapperInterface().getName() + "@Param is missing");
    }
    for (int i = 0; i < args.length; i++) {
        Object arg = args[i];
        Annotation[] as = parameterAnnotations[i];
        if (as.length == 0) {
            throw new JkException(method.toGenericString() + " @Param not find ");
        }
        if (arg instanceof Map) {
            Map<String, Object> mmp = (Map<String, Object>) arg;
            for (Entry<String, Object> entry : mmp.entrySet()) {
                Object val = entry.getValue();
                if (val instanceof String) {
                    // 转移sql防注入
                    entry.setValue(SqlUtils.escapeSql((String) val));
                }
            }
            paramMap.putAll(mmp);
        }
        // 转移sql防注入
        if (arg instanceof String) {
            arg = SqlUtils.escapeSql((String) arg);
        }
        Param param = (Param) as[0];
        paramMap.put(param.value(), arg);
    }
    return paramMap;
}
 
Example 8
Project: amanda   File: FileServerUtil.java   View Source Code Vote up 5 votes
/**
 * Url获取函数,作为函数传入StorageService。
 * @param path
 * @return FileInfo
 */
public static String getPathUrl(Path path) {
    String resourcePath = path.getName(0).relativize(path).toString().replace("\\", "/");
    String methodName = path.toFile().isDirectory() ? "viewDir" : "serveFile";
    Method method;
    try {
        method = FileServerEndpoint.class.getDeclaredMethod(methodName, HttpServletRequest.class);
    } catch (NoSuchMethodException e) {
        throw new IllegalArgumentException("No " + methodName + " method in " + FileServerEndpoint.class.getSimpleName());
    }

    String methodPath;
    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])) {
        methodPath = "/";
    }else {
        methodPath = paths[0].substring(0, paths[0].length() - 2);
    }

    String baseUrl = MvcUriComponentsBuilder
            .fromController(FileServerEndpoint.class)
            .build().toString();

    String pathUrl = baseUrl + methodPath + resourcePath;

    return pathUrl;
}
 
Example 9
Project: OpenJSharp   File: MethodRef.java   View Source Code Vote up 5 votes
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
Project: jdk8u-jdk   File: MethodRef.java   View Source Code Vote up 5 votes
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
Project: openjdk-jdk10   File: MethodRef.java   View Source Code Vote up 5 votes
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 12
Project: vscrawler   File: AnnotationSeedProcessor.java   View Source Code Vote up 5 votes
private void judgeDownloader(Class<? extends AbstractAutoProcessModel> aClass) {
    Method[] methods = aClass.getMethods();
    for (final Method method : methods) {
        if (method.getAnnotation(DownLoadMethod.class) == null) {
            continue;
        }
        Preconditions.checkArgument(String.class.isAssignableFrom(method.getReturnType()));
        Preconditions.checkArgument(method.getParameterTypes().length >= 2);
        Preconditions.checkArgument(method.getParameterTypes()[0].isAssignableFrom(Seed.class));
        Preconditions.checkArgument(method.getParameterTypes()[1].isAssignableFrom(CrawlerSession.class));

        downloader = new Downloader() {
            @Override
            public String download(Seed seed, AbstractAutoProcessModel model, CrawlerSession crawlerSession) {
                try {
                    return (String) method.invoke(model, seed, crawlerSession);
                } catch (Exception e) {
                    throw new RuntimeException("invoke download method :" + method.toGenericString() + " failed", e);
                }
            }
        };
        return;
    }

    downloader = new Downloader() {
        @Override
        public String download(Seed seed, AbstractAutoProcessModel model, CrawlerSession crawlerSession) {
            return crawlerSession.getCrawlerHttpClient().get(seed.getData());
        }
    };
}
 
Example 13
Project: perceptor   File: Invocation.java   View Source Code Vote up 4 votes
public Invocation(Method methodName) {
    this.methodName = methodName.toGenericString();
}