langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacFiler.java
equal
deleted
inserted
replaced
54 import com.sun.tools.javac.code.Symbol.ClassSymbol; |
54 import com.sun.tools.javac.code.Symbol.ClassSymbol; |
55 import com.sun.tools.javac.code.Symbol.ModuleSymbol; |
55 import com.sun.tools.javac.code.Symbol.ModuleSymbol; |
56 import com.sun.tools.javac.code.Symtab; |
56 import com.sun.tools.javac.code.Symtab; |
57 import com.sun.tools.javac.comp.Modules; |
57 import com.sun.tools.javac.comp.Modules; |
58 import com.sun.tools.javac.model.JavacElements; |
58 import com.sun.tools.javac.model.JavacElements; |
|
59 import com.sun.tools.javac.resources.CompilerProperties.Warnings; |
59 import com.sun.tools.javac.util.*; |
60 import com.sun.tools.javac.util.*; |
60 import com.sun.tools.javac.util.DefinedBy.Api; |
61 import com.sun.tools.javac.util.DefinedBy.Api; |
61 |
62 |
62 import static com.sun.tools.javac.code.Lint.LintCategory.PROCESSING; |
63 import static com.sun.tools.javac.code.Lint.LintCategory.PROCESSING; |
63 import com.sun.tools.javac.code.Symbol.PackageSymbol; |
64 import com.sun.tools.javac.code.Symbol.PackageSymbol; |
480 int periodIndex = name.lastIndexOf("."); |
481 int periodIndex = name.lastIndexOf("."); |
481 if (periodIndex != -1) { |
482 if (periodIndex != -1) { |
482 String base = name.substring(periodIndex); |
483 String base = name.substring(periodIndex); |
483 String extn = (isSourceFile ? ".java" : ".class"); |
484 String extn = (isSourceFile ? ".java" : ".class"); |
484 if (base.equals(extn)) |
485 if (base.equals(extn)) |
485 log.warning("proc.suspicious.class.name", name, extn); |
486 log.warning(Warnings.ProcSuspiciousClassName(name, extn)); |
486 } |
487 } |
487 } |
488 } |
488 checkNameAndExistence(mod, name, isSourceFile); |
489 checkNameAndExistence(mod, name, isSourceFile); |
489 Location loc = (isSourceFile ? SOURCE_OUTPUT : CLASS_OUTPUT); |
490 Location loc = (isSourceFile ? SOURCE_OUTPUT : CLASS_OUTPUT); |
490 |
491 |
498 JavaFileObject fileObject = |
499 JavaFileObject fileObject = |
499 fileManager.getJavaFileForOutput(loc, name, kind, null); |
500 fileManager.getJavaFileForOutput(loc, name, kind, null); |
500 checkFileReopening(fileObject, true); |
501 checkFileReopening(fileObject, true); |
501 |
502 |
502 if (lastRound) |
503 if (lastRound) |
503 log.warning("proc.file.create.last.round", name); |
504 log.warning(Warnings.ProcFileCreateLastRound(name)); |
504 |
505 |
505 if (isSourceFile) |
506 if (isSourceFile) |
506 aggregateGeneratedSourceNames.add(Pair.of(mod, name)); |
507 aggregateGeneratedSourceNames.add(Pair.of(mod, name)); |
507 else |
508 else |
508 aggregateGeneratedClassNames.add(Pair.of(mod, name)); |
509 aggregateGeneratedClassNames.add(Pair.of(mod, name)); |
688 } |
689 } |
689 |
690 |
690 private void checkName(String name, boolean allowUnnamedPackageInfo) throws FilerException { |
691 private void checkName(String name, boolean allowUnnamedPackageInfo) throws FilerException { |
691 if (!SourceVersion.isName(name) && !isPackageInfo(name, allowUnnamedPackageInfo)) { |
692 if (!SourceVersion.isName(name) && !isPackageInfo(name, allowUnnamedPackageInfo)) { |
692 if (lint) |
693 if (lint) |
693 log.warning("proc.illegal.file.name", name); |
694 log.warning(Warnings.ProcIllegalFileName(name)); |
694 throw new FilerException("Illegal name " + name); |
695 throw new FilerException("Illegal name " + name); |
695 } |
696 } |
696 } |
697 } |
697 |
698 |
698 private boolean isPackageInfo(String name, boolean allowUnnamedPackageInfo) { |
699 private boolean isPackageInfo(String name, boolean allowUnnamedPackageInfo) { |
720 initialClassNames.contains(typename) || |
721 initialClassNames.contains(typename) || |
721 ((existing = elementUtils.getTypeElement(typename)) != null && |
722 ((existing = elementUtils.getTypeElement(typename)) != null && |
722 initialInputs.contains(existing.sourcefile)); |
723 initialInputs.contains(existing.sourcefile)); |
723 if (alreadySeen) { |
724 if (alreadySeen) { |
724 if (lint) |
725 if (lint) |
725 log.warning("proc.type.recreate", typename); |
726 log.warning(Warnings.ProcTypeRecreate(typename)); |
726 throw new FilerException("Attempt to recreate a file for type " + typename); |
727 throw new FilerException("Attempt to recreate a file for type " + typename); |
727 } |
728 } |
728 if (!mod.isUnnamed() && !typename.contains(".")) { |
729 if (!mod.isUnnamed() && !typename.contains(".")) { |
729 throw new FilerException("Attempt to create a type in unnamed package of a named module: " + typename); |
730 throw new FilerException("Attempt to create a type in unnamed package of a named module: " + typename); |
730 } |
731 } |
735 * an exception, otherwise add it to the set of files. |
736 * an exception, otherwise add it to the set of files. |
736 */ |
737 */ |
737 private void checkFileReopening(FileObject fileObject, boolean forWriting) throws FilerException { |
738 private void checkFileReopening(FileObject fileObject, boolean forWriting) throws FilerException { |
738 if (isInFileObjectHistory(fileObject, forWriting)) { |
739 if (isInFileObjectHistory(fileObject, forWriting)) { |
739 if (lint) |
740 if (lint) |
740 log.warning("proc.file.reopening", fileObject.getName()); |
741 log.warning(Warnings.ProcFileReopening(fileObject.getName())); |
741 throw new FilerException("Attempt to reopen a file for path " + fileObject.getName()); |
742 throw new FilerException("Attempt to reopen a file for path " + fileObject.getName()); |
742 } |
743 } |
743 if (forWriting) |
744 if (forWriting) |
744 fileObjectHistory.add(fileObject); |
745 fileObjectHistory.add(fileObject); |
745 } |
746 } |
795 return generatedClasses; |
796 return generatedClasses; |
796 } |
797 } |
797 |
798 |
798 public void warnIfUnclosedFiles() { |
799 public void warnIfUnclosedFiles() { |
799 if (!openTypeNames.isEmpty()) |
800 if (!openTypeNames.isEmpty()) |
800 log.warning("proc.unclosed.type.files", openTypeNames.toString()); |
801 log.warning(Warnings.ProcUnclosedTypeFiles(openTypeNames)); |
801 } |
802 } |
802 |
803 |
803 /** |
804 /** |
804 * Update internal state for a new round. |
805 * Update internal state for a new round. |
805 */ |
806 */ |