-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
335 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
rootProject.name = "LiteCommandsIntelliJPlugin" | ||
rootProject.name = "LiteCommands-IntelliJPlugin" |
23 changes: 23 additions & 0 deletions
23
src/main/java/dev/rollczi/litecommands/intellijplugin/InspectionToolUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package dev.rollczi.litecommands.intellijplugin; | ||
|
||
import com.intellij.codeInspection.LocalInspectionTool; | ||
|
||
public final class InspectionToolUtil { | ||
|
||
private static final String FILE_DESCRIPTION_EXCLUDE_END_NAME = "Inspection"; | ||
private static final String FILE_DESCRIPTION_EXTENSION = ".html"; | ||
|
||
private InspectionToolUtil() { | ||
} | ||
|
||
public static String getDescriptionFileName(Class<? extends LocalInspectionTool> inspectionToolClass) { | ||
String className = inspectionToolClass.getSimpleName(); | ||
|
||
if (className.endsWith(FILE_DESCRIPTION_EXCLUDE_END_NAME)) { | ||
className = className.substring(0, className.length() - FILE_DESCRIPTION_EXCLUDE_END_NAME.length()); | ||
} | ||
|
||
return className + FILE_DESCRIPTION_EXTENSION; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...ain/java/dev/rollczi/litecommands/intellijplugin/validation/annoation/AttributeValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package dev.rollczi.litecommands.intellijplugin.validation.annoation; | ||
|
||
import com.intellij.psi.PsiElement; | ||
|
||
class AttributeValue { | ||
|
||
private final String text; | ||
private final String rawText; | ||
private final PsiElement element; | ||
|
||
AttributeValue(String text, String rawText, PsiElement element) { | ||
this.text = text; | ||
this.rawText = rawText; | ||
this.element = element; | ||
} | ||
|
||
public String text() { | ||
return this.text; | ||
} | ||
|
||
public String rawText() { | ||
return this.rawText; | ||
} | ||
|
||
public PsiElement element() { | ||
return this.element; | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...llczi/litecommands/intellijplugin/validation/annoation/ReplaceWithValidValueQuickFix.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package dev.rollczi.litecommands.intellijplugin.validation.annoation; | ||
|
||
import com.intellij.codeInspection.LocalQuickFix; | ||
import com.intellij.codeInspection.ProblemDescriptor; | ||
import com.intellij.codeInspection.util.IntentionFamilyName; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.psi.JavaPsiFacade; | ||
import com.intellij.psi.PsiAnnotation; | ||
import com.intellij.psi.PsiElement; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
class ReplaceWithValidValueQuickFix implements LocalQuickFix { | ||
|
||
private final PsiAnnotation patternAnnotation; | ||
private final AttributeValidator validator; | ||
private final AttributeValue value; | ||
|
||
public ReplaceWithValidValueQuickFix(PsiAnnotation patternAnnotation, AttributeValidator validator, AttributeValue value) { | ||
this.patternAnnotation = patternAnnotation; | ||
this.validator = validator; | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public @IntentionFamilyName @NotNull String getFamilyName() { | ||
String quickFix = this.validator.quickFix(this.value.rawText()); | ||
|
||
if (quickFix.startsWith("\"") && quickFix.endsWith("\"")) { | ||
quickFix = quickFix.substring(1, quickFix.length() - 1); | ||
} | ||
|
||
return "Replace with '" + quickFix + "'"; | ||
} | ||
|
||
@Override | ||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { | ||
String quickFix = this.validator.quickFix(this.value.rawText()); | ||
PsiElement old = this.value.element(); | ||
String annotationText = this.patternAnnotation.getText(); | ||
|
||
int start = old.getTextRange().getStartOffset() - this.patternAnnotation.getTextRange().getStartOffset(); | ||
int end = old.getTextRange().getEndOffset() - this.patternAnnotation.getTextRange().getStartOffset(); | ||
|
||
String newAnnotationText = annotationText.substring(0, start) + quickFix + annotationText.substring(end); | ||
|
||
this.patternAnnotation.replace(JavaPsiFacade.getElementFactory(project).createAnnotationFromText( | ||
newAnnotationText, | ||
this.patternAnnotation | ||
)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.