Skip to content

Commit

Permalink
style: fix checkstyle findings
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed May 17, 2023
1 parent a75a613 commit 7a8619d
Show file tree
Hide file tree
Showing 27 changed files with 59 additions and 92 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.core.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.tm4e.core.tests;singleton:=true
Bundle-Version: 0.5.0.qualifier
Bundle-Version: 0.5.1.qualifier
Require-Bundle: org.apache.batik.css;bundle-version="1.7.0";resolution:=optional,
org.apache.batik.util;bundle-version="1.7.0";resolution:=optional,
com.google.gson;bundle-version="2.9.0";resolution:=optional,
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.core.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<artifactId>org.eclipse.tm4e.core.tests</artifactId>
<packaging>eclipse-test-plugin</packaging>
<version>0.5.0-SNAPSHOT</version>
<version>0.5.1-SNAPSHOT</version>

<build>
<pluginManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Collection<String> getInjections(final String scopeName) {
grammar = registry.grammarForScopeName(getGrammarScopeName());
}
if (grammar == null) {
throw new Exception("I HAVE NO GRAMMAR FOR TEST");
throw new IllegalStateException("I HAVE NO GRAMMAR FOR TEST");
}

IStateStack prevState = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package org.eclipse.tm4e.core.internal.grammar;

import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.*;
import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.castNonNull;

import java.util.ArrayList;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* - Fabio Zadrozny <fabiofz@gmail.com> - Convert uniqueId to Object (for identity compare)
* - Fabio Zadrozny <fabiofz@gmail.com> - Fix recursion error on creation of OnigRegExp with unicode chars
*/

package org.eclipse.tm4e.core.internal.oniguruma;

import java.lang.System.Logger;
Expand Down Expand Up @@ -44,13 +43,8 @@ final class OnigRegExp {
/**
* {@link WarnCallback} which is used if log level is at least Level.WARNING.
*/
private static WarnCallback LOGGER_WARN_CALLBACK = new WarnCallback() {
@Override
public void warn(@Nullable String message) {
LOGGER.log(Level.WARNING, message);
}
};

private static final WarnCallback LOGGER_WARN_CALLBACK = message -> LOGGER.log(Level.WARNING, message);

@Nullable
private OnigString lastSearchString;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.tm4e.core.internal.theme.css.sac;

import static java.lang.System.Logger.Level.*;
import static java.lang.System.Logger.Level.ERROR;

import java.lang.System.Logger;

Expand Down Expand Up @@ -41,7 +41,7 @@ public Parser makeParser() throws ClassNotFoundException, IllegalAccessException
if (preferredParserName != null) {
return makeParser(preferredParserName);
}
} catch (final Throwable ex) {
} catch (final Exception | LinkageError ex) {
LOGGER.log(ERROR, ex.getMessage(), ex);
}
return super.makeParser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public interface ISACParserFactory {

/**
* Set the preferred SAC parser name to use when makeParser is called.
*
* @param preferredParserName
*/
void setPreferredParserName(@Nullable String preferredParserName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Parser makeParser(final String name) throws ClassNotFoundException, Illeg
assert parser != null;
return parser;
} catch (InvocationTargetException | NoSuchMethodException ex) {
throw (InstantiationException) ((new InstantiationException()).initCause(ex));
throw (InstantiationException) new InstantiationException().initCause(ex);
}
}
throw new IllegalAccessException(
Expand All @@ -61,19 +61,13 @@ public Parser makeParser(final String name) throws ClassNotFoundException, Illeg

/**
* Register SAC parser name.
*
* @param parser
*/
private static void registerSACParser(final String parser) {
registerSACParser(parser, parser);
}

/**
* register SAC parser with name <code>name</code> mapped with Class name
* <code>classNameParser</code>.
*
* @param name
* @param classNameParser
* Register SAC parser with name <code>name</code> mapped with Class name <code>classNameParser</code>.
*/
private static void registerSACParser(final String name, final String classNameParser) {
parsers.put(name, classNameParser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.Collection;
import java.util.List;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tm4e.core.internal.theme.IRawTheme;

Expand All @@ -46,7 +45,7 @@ default IGrammarSource getGrammarSource(@SuppressWarnings("unused") final String
}

@Nullable
default Collection<@NonNull String> getInjections(@SuppressWarnings("unused") final String scopeName) {
default Collection<String> getInjections(@SuppressWarnings("unused") final String scopeName) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package org.eclipse.tm4e.core.grammar;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -51,10 +50,8 @@ public static Stream<ITokenizeLineResult<IToken[]>> tokenizeText(final CharSeque
* @param text the text to tokenize
*
* @return The stream of {@link ITokenizeLineResult}, each item covering 1 line of the text
*
* @throws IOException
*/
public static Stream<ITokenizeLineResult<IToken[]>> tokenizeText(final InputStream text, final IGrammar grammar) throws IOException {
public static Stream<ITokenizeLineResult<IToken[]>> tokenizeText(final InputStream text, final IGrammar grammar) {
final var reader = new BufferedReader(new InputStreamReader(text));

final var prevStack = new AtomicReference<IStateStack>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1412,4 +1412,4 @@
},
"scopeName": "source.js",
"uuid": "805375ec-d614-41f5-8993-5843fe63ea82"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3102,4 +3102,4 @@
}
},
"version": "https://github.com/Microsoft/TypeScript-TmLanguage/commit/fea3b25eb632f689a02057a1715faab29343dda2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1027,4 +1027,4 @@
"scopeName": "source.java",
"uuid": "2B449DF6-6B1D-11D9-94EC-000D93589AF6",
"version": "https://github.com/textmate/java.tmbundle/commit/faffa518d0b22b68b4e5e6b4c939722522b97d40"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -638,4 +638,4 @@
"name": "storage.modifier.cs"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -626,4 +626,4 @@
}
},
"scopeName": "source.css"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
],
"repository": {

"object-member-ng-styles": {
"begin": "styles\\s*:",
"end": "(?=,|\\})",
Expand Down Expand Up @@ -66,4 +66,4 @@
}
},
"scopeName": "styles.ng"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
],
"repository": {

"object-member-ng-template": {
"begin": "template\\s*:",
"end": "(?=,|\\})",
Expand Down Expand Up @@ -251,7 +251,7 @@
},
"match": "(?x)\\s*([_$a-zA-Z*#(\\[][-$.:\\w()\\[\\]]*)(?=\\s|=|/?>|/\\*|//)",
"name": "meta.tag.attribute-name"
},
},

