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

Adapt changes in upstream project #400

Merged
merged 41 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
765fb52
add RuleId class
sebthom May 15, 2022
7c06fbe
Minor update
sebthom May 15, 2022
e7198b3
Set missing Java 17 constraints
sebthom May 15, 2022
828edd8
Remove unused import
sebthom May 15, 2022
8edb65c
Reduce formatter indention
sebthom May 15, 2022
02fe725
Refactor theme tests
sebthom May 15, 2022
00f4ef7
add NullSafetyHelper#defaultIfNull
sebthom May 16, 2022
e66cd50
Rename some variables in oniguruma package
sebthom May 16, 2022
c705814
Change `Set<String> getColorMap()` to `List<String> getColorMap()`
sebthom May 16, 2022
3ab8ff9
Refactor LineTokenizer
sebthom May 16, 2022
9a6a13f
Reformat BalancedBracketSelectors
sebthom May 16, 2022
12d2f1d
Change formatter indention
sebthom May 16, 2022
760b523
Change PListParser to accept Reader instead of InputStream
sebthom May 16, 2022
a9e2b1e
Make TokenTypeMatcher a class
sebthom May 16, 2022
bc6c683
Add missing test grammar
sebthom May 16, 2022
3f91b2d
Reformat LineTokens
sebthom May 16, 2022
d289122
Make RawRule setter fluent
sebthom May 16, 2022
ee3af0c
Change ThemeReader to accept Reader instead of Inputstream
sebthom May 16, 2022
6c14ad0
Refactor Grammar class according upstream project
sebthom May 16, 2022
10643cf
Refactor RuleFactory according upstream project
sebthom May 16, 2022
998268e
Refactor Rule#collectPatternsRecursive to Rule#collectPatterns
sebthom May 16, 2022
b0366c3
Use Strings.isNullOrEmpty
sebthom May 16, 2022
47a729e
Configure Java 17 as target
sebthom May 16, 2022
3520629
Adapt Registry/ScopeDependencyProcessor changes from upstream
sebthom May 16, 2022
5132373
Rename classes according upstream project
sebthom May 17, 2022
773abee
add FontStyle#fontStyleToString
sebthom May 17, 2022
b248d66
Don't consider cache field in hashCode/equals
sebthom May 17, 2022
796ceee
add EncodedTokenAttributes#toString
sebthom May 17, 2022
3ac8233
Rename fields and methods according upstream
sebthom May 17, 2022
b42c541
Adapt equals method according upstream project
sebthom May 17, 2022
9f35f9f
Replace IMatchResult interface with MatchResult class
sebthom May 17, 2022
8e8fdaf
Remove unused scopeName field
sebthom May 17, 2022
db50a61
Remove unnecessary @Nullable annotations
sebthom May 17, 2022
53610e6
Rename fields and methods according upstream
sebthom May 17, 2022
e5a9f5f
Update github URLs in javadoc
sebthom May 17, 2022
8133ed2
Remove Token class
sebthom May 17, 2022
931b43c
Reorder constructors
sebthom May 17, 2022
04c2f71
Remove unused IStateStack.INITIAL field
sebthom May 17, 2022
d3e4a72
Add ScopeStack, StyleAttributes and refactor according upstream project
sebthom May 17, 2022
6bb73aa
Improve test cases
sebthom May 17, 2022
75b6a33
Update tm4e dependencies
sebthom May 17, 2022
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 @@ -233,8 +233,8 @@ org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=true
org.eclipse.jdt.core.formatter.compact_else_if=true
org.eclipse.jdt.core.formatter.continuation_indentation=2
org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
org.eclipse.jdt.core.formatter.continuation_indentation=1
org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=1
org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import java.util.List;

import org.eclipse.tm4e.core.grammar.IGrammar;
import org.eclipse.tm4e.core.grammar.IStackElement;
import org.eclipse.tm4e.core.grammar.IStateStack;
import org.eclipse.tm4e.core.registry.IGrammarSource;
import org.eclipse.tm4e.core.registry.IRegistryOptions;
import org.eclipse.tm4e.core.registry.Registry;

