diff --git a/src/fr/adrienbrault/idea/symfony2plugin/templating/path/TwigNamespaceSetting.java b/src/fr/adrienbrault/idea/symfony2plugin/templating/path/TwigNamespaceSetting.java index 3c57ae633..3485c9a51 100644 --- a/src/fr/adrienbrault/idea/symfony2plugin/templating/path/TwigNamespaceSetting.java +++ b/src/fr/adrienbrault/idea/symfony2plugin/templating/path/TwigNamespaceSetting.java @@ -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) { diff --git a/src/fr/adrienbrault/idea/symfony2plugin/templating/path/TwigPath.java b/src/fr/adrienbrault/idea/symfony2plugin/templating/path/TwigPath.java index bbbd90c72..732791dd2 100644 --- a/src/fr/adrienbrault/idea/symfony2plugin/templating/path/TwigPath.java +++ b/src/fr/adrienbrault/idea/symfony2plugin/templating/path/TwigPath.java @@ -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; @@ -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; } @@ -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; } @@ -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 @@ -103,6 +109,7 @@ public boolean isEnabled() { return enabled; } + @Deprecated public TwigPath setEnabled(boolean enabled) { this.enabled = enabled; return this; diff --git a/tests/fr/adrienbrault/idea/symfony2plugin/tests/templating/path/TwigPathTempTest.java b/tests/fr/adrienbrault/idea/symfony2plugin/tests/templating/path/TwigPathTempTest.java new file mode 100644 index 000000000..48a467fa9 --- /dev/null +++ b/tests/fr/adrienbrault/idea/symfony2plugin/tests/templating/path/TwigPathTempTest.java @@ -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 + * @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())); + } +}