From dca587074567f7f5c2505d1813c5dda9acb44743 Mon Sep 17 00:00:00 2001 From: Fabio Zadrozny Date: Wed, 15 May 2024 10:42:05 -0300 Subject: [PATCH] Stubs should accept IProject as the root project. --- .../shared_core/resource_stubs/FileStub.java | 8 +++--- .../resource_stubs/FolderStub.java | 25 ++++++++----------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/resource_stubs/FileStub.java b/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/resource_stubs/FileStub.java index a2cdfdd868..16dfae33e8 100644 --- a/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/resource_stubs/FileStub.java +++ b/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/resource_stubs/FileStub.java @@ -30,10 +30,10 @@ public class FileStub extends AbstractIFileStub implements IFile { - private IProjectStub project; + private IProject project; protected File file; - public FileStub(IProjectStub project, File file) { + public FileStub(IProject project, File file) { this.project = project; this.file = file; } @@ -75,7 +75,7 @@ public String getName() { @Override public IContainer getParent() { - return project.getFolder(this.file.getParentFile()); + return new FolderStub(project, file.getParentFile()); } @Override @@ -115,7 +115,7 @@ public InputStream getContents(boolean force) throws CoreException { @Override public IPath getFullPath() { - IPath projectPath = Path.fromOSString(FileUtils.getFileAbsolutePath(project.getProjectRoot())); + IPath projectPath = project.getLocation(); IPath filePath = Path.fromOSString(FileUtils.getFileAbsolutePath(file)); return filePath.makeRelativeTo(projectPath); } diff --git a/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/resource_stubs/FolderStub.java b/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/resource_stubs/FolderStub.java index 18d6a53b31..727f44ae33 100644 --- a/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/resource_stubs/FolderStub.java +++ b/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/resource_stubs/FolderStub.java @@ -20,18 +20,18 @@ public class FolderStub extends AbstractIFolderStub implements IFolder { private File folder; - private IProjectStub project; + private IProject project; private IContainer parent; - public FolderStub(IProjectStub stub, File parentFile) { + public FolderStub(IProject stub, File parentFile) { this(stub, null, parentFile); } - public FolderStub(IProjectStub stub, IContainer parent, File parentFile) { + public FolderStub(IProject stub, IContainer parent, File parentFile) { this(stub, parent, parentFile, true); } - public FolderStub(IProjectStub stub, IContainer parent, File parentFile, boolean mustExist) { + public FolderStub(IProject stub, IContainer parent, File parentFile, boolean mustExist) { if (mustExist) { Assert.isTrue(parentFile.exists() && parentFile.isDirectory()); } @@ -50,7 +50,7 @@ public IContainer getParent() { if (parent != null) { return parent; } - return project.getFolder(this.folder.getParentFile()); + return new FolderStub(this.project, this.folder.getParentFile()); } @Override @@ -69,15 +69,11 @@ public IFile getFile(String name) { @Override public IFolder getFolder(IPath path) { String[] segments = path.segments(); - - IFolder f = null; - File curr = this.folder; - for (String string : segments) { - File parentFile = new File(curr, string); - f = (IFolder) project.getFolder(parentFile); - curr = parentFile; + File f = this.folder; + for (String s : segments) { + f = new File(f, s); } - return f; + return new FolderStub(project, f); } @Override @@ -124,10 +120,9 @@ public boolean equals(Object obj) { public IPath getFullPath() { // return Path.fromOSString(FileUtils.getFileAbsolutePath(this.folder)); String fileAbsolutePath = FileUtils.getFileAbsolutePath(this.folder); - String workspaceAbsolutePath = FileUtils.getFileAbsolutePath(this.project.getProjectRoot().getParentFile()); IPath fromOSString = Path.fromOSString(fileAbsolutePath); - IPath workspace = Path.fromOSString(workspaceAbsolutePath); + IPath workspace = this.project.getLocation(); return fromOSString.makeRelativeTo(workspace); }