Search in sources :

Example 86 with Parameter

use of java.lang.reflect.Parameter in project mars-fx by duderstadt-lab.

the class GroovySuggestionGenerator method addToAutoCompletionClasses.

private void addToAutoCompletionClasses(Class clazz, String library) {
    List<CompletionItem> classItemList = new ArrayList<CompletionItem>();
    List<Class> allClasses = ClassUtils.getAllSuperclasses(clazz);
    allClasses.add(0, clazz);
    for (Class c : allClasses) {
        Method[] methods = c.getDeclaredMethods();
        for (Method method : methods) {
            if (!Modifier.isPublic(method.getModifiers()))
                continue;
            boolean overridden = false;
            for (CompletionItem item : classItemList) {
                if (item.getMethod().getName().equals(method.getName())) {
                    if (method.getParameters().length == 0)
                        overridden = true;
                    else if (Arrays.equals(method.getParameterTypes(), item.getMethod().getParameterTypes())) {
                        overridden = true;
                    }
                }
            }
            if (overridden)
                continue;
            String description = "<ul>";
            String shortDesc = method.getName() + "(";
            String replacementText = method.getName() + "(";
            String parameters = "-";
            for (Parameter parameter : method.getParameters()) {
                if (!shortDesc.endsWith("(")) {
                    shortDesc = shortDesc + ", ";
                }
                shortDesc = shortDesc + parameter.getType().getSimpleName() + " " + parameter.getName();
                if (!replacementText.endsWith("(")) {
                    replacementText = replacementText + ", ";
                }
                replacementText = replacementText + parameter.getName();
                description = description + "<li>" + parameter.getType().getSimpleName() + " " + parameter.getName() + "</li>";
                parameters = parameters + parameter.getType().getCanonicalName() + "-";
            }
            shortDesc = shortDesc + ") : " + method.getReturnType().getSimpleName();
            replacementText = replacementText + ")";
            description = description + "</ul>";
            if (parameters.length() == 1) {
                parameters = parameters + "-";
            }
            String classLink = getUrlPrefix(c.getCanonicalName(), library) + "/" + c.getCanonicalName().replace(".", "/") + ".html";
            String methodLink = classLink + "#" + method.getName() + parameters;
            // // System.out.println("Link: " + link);
            description = "<a href=\"" + methodLink + "\">" + method.getName() + "</a><br>" + description;
            description = description + "<br>" + "Defined in " + "<a href=\"" + methodLink + "\">" + c.getCanonicalName() + "</a><br>";
            description = description + "<br>" + "returns " + method.getReturnType().getSimpleName();
            classItemList.add(new CompletionItem(method, replacementText, shortDesc, description));
        }
    }
    autoCompletionClasses.put(clazz, classItemList);
}
Also used : ArrayList(java.util.ArrayList) Parameter(java.lang.reflect.Parameter) Method(java.lang.reflect.Method)

Example 87 with Parameter

use of java.lang.reflect.Parameter in project hummer-framework by hummer-team.

the class KeyUtil method getFieldNameTypeMap.

private static Map<String, String> getFieldNameTypeMap(ProceedingJoinPoint point) {
    Parameter[] parameters = ((MethodSignature) point.getSignature()).getMethod().getParameters();
    if (parameters == null) {
        return Collections.emptyMap();
    }
    Map<String, String> clsMap = Maps.newHashMapWithExpectedSize(16);
    for (int p = 0; p < parameters.length; p++) {
        clsMap.put(parameters[p].getName(), parameters[p].getType().getSimpleName());
    }
    return clsMap;
}
Also used : Parameter(java.lang.reflect.Parameter) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint)

Example 88 with Parameter

use of java.lang.reflect.Parameter in project hummer-framework by hummer-team.

the class KeyUtil method getFieldNameValueMap.

public static Map<String, Object> getFieldNameValueMap(ProceedingJoinPoint joinPoint, String keyName, String keyValue) {
    // 
    Parameter[] parameters = ((MethodSignature) joinPoint.getSignature()).getMethod().getParameters();
    if (parameters == null) {
        return Collections.emptyMap();
    }
    Map<String, Object> clsMap = Maps.newHashMapWithExpectedSize(16);
    for (int p = 0; p < parameters.length; p++) {
        clsMap.put(parameters[p].getName(), parameters[p].getType().getSimpleName());
    }
    clsMap.put(keyName, keyValue);
    return clsMap;
}
Also used : Parameter(java.lang.reflect.Parameter) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint)

