Search in sources :

Example 1 with GoRenameToBlankQuickFix

use of com.goide.quickfix.GoRenameToBlankQuickFix in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoUnusedFunctionInspection method buildGoVisitor.

@NotNull
@Override
protected GoVisitor buildGoVisitor(@NotNull ProblemsHolder holder, @NotNull LocalInspectionToolSession session) {
    return new GoVisitor() {

        @Override
        public void visitFunctionDeclaration(@NotNull GoFunctionDeclaration o) {
            if (o.isBlank())
                return;
            GoFile file = o.getContainingFile();
            String name = o.getName();
            if (!canRun(name))
                return;
            if (GoConstants.MAIN.equals(file.getPackageName()) && GoConstants.MAIN.equals(name))
                return;
            if (GoConstants.INIT.equals(name))
                return;
            if (GoTestFinder.isTestFile(file) && GoTestFunctionType.fromName(name) != null)
                return;
            if (ReferencesSearch.search(o, o.getUseScope()).findFirst() == null) {
                PsiElement id = o.getIdentifier();
                TextRange range = TextRange.from(id.getStartOffsetInParent(), id.getTextLength());
                holder.registerProblem(o, "Unused function <code>#ref</code> #loc", ProblemHighlightType.LIKE_UNUSED_SYMBOL, range, new GoDeleteQuickFix("Delete function", GoFunctionDeclaration.class), new GoRenameToBlankQuickFix(o));
            }
        }
    };
}
Also used : GoFunctionDeclaration(com.goide.psi.GoFunctionDeclaration) GoFile(com.goide.psi.GoFile) GoRenameToBlankQuickFix(com.goide.quickfix.GoRenameToBlankQuickFix) TextRange(com.intellij.openapi.util.TextRange) GoDeleteQuickFix(com.goide.quickfix.GoDeleteQuickFix) NotNull(org.jetbrains.annotations.NotNull) GoVisitor(com.goide.psi.GoVisitor) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GoRenameToBlankQuickFix

use of com.goide.quickfix.GoRenameToBlankQuickFix in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoUnusedLabelInspection method buildGoVisitor.

@NotNull
@Override
protected GoVisitor buildGoVisitor(@NotNull ProblemsHolder holder, @NotNull LocalInspectionToolSession session) {
    return new GoVisitor() {

        @Override
        public void visitLabelDefinition(@NotNull GoLabelDefinition o) {
            super.visitLabelDefinition(o);
            if (o.isBlank())
                return;
            if (ReferencesSearch.search(o, o.getUseScope()).findFirst() == null) {
                String name = o.getName();
                holder.registerProblem(o, "Unused label <code>#ref</code> #loc", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new GoRenameToBlankQuickFix(o), new GoDeleteLabelStatementQuickFix(name));
            }
        }
    };
}
Also used : GoLabelDefinition(com.goide.psi.GoLabelDefinition) GoRenameToBlankQuickFix(com.goide.quickfix.GoRenameToBlankQuickFix) NotNull(org.jetbrains.annotations.NotNull) GoVisitor(com.goide.psi.GoVisitor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GoVisitor (com.goide.psi.GoVisitor)2 GoRenameToBlankQuickFix (com.goide.quickfix.GoRenameToBlankQuickFix)2 NotNull (org.jetbrains.annotations.NotNull)2 GoFile (com.goide.psi.GoFile)1 GoFunctionDeclaration (com.goide.psi.GoFunctionDeclaration)1 GoLabelDefinition (com.goide.psi.GoLabelDefinition)1 GoDeleteQuickFix (com.goide.quickfix.GoDeleteQuickFix)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiElement (com.intellij.psi.PsiElement)1