Package org.jboss.errai.codegen.meta

Examples of org.jboss.errai.codegen.meta.MetaClass


            public void getDependencies(final DependencyControl control,
                                        final InjectableInstance instance,
                                        final Annotation annotation,
                                        final IOCProcessingContext context) {

              final MetaClass providerClassType = instance.getType();
              final MetaClass MC_Provider = MetaClassFactory.get(Provider.class);
              final MetaClass MC_ContextualTypeProvider = MetaClassFactory.get(ContextualTypeProvider.class);

              MetaClass providerInterface = null;
              final MetaClass providedType;

              if (MC_Provider.isAssignableFrom(providerClassType)) {
                for (final MetaClass interfaceType : providerClassType.getInterfaces()) {
                  if (MC_Provider.equals(interfaceType.getErased())) {
                    providerInterface = interfaceType;
                  }
                }

                if (providerInterface == null) {
                  throw new RuntimeException("top level provider " + providerClassType.getFullyQualifiedName()
                      + " must directly implement " + Provider.class.getName());
                }

                if (providerInterface.getParameterizedType() == null) {
                  throw new RuntimeException("top level provider " + providerClassType.getFullyQualifiedName()
                      + " must use a parameterized " + Provider.class.getName() + " interface type.");
                }

                final MetaType parmType = providerInterface.getParameterizedType().getTypeParameters()[0];
                if (parmType instanceof MetaParameterizedType) {
                  providedType = (MetaClass) ((MetaParameterizedType) parmType).getRawType();
                }
                else {
                  providedType = (MetaClass) parmType;
                }

                injectionContext.registerInjector(
                    new ProviderInjector(providedType, providerClassType, injectionContext)
                );
              }
              else if (MC_ContextualTypeProvider.isAssignableFrom(providerClassType)) {
                for (final MetaClass interfaceType : providerClassType.getInterfaces()) {
                  if (MC_ContextualTypeProvider.equals(interfaceType.getErased())) {
                    providerInterface = interfaceType;
                  }
                }

                if (providerInterface == null) {
                  throw new RuntimeException("top level provider " + providerClassType.getFullyQualifiedName()
                      + " must directly implement " + ContextualTypeProvider.class.getName());
                }

                if (providerInterface.getParameterizedType() == null) {
                  throw new RuntimeException("top level provider " + providerClassType.getFullyQualifiedName()
                      + " must use a parameterized " + ContextualTypeProvider.class.getName() + " interface type.");
                }

                final MetaType parmType = providerInterface.getParameterizedType().getTypeParameters()[0];
                if (parmType instanceof MetaParameterizedType) {
                  providedType = (MetaClass) ((MetaParameterizedType) parmType).getRawType();
                }
                else {
                  providedType = (MetaClass) parmType;
                }

                injectionContext.registerInjector(
                    new ContextualProviderInjector(providedType, providerClassType, injectionContext)
                );
              }
              else {
                throw new RuntimeException("top level provider " + providerClassType.getFullyQualifiedName()
                    + " does not implement: " + Provider.class.getName() + " or " + ContextualTypeProvider.class);
              }

              injectionContext.getGraphBuilder().addDependency(providedType, Dependency.on(providerClassType));

              control.masqueradeAs(providedType);
              super.getDependencies(control, instance, annotation, context);
            }

            @Override
            public boolean handle(final InjectableInstance instance,
                                  final Annotation annotation,
                                  final IOCProcessingContext context) {
              return true;
            }
          }, Rule.before(injectionContext.getAnnotationsForElementType(WiringElementType.SingletonBean),
              injectionContext.getAnnotationsForElementType(WiringElementType.DependentBean)));

          break;
      }
    }

    for (final Map.Entry<WiringElementType, Class<? extends Annotation>> entry
        : injectionContext.getAllElementMappings()) {
      switch (entry.getKey()) {
        case ProducerElement:
          registerHandler(entry.getValue(), new JSR330AnnotationHandler() {
            @Override
            public void getDependencies(final DependencyControl control,
                                        final InjectableInstance instance,
                                        final Annotation annotation,
                                        final IOCProcessingContext context) {

              final MetaClass injectedType = instance.getElementTypeOrMethodReturnType();
              final MetaClassMember producerMember;

              switch (instance.getTaskType()) {
                case PrivateMethod:
                case Method:
View Full Code Here


                System.out.println("*** version without notice.                                                ***");
                System.out.println("******************************************************************************");

                classes = new ArrayList<MetaClass>(classes);

                MetaClass metaClass;
                Scan:
                for (final String type : injectionContext.getAllReachableTypes()) {
                  if (type.indexOf('$') != -1) {
                    try {
                      metaClass = MetaClassFactory.get(type);
                    }
                    catch (Throwable t) {
                      continue;
                    }
                  }
                  else {
                    metaClass = MetaClassFactory.get(type);
                  }

                  if (metaClass.isDefaultInstantiable() && metaClass.isPublic() && metaClass.isConcrete()) {
                    for (final Annotation anno : metaClass.getAnnotations()) {
                      if (anno.annotationType().isAnnotationPresent(Scope.class)
                          || anno.annotationType().isAnnotationPresent(NormalScope.class)) {
                        continue Scan;
                      }
                    }
View Full Code Here

    entry.handler.registerMetadata(injectableInstance, annotation, context);

    del.processDependencies();

    final MetaClass masqueradeClass = ((DependencyControlImpl) dependencyControl).masqueradeClass;

    injectionContext.getGraphBuilder().addItem(masqueradeClass, del);
  }
View Full Code Here

                            final MetaMethod metaMethod,
                            final Class<? extends Annotation> annotationClass,
                            final IOCProcessingContext context) {

    final Annotation annotation = metaMethod.getAnnotation(annotationClass);
    final MetaClass type = metaMethod.getDeclaringClass();

    //final MetaMethod metaMethod = MetaClassFactory.get(method);

    dependencyControl.masqueradeAs(type);

    final InjectableInstance injectableInstance
        = getMethodInjectedInstance(metaMethod, null,
        injectionContext);

    final ProcessingDelegate del = new ProcessingDelegate() {
      @Override
      public void processDependencies() {
        entry.handler.getDependencies(dependencyControl, injectableInstance, annotation, context);
      }

      @Override
      public boolean process() {
        injectionContext.addType(type);

        final Injector injector = injectionContext.getInjector(type);
        final InjectableInstance injectableInstance
            = getMethodInjectedInstance(metaMethod, injector,
            injectionContext);

        return entry.handler.handle(injectableInstance, annotation, context);
      }

      @Override
      public String toString() {
        return type.getFullyQualifiedName();
      }
    };

    entry.handler.registerMetadata(injectableInstance, annotation, context);

    del.processDependencies();

    final MetaClass masqueradeClass = ((DependencyControlImpl) dependencyControl).masqueradeClass;

    injectionContext.getGraphBuilder().addItem(masqueradeClass, del);
  }
View Full Code Here

                           final MetaField metaField,
                           final Class<? extends Annotation> annotationClass,
                           final IOCProcessingContext context) {

    final Annotation annotation = metaField.getAnnotation(annotationClass);
    final MetaClass type = metaField.getDeclaringClass();

    dependencyControl.masqueradeAs(type);

    final ProcessingDelegate del = new ProcessingDelegate() {
      @SuppressWarnings("unchecked")
      @Override
      public void processDependencies() {

        entry.handler.getDependencies(dependencyControl, InjectableInstance.getFieldInjectedInstance(metaField, null,
            injectionContext), annotation, context);
      }

      @SuppressWarnings("unchecked")
      @Override
      public boolean process() {
        injectionContext.addType(type);

        final InjectableInstance injectableInstance
            = InjectableInstance.getFieldInjectedInstance(metaField, injectionContext.getInjector(type),
            injectionContext);

        entry.handler.registerMetadata(injectableInstance, annotation, context);

        return entry.handler.handle(injectableInstance, annotation, context);
      }

      @Override
      public String toString() {
        return type.getFullyQualifiedName();
      }
    };

    del.processDependencies();
View Full Code Here

        .implementsInterface(QualifierEqualityFactory.class)
        .body();

    builder.getClassDefinition().getContext().setPermissiveMode(true);

    final MetaClass mapStringAnnoComp
        = parameterizedAs(HashMap.class, typeParametersOf(String.class, AnnotationComparator.class));

    builder.privateField(COMPARATOR_MAP_VAR, mapStringAnnoComp)
        .initializesWith(Stmt.newObject(mapStringAnnoComp)).finish();

    final ConstructorBlockBuilder<? extends ClassStructureBuilder<?>> constrBuilder = builder.publicConstructor();

    final MetaDataScanner scanner = ScannerSingleton.getOrCreateInstance();
    final Set<Class<?>> typesAnnotatedWith = scanner.getTypesAnnotatedWith(Qualifier.class);

    for (final Class<?> aClass : typesAnnotatedWith) {
      try {
        final MetaClass MC_annotationClass = GWTClass.newInstance(oracle, oracle.getType(aClass.getName()));
        final Collection<MetaMethod> methods = getAnnotationAttributes(MC_annotationClass);

        if (methods.isEmpty()) continue;

        constrBuilder._(Stmt.loadVariable(COMPARATOR_MAP_VAR)
            .invoke("put", aClass.getName(), generateComparatorFor(MC_annotationClass, methods)));
      }
      catch (NotFoundException e) {
        // ignore.
      }
    }

    // finish constructor
    constrBuilder.finish();

    final MetaClass annotationClazz = JavaReflectionClass.newUncachedInstance(Annotation.class);
    builder.publicMethod(boolean.class, "isEqual",
        Parameter.of(annotationClazz, "a1"), Parameter.of(annotationClazz, "a2"))
        .body()
        ._(If.cond(invokeStatic(QualifierUtil.class, "isSameType", Refs.get("a1"), Refs.get("a2")))
            ._(
View Full Code Here

    }
    return methods;
  }

  private Statement generateComparatorFor(final MetaClass MC_annotationClass, final Collection<MetaMethod> methods) {
    final MetaClass MC_annoComparator = parameterizedAs(AnnotationComparator.class, typeParametersOf(MC_annotationClass));

    final AnonymousClassStructureBuilder clsBuilder = ObjectBuilder.newInstanceOf(MC_annoComparator).extend();
    final MethodBlockBuilder<AnonymousClassStructureBuilder> isEqualBuilder = clsBuilder
        .publicMethod(boolean.class, "isEqual",
            Parameter.of(MC_annotationClass, "a1"), Parameter.of(MC_annotationClass, "a2"))
View Full Code Here

        + packageName + "." + className);

    final BuildMetaClass bootStrapClass = classStructureBuilder.getClassDefinition();
    final Context buildContext = bootStrapClass.getContext();

    final MetaClass Annotation_MC = MetaClassFactory.get(Annotation.class);

    buildContext.addInterningCallback(new InterningCallback() {
      private final Map<Set<Annotation>, String> cachedArrays = new HashMap<Set<Annotation>, String>();

      @Override
      public Statement intern(final LiteralValue<?> literalValue) {
        if (literalValue.getValue() == null) {
          return null;
        }

        if (literalValue.getValue() instanceof Annotation) {
          final Annotation annotation = (Annotation) literalValue.getValue();

          final Class<? extends Annotation> aClass = annotation.annotationType();
          final String fieldName = PrivateAccessUtil.condensify(aClass.getPackage().getName()) +
              aClass.getSimpleName() + "_" + String.valueOf(literalValue.getValue().hashCode()).replaceFirst("\\-", "_");

          classStructureBuilder.privateField(fieldName, annotation.annotationType())
              .modifiers(Modifier.Final).initializesWith(AnnotationEncoder.encode(annotation))
              .finish();

          return Refs.get(fieldName);
        }
        else if (literalValue.getType().isArray()
            && Annotation_MC.isAssignableFrom(literalValue.getType().getOuterComponentType())) {

          final Set<Annotation> annotationSet
              = new HashSet<Annotation>(Arrays.asList((Annotation[]) literalValue.getValue()));

          if (cachedArrays.containsKey(annotationSet)) {
            return Refs.get(cachedArrays.get(annotationSet));
          }

          final MetaClass type = literalValue.getType().getOuterComponentType();
          final String fieldName = "arrayOf" + PrivateAccessUtil.condensify(type.getPackageName()) +
              type.getName().replaceAll("\\.", "_") + "_"
              + String.valueOf(literalValue.getValue().hashCode()).replaceAll("\\-", "_");

          // force rendering of literals in this array first.
          for (final Annotation a : annotationSet) {
            LiteralFactory.getLiteral(a).generate(buildContext);
View Full Code Here

      return;
    }

    creationalCallbackRendered = true;

    final MetaClass beanProviderMC = parameterizedAs(AsyncBeanProvider.class,
        typeParametersOf(injectedType));
    final MetaClass creationCallbackMC = parameterizedAs(CreationalCallback.class,
        typeParametersOf(injectedType));

    final BlockBuilder<AnonymousClassStructureBuilder> statements = ObjectBuilder.newInstanceOf(beanProviderMC)
        .extend()
        .publicOverridesMethod("getInstance",
            Parameter.finalOf(creationCallbackMC, "callback"),
            Parameter.finalOf(AsyncCreationalContext.class, "pContext")
        );

    injectionContext.getProcessingContext().pushBlockBuilder(statements);

    statements
        ._(Stmt.declareFinalVariable("async", AsyncBeanContext.class, Stmt.newObject(AsyncBeanContext.class)));

    if (producerMember instanceof MetaMethod) {
      final MetaMethod producerMethod = (MetaMethod) producerMember;
      for (final MetaParameter metaParameter : producerMethod.getParameters()) {
        final Injector inj = injectionContext.getQualifiedInjector(metaParameter.getType(), metaParameter.getAnnotations());

        final MetaClass concreteInjectedType = inj.getConcreteInjectedType();
        final String varName = InjectUtil.getVarNameFromType(concreteInjectedType, metaParameter);

        final MetaClass depCreationCallbackMC = parameterizedAs(CreationalCallback.class,
            typeParametersOf(concreteInjectedType));

        final ObjectBuilder callback = Stmt.newObject(depCreationCallbackMC)
            .extend().publicOverridesMethod("callback", Parameter.finalOf(concreteInjectedType, "beanValue"))
            .append(Stmt.loadVariable("async").invoke("finish", Refs.get("this"), Refs.get("beanValue")))
            .finish().finish();

        statements.append(Stmt.declareFinalVariable(varName, depCreationCallbackMC, callback));
        statements.append(Stmt.loadVariable("async").invoke("wait", Refs.get(varName)));
      }
    }

    final String producerBeanCBVar = InjectUtil.getVarNameFromType(producerMember.getDeclaringClass(), injectableInstance);
    final MetaClass callbackMC = parameterizedAs(CreationalCallback.class, typeParametersOf(producerMember.getDeclaringClass()));

    final BlockBuilder<AnonymousClassStructureBuilder> blockBuilder = Stmt.create().newObject(callbackMC)
        .extend()
        .publicOverridesMethod("callback", Parameter.finalOf(producerMember.getDeclaringClass(), "bean"));
View Full Code Here

    registerDestructorCallback(injectableInstance, disposerMethod);
    return null;
  }

  private MetaMethod findDisposerMethod(final IOCProcessingContext ctx) {
    final MetaClass declaringClass = producerMember.getDeclaringClass();

    for (final MetaMethod method : declaringClass.getDeclaredMethods()) {
      final MetaParameter[] parameters = method.getParameters();
      if (parameters.length != 1) continue;

      if (parameters[0].isAnnotationPresent(Disposes.class)
          && parameters[0].getType().isAssignableFrom(injectedType)
View Full Code Here

TOP

Related Classes of org.jboss.errai.codegen.meta.MetaClass

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.