本文整理汇总了Java中java.lang.reflect.Parameter.getAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java Parameter.getAnnotation方法的具体用法?Java Parameter.getAnnotation怎么用?Java Parameter.getAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.Parameter
的用法示例。
在下文中一共展示了Parameter.getAnnotation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUrl
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
public Optional<URL> getUrl(Parameter parameter,
Optional<Object> testInstance)
throws MalformedURLException, IllegalAccessException {
Optional<URL> out = empty();
String urlValue = null;
DriverUrl driverUrl = parameter.getAnnotation(DriverUrl.class);
if (driverUrl != null) {
// Search first DriverUrl annotation in parameter
urlValue = driverUrl.value();
out = Optional.of(new URL(urlValue));
} else {
// If not, search DriverUrl in any field
Optional<Object> annotatedField = seekFieldAnnotatedWith(
testInstance, DriverUrl.class);
if (annotatedField.isPresent()) {
urlValue = (String) annotatedField.get();
out = Optional.of(new URL(urlValue));
}
}
return out;
}
示例2: invoke
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
private void invoke(Object mediator, Method method) {
method = ReflectionHelper.makeAccessibleIfNot(method);
List<Object> values = new ArrayList<>();
for (Parameter param : method.getParameters()) {
Port port = param.getAnnotation(Port.class);
if (port != null) {
String name = port.value();
if (param.getType().isAssignableFrom(Sink.class)) {
values.add(getSinkOrFail(name));
} else if (param.getType().isAssignableFrom(Source.class)) {
values.add(getSourceOrFail(name));
}
} else {
throw new IllegalArgumentException("Invalid parameter - one parameter of " + method.getName()
+ " is not annotated with @Port");
}
}
try {
method.invoke(mediator, values.toArray());
} catch (Exception e) {
throw new IllegalStateException("Unable to invoke " + method.getName() + " from " + mediator.getClass()
.getName(), e);
}
}
示例3: FunctionCommandParameter
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
public FunctionCommandParameter(FunctionCommand command, Parameter parameter) {
super(command);
WithName nameAnnotation = parameter.getAnnotation(WithName.class);
if (nameAnnotation != null) {
setName(nameAnnotation.value());
}
WithOptional optionalAnnotation = parameter.getAnnotation(WithOptional.class);
if (optionalAnnotation != null) {
setOptional(true);
setDefaultValue(optionalAnnotation.value());
}
WithPermission permissionAnnotation = parameter.getAnnotation(WithPermission.class);
if (permissionAnnotation != null) {
StringJoiner path = new StringJoiner(".");
if (command.getPermission() != null) {
path.add(command.getPermission().getName());
}
path.add(permissionAnnotation.value());
Permission permission = new Permission(path.toString());
if (command.getPermission() != null) {
permission.addParent(command.getPermission(), true);
}
permission.setDescription(permissionAnnotation.value());
setPermission(permission);
}
this.parameter = parameter;
}
示例4: findPayloadParameter
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
private void findPayloadParameter(){
if(this.method.getParameterCount() == 0){
throw new IllegalStateException("Service methods must have at least one receiving parameter");
}
else if(this.method.getParameterCount() == 1){
this.payloadParameter = new MethodParameter(this.method, 0);
}
int payloadAnnotations = Flux.just(this.method.getParameters())
.filter(parameter -> parameter.getAnnotation(Payload.class) != null)
.reduce(0, (a, parameter) -> { return a+1; })
.block();
if(payloadAnnotations > 1){
throw new IllegalStateException("Service methods can have at most one @Payload annotated parameters");
}
for(int i=0; i<this.method.getParameters().length; i++){
Parameter p = this.method.getParameters()[i];
if(p.getAnnotation(Payload.class) != null){
this.payloadParameter = new MethodParameter(this.method, i);
break;
}
}
if(this.payloadParameter == null){
throw new IllegalStateException("Service methods annotated with more than one parameter must declare one @Payload parameter");
}
resolvePayloadType();
}
示例5: containsAnnotation
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
private static boolean containsAnnotation(Parameter parameter) {
return parameter.getAnnotation(PathParam.class) != null || parameter.getAnnotation(Param.class) != null
|| parameter.getAnnotation(HeaderParam.class) != null
|| parameter.getAnnotation(BodyParam.class) != null
|| parameter.getAnnotation(CookieParam.class) != null
|| parameter.getAnnotation(MultipartParam.class) != null;
}
示例6: getAnnotationParam
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
private static Object getAnnotationParam(Parameter parameter, String paramName, Request request) throws Exception {
Class<?> argType = parameter.getType();
Param param = parameter.getAnnotation(Param.class);
if (null != param) {
return getQueryParam(
ParamStrut.builder().argType(argType).param(param).paramName(paramName).request(request).build());
}
BodyParam bodyParam = parameter.getAnnotation(BodyParam.class);
if (null != bodyParam) {
return getBodyParam(ParamStrut.builder().argType(argType).request(request).build());
}
PathParam pathParam = parameter.getAnnotation(PathParam.class);
if (null != pathParam) {
return getPathParam(ParamStrut.builder().argType(argType).pathParam(pathParam).paramName(paramName)
.request(request).build());
}
HeaderParam headerParam = parameter.getAnnotation(HeaderParam.class);
if (null != headerParam) {
return getHeader(ParamStrut.builder().argType(argType).headerParam(headerParam).paramName(paramName)
.request(request).build());
}
// cookie param
CookieParam cookieParam = parameter.getAnnotation(CookieParam.class);
if (null != cookieParam) {
return getCookie(ParamStrut.builder().argType(argType).cookieParam(cookieParam).paramName(paramName)
.request(request).build());
}
// form multipart
MultipartParam multipartParam = parameter.getAnnotation(MultipartParam.class);
if (null != multipartParam && argType == FileItem.class) {
String name = StringKit.isBlank(multipartParam.value()) ? paramName : multipartParam.value();
return request.fileItem(name).orElse(null);
}
return null;
}
示例7: parameterRefNameOrNull
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
static String parameterRefNameOrNull(final Parameter parameter) {
final Spockito.Ref ref = parameter.getAnnotation(Spockito.Ref.class);
if (ref == null) {
return parameter.isNamePresent() ? parameter.getName() : null;
} else {
return ref.value();
}
}
示例8: getParameterValue
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
@Override
public Object getParameterValue(Parameter parameter) {
Mock annotation = parameter.getAnnotation(Mock.class);
MockSettings settings = Mockito.withSettings();
if (annotation.extraInterfaces().length > 0) {
settings.extraInterfaces(annotation.extraInterfaces());
}
if (annotation.serializable()) {
settings.serializable();
}
settings.name(annotation.name().isEmpty() ? parameter.getName() : annotation.name());
settings.defaultAnswer(annotation.answer());
return Mockito.mock(parameter.getType(), settings);
}
示例9: getMapper
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
private IRowMapper getMapper(Parameter param) {
Mapper vAnno = param.getAnnotation(Mapper.class);
Class<? extends IRowMapper> vClazz = vAnno.value();
IRowMapper vMapper = getMapperFromCache(vClazz);
if (vMapper == null) {
vMapper = createMapper(vClazz);
}
return vMapper;
}
示例10: resolve
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
@Override
public Object resolve(Parameter param, IRow row) {
Key vKey = param.getAnnotation(Key.class);
String vColumnName = vKey.value();
Class<?> vClazz = param.getType();
if (vClazz == boolean.class) {
return row.getBoolean(vColumnName);
}
if (vClazz == char.class) {
return row.getChar(vColumnName);
}
if (vClazz == byte.class) {
return row.getByte(vColumnName);
}
if (vClazz == short.class) {
return row.getShort(vColumnName);
}
if (vClazz == int.class) {
return row.getInt(vColumnName);
}
if (vClazz == long.class) {
return row.getLong(vColumnName);
}
if (vClazz == float.class) {
return row.getFloat(vColumnName);
}
if (vClazz == double.class) {
return row.getDouble(vColumnName);
}
if (vClazz == String.class) {
return row.getString(vColumnName);
}
if (vClazz == Date.class) {
return row.getDate(vColumnName);
}
throw new IllegalArgumentException("Should never be here");
}
示例11: getOptions
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
@Override
public MutableCapabilities getOptions(Parameter parameter,
Optional<Object> testInstance)
throws IOException, IllegalAccessException {
ChromeOptions chromeOptions = new ChromeOptions();
// @Arguments
Arguments arguments = parameter.getAnnotation(Arguments.class);
if (arguments != null) {
stream(arguments.value()).forEach(chromeOptions::addArguments);
}
// @Extensions
Extensions extensions = parameter.getAnnotation(Extensions.class);
if (extensions != null) {
for (String extension : extensions.value()) {
chromeOptions.addExtensions(getExtension(extension));
}
}
// @Binary
Binary binary = parameter.getAnnotation(Binary.class);
if (binary != null) {
chromeOptions.setBinary(binary.value());
}
// @Options
Object optionsFromAnnotatedField = annotationsReader
.getOptionsFromAnnotatedField(testInstance, Options.class);
if (optionsFromAnnotatedField != null) {
chromeOptions = ((ChromeOptions) optionsFromAnnotatedField)
.merge(chromeOptions);
}
return chromeOptions;
}
示例12: getDocker
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
public Optional<DockerBrowser> getDocker(Parameter parameter) {
Optional<DockerBrowser> out = empty();
DockerBrowser dockerBrowser = parameter
.getAnnotation(DockerBrowser.class);
if (dockerBrowser != null) {
out = Optional.of(dockerBrowser);
}
return out;
}
示例13: getOptions
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
@Override
public MutableCapabilities getOptions(Parameter parameter,
Optional<Object> testInstance)
throws IOException, IllegalAccessException {
FirefoxOptions firefoxOptions = new FirefoxOptions();
// @Arguments
Arguments arguments = parameter.getAnnotation(Arguments.class);
if (arguments != null) {
stream(arguments.value()).forEach(firefoxOptions::addArguments);
}
// @Extensions
Extensions extensions = parameter.getAnnotation(Extensions.class);
if (extensions != null) {
for (String extension : extensions.value()) {
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(getExtension(extension));
firefoxOptions.setProfile(firefoxProfile);
}
}
// @Binary
Binary binary = parameter.getAnnotation(Binary.class);
if (binary != null) {
firefoxOptions.setBinary(binary.value());
}
// @Preferences
managePreferences(parameter, firefoxOptions);
// @Options
Object optionsFromAnnotatedField = annotationsReader
.getOptionsFromAnnotatedField(testInstance, Options.class);
if (optionsFromAnnotatedField != null) {
firefoxOptions = ((FirefoxOptions) optionsFromAnnotatedField)
.merge(firefoxOptions);
}
return firefoxOptions;
}
示例14: scanClass
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
private static void scanClass(Class klazz){
// 检查是否有@RequestHeader("token")参数
// 主要是怕日后有其他用了header参数的会留坑
Method[] methods = klazz.getMethods();
List<String> infix = new LinkedList();
for (Method method : methods){
Parameter[] parameters = method.getParameters();
for (Parameter parameter : parameters){
if (parameter.getAnnotation(RequestHeader.class) != null
&& parameter.getAnnotation(RequestHeader.class).value().equals("token")){
// 判断是哪一种注解
for (Annotation annotation : method.getAnnotations()){
if (annotation instanceof GetMapping){
addInfix(infix,((GetMapping) annotation).value());
}
else if (annotation instanceof PostMapping){
addInfix(infix,((PostMapping) annotation).value());
}
else if (annotation instanceof PutMapping){
addInfix(infix,((PutMapping) annotation).value());
}
else if (annotation instanceof DeleteMapping){
addInfix(infix,((DeleteMapping) annotation).value());
}
}
}
}
}
// 如果中缀不为空尝试获取前缀
if (infix.size() > 0){
// 前缀获取
String prefix[] = null;
if (klazz.isAnnotationPresent(RequestMapping.class)){
RequestMapping requestMapping = (RequestMapping) klazz.getAnnotation(RequestMapping.class);
prefix = requestMapping.value();
}
// 前缀不为空添加前缀
if (prefix.length > 0){
for (String p : prefix){
for (String i : infix)
result.add(p + i);
}
}
// 前缀为空直接把中缀加到url列表里
else
result.addAll(infix);
}
}
示例15: injectParameters
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
@Override
public Object[] injectParameters() throws Throwable {
Object[] args = new Object[methodWrapper.getParamterLength()];
for (int i = 1; i < args.length; i++) {
// 当前方法参数的名称
String paramName = methodWrapper.getParameterName(i);
// 在请求参数中寻找和当前方法形参名相同的对应的参数值
String[] param = paramMap.get(paramName);
// 当前方法的参数对象
Parameter parameter = methodWrapper.getParameter(i);
// 当前方法参数的类型
Class<?> paramType = parameter.getType();
if (paramType == Transfer.class) {
// 操作request 和 session的类
args[i] = new Transfer(wrapper);
}
else if (paramType == Share.class) {
// 文件下载类
args[i] = new Share(wrapper);
}
else if (paramType == Multipart.class) {
// 文件上传的类
args[i] = multipartCheck(contextParameter.getMultipart());
}
else if (parameter.isAnnotationPresent(UrlHolder.class)) {
// 获取到方法参数内的@UrlHolder注解对象
UrlHolder urlVar = parameter.getAnnotation(UrlHolder.class);
// 在map中获取@UrlHolder value()方法中字符串对应的值
String string = contextParameter.getPlaceHolder(paramName);
if (string == null) {
string = contextParameter.getPlaceHolder(urlVar.value());
}
args[i] = BasicUtil.convert(paramType, string);
}
else if (BasicUtil.isCollection(paramType)) { // 当参数为集合时
// 当集合的泛型是primitive时 如 int long 这里也把String当做原生类型
if (BasicUtil.isCommonCollection(parameter.getParameterizedType())) {
args[i] = BasicUtil.convertList(paramType, param);
}
// 当集合的泛型为 除上面之外的其他java对象时
else {
existDateFormatAnnotation(parameter);
args[i] = resultList(parameter.getParameterizedType());
cycleControl();
}
}
else if (BasicUtil.isCommonType(paramType)) { // 当参数为基本类型时
// param数组为空时结束此次循环
if (BasicUtil.notNullAndLenNotZero(param))
continue;
args[i] = BasicUtil.convert(paramType, param[0]);
}
else if (paramType == Date.class) { // 当参数为时间类型时
// param数组为空时结束此次循环
if (BasicUtil.notNullAndLenNotZero(param))
continue;
existDateFormatAnnotation(parameter);
dateFormatCheck(format);
args[i] = DateUtil.resolve(param[0], format);
}
else { // 这里一般表示用户自定义的java对象
existDateFormatAnnotation(parameter);
args[i] = resultSingle(paramType, 0);
cycleControl();
}
}
return args;
}