Esempio n. 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;
  }
Esempio n. 2
0
  public static Set<MethodSymbol> findSuperMethods(MethodSymbol methodSymbol, Types types) {
    Set<MethodSymbol> supers = new HashSet<>();
    if (methodSymbol.isStatic()) {
      return supers;
    }

    TypeSymbol owner = (TypeSymbol) methodSymbol.owner;
    // Iterates over an ordered list of all super classes and interfaces.
    for (Type sup : types.closure(owner.type)) {
      if (sup == owner.type) {
        continue; // Skip the owner of the method
      }
      Scope scope = sup.tsym.members();
      for (Symbol sym : scope.getSymbolsByName(methodSymbol.name)) {
        if (sym != null
            && !sym.isStatic()
            && ((sym.flags() & Flags.SYNTHETIC) == 0)
            && sym.name.contentEquals(methodSymbol.name)
            && methodSymbol.overrides(sym, owner, types, true)) {
          supers.add((MethodSymbol) sym);
        }
      }
    }
    return supers;
  }
Esempio n. 3
0
    @Override
    public boolean matches(ExpressionTree expressionTree, VisitorState state) {
      Symbol sym = ASTHelpers.getSymbol(expressionTree);
      if (sym != null && sym.getSimpleName().toString().startsWith("log")) {
        return true;
      }

      if (sym != null && sym.isStatic()) {
        if (sym.owner.getQualifiedName().toString().contains("Logger")) {
          return true;
        }
      } else if (expressionTree instanceof MemberSelectTree) {
        if (((MemberSelectTree) expressionTree).getExpression().toString().startsWith("log")) {
          return true;
        }
      }

      return false;
    }