Skip to content

Commit

Permalink
fixed some qulice reports
Browse files Browse the repository at this point in the history
  • Loading branch information
yasamprom committed Jul 5, 2022
1 parent e41a55d commit cd26637
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 98 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2022 Stepan Strunkov
Copyright (c) 2021-2022 Stepan Strunkov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
35 changes: 16 additions & 19 deletions src/main/java/org/eolang/jetbrains/EoColorSettingsPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.intellij.openapi.options.colors.ColorDescriptor;
import com.intellij.openapi.options.colors.ColorSettingsPage;
import java.util.Map;
import javax.swing.*;
import javax.swing.Icon;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -74,24 +74,21 @@ public final SyntaxHighlighter getHighlighter() {
@Override
public final 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";
.concat("+alias org.eolang.txt.sprintf\n\n")
.concat("# is year leap?\n\n")
.concat("[args...] > main\n")
.concat(" [y] > leap\n")
.concat(" or. > @\n")
.concat(" and.\n")
.concat(" eq. (mod. y 4) 0\n")
.concat(" not. (eq. (mod. y 100) 0)\n")
.concat(" eq. (mod. y 400) 0\n")
.concat(" stdout > @\n")
.concat(" sprintf\n")
.concat(" \"%d is %sa leap year!\"\n")
.concat(" (args.get 0).as-int > year!\n")
.concat(" if. (leap year:y) \"")
.concat("\" \"not \"\\n\"");
}

@NotNull
Expand Down
64 changes: 33 additions & 31 deletions src/main/java/org/eolang/jetbrains/EoExternalAnnotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,41 @@
* GUI event loop. Jetbrains provides this external annotator mechanism to run these analyzers out
* of band.
* @since 0.0.0
* @checkstyle MultilineJavadocTagsCheck (200 lines)
* @checkstyle MemberNameCheck (200 lines)
*/
public class EoExternalAnnotator
extends ExternalAnnotator<PsiFile, List<EoExternalAnnotator.Issue>> {
// NOTE: can't use instance vars as only 1 instance

// Called first; in our case, just return file and do nothing.
@Override
@Nullable
public final PsiFile collectInformation(@NotNull final PsiFile file) {
return file;
}

/*
* Called 2nd; look for trouble in file and return list of issues.
*
* <p>For most custom languages, you would not reimplement your semantic analyzer
* using PSI trees. Instead, here is where you would call out to your custom languages
* compiler or interpreter to get error messages or other bits of information you'd
* like to annotate the document with.
*/
@Override
public final List<Issue> doAnnotate(final PsiFile file) {
return new ArrayList<>(0);
}

// Called 3rd to actually annotate the editor window.
@Override
public final void apply(@NotNull final PsiFile file, final List<Issue> issues,
@NotNull final AnnotationHolder holder) {
for (final Issue issue : issues) {
final TextRange range = issue.getOffendingNode().getTextRange();
holder.createErrorAnnotation(range, issue.getMsg());
}
}

/**
* Issue report.
Expand All @@ -70,6 +101,7 @@ public Issue(final String msg, final PsiElement node) {
this.msg = msg;
this.offendingNode = node;
}

/**
* Accessor.
* @return String message
Expand All @@ -86,34 +118,4 @@ final PsiElement getOffendingNode() {
return this.offendingNode;
}
}

// Called first; in our case, just return file and do nothing.
@Override
@Nullable
public final PsiFile collectInformation(@NotNull final PsiFile file) {
return file;
}

/*
* Called 2nd; look for trouble in file and return list of issues.
*
* <p>For most custom languages, you would not reimplement your semantic analyzer using PSI trees.
* Instead, here is where you would call out to your custom languages compiler or interpreter to
* get error messages or other bits of information you'd like to annotate the document with.
*/

@Override
public final List<Issue> doAnnotate(final PsiFile file) {
return new ArrayList<>();
}

// Called 3rd to actually annotate the editor window.
@Override
public final void apply(@NotNull final PsiFile file, final List<Issue> issues,
@NotNull final AnnotationHolder holder) {
for (final Issue issue : issues) {
final TextRange range = issue.getOffendingNode().getTextRange();
holder.createErrorAnnotation(range, issue.getMsg());
}
}
}
3 changes: 1 addition & 2 deletions src/main/java/org/eolang/jetbrains/EoFileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
package org.eolang.jetbrains;

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

