65 import com.sun.tools.javac.parser.*; |
65 import com.sun.tools.javac.parser.*; |
66 import com.sun.tools.javac.tree.*; |
66 import com.sun.tools.javac.tree.*; |
67 import com.sun.tools.javac.tree.JCTree.*; |
67 import com.sun.tools.javac.tree.JCTree.*; |
68 import com.sun.tools.javac.util.Abort; |
68 import com.sun.tools.javac.util.Abort; |
69 import com.sun.tools.javac.util.Context; |
69 import com.sun.tools.javac.util.Context; |
|
70 import com.sun.tools.javac.util.Convert; |
70 import com.sun.tools.javac.util.List; |
71 import com.sun.tools.javac.util.List; |
71 import com.sun.tools.javac.util.ListBuffer; |
72 import com.sun.tools.javac.util.ListBuffer; |
72 import com.sun.tools.javac.util.Log; |
73 import com.sun.tools.javac.util.Log; |
73 import com.sun.tools.javac.util.JavacMessages; |
74 import com.sun.tools.javac.util.JavacMessages; |
74 import com.sun.tools.javac.util.Name; |
75 import com.sun.tools.javac.util.Name; |
891 // Check for errors after parsing |
892 // Check for errors after parsing |
892 if (compiler.parseErrors()) { |
893 if (compiler.parseErrors()) { |
893 errorStatus = true; |
894 errorStatus = true; |
894 break runAround; |
895 break runAround; |
895 } else { |
896 } else { |
896 ListBuffer<ClassSymbol> classes = enterNewClassFiles(currentContext); |
897 List<ClassSymbol> newClasses = enterNewClassFiles(currentContext); |
897 compiler.enterTrees(roots); |
898 compiler.enterTrees(roots); |
898 |
899 |
899 // annotationsPresentInSource = |
900 // annotationsPresentInSource = |
900 // collector.findAnnotations(parsedFiles); |
901 // collector.findAnnotations(parsedFiles); |
901 classes.appendList(getTopLevelClasses(parsedFiles)); |
902 ListBuffer<ClassSymbol> tlc = new ListBuffer<ClassSymbol>(); |
902 topLevelClasses = classes.toList(); |
903 tlc.appendList(getTopLevelClasses(parsedFiles)); |
903 packageInfoFiles = getPackageInfoFiles(parsedFiles); |
904 tlc.appendList(getTopLevelClassesFromClasses(newClasses)); |
|
905 topLevelClasses = tlc.toList(); |
|
906 |
|
907 ListBuffer<PackageSymbol> pif = new ListBuffer<PackageSymbol>(); |
|
908 pif.appendList(getPackageInfoFiles(parsedFiles)); |
|
909 pif.appendList(getPackageInfoFilesFromClasses(newClasses)); |
|
910 packageInfoFiles = pif.toList(); |
904 |
911 |
905 annotationsPresent = new LinkedHashSet<TypeElement>(); |
912 annotationsPresent = new LinkedHashSet<TypeElement>(); |
906 for (ClassSymbol classSym : topLevelClasses) |
913 for (ClassSymbol classSym : topLevelClasses) |
907 annotationComputer.scan(classSym, annotationsPresent); |
914 annotationComputer.scan(classSym, annotationsPresent); |
908 for (PackageSymbol pkgSym : packageInfoFiles) |
915 for (PackageSymbol pkgSym : packageInfoFiles) |
1024 annotationsPresent, |
1031 annotationsPresent, |
1025 lastRound)); |
1032 lastRound)); |
1026 } |
1033 } |
1027 } |
1034 } |
1028 |
1035 |
1029 private ListBuffer<ClassSymbol> enterNewClassFiles(Context currentContext) { |
1036 private List<ClassSymbol> enterNewClassFiles(Context currentContext) { |
1030 ClassReader reader = ClassReader.instance(currentContext); |
1037 ClassReader reader = ClassReader.instance(currentContext); |
1031 Names names = Names.instance(currentContext); |
1038 Names names = Names.instance(currentContext); |
1032 ListBuffer<ClassSymbol> list = new ListBuffer<ClassSymbol>(); |
1039 List<ClassSymbol> list = List.nil(); |
1033 |
1040 |
1034 for (Map.Entry<String,JavaFileObject> entry : filer.getGeneratedClasses().entrySet()) { |
1041 for (Map.Entry<String,JavaFileObject> entry : filer.getGeneratedClasses().entrySet()) { |
1035 Name name = names.fromString(entry.getKey()); |
1042 Name name = names.fromString(entry.getKey()); |
1036 JavaFileObject file = entry.getValue(); |
1043 JavaFileObject file = entry.getValue(); |
1037 if (file.getKind() != JavaFileObject.Kind.CLASS) |
1044 if (file.getKind() != JavaFileObject.Kind.CLASS) |
1038 throw new AssertionError(file); |
1045 throw new AssertionError(file); |
1039 ClassSymbol cs = reader.enterClass(name, file); |
1046 ClassSymbol cs; |
1040 list.append(cs); |
1047 if (isPkgInfo(file, JavaFileObject.Kind.CLASS)) { |
1041 } |
1048 Name packageName = Convert.packagePart(name); |
1042 return list; |
1049 PackageSymbol p = reader.enterPackage(packageName); |
|
1050 if (p.package_info == null) |
|
1051 p.package_info = reader.enterClass(Convert.shortName(name), p); |
|
1052 cs = p.package_info; |
|
1053 if (cs.classfile == null) |
|
1054 cs.classfile = file; |
|
1055 } else |
|
1056 cs = reader.enterClass(name, file); |
|
1057 list = list.prepend(cs); |
|
1058 } |
|
1059 return list.reverse(); |
1043 } |
1060 } |
1044 |
1061 |
1045 /** |
1062 /** |
1046 * Free resources related to annotation processing. |
1063 * Free resources related to annotation processing. |
1047 */ |
1064 */ |
1064 } |
1081 } |
1065 } |
1082 } |
1066 return classes.reverse(); |
1083 return classes.reverse(); |
1067 } |
1084 } |
1068 |
1085 |
|
1086 private List<ClassSymbol> getTopLevelClassesFromClasses(List<? extends ClassSymbol> syms) { |
|
1087 List<ClassSymbol> classes = List.nil(); |
|
1088 for (ClassSymbol sym : syms) { |
|
1089 if (!isPkgInfo(sym)) { |
|
1090 classes = classes.prepend(sym); |
|
1091 } |
|
1092 } |
|
1093 return classes.reverse(); |
|
1094 } |
|
1095 |
1069 private List<PackageSymbol> getPackageInfoFiles(List<? extends JCCompilationUnit> units) { |
1096 private List<PackageSymbol> getPackageInfoFiles(List<? extends JCCompilationUnit> units) { |
1070 List<PackageSymbol> packages = List.nil(); |
1097 List<PackageSymbol> packages = List.nil(); |
1071 for (JCCompilationUnit unit : units) { |
1098 for (JCCompilationUnit unit : units) { |
1072 boolean isPkgInfo = unit.sourcefile.isNameCompatible("package-info", |
1099 if (isPkgInfo(unit.sourcefile, JavaFileObject.Kind.SOURCE)) { |
1073 JavaFileObject.Kind.SOURCE); |
|
1074 if (isPkgInfo) { |
|
1075 packages = packages.prepend(unit.packge); |
1100 packages = packages.prepend(unit.packge); |
1076 } |
1101 } |
1077 } |
1102 } |
1078 return packages.reverse(); |
1103 return packages.reverse(); |
|
1104 } |
|
1105 |
|
1106 private List<PackageSymbol> getPackageInfoFilesFromClasses(List<? extends ClassSymbol> syms) { |
|
1107 List<PackageSymbol> packages = List.nil(); |
|
1108 for (ClassSymbol sym : syms) { |
|
1109 if (isPkgInfo(sym)) { |
|
1110 packages = packages.prepend((PackageSymbol) sym.owner); |
|
1111 } |
|
1112 } |
|
1113 return packages.reverse(); |
|
1114 } |
|
1115 |
|
1116 private boolean isPkgInfo(JavaFileObject fo, JavaFileObject.Kind kind) { |
|
1117 return fo.isNameCompatible("package-info", kind); |
|
1118 } |
|
1119 |
|
1120 private boolean isPkgInfo(ClassSymbol sym) { |
|
1121 return isPkgInfo(sym.classfile, JavaFileObject.Kind.CLASS) && (sym.packge().package_info == sym); |
1079 } |
1122 } |
1080 |
1123 |
1081 private Context contextForNextRound(Context context, boolean shareNames) |
1124 private Context contextForNextRound(Context context, boolean shareNames) |
1082 throws IOException |
1125 throws IOException |
1083 { |
1126 { |