langtools/src/share/classes/com/sun/tools/javac/comp/Check.java
changeset 939 38e24969c7e9
parent 938 13aae74ca013
child 1040 c0f5acfd9d15
equal deleted inserted replaced
938:13aae74ca013 939:38e24969c7e9
   574      */
   574      */
   575     boolean checkDisjoint(DiagnosticPosition pos, long flags, long set1, long set2) {
   575     boolean checkDisjoint(DiagnosticPosition pos, long flags, long set1, long set2) {
   576         if ((flags & set1) != 0 && (flags & set2) != 0) {
   576         if ((flags & set1) != 0 && (flags & set2) != 0) {
   577             log.error(pos,
   577             log.error(pos,
   578                       "illegal.combination.of.modifiers",
   578                       "illegal.combination.of.modifiers",
   579                       TreeInfo.flagNames(TreeInfo.firstFlag(flags & set1)),
   579                       asFlagSet(TreeInfo.firstFlag(flags & set1)),
   580                       TreeInfo.flagNames(TreeInfo.firstFlag(flags & set2)));
   580                       asFlagSet(TreeInfo.firstFlag(flags & set2)));
   581             return false;
   581             return false;
   582         } else
   582         } else
   583             return true;
   583             return true;
   584     }
   584     }
   585 
   585 
   668                 log.error(pos, "intf.not.allowed.here");
   668                 log.error(pos, "intf.not.allowed.here");
   669                 mask |= INTERFACE;
   669                 mask |= INTERFACE;
   670             }
   670             }
   671             else {
   671             else {
   672                 log.error(pos,
   672                 log.error(pos,
   673                           "mod.not.allowed.here", TreeInfo.flagNames(illegal));
   673                           "mod.not.allowed.here", asFlagSet(illegal));
   674             }
   674             }
   675         }
   675         }
   676         else if ((sym.kind == TYP ||
   676         else if ((sym.kind == TYP ||
   677                   // ISSUE: Disallowing abstract&private is no longer appropriate
   677                   // ISSUE: Disallowing abstract&private is no longer appropriate
   678                   // in the presence of inner classes. Should it be deleted here?
   678                   // in the presence of inner classes. Should it be deleted here?
  1021         case PUBLIC: return 0;
  1021         case PUBLIC: return 0;
  1022         case 0: return 2;
  1022         case 0: return 2;
  1023         }
  1023         }
  1024     }
  1024     }
  1025 
  1025 
  1026     /** A string describing the access permission given by a flag set.
       
  1027      *  This always returns a space-separated list of Java Keywords.
       
  1028      */
       
  1029     private static String protectionString(long flags) {
       
  1030         long flags1 = flags & AccessFlags;
       
  1031         return (flags1 == 0) ? "package" : TreeInfo.flagNames(flags1);
       
  1032     }
       
  1033 
       
  1034     /** A customized "cannot override" error message.
  1026     /** A customized "cannot override" error message.
  1035      *  @param m      The overriding method.
  1027      *  @param m      The overriding method.
  1036      *  @param other  The overridden method.
  1028      *  @param other  The overridden method.
  1037      *  @return       An internationalized string.
  1029      *  @return       An internationalized string.
  1038      */
  1030      */
  1122         if ((other.flags() & FINAL) != 0 ||
  1114         if ((other.flags() & FINAL) != 0 ||
  1123                  (m.flags() & STATIC) == 0 &&
  1115                  (m.flags() & STATIC) == 0 &&
  1124                  (other.flags() & STATIC) != 0) {
  1116                  (other.flags() & STATIC) != 0) {
  1125             log.error(TreeInfo.diagnosticPositionFor(m, tree), "override.meth",
  1117             log.error(TreeInfo.diagnosticPositionFor(m, tree), "override.meth",
  1126                       cannotOverride(m, other),
  1118                       cannotOverride(m, other),
  1127                       TreeInfo.flagNames(other.flags() & (FINAL | STATIC)));
  1119                       asFlagSet(other.flags() & (FINAL | STATIC)));
  1128             return;
  1120             return;
  1129         }
  1121         }
  1130 
  1122 
  1131         if ((m.owner.flags() & ANNOTATION) != 0) {
  1123         if ((m.owner.flags() & ANNOTATION) != 0) {
  1132             // handled in validateAnnotationMethod
  1124             // handled in validateAnnotationMethod
  1136         // Error if overriding method has weaker access (JLS 8.4.6.3).
  1128         // Error if overriding method has weaker access (JLS 8.4.6.3).
  1137         if ((origin.flags() & INTERFACE) == 0 &&
  1129         if ((origin.flags() & INTERFACE) == 0 &&
  1138                  protection(m.flags()) > protection(other.flags())) {
  1130                  protection(m.flags()) > protection(other.flags())) {
  1139             log.error(TreeInfo.diagnosticPositionFor(m, tree), "override.weaker.access",
  1131             log.error(TreeInfo.diagnosticPositionFor(m, tree), "override.weaker.access",
  1140                       cannotOverride(m, other),
  1132                       cannotOverride(m, other),
  1141                       protectionString(other.flags()));
  1133                       other.flags() == 0 ?
       
  1134                           Flag.PACKAGE :
       
  1135                           asFlagSet(other.flags() & AccessFlags));
  1142             return;
  1136             return;
  1143 
       
  1144         }
  1137         }
  1145 
  1138 
  1146         Type mt = types.memberType(origin.type, m);
  1139         Type mt = types.memberType(origin.type, m);
  1147         Type ot = types.memberType(origin.type, other);
  1140         Type ot = types.memberType(origin.type, other);
  1148         // Error if overriding result type is different
  1141         // Error if overriding result type is different
  2033                        Type right) {
  2026                        Type right) {
  2034         if (operator.opcode == ByteCodes.error) {
  2027         if (operator.opcode == ByteCodes.error) {
  2035             log.error(pos,
  2028             log.error(pos,
  2036                       "operator.cant.be.applied",
  2029                       "operator.cant.be.applied",
  2037                       treeinfo.operatorName(tag),
  2030                       treeinfo.operatorName(tag),
  2038                       left + "," + right);
  2031                       List.of(left, right));
  2039         }
  2032         }
  2040         return operator.opcode;
  2033         return operator.opcode;
  2041     }
  2034     }
  2042 
  2035 
  2043 
  2036