851 JCClassDecl classDefPrev = classDef; |
851 JCClassDecl classDefPrev = classDef; |
852 List<Type> thrownPrev = thrown; |
852 List<Type> thrownPrev = thrown; |
853 List<Type> caughtPrev = caught; |
853 List<Type> caughtPrev = caught; |
854 ListBuffer<FlowPendingExit> pendingExitsPrev = pendingExits; |
854 ListBuffer<FlowPendingExit> pendingExitsPrev = pendingExits; |
855 Lint lintPrev = lint; |
855 Lint lintPrev = lint; |
856 |
856 boolean anonymousClass = tree.name == names.empty; |
857 pendingExits = new ListBuffer<>(); |
857 pendingExits = new ListBuffer<>(); |
858 if (tree.name != names.empty) { |
858 if (!anonymousClass) { |
859 caught = List.nil(); |
859 caught = List.nil(); |
860 } |
860 } |
861 classDef = tree; |
861 classDef = tree; |
862 thrown = List.nil(); |
862 thrown = List.nil(); |
863 lint = lint.augment(tree.sym); |
863 lint = lint.augment(tree.sym); |
872 } |
872 } |
873 } |
873 } |
874 |
874 |
875 // add intersection of all thrown clauses of initial constructors |
875 // add intersection of all thrown clauses of initial constructors |
876 // to set of caught exceptions, unless class is anonymous. |
876 // to set of caught exceptions, unless class is anonymous. |
877 if (tree.name != names.empty) { |
877 if (!anonymousClass) { |
878 boolean firstConstructor = true; |
878 boolean firstConstructor = true; |
879 for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { |
879 for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { |
880 if (TreeInfo.isInitialConstructor(l.head)) { |
880 if (TreeInfo.isInitialConstructor(l.head)) { |
881 List<Type> mthrown = |
881 List<Type> mthrown = |
882 ((JCMethodDecl) l.head).sym.type.getThrownTypes(); |
882 ((JCMethodDecl) l.head).sym.type.getThrownTypes(); |
903 // the throws clause of the synthetic constructor and propagate |
903 // the throws clause of the synthetic constructor and propagate |
904 // outwards. |
904 // outwards. |
905 // Changing the throws clause on the fly is okay here because |
905 // Changing the throws clause on the fly is okay here because |
906 // the anonymous constructor can't be invoked anywhere else, |
906 // the anonymous constructor can't be invoked anywhere else, |
907 // and its type hasn't been cached. |
907 // and its type hasn't been cached. |
908 if (tree.name == names.empty) { |
908 if (anonymousClass) { |
909 for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { |
909 for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { |
910 if (TreeInfo.isInitialConstructor(l.head)) { |
910 if (TreeInfo.isConstructor(l.head)) { |
911 JCMethodDecl mdef = (JCMethodDecl)l.head; |
911 JCMethodDecl mdef = (JCMethodDecl)l.head; |
|
912 scan(mdef); |
912 mdef.thrown = make.Types(thrown); |
913 mdef.thrown = make.Types(thrown); |
913 mdef.sym.type = types.createMethodTypeWithThrown(mdef.sym.type, thrown); |
914 mdef.sym.type = types.createMethodTypeWithThrown(mdef.sym.type, thrown); |
914 } |
915 } |
915 } |
916 } |
916 thrownPrev = chk.union(thrown, thrownPrev); |
917 thrownPrev = chk.union(thrown, thrownPrev); |
917 } |
918 } |
918 |
919 |
919 // process all the methods |
920 // process all the methods |
920 for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { |
921 for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { |
|
922 if (anonymousClass && TreeInfo.isConstructor(l.head)) |
|
923 continue; // there can never be an uncaught exception. |
921 if (l.head.hasTag(METHODDEF)) { |
924 if (l.head.hasTag(METHODDEF)) { |
922 scan(l.head); |
925 scan(l.head); |
923 errorUncaught(); |
926 errorUncaught(); |
924 } |
927 } |
925 } |
928 } |