public static Object[] isSimpleGeneric(Type type, ClassTypeResolver classTypeResolver) throws ModelDriverException { Object[] result = new Object[3]; result[0] = false; result[1] = null; result[2] = null; if (type.isArray() || type.isPrimitive() || !type.isParameterized() || (type.isParameterized() && type.getTypeArguments().size() != 1)) { return result; } Type<?> argument = ((List<Type>) type.getTypeArguments()).get(0); if (!isSimpleClass(argument)) { return result; } try { String outerClass = classTypeResolver.getFullTypeName(type.getName()); String argumentClass = classTypeResolver.getFullTypeName(argument.getName()); result[0] = true; result[1] = outerClass; result[2] = argumentClass; return result; } catch (ClassNotFoundException e) { throw new ModelDriverException( "Class could not be resolved for name: " + type.getName() + ". " + e.getMessage(), e); } }
@Override public String getName() { List<String> parameterTypes = new ArrayList<>(); for (Parameter<?> p : method.getParameters()) { parameterTypes.add(p.getType().getQualifiedName()); } Type<?> methodReturnType = method.getReturnType(); String returnType = (method.isReturnTypeVoid() || methodReturnType == null) ? "void" : methodReturnType.getQualifiedName(); return String.format( "%s(%s)::%s", method.getName(), Strings.join(parameterTypes, ","), returnType); }
public static boolean equalsType( Type type, String fullClassName, boolean multiple, String fullBagClassName, ClassTypeResolver classTypeResolver) throws Exception { String currentClassName; String currentBag; if (type.isArray()) { return false; } if (type.isPrimitive()) { return !multiple && fullClassName.equals(type.getName()); } if (isSimpleClass(type)) { currentClassName = classTypeResolver.getFullTypeName(type.getName()); return !multiple && fullClassName.equals(currentClassName); } Object[] simpleGenerics = isSimpleGeneric(type, classTypeResolver); if (multiple && Boolean.TRUE.equals(simpleGenerics[0]) && isManagedType(type, classTypeResolver)) { currentBag = (String) simpleGenerics[1]; currentBag = classTypeResolver.getFullTypeName(currentBag); currentClassName = (String) simpleGenerics[2]; currentClassName = classTypeResolver.getFullTypeName(currentClassName); return fullBagClassName.equals(currentBag) && fullClassName.equals(currentClassName); } return false; }
/** * @return Return true if the given type can be managed by the driver, and subsequently by the UI. * <p>E.g. of managed types are: int, Integer, java.lang.Integer, org.kie.SomeClass, * List<Integer>, java.util.List<org.kie.SomeClass> * <p>e.g. of not manged types are: int[], java.util.List<List<String>>, List<Map<String, * org.kie.SomeClass>> */ public static boolean isManagedType(Type type, ClassTypeResolver classTypeResolver) throws ModelDriverException { // quickest checks first. if (type.isPrimitive()) { return true; } if (type.isArray()) { return false; } if (type.isParameterized() && type.getTypeArguments().size() > 1) { return false; } try { Class<?> clazz = classTypeResolver.resolveType(type.getName()); if (clazz.isAnonymousClass() || clazz.isLocalClass() || clazz.isMemberClass()) { return false; } if (type.isParameterized()) { Class<?> bag = classTypeResolver.resolveType(type.getName()); if (!Collection.class.isAssignableFrom(bag)) { return false; } return isSimpleClass(((List<Type>) type.getTypeArguments()).get(0)); } return true; } catch (ClassNotFoundException e) { throw new ModelDriverException( "Class could not be resolved for name: " + type.getName() + ". " + e.getMessage(), e); } }
public static boolean isSimpleClass(Type<?> type) { return !type.isArray() && !type.isPrimitive() && !type.isParameterized(); }