Ilya Ryzhenkov | 8a4dad4 | 2014-07-11 20:41:53 +0400 | [diff] [blame] | 1 | package org.jetbrains.dokka.tests |
Ilya Ryzhenkov | 044e1b8 | 2014-07-11 17:11:35 +0400 | [diff] [blame] | 2 | |
Dmitry Jemerov | 84ea5c6 | 2015-11-04 16:26:07 +0100 | [diff] [blame] | 3 | import com.google.inject.Guice |
Dmitry Jemerov | 69dd298 | 2014-12-30 18:47:03 +0100 | [diff] [blame] | 4 | import com.intellij.openapi.application.PathManager |
Dmitry Jemerov | bc0654e | 2015-05-27 19:26:13 +0200 | [diff] [blame] | 5 | import com.intellij.openapi.util.Disposer |
Dmitry Jemerov | f724ba6 | 2015-11-03 19:36:48 +0100 | [diff] [blame] | 6 | import com.intellij.openapi.util.io.FileUtil |
Simon Ogorodnik | 0fccc3f | 2017-03-23 16:35:10 +0300 | [diff] [blame] | 7 | import com.intellij.rt.execution.junit.FileComparisonFailure |
Dmitry Jemerov | bc0654e | 2015-05-27 19:26:13 +0200 | [diff] [blame] | 8 | import org.jetbrains.dokka.* |
Dmitry Jemerov | 2bd8bdf | 2017-02-22 17:29:39 +0100 | [diff] [blame] | 9 | import org.jetbrains.dokka.Utilities.DokkaAnalysisModule |
Dmitry Jemerov | bc0654e | 2015-05-27 19:26:13 +0200 | [diff] [blame] | 10 | import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation |
| 11 | import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity |
| 12 | import org.jetbrains.kotlin.cli.common.messages.MessageCollector |
| 13 | import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot |
| 14 | import org.jetbrains.kotlin.config.ContentRoot |
| 15 | import org.jetbrains.kotlin.config.KotlinSourceRoot |
Dmitry Jemerov | edb0d90 | 2017-02-24 10:51:22 +0100 | [diff] [blame] | 16 | import org.jetbrains.kotlin.descriptors.DeclarationDescriptor |
Dmitry Jemerov | 7fbff24 | 2015-01-09 18:54:06 +0100 | [diff] [blame] | 17 | import org.junit.Assert |
Dmitry Jemerov | 74fa763 | 2016-01-25 13:56:01 +0100 | [diff] [blame] | 18 | import org.junit.Assert.fail |
Dmitry Jemerov | bc0654e | 2015-05-27 19:26:13 +0200 | [diff] [blame] | 19 | import java.io.File |
Ilya Ryzhenkov | 044e1b8 | 2014-07-11 17:11:35 +0400 | [diff] [blame] | 20 | |
Dmitry Jemerov | b96aaa5 | 2016-06-30 17:36:22 +0200 | [diff] [blame] | 21 | fun verifyModel(vararg roots: ContentRoot, |
| 22 | withJdk: Boolean = false, |
| 23 | withKotlinRuntime: Boolean = false, |
| 24 | format: String = "html", |
| 25 | includeNonPublic: Boolean = true, |
Chris Rankin | f941d6a | 2017-10-06 14:14:09 +0100 | [diff] [blame] | 26 | perPackageOptions: List<DokkaConfiguration.PackageOptions> = emptyList(), |
Simon Ogorodnik | 9e65c3d | 2018-01-11 22:22:36 +0300 | [diff] [blame] | 27 | noStdlibLink: Boolean = true, |
Simon Ogorodnik | bf2945d | 2018-01-17 20:01:20 +0300 | [diff] [blame^] | 28 | collectInheritedExtensionsFromLibraries: Boolean = false, |
Dmitry Jemerov | b96aaa5 | 2016-06-30 17:36:22 +0200 | [diff] [blame] | 29 | verifier: (DocumentationModule) -> Unit) { |
Dmitry Jemerov | a39c7a1 | 2017-02-23 15:21:03 +0100 | [diff] [blame] | 30 | val documentation = DocumentationModule("test") |
Dmitry Jemerov | ff8fdb0 | 2017-02-23 19:08:31 +0100 | [diff] [blame] | 31 | |
Simon Ogorodnik | 13c4cb9 | 2017-11-27 16:05:59 +0300 | [diff] [blame] | 32 | val options = DocumentationOptions( |
Simon Ogorodnik | bf2945d | 2018-01-17 20:01:20 +0300 | [diff] [blame^] | 33 | "", |
| 34 | format, |
| 35 | includeNonPublic = includeNonPublic, |
| 36 | skipEmptyPackages = false, |
| 37 | includeRootPackage = true, |
| 38 | sourceLinks = listOf(), |
| 39 | perPackageOptions = perPackageOptions, |
| 40 | generateIndexPages = false, |
| 41 | noStdlibLink = noStdlibLink, |
| 42 | cacheRoot = "default", |
| 43 | languageVersion = null, |
| 44 | apiVersion = null, |
| 45 | collectInheritedExtensionsFromLibraries = collectInheritedExtensionsFromLibraries |
Simon Ogorodnik | 13c4cb9 | 2017-11-27 16:05:59 +0300 | [diff] [blame] | 46 | ) |
Dmitry Jemerov | ff8fdb0 | 2017-02-23 19:08:31 +0100 | [diff] [blame] | 47 | |
Dmitry Jemerov | a39c7a1 | 2017-02-23 15:21:03 +0100 | [diff] [blame] | 48 | appendDocumentation(documentation, *roots, |
| 49 | withJdk = withJdk, |
| 50 | withKotlinRuntime = withKotlinRuntime, |
Dmitry Jemerov | ff8fdb0 | 2017-02-23 19:08:31 +0100 | [diff] [blame] | 51 | options = options) |
| 52 | documentation.prepareForGeneration(options) |
| 53 | |
Dmitry Jemerov | a39c7a1 | 2017-02-23 15:21:03 +0100 | [diff] [blame] | 54 | verifier(documentation) |
| 55 | } |
| 56 | |
| 57 | fun appendDocumentation(documentation: DocumentationModule, |
| 58 | vararg roots: ContentRoot, |
| 59 | withJdk: Boolean = false, |
| 60 | withKotlinRuntime: Boolean = false, |
Dmitry Jemerov | ff8fdb0 | 2017-02-23 19:08:31 +0100 | [diff] [blame] | 61 | options: DocumentationOptions, |
Dmitry Jemerov | 64a8684 | 2017-02-23 17:05:32 +0100 | [diff] [blame] | 62 | defaultPlatforms: List<String> = emptyList()) { |
Ilya Ryzhenkov | 044e1b8 | 2014-07-11 17:11:35 +0400 | [diff] [blame] | 63 | val messageCollector = object : MessageCollector { |
Simon Ogorodnik | c4cf001 | 2016-11-03 19:25:09 +0300 | [diff] [blame] | 64 | override fun clear() { |
| 65 | |
| 66 | } |
| 67 | |
Simon Ogorodnik | 4810d07 | 2017-06-26 15:25:09 +0300 | [diff] [blame] | 68 | override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) { |
Ilya Ryzhenkov | 044e1b8 | 2014-07-11 17:11:35 +0400 | [diff] [blame] | 69 | when (severity) { |
Simon Ogorodnik | 4810d07 | 2017-06-26 15:25:09 +0300 | [diff] [blame] | 70 | CompilerMessageSeverity.STRONG_WARNING, |
Ilya Ryzhenkov | 044e1b8 | 2014-07-11 17:11:35 +0400 | [diff] [blame] | 71 | CompilerMessageSeverity.WARNING, |
| 72 | CompilerMessageSeverity.LOGGING, |
| 73 | CompilerMessageSeverity.OUTPUT, |
| 74 | CompilerMessageSeverity.INFO, |
| 75 | CompilerMessageSeverity.ERROR -> { |
| 76 | println("$severity: $message at $location") |
| 77 | } |
| 78 | CompilerMessageSeverity.EXCEPTION -> { |
| 79 | fail("$severity: $message at $location") |
| 80 | } |
| 81 | } |
| 82 | } |
Dmitry Jemerov | 95a606f | 2016-07-08 12:55:26 +0200 | [diff] [blame] | 83 | |
| 84 | override fun hasErrors() = false |
Ilya Ryzhenkov | 044e1b8 | 2014-07-11 17:11:35 +0400 | [diff] [blame] | 85 | } |
| 86 | |
Dmitry Jemerov | 3655b70 | 2015-11-04 14:09:53 +0100 | [diff] [blame] | 87 | val environment = AnalysisEnvironment(messageCollector) |
| 88 | environment.apply { |
Dmitry Jemerov | 47ccfb0 | 2015-10-28 12:15:40 +0100 | [diff] [blame] | 89 | if (withJdk || withKotlinRuntime) { |
| 90 | val stringRoot = PathManager.getResourceRoot(String::class.java, "/java/lang/String.class") |
| 91 | addClasspath(File(stringRoot)) |
| 92 | } |
| 93 | if (withKotlinRuntime) { |
Dmitry Jemerov | 39fefdc | 2016-05-10 18:06:35 +0200 | [diff] [blame] | 94 | val kotlinStrictfpRoot = PathManager.getResourceRoot(Strictfp::class.java, "/kotlin/jvm/Strictfp.class") |
| 95 | addClasspath(File(kotlinStrictfpRoot)) |
Dmitry Jemerov | 47ccfb0 | 2015-10-28 12:15:40 +0100 | [diff] [blame] | 96 | } |
Dmitry Jemerov | bc0654e | 2015-05-27 19:26:13 +0200 | [diff] [blame] | 97 | addRoots(roots.toList()) |
Simon Ogorodnik | 13c4cb9 | 2017-11-27 16:05:59 +0300 | [diff] [blame] | 98 | |
| 99 | loadLanguageVersionSettings(options.languageVersion, options.apiVersion) |
Ilya Ryzhenkov | 044e1b8 | 2014-07-11 17:11:35 +0400 | [diff] [blame] | 100 | } |
Dmitry Jemerov | edb0d90 | 2017-02-24 10:51:22 +0100 | [diff] [blame] | 101 | val defaultPlatformsProvider = object : DefaultPlatformsProvider { |
| 102 | override fun getDefaultPlatforms(descriptor: DeclarationDescriptor) = defaultPlatforms |
| 103 | } |
Dmitry Jemerov | 99689ad | 2017-02-23 16:35:45 +0100 | [diff] [blame] | 104 | val injector = Guice.createInjector( |
Dmitry Jemerov | edb0d90 | 2017-02-24 10:51:22 +0100 | [diff] [blame] | 105 | DokkaAnalysisModule(environment, options, defaultPlatformsProvider, documentation.nodeRefGraph, DokkaConsoleLogger)) |
Dmitry Jemerov | 2bd8bdf | 2017-02-22 17:29:39 +0100 | [diff] [blame] | 106 | buildDocumentationModule(injector, documentation) |
Ilya Ryzhenkov | 044e1b8 | 2014-07-11 17:11:35 +0400 | [diff] [blame] | 107 | Disposer.dispose(environment) |
| 108 | } |
| 109 | |
Dmitry Jemerov | b96aaa5 | 2016-06-30 17:36:22 +0200 | [diff] [blame] | 110 | fun verifyModel(source: String, |
| 111 | withJdk: Boolean = false, |
| 112 | withKotlinRuntime: Boolean = false, |
| 113 | format: String = "html", |
| 114 | includeNonPublic: Boolean = true, |
| 115 | verifier: (DocumentationModule) -> Unit) { |
Dmitry Jemerov | b643bf6 | 2015-11-05 15:51:23 +0100 | [diff] [blame] | 116 | if (!File(source).exists()) { |
| 117 | throw IllegalArgumentException("Can't find test data file $source") |
| 118 | } |
Dmitry Jemerov | e4b2ae9 | 2015-10-30 18:43:48 +0100 | [diff] [blame] | 119 | verifyModel(contentRootFromPath(source), |
| 120 | withJdk = withJdk, |
| 121 | withKotlinRuntime = withKotlinRuntime, |
Dmitry Jemerov | 84ea5c6 | 2015-11-04 16:26:07 +0100 | [diff] [blame] | 122 | format = format, |
Dmitry Jemerov | b96aaa5 | 2016-06-30 17:36:22 +0200 | [diff] [blame] | 123 | includeNonPublic = includeNonPublic, |
Dmitry Jemerov | e4b2ae9 | 2015-10-30 18:43:48 +0100 | [diff] [blame] | 124 | verifier = verifier) |
Dmitry Jemerov | bc0654e | 2015-05-27 19:26:13 +0200 | [diff] [blame] | 125 | } |
| 126 | |
Dmitry Jemerov | b96aaa5 | 2016-06-30 17:36:22 +0200 | [diff] [blame] | 127 | fun verifyPackageMember(source: String, |
| 128 | withJdk: Boolean = false, |
| 129 | withKotlinRuntime: Boolean = false, |
| 130 | verifier: (DocumentationNode) -> Unit) { |
Dmitry Jemerov | f724ba6 | 2015-11-03 19:36:48 +0100 | [diff] [blame] | 131 | verifyModel(source, withJdk = withJdk, withKotlinRuntime = withKotlinRuntime) { model -> |
| 132 | val pkg = model.members.single() |
| 133 | verifier(pkg.members.single()) |
| 134 | } |
| 135 | } |
| 136 | |
Dmitry Jemerov | b96aaa5 | 2016-06-30 17:36:22 +0200 | [diff] [blame] | 137 | fun verifyJavaModel(source: String, |
| 138 | withKotlinRuntime: Boolean = false, |
| 139 | verifier: (DocumentationModule) -> Unit) { |
Dmitry Jemerov | f724ba6 | 2015-11-03 19:36:48 +0100 | [diff] [blame] | 140 | val tempDir = FileUtil.createTempDirectory("dokka", "") |
| 141 | try { |
| 142 | val sourceFile = File(source) |
| 143 | FileUtil.copy(sourceFile, File(tempDir, sourceFile.name)) |
Dmitry Jemerov | 64946ea | 2015-11-16 19:45:45 +0100 | [diff] [blame] | 144 | verifyModel(JavaSourceRoot(tempDir, null), withJdk = true, withKotlinRuntime = withKotlinRuntime, verifier = verifier) |
Dmitry Jemerov | f724ba6 | 2015-11-03 19:36:48 +0100 | [diff] [blame] | 145 | } |
| 146 | finally { |
| 147 | FileUtil.delete(tempDir) |
| 148 | } |
| 149 | } |
| 150 | |
Dmitry Jemerov | b96aaa5 | 2016-06-30 17:36:22 +0200 | [diff] [blame] | 151 | fun verifyJavaPackageMember(source: String, |
| 152 | withKotlinRuntime: Boolean = false, |
| 153 | verifier: (DocumentationNode) -> Unit) { |
Dmitry Jemerov | f724ba6 | 2015-11-03 19:36:48 +0100 | [diff] [blame] | 154 | verifyJavaModel(source, withKotlinRuntime) { model -> |
Dmitry Jemerov | aa3f051 | 2015-02-13 17:04:58 +0100 | [diff] [blame] | 155 | val pkg = model.members.single() |
| 156 | verifier(pkg.members.single()) |
| 157 | } |
| 158 | } |
| 159 | |
Dmitry Jemerov | b96aaa5 | 2016-06-30 17:36:22 +0200 | [diff] [blame] | 160 | fun verifyOutput(roots: Array<ContentRoot>, |
| 161 | outputExtension: String, |
| 162 | withJdk: Boolean = false, |
| 163 | withKotlinRuntime: Boolean = false, |
Simon Ogorodnik | 47790d1 | 2016-11-14 18:08:17 +0300 | [diff] [blame] | 164 | format: String = "html", |
Simon Ogorodnik | 46af59c | 2017-11-21 18:58:06 +0300 | [diff] [blame] | 165 | includeNonPublic: Boolean = true, |
Simon Ogorodnik | 9e65c3d | 2018-01-11 22:22:36 +0300 | [diff] [blame] | 166 | noStdlibLink: Boolean = true, |
Simon Ogorodnik | bf2945d | 2018-01-17 20:01:20 +0300 | [diff] [blame^] | 167 | collectInheritedExtensionsFromLibraries: Boolean = false, |
Dmitry Jemerov | b96aaa5 | 2016-06-30 17:36:22 +0200 | [diff] [blame] | 168 | outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { |
Simon Ogorodnik | 46af59c | 2017-11-21 18:58:06 +0300 | [diff] [blame] | 169 | verifyModel( |
Simon Ogorodnik | 9e65c3d | 2018-01-11 22:22:36 +0300 | [diff] [blame] | 170 | *roots, |
| 171 | withJdk = withJdk, |
| 172 | withKotlinRuntime = withKotlinRuntime, |
| 173 | format = format, |
| 174 | includeNonPublic = includeNonPublic, |
Simon Ogorodnik | bf2945d | 2018-01-17 20:01:20 +0300 | [diff] [blame^] | 175 | noStdlibLink = noStdlibLink, |
| 176 | collectInheritedExtensionsFromLibraries = collectInheritedExtensionsFromLibraries |
Simon Ogorodnik | 46af59c | 2017-11-21 18:58:06 +0300 | [diff] [blame] | 177 | ) { |
Dmitry Jemerov | a39c7a1 | 2017-02-23 15:21:03 +0100 | [diff] [blame] | 178 | verifyModelOutput(it, outputExtension, roots.first().path, outputGenerator) |
Dmitry Jemerov | c43a437 | 2014-12-29 20:22:43 +0100 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | |
Dmitry Jemerov | a39c7a1 | 2017-02-23 15:21:03 +0100 | [diff] [blame] | 182 | fun verifyModelOutput(it: DocumentationModule, |
| 183 | outputExtension: String, |
| 184 | sourcePath: String, |
| 185 | outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { |
Dmitry Jemerov | f724ba6 | 2015-11-03 19:36:48 +0100 | [diff] [blame] | 186 | val output = StringBuilder() |
| 187 | outputGenerator(it, output) |
| 188 | val ext = outputExtension.removePrefix(".") |
Simon Ogorodnik | 0fccc3f | 2017-03-23 16:35:10 +0300 | [diff] [blame] | 189 | val expectedFile = File(sourcePath.replaceAfterLast(".", ext, sourcePath + "." + ext)) |
| 190 | assertEqualsIgnoringSeparators(expectedFile, output.toString()) |
Dmitry Jemerov | f724ba6 | 2015-11-03 19:36:48 +0100 | [diff] [blame] | 191 | } |
| 192 | |
Simon Ogorodnik | 9e65c3d | 2018-01-11 22:22:36 +0300 | [diff] [blame] | 193 | fun verifyOutput( |
| 194 | path: String, |
| 195 | outputExtension: String, |
| 196 | withJdk: Boolean = false, |
| 197 | withKotlinRuntime: Boolean = false, |
| 198 | format: String = "html", |
| 199 | includeNonPublic: Boolean = true, |
| 200 | noStdlibLink: Boolean = true, |
Simon Ogorodnik | bf2945d | 2018-01-17 20:01:20 +0300 | [diff] [blame^] | 201 | collectInheritedExtensionsFromLibraries: Boolean = false, |
Simon Ogorodnik | 9e65c3d | 2018-01-11 22:22:36 +0300 | [diff] [blame] | 202 | outputGenerator: (DocumentationModule, StringBuilder) -> Unit |
| 203 | ) { |
Simon Ogorodnik | 46af59c | 2017-11-21 18:58:06 +0300 | [diff] [blame] | 204 | verifyOutput( |
Simon Ogorodnik | 9e65c3d | 2018-01-11 22:22:36 +0300 | [diff] [blame] | 205 | arrayOf(contentRootFromPath(path)), |
| 206 | outputExtension, |
| 207 | withJdk, |
| 208 | withKotlinRuntime, |
| 209 | format, |
| 210 | includeNonPublic, |
| 211 | noStdlibLink, |
Simon Ogorodnik | bf2945d | 2018-01-17 20:01:20 +0300 | [diff] [blame^] | 212 | collectInheritedExtensionsFromLibraries, |
Simon Ogorodnik | 9e65c3d | 2018-01-11 22:22:36 +0300 | [diff] [blame] | 213 | outputGenerator |
Simon Ogorodnik | 46af59c | 2017-11-21 18:58:06 +0300 | [diff] [blame] | 214 | ) |
Dmitry Jemerov | bc0654e | 2015-05-27 19:26:13 +0200 | [diff] [blame] | 215 | } |
| 216 | |
Dmitry Jemerov | b96aaa5 | 2016-06-30 17:36:22 +0200 | [diff] [blame] | 217 | fun verifyJavaOutput(path: String, |
| 218 | outputExtension: String, |
| 219 | withKotlinRuntime: Boolean = false, |
| 220 | outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { |
Dmitry Jemerov | f724ba6 | 2015-11-03 19:36:48 +0100 | [diff] [blame] | 221 | verifyJavaModel(path, withKotlinRuntime) { model -> |
Dmitry Jemerov | a39c7a1 | 2017-02-23 15:21:03 +0100 | [diff] [blame] | 222 | verifyModelOutput(model, outputExtension, path, outputGenerator) |
Dmitry Jemerov | f724ba6 | 2015-11-03 19:36:48 +0100 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
Simon Ogorodnik | 0fccc3f | 2017-03-23 16:35:10 +0300 | [diff] [blame] | 226 | fun assertEqualsIgnoringSeparators(expectedFile: File, output: String) { |
Simon Ogorodnik | fff865c | 2017-06-05 18:28:49 +0300 | [diff] [blame] | 227 | if (!expectedFile.exists()) expectedFile.createNewFile() |
Simon Ogorodnik | 0fccc3f | 2017-03-23 16:35:10 +0300 | [diff] [blame] | 228 | val expectedText = expectedFile.readText().replace("\r\n", "\n") |
| 229 | val actualText = output.replace("\r\n", "\n") |
| 230 | |
| 231 | if(expectedText != actualText) |
| 232 | throw FileComparisonFailure("", expectedText, actualText, expectedFile.canonicalPath) |
| 233 | } |
| 234 | |
Dmitry Jemerov | b96aaa5 | 2016-06-30 17:36:22 +0200 | [diff] [blame] | 235 | fun assertEqualsIgnoringSeparators(expectedOutput: String, output: String) { |
Dmitry Jemerov | 599f32d | 2015-01-22 11:30:57 +0100 | [diff] [blame] | 236 | Assert.assertEquals(expectedOutput.replace("\r\n", "\n"), output.replace("\r\n", "\n")) |
| 237 | } |
| 238 | |
Dmitry Jemerov | 0d0fc1f | 2015-02-10 18:32:12 +0100 | [diff] [blame] | 239 | fun StringBuilder.appendChildren(node: ContentBlock): StringBuilder { |
Ilya Ryzhenkov | 778e2b3 | 2014-09-29 20:54:59 +0400 | [diff] [blame] | 240 | for (child in node.children) { |
| 241 | val childText = child.toTestString() |
| 242 | append(childText) |
| 243 | } |
| 244 | return this |
| 245 | } |
| 246 | |
Ilya Ryzhenkov | 11355ce | 2014-10-12 22:35:47 +0400 | [diff] [blame] | 247 | fun StringBuilder.appendNode(node: ContentNode): StringBuilder { |
Ilya Ryzhenkov | 778e2b3 | 2014-09-29 20:54:59 +0400 | [diff] [blame] | 248 | when (node) { |
| 249 | is ContentText -> { |
| 250 | append(node.text) |
| 251 | } |
| 252 | is ContentEmphasis -> append("*").appendChildren(node).append("*") |
Ilya Ryzhenkov | 1b5f12b | 2014-12-22 20:01:01 +0300 | [diff] [blame] | 253 | is ContentBlockCode -> { |
Simon Ogorodnik | 7922e2a | 2016-11-01 20:31:16 +0300 | [diff] [blame] | 254 | if (node.language.isNotBlank()) |
| 255 | appendln("[code lang=${node.language}]") |
| 256 | else |
| 257 | appendln("[code]") |
Ilya Ryzhenkov | 1b5f12b | 2014-12-22 20:01:01 +0300 | [diff] [blame] | 258 | appendChildren(node) |
| 259 | appendln() |
| 260 | appendln("[/code]") |
| 261 | } |
Ilya Ryzhenkov | bd6cddd | 2014-12-16 21:41:32 +0300 | [diff] [blame] | 262 | is ContentNodeLink -> { |
| 263 | append("[") |
| 264 | appendChildren(node) |
| 265 | append(" -> ") |
| 266 | append(node.node.toString()) |
| 267 | append("]") |
| 268 | } |
Dmitry Jemerov | 0d0fc1f | 2015-02-10 18:32:12 +0100 | [diff] [blame] | 269 | is ContentBlock -> { |
Ilya Ryzhenkov | 778e2b3 | 2014-09-29 20:54:59 +0400 | [diff] [blame] | 270 | appendChildren(node) |
| 271 | } |
Dmitry Jemerov | ded5696 | 2015-10-30 19:33:29 +0100 | [diff] [blame] | 272 | is ContentEmpty -> { /* nothing */ } |
Dmitry Jemerov | 0d0fc1f | 2015-02-10 18:32:12 +0100 | [diff] [blame] | 273 | else -> throw IllegalStateException("Don't know how to format node $node") |
Ilya Ryzhenkov | 778e2b3 | 2014-09-29 20:54:59 +0400 | [diff] [blame] | 274 | } |
| 275 | return this |
| 276 | } |
| 277 | |
| 278 | fun ContentNode.toTestString(): String { |
| 279 | val node = this |
Ilya Ryzhenkov | a76e5a6 | 2015-10-22 19:18:07 +0300 | [diff] [blame] | 280 | return StringBuilder().apply { |
Ilya Ryzhenkov | 778e2b3 | 2014-09-29 20:54:59 +0400 | [diff] [blame] | 281 | appendNode(node) |
| 282 | }.toString() |
| 283 | } |
Dmitry Jemerov | c43a437 | 2014-12-29 20:22:43 +0100 | [diff] [blame] | 284 | |
Dmitry Jemerov | bc0654e | 2015-05-27 19:26:13 +0200 | [diff] [blame] | 285 | val ContentRoot.path: String |
| 286 | get() = when(this) { |
| 287 | is KotlinSourceRoot -> path |
| 288 | is JavaSourceRoot -> file.path |
| 289 | else -> throw UnsupportedOperationException() |
| 290 | } |