Пример #1
0
  @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));
        }
      }
    }
  }
  @Override
  public void analyzeField(
      InjectionNode injectionNode,
      ASTType concreteType,
      ASTField astField,
      AnalysisContext context) {

    if (astField.isAnnotated(NonConfigurationInstance.class)) {
      NonConfigurationAspect aspect = buildAspect(injectionNode);
      aspect.add(injectionPointFactory.buildInjectionPoint(concreteType, astField, context));

      if (!injectionNode.containsAspect(ASTInjectionAspect.class)) {
        injectionNode.addAspect(ASTInjectionAspect.class, new ASTInjectionAspect());
      }

      injectionNode
          .getAspect(ASTInjectionAspect.class)
          .setAssignmentType(ASTInjectionAspect.InjectionAssignmentType.FIELD);
    }
  }
Пример #3
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;
  }
Пример #4
0
  @Test
  public void testBackLinkAnalysis() {
    ASTType astType = astClassFactory.getType(A.class);

    InjectionNode injectionNode = analyzer.analyze(astType, astType, analysisContext);
    injectionNode.addAspect(VariableBuilder.class, variableInjectionBuilderProvider.get());

    // A -> B && A -> E
    assertEquals(1, countMethodInjectionPoints(injectionNode.getAspect(ASTInjectionAspect.class)));
    MethodInjectionPoint bInjectionPoint =
        injectionNode
            .getAspect(ASTInjectionAspect.class)
            .getGroups()
            .get(1)
            .getMethodInjectionPoints()
            .iterator()
            .next();

    assertEquals(2, bInjectionPoint.getInjectionNodes().size());
    // A -> B
    InjectionNode bInjectionNode = bInjectionPoint.getInjectionNodes().get(0);
    assertTrue(isProxyRequired(bInjectionNode));
    assertEquals(BImpl.class.getCanonicalName(), bInjectionNode.getClassName());

    // A -> E
    InjectionNode eInjectionNode = bInjectionPoint.getInjectionNodes().get(1);
    assertFalse(isProxyRequired(eInjectionNode));
    assertEquals(E.class.getCanonicalName(), eInjectionNode.getClassName());

    // B -> C
    assertEquals(1, countFieldInjectionPoints(bInjectionNode.getAspect(ASTInjectionAspect.class)));
    FieldInjectionPoint cInjectionPoint =
        bInjectionNode
            .getAspect(ASTInjectionAspect.class)
            .getGroups()
            .get(1)
            .getFieldInjectionPoints()
            .iterator()
            .next();
    InjectionNode cInjectionNode = cInjectionPoint.getInjectionNode();
    assertFalse(isProxyRequired(cInjectionNode));
    assertEquals(C.class.getCanonicalName(), cInjectionNode.getClassName());

    // B -> F
    ConstructorInjectionPoint fNonBackLinkInjectionPoint =
        bInjectionNode.getAspect(ASTInjectionAspect.class).getConstructorInjectionPoint();
    assertEquals(1, fNonBackLinkInjectionPoint.getInjectionNodes().size());
    InjectionNode fInjectionNode = fNonBackLinkInjectionPoint.getInjectionNodes().get(0);
    assertFalse(isProxyRequired(fInjectionNode));
    assertEquals(F.class.getCanonicalName(), fInjectionNode.getClassName());

    // E -> F
    ConstructorInjectionPoint fNonBackLinkInjectionPoint2 =
        eInjectionNode.getAspect(ASTInjectionAspect.class).getConstructorInjectionPoint();
    assertEquals(1, fNonBackLinkInjectionPoint2.getInjectionNodes().size());
    InjectionNode fInjectionNode2 = fNonBackLinkInjectionPoint2.getInjectionNodes().get(0);
    assertFalse(isProxyRequired(fInjectionNode2));

    // C -> D
    assertEquals(1, countFieldInjectionPoints(cInjectionNode.getAspect(ASTInjectionAspect.class)));
    FieldInjectionPoint dInjectionPoint =
        cInjectionNode
            .getAspect(ASTInjectionAspect.class)
            .getGroups()
            .get(1)
            .getFieldInjectionPoints()
            .iterator()
            .next();
    InjectionNode dInjectionNode = dInjectionPoint.getInjectionNode();
    assertFalse(isProxyRequired(dInjectionNode));
    assertEquals(D.class.getCanonicalName(), dInjectionNode.getClassName());

    // D -> B back link
    ConstructorInjectionPoint bBackLinkInjectionPoint =
        dInjectionNode.getAspect(ASTInjectionAspect.class).getConstructorInjectionPoint();
    assertEquals(1, bBackLinkInjectionPoint.getInjectionNodes().size());
    InjectionNode bBackLinkInjectionNode = bBackLinkInjectionPoint.getInjectionNodes().get(0);
    assertEquals(BImpl.class.getCanonicalName(), bBackLinkInjectionNode.getClassName());
    assertTrue(isProxyRequired(bBackLinkInjectionNode));

    // B -> F and E -> F difference
    assertNotSame(fInjectionNode, fInjectionNode2);
    assertFalse(fInjectionNode.equals(fInjectionNode2));
  }
 private NonConfigurationAspect buildAspect(InjectionNode injectionNode) {
   if (!injectionNode.containsAspect(NonConfigurationAspect.class)) {
     injectionNode.addAspect(new NonConfigurationAspect());
   }
   return injectionNode.getAspect(NonConfigurationAspect.class);
 }