-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from xonixx/remove_trailing_semicolon
Remove trailing semicolon
- Loading branch information
Showing
15 changed files
with
124 additions
and
2 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
52 changes: 52 additions & 0 deletions
52
src/main/java/intellij_awk/AwkInspectionUnnecessarySemicolon.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 intellij_awk; | ||
|
||
import com.intellij.codeInspection.*; | ||
import com.intellij.codeInspection.util.IntentionFamilyName; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiElementVisitor; | ||
import intellij_awk.psi.AwkSemicolonPsi; | ||
import intellij_awk.psi.AwkTypes; | ||
import intellij_awk.psi.AwkVisitor; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class AwkInspectionUnnecessarySemicolon extends LocalInspectionTool { | ||
|
||
private static final DeleteUnnecessarySemicolonQuickFix deleteUnnecessarySemicolonQuickFix = | ||
new DeleteUnnecessarySemicolonQuickFix(); | ||
public static final String QUICK_FIX_NAME = "Remove unnecessary semicolon"; | ||
|
||
@Override | ||
public @NotNull PsiElementVisitor buildVisitor( | ||
@NotNull ProblemsHolder holder, boolean isOnTheFly) { | ||
|
||
return new AwkVisitor() { | ||
@Override | ||
public void visitSemicolonPsi(@NotNull AwkSemicolonPsi semicolonPsi) { | ||
PsiElement nextSibling = AwkUtil.getNextNotWhitespace(semicolonPsi); | ||
if (nextSibling instanceof AwkSemicolonPsi | ||
|| AwkUtil.isType(nextSibling, AwkTypes.NEWLINE) | ||
|| AwkUtil.isType(nextSibling, AwkTypes.RBRACE)) { | ||
holder.registerProblem( | ||
semicolonPsi, | ||
"Unnecessary semicolon ';'", | ||
ProblemHighlightType.LIKE_UNUSED_SYMBOL, | ||
deleteUnnecessarySemicolonQuickFix); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
private static class DeleteUnnecessarySemicolonQuickFix implements LocalQuickFix { | ||
|
||
@Override | ||
public @IntentionFamilyName @NotNull String getFamilyName() { | ||
return QUICK_FIX_NAME; | ||
} | ||
|
||
@Override | ||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { | ||
descriptor.getPsiElement().delete(); | ||
} | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
src/main/resources/inspectionDescriptions/AwkInspectionUnnecessarySemicolon.html
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,6 @@ | ||
<html> | ||
<body> | ||
Reports on unnecessary semicolon. | ||
<!-- tooltip end --> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
BEGIN { | ||
print 123;<caret> | ||
} |
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,3 @@ | ||
BEGIN { | ||
print 123<caret> | ||
} |
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 @@ | ||
{ print 123;<caret> } |
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 @@ | ||
{ print 123<caret> } |
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,3 @@ | ||
BEGIN { | ||
print 123<caret>;; | ||
} |
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,3 @@ | ||
BEGIN { | ||
print 123<caret>; | ||
} |
1 change: 1 addition & 0 deletions
1
src/test/testData/inspection/unnecessarySemicolonNecessary1.awk
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 @@ | ||
function f() { while(1);<caret> } |
3 changes: 3 additions & 0 deletions
3
src/test/testData/inspection/unnecessarySemicolonNecessary2.awk
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,3 @@ | ||
function f() { | ||
for(;;);<caret> | ||
} |
3 changes: 3 additions & 0 deletions
3
src/test/testData/inspection/unnecessarySemicolonNecessary3.awk
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,3 @@ | ||
{ | ||
if(1) ;<caret> | ||
} |
3 changes: 3 additions & 0 deletions
3
src/test/testData/inspection/unnecessarySemicolonNecessary4.awk
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,3 @@ | ||
BEGIN { | ||
;<caret> | ||
} |