From db180813c79667c887e5f6d096439d079374cba1 Mon Sep 17 00:00:00 2001 From: Stepa Strunkov Date: Mon, 4 Jul 2022 16:48:30 +0300 Subject: [PATCH] fixed more reports --- .../eolang/jetbrains/EOColorSettingsPage.java | 36 ++++++++-------- .../java/org/eolang/jetbrains/EOFileType.java | 14 +++++++ .../eolang/jetbrains/EOFileTypeFactory.java | 4 ++ .../java/org/eolang/jetbrains/EOLanguage.java | 4 +- .../eolang/jetbrains/EOParserDefinition.java | 24 +++++++---- .../eolang/jetbrains/EOPluginController.java | 12 ++++-- .../eolang/jetbrains/EOSyntaxHighlighter.java | 42 ++++++++++++++++++- .../eolang/jetbrains/psi/EOPSIFileRoot.java | 6 ++- .../eolang/jetbrains/test/EOParsingTest1.java | 1 - 9 files changed, 108 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/eolang/jetbrains/EOColorSettingsPage.java b/src/main/java/org/eolang/jetbrains/EOColorSettingsPage.java index 622f6af..4970036 100755 --- a/src/main/java/org/eolang/jetbrains/EOColorSettingsPage.java +++ b/src/main/java/org/eolang/jetbrains/EOColorSettingsPage.java @@ -36,10 +36,10 @@ /** * Class drawing settings page in IDE + * @since 0.0.0 * @see - * documentation + * documentation */ - public class EOColorSettingsPage implements ColorSettingsPage { private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[] { @@ -49,7 +49,7 @@ public class EOColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor("Strings", EOSyntaxHighlighter.STRING), new AttributesDescriptor("Metas", EOSyntaxHighlighter.META), new AttributesDescriptor("Constants", EOSyntaxHighlighter.NUMBERS), - new AttributesDescriptor("Braces", EOSyntaxHighlighter.BRACES) + new AttributesDescriptor("Braces", EOSyntaxHighlighter.BRACES), }; @Nullable @@ -73,21 +73,21 @@ public SyntaxHighlighter getHighlighter() { @NotNull @Override public String getDemoText() { - return "+alias org.eolang.io.stdout\n" + - "+alias org.eolang.txt.sprintf\n\n" + - "# is year leap?\n\n" + - "[args...] > main\n" + - " [y] > leap\n" + - " or. > @\n" + - " and.\n" + - " eq. (mod. y 4) 0\n" + - " not. (eq. (mod. y 100) 0)\n" + - " eq. (mod. y 400) 0\n" + - " stdout > @\n" + - " sprintf\n" + - " \"%d is %sa leap year!\"\n" + - " (args.get 0).as-int > year!\n" + - " if. (leap year:y) \"\" \"not \"\n"; + return "+alias org.eolang.io.stdout\n" + + "+alias org.eolang.txt.sprintf\n\n" + + "# is year leap?\n\n" + + "[args...] > main\n" + + " [y] > leap\n" + + " or. > @\n" + + " and.\n" + + " eq. (mod. y 4) 0\n" + + " not. (eq. (mod. y 100) 0)\n" + + " eq. (mod. y 400) 0\n" + + " stdout > @\n" + + " sprintf\n" + + " \"%d is %sa leap year!\"\n" + + " (args.get 0).as-int > year!\n" + + " if. (leap year:y) \"\" \"not \"\n"; } @NotNull diff --git a/src/main/java/org/eolang/jetbrains/EOFileType.java b/src/main/java/org/eolang/jetbrains/EOFileType.java index ea22a88..130c33c 100755 --- a/src/main/java/org/eolang/jetbrains/EOFileType.java +++ b/src/main/java/org/eolang/jetbrains/EOFileType.java @@ -29,10 +29,24 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * Description of *.eo files. + * @since 0.0.0 + */ public class EOFileType extends LanguageFileType { + /** + * EO language file extension. + */ public static final String FILE_EXTENSION = "eo"; + + /** + * Creating instance. + */ public static final EOFileType INSTANCE = new EOFileType(); + /** + * Call constructor of super class. + */ protected EOFileType() { super(EOLanguage.INSTANCE); } diff --git a/src/main/java/org/eolang/jetbrains/EOFileTypeFactory.java b/src/main/java/org/eolang/jetbrains/EOFileTypeFactory.java index 9fe1a83..9101274 100755 --- a/src/main/java/org/eolang/jetbrains/EOFileTypeFactory.java +++ b/src/main/java/org/eolang/jetbrains/EOFileTypeFactory.java @@ -28,6 +28,10 @@ import com.intellij.openapi.fileTypes.FileTypeFactory; import org.jetbrains.annotations.NotNull; +/** + * Class for definition of FileType. + * @since 0.0.0 + */ public class EOFileTypeFactory extends FileTypeFactory { @Override public void createFileTypes(@NotNull final FileTypeConsumer fileTypeConsumer) { diff --git a/src/main/java/org/eolang/jetbrains/EOLanguage.java b/src/main/java/org/eolang/jetbrains/EOLanguage.java index 8924313..8edb30b 100755 --- a/src/main/java/org/eolang/jetbrains/EOLanguage.java +++ b/src/main/java/org/eolang/jetbrains/EOLanguage.java @@ -30,8 +30,10 @@ * Language Definition. * @since 0.0.0 */ - public final class EOLanguage extends Language { + /** + * Creating instance. + */ public static final EOLanguage INSTANCE = new EOLanguage(); /** diff --git a/src/main/java/org/eolang/jetbrains/EOParserDefinition.java b/src/main/java/org/eolang/jetbrains/EOParserDefinition.java index bba502f..1dabcd2 100755 --- a/src/main/java/org/eolang/jetbrains/EOParserDefinition.java +++ b/src/main/java/org/eolang/jetbrains/EOParserDefinition.java @@ -48,6 +48,9 @@ import org.eolang.jetbrains.psi.EOPSIFileRoot; import org.jetbrains.annotations.NotNull; +/** + * Let's define a parser for EO language + */ public class EOParserDefinition implements ParserDefinition { public static final IFileElementType FILE = new IFileElementType(EOLanguage.INSTANCE); @@ -55,9 +58,10 @@ public class EOParserDefinition implements ParserDefinition { static { PSIElementTypeFactory.defineLanguageIElementTypes( - EOLanguage.INSTANCE, EOParser.tokenNames, EOParser.ruleNames); + EOLanguage.INSTANCE, EOParser.tokenNames, EOParser.ruleNames + ); final List tokenIElementTypes = - PSIElementTypeFactory.getTokenIElementTypes(EOLanguage.INSTANCE); + PSIElementTypeFactory.getTokenIElementTypes(EOLanguage.INSTANCE); EOParserDefinition.ID = tokenIElementTypes.get(EOLexer.AT); } @@ -120,15 +124,17 @@ public PsiFile createFile(final FileViewProvider viewProvider) { } /** - * Convert from *NON-LEAF* parse node (AST they call it) to PSI node. Leaves are created in the - * AST factory. Rename re-factoring can cause this to be called on a TokenIElementType since we - * want to rename ID nodes. In that case, this method is called to create the root node but with - * ID type. Kind of strange, but we can simply create a ASTWrapperPsiElement to make everything + * Convert from *NON-LEAF* parse node (AST they call it) to PSI node. Leaves are + * created in the AST factory. Rename re-factoring can cause this to be called + * on a TokenIElementType since we want to rename ID nodes. In that case, this + * method is called to create the root node but with ID type. Kind of strange, + * but we can simply create a ASTWrapperPsiElement to make everything * work correctly. * - *

RuleIElementType. Ah! It's that ID is the root IElementType requested to parse, which means - * that the root node returned from parsetree->PSI conversion. But, it must be a CompositeElement! - * The adaptor calls rootMarker.done(root) to finish off the PSI conversion. + *

RuleIElementType. Ah! It's that ID is the root IElementType requested to parse, + * which means that the root node returned from parsetree->PSI conversion. But, it + * must be a CompositeElement! The adaptor calls rootMarker.done(root) to finish off + * the PSI conversion. * *

If you don't care to distinguish PSI nodes by type, it is sufficient to create a {@link * ANTLRPsiNode} around the parse tree node diff --git a/src/main/java/org/eolang/jetbrains/EOPluginController.java b/src/main/java/org/eolang/jetbrains/EOPluginController.java index 89aea5d..475eece 100755 --- a/src/main/java/org/eolang/jetbrains/EOPluginController.java +++ b/src/main/java/org/eolang/jetbrains/EOPluginController.java @@ -66,10 +66,14 @@ public void projectOpened() { @Override public void initComponent() { final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); - final Runnable r1 = ()->fileTypeManager.removeAssociatedExtension(FileTypes.PLAIN_TEXT, "eo"); - final Runnable r2 = ()->fileTypeManager.associateExtension(EOFileType.INSTANCE, "eo"); - WriteCommandAction.runWriteCommandAction(project, r1); - WriteCommandAction.runWriteCommandAction(project, r2); + final Runnable runnableRemove = () -> fileTypeManager.removeAssociatedExtension( + FileTypes.PLAIN_TEXT, "eo" + ); + final Runnable runnableAssociate = () -> fileTypeManager.associateExtension( + EOFileType.INSTANCE, "eo" + ); + WriteCommandAction.runWriteCommandAction(project, runnableRemove); + WriteCommandAction.runWriteCommandAction(project, runnableAssociate); } @Override diff --git a/src/main/java/org/eolang/jetbrains/EOSyntaxHighlighter.java b/src/main/java/org/eolang/jetbrains/EOSyntaxHighlighter.java index 176e963..9e12fad 100755 --- a/src/main/java/org/eolang/jetbrains/EOSyntaxHighlighter.java +++ b/src/main/java/org/eolang/jetbrains/EOSyntaxHighlighter.java @@ -39,46 +39,86 @@ /** * Class for declaration groups of tokens and highlighting colors. + * We will highlight all tokens with one of colors below. One group - one color. * @since 0.0.0 */ public class EOSyntaxHighlighter extends SyntaxHighlighterBase { + /** + * Code below is description of token groups. + */ public static final TextAttributesKey NUMBERS = createTextAttributesKey("EO_INT", DefaultLanguageHighlighterColors.CONSTANT); + /** + * Define comments. + */ public static final TextAttributesKey COMMENT = createTextAttributesKey("EO_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT); + /** + * Define metas. + */ public static final TextAttributesKey META = createTextAttributesKey("EO_META", DefaultLanguageHighlighterColors.METADATA); + /** + * Define keyword. + */ public static final TextAttributesKey KEYWORD = createTextAttributesKey("EO_STAR", DefaultLanguageHighlighterColors.KEYWORD); + /** + * Define space. + */ public static final TextAttributesKey SPACE = createTextAttributesKey("EO_SPACE", DefaultLanguageHighlighterColors.TEMPLATE_LANGUAGE_COLOR); + /** + * Define dot. + */ public static final TextAttributesKey DOT = createTextAttributesKey("EO_DOT", DefaultLanguageHighlighterColors.DOT); + /** + * Define braces. + */ public static final TextAttributesKey BRACES = createTextAttributesKey("EO_LSQ", DefaultLanguageHighlighterColors.BRACES); + /** + * Define hash. + */ public static final TextAttributesKey HASH = createTextAttributesKey("EO_HASH", DefaultLanguageHighlighterColors.LINE_COMMENT); + /** + * Define EOL. + */ public static final TextAttributesKey EOL = createTextAttributesKey("EO_EOL", DefaultLanguageHighlighterColors.TEMPLATE_LANGUAGE_COLOR); + /** + * Define string. + */ public static final TextAttributesKey STRING = createTextAttributesKey("EO_STRING", DefaultLanguageHighlighterColors.STRING); + /** + * Define name. + */ public static final TextAttributesKey NAME = createTextAttributesKey("EO_NAME", DefaultLanguageHighlighterColors.IDENTIFIER); + /** + * Define bad symbol. + */ public static final TextAttributesKey BAD_CHARACTER = createTextAttributesKey("EO_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER); + /** + * Define empty key. + */ private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[0]; @NotNull @@ -96,7 +136,7 @@ public TextAttributesKey[] getTokenHighlights(final IElementType tokenType) { } final TokenIElementType myType = (TokenIElementType) tokenType; final int ttype = myType.getANTLRTokenType(); - TextAttributesKey attrKey; + final TextAttributesKey attrKey; switch (ttype) { case EOLexer.LSQ: case EOLexer.RSQ: diff --git a/src/main/java/org/eolang/jetbrains/psi/EOPSIFileRoot.java b/src/main/java/org/eolang/jetbrains/psi/EOPSIFileRoot.java index c769a94..f884455 100644 --- a/src/main/java/org/eolang/jetbrains/psi/EOPSIFileRoot.java +++ b/src/main/java/org/eolang/jetbrains/psi/EOPSIFileRoot.java @@ -31,10 +31,14 @@ import org.jetbrains.annotations.Nullable; /** - * Describing PSIFileRoot + * Describing PSIFileRoot. * @since 0.0.0 */ public class EOPSIFileRoot extends PsiFileBase implements ScopeNode { + /** + * Definition of PsiFileRoot + * @param viewProvider FileViewProvider + */ public EOPSIFileRoot(@NotNull final FileViewProvider viewProvider) { super(viewProvider, EOLanguage.INSTANCE); } diff --git a/src/test/java/org/eolang/jetbrains/test/EOParsingTest1.java b/src/test/java/org/eolang/jetbrains/test/EOParsingTest1.java index 36c2cee..d9d972c 100644 --- a/src/test/java/org/eolang/jetbrains/test/EOParsingTest1.java +++ b/src/test/java/org/eolang/jetbrains/test/EOParsingTest1.java @@ -49,7 +49,6 @@ public void testParsingTestData() { @Override protected final String getTestDataPath() { - System.out.println("TEST1\n"); return "src/test/testData_1"; }