From b388a4b47c5d02cb7cb42289ee60111e642d1fb1 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 13 Apr 2015 21:00:04 +0200 Subject: [PATCH] Cleanup (duplicate method deprecated) --- .../openapi/vfs/UrlSplittingTest.java | 48 ++++++++++++++ .../sm/TestsLocationProviderUtil.java | 20 +++--- .../testframework/sm/runner/SMTestProxy.java | 21 +++---- .../sm/LocationProviderUtilTest.java | 62 ------------------- 4 files changed, 64 insertions(+), 87 deletions(-) create mode 100644 platform/platform-tests/testSrc/com/intellij/openapi/vfs/UrlSplittingTest.java delete mode 100644 platform/smRunner/testSrc/com/intellij/execution/testframework/sm/LocationProviderUtilTest.java diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/UrlSplittingTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/UrlSplittingTest.java new file mode 100644 index 000000000000..71d6a3b8a4c9 --- /dev/null +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/UrlSplittingTest.java @@ -0,0 +1,48 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.vfs; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class UrlSplittingTest { + @Test + public void testExtractProtocol() { + assertEquals(null, VirtualFileManager.extractProtocol("")); + assertEquals(null, VirtualFileManager.extractProtocol("file:/")); + + assertEquals("file", VirtualFileManager.extractProtocol("file://")); + assertEquals("file", VirtualFileManager.extractProtocol("file:///some/path/file.rb:24")); + assertEquals("file", VirtualFileManager.extractProtocol("file://./some/path/file.rb:24")); + + assertEquals("ruby_qn", VirtualFileManager.extractProtocol("ruby_qn://")); + assertEquals("ruby_qn", VirtualFileManager.extractProtocol("ruby_qn://A::B.method")); + } + + @Test + public void testExtractPath() { + assertEquals("", VirtualFileManager.extractPath("")); + assertEquals("file:/", VirtualFileManager.extractPath("file:/")); + + assertEquals("", VirtualFileManager.extractPath("file://")); + assertEquals("/some/path/file.rb:24", VirtualFileManager.extractPath("file:///some/path/file.rb:24")); + assertEquals("./some/path/file.rb:24", VirtualFileManager.extractPath("file://./some/path/file.rb:24")); + + assertEquals("", VirtualFileManager.extractPath("ruby_qn://")); + assertEquals("A::B.method", VirtualFileManager.extractPath("ruby_qn://A::B.method")); + } +} diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/TestsLocationProviderUtil.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/TestsLocationProviderUtil.java index bdfde7ea61e9..f0452412a59f 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/TestsLocationProviderUtil.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/TestsLocationProviderUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,8 @@ import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.ex.temp.TempFileSystem; import com.intellij.psi.PsiFile; +import com.intellij.util.io.URLUtil; import com.intellij.util.text.StringTokenizer; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -40,19 +40,15 @@ import java.util.List; * @author Roman Chernyatchik */ public class TestsLocationProviderUtil { - @NonNls private static final String PROTOCOL_SEPARATOR = "://"; private static final int MIN_PROXIMITY_THRESHOLD = 1; - private TestsLocationProviderUtil() { - } + private TestsLocationProviderUtil() { } - @Nullable - public static String extractPath(@NotNull final String locationUrl) { - final int index = locationUrl.indexOf(PROTOCOL_SEPARATOR); - if (index >= 0) { - return locationUrl.substring(index + PROTOCOL_SEPARATOR.length()); - } - return null; + /** @deprecated to be removed in IDEA 16 */ + @SuppressWarnings("unused") + public static String extractPath(@NotNull String locationUrl) { + int index = locationUrl.indexOf(URLUtil.SCHEME_SEPARATOR); + return index >= 0 ? locationUrl.substring(index + URLUtil.SCHEME_SEPARATOR.length()) : null; } public static List findSuitableFilesFor(final String filePath, final Project project) { diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java index 219473b28fa2..9738d9f11f82 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java @@ -18,7 +18,6 @@ package com.intellij.execution.testframework.sm.runner; import com.intellij.execution.Location; import com.intellij.execution.testframework.*; import com.intellij.execution.testframework.sm.SMStacktraceParser; -import com.intellij.execution.testframework.sm.TestsLocationProviderUtil; import com.intellij.execution.testframework.sm.runner.states.*; import com.intellij.execution.testframework.sm.runner.ui.TestsPresentationUtil; import com.intellij.execution.testframework.stacktrace.DiffHyperlink; @@ -247,18 +246,14 @@ public class SMTestProxy extends AbstractTestProxy { @Nullable public Location getLocation(final Project project, GlobalSearchScope searchScope) { //determines location of test proxy - - if (myLocationUrl == null || myLocator == null) { - return null; - } - - final String protocolId = VirtualFileManager.extractProtocol(myLocationUrl); - final String path = TestsLocationProviderUtil.extractPath(myLocationUrl); - - if (protocolId != null && path != null) { - List locations = myLocator.getLocation(protocolId, path, project); - if (!locations.isEmpty()) { - return locations.iterator().next(); + if (myLocationUrl != null && myLocator != null) { + String protocolId = VirtualFileManager.extractProtocol(myLocationUrl); + if (protocolId != null) { + String path = VirtualFileManager.extractPath(myLocationUrl); + List locations = myLocator.getLocation(protocolId, path, project); + if (!locations.isEmpty()) { + return locations.get(0); + } } } diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/LocationProviderUtilTest.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/LocationProviderUtilTest.java deleted file mode 100644 index 6e81886907b7..000000000000 --- a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/LocationProviderUtilTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.execution.testframework.sm; - -import com.intellij.openapi.vfs.VirtualFileManager; -import com.intellij.testFramework.UsefulTestCase; - -/** - * @author Roman Chernyatchik - */ -public class LocationProviderUtilTest extends UsefulTestCase { - public void testExtractProtocol() { - assertEquals(null, - VirtualFileManager.extractProtocol("")); - assertEquals(null, - VirtualFileManager.extractProtocol("file:/")); - - assertEquals("file", - VirtualFileManager.extractProtocol("file://")); - assertEquals("file", - VirtualFileManager.extractProtocol("file:///some/path/file.rb:24")); - assertEquals("file", - VirtualFileManager.extractProtocol("file://./some/path/file.rb:24")); - - assertEquals("ruby_qn", - VirtualFileManager.extractProtocol("ruby_qn://")); - assertEquals("ruby_qn", - VirtualFileManager.extractProtocol("ruby_qn://A::B.method")); - } - - public void testExtractPath() { - assertEquals(null, - TestsLocationProviderUtil.extractPath("")); - assertEquals(null, - TestsLocationProviderUtil.extractPath("file:/")); - - assertEquals("", - TestsLocationProviderUtil.extractPath("file://")); - assertEquals("/some/path/file.rb:24", - TestsLocationProviderUtil.extractPath("file:///some/path/file.rb:24")); - assertEquals("./some/path/file.rb:24", - TestsLocationProviderUtil.extractPath("file://./some/path/file.rb:24")); - - assertEquals("", - TestsLocationProviderUtil.extractPath("ruby_qn://")); - assertEquals("A::B.method", - TestsLocationProviderUtil.extractPath("ruby_qn://A::B.method")); - } -}