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);
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations