/*
  * @see ASTVisitor#visit(MemberValuePair)
  * @since 3.0
  */
 @Override
 public boolean visit(MemberValuePair node) {
   node.getName().accept(this);
   this.fBuffer.append("="); // $NON-NLS-1$
   node.getValue().accept(this);
   return false;
 }
示例#2
0
 public void visit(NormalAnnotationExpr n, Object arg) {
   n.getName().accept(this, arg);
   for (Iterator<MemberValuePair> i = n.getPairs().iterator(); i.hasNext(); ) {
     MemberValuePair m = i.next();
     m.accept(this, arg);
     if (i.hasNext()) {}
   }
 }
  private IAnnotation getAnnotation(
      final org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation annotation,
      JavaElement parentElement) {
    final int typeStart = annotation.type.sourceStart();
    final int typeEnd = annotation.type.sourceEnd();
    final int sourceStart = annotation.sourceStart();
    final int sourceEnd = annotation.declarationSourceEnd;
    class LocalVarAnnotation extends Annotation {
      IMemberValuePair[] memberValuePairs;

      public LocalVarAnnotation(JavaElement localVar, String elementName) {
        super(localVar, elementName);
      }

      public IMemberValuePair[] getMemberValuePairs() throws JavaModelException {
        return this.memberValuePairs;
      }

      public ISourceRange getNameRange() throws JavaModelException {
        return new SourceRange(typeStart, typeEnd - typeStart + 1);
      }

      public ISourceRange getSourceRange() throws JavaModelException {
        return new SourceRange(sourceStart, sourceEnd - sourceStart + 1);
      }

      public boolean exists() {
        return this.parent.exists();
      }
    }
    String annotationName =
        new String(CharOperation.concatWith(annotation.type.getTypeName(), '.'));
    LocalVarAnnotation localVarAnnotation = new LocalVarAnnotation(parentElement, annotationName);
    org.aspectj.org.eclipse.jdt.internal.compiler.ast.MemberValuePair[] astMemberValuePairs =
        annotation.memberValuePairs();
    int length;
    IMemberValuePair[] memberValuePairs;
    if (astMemberValuePairs == null || (length = astMemberValuePairs.length) == 0) {
      memberValuePairs = Annotation.NO_MEMBER_VALUE_PAIRS;
    } else {
      memberValuePairs = new IMemberValuePair[length];
      for (int i = 0; i < length; i++) {
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.MemberValuePair astMemberValuePair =
            astMemberValuePairs[i];
        MemberValuePair memberValuePair = new MemberValuePair(new String(astMemberValuePair.name));
        memberValuePair.value =
            getAnnotationMemberValue(memberValuePair, astMemberValuePair.value, localVarAnnotation);
        memberValuePairs[i] = memberValuePair;
      }
    }
    localVarAnnotation.memberValuePairs = memberValuePairs;
    return localVarAnnotation;
  }
示例#4
0
  @Override
  public Boolean visit(final MemberValuePair n1, final Node arg) {
    final MemberValuePair n2 = (MemberValuePair) arg;

    if (!objEquals(n1.getName(), n2.getName())) {
      return Boolean.FALSE;
    }

    if (!nodeEquals(n1.getValue(), n2.getValue())) {
      return Boolean.FALSE;
    }

    return Boolean.TRUE;
  }
 /*
  * @see ASTVisitor#visit(NormalAnnotation)
  * @since 3.0
  */
 @Override
 public boolean visit(NormalAnnotation node) {
   this.fBuffer.append("@"); // $NON-NLS-1$
   node.getTypeName().accept(this);
   this.fBuffer.append("("); // $NON-NLS-1$
   for (Iterator<MemberValuePair> it = node.values().iterator(); it.hasNext(); ) {
     MemberValuePair p = it.next();
     p.accept(this);
     if (it.hasNext()) {
       this.fBuffer.append(","); // $NON-NLS-1$
     }
   }
   this.fBuffer.append(")"); // $NON-NLS-1$
   return false;
 }
示例#6
0
 public void visit(MemberValuePair n, Object arg) {
   n.getValue().accept(this, arg);
 }
 /*
  * Creates the value wrapper from the given expression, and sets the valueKind on the given memberValuePair
  */
 private Object getAnnotationMemberValue(
     MemberValuePair memberValuePair, Expression expression, JavaElement parentElement) {
   if (expression instanceof NullLiteral) {
     return null;
   } else if (expression instanceof Literal) {
     ((Literal) expression).computeConstant();
     return Util.getAnnotationMemberValue(memberValuePair, expression.constant);
   } else if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation) {
     memberValuePair.valueKind = IMemberValuePair.K_ANNOTATION;
     return getAnnotation(
         (org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation) expression, parentElement);
   } else if (expression instanceof ClassLiteralAccess) {
     ClassLiteralAccess classLiteral = (ClassLiteralAccess) expression;
     char[] typeName = CharOperation.concatWith(classLiteral.type.getTypeName(), '.');
     memberValuePair.valueKind = IMemberValuePair.K_CLASS;
     return new String(typeName);
   } else if (expression instanceof QualifiedNameReference) {
     char[] qualifiedName =
         CharOperation.concatWith(((QualifiedNameReference) expression).tokens, '.');
     memberValuePair.valueKind = IMemberValuePair.K_QUALIFIED_NAME;
     return new String(qualifiedName);
   } else if (expression instanceof SingleNameReference) {
     char[] simpleName = ((SingleNameReference) expression).token;
     if (simpleName == RecoveryScanner.FAKE_IDENTIFIER) {
       memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
       return null;
     }
     memberValuePair.valueKind = IMemberValuePair.K_SIMPLE_NAME;
     return new String(simpleName);
   } else if (expression instanceof ArrayInitializer) {
     memberValuePair.valueKind = -1; // modified below by the first call to getMemberValue(...)
     Expression[] expressions = ((ArrayInitializer) expression).expressions;
     int length = expressions == null ? 0 : expressions.length;
     Object[] values = new Object[length];
     for (int i = 0; i < length; i++) {
       int previousValueKind = memberValuePair.valueKind;
       Object value = getAnnotationMemberValue(memberValuePair, expressions[i], parentElement);
       if (previousValueKind != -1 && memberValuePair.valueKind != previousValueKind) {
         // values are heterogeneous, value kind is thus unknown
         memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
       }
       values[i] = value;
     }
     if (memberValuePair.valueKind == -1) memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
     return values;
   } else if (expression
       instanceof UnaryExpression) { // to deal with negative numerals (see bug - 248312)
     UnaryExpression unaryExpression = (UnaryExpression) expression;
     if ((unaryExpression.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT
         == OperatorIds.MINUS) {
       if (unaryExpression.expression instanceof Literal) {
         Literal subExpression = (Literal) unaryExpression.expression;
         subExpression.computeConstant();
         return Util.getNegativeAnnotationMemberValue(memberValuePair, subExpression.constant);
       }
     }
     memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
     return null;
   } else {
     memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
     return null;
   }
 }