org.jboss.jandex.MethodParameterInfo Java Examples
The following examples show how to use
org.jboss.jandex.MethodParameterInfo.
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: Annotations.java From smallrye-graphql with Apache License 2.0 | 6 votes |
/** * Used when we are creating operation and arguments for these operations * * @param methodInfo the java method * @param pos the argument position * @return annotation for this argument */ public static Annotations getAnnotationsForArgument(MethodInfo methodInfo, short pos) { if (pos >= methodInfo.parameters().size()) { throw new IndexOutOfBoundsException( "Parameter at position " + pos + " not found on method " + methodInfo.name()); } final org.jboss.jandex.Type parameterType = methodInfo.parameters().get(pos); Map<DotName, AnnotationInstance> annotationMap = new HashMap<>(); annotationMap.putAll(getAnnotations(parameterType)); for (AnnotationInstance anno : methodInfo.annotations()) { if (anno.target().kind().equals(AnnotationTarget.Kind.METHOD_PARAMETER)) { MethodParameterInfo methodParameter = anno.target().asMethodParameter(); short position = methodParameter.position(); if (position == pos) { annotationMap.put(anno.name(), anno); } } } return new Annotations(annotationMap); }
Example #2
Source File: SourceOperationHelper.java From smallrye-graphql with Apache License 2.0 | 6 votes |
public static Map<DotName, List<MethodParameterInfo>> getAllSourceAnnotations() { Map<DotName, List<MethodParameterInfo>> sourceFields = new HashMap<>(); Collection<AnnotationInstance> sourceAnnotations = ScanningContext.getIndex().getAnnotations(Annotations.SOURCE); for (AnnotationInstance ai : sourceAnnotations) { AnnotationTarget target = ai.target(); if (target.kind().equals(AnnotationTarget.Kind.METHOD_PARAMETER)) { MethodParameterInfo methodParameter = target.asMethodParameter(); short position = methodParameter.position(); DotName name = methodParameter.method().parameters().get(position).name(); sourceFields.computeIfAbsent(name, k -> new ArrayList<>()).add(methodParameter); } else { LOG.warn("Ignoring " + ai.target() + " on kind " + ai.target().kind() + ". Only expecting @" + Annotations.SOURCE.local() + " on Method parameters"); } } return sourceFields; }
Example #3
Source File: TypeUtil.java From smallrye-open-api with Apache License 2.0 | 6 votes |
public static boolean hasAnnotation(AnnotationTarget target, DotName annotationName) { if (target == null) { return false; } switch (target.kind()) { case CLASS: return target.asClass().classAnnotation(annotationName) != null; case FIELD: return target.asField().hasAnnotation(annotationName); case METHOD: return target.asMethod().hasAnnotation(annotationName); case METHOD_PARAMETER: MethodParameterInfo parameter = target.asMethodParameter(); return parameter.method() .annotations() .stream() .filter(a -> a.target().kind() == Kind.METHOD_PARAMETER) .filter(a -> a.target().asMethodParameter().position() == parameter.position()) .anyMatch(a -> a.name().equals(annotationName)); case TYPE: break; } return false; }
Example #4
Source File: TypeUtil.java From smallrye-open-api with Apache License 2.0 | 6 votes |
public static Collection<AnnotationInstance> getAnnotations(AnnotationTarget type) { switch (type.kind()) { case CLASS: return type.asClass().classAnnotations(); case FIELD: return type.asField().annotations(); case METHOD: return type.asMethod().annotations(); case METHOD_PARAMETER: MethodParameterInfo parameter = type.asMethodParameter(); return parameter .method() .annotations() .stream() .filter(a -> a.target().kind() == Kind.METHOD_PARAMETER) .filter(a -> a.target().asMethodParameter().position() == parameter.position()) .collect(Collectors.toList()); case TYPE: break; } return Collections.emptyList(); }
Example #5
Source File: TypeUtil.java From smallrye-open-api with Apache License 2.0 | 6 votes |
public static ClassInfo getDeclaringClass(AnnotationTarget type) { switch (type.kind()) { case FIELD: return type.asField().declaringClass(); case METHOD: return type.asMethod().declaringClass(); case METHOD_PARAMETER: MethodParameterInfo parameter = type.asMethodParameter(); return parameter.method().declaringClass(); case CLASS: case TYPE: break; } return null; }
Example #6
Source File: ObserverInfo.java From quarkus with Apache License 2.0 | 6 votes |
static ObserverInfo create(BeanInfo declaringBean, MethodInfo observerMethod, Injection injection, boolean isAsync, List<ObserverTransformer> transformers, BuildContext buildContext, boolean jtaCapabilities) { MethodParameterInfo eventParameter = initEventParam(observerMethod, declaringBean.getDeployment()); AnnotationInstance priorityAnnotation = observerMethod.annotation(DotNames.PRIORITY); Integer priority; if (priorityAnnotation != null && priorityAnnotation.target().equals(eventParameter)) { priority = priorityAnnotation.value().asInt(); } else { priority = ObserverMethod.DEFAULT_PRIORITY; } return create(declaringBean.getDeployment(), declaringBean.getTarget().get().asClass().name(), declaringBean, observerMethod, injection, eventParameter, observerMethod.parameters().get(eventParameter.position()), initQualifiers(declaringBean.getDeployment(), observerMethod, eventParameter), initReception(isAsync, declaringBean.getDeployment(), observerMethod), initTransactionPhase(isAsync, declaringBean.getDeployment(), observerMethod), isAsync, priority, transformers, buildContext, jtaCapabilities, null); }
Example #7
Source File: ObserverInfo.java From quarkus with Apache License 2.0 | 6 votes |
ObserverInfo(BeanDeployment beanDeployment, DotName beanClass, BeanInfo declaringBean, MethodInfo observerMethod, Injection injection, MethodParameterInfo eventParameter, boolean isAsync, int priority, Reception reception, TransactionPhase transactionPhase, Type observedType, Set<AnnotationInstance> qualifiers, Consumer<MethodCreator> notify) { this.beanDeployment = beanDeployment; this.beanClass = beanClass; this.declaringBean = declaringBean; this.observerMethod = observerMethod; this.injection = injection; this.eventParameter = eventParameter; this.eventMetadataParameterPosition = initEventMetadataParam(observerMethod); this.isAsync = isAsync; this.priority = priority; this.reception = reception; this.transactionPhase = transactionPhase; this.observedType = observedType; this.qualifiers = qualifiers; this.notify = notify; }
Example #8
Source File: TypeCreator.java From smallrye-graphql with Apache License 2.0 | 5 votes |
private void addOperations(Type type, ClassInfo classInfo) { Map<DotName, List<MethodParameterInfo>> sourceFields = SourceOperationHelper.getAllSourceAnnotations(); // See if there is source operations for this class if (sourceFields.containsKey(classInfo.name())) { List<MethodParameterInfo> methodParameterInfos = sourceFields.get(classInfo.name()); for (MethodParameterInfo methodParameterInfo : methodParameterInfos) { MethodInfo methodInfo = methodParameterInfo.method(); Operation operation = operationCreator.createOperation(methodInfo, OperationType.Source, type); type.addOperation(operation); } } }
Example #9
Source File: ObserverInfo.java From quarkus with Apache License 2.0 | 5 votes |
static Set<AnnotationInstance> initQualifiers(BeanDeployment beanDeployment, MethodInfo observerMethod, MethodParameterInfo eventParameter) { Set<AnnotationInstance> qualifiers = new HashSet<>(); for (AnnotationInstance annotation : beanDeployment.getAnnotations(observerMethod)) { if (annotation.target().equals(eventParameter)) { beanDeployment.extractQualifiers(annotation).forEach(qualifiers::add); } } return qualifiers; }
Example #10
Source File: ObserverInfo.java From quarkus with Apache License 2.0 | 5 votes |
static MethodParameterInfo initEventParam(MethodInfo observerMethod, BeanDeployment beanDeployment) { List<MethodParameterInfo> eventParams = new ArrayList<>(); for (AnnotationInstance annotation : beanDeployment.getAnnotations(observerMethod)) { if (Kind.METHOD_PARAMETER == annotation.target().kind() && (annotation.name().equals(DotNames.OBSERVES) || annotation.name().equals(DotNames.OBSERVES_ASYNC))) { eventParams.add(annotation.target().asMethodParameter()); } } if (eventParams.isEmpty()) { throw new DefinitionException("No event parameters found for " + observerMethod); } else if (eventParams.size() > 1) { throw new DefinitionException("Multiple event parameters found for " + observerMethod); } return eventParams.get(0); }
Example #11
Source File: DisposerInfo.java From quarkus with Apache License 2.0 | 5 votes |
MethodParameterInfo initDisposedParam(MethodInfo disposerMethod) { List<MethodParameterInfo> disposedParams = new ArrayList<>(); for (AnnotationInstance annotation : disposerMethod.annotations()) { if (Kind.METHOD_PARAMETER.equals(annotation.target().kind()) && annotation.name().equals(DotNames.DISPOSES)) { disposedParams.add(annotation.target().asMethodParameter()); } } if (disposedParams.isEmpty()) { throw new DefinitionException("No disposed parameters found for " + disposerMethod); } else if (disposedParams.size() > 1) { throw new DefinitionException("Multiple disposed parameters found for " + disposerMethod); } return disposedParams.get(0); }
Example #12
Source File: AddObservesTest.java From quarkus with Apache License 2.0 | 5 votes |
@Override public void transform(TransformationContext transformationContext) { MethodInfo method = transformationContext.getTarget().asMethod(); if (method.name().equals("observe")) { transformationContext.transform() .add(AnnotationInstance.create(DotName.createSimple(Observes.class.getName()), MethodParameterInfo.create(method, (short) 0), new AnnotationValue[] {})) .done(); } }
Example #13
Source File: ResteasyServerCommonProcessor.java From quarkus with Apache License 2.0 | 5 votes |
private static void checkParameterNames(IndexView index, List<AdditionalJaxRsResourceMethodParamAnnotations> additionalJaxRsResourceMethodParamAnnotations) { final List<DotName> methodParameterAnnotations = new ArrayList<>(RESTEASY_PARAM_ANNOTATIONS.length); methodParameterAnnotations.addAll(Arrays.asList(RESTEASY_PARAM_ANNOTATIONS)); for (AdditionalJaxRsResourceMethodParamAnnotations annotations : additionalJaxRsResourceMethodParamAnnotations) { methodParameterAnnotations.addAll(annotations.getAnnotationClasses()); } OUTER: for (DotName annotationType : methodParameterAnnotations) { Collection<AnnotationInstance> instances = index.getAnnotations(annotationType); for (AnnotationInstance instance : instances) { // we only care about method parameters, because properties or fields always work if (instance.target().kind() != Kind.METHOD_PARAMETER) { continue; } MethodParameterInfo param = instance.target().asMethodParameter(); if (param.name() == null) { log.warnv( "Detected RESTEasy annotation {0} on method parameter {1}.{2} with no name. Either specify its name," + " or tell your compiler to enable debug info (-g) or parameter names (-parameters). This message is only" + " logged for the first such parameter.", instance.name(), param.method().declaringClass(), param.method().name()); break OUTER; } } } }
Example #14
Source File: DisposerInfo.java From quarkus with Apache License 2.0 | 4 votes |
public MethodParameterInfo getDisposedParameter() { return disposedParameter; }
Example #15
Source File: JandexUtil.java From smallrye-open-api with Apache License 2.0 | 2 votes |
/** * Returns the class type of the method parameter. * * @param parameter the {@link MethodParameterInfo parameter} * @return Type */ public static Type getMethodParameterType(MethodParameterInfo parameter) { return parameter.method().parameters().get(parameter.position()); }
Example #16
Source File: ObserverInfo.java From quarkus with Apache License 2.0 | 2 votes |
/** * * @return the event parameter or null in case of synthetic observer */ public MethodParameterInfo getEventParameter() { return eventParameter; }