private static Environment makeProjectEnvironment(IJavaProject project) throws JavaModelException {
Environment env = new Environment(false, StdLib.stdLibDir);
IPath fullPath = project.getProject().getFullPath();
Path root = new AbsolutePath(project.getProject().getLocation().makeAbsolute().toString());
Path bin = new RelativePath(root, project.getOutputLocation().makeRelativeTo(fullPath).toString());
env.setRoot(root);
env.setBin(bin);
for (IPackageFragmentRoot fragment : project.getAllPackageFragmentRoots()) {
IPath path = fragment.getPath();
boolean externalPath = fragment.getResource() == null;
String p = externalPath ? path.toString() : path.makeRelativeTo(fullPath).toString();
Path includePath;
if (fullPath.isPrefixOf(path))
includePath = p.isEmpty() ? root : new RelativePath(root, p);
else if (externalPath)
includePath = new AbsolutePath(p);
else
includePath = new RelativePath(root, p);
if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE && fragment.getParent().equals(project))
env.addToSourcePath(includePath);