|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -package org.jetbrains.kotlin.idea.filters; |
18 |
| - |
19 |
| -import com.intellij.execution.filters.Filter; |
20 |
| -import com.intellij.execution.filters.HyperlinkInfo; |
21 |
| -import com.intellij.execution.filters.OpenFileHyperlinkInfo; |
22 |
| -import com.intellij.openapi.editor.Document; |
23 |
| -import com.intellij.openapi.fileEditor.FileDocumentManager; |
24 |
| -import com.intellij.openapi.fileEditor.OpenFileDescriptor; |
25 |
| -import com.intellij.openapi.vfs.VfsUtilCore; |
26 |
| -import com.intellij.openapi.vfs.VirtualFile; |
27 |
| -import com.intellij.psi.PsiDocumentManager; |
28 |
| -import com.intellij.psi.search.GlobalSearchScope; |
29 |
| -import com.intellij.refactoring.MultiFileTestCase; |
30 |
| -import com.intellij.testFramework.PsiTestUtil; |
31 |
| -import kotlin.jvm.functions.Function1; |
32 |
| -import org.jetbrains.annotations.NotNull; |
33 |
| -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; |
34 |
| -import org.jetbrains.kotlin.name.FqName; |
35 |
| -import org.jetbrains.kotlin.utils.UtilsPackage; |
36 |
| - |
37 |
| -import java.io.File; |
38 |
| - |
39 |
| -import static org.jetbrains.kotlin.load.kotlin.PackageClassUtils.getPackageClassFqName; |
40 |
| -import static org.jetbrains.kotlin.load.kotlin.PackageClassUtils.getPackageClassName; |
41 |
| -import static org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils.getPackagePartFqName; |
42 |
| - |
43 |
| -public class JetExceptionFilterTest extends MultiFileTestCase { |
44 |
| - private VirtualFile rootDir; |
45 |
| - |
46 |
| - @Override |
47 |
| - protected void tearDown() throws Exception { |
48 |
| - rootDir = null; |
49 |
| - super.tearDown(); |
| 17 | +package org.jetbrains.kotlin.idea.filters |
| 18 | + |
| 19 | +import com.intellij.execution.filters.Filter |
| 20 | +import com.intellij.execution.filters.HyperlinkInfo |
| 21 | +import com.intellij.execution.filters.OpenFileHyperlinkInfo |
| 22 | +import com.intellij.openapi.editor.Document |
| 23 | +import com.intellij.openapi.fileEditor.FileDocumentManager |
| 24 | +import com.intellij.openapi.fileEditor.OpenFileDescriptor |
| 25 | +import com.intellij.openapi.vfs.VfsUtilCore |
| 26 | +import com.intellij.openapi.vfs.VirtualFile |
| 27 | +import com.intellij.psi.PsiDocumentManager |
| 28 | +import com.intellij.psi.search.GlobalSearchScope |
| 29 | +import com.intellij.refactoring.MultiFileTestCase |
| 30 | +import com.intellij.testFramework.PsiTestUtil |
| 31 | +import org.jetbrains.kotlin.idea.test.PluginTestCaseBase |
| 32 | +import org.jetbrains.kotlin.name.FqName |
| 33 | +import org.jetbrains.kotlin.utils.* |
| 34 | + |
| 35 | +import java.io.File |
| 36 | + |
| 37 | +import org.jetbrains.kotlin.load.kotlin.PackageClassUtils.getPackageClassFqName |
| 38 | +import org.jetbrains.kotlin.load.kotlin.PackageClassUtils.getPackageClassName |
| 39 | +import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils.getPackagePartFqName |
| 40 | + |
| 41 | +public class JetExceptionFilterTest : MultiFileTestCase() { |
| 42 | + private var rootDir: VirtualFile? = null |
| 43 | + |
| 44 | + throws(Exception::class) |
| 45 | + override fun tearDown() { |
| 46 | + rootDir = null |
| 47 | + super.tearDown() |
50 | 48 | }
|
51 | 49 |
|
52 |
| - @Override |
53 |
| - @NotNull |
54 |
| - protected String getTestDataPath() { |
55 |
| - return PluginTestCaseBase.getTestDataPathBase(); |
| 50 | + override fun getTestDataPath(): String { |
| 51 | + return PluginTestCaseBase.getTestDataPathBase() |
56 | 52 | }
|
57 | 53 |
|
58 |
| - @Override |
59 |
| - @NotNull |
60 |
| - protected String getTestRoot() { |
61 |
| - return "/filters/exceptionFilter/"; |
| 54 | + override fun getTestRoot(): String { |
| 55 | + return "/filters/exceptionFilter/" |
62 | 56 | }
|
63 | 57 |
|
64 |
| - private void configure() { |
| 58 | + private fun configure() { |
65 | 59 | try {
|
66 |
| - String path = getTestDataPath() + getTestRoot() + getTestName(true); |
| 60 | + val path = getTestDataPath() + getTestRoot() + getTestName(true) |
67 | 61 |
|
68 |
| - rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, path, myFilesToDelete, false); |
69 |
| - prepareProject(rootDir); |
70 |
| - PsiDocumentManager.getInstance(myProject).commitAllDocuments(); |
| 62 | + rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, path, PlatformTestCase.myFilesToDelete, false) |
| 63 | + prepareProject(rootDir) |
| 64 | + PsiDocumentManager.getInstance(myProject).commitAllDocuments() |
71 | 65 | }
|
72 |
| - catch (Exception e) { |
73 |
| - throw UtilsPackage.rethrow(e); |
| 66 | + catch (e: Exception) { |
| 67 | + throw rethrow(e) |
74 | 68 | }
|
| 69 | + |
75 | 70 | }
|
76 | 71 |
|
77 |
| - @NotNull |
78 |
| - private static String createStackTraceElementLine(@NotNull String prefix, @NotNull String fileName, @NotNull String className, int lineNumber) { |
| 72 | + private fun createStackTraceElementLine(prefix: String, fileName: String, className: String, lineNumber: Int): String { |
79 | 73 | // Method name doesn't matter
|
80 |
| - String methodName = "foo"; |
| 74 | + val methodName = "foo" |
81 | 75 |
|
82 | 76 | // File's last name appears in stack trace
|
83 |
| - String fileLastName = new File(fileName).getName(); |
| 77 | + val fileLastName = File(fileName).getName() |
84 | 78 |
|
85 |
| - StackTraceElement element = new StackTraceElement(className, methodName, fileLastName, lineNumber); |
86 |
| - return prefix + element + "\n"; |
| 79 | + val element = StackTraceElement(className, methodName, fileLastName, lineNumber) |
| 80 | + return prefix + element + "\n" |
87 | 81 | }
|
88 | 82 |
|
89 |
| - private void doTest(@NotNull String fileName, int lineNumber, @NotNull Function1<VirtualFile, String> className) { |
90 |
| - doTest("\tat ", fileName, lineNumber, className); |
| 83 | + private fun doTest(fileName: String, lineNumber: Int, className: Function1<VirtualFile, String>) { |
| 84 | + doTest("\tat ", fileName, lineNumber, className) |
91 | 85 | }
|
92 | 86 |
|
93 |
| - private void doTest(@NotNull String linePrefix, @NotNull String fileName, int lineNumber, @NotNull Function1<VirtualFile, String> className) { |
| 87 | + private fun doTest(linePrefix: String, fileName: String, lineNumber: Int, className: Function1<VirtualFile, String>) { |
94 | 88 | if (rootDir == null) {
|
95 |
| - configure(); |
| 89 | + configure() |
96 | 90 | }
|
97 |
| - assert rootDir != null; |
| 91 | + assert(rootDir != null) |
98 | 92 |
|
99 |
| - Filter filter = new JetExceptionFilterFactory().create(GlobalSearchScope.allScope(myProject)); |
| 93 | + val filter = JetExceptionFilterFactory().create(GlobalSearchScope.allScope(myProject)) |
100 | 94 |
|
101 |
| - VirtualFile expectedFile = VfsUtilCore.findRelativeFile(fileName, rootDir); |
102 |
| - assertNotNull(expectedFile); |
| 95 | + val expectedFile = VfsUtilCore.findRelativeFile(fileName, rootDir) |
| 96 | + TestCase.assertNotNull(expectedFile) |
103 | 97 |
|
104 |
| - String line = createStackTraceElementLine(linePrefix, fileName, className.invoke(expectedFile), lineNumber); |
105 |
| - Filter.Result result = filter.applyFilter(line, 0); |
| 98 | + val line = createStackTraceElementLine(linePrefix, fileName, className.invoke(expectedFile), lineNumber) |
| 99 | + val result = filter.applyFilter(line, 0) |
106 | 100 |
|
107 |
| - assertNotNull(result); |
108 |
| - HyperlinkInfo info = result.getFirstHyperlinkInfo(); |
109 |
| - assertNotNull(info); |
110 |
| - assertInstanceOf(info, OpenFileHyperlinkInfo.class); |
111 |
| - OpenFileDescriptor descriptor = ((OpenFileHyperlinkInfo) info).getDescriptor(); |
112 |
| - assertNotNull(descriptor); |
| 101 | + TestCase.assertNotNull(result) |
| 102 | + val info = result.getFirstHyperlinkInfo() |
| 103 | + TestCase.assertNotNull(info) |
| 104 | + UsefulTestCase.assertInstanceOf(info, javaClass<OpenFileHyperlinkInfo>()) |
| 105 | + val descriptor = (info as OpenFileHyperlinkInfo).getDescriptor() |
| 106 | + TestCase.assertNotNull(descriptor) |
113 | 107 |
|
114 |
| - assertEquals(expectedFile, descriptor.getFile()); |
| 108 | + TestCase.assertEquals(expectedFile, descriptor.getFile()) |
115 | 109 |
|
116 |
| - Document document = FileDocumentManager.getInstance().getDocument(expectedFile); |
117 |
| - assertNotNull(document); |
118 |
| - int expectedOffset = document.getLineStartOffset(lineNumber - 1); |
119 |
| - assertEquals(expectedOffset, descriptor.getOffset()); |
| 110 | + val document = FileDocumentManager.getInstance().getDocument(expectedFile) |
| 111 | + TestCase.assertNotNull(document) |
| 112 | + val expectedOffset = document.getLineStartOffset(lineNumber - 1) |
| 113 | + TestCase.assertEquals(expectedOffset, descriptor.getOffset()) |
120 | 114 | }
|
121 | 115 |
|
122 |
| - public void testBreakpointReachedAt() { |
123 |
| - doTest("Breakpoint reached at ", "breakpointReachedAt.kt", 2, new Function1<VirtualFile, String>() { |
124 |
| - @Override |
125 |
| - public String invoke(VirtualFile file) { |
126 |
| - return getPackageClassName(FqName.ROOT); |
| 116 | + public fun testBreakpointReachedAt() { |
| 117 | + doTest("Breakpoint reached at ", "breakpointReachedAt.kt", 2, object : Function1<VirtualFile, String> { |
| 118 | + override fun invoke(file: VirtualFile): String { |
| 119 | + return getPackageClassName(FqName.ROOT) |
127 | 120 | }
|
128 |
| - }); |
| 121 | + }) |
129 | 122 | }
|
130 | 123 |
|
131 |
| - public void testSimple() { |
132 |
| - doTest("simple.kt", 2, new Function1<VirtualFile, String>() { |
133 |
| - @Override |
134 |
| - public String invoke(VirtualFile file) { |
135 |
| - return getPackageClassName(FqName.ROOT); |
| 124 | + public fun testSimple() { |
| 125 | + doTest("simple.kt", 2, object : Function1<VirtualFile, String> { |
| 126 | + override fun invoke(file: VirtualFile): String { |
| 127 | + return getPackageClassName(FqName.ROOT) |
136 | 128 | }
|
137 |
| - }); |
| 129 | + }) |
138 | 130 | }
|
139 | 131 |
|
140 |
| - public void testKt2489() { |
141 |
| - final FqName packageClassFqName = getPackageClassFqName(FqName.ROOT); |
142 |
| - doTest("a.kt", 3, new Function1<VirtualFile, String>() { |
143 |
| - @Override |
144 |
| - public String invoke(VirtualFile file) { |
145 |
| - return getPackagePartFqName(packageClassFqName, file) + "$a$f$1"; |
| 132 | + public fun testKt2489() { |
| 133 | + val packageClassFqName = getPackageClassFqName(FqName.ROOT) |
| 134 | + doTest("a.kt", 3, object : Function1<VirtualFile, String> { |
| 135 | + override fun invoke(file: VirtualFile): String { |
| 136 | + return getPackagePartFqName(packageClassFqName, file) + "$a$f$1" |
146 | 137 | }
|
147 |
| - }); |
148 |
| - doTest("main.kt", 3, new Function1<VirtualFile, String>() { |
149 |
| - @Override |
150 |
| - public String invoke(VirtualFile file) { |
151 |
| - return getPackagePartFqName(packageClassFqName, file) + "$main$f$1"; |
| 138 | + }) |
| 139 | + doTest("main.kt", 3, object : Function1<VirtualFile, String> { |
| 140 | + override fun invoke(file: VirtualFile): String { |
| 141 | + return getPackagePartFqName(packageClassFqName, file) + "$main$f$1" |
152 | 142 | }
|
153 |
| - }); |
| 143 | + }) |
154 | 144 | }
|
155 | 145 |
|
156 |
| - public void testMultiSameName() { |
157 |
| - final FqName packageClassFqName = getPackageClassFqName(new FqName("multiSameName")); |
| 146 | + public fun testMultiSameName() { |
| 147 | + val packageClassFqName = getPackageClassFqName(FqName("multiSameName")) |
158 | 148 | // The order and the exact names do matter here
|
159 |
| - doTest("1/foo.kt", 4, new Function1<VirtualFile, String>() { |
160 |
| - @Override |
161 |
| - public String invoke(VirtualFile file) { |
162 |
| - return getPackagePartFqName(packageClassFqName, file) + "$foo$f$1"; |
| 149 | + doTest("1/foo.kt", 4, object : Function1<VirtualFile, String> { |
| 150 | + override fun invoke(file: VirtualFile): String { |
| 151 | + return getPackagePartFqName(packageClassFqName, file) + "$foo$f$1" |
163 | 152 | }
|
164 |
| - }); |
165 |
| - doTest("2/foo.kt", 4, new Function1<VirtualFile, String>() { |
166 |
| - @Override |
167 |
| - public String invoke(VirtualFile file) { |
168 |
| - return getPackagePartFqName(packageClassFqName, file) + "$foo$f$1"; |
| 153 | + }) |
| 154 | + doTest("2/foo.kt", 4, object : Function1<VirtualFile, String> { |
| 155 | + override fun invoke(file: VirtualFile): String { |
| 156 | + return getPackagePartFqName(packageClassFqName, file) + "$foo$f$1" |
169 | 157 | }
|
170 |
| - }); |
| 158 | + }) |
171 | 159 | }
|
172 | 160 | }
|
0 commit comments