private void addConstructorInjectionStatements(final Injectable injectable, final Collection<Dependency> constructorDependencies, final List<Statement> createInstanceStatements) { final Object[] constructorParameterStatements = new Object[constructorDependencies.size()]; final List<Statement> dependentScopedRegistrationStatements = new ArrayList<>(constructorDependencies.size()); for (final Dependency dep : constructorDependencies) { processConstructorDependencyStatement(createInstanceStatements, constructorParameterStatements, dependentScopedRegistrationStatements, dep); } createInstanceStatements.add(declareFinalVariable("instance", injectable.getInjectedType(), newObject(injectable.getInjectedType(), constructorParameterStatements))); createInstanceStatements.addAll(dependentScopedRegistrationStatements); }
private void assignNewObjectWithZeroArgConstructor(final Injectable injectable, final List<Statement> createInstanceStatements) { final MetaConstructor noArgConstr = injectable.getInjectedType().getDeclaredConstructor(new MetaClass[0]); final Object newObjectStmt; if (noArgConstr.isPublic()) { newObjectStmt = newObject(injectable.getInjectedType()); } else { newObjectStmt = controller.exposedConstructorStmt(noArgConstr); } createInstanceStatements.add(declareFinalVariable("instance", injectable.getInjectedType(), newObjectStmt)); }
private static void traceConstituentHashContents(final Injectable injectable, final String name) { log.trace("Begin trace of hashContent for {}", name); log.trace("Combined content: {}", injectable.hashContent()); log.trace("HashContent for injectable type: {}", injectable.getInjectedType().hashContent()); for (final Dependency dep : injectable.getDependencies()) { log.trace("HashContent for {} dep of type {}: {}", dep.getDependencyType().toString(), dep.getInjectable().getInjectedType(), dep.getInjectable().getInjectedType().hashContent()); } log.trace("End trace of hashContent for {}", name); }
private MetaClass addFactoryDeclaration(final Injectable injectable, final IOCProcessingContext processingContext) { final String factoryName = injectable.getFactoryName(); final MetaClass typeCreatedByFactory = injectable.getInjectedType(); return addFactoryDeclaration(factoryName, typeCreatedByFactory, processingContext); }
private int computeHashContent() { int hashContent = type.hashContent(); for (final BaseDependency dep: dependencies) { hashContent ^= dep.injectable.resolution.getInjectedType().hashContent(); } return hashContent; }
private String injectableConstructorErrorMessage(final Injectable injectable) { final MetaConstructor constr = getAccessibleConstructor(injectable); return "While creating a proxy for " + injectable.getInjectedType().getFullyQualifiedName() + " an exception was thrown from this constructor: " + constr + "\nTo fix this problem, add a no-argument public or protected constructor for use in proxying."; }
private Class<?> getAsyncFragmentId(final Injectable injectable) { final LoadAsync loadAsync = injectable.getInjectedType().getAnnotation(LoadAsync.class); if (loadAsync == null) { return LoadAsync.NO_FRAGMENT.class; } else { return loadAsync.value(); } }
@Override protected List<Statement> generateCreateInstanceStatements(final ClassStructureBuilder<?> bodyBlockBuilder, final Injectable injectable, final DependencyGraph graph, final InjectionContext injectionContext) { return Collections.<Statement> singletonList( Stmt.castTo(injectable.getInjectedType(), invokeStatic(WindowInjectionContextStorage.class, "createOrGet") .invoke("getBean", injectable.getInjectedType().getFullyQualifiedName())).returnValue()); }
private void processInjectionPoints(final Injectable typeInjectable, final DependencyGraphBuilder builder, final List<String> problems) { final MetaClass type = typeInjectable.getInjectedType(); final MetaConstructor injectableConstructor = getInjectableConstructor(type); if (injectableConstructor != null) { if (!injectableConstructor.isPublic()) { problems.add("The constructor of " + typeInjectable.getInjectedType().getFullyQualifiedName() + " annotated with @Inject must be public."); } addConstructorInjectionPoints(typeInjectable, injectableConstructor, builder); } addFieldInjectionPoints(typeInjectable, builder, problems); addMethodInjectionPoints(typeInjectable, builder, problems); }
private void addProviderInjectable(final Injectable providerImplInjectable, final DependencyGraphBuilder builder, final boolean enabled) { final MetaClass providerImpl = providerImplInjectable.getInjectedType(); final MetaMethod providerMethod = providerImpl.getMethod("get", new Class[0]); final MetaClass providedType = getMethodReturnType(providerMethod); final InjectableType injectableType = (enabled ? InjectableType.Provider : InjectableType.Disabled); final Injectable providedInjectable = builder.addInjectable(providedType, qualFactory.forSource(providerMethod), EXACT_TYPE, Dependent.class, injectableType, WiringElementType.Provider, WiringElementType.DependentBean); builder.addProducerMemberDependency(providedInjectable, providerImplInjectable.getInjectedType(), providerImplInjectable.getQualifier(), providerMethod); }
private void maybeImplementInvokePostConstructs(final ClassStructureBuilder<?> bodyBlockBuilder, final Injectable injectable, final List<Statement> invokePostConstructStatements) { if (!invokePostConstructStatements.isEmpty()) { bodyBlockBuilder .publicMethod(MetaClassFactory.get(void.class), "invokePostConstructs", finalOf(injectable.getInjectedType(), "instance")) .appendAll(invokePostConstructStatements).finish(); } }
private Statement initializeProxyHelper(final Injectable injectable) { return newObject( parameterizedAs(ProxyHelperImpl.class, typeParametersOf(injectable.getInjectedType())), injectable.getFactoryName()); }
private void maybeImplementConstructor(final ClassStructureBuilder<?> proxyImpl, final Injectable injectable) { if (injectable.getInjectedType().isInterface()) { return; } final MetaConstructor accessibleConstructor = getAccessibleConstructor(injectable); if (accessibleConstructor.getParameters().length > 0) { implementConstructor(proxyImpl, accessibleConstructor); } }
private void implementInitProxyProperties(final ClassStructureBuilder<?> proxyImpl, final Injectable injectable) { final BlockBuilder<?> initBody = proxyImpl .publicMethod(void.class, "initProxyProperties", finalOf(injectable.getInjectedType(), "instance")).body(); for (final Entry<String, Statement> prop : controller.getProxyProperties()) { proxyImpl.privateField(prop.getKey(), prop.getValue().getType()).finish(); initBody.append(loadVariable(prop.getKey()).assignValue(prop.getValue())); } initBody.finish(); }
private void addFieldInjectionPoints(final Injectable typeInjectable, final DependencyGraphBuilder builder, final List<String> problems) { final boolean noPublicFieldsAllowed = typeInjectable.getWiringElementTypes().contains(WiringElementType.NormalScopedBean); final MetaClass type = typeInjectable.getInjectedType(); final Collection<Class<? extends Annotation>> injectAnnotations = injectionContext.getAnnotationsForElementType(WiringElementType.InjectionPoint); for (final Class<? extends Annotation> inject : injectAnnotations) { for (final MetaField field : type.getFieldsAnnotatedWith(inject)) { if (noPublicFieldsAllowed && field.isPublic()) { problems.add("The normal scoped bean " + type.getFullyQualifiedName() + " has a public field " + field.getName()); } builder.addFieldDependency(typeInjectable, field.getType(), qualFactory.forSink(field), field); } } }
private void registerFactoryWithContext(final Injectable injectable, final MetaClass factoryClass, final Map<Class<? extends Annotation>, MetaClass> scopeContexts, @SuppressWarnings("rawtypes") final BlockBuilder registerFactoriesBody) { final Class<? extends Annotation> scope = injectable.getScope(); final MetaClass injectedType = injectable.getInjectedType(); final MetaClass scopeContextImpl = Assert.notNull("No scope context for " + scope.getSimpleName(), scopeContexts.get(scope)); final String contextVarName = getContextVarName(scopeContextImpl); registerFactoriesBody.append(loadVariable(contextVarName).invoke("registerFactory", Stmt.castTo(parameterizedAs(Factory.class, typeParametersOf(injectedType)), invokeStatic(GWT.class, "create", factoryClass)))); }
private void implementAsBeanType(final ClassStructureBuilder<?> proxyImpl, final Injectable injectable) { proxyImpl.publicMethod(injectable.getInjectedType(), "asBeanType") .body() .append(loadVariable("this").returnValue()) .finish(); }
private void addContextualProviderInjectable(final Injectable providerInjectable, final DependencyGraphBuilder builder, final boolean enabled) { final MetaClass providerImpl = providerInjectable.getInjectedType(); final MetaMethod providerMethod = providerImpl.getMethod("provide", Class[].class, Annotation[].class); // Do not get generic return type for contextual providers final MetaClass providedType = providerMethod.getReturnType(); final InjectableType injectableType = (enabled ? InjectableType.ContextualProvider : InjectableType.Disabled); final Injectable providedInjectable = builder.addInjectable(providedType, qualFactory.forUniversallyQualified(), EXACT_TYPE, Dependent.class, injectableType, WiringElementType.Provider, WiringElementType.DependentBean); builder.addProducerMemberDependency(providedInjectable, providerImpl, providerInjectable.getQualifier(), providerMethod); }
private void declareAndInitializeProxyHelper(final Injectable injectable, final ClassStructureBuilder<?> bodyBlockBuilder) { bodyBlockBuilder .privateField("proxyHelper", parameterizedAs(ProxyHelper.class, typeParametersOf(injectable.getInjectedType()))) .modifiers(Modifier.Final) .initializesWith(initializeProxyHelper(injectable)) .finish(); }
private void implementSetInstance(final ClassStructureBuilder<?> proxyImpl, final Injectable injectable) { proxyImpl.publicMethod(void.class, "setInstance", finalOf(injectable.getInjectedType(), "instance")) .body() .append(loadVariable("proxyHelper").invoke("setInstance", loadVariable("instance"))) .finish(); }