org.jboss.errai.codegen.meta.MetaClass.getMethodsAnnotatedWith()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(111)

本文整理了Java中org.jboss.errai.codegen.meta.MetaClass.getMethodsAnnotatedWith()方法的一些代码示例,展示了MetaClass.getMethodsAnnotatedWith()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MetaClass.getMethodsAnnotatedWith()方法的具体详情如下:
包路径:org.jboss.errai.codegen.meta.MetaClass
类名称:MetaClass
方法名:getMethodsAnnotatedWith

MetaClass.getMethodsAnnotatedWith介绍

[英]Returns all declared and inherited methods on this class that have the given annotation targeting them.
[中]返回该类上所有已声明和继承的方法,这些方法都有针对它们的给定注释。

代码示例

代码示例来源:origin: errai/errai

@SuppressWarnings({ "unchecked", "rawtypes" })
private List<HasAnnotations> getAnnotatedWithForElementType(final MetaClass type, final ElementType elemType, final Class<? extends Annotation> annoType) {
 final List annotatedItems;
 switch (elemType) {
 case FIELD:
  annotatedItems = type.getFieldsAnnotatedWith(annoType);
  break;
 case METHOD:
  annotatedItems = type.getMethodsAnnotatedWith(annoType);
  break;
 case PARAMETER:
  annotatedItems = type.getParametersAnnotatedWith(annoType);
  break;
 case TYPE:
  annotatedItems = (type.isAnnotationPresent(annoType)) ? Collections.singletonList(type) : Collections.emptyList();
  break;
 default:
  throw new RuntimeException("Not yet implemented.");
 }
 return annotatedItems;
}

代码示例来源:origin: org.jboss.errai/errai-data-binding

private Collection<Statement> registerDeclarativeHandlers(final MetaClass bindable) {
 final List<MetaMethod> handlerMethods = bindable.getMethodsAnnotatedWith(org.jboss.errai.ui.shared.api.annotations.PropertyChangeHandler.class);
 if ( handlerMethods.isEmpty() ) return Collections.emptyList();
 final List<Statement> retVal = new ArrayList<>();
 for (final MetaMethod method : handlerMethods) {
  if (method.getParameters().length == 1
      && method.getParameters()[0].getType().getFullyQualifiedName().equals(PropertyChangeEvent.class.getName())) {
   final String property = method.getAnnotation(org.jboss.errai.ui.shared.api.annotations.PropertyChangeHandler.class).value();
   if (!property.isEmpty()) validateProperty(bindable, property);
   final Object handler = createHandlerForMethod(method);
   final ContextualStatementBuilder subStmt = (property.isEmpty() ?
       loadVariable("agent").invoke("addPropertyChangeHandler", handler):
       loadVariable("agent").invoke("addPropertyChangeHandler", property, handler));
   retVal.add(subStmt);
  }
  else {
   throw new RuntimeException(
       String.format("The @ChangeHandler method [%s] must have exactly one argument of type %s.",
           method.getName(), PropertyChangeEvent.class.getSimpleName()));
  }
 }
 return retVal;
}

代码示例来源:origin: errai/errai

private Collection<Statement> registerDeclarativeHandlers(final MetaClass bindable) {
 final List<MetaMethod> handlerMethods = bindable.getMethodsAnnotatedWith(org.jboss.errai.ui.shared.api.annotations.PropertyChangeHandler.class);
 if ( handlerMethods.isEmpty() ) return Collections.emptyList();
 final List<Statement> retVal = new ArrayList<>();
 for (final MetaMethod method : handlerMethods) {
  if (method.getParameters().length == 1
      && method.getParameters()[0].getType().getFullyQualifiedName().equals(PropertyChangeEvent.class.getName())) {
   final String property = method.getAnnotation(org.jboss.errai.ui.shared.api.annotations.PropertyChangeHandler.class).value();
   if (!property.isEmpty()) validateProperty(bindable, property);
   final Object handler = createHandlerForMethod(method);
   final ContextualStatementBuilder subStmt = (property.isEmpty() ?
       loadVariable("agent").invoke("addPropertyChangeHandler", handler):
       loadVariable("agent").invoke("addPropertyChangeHandler", property, handler));
   retVal.add(subStmt);
  }
  else {
   throw new RuntimeException(
       String.format("The @ChangeHandler method [%s] must have exactly one argument of type %s.",
           method.getName(), PropertyChangeEvent.class.getSimpleName()));
  }
 }
 return retVal;
}

代码示例来源:origin: org.jboss.errai/errai-data-binding

annotated.addAll(enclosingType.getMethodsAnnotatedWith(annoType));

代码示例来源:origin: errai/errai

annotated.addAll(enclosingType.getMethodsAnnotatedWith(annoType));

代码示例来源:origin: errai/errai

