예제 #1
0
 /** Is symbol inherited in given class? */
 @VisibleForTesting
 static boolean isInheritedIn(JavaSymbol symbol, JavaSymbol.TypeJavaSymbol clazz) {
   switch (symbol.flags() & Flags.ACCESS_FLAGS) {
     case Flags.PUBLIC:
       return true;
     case Flags.PRIVATE:
       return symbol.owner() == clazz;
     case Flags.PROTECTED:
       // TODO see Javac
       return true;
     case 0:
       // TODO see Javac
       JavaSymbol.PackageJavaSymbol thisPackage = symbol.packge();
       for (JavaSymbol.TypeJavaSymbol sup = clazz;
           sup != null && sup != symbol.owner();
           sup = superclassSymbol(sup)) {
         if (sup.packge() != thisPackage) {
           return false;
         }
       }
       return true;
     default:
       throw new IllegalStateException();
   }
 }
예제 #2
0
 /** Is class accessible in given environment? */
 @VisibleForTesting
 static boolean isAccessible(Env env, JavaSymbol.TypeJavaSymbol c) {
   final boolean result;
   switch (c.flags() & Flags.ACCESS_FLAGS) {
     case Flags.PRIVATE:
       result = sameOutermostClass(env.enclosingClass, c.owner());
       break;
     case 0:
       result = env.packge == c.packge();
       break;
     case Flags.PUBLIC:
       result = true;
       break;
     case Flags.PROTECTED:
       result = env.packge == c.packge() || isInnerSubClass(env.enclosingClass, c.owner());
       break;
     default:
       throw new IllegalStateException();
   }
   // TODO check accessibility of enclosing type: isAccessible(env, c.type.getEnclosingType())
   return result;
 }