Skip to content

Commit de51430

Browse files
committed
fix loading of syntax style rules
1 parent 541840f commit de51430

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/main/java/org/openstreetmap/josm/plugins/scripting/ui/console/ScriptEditor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ protected void build() {
9898
Objects.requireNonNull(mimeType);
9999
var normalizedMimeType = mimeType.toLowerCase();
100100
return SyntaxConstantsEngine
101-
.getInstance().deriveSyntaxStyle(mimeType);
101+
.getInstance().deriveSyntaxStyle(normalizedMimeType);
102102
}
103103

104104
public void changeSyntaxEditingStyle(@NotNull String syntaxStyle){

src/main/java/org/openstreetmap/josm/plugins/scripting/ui/console/SyntaxConstantsEngine.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,16 @@ public static class Rules {
122122
try {
123123
return Integer.parseInt(matcher.group(1));
124124
} catch(NumberFormatException e) {
125+
logger.log(Level.FINE, MessageFormat.format(
126+
"Illegal property key ''{0}''", key
127+
), e);
125128
// shouldn't happen because of matching regexp
126129
return null;
127130
}
128131
} else {
132+
logger.log(Level.FINE, MessageFormat.format(
133+
"Illegal property key ''{0}''", key
134+
));
129135
return null;
130136
}
131137
})
@@ -134,7 +140,7 @@ public static class Rules {
134140
.collect(Collectors.toList());
135141

136142
var syntaxStyleFormat = new MessageFormat("rule.{0}.syntax-style");
137-
var patternFormat = new MessageFormat("rule.{0}.pattern");
143+
var patternFormat = new MessageFormat("rule.{0}.regexp");
138144

139145
var rules = ruleIds.stream().sorted()
140146
.map(id -> {
@@ -144,6 +150,11 @@ public static class Rules {
144150
var patternValue = properties.getProperty(
145151
patternFormat.format(formatArgs));
146152
if (syntaxStyleValue == null || patternValue == null) {
153+
logger.fine(MessageFormat.format(
154+
"Property for property key ''{0}'' or property key ''{1}'' not found in syntax rules",
155+
syntaxStyleFormat.format(formatArgs),
156+
patternFormat.format(formatArgs)
157+
));
147158
return null;
148159
}
149160
return Rule.fromProperties(syntaxStyleValue, patternValue);
@@ -274,7 +285,7 @@ public void loadRules(@NotNull final Plugin context) {
274285
} else {
275286
// if no configuration file is available try to load default
276287
// rules from a resource
277-
var resourceName = "/" + SYNTAX_STYLE_RULES_FILE;
288+
var resourceName = "/resources/" + SYNTAX_STYLE_RULES_FILE;
278289
if (logger.isLoggable(Level.FINE)) {
279290
logger.fine(MessageFormat.format(
280291
"Loading syntax style rules from resource ''{0}''",

src/test/unit/groovy/org/openstreetmap/josm/plugins/scripting/ui/console/SyntaxConstantsEngineTest.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class SyntaxConstantsEngineTest extends GroovyTestCase {
107107
assertEquals("text/javascript", style)
108108
style = rules.deriveSuitableSyntaxStyle("application/GrOOvY")
109109
assertEquals("text/groovy", style)
110+
style = rules.deriveSuitableSyntaxStyle("application/x-groovy")
111+
assertEquals("text/groovy", style)
110112

111113
// no matching rule
112114
style = rules.deriveSuitableSyntaxStyle("text/python")
@@ -183,4 +185,5 @@ class SyntaxConstantsEngineTest extends GroovyTestCase {
183185
style = rules.deriveSuitableSyntaxStyle("application/GrOOvY")
184186
assertEquals("text/groovy", style)
185187
}
188+
186189
}

0 commit comments

Comments
 (0)