@Override
 public boolean visit(SingleMemberAnnotation node) {
   if (nestLevel != 1) return false;
   String typeFqn = node.resolveTypeBinding().getQualifiedName();
   if ("org.apache.ibatis.annotations.Select".equals(typeFqn)
       || "org.apache.ibatis.annotations.Update".equals(typeFqn)
       || "org.apache.ibatis.annotations.Insert".equals(typeFqn)
       || "org.apache.ibatis.annotations.Delete".equals(typeFqn)) {
     Expression value = node.getValue();
     int valueType = value.getNodeType();
     if (valueType == ASTNode.STRING_LITERAL) {
       mapperMethod.setStatement(((StringLiteral) value).getLiteralValue());
     } else if (valueType == ASTNode.ARRAY_INITIALIZER) {
       StringBuilder buffer = new StringBuilder();
       @SuppressWarnings("unchecked")
       List<Expression> expressions =
           (List<Expression>) ((ArrayInitializer) value).expressions();
       for (Expression expression : expressions) {
         int expressionType = expression.getNodeType();
         if (expressionType == ASTNode.STRING_LITERAL) {
           if (buffer.length() > 0) buffer.append(' ');
           buffer.append(((StringLiteral) expression).getLiteralValue());
         } else if (expressionType == ASTNode.INFIX_EXPRESSION) {
           buffer.append(parseInfixExpression((InfixExpression) expression));
         }
       }
       mapperMethod.setStatement(buffer.toString());
     } else if (valueType == ASTNode.INFIX_EXPRESSION) {
       mapperMethod.setStatement(parseInfixExpression((InfixExpression) value));
     }
   }
   return false;
 }
 /*
  * @see ASTVisitor#visit(SingleMemberAnnotation)
  * @since 3.0
  */
 public boolean visit(SingleMemberAnnotation node) {
   this.fBuffer.append("@"); // $NON-NLS-1$
   node.getTypeName().accept(this);
   this.fBuffer.append("("); // $NON-NLS-1$
   node.getValue().accept(this);
   this.fBuffer.append(")"); // $NON-NLS-1$
   return false;
 }
  /**
   * Only Parameters annotation can be used to describe the parameters.
   *
   * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SingleMemberAnnotation)
   */
  public boolean visit(SingleMemberAnnotation annotation) {
    if (isParameterAnnotation(annotation.getTypeName().getFullyQualifiedName())) {
      Expression paramValues = annotation.getValue();
      if (paramValues instanceof ArrayInitializer) {
        record((MethodDeclaration) annotation.getParent(), (ArrayInitializer) paramValues);
      }
    }

    return false;
  }
Exemplo n.º 4
0
 public static Expression obtainSingleMemberAnnotationValue(
     BodyDeclaration declaration, Class<?> annotationClass) {
   for (Object mod : declaration.modifiers()) {
     IExtendedModifier modifier = (IExtendedModifier) mod;
     if (modifier.isAnnotation()) {
       Annotation annotation = (Annotation) modifier;
       if (annotation.isSingleMemberAnnotation()
           && identicalAnnotations(annotation, annotationClass)) {
         SingleMemberAnnotation singleMemberAnnot = (SingleMemberAnnotation) annotation;
         return singleMemberAnnot.getValue();
       }
     }
   }
   return null;
 }
 /* (non-Javadoc)
  * @see org.eclipse.jdt.internal.corext.dom.GenericVisitor#visit(org.eclipse.jdt.core.dom.MarkerAnnotation)
  */
 @Override
 public boolean visit(SingleMemberAnnotation node) {
   typeRefFound(node.getTypeName());
   doVisitNode(node.getValue());
   return false;
 }