Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,12 @@ public boolean isEnabled() {
}

public boolean equals(Project project, TwigPath twigPath) {

if(!twigPath.getNamespaceType().equals(this.getNamespaceType()) || !twigPath.getNamespace().equals(this.getNamespace())) {
return false;
}

String relativePath = twigPath.getRelativePath(project);
if(relativePath == null || !relativePath.equals(this.getPath())) {
return false;
}

return true;

return relativePath != null && relativePath.equals(this.getPath());
}

public TwigNamespaceSetting setEnabled(boolean disabled) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.adrienbrault.idea.symfony2plugin.templating.path;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -53,6 +54,7 @@ public TwigPath clone() {

TwigPath twigPath = new TwigPath(this.getPath(), this.getNamespace(), this.getNamespaceType(), this.isCustomPath());
twigPath.setEnabled(this.isEnabled());

return twigPath;
}

Expand All @@ -72,11 +74,11 @@ public boolean isGlobalNamespace() {

@Nullable
public String getRelativePath(@NotNull Project project) {
if(this.isCustomPath()) {
return this.getPath();
if(!FileUtil.isAbsolute(path)) {
return path;
}

VirtualFile virtualFile = this.getDirectory();
VirtualFile virtualFile = getDirectory();
if(virtualFile == null) {
return null;
}
Expand All @@ -86,12 +88,16 @@ public String getRelativePath(@NotNull Project project) {

@Nullable
public VirtualFile getDirectory(@NotNull Project project) {
String relativePath = this.getRelativePath(project);
if(relativePath == null) {
return null;
if(!FileUtil.isAbsolute(path)) {
return VfsUtil.findRelativeFile(path, project.getBaseDir());
} else {
VirtualFile fileByIoFile = VfsUtil.findFileByIoFile(new File(path), true);
if(fileByIoFile != null) {
return fileByIoFile;
}
}

return VfsUtil.findRelativeFile(relativePath, project.getBaseDir());
return null;
}

@NotNull
Expand All @@ -103,6 +109,7 @@ public boolean isEnabled() {
return enabled;
}

@Deprecated
public TwigPath setEnabled(boolean enabled) {
this.enabled = enabled;
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package fr.adrienbrault.idea.symfony2plugin.tests.templating.path;

import com.intellij.util.SystemIndependent;
import fr.adrienbrault.idea.symfony2plugin.templating.path.TwigPath;
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyTempCodeInsightFixtureTestCase;

/**
* @author Daniel Espendiller <daniel@espendiller.net>
* @see fr.adrienbrault.idea.symfony2plugin.templating.path.TwigPath#TwigPath
*/
public class TwigPathTempTest extends SymfonyTempCodeInsightFixtureTestCase {
public void testRelativePathResolving() {
createFile("app/views");

TwigPath twigPath = new TwigPath("app", "namespace");
assertEquals("app", twigPath.getDirectory(getProject()).getName());

assertEquals("app", twigPath.getPath());
assertEquals("namespace", twigPath.getNamespace());

assertEquals("app", twigPath.getRelativePath(getProject()));
}

public void testAbsolutePathResolving() {
createFile("app/views");

@SystemIndependent String basePath = getProject().getBasePath();
TwigPath twigPath = new TwigPath(basePath + "/app", "namespace");
assertEquals("app", twigPath.getDirectory(getProject()).getName());

assertTrue(twigPath.getPath().endsWith("app"));
assertEquals("namespace", twigPath.getNamespace());

assertEquals("app", twigPath.getRelativePath(getProject()));
}
}