< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java

Print this page




1152                     implicit = PUBLIC | ABSTRACT;
1153                 } else if ((flags & (DEFAULT | STATIC | PRIVATE)) != 0) {
1154                     mask = InterfaceMethodMask;
1155                     implicit = (flags & PRIVATE) != 0 ? 0 : PUBLIC;
1156                     if ((flags & DEFAULT) != 0) {
1157                         implicit |= ABSTRACT;
1158                     }
1159                 } else {
1160                     mask = implicit = InterfaceMethodFlags;
1161                 }
1162             } else {
1163                 mask = MethodFlags;
1164             }
1165             // Imply STRICTFP if owner has STRICTFP set.
1166             if (((flags|implicit) & Flags.ABSTRACT) == 0 ||
1167                 ((flags) & Flags.DEFAULT) != 0)
1168                 implicit |= sym.owner.flags_field & STRICTFP;
1169             break;
1170         case TYP:
1171             if (sym.isLocal()) {
1172                 mask = LocalClassFlags;
1173                 if ((sym.owner.flags_field & STATIC) == 0 &&
1174                     (flags & ENUM) != 0)
1175                     log.error(pos, Errors.EnumsMustBeStatic);




1176             } else if (sym.owner.kind == TYP) {
1177                 mask = MemberClassFlags;
1178                 if (sym.owner.owner.kind == PCK ||
1179                     (sym.owner.flags_field & STATIC) != 0)
1180                     mask |= STATIC;
1181                 else if ((flags & ENUM) != 0)
1182                     log.error(pos, Errors.EnumsMustBeStatic);

1183                 // Nested interfaces and enums are always STATIC (Spec ???)
1184                 if ((flags & (INTERFACE | ENUM)) != 0 ) implicit = STATIC;
1185             } else {
1186                 mask = ClassFlags;
1187             }
1188             // Interfaces are always ABSTRACT
1189             if ((flags & INTERFACE) != 0) implicit |= ABSTRACT;
1190 
1191             if ((flags & ENUM) != 0) {
1192                 // enums can't be declared abstract or final
1193                 mask &= ~(ABSTRACT | FINAL);
1194                 implicit |= implicitEnumFinalFlag(tree);
1195             }