"ng-tag-attributes": {
"patterns": [
Expand Down Expand Up @@ -333,4 +333,4 @@
}
},
"scopeName": "template.ng"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -618,4 +618,4 @@
]
}
}
}
}
6 changes: 3 additions & 3 deletions org.eclipse.tm4e.languageconfiguration/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.tm4e.languageconfiguration;singleton:=true
Bundle-Version: 0.5.4.qualifier
Bundle-Version: 0.5.5.qualifier
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.3",
org.eclipse.tm4e.ui;bundle-version="0.6.2",
org.eclipse.tm4e.core;bundle-version="0.5.4",
org.eclipse.tm4e.ui;bundle-version="0.6.4",
org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.ui,
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.languageconfiguration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

<artifactId>org.eclipse.tm4e.languageconfiguration</artifactId>
<packaging>eclipse-plugin</packaging>
<version>0.5.4-SNAPSHOT</version>
<version>0.5.5-SNAPSHOT</version>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
import org.eclipse.tm4e.ui.internal.model.TMModelManager;
import org.eclipse.tm4e.ui.internal.utils.ContentTypeHelper;
import org.eclipse.tm4e.ui.internal.utils.ContentTypeInfo;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
import org.eclipse.ui.texteditor.ITextEditor;
Expand Down Expand Up @@ -180,6 +177,7 @@ private static boolean isFollowedBy(final IDocument document, int offset, final
}

