Skip to content

Commit 0d1b3ac

Browse files
yissacharautonomousapps
authored andcommitted
Rename exception to be more generic
1 parent 1cd916f commit 0d1b3ac

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

core/src/main/kotlin/cash/grammar/kotlindsl/parse/BuildScriptParseException.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package cash.grammar.kotlindsl.parse
2+
3+
public class KotlinParseException private constructor(msg: String) : RuntimeException(msg) {
4+
5+
public companion object {
6+
public fun withErrors(messages: List<String>): KotlinParseException {
7+
var i = 1
8+
val msg = messages.joinToString { "${i++}: $it" }
9+
return KotlinParseException(msg)
10+
}
11+
}
12+
}

core/src/main/kotlin/cash/grammar/kotlindsl/utils/BlockRemover.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cash.grammar.kotlindsl.utils
22

33
import cash.grammar.kotlindsl.model.RemovableBlock
4-
import cash.grammar.kotlindsl.parse.BuildScriptParseException
4+
import cash.grammar.kotlindsl.parse.KotlinParseException
55
import cash.grammar.kotlindsl.parse.Parser
66
import cash.grammar.kotlindsl.parse.Rewriter
77
import cash.grammar.kotlindsl.utils.Whitespace.trimGently
@@ -28,10 +28,10 @@ public class BlockRemover private constructor(
2828
private val rewriter = Rewriter(tokens)
2929
private var terminalNewlines = 0
3030

31-
@Throws(BuildScriptParseException::class)
31+
@Throws(KotlinParseException::class)
3232
public fun rewritten(): String {
3333
errorListener.getErrorMessages().ifNotEmpty {
34-
throw BuildScriptParseException.withErrors(it)
34+
throw KotlinParseException.withErrors(it)
3535
}
3636

3737
return rewriter.text.trimGently(terminalNewlines)

recipes/plugins/src/main/kotlin/cash/recipes/plugins/PluginMutator.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cash.recipes.plugins
22

33
import cash.grammar.kotlindsl.model.Plugin
4-
import cash.grammar.kotlindsl.parse.BuildScriptParseException
4+
import cash.grammar.kotlindsl.parse.KotlinParseException
55
import cash.grammar.kotlindsl.parse.Parser
66
import cash.grammar.kotlindsl.parse.Rewriter
77
import cash.grammar.kotlindsl.utils.Blocks.isPlugins
@@ -37,7 +37,7 @@ import java.nio.file.Path
3737
*
3838
* @throws NonNormalizedScriptException if the script has not been normalized.
3939
* @throws IllegalArgumentException if conflicting plugins are found in both the pluginsToAdd and pluginsToRemove sets.
40-
* @throws BuildScriptParseException if the script cannot be parsed.
40+
* @throws KotlinParseException if the script cannot be parsed.
4141
*/
4242
public class PluginMutator private constructor(
4343
private val tokens: CommonTokenStream,
@@ -57,10 +57,10 @@ public class PluginMutator private constructor(
5757

5858
public fun getPluginIds(): Set<String> = pluginIds
5959

60-
@Throws(BuildScriptParseException::class, NonNormalizedScriptException::class)
60+
@Throws(KotlinParseException::class, NonNormalizedScriptException::class)
6161
public fun rewritten(): String {
6262
errorListener.getErrorMessages().ifNotEmpty {
63-
throw BuildScriptParseException.withErrors(it)
63+
throw KotlinParseException.withErrors(it)
6464
}
6565

6666
return rewriter.text.trimGently(terminalNewlines)

recipes/plugins/src/main/kotlin/cash/recipes/plugins/PluginNormalizer.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package cash.recipes.plugins
22

33
import cash.grammar.kotlindsl.model.Plugin
44
import cash.grammar.kotlindsl.model.Plugin.Type
5-
import cash.grammar.kotlindsl.parse.BuildScriptParseException
5+
import cash.grammar.kotlindsl.parse.KotlinParseException
66
import cash.grammar.kotlindsl.parse.Parser
77
import cash.grammar.kotlindsl.parse.Rewriter
88
import cash.grammar.kotlindsl.utils.Blocks.isBuildscript
@@ -72,10 +72,10 @@ public class PluginNormalizer private constructor(
7272
// Is this an empty script?
7373
private var empty = true
7474

75-
@Throws(BuildScriptParseException::class)
75+
@Throws(KotlinParseException::class)
7676
public fun rewritten(): String {
7777
errorListener.getErrorMessages().ifNotEmpty {
78-
throw BuildScriptParseException.withErrors(it)
78+
throw KotlinParseException.withErrors(it)
7979
}
8080

8181
return rewriter.text.trimGently(terminalNewlines)

recipes/repos/src/main/kotlin/cash/recipes/repos/DependencyResolutionManagementAdder.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cash.recipes.repos
22

3-
import cash.grammar.kotlindsl.parse.BuildScriptParseException
3+
import cash.grammar.kotlindsl.parse.KotlinParseException
44
import cash.grammar.kotlindsl.parse.Parser
55
import cash.grammar.kotlindsl.utils.Blocks.isDependencyResolutionManagement
66
import cash.grammar.kotlindsl.utils.Blocks.isPlugins
@@ -53,10 +53,10 @@ public class DependencyResolutionManagementAdder private constructor(
5353

5454
private val rewriter = TokenStreamRewriter(tokens)
5555

56-
@Throws(BuildScriptParseException::class, AlreadyHasBlockException::class)
56+
@Throws(KotlinParseException::class, AlreadyHasBlockException::class)
5757
public fun rewritten(): String {
5858
errorListener.getErrorMessages().ifNotEmpty {
59-
throw BuildScriptParseException.withErrors(it)
59+
throw KotlinParseException.withErrors(it)
6060
}
6161

6262
if (alreadyHasBlock) {

recipes/repos/src/main/kotlin/cash/recipes/repos/RepositoriesDeleter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cash.recipes.repos
22

3-
import cash.grammar.kotlindsl.parse.BuildScriptParseException
3+
import cash.grammar.kotlindsl.parse.KotlinParseException
44
import cash.grammar.kotlindsl.parse.Parser
55
import cash.grammar.kotlindsl.parse.Rewriter
66
import cash.grammar.kotlindsl.utils.Blocks
@@ -66,10 +66,10 @@ public class RepositoriesDeleter private constructor(
6666
private var terminalNewlines = 0
6767
private val blockStack = ArrayDeque<NamedBlockContext>()
6868

69-
@Throws(BuildScriptParseException::class)
69+
@Throws(KotlinParseException::class)
7070
public fun rewritten(): String {
7171
errorListener.getErrorMessages().ifNotEmpty {
72-
throw BuildScriptParseException.withErrors(it)
72+
throw KotlinParseException.withErrors(it)
7373
}
7474

7575
return rewriter.text.trimGently(terminalNewlines)

0 commit comments

Comments
 (0)