chore: Cleanup code

This commit is contained in:
FalsePattern 2023-08-10 22:40:16 +02:00
parent 9438d8052f
commit a6e3703616
Signed by: falsepattern
GPG key ID: FDF7126A9E124447
11 changed files with 55 additions and 54 deletions

View file

@ -65,7 +65,9 @@ public class HighlightingUtil {
if (editor.isDisposed()) {
return;
}
if (highlightRanges.size() == 1 && highlightRanges.get(0).start() == 0 && highlightRanges.get(0).remove() == -1) {
if (highlightRanges.size() == 1 &&
highlightRanges.get(0).start() == 0 &&
highlightRanges.get(0).remove() == -1) {
markup.removeAllHighlighters();
}
var documentLength = editor.getDocument().getTextLength();

View file

@ -48,8 +48,8 @@ public class AppSettingsComponent {
.addLabeledComponent(new JBLabel("Asynchronous code folding ranges: "),
asyncFoldingCheckBox, 1, false)
.addSeparator()
.addComponent(new JBLabel("Developer settings" +
" (only usable when the IDE was launched with " +
.addComponent(new JBLabel(
"Developer settings (only usable when the IDE was launched with " +
"the runIDE gradle task in ZigBrains!)"))
.addVerticalGap(10)
.addLabeledComponent(new JBLabel("ZLS debug log: "), debugCheckBox, 1, false)

View file

@ -20,6 +20,7 @@ import com.intellij.lang.Language;
public class ZonLanguage extends Language {
public static final ZonLanguage INSTANCE = new ZonLanguage();
private ZonLanguage() {
super("Zon");
}

View file

@ -38,6 +38,7 @@ import java.util.Set;
public class ZonCompletionContributor extends CompletionContributor {
private static final List<String> ZON_ROOT_KEYS = List.of("name", "version", "dependencies");
private static final List<String> ZON_DEP_KEYS = List.of("url", "hash");
public ZonCompletionContributor() {
extend(CompletionType.BASIC,
PlatformPatterns.psiElement()
@ -79,8 +80,9 @@ public class ZonCompletionContributor extends CompletionContributor {
}
});
}
private static void doAddCompletions(boolean hasDot, Set<String> current, List<String> expected, CompletionResultSet result) {
for (var key: expected) {
for (var key : expected) {
if (current.contains(key)) {
continue;
}

View file

@ -35,8 +35,7 @@ import java.util.List;
public class ZonBlock extends AbstractBlock {
private final SpacingBuilder spacingBuilder;
protected ZonBlock(@NotNull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment,
SpacingBuilder spacingBuilder) {
protected ZonBlock(@NotNull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment, SpacingBuilder spacingBuilder) {
super(node, wrap, alignment);
this.spacingBuilder = spacingBuilder;
}
@ -46,9 +45,8 @@ public class ZonBlock extends AbstractBlock {
var blocks = new ArrayList<Block>();
var child = myNode.getFirstChildNode();
while (child != null) {
if ( child.getElementType() != TokenType.WHITE_SPACE) {
var block = new ZonBlock(child, null, null,
spacingBuilder);
if (child.getElementType() != TokenType.WHITE_SPACE) {
var block = new ZonBlock(child, null, null, spacingBuilder);
blocks.add(block);
}
child = child.getTreeNext();
@ -66,8 +64,6 @@ public class ZonBlock extends AbstractBlock {
}
@Override
public @Nullable Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) {
return null;

View file

@ -29,6 +29,7 @@ public class ZonFormattingModelBuilder implements FormattingModelBuilder {
private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {
return new SpacingBuilder(settings, ZonLanguage.INSTANCE);
}
@Override
public @NotNull FormattingModel createModel(@NotNull FormattingContext formattingContext) {
final var codeStyleSettings = formattingContext.getCodeStyleSettings();

View file

@ -22,7 +22,6 @@ import com.intellij.openapi.fileTypes.SyntaxHighlighter;
import com.intellij.openapi.options.colors.AttributesDescriptor;
import com.intellij.openapi.options.colors.ColorDescriptor;
import com.intellij.openapi.options.colors.ColorSettingsPage;
import com.intellij.openapi.util.NlsContexts;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -31,16 +30,14 @@ import javax.swing.Icon;
import java.util.Map;
public class ZonColorSettingsPage implements ColorSettingsPage {
private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[] {
desc("Equals", ZonSyntaxHighlighter.EQ),
private static final AttributesDescriptor[] DESCRIPTORS =
new AttributesDescriptor[]{desc("Equals", ZonSyntaxHighlighter.EQ),
desc("Identifier", ZonSyntaxHighlighter.ID),
desc("Comment", ZonSyntaxHighlighter.COMMENT),
desc("Bad Value", ZonSyntaxHighlighter.BAD_CHAR),
desc("String", ZonSyntaxHighlighter.STRING),
desc("Comma", ZonSyntaxHighlighter.COMMA),
desc("Dot", ZonSyntaxHighlighter.DOT),
desc("Braces", ZonSyntaxHighlighter.BRACE)
};
desc("Comma", ZonSyntaxHighlighter.COMMA), desc("Dot", ZonSyntaxHighlighter.DOT),
desc("Braces", ZonSyntaxHighlighter.BRACE)};
private static AttributesDescriptor desc(String name, TextAttributesKey key) {
return new AttributesDescriptor(name, key);

View file

@ -31,7 +31,7 @@ import java.util.HashMap;
import java.util.Map;
public class ZonSyntaxHighlighter extends SyntaxHighlighterBase {
// @formatter: off
// @formatter:off
public static final TextAttributesKey
EQ = createKey("EQ" , DefaultLanguageHighlighterColors.OPERATION_SIGN),
ID = createKey("ID" , DefaultLanguageHighlighterColors.INSTANCE_FIELD),
@ -41,13 +41,13 @@ public class ZonSyntaxHighlighter extends SyntaxHighlighterBase {
COMMA = createKey("COMMA" , DefaultLanguageHighlighterColors.COMMA ),
DOT = createKey("DOT" , DefaultLanguageHighlighterColors.DOT ),
BRACE = createKey("BRACE" , DefaultLanguageHighlighterColors.BRACES );
// @formatter: on
// @formatter:on
private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[0];
private static final Map<IElementType, TextAttributesKey[]> KEYMAP = new HashMap<>();
static {
// @formatter: off
// @formatter:off
addMapping(DOT , ZonTypes.DOT);
addMapping(COMMA , ZonTypes.COMMA);
addMapping(BRACE , ZonTypes.LBRACE);
@ -57,11 +57,11 @@ public class ZonSyntaxHighlighter extends SyntaxHighlighterBase {
addMapping(COMMENT , ZonTypes.COMMENT);
addMapping(ID , ZonTypes.ID);
addMapping(EQ , ZonTypes.EQ);
// @formatter: on
// @formatter:on
}
private static void addMapping(TextAttributesKey key, IElementType... types) {
for (var type: types) {
for (var type : types) {
KEYMAP.put(type, new TextAttributesKey[]{key});
}
}

View file

@ -27,6 +27,7 @@ import org.jetbrains.annotations.Nullable;
public class ZonBraceMatcher implements PairedBraceMatcher {
public static final BracePair PAIR = new BracePair(ZonTypes.LBRACE, ZonTypes.RBRACE, true);
private static final BracePair[] PAIRS = new BracePair[]{PAIR};
@Override
public BracePair @NotNull [] getPairs() {
return PAIRS;

View file

@ -33,6 +33,7 @@ import org.jetbrains.annotations.NotNull;
public class ZonParserDefinition implements ParserDefinition {
public static final IFileElementType FILE = new IFileElementType(ZonLanguage.INSTANCE);
@Override
public @NotNull Lexer createLexer(Project project) {
return new ZonLexerAdapter();

View file

@ -26,7 +26,7 @@ import java.util.Set;
public class ZonPsiImplUtil {
public static Set<String> getKeys(ZonStruct struct) {
var result = new HashSet<String>();
for (var property: struct.getPropertyList()) {
for (var property : struct.getPropertyList()) {
result.add(getText(property.getIdentifier()));
}
return result;