Java Code Examples for ru.vyarus.java.generics.resolver.GenericsResolver#resolve()
The following examples show how to use
ru.vyarus.java.generics.resolver.GenericsResolver#resolve() .
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 File: TargetMethodAnalyzer.java From guice-persist-orient with MIT License | 6 votes |
/** * Analyze target bean methods, finding all matching (by parameters) methods. * If method name was specified, only methods with the same name resolved. * * @param target target bean type * @param params repository method params * @param hint method name hint (may be null) * @return descriptor of all matching methods */ private static List<MatchedMethod> findPossibleMethods(final List<Class<?>> params, final Class<?> target, final String hint) { final List<MatchedMethod> possibilities = Lists.newArrayList(); // use generics to enforce type checks final GenericsContext targetGenerics = GenericsResolver.resolve(target); for (Method method : target.getMethods()) { // method hint force to check only methods with this name final boolean methodHintValid = hint == null || method.getName().equals(hint); if (!isAcceptableMethod(method) || !methodHintValid) { continue; } final MatchedMethod matched = analyzeMethod(method, params, targetGenerics); if (matched != null) { possibilities.add(matched); } } return possibilities; }
Example 2
Source File: GenericsTrackingUtils.java From generics-resolver with MIT License | 5 votes |
private static Type[] alignParametrizationArguments(final Class<?> exactActualType, final Class<?> knownGenericType, final ParameterizedType knownGeneric, final LinkedHashMap<String, Type> knownGenerics) { final Type[] knownArguments; // if base types are equal we can match types in parametrization if (exactActualType.equals(knownGenericType)) { knownArguments = knownGeneric.getActualTypeArguments(); } else { // known generic type is a subclass of resolved root type.. inception! // trying to track generics if (knownGenericType.isAssignableFrom(exactActualType)) { // Actual type is higher then declared in generic: need to analyze this mismatch // (again not known root generics and known generics in sub type) final LinkedHashMap<String, Type> sub = track(exactActualType, knownGenericType, GenericsResolutionUtils.resolveGenerics(knownGeneric, knownGenerics)); knownArguments = sub.values().toArray(new Type[0]); } else { // actual class, resolved in root class hierarchy is a subtype of known generic type // building hierarchy for known generic value class and look generics of required subclass final GenericsContext ctx = GenericsResolver.resolve(knownGenericType); knownArguments = GenericInfoUtils.create(ctx, knownGeneric) .getTypeGenerics(exactActualType).values().toArray(new Type[0]); } } return knownArguments; }