< prev index next >

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

Print this page

        

*** 92,101 **** --- 92,102 ---- private final JavaFileManager fileManager; private final Source source; private final Target target; private final Profile profile; private final boolean warnOnAnyAccessToMembers; + private final boolean debug; // The set of lint options currently in effect. It is initialized // from the context, and then is set/reset as needed by Attr as it // visits all the various parts of the trees during attribution. private Lint lint;
*** 153,162 **** --- 154,164 ---- enforceMandatoryWarnings, "unchecked", LintCategory.UNCHECKED); sunApiHandler = new MandatoryWarningHandler(log, false, enforceMandatoryWarnings, "sunapi", null); deferredLintHandler = DeferredLintHandler.instance(context); + debug = options.isSet("debug"); } /** Character for synthetic names */ char syntheticNameChar;
*** 1135,1144 **** --- 1137,1149 ---- mask = implicit = InterfaceVarFlags; else mask = VarFlags; break; case MTH: + if (debug) { + System.out.println("checking method with flags " + Flags.toString(flags)); + } if (sym.name == names.init) { if ((sym.owner.flags_field & ENUM) != 0) { // enum constructors cannot be declared public or // protected and must be implicitly or explicitly // private
*** 1166,1207 **** if (((flags|implicit) & Flags.ABSTRACT) == 0 || ((flags) & Flags.DEFAULT) != 0) implicit |= sym.owner.flags_field & STRICTFP; break; case TYP: if (sym.isLocal()) { ! mask = LocalClassFlags; if ((sym.owner.flags_field & STATIC) == 0 && ! (flags & ENUM) != 0) log.error(pos, Errors.EnumsMustBeStatic); } else if (sym.owner.kind == TYP) { ! mask = MemberClassFlags; if (sym.owner.owner.kind == PCK || (sym.owner.flags_field & STATIC) != 0) mask |= STATIC; ! else if ((flags & ENUM) != 0) log.error(pos, Errors.EnumsMustBeStatic); // Nested interfaces and enums are always STATIC (Spec ???) if ((flags & (INTERFACE | ENUM)) != 0 ) implicit = STATIC; } else { ! mask = ClassFlags; } // Interfaces are always ABSTRACT if ((flags & INTERFACE) != 0) implicit |= ABSTRACT; if ((flags & ENUM) != 0) { // enums can't be declared abstract or final mask &= ~(ABSTRACT | FINAL); implicit |= implicitEnumFinalFlag(tree); } // Imply STRICTFP if owner has STRICTFP set. implicit |= sym.owner.flags_field & STRICTFP; break; default: throw new AssertionError(); } long illegal = flags & ExtendedStandardFlags & ~mask; if (illegal != 0) { if ((illegal & INTERFACE) != 0) { log.error(pos, ((flags & ANNOTATION) != 0) ? Errors.AnnotationDeclNotAllowedHere : Errors.IntfNotAllowedHere); mask |= INTERFACE; } --- 1171,1227 ---- if (((flags|implicit) & Flags.ABSTRACT) == 0 || ((flags) & Flags.DEFAULT) != 0) implicit |= sym.owner.flags_field & STRICTFP; break; case TYP: + if (debug) { + System.out.println("checking type with flags " + Flags.toString(flags)); + } if (sym.isLocal()) { ! mask = (flags & RECORD) != 0 ? LocalRecordFlags : ExtendedLocalClassFlags; if ((sym.owner.flags_field & STATIC) == 0 && ! (flags & ENUM) != 0) { log.error(pos, Errors.EnumsMustBeStatic); + } + if ((flags & RECORD) != 0 && (flags & STATIC) == 0) { + log.error(pos, Errors.NestedRecordsMustBeStatic); + } } else if (sym.owner.kind == TYP) { ! mask = (flags & RECORD) != 0 ? ExtendedMemberRecordClassFlags : ExtendedMemberClassFlags; if (sym.owner.owner.kind == PCK || (sym.owner.flags_field & STATIC) != 0) mask |= STATIC; ! else if ((flags & ENUM) != 0) { log.error(pos, Errors.EnumsMustBeStatic); + } // Nested interfaces and enums are always STATIC (Spec ???) if ((flags & (INTERFACE | ENUM)) != 0 ) implicit = STATIC; } else { ! mask = ExtendedClassFlags; } // Interfaces are always ABSTRACT if ((flags & INTERFACE) != 0) implicit |= ABSTRACT; if ((flags & ENUM) != 0) { // enums can't be declared abstract or final mask &= ~(ABSTRACT | FINAL); implicit |= implicitEnumFinalFlag(tree); } + if ((flags & RECORD) != 0) { + // records can't be declared abstract + mask &= ~ABSTRACT; + } // Imply STRICTFP if owner has STRICTFP set. implicit |= sym.owner.flags_field & STRICTFP; break; default: throw new AssertionError(); } long illegal = flags & ExtendedStandardFlags & ~mask; + if (debug) { + System.out.println("illegal flags: " + Flags.toString(illegal)); + } if (illegal != 0) { if ((illegal & INTERFACE) != 0) { log.error(pos, ((flags & ANNOTATION) != 0) ? Errors.AnnotationDeclNotAllowedHere : Errors.IntfNotAllowedHere); mask |= INTERFACE; }
*** 1238,1248 **** VOLATILE) && (sym.kind == TYP || checkDisjoint(pos, flags, ABSTRACT | NATIVE, ! STRICTFP))) { // skip } return flags & (mask | ~ExtendedStandardFlags) | implicit; } --- 1258,1274 ---- VOLATILE) && (sym.kind == TYP || checkDisjoint(pos, flags, ABSTRACT | NATIVE, ! STRICTFP)) ! && checkDisjoint(pos, flags, ! FINAL, ! SEALED | NON_SEALED) ! && checkDisjoint(pos, flags, ! SEALED, ! FINAL | NON_SEALED)) { // skip } return flags & (mask | ~ExtendedStandardFlags) | implicit; }
*** 2811,2823 **** } } /** Check the annotations of a symbol. */ ! public void validateAnnotations(List<JCAnnotation> annotations, Symbol s) { for (JCAnnotation a : annotations) ! validateAnnotation(a, s); } /** Check the type annotations. */ public void validateTypeAnnotations(List<JCAnnotation> annotations, boolean isTypeParameter) { --- 2837,2849 ---- } } /** Check the annotations of a symbol. */ ! public void validateAnnotations(List<JCAnnotation> annotations, JCTree declarationTree, Symbol s) { for (JCAnnotation a : annotations) ! validateAnnotation(a, declarationTree, s); } /** Check the type annotations. */ public void validateTypeAnnotations(List<JCAnnotation> annotations, boolean isTypeParameter) {
*** 2825,2839 **** validateTypeAnnotation(a, isTypeParameter); } /** Check an annotation of a symbol. */ ! private void validateAnnotation(JCAnnotation a, Symbol s) { validateAnnotationTree(a); ! if (a.type.tsym.isAnnotationType() && !annotationApplicable(a, s)) ! log.error(a.pos(), Errors.AnnotationTypeNotApplicable); if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) { if (s.kind != TYP) { log.error(a.pos(), Errors.BadFunctionalIntfAnno); } else if (!s.isInterface() || (s.flags() & ANNOTATION) != 0) { --- 2851,2909 ---- validateTypeAnnotation(a, isTypeParameter); } /** Check an annotation of a symbol. */ ! private void validateAnnotation(JCAnnotation a, JCTree declarationTree, Symbol s) { validateAnnotationTree(a); ! if (s.isRecord() && s.flags_field == (Flags.PRIVATE | Flags.FINAL | Flags.MANDATED | Flags.RECORD) && declarationTree.hasTag(VARDEF)) { ! // we are seeing a record field, which had the original annotations, now is the moment, ! // before stripping some of them just below, to check if the original annotations ! // applied to records at all, first version only cares about declaration annotations ! // we will add type annotations later on ! Name[] targets = getTargetNames(a, s); ! boolean appliesToRecords = false; ! for (Name target : targets) { ! appliesToRecords = ! target == names.FIELD || ! target == names.PARAMETER || ! target == names.METHOD || ! target == names.TYPE_USE || ! target == names.TYPE_PARAMETER; ! if (appliesToRecords) { ! break; ! } ! } ! if (!appliesToRecords) { ! log.error(a.pos(), Errors.AnnotationTypeNotApplicable); ! } ! } ! ! //System.out.println("at Check.validateAnnotation: flags: " + Flags.toString(s.flags_field) + ", declaration tree " + declarationTree); ! ! if (a.type.tsym.isAnnotationType() && !annotationApplicable(a, s)) { ! // debug ! //System.out.println("at Check.validateAnnotation: flags: " + Flags.toString(s.flags_field) + ", declaration tree " + declarationTree); ! if (s.isRecord() || s.owner.isRecord() && (s.flags_field & Flags.MANDATED) != 0) { ! JCModifiers modifiers = TreeInfo.getModifiers(declarationTree); ! // lets first remove the annotation from the modifier ! if (modifiers != null) { ! ListBuffer<JCAnnotation> newAnnotations = new ListBuffer<>(); ! for (JCAnnotation anno : modifiers.annotations) { ! if (anno != a) { ! newAnnotations.add(anno); ! } ! } ! modifiers.annotations = newAnnotations.toList(); ! } ! // now lets remove it from the symbol ! s.getMetadata().remove(a.attribute); ! } else { ! log.error(a.pos(), Errors.AnnotationTypeNotApplicable); ! } ! } if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) { if (s.kind != TYP) { log.error(a.pos(), Errors.BadFunctionalIntfAnno); } else if (!s.isInterface() || (s.flags() & ANNOTATION) != 0) {
*** 3079,3106 **** return (e.value.name == names.TYPE_USE || (isTypeParameter && e.value.name == names.TYPE_PARAMETER)); } /** Is the annotation applicable to the symbol? */ ! boolean annotationApplicable(JCAnnotation a, Symbol s) { Attribute.Array arr = getAttributeTargetAttribute(a.annotationType.type.tsym); Name[] targets; - if (arr == null) { targets = defaultTargetMetaInfo(a, s); } else { // TODO: can we optimize this? targets = new Name[arr.values.length]; for (int i=0; i<arr.values.length; ++i) { Attribute app = arr.values[i]; if (!(app instanceof Attribute.Enum)) { ! return true; // recovery } Attribute.Enum e = (Attribute.Enum) app; targets[i] = e.value.name; } } for (Name target : targets) { if (target == names.TYPE) { if (s.kind == TYP) return true; } else if (target == names.FIELD) { --- 3149,3184 ---- return (e.value.name == names.TYPE_USE || (isTypeParameter && e.value.name == names.TYPE_PARAMETER)); } /** Is the annotation applicable to the symbol? */ ! Name[] getTargetNames(JCAnnotation a, Symbol s) { Attribute.Array arr = getAttributeTargetAttribute(a.annotationType.type.tsym); Name[] targets; if (arr == null) { targets = defaultTargetMetaInfo(a, s); } else { // TODO: can we optimize this? targets = new Name[arr.values.length]; for (int i=0; i<arr.values.length; ++i) { Attribute app = arr.values[i]; if (!(app instanceof Attribute.Enum)) { ! return new Name[0]; } Attribute.Enum e = (Attribute.Enum) app; targets[i] = e.value.name; } } + return targets; + } + + boolean annotationApplicable(JCAnnotation a, Symbol s) { + Name[] targets = getTargetNames(a, s); + if (targets.length == 0) { + // recovery + return true; + } for (Name target : targets) { if (target == names.TYPE) { if (s.kind == TYP) return true; } else if (target == names.FIELD) {
*** 3108,3119 **** return true; } else if (target == names.METHOD) { if (s.kind == MTH && !s.isConstructor()) return true; } else if (target == names.PARAMETER) { ! if (s.kind == VAR && s.owner.kind == MTH && ! (s.flags() & PARAMETER) != 0) { return true; } } else if (target == names.CONSTRUCTOR) { if (s.kind == MTH && s.isConstructor()) return true; --- 3186,3197 ---- return true; } else if (target == names.METHOD) { if (s.kind == MTH && !s.isConstructor()) return true; } else if (target == names.PARAMETER) { ! if (s.kind == VAR && ! (s.owner.kind == MTH && (s.flags() & PARAMETER) != 0)) { return true; } } else if (target == names.CONSTRUCTOR) { if (s.kind == MTH && s.isConstructor()) return true;
*** 3448,3457 **** --- 3526,3540 ---- return true; } else if (sym.kind == MTH && !types.hasSameArgs(sym.type, byName.type, false)) { duplicateErasureError(pos, sym, byName); sym.flags_field |= CLASH; return true; + } else if ((sym.flags() & MATCH_BINDING) != 0 && + (byName.flags() & MATCH_BINDING) != 0 && + (byName.flags() & MATCH_BINDING_TO_OUTER) == 0) { + //this error will be reported separatelly in MatchBindingsComputer + return false; } else { duplicateError(pos, byName); return false; } }
< prev index next >