com.google.common.reflect.Parameter Java Examples
The following examples show how to use
com.google.common.reflect.Parameter.
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: SetterAndFieldFixtureMapper.java From beanmother with Apache License 2.0 | 6 votes |
@Override protected void bind(Object target, String key, FixtureMap fixtureMap) { List<Method> candidates = findSetterCandidates(target, key); for (Method candidate : candidates) { ImmutableList<Parameter> paramTypes = Invokable.from(candidate).getParameters(); if (paramTypes.size() != 1) continue; TypeToken<?> paramType = paramTypes.get(0).getType(); try { Object candidateParam = getFixtureConverter().convert(fixtureMap, paramType); if (candidateParam != null) { candidate.invoke(target, candidateParam); return; } } catch (Exception e) { throw new FixtureMappingException(e); } } bindByField(target, key, fixtureMap); }
Example #2
Source File: SetterAndFieldFixtureMapper.java From beanmother with Apache License 2.0 | 6 votes |
@Override protected void bind(Object target, String key, FixtureList fixtureList) { List<Method> candidates = findSetterCandidates(target, key); for (Method candidate :candidates) { try { ImmutableList<Parameter> paramTypes = Invokable.from(candidate).getParameters(); if (paramTypes.size() != 1) continue; TypeToken<?> paramType = paramTypes.get(0).getType(); Object candidateParam = getFixtureConverter().convert(fixtureList, paramType); if (candidateParam != null) { candidate.invoke(target, candidateParam); return; } } catch (Exception e) { throw new FixtureMappingException(e); } } bindByField(target, key, fixtureList); }
Example #3
Source File: SetterAndFieldFixtureMapper.java From beanmother with Apache License 2.0 | 6 votes |
@Override protected void bind(Object target, String key, FixtureValue fixtureValue) { if (fixtureValue == null || fixtureValue.isNull()) return; List<Method> candidates = findSetterCandidates(target, key); for (Method candidate : candidates) { ImmutableList<Parameter> paramTypes = Invokable.from(candidate).getParameters(); if (paramTypes == null || paramTypes.size() != 1) continue; TypeToken<?> paramType = paramTypes.get(0).getType(); Object param = getFixtureConverter().convert(fixtureValue, paramType); if (param == null) continue; try { candidate.invoke(target, param); } catch (Exception e) { throw new FixtureMappingException(e); } } bindByField(target, key, fixtureValue); }
Example #4
Source File: AnnotatedAuroraAdminTest.java From attic-aurora with Apache License 2.0 | 6 votes |
@Test public void testAllAuroraSchedulerManagerIfaceMethodsHaveAuthorizingParam() throws Exception { for (Method declaredMethod : AuroraSchedulerManager.Iface.class.getDeclaredMethods()) { Invokable<?, ?> invokable = Invokable.from(declaredMethod); Collection<Parameter> parameters = invokable.getParameters(); Invokable<?, ?> annotatedInvokable = Invokable.from( AnnotatedAuroraAdmin.class.getDeclaredMethod( invokable.getName(), FluentIterable.from(parameters) .transform(input -> input.getType().getRawType()) .toList() .toArray(new Class<?>[0]))); Collection<Parameter> annotatedParameters = Collections2.filter( annotatedInvokable.getParameters(), input -> input.getAnnotation(AuthorizingParam.class) != null); assertFalse( "Method " + invokable + " should have at least 1 " + AuthorizingParam.class.getName() + " annotation but none were found.", annotatedParameters.isEmpty()); } }
Example #5
Source File: GenericMethodType.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public static GenericMethodType<?> of(Invokable<?, ?> invokable) { return new GenericMethodType<>(invokable.getReturnType(), invokable.getParameters() .stream() .map(Parameter::getType) .collect(Collectors.toImmutableList())); }
Example #6
Source File: Methods.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
public static MethodType methodType(TypeToken<?> returnType, Collection<Parameter> parameters) { return MethodType.methodType(returnType.getRawType(), parameters.stream() .map(p -> p.getType().getRawType()) .collect(Collectors.toList())); }