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 code maintenance #456

Merged
merged 4 commits into from
Oct 22, 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 @@ -18,7 +18,6 @@

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.jdt.annotation.Nullable;

Expand All @@ -31,7 +30,7 @@ final class OnigSearcher {
private final List<OnigRegExp> regExps;

OnigSearcher(final Collection<String> regExps) {
this.regExps = regExps.stream().map(OnigRegExp::new).collect(Collectors.toList());
this.regExps = regExps.stream().map(OnigRegExp::new).toList();
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import org.eclipse.jdt.annotation.Nullable;

Expand Down Expand Up @@ -74,7 +73,7 @@ void setSource(final int index, final String newSource) {
CompiledRule compile() {
var cached = this.cached;
if (cached == null) {
final List<String> regexps = items.stream().map(RegExpSource::getSource).collect(Collectors.toList());
final List<String> regexps = items.stream().map(RegExpSource::getSource).toList();
cached = this.cached = new CompiledRule(regexps, items.stream().map(e -> e.ruleId).toArray(RuleId[]::new));
}
return cached;
Expand All @@ -96,8 +95,7 @@ CompiledRule compileAG(final boolean allowA, final boolean allowG) {
}

private CompiledRule resolveAnchors(final boolean allowA, final boolean allowG) {
final List<String> regexps = items.stream().map(e -> e.resolveAnchors(allowA, allowG))
.collect(Collectors.toList());
final List<String> regexps = items.stream().map(e -> e.resolveAnchors(allowA, allowG)).toList();
return new CompiledRule(regexps, items.stream().map(e -> e.ruleId).toArray(RuleId[]::new));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/
package org.eclipse.tm4e.core.grammar;

import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*;
import static org.eclipse.tm4e.core.registry.IGrammarSource.*;
import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -78,7 +77,7 @@ class GrammarTest {
void testTokenizeSingleLineExpression() throws Exception {
final var registry = new Registry();
final IGrammar grammar = registry.addGrammar(fromResource(Data.class, "JavaScript.tmLanguage"));
final var lineTokens = castNonNull(grammar).tokenizeLine("function add(a,b) { return a+b; }");
final var lineTokens = grammar.tokenizeLine("function add(a,b) { return a+b; }");
assertFalse(lineTokens.isStoppedEarly());
for (int i = 0; i < lineTokens.getTokens().length; i++) {
final IToken token = lineTokens.getTokens()[i];
Expand All @@ -98,7 +97,7 @@ void testTokenizeMultilineExpression() throws Exception {
int j = 0;
final String[] lines = { "function add(a,b)", "{ return a+b; }" };
for (final String line : lines) {
final var lineTokens = castNonNull(grammar).tokenizeLine(line, ruleStack, null);
final var lineTokens = grammar.tokenizeLine(line, ruleStack, null);
assertFalse(lineTokens.isStoppedEarly());
ruleStack = lineTokens.getRuleStack();
for (i = 0; i < lineTokens.getTokens().length; i++) {
Expand All @@ -116,7 +115,7 @@ void testTokenize0Tokens() throws Exception {
final var registry = new Registry();
final IGrammar grammar = registry.addGrammar(fromResource(Data.class, "JavaScript.tmLanguage"));
final String lineText = "";
final var lineTokens = castNonNull(grammar).tokenizeLine(lineText);
final var lineTokens = grammar.tokenizeLine(lineText);
assertFalse(lineTokens.isStoppedEarly());

final var endIndexOffset = 1; // IToken's end-indexes are exclusive
Expand All @@ -132,7 +131,7 @@ void testTokenize1Token() throws Exception {
final var registry = new Registry();
final IGrammar grammar = registry.addGrammar(fromResource(Data.class, "JavaScript.tmLanguage"));
final String lineText = "true";
final var lineTokens = castNonNull(grammar).tokenizeLine(lineText);
final var lineTokens = grammar.tokenizeLine(lineText);
assertFalse(lineTokens.isStoppedEarly());

final var endIndexOffset = 1; // IToken's end-indexes are exclusive
Expand All @@ -148,7 +147,7 @@ void testTokenize1TokenWithNewLine() throws Exception {
final var registry = new Registry();
final IGrammar grammar = registry.addGrammar(fromResource(Data.class, "JavaScript.tmLanguage"));
final String lineText = "true\n";
final var lineTokens = castNonNull(grammar).tokenizeLine(lineText);
final var lineTokens = grammar.tokenizeLine(lineText);
assertFalse(lineTokens.isStoppedEarly());

final var endIndexOffset = 1; // IToken's end-indexes are exclusive
Expand All @@ -165,7 +164,7 @@ void testTokenize1IllegalToken() throws Exception {
final var registry = new Registry();
final IGrammar grammar = registry.addGrammar(fromResource(Data.class, "JavaScript.tmLanguage"));
final String lineText = "@"; // Uncaught SyntaxError: illegal character U+0040
final var lineTokens = castNonNull(grammar).tokenizeLine(lineText);
final var lineTokens = grammar.tokenizeLine(lineText);
assertFalse(lineTokens.isStoppedEarly());
final var endIndexOffset = 1; // IToken's end-indexes are exclusive

Expand All @@ -181,7 +180,7 @@ void testTokenize2Tokens() throws Exception {
final IGrammar grammar = registry.addGrammar(fromResource(Data.class, "JavaScript.tmLanguage"));

final String lineText = "{}";
final var lineTokens = castNonNull(grammar).tokenizeLine(lineText);
final var lineTokens = grammar.tokenizeLine(lineText);
assertFalse(lineTokens.isStoppedEarly());

final var endIndexOffset = 1; // IToken's end-indexes are exclusive
Expand Down Expand Up @@ -215,8 +214,7 @@ void testTokenizeTypeScriptFile() throws Exception {
final List<String> expectedTokens;
try (var resource = Data.class.getResourceAsStream("raytracer_tokens.txt")) {
expectedTokens = new BufferedReader(new InputStreamReader(resource, StandardCharsets.UTF_8))
.lines()
.collect(Collectors.toList());
.lines().toList();
}

IStateStack stateStack = null;
Expand Down
4 changes: 2 additions & 2 deletions org.eclipse.tm4e.languageconfiguration/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: org.eclipse.jface.text,
org.eclipse.ui.genericeditor,
com.google.gson;bundle-version="2.9.0",
org.eclipse.tm4e.core;bundle-version="0.5.0",
org.eclipse.tm4e.ui;bundle-version="0.6.0",
org.eclipse.tm4e.core;bundle-version="0.5.1",
org.eclipse.tm4e.ui;bundle-version="0.6.1",
org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.ui,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import java.util.Collection;
import java.util.Collections;
import java.util.stream.Collectors;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jface.dialogs.Dialog;
Expand Down Expand Up @@ -265,7 +264,7 @@ private Collection<ILanguageConfigurationDefinition> getSelectedUserDefinitions(
return Collections.emptyList();
}
return ((Collection<ILanguageConfigurationDefinition>) selection.toList()).stream()
.filter(definition -> definition.getPluginId() == null).collect(Collectors.toList());
.filter(definition -> definition.getPluginId() == null).toList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tm4e.languageconfiguration.internal.model.AutoClosingPair;
Expand Down Expand Up @@ -50,11 +49,11 @@ public CharacterPairSupport(LanguageConfiguration config) {
if (autoClosingPairs != null) {
this.autoClosingPairs = autoClosingPairs.stream().filter(Objects::nonNull)
.map(el -> new AutoClosingPairConditional(el.open, el.close, el.notIn))
.collect(Collectors.toList());
.toList();
} else if (brackets != null) {
this.autoClosingPairs = brackets.stream().filter(Objects::nonNull)
.map(el -> new AutoClosingPairConditional(el.open, el.close, Collections.emptyList()))
.collect(Collectors.toList());
.toList();
} else {
this.autoClosingPairs = Collections.emptyList();
}
Expand All @@ -66,7 +65,7 @@ public CharacterPairSupport(LanguageConfiguration config) {

final var surroundingPairs = config.getSurroundingPairs();
this.surroundingPairs = surroundingPairs != null
? surroundingPairs.stream().filter(Objects::nonNull).collect(Collectors.toList())
? surroundingPairs.stream().filter(Objects::nonNull).toList()
: (List<AutoClosingPair>) (List<?>) this.autoClosingPairs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tm4e.languageconfiguration.internal.model.CharacterPair;
Expand Down Expand Up @@ -45,7 +44,7 @@ public OnEnterSupport(@Nullable final List<CharacterPair> brackets, @Nullable fi
.stream()
.filter(Objects::nonNull)
.map(ProcessedBracketPair::new)
.collect(Collectors.toList());
.toList();

this.regExpRules = regExpRules != null ? regExpRules : Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public static TabSpacesInfo getTabSpaces(@Nullable final ITextViewer viewer) {
final TabsToSpacesConverter converter = ClassHelper.getFieldValue(viewer, "fTabsToSpacesConverter", //$NON-NLS-1$
TextViewer.class);
if (converter != null) {
@SuppressWarnings("null")
final int tabSize = ClassHelper.getFieldValue(converter, "fTabRatio", TabsToSpacesConverter.class); //$NON-NLS-1$
return new TabSpacesInfo(tabSize, true);
}
Expand All @@ -188,7 +189,7 @@ public static TabSpacesInfo getTabSpaces(@Nullable final ITextViewer viewer) {
* @param document the document to search in
* @param line zero-based document line number
*
* @return <code>true</code> if all the characters of the specified document range are the whitespace
* @return <code>true</code> if all the characters of the specified document range are the whitespace
* characters, otherwise returns <code>false</code>
*/
public static boolean isBlankLine(final IDocument document, int line) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -152,7 +151,7 @@ private List<?> removeNullElements(@Nullable final List<?> list) {
if (list == null) {
return null;
}
return list.stream().filter(Objects::nonNull).collect(Collectors.toList());
return list.stream().filter(Objects::nonNull).toList();
}

private void createCommentsTab(final TabFolder folder) {
Expand Down
4 changes: 2 additions & 2 deletions org.eclipse.tm4e.registry/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-SymbolicName: org.eclipse.tm4e.registry;singleton:=true
Bundle-Version: 0.6.1.qualifier
Bundle-Version: 0.6.2.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: org.eclipse.tm4e.core;bundle-version="0.5.0",
Require-Bundle: org.eclipse.tm4e.core;bundle-version="0.5.1",
org.eclipse.core.runtime,
com.google.gson;bundle-version="2.9.0",
com.google.guava;bundle-version="30.1.0",
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.registry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

<artifactId>org.eclipse.tm4e.registry</artifactId>
<packaging>eclipse-plugin</packaging>
<version>0.6.1-SNAPSHOT</version>
<version>0.6.2-SNAPSHOT</version>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;

import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -103,7 +102,7 @@ List<IContentType> getContentTypesForScope(@Nullable final String scopeName) {
}

return scopeNameBindings.entrySet().stream().filter(map -> scopeName.equals(map.getValue()))
.map(Entry::getKey).collect(Collectors.toList());
.map(Entry::getKey).toList();
}

void registerContentTypeBinding(final IContentType contentType, final String scopeName) {
Expand Down
4 changes: 2 additions & 2 deletions org.eclipse.tm4e.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.tm4e.ui;singleton:=true
Bundle-Version: 0.6.1.qualifier
Require-Bundle: org.eclipse.tm4e.core;bundle-version="0.5.0",
Require-Bundle: org.eclipse.tm4e.core;bundle-version="0.5.1",
org.eclipse.jface.text,
org.eclipse.core.runtime,
org.eclipse.ui,
org.eclipse.core.resources,
org.eclipse.core.filesystem,
org.eclipse.tm4e.registry;bundle-version="0.6.0",
org.eclipse.tm4e.registry;bundle-version="0.6.2",
org.eclipse.ui.ide;resolution:=optional,
com.google.gson;bundle-version="2.9.0",
com.google.guava,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@
public final class TMPresentationReconcilerTestGenerator
implements ITMPresentationReconcilerListener, IDocumentListener, ITextListener {

@Nullable
private ITextViewer viewer;

@Nullable
private IDocument document;
private ITextViewer viewer = lazyNonNull();
private IDocument document = lazyNonNull();

private final StringBuilder code = new StringBuilder();

Expand Down Expand Up @@ -150,8 +147,8 @@ public void uninstall() {
write("}");

System.err.println(code.toString());
castNonNull(document).removeDocumentListener(this);
castNonNull(viewer).removeTextListener(this);
document.removeDocumentListener(this);
viewer.removeTextListener(this);
// commands.clear();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.swt.graphics.RGB;
Expand Down Expand Up @@ -75,8 +74,7 @@ ITheme getDefaultTheme(final boolean dark) {

@Override
public ITheme[] getThemes(final boolean dark) {
return themes.values().stream().filter(theme -> theme.isDark() == dark)
.collect(Collectors.toList()).toArray(ITheme[]::new);
return themes.values().stream().filter(theme -> theme.isDark() == dark).toArray(ITheme[]::new);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tm4e.ui.themes.IThemeAssociation;
Expand Down Expand Up @@ -85,8 +84,7 @@ IThemeAssociation getThemeAssociationFor(final String eclipseThemeId) {

IThemeAssociation[] getThemeAssociations(final boolean isDefault) {
/*if (isDefault) {
return getThemeAssociations().stream().filter(theme -> theme.isDefault()).collect(Collectors.toList())
.toArray(IThemeAssociation[]::new);
return getThemeAssociations().stream().filter(theme -> theme.isDefault()).toArray(IThemeAssociation[]::new);
}*/
return getThemeAssociations().toArray(IThemeAssociation[]::new);
}
Expand All @@ -98,7 +96,7 @@ IThemeAssociation getDefaultAssociation() {

IThemeAssociation[] getThemeAssociationsForTheme(final String themeId) {
return getThemeAssociations().stream().filter(themeAssociation -> themeId.equals(themeAssociation.getThemeId()))
.collect(Collectors.toList()).toArray(IThemeAssociation[]::new);
.toArray(IThemeAssociation[]::new);
}

boolean hasThemeAssociationsForTheme(final String themeId, final String eclipseThemeId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void unregister(final IThemeAssociation association) {
// // Get the default associations (from plugin)
// /*List<IThemeAssociation> defaultAssociations =
// getThemeAssociations().stream()
// .filter().collect(Collectors.toList());
// .filter().toList();
// // Add default association if user associations doesn't define it.
// for (IThemeAssociation defaultAssociation : defaultAssociations) {
// if (!(contains(userAssociations, defaultAssociation))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
package org.eclipse.tm4e.ui.internal.themes;

import java.util.Arrays;
import java.util.stream.Collectors;

import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
Expand Down Expand Up @@ -135,7 +134,7 @@ public void save() throws BackingStoreException {
// Save Theme associations in the
// "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.ui.prefs"
final String json = PreferenceHelper.toJsonThemeAssociations(Arrays.stream(getAllThemeAssociations())
.filter(t -> t.getPluginId() == null).collect(Collectors.toList()));
.filter(t -> t.getPluginId() == null).toList());
prefs.put(PreferenceConstants.THEME_ASSOCIATIONS, json);

// Save preferences
Expand Down