Skip to content

Commit

Permalink
chore: fix formatting (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-jeffery authored Jul 21, 2024
1 parent f088ddc commit 114da44
Show file tree
Hide file tree
Showing 48 changed files with 300 additions and 280 deletions.
13 changes: 13 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id("java")
id("jacoco")
id("com.diffplug.spotless") version "6.25.0"
id("org.jetbrains.kotlin.jvm") version "1.9.24"
id("org.jetbrains.intellij") version "1.17.3"
id("org.jetbrains.grammarkit") version "2022.3.2"
Expand All @@ -22,6 +23,8 @@ dependencies {
implementation("org.apache.commons:commons-lang3:3.14.0")
implementation("dev.openfga:openfga-language:v0.2.0-beta.1")

implementation("com.diffplug.spotless:spotless-plugin-gradle:6.25.0")

testImplementation("junit:junit:4.13.2")
}

Expand All @@ -43,6 +46,15 @@ grammarKit {
intellijRelease.set("203.7717.81")
}

spotless {
java {
target("src/main/java/dev/openfga/intellijplugin/**/*.java")
palantirJavaFormat()
removeUnusedImports()
importOrder()
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "17"
Expand Down Expand Up @@ -120,3 +132,4 @@ tasks {
token.set(System.getenv("PUBLISH_TOKEN"))
}
}

1 change: 1 addition & 0 deletions src/main/java/dev/openfga/intellijplugin/Notifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static void notifyError(Project project, String content) {
.createNotification(content, NotificationType.ERROR)
.notify(project);
}

public static void notifyError(String title, String content) {
notifyError(null, title, content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
import com.intellij.openapi.options.colors.AttributesDescriptor;
import com.intellij.openapi.options.colors.ColorDescriptor;
import com.intellij.openapi.options.colors.ColorSettingsPage;
import java.util.Map;
import javax.swing.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.Map;

public class OpenFGAColorSettingsPage implements ColorSettingsPage {
public class OpenFGAColorSettingsPage implements ColorSettingsPage {

private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[]{
new AttributesDescriptor("Keyword", OpenFGASyntaxHighlighter.KEYWORD),
new AttributesDescriptor("Comment", OpenFGASyntaxHighlighter.COMMENT),
new AttributesDescriptor("Type identifier", OpenFGASyntaxHighlighter.TYPE_IDENTIFIER),
new AttributesDescriptor("Relation name", OpenFGASyntaxHighlighter.RELATION_NAME),
new AttributesDescriptor("Schema version", OpenFGASyntaxHighlighter.SCHEMA_VERSIONS),
private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[] {
new AttributesDescriptor("Keyword", OpenFGASyntaxHighlighter.KEYWORD),
new AttributesDescriptor("Comment", OpenFGASyntaxHighlighter.COMMENT),
new AttributesDescriptor("Type identifier", OpenFGASyntaxHighlighter.TYPE_IDENTIFIER),
new AttributesDescriptor("Relation name", OpenFGASyntaxHighlighter.RELATION_NAME),
new AttributesDescriptor("Schema version", OpenFGASyntaxHighlighter.SCHEMA_VERSIONS),
};

@Nullable
Expand All @@ -36,16 +35,15 @@ public SyntaxHighlighter getHighlighter() {
@NotNull
@Override
public String getDemoText() {
return "# Administrator model\n" +
"model\n" +
" schema 1.1\n" +
"\n" +
"type user\n" +
"type organization\n" +
" relations\n" +
" define administrator : [user]\n" +
" define entity_of: [entity]\n" +
" define member: administrator or member from entity_of";
return "# Administrator model\n" + "model\n"
+ " schema 1.1\n"
+ "\n"
+ "type user\n"
+ "type organization\n"
+ " relations\n"
+ " define administrator : [user]\n"
+ " define entity_of: [entity]\n"
+ " define member: administrator or member from entity_of";
}

@Nullable
Expand All @@ -69,5 +67,4 @@ public Map<String, TextAttributesKey> getAdditionalHighlightingTagToDescriptorMa
public String getDisplayName() {
return "OpenFGA";
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ public String getCommentedBlockCommentPrefix() {
public String getCommentedBlockCommentSuffix() {
return null;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import com.intellij.ide.fileTemplates.DefaultTemplatePropertiesProvider;
import com.intellij.psi.PsiDirectory;
import org.jetbrains.annotations.NotNull;

import java.util.Properties;
import org.jetbrains.annotations.NotNull;

public class OpenFGADefaultTemplatePropertiesProvider implements DefaultTemplatePropertiesProvider {
@Override
Expand Down
1 change: 0 additions & 1 deletion src/main/java/dev/openfga/intellijplugin/OpenFGAFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ public FileType getFileType() {
public String toString() {
return getFileType().getName();
}

}
11 changes: 4 additions & 7 deletions src/main/java/dev/openfga/intellijplugin/OpenFGAFileType.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
package dev.openfga.intellijplugin;

import com.intellij.openapi.fileTypes.LanguageFileType;
import javax.swing.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

public class OpenFGAFileType extends LanguageFileType {

public static final OpenFGAFileType INSTANCE = new OpenFGAFileType();

private OpenFGAFileType() {
private OpenFGAFileType() {
super(OpenFGALanguage.INSTANCE);
}

@NotNull
@Override
public String getName() {
return "OpenFGA File";
return "OpenFGA Model File";
}

@NotNull
@Override
public String getDescription() {
return "OpenFGA DSL file";
return "OpenFGA Model file";
}

@NotNull
Expand All @@ -37,6 +36,4 @@ public String getDefaultExtension() {
public Icon getIcon() {
return OpenFGAIcons.FILE;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ public void visit(@NotNull PsiElement element) {

for (var attributesKey : attributesKeys) {
builder = builder.textAttributes(attributesKey);

}

return builder.range(element).create();
}

@Override
public boolean analyze(@NotNull PsiFile file, boolean updateWholeFile, @NotNull HighlightInfoHolder holder, @NotNull Runnable action) {
public boolean analyze(
@NotNull PsiFile file,
boolean updateWholeFile,
@NotNull HighlightInfoHolder holder,
@NotNull Runnable action) {
myHolder = holder;
openfgaHighlighter = new OpenFGASyntaxHighlighter();
try {
Expand All @@ -72,5 +75,4 @@ public boolean analyze(@NotNull PsiFile file, boolean updateWholeFile, @NotNull
}
return true;
}

}
2 changes: 0 additions & 2 deletions src/main/java/dev/openfga/intellijplugin/OpenFGAIcons.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package dev.openfga.intellijplugin;

import com.intellij.openapi.util.IconLoader;

import javax.swing.*;

public interface OpenFGAIcons {

Icon FILE = IconLoader.getIcon("/icons/openfga-color-transparent-16x16.svg", OpenFGAIcons.class);
Icon TOOL_WINDOW = IconLoader.getIcon("/icons/tool-window.svg", OpenFGAIcons.class);

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ public class OpenFGALanguage extends Language {
private OpenFGALanguage() {
super("OpenFGA");
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package dev.openfga.intellijplugin;

import dev.openfga.intellijplugin.parsing.OpenFGALexer;
import com.intellij.lexer.FlexAdapter;
import dev.openfga.intellijplugin.parsing.OpenFGALexer;

public class OpenFGALexerAdapter extends FlexAdapter {

public OpenFGALexerAdapter() {
super(new OpenFGALexer(null));
}

}
}
40 changes: 40 additions & 0 deletions src/main/java/dev/openfga/intellijplugin/OpenFGAStoreFileType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package dev.openfga.intellijplugin;

import com.intellij.openapi.fileTypes.LanguageFileType;
import javax.swing.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.yaml.YAMLLanguage;

public class OpenFGAStoreFileType extends LanguageFileType {

public static final OpenFGAStoreFileType INSTANCE = new OpenFGAStoreFileType();

private OpenFGAStoreFileType() {
super(YAMLLanguage.INSTANCE);
}

@NotNull
@Override
public String getName() {
return "OpenFGA Store File";
}

@NotNull
@Override
public String getDescription() {
return "OpenFGA Store file";
}

@NotNull
@Override
public String getDefaultExtension() {
return "fga.yaml";
}

@Nullable
@Override
public Icon getIcon() {
return OpenFGAIcons.FILE;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package dev.openfga.intellijplugin;

import dev.openfga.intellijplugin.parsing.OpenFGATokenSets;
import dev.openfga.intellijplugin.psi.OpenFGATypes;
import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey;

import com.intellij.lexer.Lexer;
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase;
import com.intellij.psi.tree.IElementType;
import dev.openfga.intellijplugin.parsing.OpenFGATokenSets;
import dev.openfga.intellijplugin.psi.OpenFGATypes;
import org.jetbrains.annotations.NotNull;

import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey;

public class OpenFGASyntaxHighlighter extends SyntaxHighlighterBase {
public static final TextAttributesKey KEYWORD =
createTextAttributesKey("OPENFGA_KEYWORD", DefaultLanguageHighlighterColors.KEYWORD);
Expand All @@ -30,25 +30,26 @@ public class OpenFGASyntaxHighlighter extends SyntaxHighlighterBase {
createTextAttributesKey("OPENFGA_CONDITION_IDENTIFIER", DefaultLanguageHighlighterColors.CLASS_NAME);
public static final TextAttributesKey CONDITION_REFERENCE =
createTextAttributesKey("OPENFGA_CONDITION_REFERENCE", DefaultLanguageHighlighterColors.CLASS_REFERENCE);
public static final TextAttributesKey CONDITION_PARAM_IDENTIFIER =
createTextAttributesKey("OPENFGA_CONDITION_PARAM_IDENTIFIER", DefaultLanguageHighlighterColors.INSTANCE_METHOD);
public static final TextAttributesKey CONDITION_PARAM_IDENTIFIER = createTextAttributesKey(
"OPENFGA_CONDITION_PARAM_IDENTIFIER", DefaultLanguageHighlighterColors.INSTANCE_METHOD);
public static final TextAttributesKey CONDITION_PARAM_TYPE =
createTextAttributesKey("OPENFGA_CONDITION_PARAM_TYPE", DefaultLanguageHighlighterColors.PARAMETER);
public static final TextAttributesKey COMMENT =
createTextAttributesKey("OPENFGA_COMMENTS", DefaultLanguageHighlighterColors.LINE_COMMENT);

private static final TextAttributesKey[] KEYWORD_KEYS = new TextAttributesKey[]{KEYWORD};
private static final TextAttributesKey[] MODULE_NAME_KEY = new TextAttributesKey[]{MODULE_NAME};
private static final TextAttributesKey[] SCHEMA_VERSIONS_KEYS = new TextAttributesKey[]{SCHEMA_VERSIONS};
private static final TextAttributesKey[] RELATION_NAME_KEYS = new TextAttributesKey[]{RELATION_NAME};
private static final TextAttributesKey[] RELATION_REFERENCE_KEYS = new TextAttributesKey[]{RELATION_REFERENCE};
private static final TextAttributesKey[] TYPE_IDENTIFIER_KEYS = new TextAttributesKey[]{TYPE_IDENTIFIER};
private static final TextAttributesKey[] TYPE_REFERENCE_KEYS = new TextAttributesKey[]{TYPE_REFERENCE};
private static final TextAttributesKey[] CONDITION_IDENTIFIER_KEYS = new TextAttributesKey[]{CONDITION_IDENTIFIER};
private static final TextAttributesKey[] CONDITION_REFERENCE_KEYS = new TextAttributesKey[]{CONDITION_REFERENCE};
private static final TextAttributesKey[] CONDITION_PARAM_KEYS = new TextAttributesKey[]{CONDITION_PARAM_IDENTIFIER};
private static final TextAttributesKey[] CONDITION_PARAM_TYPES = new TextAttributesKey[]{CONDITION_PARAM_TYPE};
private static final TextAttributesKey[] COMMENT_KEYS = new TextAttributesKey[]{COMMENT};
private static final TextAttributesKey[] KEYWORD_KEYS = new TextAttributesKey[] {KEYWORD};
private static final TextAttributesKey[] MODULE_NAME_KEY = new TextAttributesKey[] {MODULE_NAME};
private static final TextAttributesKey[] SCHEMA_VERSIONS_KEYS = new TextAttributesKey[] {SCHEMA_VERSIONS};
private static final TextAttributesKey[] RELATION_NAME_KEYS = new TextAttributesKey[] {RELATION_NAME};
private static final TextAttributesKey[] RELATION_REFERENCE_KEYS = new TextAttributesKey[] {RELATION_REFERENCE};
private static final TextAttributesKey[] TYPE_IDENTIFIER_KEYS = new TextAttributesKey[] {TYPE_IDENTIFIER};
private static final TextAttributesKey[] TYPE_REFERENCE_KEYS = new TextAttributesKey[] {TYPE_REFERENCE};
private static final TextAttributesKey[] CONDITION_IDENTIFIER_KEYS = new TextAttributesKey[] {CONDITION_IDENTIFIER};
private static final TextAttributesKey[] CONDITION_REFERENCE_KEYS = new TextAttributesKey[] {CONDITION_REFERENCE};
private static final TextAttributesKey[] CONDITION_PARAM_KEYS =
new TextAttributesKey[] {CONDITION_PARAM_IDENTIFIER};
private static final TextAttributesKey[] CONDITION_PARAM_TYPES = new TextAttributesKey[] {CONDITION_PARAM_TYPE};
private static final TextAttributesKey[] COMMENT_KEYS = new TextAttributesKey[] {COMMENT};
private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[0];

@NotNull
Expand Down Expand Up @@ -110,5 +111,4 @@ public Lexer getHighlightingLexer() {

return EMPTY_KEYS;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ public class OpenFGASyntaxHighlighterFactory extends SyntaxHighlighterFactory {
public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile) {
return new OpenFGASyntaxHighlighter();
}

}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package dev.openfga.intellijplugin.actions;

import dev.openfga.intellijplugin.cli.tasks.DslToJsonTask;
import dev.openfga.intellijplugin.OpenFGALanguage;
import dev.openfga.intellijplugin.settings.OpenFGASettingsState;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.progress.ProgressManager;
import dev.openfga.intellijplugin.OpenFGALanguage;
import dev.openfga.intellijplugin.cli.tasks.DslToJsonTask;
import dev.openfga.intellijplugin.settings.OpenFGASettingsState;
import org.jetbrains.annotations.NotNull;

public class DslToJsonAction extends AnAction {
Expand Down Expand Up @@ -41,12 +41,11 @@ public void actionPerformed(@NotNull AnActionEvent event) {
if (virtualFile == null) {
return;
}
DslToJsonTask.create(dslFile, virtualFile.toNioPath())
.ifPresent(ProgressManager.getInstance()::run);
DslToJsonTask.create(dslFile, virtualFile.toNioPath()).ifPresent(ProgressManager.getInstance()::run);
}

@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}
}
}
Loading

0 comments on commit 114da44

Please sign in to comment.