Skip to content

Commit 5ea7761

Browse files
committed
fix: potential ClassCastException in RawGrammar.getInjectionSelector
1 parent b79af53 commit 5ea7761

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

  • org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/raw

org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/raw/RawGrammar.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.Map;
1818
import java.util.NoSuchElementException;
1919
import java.util.Objects;
20+
import java.util.stream.Collectors;
2021

2122
import org.eclipse.jdt.annotation.Nullable;
2223
import org.eclipse.tm4e.core.internal.parser.PropertySettable;
@@ -79,6 +80,15 @@ public Collection<String> getFileTypes() {
7980

8081
@Override
8182
public @Nullable String getInjectionSelector() {
83+
final var value = get(INJECTION_SELECTOR);
84+
85+
if (value instanceof final Collection<?> coll)
86+
// Some grammars incorrectly provide a list of selectors,
87+
// so we join them into a single 'or' condition string
88+
return coll.stream()
89+
.map(Object::toString)
90+
.collect(Collectors.joining(" | "));
91+
8292
return (String) get(INJECTION_SELECTOR);
8393
}
8494

@@ -106,9 +116,8 @@ public IRawRepository getRepository() {
106116
private Object getOrThrow(final Object key) {
107117
@SuppressWarnings("unlikely-arg-type")
108118
final var obj = get(key);
109-
if (obj == null) {
119+
if (obj == null)
110120
throw new NoSuchElementException("Key '" + key + "' does not exit for grammar '" + getName() + '"');
111-
}
112121
return obj;
113122
}
114123

@@ -119,17 +128,19 @@ public String getScopeName() {
119128

120129
@Override
121130
public @Nullable Object put(final String key, final @Nullable Object value) {
122-
if (FILE_TYPES.equals(key))
131+
if (FILE_TYPES.equals(key)) {
123132
fileTypes = null;
133+
}
124134

125135
return super.put(key, value);
126136
}
127137

128138
@Override
129139
@SuppressWarnings("unlikely-arg-type")
130140
public void putAll(final Map<? extends String, ? extends @Nullable Object> m) {
131-
if (m.containsKey(FILE_TYPES))
141+
if (m.containsKey(FILE_TYPES)) {
132142
fileTypes = null;
143+
}
133144
super.putAll(m);
134145
}
135146

0 commit comments

Comments
 (0)