예제 #1
0
 /**
  * Find a method in the enclosing class's superclass that this method overrides.
  *
  * @return A superclass method that is overridden by {@code method}
  */
 public static MethodSymbol findSuperMethod(MethodSymbol method, Types types) {
   TypeSymbol superClass = method.enclClass().getSuperclass().tsym;
   if (superClass == null) {
     return null;
   }
   for (Symbol sym : superClass.members().getSymbols()) {
     if (sym.name.contentEquals(method.name) && method.overrides(sym, superClass, types, true)) {
       return (MethodSymbol) sym;
     }
   }
   return null;
 }
예제 #2
0
 /** @return all values of the given enum type, in declaration order. */
 public static LinkedHashSet<String> enumValues(TypeSymbol enumType) {
   if (enumType.getKind() != ElementKind.ENUM) {
     throw new IllegalStateException();
   }
   Scope scope = enumType.members();
   Deque<String> values = new ArrayDeque<>();
   for (Symbol sym : scope.getSymbols()) {
     if (sym instanceof VarSymbol) {
       VarSymbol var = (VarSymbol) sym;
       if ((var.flags() & Flags.ENUM) != 0) {
         /**
          * Javac gives us the members backwards, apparently. It's worth making an effort to
          * preserve declaration order because it's useful for diagnostics (e.g. in {@link
          * MissingCasesInEnumSwitch}).
          */
         values.push(sym.name.toString());
       }
     }
   }
   return new LinkedHashSet<>(values);
 }