Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jboss.errai.enterprise.rebind;
  
  import static org.jboss.errai.codegen.meta.MetaClassFactory.parameterizedAs;
  import static org.jboss.errai.codegen.meta.MetaClassFactory.typeParametersOf;
  
 
 import java.util.List;
 import java.util.Set;

Author(s):
Mike Brock
 
   private static final Inject INJECT_INSTANCE = new Inject() {
     @Override
     public Class<? extends AnnotationannotationType() {
       return Inject.class;
     }
   };
   private static final ObserverModel OBSERVER_MODEL_INSTANCE = new ObserverModel() {
     @Override
     public Class<? extends AnnotationannotationType() {
       return ObserverModel.class;
     }
   };
 
   @Override
   public void configure(GeneratorMappingContext generatorMappingContext) {
     if (!MarshallingGenUtil.isUseStaticMarshallers()) return;
 
     final ClassStructureBuilder<?> builder = generatorMappingContext.getClassStructureBuilder();
 
     for (final ObserverPoint observerPoint : scanForObserverPointsInClassPath()) {
       if (!EnvUtil.isPortableType(observerPoint.getObservedType())
               || EnvUtil.isLocalEventType(observerPoint.getObservedType()))
         continue;
 
       final MetaClass eventObserverType
               = parameterizedAs(Event.classtypeParametersOf(observerPoint.getObservedType()));
 
       builder.privateField(InjectUtil.getUniqueVarName(), eventObserverType)
               .annotatedWith()
               .annotatedWith()
               .annotatedWith(observerPoint.getQualifiers()).finish();
     }
   }
 
     final Set<Class<?>> annotations = new HashSet<Class<?>>() {
       {
         add(Dependent.class);
         add(ApplicationScoped.class);
         add(Singleton.class);
         add(EntryPoint.class);
       }
     };
 
     //noinspection unchecked
     annotations.addAll(
             ScannerSingleton.getOrCreateInstance().getTypesAnnotatedWith(Scope.class));
 
     final Set<StringvisitedTypes = new HashSet<String>();
     final Set<ObserverPointobserverPoints = new HashSet<ObserverPoint>();
 
     for (final Class<?> annotationType : annotations) {
       for (final Class<?> beanType : ScannerSingleton.getOrCreateInstance()
               .getTypesAnnotatedWith(annotationType.asSubclass(Annotation.class))) {
         scanForObserverPoints(visitedTypesobserverPointsbeanType);
       }
     }
 
     return observerPoints;
   }
 
   private static void scanForObserverPoints(final Set<StringvisitedTypes,
                                            final Set<ObserverPointobserverPoints,
                                            final Class<?> beanType) {
    try {
      visitedTypes.add(beanType.getName());
      for (final Field field : beanType.getDeclaredFields()) {
        final Class<?> fieldType = field.getType();
        if (field.isAnnotationPresent(Inject.class)) {
          visit(visitedTypesobserverPointsfieldType);
          for (final Class<?> subType : ScannerSingleton.getOrCreateInstance().getSubTypesOf(fieldType)) {
            visit(visitedTypesobserverPointssubType);
          }
        }
      }
      for (final Method method : beanType.getDeclaredMethods()) {
        final int parameterLength = method.getParameterTypes().length;
        for (int i = 0; i < parameterLengthi++) {
          final Annotation[] parmAnnotations = method.getParameterAnnotations()[i];
          for (Annotation a : parmAnnotations) {
            if (Observes.class.equals(a.annotationType())) {
              final List<AnnotationqualifiersFromAnnotations = InjectUtil.getQualifiersFromAnnotations(parmAnnotations);
              final Annotation[] qualifiers =
                      qualifiersFromAnnotations.toArray(new Annotation[qualifiersFromAnnotations.size()]);
              observerPoints.add(new ObserverPoint(method.getParameterTypes()[i], qualifiers));
            }
          }
        }
      }
      if (!Object.class.equals(beanType)) {
        visit(visitedTypesobserverPointsbeanType.getSuperclass());
      }
    }
    catch (NoClassDefFoundError e) {
      // ignore this -- may be GWT client code.
    }
  }
  private static void visit(final Set<StringvisitedTypes,
                            final Set<ObserverPointobserverPoints,
                            final Class<?> beanType) {
    if (beanType == nullreturn;
    if (!visitedTypes.contains(beanType.getName())) {
      scanForObserverPoints(visitedTypesobserverPointsbeanType);
    }
  }
  public static class ObserverPoint {
    private final Class<?> observedType;
    private final Set<Annotationannotations;
    public ObserverPoint(Class<?> observedTypeAnnotation[] annotations) {
      this. = observedType;
      this. = new HashSet<Annotation>(Arrays.asList(annotations));
    }
    public Class<?> getObservedType() {
      return ;
    }
    public Annotation[] getQualifiers() {
      return .toArray(new Annotation[.size()]);
    }
    @Override
    public String toString() {
      return "ObserverPoint{" +
              "observedType=" +  +
              ", annotations=" +  +
              '}';
    }
    @Override
    public boolean equals(Object o) {
      if (this == oreturn true;
      if (!(o instanceof ObserverPoint)) return false;
      ObserverPoint that = (ObserverPointo;
      if ( != null ? !.equals(that.annotations) : that.annotations != nullreturn false;
      if ( != null ? !.equals(that.observedType) : that.observedType != nullreturn false;
      return true;
    }
    @Override
    public int hashCode() {
      int result =  != null ? .hashCode() : 0;
      result = 31 * result + ( != null ? .hashCode() : 0);
      return result;
    }
  }
New to GrepCode? Check out our FAQ X