Пример #1
0
  @Override
  public boolean visit(NormalAnnotation node) {
    //
    // Test method?
    //
    if (isTestAnnotation(node.getTypeName().toString())) {
      ASTNode parent = node.getParent();
      if (parent instanceof MethodDeclaration) {
        addTestMethod((MethodDeclaration) parent, JDK15_ANNOTATION);
      } else if (parent instanceof TypeDeclaration) {
        m_typeIsTest = true;
        m_annotationType = JDK15_ANNOTATION;
      }

      List pairs = node.values();
      for (Iterator it = pairs.iterator(); it.hasNext(); ) {
        MemberValuePair mvp = (MemberValuePair) it.next();
        Name attribute = mvp.getName();
        String name = attribute.getFullyQualifiedName();
        if ("groups".equals(name)) {
          Expression value = mvp.getValue();
          // Array?
          if (value instanceof ArrayInitializer) {
            ArrayInitializer ai = (ArrayInitializer) value;
            List expressions = ai.expressions();
            for (Iterator it2 = expressions.iterator(); it2.hasNext(); ) {
              Expression e = (Expression) it2.next();
              addGroup(e.toString());
            }
          } else if (value instanceof SimpleName) {
            Object boundValue = value.resolveConstantExpressionValue();
            addGroup(boundValue.toString());
          } else if (value instanceof StringLiteral) {
            addGroup(value.toString());
          }
        }
      }
    } else if (isFactoryAnnotation(node.getTypeName().toString())) {
      if (node.getParent() instanceof MethodDeclaration) {
        m_annotationType = JDK15_ANNOTATION;
        addFactoryMethod((MethodDeclaration) node.getParent(), JDK15_ANNOTATION);
      }
    }

    return false;
  }
  public boolean visit(NormalAnnotation annotation) {
    if (!isKnownAnnotation(annotation.getTypeName().getFullyQualifiedName())) {
      return false;
    }

    List values = annotation.values();

    if (null != values && !values.isEmpty()) {
      for (int i = 0; i < values.size(); i++) {
        MemberValuePair pair = (MemberValuePair) values.get(i);
        if ("parameters".equals(pair.getName().toString())) {
          Expression paramAttr = pair.getValue();
          if (paramAttr instanceof ArrayInitializer) {
            record((MethodDeclaration) annotation.getParent(), (ArrayInitializer) paramAttr);
          }
        }
      }
    }

    return false;
  }