use of org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager in project ceylon by eclipse.
the class LanguageCompiler method getSrcDir.
// FIXME: this function is terrible, possibly refactor it with getPackage?
private File getSrcDir(File sourceFile) throws IOException {
Iterable<? extends File> prefixes = ((JavacFileManager) fileManager).getLocation(StandardLocation.SOURCE_PATH);
File srcDirFile = FileUtil.selectPath(prefixes, sourceFile.getPath());
if (srcDirFile != null) {
return srcDirFile;
} else {
// This error should have been caught by the tool chain
throw new RuntimeException(sourceFile.getPath() + " is not in the current source path");
}
}
use of org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager in project ceylon by eclipse.
the class LanguageCompiler method addModuleDescriptors.
// This is a bit of a hack, but if we got passed a list of resources
// without any accompaning source files we'll not be able to determine
// the module to which the resource files belong. So to try to fix that
// we see if a module file exists in the source folders and add it to
// the list of source files
private List<JavaFileObject> addModuleDescriptors(List<JavaFileObject> sourceFiles, List<JavaFileObject> resourceFiles) {
List<JavaFileObject> result = sourceFiles;
JavacFileManager dfm = (JavacFileManager) fileManager;
for (JavaFileObject fo : resourceFiles) {
String resName = JarUtils.toPlatformIndependentPath(dfm.getLocation(CeylonLocation.RESOURCE_PATH), fo.getName());
JavaFileObject moduleFile = findModuleDescriptorForFile(new File(resName));
if (moduleFile != null && !result.contains(moduleFile)) {
result = result.append(moduleFile);
}
}
return result;
}
use of org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager in project ceylon by eclipse.
the class LanguageCompiler method findModuleDescriptorForFile.
private JavaFileObject findModuleDescriptorForFile(File file) {
JavacFileManager dfm = (JavacFileManager) fileManager;
File dir = file.getParentFile();
while (dir != null) {
try {
String name = dir.getPath() + "/module";
JavaFileObject fo = dfm.getJavaFileForInput(StandardLocation.SOURCE_PATH, name, Kind.SOURCE);
if (fo != null) {
return fo;
}
} catch (IOException e) {
// Ignore
}
dir = dir.getParentFile();
}
return null;
}
use of org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager in project ceylon by eclipse.
the class LanguageCompiler method isResource.
private boolean isResource(JavaFileObject fo) {
// make sure we get a proper normalized abslute path
String fileName = FileUtil.absoluteFile(new File(fo.toUri().getPath())).getPath();
// now see if it's in any of the resource paths
JavacFileManager dfm = (JavacFileManager) fileManager;
for (File dir : dfm.getLocation(CeylonLocation.RESOURCE_PATH)) {
String prefix = FileUtil.absoluteFile(dir).getPath();
if (fileName.startsWith(prefix)) {
return true;
}
}
return false;
}
use of org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager in project ceylon by eclipse.
the class LanguageCompiler method getPackage.
private String getPackage(JavaFileObject file) throws IOException {
Iterable<? extends File> prefixes = ((JavacFileManager) fileManager).getLocation(StandardLocation.SOURCE_PATH);
// Figure out the package name by stripping the "-src" prefix and
// extracting
// the package part of the fullname.
String filePath = file.toUri().getPath();
// go absolute
filePath = new File(filePath).getCanonicalPath();
int srcDirLength = 0;
for (File prefixFile : prefixes) {
String prefix = prefixFile.getCanonicalPath();
if (filePath.startsWith(prefix) && prefix.length() > srcDirLength) {
srcDirLength = prefix.length();
}
}
if (srcDirLength > 0) {
String fullname = filePath.substring(srcDirLength);
assert fullname.endsWith(".ceylon");
fullname = fullname.substring(0, fullname.length() - ".ceylon".length());
fullname = fullname.replace(File.separator, ".");
if (fullname.startsWith("."))
fullname = fullname.substring(1);
String packageName = Convert.packagePart(fullname);
if (!packageName.equals(""))
return packageName;
}
return null;
}
Aggregations