コード例 #1
0
  @Override
  public TypedExpression buildVariable(
      InjectionBuilderContext injectionBuilderContext, InjectionNode injectionNode) {

    TypedExpression providerVar =
        injectionExpressionBuilder.buildVariable(injectionBuilderContext, providerInjectionNode);

    JExpression expression = providerVar.getExpression().invoke(PROVIDER_METHOD);

    return typedExpressionFactory.build(injectionNode.getASTType(), expression);
  }
コード例 #2
0
  private JInvocation buildScopeKey(InjectionNode injectionNode) {
    InjectionSignature signature = injectionNode.getTypeSignature();

    JClass injectionNodeClassRef = generationUtil.ref(injectionNode.getASTType());

    return codeModel
        .ref(ScopeKey.class)
        .staticInvoke(ScopeKey.GET_METHOD)
        .arg(injectionNodeClassRef.dotclass())
        .arg(JExpr.lit(signature.buildScopeKeySignature()));
  }
コード例 #3
0
ファイル: ScopeAnalysis.java プロジェクト: kamiox/transfuse
  @Override
  public void analyzeType(
      InjectionNode injectionNode, ASTType concreteType, AnalysisContext context) {

    if (injectionNode.getASTType().equals(concreteType)) {
      for (Class<? extends Annotation> scopeType : scopeAspectFactoryRepository.getScopes()) {
        if (concreteType.isAnnotated(scopeType)) {
          ScopeAspectFactory scopeAspectFactory =
              scopeAspectFactoryRepository.getScopeAspectFactory(scopeType);
          injectionNode.addAspect(
              scopeAspectFactory.buildAspect(injectionNode, concreteType, context));
        }
      }
    }
  }
コード例 #4
0
  @Test
  public void testAnalysis() {
    AnalysisContext analysisContext = simpleAnalysisContextFactory.buildContext();
    analysisContext.getAOPRepository().put(aopAnnotationASTType, methodInterceptorASTType);

    for (ASTMethod astMethod : proxyTargetASTType.getMethods()) {
      proxyAnalyzer.analyzeMethod(
          proxyTargetInjectionNode, proxyTargetASTType, astMethod, analysisContext);
    }

    assertTrue(proxyTargetInjectionNode.containsAspect(AOPProxyAspect.class));
    AOPProxyAspect aspect = proxyTargetInjectionNode.getAspect(AOPProxyAspect.class);
    for (ASTMethod astMethod : proxyTargetASTType.getMethods()) {
      assertTrue(aspect.getMethodInterceptors().containsKey(astMethod));
      Set<InjectionNode> interceptorInjectionNodes = aspect.getMethodInterceptors().get(astMethod);
      for (InjectionNode interceptorInjectionNode : interceptorInjectionNodes) {
        assertEquals(methodInterceptorASTType, interceptorInjectionNode.getASTType());
      }
    }
  }
コード例 #5
0
  public TypedExpression buildVariable(
      InjectionBuilderContext injectionBuilderContext, InjectionNode injectionNode) {

    // build provider
    JDefinedClass providerClass = providerGenerator.generateProvider(injectionNode, true);
    JExpression provider = JExpr._new(providerClass).arg(injectionBuilderContext.getScopeVar());

    // build scope call
    // <T> T getScopedObject(Class<T> clazz, Provider<T> provider);
    TypedExpression contextScopeHolderExpression =
        injectionExpressionBuilder.buildVariable(injectionBuilderContext, this.contextScopeHolder);

    JExpression cast =
        invocationHelper.coerceType(ContextScopeHolder.class, contextScopeHolderExpression);
    JExpression scopeVar = cast.invoke(ContextScopeHolder.GET_SCOPE);

    JExpression expression =
        scopeVar.invoke(Scope.GET_SCOPED_OBJECT).arg(buildScopeKey(injectionNode)).arg(provider);

    return typedExpressionFactory.build(injectionNode.getASTType(), expression);
  }
コード例 #6
0
  private InjectionNode buildProxyInjectionNode(
      InjectionNode injectionNode,
      String proxyClassName,
      ASTInjectionAspect injectionAspect,
      ConstructorInjectionPoint proxyConstructorInjectionPoint) {
    InjectionNode proxyInjectionNode =
        new InjectionNode(new ASTProxyType(injectionNode.getASTType(), proxyClassName));

    proxyInjectionNode.getAspects().putAll(injectionNode.getAspects());

    // alter construction injection
    ASTInjectionAspect proxyInjectionAspect = new ASTInjectionAspect();
    proxyInjectionAspect.addAllFieldInjectionPoints(injectionAspect.getFieldInjectionPoints());
    proxyInjectionAspect.addAllMethodInjectionPoints(injectionAspect.getMethodInjectionPoints());
    // replace proxy constructor because of optional interceptor construction parameters
    proxyInjectionAspect.add(proxyConstructorInjectionPoint);

    proxyInjectionAspect.setAssignmentType(injectionAspect.getAssignmentType());

    proxyInjectionNode.addAspect(proxyInjectionAspect);

    return proxyInjectionNode;
  }