protected void implementCreateInstance(final ClassStructureBuilder<?> bodyBlockBuilder, final Injectable injectable, final List<Statement> createInstanceStatements) { String createInstanceMethodName; Parameter[] params; if (injectable.isContextual()) { createInstanceMethodName = "createContextualInstance"; params = new Parameter[] { finalOf(ContextManager.class, "contextManager"), finalOf(Class[].class, "typeArgs"), finalOf(Annotation[].class, "qualifiers") }; } else { createInstanceMethodName = "createInstance"; params = new Parameter[] { finalOf(ContextManager.class, "contextManager") }; } bodyBlockBuilder.publicMethod(injectable.getInjectedType(), createInstanceMethodName, params) .appendAll(createInstanceStatements) .finish(); }
if (depInjectable.isContextual()) { final MetaClass[] typeArgsClasses = getTypeArguments(field.getType()); final Annotation[] qualifiers = getQualifiers(field).toArray(new Annotation[0]);
protected Statement generateFactoryHandleStatement(final Injectable injectable) { final Statement newObject; if (injectable.getInjectedType().isAnnotationPresent(ActivatedBy.class)) { final Class<? extends BeanActivator> activatorType = injectable.getInjectedType().getAnnotation(ActivatedBy.class).value(); newObject = newObject(FactoryHandleImpl.class, loadLiteral(injectable.getInjectedType()), injectable.getFactoryName(), injectable.getScope(), isEager(injectable.getInjectedType()), injectable.getBeanName(), !injectable.isContextual(), loadLiteral(activatorType)); } else { newObject = newObject(FactoryHandleImpl.class, loadLiteral(injectable.getInjectedType()), injectable.getFactoryName(), injectable.getScope(), isEager(injectable.getInjectedType()), injectable.getBeanName(), !injectable.isContextual()); } return newObject; }
private ContextualStatementBuilder getInjectedValue(final Injectable depInjectable, final ParamDependency paramDep) { final ContextualStatementBuilder injectedValue; if (depInjectable.isContextual()) { final MetaClass[] typeArgsClasses = getTypeArguments(paramDep.getParameter().getType()); final Annotation[] qualifiers = getQualifiers(paramDep.getParameter()).toArray(new Annotation[0]); injectedValue = castTo(depInjectable.getInjectedType(), loadVariable("contextManager").invoke("getContextualInstance", loadLiteral(depInjectable.getFactoryName()), typeArgsClasses, qualifiers)); } else { injectedValue = castTo(depInjectable.getInjectedType(), loadVariable("contextManager").invoke("getInstance", loadLiteral(depInjectable.getFactoryName()))); } return injectedValue; } }
if (depInjectable.isContextual()) { final MetaClass[] typeArgsClasses = getTypeArguments(setter.getParameters()[0].getType()); final Annotation[] qualifiers = getQualifiers(setter).toArray(new Annotation[0]);
private ContextualStatementBuilder generateProducerParamCreationStmt(final ParamDependency paramDep) { ContextualStatementBuilder producerParamCreationStmt; if (paramDep.getInjectable().isContextual()) { final MetaParameter param = paramDep.getParameter(); final MetaClass[] typeArgs = getTypeArguments(param.getType()); final Annotation[] annotations = param.getAnnotations(); producerParamCreationStmt = castTo(paramDep.getInjectable().getInjectedType(), loadVariable("contextManager").invoke("getContextualInstance", paramDep.getInjectable().getFactoryName(), typeArgs, annotations)); } else { producerParamCreationStmt = castTo(paramDep.getInjectable().getInjectedType(), loadVariable("contextManager").invoke("getInstance", paramDep.getInjectable().getFactoryName())); } return producerParamCreationStmt; }
private Statement generateFactoryHandle(final Injectable injectable, @SuppressWarnings("rawtypes") final BlockBuilder curMethod) { final String handleVarName = "handleFor" + injectable.getFactoryName(); curMethod.append(declareFinalVariable(handleVarName, FactoryHandleImpl.class, ObjectBuilder.newInstanceOf(FactoryHandleImpl.class) .withParameters(loadLiteral(injectable.getInjectedType()), loadLiteral(injectable.getFactoryName()), loadLiteral(injectable.getScope()), loadLiteral(false), loadLiteral(injectable.getBeanName()), loadLiteral(!injectable.isContextual())))); curMethod.append(loadVariable(handleVarName).invoke("setAssignableTypes", getAssignableTypesArrayStmt(injectable))); if (!injectable.getQualifier().isDefaultQualifier()) { curMethod.append(loadVariable(handleVarName).invoke("setQualifiers", getAnnotationArrayStmt(injectable.getQualifier()))); } return loadVariable(handleVarName); }