private void onEnter(final IDocument document, final DocumentCommand command, final @Nullable ITextEditor editor) {
final var contentTypes = this.contentTypes;
if (contentTypes != null) {
final var registry = LanguageConfigurationRegistryManager.getInstance();
for (final IContentType contentType : contentTypes) {
Expand Down Expand Up @@ -223,8 +221,10 @@ private void onEnter(final IDocument document, final DocumentCommand command, fi
break;
}
case Outdent:
final String indentation = TextUtils.getIndentationFromWhitespace(enterAction.indentation, getTabSize(editor), isInsertSpaces(editor));
final String outdentedText = outdentString(normalizeIndentation(indentation + enterAction.appendText, editor), editor);
final String indentation = TextUtils.getIndentationFromWhitespace(enterAction.indentation, getTabSize(editor),
isInsertSpaces(editor));
final String outdentedText = outdentString(normalizeIndentation(indentation + enterAction.appendText, editor),
editor);

command.text = delim + outdentedText;
command.shiftsCaret = false;
Expand Down Expand Up @@ -254,8 +254,8 @@ private void onEnter(final IDocument document, final DocumentCommand command, fi
return contentTypes;
}

private String outdentString(final String str, @Nullable ITextEditor editor) {
if (str.startsWith("\t")) {//$NON-NLS-1$
private String outdentString(final String str, final @Nullable ITextEditor editor) {
if (str.startsWith("\t")) { //$NON-NLS-1$
return str.substring(1);
}
if (isInsertSpaces(editor)) {
Expand All @@ -269,36 +269,33 @@ private String outdentString(final String str, @Nullable ITextEditor editor) {
return str;
}

private String normalizeIndentation(final String str, @Nullable ITextEditor editor) {
int tabSize = getTabSize(editor);
boolean insertSpaces = isInsertSpaces(editor);
private String normalizeIndentation(final String str, final @Nullable ITextEditor editor) {
final int tabSize = getTabSize(editor);
final boolean insertSpaces = isInsertSpaces(editor);
return TextUtils.normalizeIndentation(str, tabSize, insertSpaces);
}

private int getTabSize(@Nullable ITextEditor editor) {
String name = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH;
private int getTabSize(final @Nullable ITextEditor editor) {
final String name = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH;
return getPreferenceStoreFor(name, editor).getInt(name);
}
private boolean isInsertSpaces(@Nullable ITextEditor editor) {
String name = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS;

private boolean isInsertSpaces(final @Nullable ITextEditor editor) {
final String name = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS;
return getPreferenceStoreFor(name, editor).getBoolean(name);
}

private IPreferenceStore getPreferenceStoreFor(String name, @Nullable ITextEditor editor) {
IPreferenceStore editorPreferenceStore = editor != null ? editor.getAdapter(IPreferenceStore.class) : null;
private IPreferenceStore getPreferenceStoreFor(final String name, final @Nullable ITextEditor editor) {
final IPreferenceStore editorPreferenceStore = editor != null ? editor.getAdapter(IPreferenceStore.class) : null;
if (editorPreferenceStore != null && editorPreferenceStore.contains(name)) {
return editorPreferenceStore;
}
return EditorsUI.getPreferenceStore();
}


private void installViewer() {
if (viewer == null) {
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final IEditorPart editorPart = page.getActiveEditor();
viewer = editorPart.getAdapter(ITextViewer.class);
viewer = UI.getActiveTextViewer();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ protected Control createContents(@Nullable final Composite ancestor) {

/**
* Create grammar list content.
*
* @param parent
*/
private void createDefinitionsListContent(final Composite parent) {
final var description = new Label(parent, SWT.NONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,18 @@ public interface ILanguageConfigurationRegistryManager {
* Add language configuration definition to the registry.
*
* NOTE: you must call save() method if you wish to save in the preferences.
*
* @param definition
*/
void registerLanguageConfigurationDefinition(ILanguageConfigurationDefinition definition);

/**
* Remove language configuration definition from the registry.
*
* NOTE: you must call save() method if you wish to save in the preferences.
*
* @param definition
*/
void unregisterLanguageConfigurationDefinition(ILanguageConfigurationDefinition definition);

/**
* Save the language configuration definitions.
*
* @throws BackingStoreException
*/
void save() throws BackingStoreException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public CompleteEnterAction getEnterAction(final IDocument document, final int of

return new CompleteEnterAction(enterResult, indentation);
} catch (final BadLocationException e1) {
// ignore
}
return null;
}
Expand Down
Loading

0 comments on commit 7a8619d

Please sign in to comment.