final List<MetaMethod> producerMethods = type.getMethodsAnnotatedWith(producerAnnoType);
 if (!producerMethods.isEmpty() && producerMethods.stream().anyMatch(method -> !method.isStatic())) {
  return false;
if (!type.getMethodsAnnotatedWith(PostConstruct.class).isEmpty()) {
 return false;

代码示例来源:origin: org.jboss.errai/errai-ui

private void generateEventHandlerMethodClasses(final Decorable decorable, final FactoryController controller,
    final List<Statement> initStmts, final String dataFieldElementsVarName, final Statement fieldsMap) {
 final Statement instance = Refs.get("instance");
 final Map<String, MetaClass> dataFieldTypes = DataFieldCodeDecorator.aggregateDataFieldTypeMap(decorable, decorable.getDecorableDeclaringType());
 dataFieldTypes.put("this", decorable.getDecorableDeclaringType());
 final MetaClass declaringClass = decorable.getDecorableDeclaringType();
 /* Ensure that no @DataFields are handled more than once when used in combination with @SyncNative */
 final Set<String> processedNativeHandlers = new HashSet<>();
 final Set<String> processedEventHandlers = new HashSet<>();
 for (final MetaMethod method : declaringClass.getMethodsAnnotatedWith(EventHandler.class)) {
  final String[] targetDataFieldNames = method.getAnnotation(EventHandler.class).value();
  validateNonEmptyEventHandlerTargets(declaringClass, method, targetDataFieldNames);
  final MetaClass eventType = assertEventType(declaringClass, method);
  if (eventType.isAssignableTo(Event.class)) {
   processGwtDomEvent(controller, initStmts, dataFieldElementsVarName, fieldsMap, instance, dataFieldTypes, declaringClass,
       processedNativeHandlers, processedEventHandlers, method, targetDataFieldNames, eventType);
  }
  else if (eventType.isAssignableTo(com.google.web.bindery.event.shared.Event.class)) {
   processGwtWidgetEvent(controller, initStmts, fieldsMap, dataFieldTypes, declaringClass, processedNativeHandlers,
       processedEventHandlers, method, targetDataFieldNames, eventType);
  }
  else {
   processJsInteropDomEvent(initStmts, dataFieldElementsVarName, fieldsMap, instance, dataFieldTypes, declaringClass, method,
       targetDataFieldNames, eventType, controller);
  }
 }
}

代码示例来源:origin: errai/errai

private void generateEventHandlerMethodClasses(final Decorable decorable, final FactoryController controller,
    final List<Statement> initStmts, final String dataFieldElementsVarName, final Statement fieldsMap) {
 final Statement instance = Refs.get("instance");
 final Map<String, MetaClass> dataFieldTypes = DataFieldCodeDecorator.aggregateDataFieldTypeMap(decorable, decorable.getDecorableDeclaringType());
 dataFieldTypes.put("this", decorable.getDecorableDeclaringType());
 final MetaClass declaringClass = decorable.getDecorableDeclaringType();
 /* Ensure that no @DataFields are handled more than once when used in combination with @SyncNative */
 final Set<String> processedNativeHandlers = new HashSet<>();
 final Set<String> processedEventHandlers = new HashSet<>();
 for (final MetaMethod method : declaringClass.getMethodsAnnotatedWith(EventHandler.class)) {
  final String[] targetDataFieldNames = method.getAnnotation(EventHandler.class).value();
  validateNonEmptyEventHandlerTargets(declaringClass, method, targetDataFieldNames);
  final MetaClass eventType = assertEventType(declaringClass, method);
  if (eventType.isAssignableTo(Event.class)) {
   processGwtDomEvent(controller, initStmts, dataFieldElementsVarName, fieldsMap, instance, dataFieldTypes, declaringClass,
       processedNativeHandlers, processedEventHandlers, method, targetDataFieldNames, eventType);
  }
  else if (eventType.isAssignableTo(com.google.web.bindery.event.shared.Event.class)) {
   processGwtWidgetEvent(controller, initStmts, fieldsMap, dataFieldTypes, declaringClass, processedNativeHandlers,
       processedEventHandlers, method, targetDataFieldNames, eventType);
  }
  else {
   processJsInteropDomEvent(initStmts, dataFieldElementsVarName, fieldsMap, instance, dataFieldTypes, declaringClass, method,
       targetDataFieldNames, eventType, controller);
  }
 }
}

代码示例来源:origin: errai/errai

private void addMethodInjectionPoints(final Injectable typeInjectable, final DependencyGraphBuilder builder, final List<String> problems) {
 final MetaClass type = typeInjectable.getInjectedType();
 final Collection<Class<? extends Annotation>> injectAnnotations = injectionContext.getAnnotationsForElementType(WiringElementType.InjectionPoint);
 for (final Class<? extends Annotation> inject : injectAnnotations) {
  for (final MetaMethod setter : type.getMethodsAnnotatedWith(inject)) {
   if (setter.getParameters().length != 1) {
    problems.add("The method injection point " + setter.getName() + " in "
        + setter.getDeclaringClass().getFullyQualifiedName() + " should have exactly one parameter, not "
        + setter.getParameters().length + ".");
   } else {
    final MetaParameter metaParam = setter.getParameters()[0];
    builder.addSetterMethodDependency(typeInjectable, metaParam.getType(), qualFactory.forSink(setter.getParameters()[0]), setter);
   }
  }
 }
}

代码示例来源:origin: errai/errai

BlockBuilder<?> methodToAppendTo, MetaClass pageClass, Class<? extends Annotation> annotation,
 Parameter... optionalParams) {
List<MetaMethod> annotatedMethods = pageClass.getMethodsAnnotatedWith(annotation);
if (annotatedMethods.size() > 1) {
 throw new UnsupportedOperationException(

代码示例来源:origin: org.jboss.errai/errai-navigation

BlockBuilder<?> methodToAppendTo, MetaClass pageClass, Class<? extends Annotation> annotation,
 Parameter... optionalParams) {
List<MetaMethod> annotatedMethods = pageClass.getMethodsAnnotatedWith(annotation);
if (annotatedMethods.size() > 1) {
 throw new UnsupportedOperationException(

代码示例来源:origin: errai/errai

for (MetaMethod callback : listenerMetaClass.getMethodsAnnotatedWith(eventType)) {
  if (callback.getParameters().length != 1) {
   throw new GenerationException("JPA lifecycle listener method " + listenerMetaClass.getName() +
for (MetaMethod callback : entityType.getMethodsAnnotatedWith(eventType)) {
 if (!callback.isPublic()) {
  PrivateAccessUtil.addPrivateAccessStubs("jsni", classBuilder, callback, new Modifier[]{});

相关文章