Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor cleanup #397

Merged
merged 5 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public MatcherTestImpl() {


public void executeTest() {
Collection<MatcherWithPriority<List<String>>> matcher = Matcher.createMatchers(expression);
boolean result = matcher.stream().anyMatch(m -> m.matcher.matches(input));
final Collection<MatcherWithPriority<List<String>>> matcher = Matcher.createMatchers(expression);
final boolean result = matcher.stream().anyMatch(m -> m.matcher.matches(input));
assertEquals(result, this.result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class RawToken {
public RawToken() {
}

public RawToken(String value, List<String> scopes) {
public RawToken(final String value, final List<String> scopes) {
this.value = value;
this.scopes = scopes;
}
Expand All @@ -36,8 +36,8 @@ public List<String> getScopes() {
}

@Override
public boolean equals(Object obj) {
return obj instanceof RawToken other ?
public boolean equals(final Object obj) {
return obj instanceof final RawToken other ?
Objects.equals(this.value, other.value) && Objects.equals(this.scopes, other.scopes) :
false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ThemeMatchingTest {

@Test
void testGivesHigherPriorityToDeeperMatches() throws Exception {
Theme theme = loadTheme("{" +
final Theme theme = loadTheme("{" +
"\"settings\": ["+
"{ \"settings\": { \"foreground\": \"#100000\", \"background\": \"#200000\" } },"+
"{ \"scope\": \"punctuation.definition.string.begin.html\", \"settings\": { \"foreground\": \"#300000\" } },"+
Expand All @@ -42,14 +42,14 @@ void testGivesHigherPriorityToDeeperMatches() throws Exception {
"}");


ColorMap colorMap = new ColorMap();
int _NOT_SET = 0;
int _A = colorMap.getId("#100000");
int _B = colorMap.getId("#200000");
int _C = colorMap.getId("#400000");
int _D = colorMap.getId("#300000");
final ColorMap colorMap = new ColorMap();
final int _NOT_SET = 0;
final int _A = colorMap.getId("#100000");
final int _B = colorMap.getId("#200000");
final int _C = colorMap.getId("#400000");
final int _D = colorMap.getId("#300000");

List<ThemeTrieElementRule> actual = theme.match("punctuation.definition.string.begin.html");
final List<ThemeTrieElementRule> actual = theme.match("punctuation.definition.string.begin.html");

assertArrayEquals(
new ThemeTrieElementRule[] { new ThemeTrieElementRule(5, null, FontStyle.NotSet, _D, _NOT_SET),
Expand All @@ -59,7 +59,7 @@ void testGivesHigherPriorityToDeeperMatches() throws Exception {

@Test
void testGivesHigherPriorityToParentMatches1() throws Exception {
Theme theme = loadTheme("{" +
final Theme theme = loadTheme("{" +
"\"settings\": ["+
"{ \"settings\": { \"foreground\": \"#100000\", \"background\": \"#200000\" } },"+
"{ \"scope\": \"c a\", \"settings\": { \"foreground\": \"#300000\" } },"+
Expand All @@ -69,15 +69,15 @@ void testGivesHigherPriorityToParentMatches1() throws Exception {
"}");


ColorMap colorMap = new ColorMap();
int _NOT_SET = 0;
int _A = colorMap.getId("#100000");
int _B = colorMap.getId("#200000");
int _C = colorMap.getId("#500000");
int _D = colorMap.getId("#300000");
int _E = colorMap.getId("#400000");
final ColorMap colorMap = new ColorMap();
final int _NOT_SET = 0;
final int _A = colorMap.getId("#100000");
final int _B = colorMap.getId("#200000");
final int _C = colorMap.getId("#500000");
final int _D = colorMap.getId("#300000");
final int _E = colorMap.getId("#400000");

List<ThemeTrieElementRule> actual = theme.match("a.b");
final List<ThemeTrieElementRule> actual = theme.match("a.b");

assertArrayEquals(new ThemeTrieElementRule[] {
new ThemeTrieElementRule(2, Arrays.asList("d"), FontStyle.NotSet, _E, _NOT_SET),
Expand All @@ -87,7 +87,7 @@ void testGivesHigherPriorityToParentMatches1() throws Exception {

@Test
void testGivesHigherPriorityToParentMatches2() throws Exception {
Theme theme = loadTheme("{" +
final Theme theme = loadTheme("{" +
"\"settings\": ["+
"{ \"settings\": { \"foreground\": \"#100000\", \"background\": \"#200000\" } },"+
"{ \"scope\": \"meta.tag entity\", \"settings\": { \"foreground\": \"#300000\" } },"+
Expand All @@ -97,17 +97,17 @@ void testGivesHigherPriorityToParentMatches2() throws Exception {
"}");


ScopeListElement root = new ScopeListElement(null, "text.html.cshtml", 0);
ScopeListElement parent = new ScopeListElement(root, "meta.tag.structure.any.html", 0);
int r = ScopeListElement.mergeMetadata(0, parent, new ScopeMetadata("entity.name.tag.structure.any.html", 0, 0,
final ScopeListElement root = new ScopeListElement(null, "text.html.cshtml", 0);
final ScopeListElement parent = new ScopeListElement(root, "meta.tag.structure.any.html", 0);
final int r = ScopeListElement.mergeMetadata(0, parent, new ScopeMetadata("entity.name.tag.structure.any.html", 0, 0,
theme.match("entity.name.tag.structure.any.html")));
String color = theme.getColor(StackElementMetadata.getForeground(r));
final String color = theme.getColor(StackElementMetadata.getForeground(r));
assertEquals("#300000", color);
}

@Test
void testCanMatch() throws Exception {
Theme theme = loadTheme("{" +
final Theme theme = loadTheme("{" +
"\"settings\": ["+
"{ \"settings\": { \"foreground\": \"#F8F8F2\", \"background\": \"#272822\" } },"+
"{ \"scope\": \"source, something\", \"settings\": { \"background\": \"#100000\" } },"+
Expand All @@ -122,16 +122,16 @@ void testCanMatch() throws Exception {
"]"+
"}");

ColorMap colorMap = new ColorMap();
int _NOT_SET = 0;
int _A = colorMap.getId("#F8F8F2");
int _B = colorMap.getId("#272822");
int _C = colorMap.getId("#200000");
int _D = colorMap.getId("#300000");
int _E = colorMap.getId("#400000");
int _F = colorMap.getId("#500000");
int _G = colorMap.getId("#100000");
int _H = colorMap.getId("#600000");
final ColorMap colorMap = new ColorMap();
final int _NOT_SET = 0;
final int _A = colorMap.getId("#F8F8F2");
final int _B = colorMap.getId("#272822");
final int _C = colorMap.getId("#200000");
final int _D = colorMap.getId("#300000");
final int _E = colorMap.getId("#400000");
final int _F = colorMap.getId("#500000");
final int _G = colorMap.getId("#100000");
final int _H = colorMap.getId("#600000");

// matches defaults
assertNoMatch(theme, "");
Expand Down Expand Up @@ -193,7 +193,7 @@ void testCanMatch() throws Exception {

@Test
void testMicrosoft_vscode_23460() throws Exception {
Theme theme = loadTheme("{" +
final Theme theme = loadTheme("{" +
"\"settings\": ["+
"{" +
"\"settings\": {"+
Expand Down Expand Up @@ -221,12 +221,12 @@ void testMicrosoft_vscode_23460() throws Exception {
"]"+
"}");

ColorMap colorMap = new ColorMap();
int _NOT_SET = 0;
int _A = colorMap.getId("#aec2e0");
int _B = colorMap.getId("#14191f");
int _C = colorMap.getId("#FF410D");
int _D = colorMap.getId("#ffffff");
final ColorMap colorMap = new ColorMap();
final int _NOT_SET = 0;
final int _A = colorMap.getId("#aec2e0");
final int _B = colorMap.getId("#14191f");
final int _C = colorMap.getId("#FF410D");
final int _D = colorMap.getId("#ffffff");

// string.quoted.double.json
// meta.structure.dictionary.value.json
Expand All @@ -238,37 +238,37 @@ void testMicrosoft_vscode_23460() throws Exception {
new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NOT_SET, _NOT_SET)
});

ScopeListElement parent3 = new ScopeListElement(null, "source.json", 0);
ScopeListElement parent2 = new ScopeListElement(parent3, "meta.structure.dictionary.json", 0);
ScopeListElement parent1 = new ScopeListElement(parent2, "meta.structure.dictionary.value.json", 0);
final ScopeListElement parent3 = new ScopeListElement(null, "source.json", 0);
final ScopeListElement parent2 = new ScopeListElement(parent3, "meta.structure.dictionary.json", 0);
final ScopeListElement parent1 = new ScopeListElement(parent2, "meta.structure.dictionary.value.json", 0);

int r = ScopeListElement.mergeMetadata(
final int r = ScopeListElement.mergeMetadata(
0,
parent1,
new ScopeMetadata("string.quoted.double.json", 0, 0, theme.match("string.quoted.double.json"))
);
String color = theme.getColor(StackElementMetadata.getForeground(r));
final String color = theme.getColor(StackElementMetadata.getForeground(r));
assertEquals("#FF410D", color);
}

private void assertMatch(Theme theme, String scopeName, ThemeTrieElementRule[] expected) {
List<ThemeTrieElementRule> actual = theme.match(scopeName);
private void assertMatch(final Theme theme, final String scopeName, final ThemeTrieElementRule[] expected) {
final List<ThemeTrieElementRule> actual = theme.match(scopeName);
assertArrayEquals(expected, actual.toArray(), "when matching <<" + scopeName + ">>");
}

private void assertSimpleMatch(Theme theme, String scopeName, int scopeDepth, int fontStyle, int foreground, int background) {
private void assertSimpleMatch(final Theme theme, final String scopeName, final int scopeDepth, final int fontStyle, final int foreground, final int background) {
assertMatch(theme, scopeName, new ThemeTrieElementRule [] {
new ThemeTrieElementRule(scopeDepth, null, fontStyle, foreground, background)
});
}

private void assertNoMatch(Theme theme, String scopeName) {
private void assertNoMatch(final Theme theme, final String scopeName) {
assertMatch(theme, scopeName, new ThemeTrieElementRule [] {
new ThemeTrieElementRule(0, null, FontStyle.NotSet, 0, 0 /*_NOT_SET, _NOT_SET*/)
});
}

private Theme loadTheme(String theme) throws Exception {
private Theme loadTheme(final String theme) throws Exception {
return Theme.createFromRawTheme(ThemeReader.readThemeSync("theme.json", new ByteArrayInputStream(theme.getBytes())), null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@ public class ThemeParsingTest {

@Test
public void testCanParse() throws Exception {
final var actual = parseTheme(("{'settings': [" +
"{ 'settings': { 'foreground': '#F8F8F2', 'background': '#272822' } }," +
"{ 'scope': 'source, something', 'settings': { 'background': '#100000' } }," +
"{ 'scope': ['bar', 'baz'], 'settings': { 'background': '#010000' } }," +
"{ 'scope': 'source.css selector bar', 'settings': { 'fontStyle': 'bold' } }," +
"{ 'scope': 'constant', 'settings': { 'fontStyle': 'italic', 'foreground': '#ff0000' } }," +
"{ 'scope': 'constant.numeric', 'settings': { 'foreground': '#00ff00' } }," +
"{ 'scope': 'constant.numeric.hex', 'settings': { 'fontStyle': 'bold' } }," +
"{ 'scope': 'constant.numeric.oct', 'settings': { 'fontStyle': 'bold italic underline' } }," +
"{ 'scope': 'constant.numeric.bin', 'settings': { 'fontStyle': 'bold strikethrough' } }," +
"{ 'scope': 'constant.numeric.dec', 'settings': { 'fontStyle': '', 'foreground': '#0000ff' } }," +
"{ 'scope': 'foo', 'settings': { 'fontStyle': '', 'foreground': '#CFA' } }" +
"]}").replace('\'', '"'));
final var actual = parseTheme("""
{ "settings": [
{ "settings": { "foreground": "#F8F8F2", "background": "#272822" } },
{ "scope": "source, something", "settings": { "background": "#100000" } },
{ "scope": ["bar", "baz"], "settings": { "background": "#010000" } },
{ "scope": "source.css selector bar", "settings": { "fontStyle": "bold" } },
{ "scope": "constant", "settings": { "fontStyle": "italic", "foreground": "#ff0000" } },
{ "scope": "constant.numeric", "settings": { "foreground": "#00ff00" } },
{ "scope": "constant.numeric.hex", "settings": { "fontStyle": "bold" } },
{ "scope": "constant.numeric.oct", "settings": { "fontStyle": "bold italic underline" } },
{ "scope": "constant.numeric.bin", "settings": { "fontStyle": "bold strikethrough" } },
{ "scope": "constant.numeric.dec", "settings": { "fontStyle": "", "foreground": "#0000ff" } },
{ "scope": "foo", "settings": { "fontStyle": "", "foreground": "#CFA" } }
]}""");

final var expected = new ParsedThemeRule[] {
new ParsedThemeRule("", null, 0, FontStyle.NotSet, "#F8F8F2", "#272822"),
Expand All @@ -64,7 +65,7 @@ public void testCanParse() throws Exception {
assertArrayEquals(expected, actual.toArray());
}

private List<ParsedThemeRule> parseTheme(String theme) throws Exception {
private List<ParsedThemeRule> parseTheme(final String theme) throws Exception {
return Theme.parseTheme(ThemeReader.readThemeSync("theme.json", new ByteArrayInputStream(theme.getBytes())));
}
}
Loading