/**
* Description of EO language files.
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/eolang/jetbrains/EoFileTypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
/**
* Class for definition of FileType.
* @since 0.0.0
* @checkstyle ParameterNameCheck (100 lines)
*/
public class EoFileTypeFactory extends FileTypeFactory {
@Override
public void createFileTypes(@NotNull final FileTypeConsumer fileTypeConsumer) {
public final void createFileTypes(@NotNull final FileTypeConsumer fileTypeConsumer) {
fileTypeConsumer.consume(EoFileType.INSTANCE, EoFileType.FILE_EXTENSION);
}
}
10 changes: 6 additions & 4 deletions src/main/java/org/eolang/jetbrains/EoParserDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
/**
* Let's define a parser for EO language.
* @since 0.0.0
* @checkstyle MultilineJavadocTagsCheck (200 lines)
* @checkstyle VisibilityModifierCheck (200 lines)
*/
public class EoParserDefinition implements ParserDefinition {
/**
Expand All @@ -67,9 +69,9 @@ public class EoParserDefinition implements ParserDefinition {
PSIElementTypeFactory.defineLanguageIElementTypes(
EoLanguage.INSTANCE, EOParser.tokenNames, EOParser.ruleNames
);
final List<TokenIElementType> tokenElementTypes =
final List<TokenIElementType> tokentypes =
PSIElementTypeFactory.getTokenIElementTypes(EoLanguage.INSTANCE);
EoParserDefinition.id = tokenElementTypes.get(EOLexer.AT);
EoParserDefinition.id = tokentypes.get(EOLexer.AT);
}

@NotNull
Expand Down Expand Up @@ -126,8 +128,8 @@ public final IFileElementType getFileNodeType() {
* eventually becomes a PsiFile. From PsiFile, we can get it back via: {@link PsiFile#getNode}.
*/
@Override
public final PsiFile createFile(final FileViewProvider viewProvider) {
return new EoPsiFileRoot(viewProvider);
public final PsiFile createFile(final FileViewProvider viewprovider) {
return new EoPsiFileRoot(viewprovider);
}

/*
Expand Down
39 changes: 21 additions & 18 deletions src/main/java/org/eolang/jetbrains/EoPluginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
* Start class of project.
* Contains instructions what to do after opening project etc
* @since 0.0.0
* @checkstyle MultilineJavadocTagsCheck (200 lines)
* @checkstyle LocalFinalVariableNameCheck (200 lines)
*/
public class EoPluginController implements ProjectComponent {
/**
Expand All @@ -47,7 +49,6 @@ public class EoPluginController implements ProjectComponent {
* Project instance.
*/
private final Project project;
// public boolean projectIsClosed = false;

/**
* Constructor.
Expand All @@ -57,22 +58,26 @@ public EoPluginController(final Project project) {
this.project = project;
}

/**
* Accessor.
* @return Project opened project
*/
final Project getProject() {
return this.project;
@Override
public final void projectOpened() {
if (LOG.isDebugEnabled()) {
LOG.debug("Project opened");
}
}

@Override
public final void projectClosed() {
LOG.info("projectClosed " + project.getName());
if (LOG.isDebugEnabled()) {
LOG.debug("Project closed ".concat(this.project.getName()));
}
}

// public final void disposeComponent() { }

@NotNull
@Override
public final void projectOpened() {
LOG.info("Project opened");
public final String getComponentName() {
return "eo.ProjectComponent";
}

@Override
Expand All @@ -88,13 +93,11 @@ public final void initComponent() {
WriteCommandAction.runWriteCommandAction(this.getProject(), runnableAssociate);
}

/*
public final void disposeComponent() { }
*/

@NotNull
@Override
public final String getComponentName() {
return "eo.ProjectComponent";
/**
* Accessor.
* @return Project opened project
*/
final Project getProject() {
return this.project;
}
}
17 changes: 11 additions & 6 deletions src/main/java/org/eolang/jetbrains/EoSyntaxHighlighter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
import com.intellij.openapi.editor.HighlighterColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase;
import com.intellij.psi.tree.IElementType;
import org.antlr.intellij.adaptor.lexer.ANTLRLexerAdaptor;
Expand All @@ -40,8 +40,10 @@
* 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
* @checkstyle LocalFinalVariableNameCheck (100 lines), CyclomaticComplexity (150 lines)
* @checkstyle CyclomaticComplexity (150 lines)
* @checkstyle NcssCount (150 lines)
*/

public class EoSyntaxHighlighter extends SyntaxHighlighterBase {
/**
* Code below is description of token groups.
Expand Down Expand Up @@ -71,7 +73,10 @@ public class EoSyntaxHighlighter extends SyntaxHighlighterBase {
* Define space.
*/
public static final TextAttributesKey SPACE =
createTextAttributesKey("EO_SPACE", DefaultLanguageHighlighterColors.TEMPLATE_LANGUAGE_COLOR);
createTextAttributesKey(
"EO_SPACE",
DefaultLanguageHighlighterColors.TEMPLATE_LANGUAGE_COLOR
);

/**
* Define dot.
Expand Down Expand Up @@ -129,11 +134,11 @@ public final Lexer getHighlightingLexer() {

// @checkstyle CyclomaticComplexity (100 lines)
@Override
public final TextAttributesKey[] getTokenHighlights(final IElementType tokenType) {
if (!(tokenType instanceof TokenIElementType)) {
public final TextAttributesKey[] getTokenHighlights(final IElementType tokentype) {
if (!(tokentype instanceof TokenIElementType)) {
return EoSyntaxHighlighter.EMPTY_KEYS;
}
final TokenIElementType myType = (TokenIElementType) tokenType;
final TokenIElementType myType = (TokenIElementType) tokentype;
final int ttype = myType.getANTLRTokenType();
final TextAttributesKey attrKey;
switch (ttype) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/eolang/jetbrains/Icons.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
/**
* Class for getting icons.
* @since 0.0.0
* @checkstyle HideUtilityClassConstructorCheck (10 lines)
* @checkstyle ModifierOrderCheck (10 lines)
*/
public class Icons {
/**
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/org/eolang/jetbrains/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2021-2022 Stepan Strunkov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/**
* Package with all classes for EO language.
*/
// @checkstyle HeaderCheck (100 lines)
package org.eolang.jetbrains;

0 comments on commit cd26637

Please sign in to comment.