Esempio n. 1
0
    @Override
    public boolean matches(TryTree tryTree, VisitorState state) {
      MethodTree enclosingMethodTree =
          ASTHelpers.findEnclosingNode(state.getPath(), MethodTree.class);

      Name name = enclosingMethodTree.getName();
      return JUnitMatchers.looksLikeJUnit3SetUp.matches(enclosingMethodTree, state)
          || JUnitMatchers.looksLikeJUnit3TearDown.matches(enclosingMethodTree, state)
          || name.contentEquals("main")
          // TODO(schmitt): Move to JUnitMatchers?
          || name.contentEquals("suite")
          || Matchers.hasAnnotation(JUNIT_BEFORE_ANNOTATION).matches(enclosingMethodTree, state)
          || Matchers.hasAnnotation(JUNIT_AFTER_ANNOTATION).matches(enclosingMethodTree, state);
    }
Esempio n. 2
0
 @Override
 public Tree getCode() {
   return method.getBody();
 }
  private static List<? extends TypeMirror> computeMethod(
      Set<ElementKind> types,
      CompilationInfo info,
      TreePath parent,
      TypeMirror[] typeParameterBound,
      Tree error,
      int offset) {
    // class or field:
    // check the error is in the body:
    // #92419: check for abstract method/method without body:
    MethodTree mt = (MethodTree) parent.getLeaf();

    if (mt.getReturnType() == error) {
      types.add(ElementKind.CLASS);
      types.add(ElementKind.INTERFACE);
      types.add(ElementKind.ENUM);
    }

    List<? extends ExpressionTree> throwList = mt.getThrows();
    if (throwList != null && !throwList.isEmpty()) {
      for (ExpressionTree t : throwList) {
        if (t == error) {
          types.add(ElementKind.CLASS);
          typeParameterBound[0] = info.getElements().getTypeElement("java.lang.Exception").asType();
          break;
        }
      }
    }

    if (mt.getBody() == null) {
      return null;
    }

    try {
      Document doc = info.getDocument();

      if (doc != null) { // XXX
        int bodyStart =
            Utilities.findBodyStart(
                parent.getLeaf(),
                info.getCompilationUnit(),
                info.getTrees().getSourcePositions(),
                doc);
        int bodyEnd =
            (int)
                info.getTrees()
                    .getSourcePositions()
                    .getEndPosition(info.getCompilationUnit(), parent.getLeaf());

        types.add(ElementKind.PARAMETER);
        types.add(ElementKind.LOCAL_VARIABLE);
        types.add(ElementKind.FIELD);

        if (bodyStart <= offset && offset <= bodyEnd)
          return Collections.singletonList(
              info.getElements().getTypeElement("java.lang.Object").asType());
      }
    } catch (IOException ex) {
      Logger.getLogger("global").log(Level.INFO, ex.getMessage(), ex);
    }

    return null;
  }
Esempio n. 4
0
 @Override
 public String toString() {
   return String.format(
       "method %s (%s) / class %s (%s)",
       (mt != null ? mt.getName() : "null"), mrt, (ct != null ? ct.getSimpleName() : "null"), act);
 }