Expand Down Expand Up @@ -71,17 +72,6 @@ public List<RawTestLine> getLines() {

public void executeTest() throws Exception {
final var options = new IRegistryOptions() {

@Override
public String getFilePath(final String scopeName) {
return null;
}

@Override
public InputStream getInputStream(final String scopeName) throws IOException {
return null;
}

@Override
public Collection<String> getInjections(final String scopeName) {
if (scopeName.equals(getGrammarScopeName())) {
Expand All @@ -100,7 +90,7 @@ public Collection<String> getInjections(final String scopeName) {
throw new Exception("I HAVE NO GRAMMAR FOR TEST");
}

IStackElement prevState = null;
IStateStack prevState = null;
for (final var testLine : lines) {
prevState = assertLineTokenization(grammar, testLine, prevState);
}
Expand All @@ -109,26 +99,27 @@ public Collection<String> getInjections(final String scopeName) {
private IGrammar getGrammar(final Registry registry, final File testLocation) throws Exception {
IGrammar grammar = null;
for (final String grammarPath : getGrammars()) {
final IGrammar tmpGrammar = registry.loadGrammarFromPathSync(new File(testLocation, grammarPath));
final IGrammar tmpGrammar = registry
.addGrammar(IGrammarSource.fromFile(new File(testLocation, grammarPath).toPath()));
if (grammarPath.equals(getGrammarPath())) {
grammar = tmpGrammar;
}
}
return grammar;
}

private static IStackElement assertLineTokenization(final IGrammar grammar, final RawTestLine testCase,
final IStackElement prevState) {
private static IStateStack assertLineTokenization(final IGrammar grammar, final RawTestLine testCase,
final IStateStack prevState) {
final var line = testCase.line;
final var actual = grammar.tokenizeLine(line, prevState);

final var actualTokens = Arrays.stream(actual.getTokens())
.map(token -> new RawToken(
line.substring(
token.getStartIndex(),
Math.min(token.getEndIndex(), line.length())), // TODO Math.min not required in upstream why?
token.getScopes()))
.collect(toList());
.map(token -> new RawToken(
line.substring(
token.getStartIndex(),
Math.min(token.getEndIndex(), line.length())), // TODO Math.min not required in upstream why?
token.getScopes()))
.collect(toList());

// TODO@Alex: fix tests instead of working around
if (!line.isEmpty()) {
Expand All @@ -142,16 +133,16 @@ private static IStackElement assertLineTokenization(final IGrammar grammar, fina
}

private static void deepEqual(final List<RawToken> actualTokens, final List<RawToken> expextedTokens,
final String message) {
final String message) {

// compare collection size
if (expextedTokens.size() != actualTokens.size()) {
final var actualTokensStr = actualTokens.stream().map(Object::toString).collect(joining("\n"));
final var expextedTokensStr = expextedTokens.stream().map(Object::toString).collect(joining("\n"));

assertEquals(expextedTokensStr, actualTokensStr,
message + " (collection size problem: actual=" + actualTokens.size() + " expected="
+ expextedTokens.size() + ")");
message + " (collection size problem: actual=" + actualTokens.size() + " expected="
+ expextedTokens.size() + ")");
}

// compare item
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Copyright (c) 2022 Sebastian Thomschke and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Initial code from https://github.com/Microsoft/vscode-textmate/
* Initial copyright Copyright (C) Microsoft Corporation. All rights reserved.
* Initial license: MIT
*
* Contributors:
* - Microsoft Corporation: Initial code, written in TypeScript, licensed under MIT license
* - Sebastian Thomschke - translation and adaptation to Java
*/
package org.eclipse.tm4e.core.internal.theme;

import java.io.StringReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.tm4e.core.internal.theme.reader.ThemeReader;
import org.junit.jupiter.api.Assertions;

public abstract class AbstractThemeTest extends Assertions {

protected static final int _NOT_SET = 0;

protected static <T> List<T> list(@SuppressWarnings("unchecked") final T... items) {
if (items.length == 0)
return Collections.emptyList();
return Arrays.asList(items);
}

@SuppressWarnings("unchecked")
protected static <K, V> Map<K, V> map(final K k, final V v, final Object... moreKVs) {
final var map = new HashMap<K, V>();
map.put(k, v);
if (moreKVs.length == 0)
return map;
boolean nextIsValue = false;
K key = null;
for (final Object obj : moreKVs)
if (nextIsValue) {
map.put(key, (V) obj);
nextIsValue = false;
} else {
key = (K) obj;
nextIsValue = true;
}
return map;
}

protected static Theme createTheme(final ParsedThemeRule... rules) {
return Theme.createFromParsedTheme(list(rules), null);
}

protected static Theme createTheme(final String themeAsJsonString) throws Exception {
return Theme.createFromRawTheme(
ThemeReader.readThemeSync("theme.json", new StringReader(themeAsJsonString)), null);
}

protected static List<ParsedThemeRule> parseTheme(final String themeAsJsonString) throws Exception {
return Theme.parseTheme(ThemeReader.readThemeSync("theme.json", new StringReader(themeAsJsonString)));
}
}
Loading