コード例 #1
0
  @SuppressWarnings("rawtypes") // DOM AST API returns raw collections
  public SourcePosition getPosition() {
    final MirrorKind kind = _parent.kind();
    ASTNode astNode = null;
    switch (kind) {
      case ANNOTATION_MIRROR:
        final AnnotationMirrorImpl anno = (AnnotationMirrorImpl) _parent;
        astNode = anno.getASTNodeForElement(_name);
        break;
      case ANNOTATION_ELEMENT:
        final AnnotationElementDeclarationImpl element = (AnnotationElementDeclarationImpl) _parent;
        astNode = element.getAstNodeForDefault();
        break;
      default:
        throw new IllegalStateException(); // should never reach this point.
    }
    // did not come from source.
    if (astNode == null) return null;
    if (_index >= 0 && astNode.getNodeType() == ASTNode.ARRAY_INITIALIZER) {
      final ArrayInitializer arrayInit = (ArrayInitializer) astNode;
      final List exprs = arrayInit.expressions();
      if (exprs != null && _index < exprs.size()) astNode = (ASTNode) exprs.get(_index);
    }
    if (astNode == null) return null;

    final CompilationUnit unit = getCompilationUnit();
    if (unit == null) return null;
    final int offset = astNode.getStartPosition();
    return new SourcePositionImpl(
        astNode.getStartPosition(),
        astNode.getLength(),
        unit.getLineNumber(offset),
        unit.getColumnNumber(offset),
        this);
  }
コード例 #2
0
ファイル: ASTBuilder.java プロジェクト: nboldi/markfactory
 @SuppressWarnings("unchecked")
 public ArrayCreation newArrayCreation(Type type, Collection<Expression> values) {
   ArrayCreation ac = ast.newArrayCreation();
   ArrayInitializer initializer = ast.newArrayInitializer();
   for (Expression expr : values) {
     initializer.expressions().add(expr);
   }
   ac.setInitializer(initializer);
   ac.setType(ast.newArrayType(type));
   return ac;
 }
コード例 #3
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;
  }
コード例 #4
0
  /**
   * @param method the known TestNG annotation with required parameters
   * @param values array initializer containing StringLiterals for the parameter names
   */
  protected void record(MethodDeclaration method, ArrayInitializer values) {
    List literals = values.expressions();
    List paramNames = new ArrayList(literals.size());
    for (int i = 0; i < literals.size(); i++) {
      StringLiteral str = (StringLiteral) literals.get(i);
      paramNames.add(str.getLiteralValue());
    }

    m_parameters.put(method, paramNames);
  }
コード例 #5
0
 /* (non-Javadoc)
  * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ArrayInitializer)
  */
 public boolean visit(ArrayInitializer node) {
   PTArrayInitializer ai = InstantiationFactory.eINSTANCE.createPTArrayInitializer();
   List exps = node.expressions();
   List aiexps = ai.getExpressions();
   int nexp = exps.size();
   for (int i = 0; i < nexp; i++) {
     aiexps.add(perform((Expression) exps.get(i)));
   }
   expression = ai;
   return false;
 }
コード例 #6
0
 public void endVisit(ArrayInitializer node) {
   Stack<VMExpression> arguments = new Stack<VMExpression>();
   for (int i = 0; i < node.expressions().size(); i++) {
     arguments.push((VMExpression) expressions.pop());
   }
   VMArrayInitializer initializer = new VMArrayInitializer(node);
   while (!arguments.empty()) {
     initializer.getExpressions().add(arguments.pop());
   }
   expressions.push(initializer);
 }
コード例 #7
0
 /*
  * @see ASTVisitor#visit(ArrayInitializer)
  */
 public boolean visit(ArrayInitializer node) {
   this.fBuffer.append("{"); // $NON-NLS-1$
   for (Iterator it = node.expressions().iterator(); it.hasNext(); ) {
     Expression e = (Expression) it.next();
     e.accept(this);
     if (it.hasNext()) {
       this.fBuffer.append(","); // $NON-NLS-1$
     }
   }
   this.fBuffer.append("}"); // $NON-NLS-1$
   return false;
 }