예제 #1
0
  @Override
  public boolean matches(ExpressionTree expressionTree, VisitorState state) {
    Symbol sym = ASTHelpers.getSymbol(expressionTree);
    if (sym == null) {
      return false;
    }
    if (!(sym instanceof MethodSymbol)) {
      throw new IllegalArgumentException(
          "DescendantOf matcher expects a method call but found "
              + sym.getClass()
              + ". Expression: "
              + expressionTree);
    }
    if (sym.isStatic()) {
      return false;
    }

    if (methodName.equals(sym.toString())) {
      Type accessedReferenceType = sym.owner.type;
      Type collectionType = state.getTypeFromString(fullClassName);
      if (collectionType != null) {
        return state
            .getTypes()
            .isSubtype(accessedReferenceType, state.getTypes().erasure(collectionType));
      }
    }

    return false;
  }
예제 #2
0
  protected void printSymbol(String label, Symbol sym, Details details) {
    if (sym == null) {
      printNull(label);
    } else {
      switch (details) {
        case SUMMARY:
          printString(label, toString(sym));
          break;

        case FULL:
          indent();
          out.print(label);
          out.println(
              ": "
                  + info(
                      sym.getClass(),
                      String.format("0x%x--%s", sym.kind.ordinal(), Kinds.kindName(sym)),
                      sym.getKind())
                  + " "
                  + sym.name
                  + " "
                  + hashString(sym));

          indent(+1);
          if (showSrc) {
            JCTree tree = (JCTree) trees.getTree(sym);
            if (tree != null) printSource("src", tree);
          }
          printString(
              "flags", String.format("0x%x--%s", sym.flags_field, Flags.toString(sym.flags_field)));
          printObject("completer", sym.completer, Details.SUMMARY); // what if too long?
          printSymbol("owner", sym.owner, Details.SUMMARY);
          printType("type", sym.type, Details.SUMMARY);
          printType("erasure", sym.erasure_field, Details.SUMMARY);
          sym.accept(symVisitor, null);
          printAnnotations("annotations", sym.getMetadata(), Details.SUMMARY);
          indent(-1);
      }
    }
  }