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; }
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; }