< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacFiler.java

Print this page

        

*** 51,60 **** --- 51,61 ---- import static javax.tools.StandardLocation.CLASS_OUTPUT; import com.sun.tools.javac.code.Lint; import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.ModuleSymbol; + import com.sun.tools.javac.code.Symbol.TypeSymbol; import com.sun.tools.javac.code.Symtab; import com.sun.tools.javac.comp.Modules; import com.sun.tools.javac.model.JavacElements; import com.sun.tools.javac.resources.CompilerProperties.Warnings; import com.sun.tools.javac.util.*;
*** 713,738 **** private void checkNameAndExistence(ModuleSymbol mod, String typename, boolean allowUnnamedPackageInfo) throws FilerException { // TODO: Check if type already exists on source or class path? // If so, use warning message key proc.type.already.exists checkName(typename, allowUnnamedPackageInfo); ! ClassSymbol existing; boolean alreadySeen = aggregateGeneratedSourceNames.contains(Pair.of(mod, typename)) || aggregateGeneratedClassNames.contains(Pair.of(mod, typename)) || initialClassNames.contains(typename) || ! ((existing = elementUtils.getTypeElement(typename)) != null && ! initialInputs.contains(existing.sourcefile)); if (alreadySeen) { if (lint) log.warning(Warnings.ProcTypeRecreate(typename)); throw new FilerException("Attempt to recreate a file for type " + typename); } if (!mod.isUnnamed() && !typename.contains(".")) { throw new FilerException("Attempt to create a type in unnamed package of a named module: " + typename); } } /** * Check to see if the file has already been opened; if so, throw * an exception, otherwise add it to the set of files. */ private void checkFileReopening(FileObject fileObject, boolean forWriting) throws FilerException { --- 714,757 ---- private void checkNameAndExistence(ModuleSymbol mod, String typename, boolean allowUnnamedPackageInfo) throws FilerException { // TODO: Check if type already exists on source or class path? // If so, use warning message key proc.type.already.exists checkName(typename, allowUnnamedPackageInfo); ! boolean alreadySeen = aggregateGeneratedSourceNames.contains(Pair.of(mod, typename)) || aggregateGeneratedClassNames.contains(Pair.of(mod, typename)) || initialClassNames.contains(typename) || ! containedInInitialInputs(typename); if (alreadySeen) { if (lint) log.warning(Warnings.ProcTypeRecreate(typename)); throw new FilerException("Attempt to recreate a file for type " + typename); } if (!mod.isUnnamed() && !typename.contains(".")) { throw new FilerException("Attempt to create a type in unnamed package of a named module: " + typename); } } + private boolean containedInInitialInputs(String typename) { + // Name could be a type name or the name of a package-info file + JavaFileObject sourceFile = null; + + ClassSymbol existingClass = elementUtils.getTypeElement(typename); + if (existingClass != null) { + sourceFile = existingClass.sourcefile; + } else if (typename.endsWith(".package-info")) { + String targetName = typename.substring(0, typename.length() - ".package-info".length()); + PackageSymbol existingPackage = + elementUtils.getPackageElement(targetName); + // System.err.println("\t\tfound " + existingPackage + + // ", sourceFile "+ (existingPackage!= null?existingPackage.sourcefile:null)); + if (existingPackage != null) + sourceFile = existingPackage.sourcefile; + } + return (sourceFile == null) ? false : initialInputs.contains(sourceFile); + } + /** * Check to see if the file has already been opened; if so, throw * an exception, otherwise add it to the set of files. */ private void checkFileReopening(FileObject fileObject, boolean forWriting) throws FilerException {
< prev index next >