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;
  }
Exemplo n.º 2
0
 @Override
 public Tree getCode() {
   return method.getBody();
 }