當前位置: 首頁>>代碼示例>>Java>>正文


Java Parameter.getAnnotation方法代碼示例

本文整理匯總了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;
}
 
開發者ID:bonigarcia,項目名稱:selenium-jupiter,代碼行數:22,代碼來源:AnnotationsReader.java

示例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);
  }
}
 
開發者ID:cescoffier,項目名稱:fluid,代碼行數:27,代碼來源:Fluid.java

示例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;
}
 
開發者ID:upperlevel,項目名稱:uppercore,代碼行數:28,代碼來源:FunctionCommandParameter.java

示例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();
}
 
開發者ID:viniciusccarvalho,項目名稱:spring-cloud-sockets,代碼行數:29,代碼來源:ServiceMethodInfo.java

示例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;
}
 
開發者ID:wujiangchao,項目名稱:chopsticks,代碼行數:8,代碼來源:MethodArgument.java

示例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;
}
 
開發者ID:wujiangchao,項目名稱:chopsticks,代碼行數:36,代碼來源:MethodArgument.java

示例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();
    }
}
 
開發者ID:tools4j,項目名稱:spockito,代碼行數:9,代碼來源:Spockito.java

示例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);
}
 
開發者ID:JeffreyFalgout,項目名稱:junit5-extensions,代碼行數:16,代碼來源:MockParameterFactory.java

示例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;
}
 
開發者ID:xinufo,項目名稱:teemo,代碼行數:10,代碼來源:MappedArgumentResolver.java

示例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");
}
 
開發者ID:xinufo,項目名稱:teemo,代碼行數:38,代碼來源:NamedArgumentResolver.java

示例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;
}
 
開發者ID:bonigarcia,項目名稱:selenium-jupiter,代碼行數:37,代碼來源:ChromeDriverHandler.java

示例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;
}
 
開發者ID:bonigarcia,項目名稱:selenium-jupiter,代碼行數:10,代碼來源:AnnotationsReader.java

示例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;
}
 
開發者ID:bonigarcia,項目名稱:selenium-jupiter,代碼行數:42,代碼來源:FirefoxDriverHandler.java

示例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);

    }
}
 
開發者ID:Nbsaw,項目名稱:miaohu,代碼行數:50,代碼來源:GetUrlUtils.java

示例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;
}
 
開發者ID:NymphWeb,項目名稱:nymph,代碼行數:71,代碼來源:ResovlerParamImpl.java


注:本文中的java.lang.reflect.Parameter.getAnnotation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。