Skip to content

Commit 390e48f

Browse files
authored
Merge pull request #388 from FWDekker/uds
Basic unified data syntax implementation
2 parents f06f8a3 + 705ab28 commit 390e48f

File tree

11 files changed

+854
-3
lines changed

11 files changed

+854
-3
lines changed

.config/detekt/.detekt.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ style:
5757
# Such comments are OK.
5858
ForbiddenComment:
5959
active: false
60+
# One more is fine in my opinion.
61+
LoopWithTooManyJumpStatements:
62+
maxJumpCount: 2
6063
# No braces are easier to read.
6164
MandatoryBracesIfStatements:
6265
active: false

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group = com.fwdekker
2-
version = 2.7.3-dev
2+
version = 3.0.0-dev
33

44
# Compatibility
55
# * If latest is 20xx.y, then support at least [20xx-1].[y+1].

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
zipStoreBase=GRADLE_USER_HOME
44
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip

src/main/kotlin/com/fwdekker/randomness/DataActions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ abstract class DataInsertAction(private val icon: Icon) : AnAction() {
262262
} catch (e: TimeoutException) {
263263
throw DataGenerationException("Timed out while generating data.", e)
264264
} catch (e: ExecutionException) {
265-
throw DataGenerationException(e.message, e)
265+
throw DataGenerationException(e.cause?.message ?: e.message, e)
266266
} finally {
267267
executor.shutdown()
268268
}