Example 89 with Parameter

use of java.lang.reflect.Parameter in project hummer-framework by hummer-team.

the class CacheKeyUtil method getFieldNameValueMap.

public static Map<String, Object> getFieldNameValueMap(ProceedingJoinPoint joinPoint) throws IllegalAccessException {
    // 
    Parameter[] parameters = ((MethodSignature) joinPoint.getSignature()).getMethod().getParameters();
    if (parameters == null) {
        return Collections.emptyMap();
    }
    Object[] args = joinPoint.getArgs();
    Map<String, Object> clsMap = Maps.newHashMapWithExpectedSize(16);
    for (int p = 0; p < parameters.length; p++) {
        HummerSimpleObjectCacheKey key = parameters[p].getAnnotation(HummerSimpleObjectCacheKey.class);
        if (key != null) {
            clsMap.put(StringUtils.isEmpty(key.keyName()) ? parameters[p].getName() : key.keyName(), formatValue(key, args[p]));
        }
    }
    for (Object arg : args) {
        if (arg == null) {
            continue;
        }
        Class<?> cls = arg.getClass();
        // class type
        if (!cls.isPrimitive()) {
            for (Field f : cls.getDeclaredFields()) {
                HummerSimpleObjectCacheKey key = f.getAnnotation(HummerSimpleObjectCacheKey.class);
                if (key != null) {
                    f.setAccessible(true);
                    clsMap.put(StringUtils.isEmpty(key.keyName()) ? f.getName() : key.keyName(), formatValue(key, f.get(arg)));
                }
            }
        } else {
            HummerSimpleObjectCacheKey key2 = cls.getAnnotation(HummerSimpleObjectCacheKey.class);
            if (key2 != null) {
                clsMap.put(StringUtils.isEmpty(key2.keyName()) ? cls.getSimpleName() : key2.keyName(), formatValue(key2, arg));
            }
        }
    }
    return clsMap;
}
Also used : Field(java.lang.reflect.Field) Parameter(java.lang.reflect.Parameter) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint)

Example 90 with Parameter

use of java.lang.reflect.Parameter in project hummer-framework by hummer-team.

the class FallbackStubFactory method createStub.

@Override
public AbstractStub<?> createStub(final Class<? extends AbstractStub<?>> stubType, final Channel channel) {
    try {
        // Search for public static *Grpc#new*Stub(Channel)
        final Class<?> declaringClass = stubType.getDeclaringClass();
        if (declaringClass != null) {
            for (final Method method : declaringClass.getMethods()) {
                final String name = method.getName();
                final int modifiers = method.getModifiers();
                final Parameter[] parameters = method.getParameters();
                if (name.startsWith("new") && name.endsWith("Stub") && Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers) && method.getReturnType().isAssignableFrom(stubType) && parameters.length == 1 && Channel.class.equals(parameters[0].getType())) {
                    return AbstractStub.class.cast(method.invoke(null, channel));
                }
            }
        }
        // Search for a public constructor *Stub(Channel)
        final Constructor<? extends AbstractStub<?>> constructor = stubType.getConstructor(Channel.class);
        return constructor.newInstance(channel);
    } catch (final Exception e) {
        throw new BeanInstantiationException(stubType, "Failed to create gRPC client via FallbackStubFactory", e);
    }
}
Also used : Channel(io.grpc.Channel) BeanInstantiationException(org.springframework.beans.BeanInstantiationException) Parameter(java.lang.reflect.Parameter) Method(java.lang.reflect.Method) BeanInstantiationException(org.springframework.beans.BeanInstantiationException)

Aggregations

Parameter (java.lang.reflect.Parameter)771 Method (java.lang.reflect.Method)276 ArrayList (java.util.ArrayList)142 Annotation (java.lang.annotation.Annotation)95 List (java.util.List)90 Type (java.lang.reflect.Type)77 HashMap (java.util.HashMap)75 Map (java.util.Map)72 Constructor (java.lang.reflect.Constructor)60 Test (org.junit.jupiter.api.Test)57 Arrays (java.util.Arrays)53 InvocationTargetException (java.lang.reflect.InvocationTargetException)52 Executable (java.lang.reflect.Executable)50 Field (java.lang.reflect.Field)45 Collectors (java.util.stream.Collectors)45 ParameterizedType (java.lang.reflect.ParameterizedType)42 Optional (java.util.Optional)42 Test (org.junit.Test)42 Set (java.util.Set)37 Modifier (java.lang.reflect.Modifier)29