use of com.goide.quickfix.GoDeleteQuickFix 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));
}
}
};
}
use of com.goide.quickfix.GoDeleteQuickFix in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoDeferGoInspection method buildGoVisitor.
@NotNull
@Override
protected GoVisitor buildGoVisitor(@NotNull ProblemsHolder holder, @NotNull LocalInspectionToolSession session) {
return new GoVisitor() {
@SuppressWarnings("DialogTitleCapitalization")
@Override
public void visitDeferStatement(@NotNull GoDeferStatement o) {
super.visitDeferStatement(o);
GoExpression expression = o.getExpression();
if (expression instanceof GoCallExpr) {
GoCallExpr callExpr = (GoCallExpr) expression;
if (GoPsiImplUtil.isPanic(callExpr)) {
holder.registerProblem(o, "defer should not call panic() directly #loc", ProblemHighlightType.WEAK_WARNING, new GoDeleteQuickFix("Delete statement", GoDeferStatement.class));
return;
}
if (GoPsiImplUtil.isRecover(callExpr)) {
holder.registerProblem(o, "defer should not call recover() directly #loc", ProblemHighlightType.WEAK_WARNING, new GoReplaceWithCorrectDeferRecoverQuickFix());
return;
}
}
checkExpression(expression, "defer");
}
@SuppressWarnings("DialogTitleCapitalization")
@Override
public void visitGoStatement(@NotNull GoGoStatement o) {
super.visitGoStatement(o);
GoExpression expression = o.getExpression();
if (expression instanceof GoCallExpr) {
GoCallExpr callExpr = (GoCallExpr) expression;
if (GoPsiImplUtil.isPanic(callExpr)) {
holder.registerProblem(o, "go should not call panic() directly #loc", ProblemHighlightType.WEAK_WARNING, new GoDeleteQuickFix("Delete statement", GoGoStatement.class));
return;
}
if (GoPsiImplUtil.isRecover(callExpr)) {
holder.registerProblem(o, "go should not call recover() directly #loc", ProblemHighlightType.WEAK_WARNING, new GoDeleteQuickFix("Delete statement", GoGoStatement.class));
return;
}
}
checkExpression(expression, "go");
}
private void checkExpression(@Nullable GoExpression o, @NotNull String who) {
if (o == null)
return;
if (o instanceof GoCallExpr || o instanceof GoBuiltinCallExpr) {
if (GoPsiImplUtil.isConversionExpression(o)) {
holder.registerProblem(o, who + " requires function call, not conversion #loc", ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
return;
}
if (o instanceof GoParenthesesExpr) {
holder.registerProblem(o, "Expression in " + who + " must not be parenthesized", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new GoUnwrapParensExpression());
}
LocalQuickFix[] fixes = o.getGoType(null) instanceof GoFunctionType ? new LocalQuickFix[] { new GoAddParensQuickFix() } : LocalQuickFix.EMPTY_ARRAY;
holder.registerProblem(o, "Expression in " + who + " must be function call", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, fixes);
}
};
}
Aggregations