Skip to content

Commit

Permalink
Stubs should accept IProject as the root project.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed May 15, 2024
1 parent f39d157 commit dca5870
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -75,7 +75,7 @@ public String getName() {

@Override
public IContainer getParent() {
return project.getFolder(this.file.getParentFile());
return new FolderStub(project, file.getParentFile());
}

@Override
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit dca5870

Please sign in to comment.