当前位置: 首页>>代码示例>>Java>>正文


Java Method.getParameterAnnotations方法代码示例

本文整理汇总了Java中java.lang.reflect.Method.getParameterAnnotations方法的典型用法代码示例。如果您正苦于以下问题:Java Method.getParameterAnnotations方法的具体用法?Java Method.getParameterAnnotations怎么用?Java Method.getParameterAnnotations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.reflect.Method的用法示例。


在下文中一共展示了Method.getParameterAnnotations方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initAnnotationsWithName

import java.lang.reflect.Method; //导入方法依赖的package包/类
private void initAnnotationsWithName(final Method method) {
    final Annotation[][] annotations = method.getParameterAnnotations();
    Fn.itArray(annotations, (annotationArr, index) -> {
        // Find annotation class
        final Annotation annotation = findAnnotation(annotationArr);
        final Class<? extends Annotation> annoCls = (null == annotation)
                ? null : annotation.annotationType();
        this.paramAnnos.add(annoCls);
        // Check names
        if (null != annoCls) {
            if (Filler.NO_VALUE.contains(annoCls)) {
                this.paramNames.add(ID.DIRECT);
            } else {
                final String name = Instance.invoke(annotation, "value");
                this.paramNames.add(name);
            }
        } else {
            this.paramNames.add(ID.IGNORE);
        }
        // Besure the params are length match others.
        this.paramValues.add(null);
    });
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:24,代码来源:Depot.java

示例2: getInParameterName

import java.lang.reflect.Method; //导入方法依赖的package包/类
@Override
public QName getInParameterName(OperationInfo op, Method method, int paramNumber)
{
	Annotation[][] annos = method.getParameterAnnotations();
	if( annos.length > paramNumber )
	{
		Annotation[] paramAnnos = annos[paramNumber];
		for( Annotation anno : paramAnnos )
		{
			if( anno instanceof WebParam )
			{
				WebParam webParam = (WebParam) anno;
				String targetNs = webParam.targetNamespace();
				if( Check.isEmpty(targetNs) )
				{
					targetNs = op.getName().getNamespaceURI();
				}
				return new QName(targetNs, webParam.name());
			}
		}
	}

	return new QName(op.getName().getNamespaceURI(), "in" + paramNumber);
}
 
开发者ID:equella,项目名称:Equella,代码行数:25,代码来源:XFireCompatabilityConfiguration.java

示例3: stripReturnedAndThrown

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static List<Class<?>> stripReturnedAndThrown(Method hookMethod) {
    Class<?>[] allTypes = hookMethod.getParameterTypes();
    Annotation[][] annotations = hookMethod.getParameterAnnotations();
    if (allTypes.length != annotations.length) {
        throw new HookException("Method.getParameterAnnotations() returned an unexpected value. This is a bug in promagent.");
    }
    List<Class<?>> result = new ArrayList<>();
    for (int i=0; i<allTypes.length; i++) {
        if (Arrays.stream(annotations[i])
                .map(Annotation::annotationType)
                .noneMatch(a -> Returned.class.equals(a) || Thrown.class.equals(a))) {
            result.add(allTypes[i]);
        }
    }
    return result;
}
 
开发者ID:fstab,项目名称:promagent,代码行数:17,代码来源:Delegator.java

示例4: getName

import java.lang.reflect.Method; //导入方法依赖的package包/类
protected Optional<String> getName(Method method) {
	ObjectMapper objectMapper = context.getObjectMapper();
	SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
	if (serializationConfig != null && serializationConfig.getPropertyNamingStrategy() != null) {
		String name = ClassUtils.getGetterFieldName(method);
		Annotation[] declaredAnnotations = method.getDeclaredAnnotations();
		AnnotationMap annotationMap = buildAnnotationMap(declaredAnnotations);

		int paramsLength = method.getParameterAnnotations().length;
		AnnotationMap[] paramAnnotations = new AnnotationMap[paramsLength];
		for (int i = 0; i < paramsLength; i++) {
			AnnotationMap parameterAnnotationMap = buildAnnotationMap(method.getParameterAnnotations()[i]);
			paramAnnotations[i] = parameterAnnotationMap;
		}

		AnnotatedClass annotatedClass = AnnotatedClassBuilder.build(method.getDeclaringClass(), serializationConfig);
		AnnotatedMethod annotatedField = AnnotatedMethodBuilder.build(annotatedClass, method, annotationMap, paramAnnotations);
		return Optional.of(serializationConfig.getPropertyNamingStrategy().nameForGetterMethod(serializationConfig, annotatedField, name));
	}
	return Optional.empty();
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:22,代码来源:JacksonResourceFieldInformationProvider.java

示例5: parse

import java.lang.reflect.Method; //导入方法依赖的package包/类
private void parse(Action action) {
    Class clazz = action.getClass();
    FastClass fastClass = FastClass.create(clazz);
    for (Method method : clazz.getDeclaredMethods()) {
        InterfaceTarget interfaceTarget = method.getAnnotation(InterfaceTarget.class);
        if (interfaceTarget == null) {
            continue;
        }
        String interfaceKey = interfaceTarget.path() + "_" + interfaceTarget.version();
        InterfaceHandler interfaceHandler = new InterfaceHandler(interfaceKey, action, method, fastClass.getMethod(method));

        // 返回表示按照声明顺序对此 Method对象所表示方法的形参进行注释的那个数组的数组。
        String[] parameterNames = parameterNameDiscoverer.getParameterNames(method);
        Class<?>[] parameterTypes = method.getParameterTypes();
        Annotation[][] parameterAnnotations = method.getParameterAnnotations();
        Preconditions.checkArgument(parameterNames.length == parameterTypes.length);
        Preconditions.checkArgument(parameterNames.length == parameterAnnotations.length);
        int parameterCount = parameterTypes.length;
        for (int i = 0; i < parameterCount; i++) {
            Annotation[] annotations = parameterAnnotations[i];
            Class<?> parameterClazz = parameterTypes[i];
            String parameterName = parameterNames[i];
            resolveParameter(parameterName, parameterClazz, annotations, interfaceHandler);
        }

        LOGGER.info("path {} ,handle {}", interfaceKey, interfaceHandler);
        interfaceHandlerHashMap.put(interfaceKey, interfaceHandler);
    }
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:30,代码来源:SpringContainer.java

示例6: Resource

import java.lang.reflect.Method; //导入方法依赖的package包/类
public Resource(String parentPath, Method method) {
  this.pathPrefix = notNull(parentPath, "parentPath");
  this.httpMethod = notNull(getHttpMethod(method), "httpMethod");
  this.methodPath = method.getAnnotation(Path.class);
  this.returnType = getDataType(method.getGenericReturnType());
  Annotation[][] parameterAnnotations = method.getParameterAnnotations();
  Type[] paramTypes = method.getGenericParameterTypes();
  DataType bodyType = null;
  for (int i = 0; i < paramTypes.length; i++) {
    DataType type = getParamDataType(paramTypes[i]);
    Annotation[] paramAnnotations = parameterAnnotations[i];
    Param p = null;
    String defaultValue = null;
    for (Annotation paramAnnotation : paramAnnotations) {
      if (paramAnnotation instanceof QueryParam) {
        p = new Param(((QueryParam)paramAnnotation).value(), type);
        params.add(p);
      } else if (paramAnnotation instanceof PathParam) {
        p = new Param(((PathParam)paramAnnotation).value(), type);
        pathParams.add(p);
      } else if (paramAnnotation instanceof FormParam) {
        p = new Param(((FormParam)paramAnnotation).value(), type);
        formParams.add(p);
      } else if (paramAnnotation instanceof FormDataParam) {
        // TODO
        p = new Param(((FormDataParam)paramAnnotation).value(), type);
        formParams.add(p);
      } else if (paramAnnotation instanceof HeaderParam) {
        p = new Param(((HeaderParam)paramAnnotation).value(), type);
        headerParams.add(p);
      } else if (paramAnnotation instanceof DefaultValue) {
        defaultValue = ((DefaultValue)paramAnnotation).value();
      } else if (paramAnnotation instanceof Context) {
        // just an injected value. Not part of the api
        p = new Param(null, null);
      } else {
        System.err.println("[WARNING] Unknown param ann: " + paramAnnotation + " on " + i + "th param of " + method);
      }
    }
    if (p == null) {
      if (bodyType != null) {
        System.err.println("[WARNING] More than one body param on " + i + "th param of " + method);
      }
      if (defaultValue != null) {
        System.err.println("[WARNING] default value " + defaultValue + " for body on " + i + "th param of " + method);
      }
      bodyType = getDataType(paramTypes[i]);
    } else {
      p.setDefaultValue(defaultValue);
    }
  }
  this.body = bodyType;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:54,代码来源:Doc.java

示例7: hasJaxRsMethodParameters

import java.lang.reflect.Method; //导入方法依赖的package包/类
private boolean hasJaxRsMethodParameters(Method method) {
	Annotation[][] parameterAnnotationsArray = method.getParameterAnnotations();
	for (int paramIndex = 0; paramIndex < parameterAnnotationsArray.length; paramIndex++) {
		Annotation[] parameterAnnotations = parameterAnnotationsArray[paramIndex];
		for (Annotation parameterAnnotation : parameterAnnotations) {
			if (parameterAnnotation instanceof PathParam || parameterAnnotation instanceof QueryParam) {
				return true;
			}
		}
	}
	return false;
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:13,代码来源:JaxrsModule.java

示例8: verifyMethodParameterAnnotationsValue

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static void verifyMethodParameterAnnotationsValue(
        String expectedValue) throws Exception {
    Class<RedefineMethodWithAnnotationsTarget> c =
            RedefineMethodWithAnnotationsTarget.class;
    Method method = c.getMethod("annotatedMethod", String.class);

    Annotation [][] parametersAnnotations =
            method.getParameterAnnotations();
    if (parametersAnnotations.length != 1) {
        throw new Exception("Incorrect number of parameters to method: " +
                method.getName() + "." +
                " Expected: 1," +
                " got: " + parametersAnnotations.length);
    }

    Annotation[] parameterAnnotations = parametersAnnotations[0];
    if (parameterAnnotations.length != 1) {
        throw new Exception("Incorrect number of annotations." +
                " Expected: 1" +
                ", got " + parameterAnnotations.length);
    }

    Annotation parameterAnnotation = parameterAnnotations[0];
    if (!(parameterAnnotation instanceof ParameterAnnotation)) {
        throw new Exception("Incorrect Annotation class." +
                " Expected: " + ParameterAnnotation.class.getName() +
                ", got: " + parameterAnnotation.getClass().getName());
    }

    ParameterAnnotation pa = (ParameterAnnotation)parameterAnnotation;
    String annotationValue = pa.value();
    if (!expectedValue.equals(annotationValue)) {
        throw new Exception("Incorrect parameter annotation value." +
                " Expected: " + expectedValue +
                ", got: " + annotationValue);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:38,代码来源:RedefineMethodWithAnnotationsApp.java

示例9: parseMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
@NonNull
@Override
public CallMethod parseMethod(@NonNull Config config, @NonNull Method method) {
    final Annotation[] methodAnnotations = method.getAnnotations();
    final Annotation[][] parameterAnnotationsArray = method.getParameterAnnotations();

    final CallMethod callMethod = new CallMethod();
    parseMethodAnnotations(callMethod, methodAnnotations, parameterAnnotationsArray);
    parseParameterAnnotation(callMethod, parameterAnnotationsArray);

    return callMethod;
}
 
开发者ID:nekocode,项目名称:Meepo,代码行数:13,代码来源:DefaultParser.java

示例10: test1

import java.lang.reflect.Method; //导入方法依赖的package包/类
void test1() throws Throwable {
    for (Method m : thisClass.getMethods()) {
        if (m.getName().equals("nop")) {
            Annotation[][] ann = m.getParameterAnnotations();
            equal(ann.length, 2);
            Annotation foo = ann[0][0];
            Annotation bar = ann[1][0];
            equal(foo.toString(), "@Named(value=foo)");
            equal(bar.toString(), "@Named(value=bar)");
            check(foo.equals(foo));
            check(! foo.equals(bar));
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:ParameterAnnotations.java

示例11: test1

import java.lang.reflect.Method; //导入方法依赖的package包/类
void test1() throws Throwable {
    for (Method m : thisClass.getMethods()) {
        if (m.getName().equals("nop")) {
            Annotation[][] ann = m.getParameterAnnotations();
            equal(ann.length, 2);
            Annotation foo = ann[0][0];
            Annotation bar = ann[1][0];
            equal(foo.toString(), "@Named(value=\"foo\")");
            equal(bar.toString(), "@Named(value=\"bar\")");
            check(foo.equals(foo));
            check(! foo.equals(bar));
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ParameterAnnotations.java

示例12: FactoryProvider2

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * @param factoryType  a Java interface that defines one or more create methods.
 * @param producedType a concrete type that is assignable to the return types of all factory
 *                     methods.
 */
FactoryProvider2(TypeLiteral<F> factoryType, Key<?> producedType) {
    this.producedType = producedType;

    Errors errors = new Errors();

    @SuppressWarnings("unchecked") // we imprecisely treat the class literal of T as a Class<T>
            Class<F> factoryRawType = (Class) factoryType.getRawType();

    try {
        ImmutableMap.Builder<Method, Key<?>> returnTypesBuilder = ImmutableMap.builder();
        ImmutableMap.Builder<Method, List<Key<?>>> paramTypesBuilder
                = ImmutableMap.builder();
        // TODO: also grab methods from superinterfaces
        for (Method method : factoryRawType.getMethods()) {
            Key<?> returnType = getKey(
                    factoryType.getReturnType(method), method, method.getAnnotations(), errors);
            returnTypesBuilder.put(method, returnType);
            List<TypeLiteral<?>> params = factoryType.getParameterTypes(method);
            Annotation[][] paramAnnotations = method.getParameterAnnotations();
            int p = 0;
            List<Key<?>> keys = new ArrayList<>();
            for (TypeLiteral<?> param : params) {
                Key<?> paramKey = getKey(param, method, paramAnnotations[p++], errors);
                keys.add(assistKey(method, paramKey, errors));
            }
            paramTypesBuilder.put(method, Collections.unmodifiableList(keys));
        }
        returnTypesByMethod = returnTypesBuilder.build();
        paramTypes = paramTypesBuilder.build();
    } catch (ErrorsException e) {
        throw new ConfigurationException(e.getErrors().getMessages());
    }

    factory = factoryRawType.cast(Proxy.newProxyInstance(factoryRawType.getClassLoader(),
            new Class[]{factoryRawType}, this));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:42,代码来源:FactoryProvider2.java

示例13: getMethodParameterAnnotation

import java.lang.reflect.Method; //导入方法依赖的package包/类
<A extends Annotation> A getMethodParameterAnnotation(Method method, Class<A> clazz) {
    Annotation[][] annotations = method.getParameterAnnotations();
    for (Annotation[] annotationA : annotations) {
        for (Annotation annotation : annotationA) {
            if (clazz.isAssignableFrom(annotation.getClass())) {
                return (A) annotation;
            }
        }
    }
    return null;
}
 
开发者ID:AlphaHelixDev,项目名称:AlphaLibary,代码行数:12,代码来源:AnnotatedCommand.java

示例14: hasThriftFieldAnnotation

import java.lang.reflect.Method; //导入方法依赖的package包/类
protected final boolean hasThriftFieldAnnotation(Method method)
{
    for (Annotation[] parameterAnnotations : method.getParameterAnnotations()) {
        for (Annotation parameterAnnotation : parameterAnnotations) {
            if (parameterAnnotation instanceof ThriftField) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:airlift,项目名称:drift,代码行数:12,代码来源:AbstractThriftMetadataBuilder.java

示例15: lookupParameterNames

import java.lang.reflect.Method; //导入方法依赖的package包/类
public String[] lookupParameterNames(AccessibleObject methodOrCtor, boolean throwExceptionIfMissing) {
	// Oh for some commonality between Constructor and Method !!
	Class<?>[] types = null;
	Class<?> declaringClass = null;
	String name = null;
	Annotation[][] anns = null;
	if (methodOrCtor instanceof Method) {
		Method method = (Method) methodOrCtor;
		types = method.getParameterTypes();
		name = method.getName();
		declaringClass = method.getDeclaringClass();
		anns = method.getParameterAnnotations();
	} else {
		Constructor<?> constructor = (Constructor<?>) methodOrCtor;
		types = constructor.getParameterTypes();
		declaringClass = constructor.getDeclaringClass();
		name = "<init>";
		anns = constructor.getParameterAnnotations();
	}

	if (types.length == 0) {
		return EMPTY_NAMES;
	}

	final String[] names = new String[types.length];
	boolean allDone = true;
	for (int i = 0; i < names.length; i++) {
		for (int j = 0; j < anns[i].length; j++) {
			Annotation ann = anns[i][j];
			if (isNamed(ann)) {
				names[i] = getNamedValue(ann);
				break;
			}
		}
		if (names[i] == null) {
			allDone = false;
		}

	}

	// fill in blanks from fallback if possible.
	if (!allDone) {
		allDone = true;
		String[] altNames = fallback.lookupParameterNames(methodOrCtor, false);
		if (altNames.length > 0) {
			for (int i = 0; i < names.length; i++) {
				if (names[i] == null) {
					if (altNames[i] != null) {
						names[i] = altNames[i];
					} else {
						allDone = false;
					}
				}
			}
		} else {
			allDone = false;
		}
	}

	// error if applicable
	if (!allDone) {
		if (throwExceptionIfMissing) {
			throw new ParameterNamesNotFoundException("One or more @Named annotations missing for class '"
					+ declaringClass.getName() + "', methodOrCtor " + name + " and parameter types "
					+ DefaultParanamer.getParameterTypeNamesCSV(types));
		} else {
			return Paranamer.EMPTY_NAMES;
		}
	}
	return names;
}
 
开发者ID:Yoio,项目名称:X4J,代码行数:72,代码来源:AnnotationParanamer.java


注:本文中的java.lang.reflect.Method.getParameterAnnotations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。