Search in sources :

Example 6 with GoVisitor

use of com.goide.psi.GoVisitor 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)

Example 7 with GoVisitor

use of com.goide.psi.GoVisitor in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoRangeIterationOnIllegalTypeInspection method buildGoVisitor.

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

        @Override
        public void visitRangeClause(@NotNull GoRangeClause o) {
            super.visitRangeClause(o);
            GoExpression expression = o.getRangeExpression();
            GoType type = expression != null ? expression.getGoType(null) : null;
            if (type != null && !GoTypeUtil.isIterable(type)) {
                holder.registerProblem(expression, "Cannot range over data (type " + GoPsiImplUtil.getText(type) + ")", ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
            }
        }
    };
}
Also used : GoRangeClause(com.goide.psi.GoRangeClause) GoExpression(com.goide.psi.GoExpression) NotNull(org.jetbrains.annotations.NotNull) GoVisitor(com.goide.psi.GoVisitor) GoType(com.goide.psi.GoType) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GoVisitor (com.goide.psi.GoVisitor)7 NotNull (org.jetbrains.annotations.NotNull)7 PsiElement (com.intellij.psi.PsiElement)4 GoReceiver (com.goide.psi.GoReceiver)2 GoRenameToBlankQuickFix (com.goide.quickfix.GoRenameToBlankQuickFix)2 GoAssignmentStatement (com.goide.psi.GoAssignmentStatement)1 GoConstDefinition (com.goide.psi.GoConstDefinition)1 GoExpression (com.goide.psi.GoExpression)1 GoFile (com.goide.psi.GoFile)1 GoFunctionDeclaration (com.goide.psi.GoFunctionDeclaration)1 GoIfStatement (com.goide.psi.GoIfStatement)1 GoLabelDefinition (com.goide.psi.GoLabelDefinition)1 GoPointerType (com.goide.psi.GoPointerType)1 GoRangeClause (com.goide.psi.GoRangeClause)1 GoReferenceExpression (com.goide.psi.GoReferenceExpression)1 GoShortVarDeclaration (com.goide.psi.GoShortVarDeclaration)1 GoType (com.goide.psi.GoType)1 GoUnaryExpr (com.goide.psi.GoUnaryExpr)1 GoDeleteConstDefinitionQuickFix (com.goide.quickfix.GoDeleteConstDefinitionQuickFix)1 GoDeleteQuickFix (com.goide.quickfix.GoDeleteQuickFix)1