src/main/kotlin/com/fwdekker/randomness/PopupAction.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import com.fwdekker.randomness.integer.IntegerGroupAction
77
import com.fwdekker.randomness.integer.IntegerSettingsAction
88
import com.fwdekker.randomness.string.StringGroupAction
99
import com.fwdekker.randomness.string.StringSettingsAction
10+
import com.fwdekker.randomness.uds.UDSGroupAction
11+
import com.fwdekker.randomness.uds.UDSSettingsAction
1012
import com.fwdekker.randomness.ui.registerModifierActions
1113
import com.fwdekker.randomness.uuid.UuidGroupAction
1214
import com.fwdekker.randomness.uuid.UuidSettingsAction
@@ -115,6 +117,7 @@ class PopupAction : AnAction() {
115117
StringGroupAction(),
116118
WordGroupAction(),
117119
UuidGroupAction(),
120+
UDSGroupAction(),
118121
Separator(),
119122
ArraySettingsAction()
120123
)
@@ -136,6 +139,7 @@ class PopupAction : AnAction() {
136139
StringSettingsAction(),
137140
WordSettingsAction(),
138141
UuidSettingsAction(),
142+
UDSSettingsAction(),
139143
Separator(),
140144
ArraySettingsAction()
141145
)
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package com.fwdekker.randomness.uds
2+
3+
import com.fwdekker.randomness.DataGenerationException
4+
import com.fwdekker.randomness.DataGroupAction
5+
import com.fwdekker.randomness.DataInsertAction
6+
import com.fwdekker.randomness.DataInsertArrayAction
7+
import com.fwdekker.randomness.DataInsertRepeatAction
8+
import com.fwdekker.randomness.DataInsertRepeatArrayAction
9+
import com.fwdekker.randomness.DataQuickSwitchSchemeAction
10+
import com.fwdekker.randomness.DataSettingsAction
11+
import com.fwdekker.randomness.array.ArrayScheme
12+
import com.fwdekker.randomness.array.ArraySettings
13+
import com.fwdekker.randomness.array.ArraySettingsAction
14+
import icons.RandomnessIcons
15+
16+
17+
/**
18+
* All actions related to inserting UDS-based strings.
19+
*/
20+
class UDSGroupAction : DataGroupAction(RandomnessIcons.Data.Base) {
21+
override val insertAction = UDSInsertAction()
22+
override val insertArrayAction = UDSInsertAction.ArrayAction()
23+
override val insertRepeatAction = UDSInsertAction.RepeatAction()
24+
override val insertRepeatArrayAction = UDSInsertAction.RepeatArrayAction()
25+
override val settingsAction = UDSSettingsAction()
26+
override val quickSwitchSchemeAction = UDSSettingsAction.UDSQuickSwitchSchemeAction()
27+
override val quickSwitchArraySchemeAction = ArraySettingsAction.ArrayQuickSwitchSchemeAction()
28+
}
29+
30+
31+
/**
32+
* Inserts random arbitrary strings based on the UDS descriptor.
33+
*
34+
* @param scheme the scheme to use for generating UDS-based strings
35+
*/
36+
class UDSInsertAction(private val scheme: UDSScheme = UDSSettings.default.currentScheme) :
37+
DataInsertAction(RandomnessIcons.Data.Base) {
38+
override val name = "Random Decimal"
39+
40+
41+
/**
42+
* Returns random UDS-based strings based on the descriptor.
43+
*
44+
* @param count the number of strings to generate
45+
* @return random UDS-based strings based on the descriptor
46+
*/
47+
override fun generateStrings(count: Int) =
48+
try {
49+
UDSParser.parse(scheme.descriptor).also { it.random = this.random }.generateStrings(count)
50+
} catch (e: UDSParseException) {
51+
throw DataGenerationException(e.message, e)
52+
}
53+
54+
/**
55+
* Inserts an array-like string of UDS-based strings.
56+
*
57+
* @param arrayScheme the scheme to use for generating arrays
58+
* @param scheme the scheme to use for generating strings
59+
*/
60+
class ArrayAction(
61+
arrayScheme: ArrayScheme = ArraySettings.default.currentScheme,
62+
scheme: UDSScheme = UDSSettings.default.currentScheme
63+
) : DataInsertArrayAction(arrayScheme, UDSInsertAction(scheme), RandomnessIcons.Data.Array) {
64+
override val name = "Random UDS Array"
65+
}
66+
67+
/**
68+
* Inserts repeated random UDS-based strings.
69+
*
70+
* @param scheme the settings to use for generating strings
71+
*/
72+
class RepeatAction(scheme: UDSScheme = UDSSettings.default.currentScheme) :
73+
DataInsertRepeatAction(UDSInsertAction(scheme), RandomnessIcons.Data.Repeat) {
74+
override val name = "Random Repeated UDS"
75+
}
76+
77+
/**
78+
* Inserts repeated array-like strings of UDS-based strings.
79+
*
80+
* @param arrayScheme the scheme to use for generating arrays
81+
* @param scheme the scheme to use for generating strings
82+
*/
83+
class RepeatArrayAction(
84+
arrayScheme: ArrayScheme = ArraySettings.default.currentScheme,
85+
scheme: UDSScheme = UDSSettings.default.currentScheme
86+
) : DataInsertRepeatArrayAction(ArrayAction(arrayScheme, scheme), RandomnessIcons.Data.RepeatArray) {
87+
override val name = "Random Repeated UDS Array"
88+
}
89+
}
90+
91+
92+
/**
93+
* Controller for random string generation settings.
94+
*
95+
* @see UDSSettings
96+
* @see UDSSettingsComponent
97+
*/
98+
class UDSSettingsAction : DataSettingsAction(RandomnessIcons.Data.Settings) {
99+
override val name = "UDS Settings"
100+
101+
override val configurableClass = UDSSettingsConfigurable::class.java
102+
103+
104+
/**
105+
* Opens a popup to allow the user to quickly switch to the selected scheme.
106+
*
107+
* @param settings the settings containing the schemes that can be switched between
108+
*/
109+
class UDSQuickSwitchSchemeAction(settings: UDSSettings = UDSSettings.default) :
110+
DataQuickSwitchSchemeAction<UDSScheme>(settings, RandomnessIcons.Data.QuickSwitchScheme) {
111+
override val name = "Quick Switch UDS Scheme"
112+
}
113+
}

0 commit comments

Comments
 (0)