1196             // Imply STRICTFP if owner has STRICTFP set.
1197             implicit |= sym.owner.flags_field & STRICTFP;
1198             break;
1199         default:
1200             throw new AssertionError();
1201         }
1202         long illegal = flags & ExtendedStandardFlags & ~mask;
1203         if (illegal != 0) {
1204             if ((illegal & INTERFACE) != 0) {
1205                 log.error(pos, ((flags & ANNOTATION) != 0) ? Errors.AnnotationDeclNotAllowedHere : Errors.IntfNotAllowedHere);
1206                 mask |= INTERFACE;
1207             }
1208             else {
1209                 log.error(pos,
1210                           Errors.ModNotAllowedHere(asFlagSet(illegal)));
1211             }
1212         }
1213         else if ((sym.kind == TYP ||
1214                   // ISSUE: Disallowing abstract&private is no longer appropriate
1215                   // in the presence of inner classes. Should it be deleted here?


3091             for (int i=0; i<arr.values.length; ++i) {
3092                 Attribute app = arr.values[i];
3093                 if (!(app instanceof Attribute.Enum)) {
3094                     return true; // recovery
3095                 }
3096                 Attribute.Enum e = (Attribute.Enum) app;
3097                 targets[i] = e.value.name;
3098             }
3099         }
3100         for (Name target : targets) {
3101             if (target == names.TYPE) {
3102                 if (s.kind == TYP)
3103                     return true;
3104             } else if (target == names.FIELD) {
3105                 if (s.kind == VAR && s.owner.kind != MTH)
3106                     return true;
3107             } else if (target == names.METHOD) {
3108                 if (s.kind == MTH && !s.isConstructor())
3109                     return true;
3110             } else if (target == names.PARAMETER) {
3111                 if (s.kind == VAR && s.owner.kind == MTH &&
3112                       (s.flags() & PARAMETER) != 0) {

3113                     return true;
3114                 }
3115             } else if (target == names.CONSTRUCTOR) {
3116                 if (s.kind == MTH && s.isConstructor())
3117                     return true;
3118             } else if (target == names.LOCAL_VARIABLE) {
3119                 if (s.kind == VAR && s.owner.kind == MTH &&
3120                       (s.flags() & PARAMETER) == 0) {
3121                     return true;
3122                 }
3123             } else if (target == names.ANNOTATION_TYPE) {
3124                 if (s.kind == TYP && (s.flags() & ANNOTATION) != 0) {
3125                     return true;
3126                 }
3127             } else if (target == names.PACKAGE) {
3128                 if (s.kind == PCK)
3129                     return true;
3130             } else if (target == names.TYPE_USE) {
3131                 if (s.kind == VAR && s.owner.kind == MTH && s.type.hasTag(NONE)) {
3132                     //cannot type annotate implictly typed locals




1152                     implicit = PUBLIC | ABSTRACT;
1153                 } else if ((flags & (DEFAULT | STATIC | PRIVATE)) != 0) {
1154                     mask = InterfaceMethodMask;
1155                     implicit = (flags & PRIVATE) != 0 ? 0 : PUBLIC;
1156                     if ((flags & DEFAULT) != 0) {
1157                         implicit |= ABSTRACT;
1158                     }
1159                 } else {
1160                     mask = implicit = InterfaceMethodFlags;
1161                 }
1162             } else {
1163                 mask = MethodFlags;
1164             }
1165             // Imply STRICTFP if owner has STRICTFP set.
1166             if (((flags|implicit) & Flags.ABSTRACT) == 0 ||
1167                 ((flags) & Flags.DEFAULT) != 0)
1168                 implicit |= sym.owner.flags_field & STRICTFP;
1169             break;
1170         case TYP:
1171             if (sym.isLocal()) {
1172                 mask = (flags & RECORD) != 0 ? LocalRecordFlags : LocalClassFlags;
1173                 if ((sym.owner.flags_field & STATIC) == 0 &&
1174                     (flags & ENUM) != 0) {
1175                     log.error(pos, Errors.EnumsMustBeStatic);
1176                 }
1177                 if ((flags & RECORD) != 0 && (flags & STATIC) == 0) {
1178                     log.error(pos, Errors.NestedRecordsMustBeStatic);
1179                 }
1180             } else if (sym.owner.kind == TYP) {
1181                 mask = (flags & RECORD) != 0 ? MemberRecordClassFlags : MemberClassFlags;
1182                 if (sym.owner.owner.kind == PCK ||
1183                     (sym.owner.flags_field & STATIC) != 0)
1184                     mask |= STATIC;
1185                 else if ((flags & ENUM) != 0) {
1186                     log.error(pos, Errors.EnumsMustBeStatic);
1187                 }
1188                 // Nested interfaces and enums are always STATIC (Spec ???)
1189                 if ((flags & (INTERFACE | ENUM)) != 0 ) implicit = STATIC;
1190             } else {
1191                 mask = ClassFlags;
1192             }
1193             // Interfaces are always ABSTRACT
1194             if ((flags & INTERFACE) != 0) implicit |= ABSTRACT;
1195 
1196             if ((flags & ENUM) != 0) {
1197                 // enums can't be declared abstract or final
1198                 mask &= ~(ABSTRACT | FINAL);
1199                 implicit |= implicitEnumFinalFlag(tree);
1200             }
1201             if ((flags & RECORD) != 0) {
1202                 // records can't be declared abstract
1203                 mask &= ~ABSTRACT;
1204             }
1205             // Imply STRICTFP if owner has STRICTFP set.
1206             implicit |= sym.owner.flags_field & STRICTFP;
1207             break;
1208         default:
1209             throw new AssertionError();
1210         }
1211         long illegal = flags & ExtendedStandardFlags & ~mask;
1212         if (illegal != 0) {
1213             if ((illegal & INTERFACE) != 0) {
1214                 log.error(pos, ((flags & ANNOTATION) != 0) ? Errors.AnnotationDeclNotAllowedHere : Errors.IntfNotAllowedHere);
1215                 mask |= INTERFACE;
1216             }
1217             else {
1218                 log.error(pos,
1219                           Errors.ModNotAllowedHere(asFlagSet(illegal)));
1220             }
1221         }
1222         else if ((sym.kind == TYP ||
1223                   // ISSUE: Disallowing abstract&private is no longer appropriate
1224                   // in the presence of inner classes. Should it be deleted here?


3100             for (int i=0; i<arr.values.length; ++i) {
3101                 Attribute app = arr.values[i];
3102                 if (!(app instanceof Attribute.Enum)) {
3103                     return true; // recovery
3104                 }
3105                 Attribute.Enum e = (Attribute.Enum) app;
3106                 targets[i] = e.value.name;
3107             }
3108         }
3109         for (Name target : targets) {
3110             if (target == names.TYPE) {
3111                 if (s.kind == TYP)
3112                     return true;
3113             } else if (target == names.FIELD) {
3114                 if (s.kind == VAR && s.owner.kind != MTH)
3115                     return true;
3116             } else if (target == names.METHOD) {
3117                 if (s.kind == MTH && !s.isConstructor())
3118                     return true;
3119             } else if (target == names.PARAMETER) {
3120                 if (s.kind == VAR &&
3121                     (s.owner.kind == MTH && (s.flags() & PARAMETER) != 0) ||
3122                     (s.owner.kind == TYP && s.owner.isRecord())) {
3123                     return true;
3124                 }
3125             } else if (target == names.CONSTRUCTOR) {
3126                 if (s.kind == MTH && s.isConstructor())
3127                     return true;
3128             } else if (target == names.LOCAL_VARIABLE) {
3129                 if (s.kind == VAR && s.owner.kind == MTH &&
3130                       (s.flags() & PARAMETER) == 0) {
3131                     return true;
3132                 }
3133             } else if (target == names.ANNOTATION_TYPE) {
3134                 if (s.kind == TYP && (s.flags() & ANNOTATION) != 0) {
3135                     return true;
3136                 }
3137             } else if (target == names.PACKAGE) {
3138                 if (s.kind == PCK)
3139                     return true;
3140             } else if (target == names.TYPE_USE) {
3141                 if (s.kind == VAR && s.owner.kind == MTH && s.type.hasTag(NONE)) {
3142                     //cannot type annotate implictly typed locals


< prev index next >