Skip to content

Commit

Permalink
refact: remove unused code and reduce visibility of some code
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Feb 8, 2024
1 parent 33f0c0c commit 13fecf1
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/grammar/grammar.ts#L418">
* github.com/microsoft/vscode-textmate/blob/main/src/grammar/grammar.ts</a>
*/
public final class AttributedScopeStack {
final class AttributedScopeStack {

@NonNullByDefault({}) // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/233
record Frame(int encodedTokenAttributes, List<String> scopeNames) {
Expand All @@ -49,12 +49,12 @@ static AttributedScopeStack fromExtension(final @Nullable AttributedScopeStack n
return current;
}

public static AttributedScopeStack createRoot(final String scopeName,
static AttributedScopeStack createRoot(final String scopeName,
final int /*EncodedTokenAttributes*/ tokenAttributes) {
return new AttributedScopeStack(null, new ScopeStack(null, scopeName), tokenAttributes);
}

public static AttributedScopeStack createRootAndLookUpScopeName(final String scopeName, final int encodedTokenAttributes,
static AttributedScopeStack createRootAndLookUpScopeName(final String scopeName, final int encodedTokenAttributes,
final Grammar grammar) {
final var rawRootMetadata = grammar.getMetadataForScope(scopeName);
final var scopePath = new ScopeStack(null, scopeName);
Expand All @@ -68,15 +68,15 @@ public static AttributedScopeStack createRootAndLookUpScopeName(final String sco
return new AttributedScopeStack(null, scopePath, resolvedTokenAttributes);
}

public String scopeName() {
String scopeName() {
return this.scopePath.scopeName;
}

private final @Nullable AttributedScopeStack parent;
private final ScopeStack scopePath;
final int tokenAttributes;

public AttributedScopeStack(
private AttributedScopeStack(
final @Nullable AttributedScopeStack parent,
final ScopeStack scopePath,
final int tokenAttributes) {
Expand All @@ -90,11 +90,11 @@ public String toString() {
return String.join(" ", this.getScopeNames());
}

public boolean equals(final AttributedScopeStack other) {
boolean equals(final AttributedScopeStack other) {
return equals(this, other);
}

public static boolean equals(
static boolean equals(
@Nullable AttributedScopeStack a,
@Nullable AttributedScopeStack b) {
do {
Expand Down Expand Up @@ -123,7 +123,7 @@ public static boolean equals(
} while (true);
}

public static int mergeAttributes(
static int mergeAttributes(
final int existingTokenAttributes,
final BasicScopeAttributes basicScopeAttributes,
final @Nullable StyleAttributes styleAttributes) {
Expand Down Expand Up @@ -184,7 +184,7 @@ List<String> getScopeNames() {
return this.scopePath.getSegments();
}

public List<AttributedScopeStack.Frame> getExtensionIfDefined(final @Nullable AttributedScopeStack base) {
List<AttributedScopeStack.Frame> getExtensionIfDefined(final @Nullable AttributedScopeStack base) {
final var result = new ArrayList<AttributedScopeStack.Frame>();
var self = this;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ private record WhileCheckResult(
}

static final class TokenizeStringResult {
public final StateStack stack;
public final boolean stoppedEarly;
final StateStack stack;
final boolean stoppedEarly;

TokenizeStringResult(final StateStack stack, final boolean stoppedEarly) {
private TokenizeStringResult(final StateStack stack, final boolean stoppedEarly) {
this.stack = stack;
this.stoppedEarly = stoppedEarly;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,16 @@ public static ScopeStack from(final String... segments) {
return result;
}

@Nullable
public static ScopeStack from(final List<String> segments) {
ScopeStack result = null;
for (var i = 0; i < segments.size(); i++) {
result = new ScopeStack(result, segments.get(i));
}
return result;
}

@Nullable
public final ScopeStack parent;
public final String scopeName;

public ScopeStack(@Nullable final ScopeStack parent, final String scopeName) {
ScopeStack(@Nullable final ScopeStack parent, final String scopeName) {
this.parent = parent;
this.scopeName = scopeName;
}

public ScopeStack push(final String scopeName) {
ScopeStack push(final String scopeName) {
return new ScopeStack(this, scopeName);
}

Expand Down Expand Up @@ -101,7 +92,7 @@ public boolean isExtending(final ScopeStack other) {
return parent.isExtending(other);
}

public List<String> getExtensionIfDefined(@Nullable final ScopeStack base) {
List<String> getExtensionIfDefined(@Nullable final ScopeStack base) {
final var result = new ArrayList<String>();
@Nullable
ScopeStack item = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package org.eclipse.tm4e.core.internal.grammar.dependencies;

import org.eclipse.tm4e.core.internal.grammar.raw.RawRepository;

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/grammar/grammarDependencies.ts#L240">
Expand All @@ -31,13 +33,13 @@ public enum Kind {
TopLevelRepositoryReference
}

public static final IncludeReference BASE = new IncludeReference(Kind.Base, "$base", "");
public static final IncludeReference SELF = new IncludeReference(Kind.Base, "$self", "");
private static final IncludeReference BASE = new IncludeReference(Kind.Base, RawRepository.DOLLAR_BASE, "");
private static final IncludeReference SELF = new IncludeReference(Kind.Base, RawRepository.DOLLAR_SELF, "");

public static IncludeReference parseInclude(final String include) {
return switch (include) {
case "$base" -> BASE;
case "$self" -> SELF;
case RawRepository.DOLLAR_BASE -> BASE;
case RawRepository.DOLLAR_SELF -> SELF;
default -> {
final var indexOfSharp = include.indexOf('#');
yield switch (indexOfSharp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ void add(final AbsoluteRuleReference reference) {
}
}

public final Set<String /*ScopeName*/> seenFullScopeRequests = new HashSet<>();
final Set<String> seenPartialScopeRequests = new HashSet<>();
private final Set<String /*ScopeName*/> seenFullScopeRequests = new HashSet<>();
private final Set<String> seenPartialScopeRequests = new HashSet<>();
public Deque<AbsoluteRuleReference> Q = new ArrayDeque<>();

public final IGrammarRepository repo;
public final String initialScopeName;
private final IGrammarRepository repo;
private final String initialScopeName;

public ScopeDependencyProcessor(final IGrammarRepository repo, final String initialScopeName) {
this.repo = repo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import org.eclipse.tm4e.core.internal.parser.PropertySettable;

public final class RawCaptures extends PropertySettable.HashMap<IRawRule> implements IRawCaptures {
final class RawCaptures extends PropertySettable.HashMap<IRawRule> implements IRawCaptures {

private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ public class RawRule extends PropertySettable.HashMap<@Nullable Object> implemen

private static final String APPLY_END_PATTERN_LAST = "applyEndPatternLast";
private static final String BEGIN = "begin";
public static final String BEGIN_CAPTURES = "beginCaptures";
public static final String CAPTURES = "captures";
static final String BEGIN_CAPTURES = "beginCaptures";
static final String CAPTURES = "captures";
private static final String CONTENT_NAME = "contentName";
private static final String END = "end";
public static final String END_CAPTURES = "endCaptures";
static final String END_CAPTURES = "endCaptures";
private static final String ID = "id";
private static final String INCLUDE = "include";
private static final String MATCH = "match";
private static final String NAME = "name";
private static final String PATTERNS = "patterns";
public static final String REPOSITORY = "repository";
static final String REPOSITORY = "repository";
private static final String WHILE = "while";
public static final String WHILE_CAPTURES = "whileCaptures";
static final String WHILE_CAPTURES = "whileCaptures";

private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
*/
public class CSSParser {

private static InputSource toSource(final InputStream source) {
final var in = new InputSource();
in.setByteStream(source);
return in;
}

protected final CSSDocumentHandler handler = new CSSDocumentHandler();

protected CSSParser() {
Expand All @@ -43,12 +49,6 @@ public CSSParser(final InputStream source) throws Exception {
this(toSource(source));
}

private static InputSource toSource(final InputStream source) {
final var in = new InputSource();
in.setByteStream(source);
return in;
}

public CSSParser(final InputSource source) throws Exception {
this(source, new SACParserFactory().makeParser());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tm4e.languageconfiguration.internal.model.LanguageConfiguration;

public abstract class AbstractLanguageConfigurationRegistryManager implements ILanguageConfigurationRegistryManager {
abstract class AbstractLanguageConfigurationRegistryManager implements ILanguageConfigurationRegistryManager {

protected final Map<IContentType, ILanguageConfigurationDefinition> pluginDefinitions = new HashMap<>();
protected final Map<IContentType, ILanguageConfigurationDefinition> userDefinitions = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public LanguageConfigurationDefinition(final IContentType contentType, final Str
this.contentType = contentType;
}

public LanguageConfigurationDefinition(final IConfigurationElement ce) throws CoreException {
LanguageConfigurationDefinition(final IConfigurationElement ce) throws CoreException {
super(ce);
final var contentTypeId = ce.getAttribute(XMLConstants.CONTENT_TYPE_ID_ATTR);
final var contentType = ContentTypeHelper.getContentTypeById(contentTypeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.tm4e.languageconfiguration.internal.model.CharacterPair;
Expand Down Expand Up @@ -59,12 +58,10 @@ public class LanguageConfigurationInfoWidget extends Composite {

private CharacterPairsTableWidget bracketsTable = lazyNonNull();

protected TabItem autoClosingPairsTab = lazyNonNull();
private AutoClosingPairConditionalTableWidget autoClosingPairsTable = lazyNonNull();

private Text autoCloseBeforeText = lazyNonNull();

protected TabItem surroundingPairsTab = lazyNonNull();
private CharacterPairsTableWidget surroundingPairsTable = lazyNonNull();

private Text foldingOffsideText = lazyNonNull();
Expand All @@ -73,7 +70,6 @@ public class LanguageConfigurationInfoWidget extends Composite {

private Text wordPatternText = lazyNonNull();

protected TabItem onEnterRulesTab = lazyNonNull();
private OnEnterRuleTableWidget onEnterRuleTable = lazyNonNull();

private Text indentationDecreaseIndentPattern = lazyNonNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,41 +93,6 @@ public GrammarPreferencePage() {
setDescription(TMUIMessages.GrammarPreferencePage_description);
}

/**
* Returns the grammar registry manager.
*
* @return the grammar registry manager.
*/
IGrammarRegistryManager getGrammarRegistryManager() {
return grammarRegistryManager;
}

/**
* Set the grammar registry manager.
*
* @param grammarRegistryManager
*/
void setGrammarRegistryManager(final IGrammarRegistryManager grammarRegistryManager) {
this.grammarRegistryManager = grammarRegistryManager;
}

/**
* Returns the theme manager.
*
* @return the theme manager.
*/
IThemeManager getThemeManager() {
return themeManager;
}

ISnippetManager getSnippetManager() {
return snippetManager;
}

void setSnippetManager(final ISnippetManager snippetManager) {
this.snippetManager = snippetManager;
}

@Override
protected Control createContents(final @Nullable Composite ancestor) {
final var parent = new Composite(ancestor, SWT.NONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
Expand All @@ -39,7 +35,6 @@
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.tm4e.core.grammar.IGrammar;
import org.eclipse.tm4e.registry.IGrammarDefinition;
import org.eclipse.tm4e.registry.IGrammarRegistryManager;
Expand Down Expand Up @@ -116,19 +111,6 @@ protected Control createContents(final @Nullable Composite ancestor) {
return parent;
}

protected void createColumn(final TableColumnLayout tableColumnLayout, final String label, final int columnWeight, final int minColWidth, final boolean resizable) {
final var col = new TableColumn(themesTable.getTable(), SWT.NONE);
col.setText(label);
final GC gc = new GC(themesTable.getTable().getShell());
try {
gc.setFont(JFaceResources.getDialogFont());
final int labelWidth = gc.stringExtent(label).x + 15;
tableColumnLayout.setColumnData(col, new ColumnWeightData(columnWeight, Math.max(labelWidth, minColWidth), resizable));
} finally {
gc.dispose();
}
}

/**
* Create the theme list content.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@
/**
* Input stream which reads from a document
*/
public final class DocumentInputStream extends InputStream {
final class DocumentInputStream extends InputStream {

private final IDocument doc;
private int pos = 0;

public DocumentInputStream(final IDocument document) {
DocumentInputStream(final IDocument document) {
doc = document;
}

public IDocument getDocument() {
return doc;
}

@Override
public int read(@NonNullByDefault({}) final byte[] buff, final int buffOffset, final int len) throws IOException {
Objects.checkFromIndexSize(buffOffset, len, buff.length);
Expand Down
Loading

0 comments on commit 13fecf1

Please sign in to comment.