Ejemplo n.º 1
0
 @SuppressWarnings("deprecation")
 private static String getFieldInjectionExpression(
     JField field, String iocContainerVariable, Map<String, IocConfig<?>> configurations) {
   Inject inject = field.getAnnotation(Inject.class);
   if (inject != null) {
     JType fieldType = field.getType();
     if (!field.isStatic()) {
       if (fieldType.isClassOrInterface() != null) {
         String fieldTypeName = fieldType.getQualifiedSourceName();
         IocConfigImpl<?> iocConfig = (IocConfigImpl<?>) configurations.get(fieldTypeName);
         if (iocConfig != null) {
           if (inject
               .scope()
               .equals(org.cruxframework.crux.core.client.ioc.Inject.Scope.DEFAULT)) {
             return iocContainerVariable
                 + ".get"
                 + fieldTypeName.replace('.', '_')
                 + "("
                 + Scope.class.getCanonicalName()
                 + "."
                 + iocConfig.getScope().name()
                 + ", null)";
           }
           return iocContainerVariable
               + ".get"
               + fieldTypeName.replace('.', '_')
               + "("
               + Scope.class.getCanonicalName()
               + "."
               + getScopeName(inject.scope())
               + ", "
               + EscapeUtils.quote(inject.subscope())
               + ")";
         } else {
           return "GWT.create(" + fieldTypeName + ".class)";
         }
       } else {
         throw new IoCException(
             "Error injecting field ["
                 + field.getName()
                 + "] from type ["
                 + field.getEnclosingType().getQualifiedSourceName()
                 + "]. Primitive fields can not be handled by ioc container.");
       }
     } else {
       throw new IoCException(
           "Error injecting field ["
               + field.getName()
               + "] from type ["
               + field.getEnclosingType().getQualifiedSourceName()
               + "]. Static fields can not be handled by ioc container.");
     }
   }
   return null;
 }