use of javax.tools.JavaFileManager.Location in project ceylon-compiler by ceylon.
the class JavadocTool method parsePackageClasses.
/**
* search all directories in path for subdirectory name. Add all
* .java files found in such a directory to args.
*/
private void parsePackageClasses(String name, Iterable<JavaFileObject> files, ListBuffer<JCCompilationUnit> trees, List<String> excludedPackages) throws IOException {
if (excludedPackages.contains(name)) {
return;
}
boolean hasFiles = false;
docenv.notice("main.Loading_source_files_for_package", name);
if (files == null) {
Location location = docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH) ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;
ListBuffer<JavaFileObject> lb = new ListBuffer<JavaFileObject>();
for (JavaFileObject fo : docenv.fileManager.list(location, name, EnumSet.of(JavaFileObject.Kind.SOURCE), false)) {
String binaryName = docenv.fileManager.inferBinaryName(location, fo);
String simpleName = getSimpleName(binaryName);
if (isValidClassName(simpleName)) {
lb.append(fo);
}
}
files = lb.toList();
}
for (JavaFileObject fo : files) {
// messager.notice("main.Loading_source_file", fn);
trees.append(parse(fo));
hasFiles = true;
}
if (!hasFiles) {
messager.warning(null, "main.no_source_files_for_package", name.replace(File.separatorChar, '.'));
}
}
use of javax.tools.JavaFileManager.Location in project ceylon-compiler by ceylon.
the class JavacFiler method createSourceOrClassFile.
private JavaFileObject createSourceOrClassFile(boolean isSourceFile, String name) throws IOException {
if (lint) {
int periodIndex = name.lastIndexOf(".");
if (periodIndex != -1) {
String base = name.substring(periodIndex);
String extn = (isSourceFile ? ".java" : ".class");
if (base.equals(extn))
log.warning("proc.suspicious.class.name", name, extn);
}
}
checkNameAndExistence(name, isSourceFile);
Location loc = (isSourceFile ? SOURCE_OUTPUT : CLASS_OUTPUT);
JavaFileObject.Kind kind = (isSourceFile ? JavaFileObject.Kind.SOURCE : JavaFileObject.Kind.CLASS);
JavaFileObject fileObject = fileManager.getJavaFileForOutput(loc, name, kind, null);
checkFileReopening(fileObject, true);
if (lastRound)
log.warning("proc.file.create.last.round", name);
if (isSourceFile)
aggregateGeneratedSourceNames.add(name);
else
aggregateGeneratedClassNames.add(name);
openTypeNames.add(name);
return new FilerOutputJavaFileObject(name, fileObject);
}
use of javax.tools.JavaFileManager.Location in project ceylon-compiler by ceylon.
the class SourceWriter method readSource.
private String readSource(ClassFile cf) {
if (fileManager == null)
return null;
Location location;
if (fileManager.hasLocation((StandardLocation.SOURCE_PATH)))
location = StandardLocation.SOURCE_PATH;
else
location = StandardLocation.CLASS_PATH;
// InnerClasses and EnclosingMethod attributes.
try {
String className = cf.getName();
SourceFile_attribute sf = (SourceFile_attribute) cf.attributes.get(Attribute.SourceFile);
if (sf == null) {
report(messages.getMessage("err.no.SourceFile.attribute"));
return null;
}
String sourceFile = sf.getSourceFile(cf.constant_pool);
String fileBase = sourceFile.endsWith(".java") ? sourceFile.substring(0, sourceFile.length() - 5) : sourceFile;
int sep = className.lastIndexOf("/");
String pkgName = (sep == -1 ? "" : className.substring(0, sep + 1));
String topClassName = (pkgName + fileBase).replace('/', '.');
JavaFileObject fo = fileManager.getJavaFileForInput(location, topClassName, JavaFileObject.Kind.SOURCE);
if (fo == null) {
report(messages.getMessage("err.source.file.not.found"));
return null;
}
return fo.getCharContent(true).toString();
} catch (ConstantPoolException e) {
report(e);
return null;
} catch (IOException e) {
report(e.getLocalizedMessage());
return null;
}
}
use of javax.tools.JavaFileManager.Location in project ceylon by eclipse.
the class T6397104 method test.
void test(boolean hasLocation, File siblingFile, String relName, String expectedPath) throws Exception {
StandardJavaFileManager fm;
if (hasLocation) {
for (Location location : StandardLocation.values()) {
fm = tool.getStandardFileManager(null, null, null);
fm.setLocation(location, Arrays.asList(new File(".")));
test(fm, location, siblingFile, relName, expectedPath);
}
} else {
fm = tool.getStandardFileManager(null, null, null);
test(fm, CLASS_OUTPUT, siblingFile, relName, expectedPath);
}
}
use of javax.tools.JavaFileManager.Location in project ceylon-compiler by ceylon.
the class T6397104 method test.
void test(boolean hasLocation, File siblingFile, String relName, String expectedPath) throws Exception {
StandardJavaFileManager fm;
if (hasLocation) {
for (Location location : StandardLocation.values()) {
fm = tool.getStandardFileManager(null, null, null);
fm.setLocation(location, Arrays.asList(new File(".")));
test(fm, location, siblingFile, relName, expectedPath);
}
} else {
fm = tool.getStandardFileManager(null, null, null);
test(fm, CLASS_OUTPUT, siblingFile, relName, expectedPath);
}
}
Aggregations