use of com.goide.psi.GoVisitor in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoAssignmentToReceiverInspection method buildGoVisitor.
@NotNull
@Override
protected GoVisitor buildGoVisitor(@NotNull ProblemsHolder holder, @NotNull LocalInspectionToolSession session) {
return new GoVisitor() {
@Override
public void visitReferenceExpression(@NotNull GoReferenceExpression o) {
super.visitReferenceExpression(o);
if (o.getReadWriteAccess() == ReadWriteAccessDetector.Access.Write) {
PsiElement resolve = o.resolve();
if (resolve instanceof GoReceiver) {
String message = "Assignment to method receiver doesn't propagate to other calls";
if (((GoReceiver) resolve).getType() instanceof GoPointerType) {
if (o.getParent() instanceof GoUnaryExpr) {
GoUnaryExpr p = (GoUnaryExpr) o.getParent();
if (p.getMul() != null) {
// pointer dereference
return;
}
}
message = "Assignment to method receiver propagates only to callees but not to callers";
}
holder.registerProblem(o, message, WEAK_WARNING);
}
}
}
};
}
use of com.goide.psi.GoVisitor 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.psi.GoVisitor in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoUsedAsValueInCondition method buildGoVisitor.
@NotNull
@Override
protected GoVisitor buildGoVisitor(@NotNull ProblemsHolder holder, @NotNull LocalInspectionToolSession session) {
return new GoVisitor() {
@Override
public void visitAssignmentStatement(@NotNull GoAssignmentStatement o) {
if (o.getParent() != null && o.getParent() instanceof GoIfStatement && ((GoIfStatement) o.getParent()).getExpression() == null) {
String left = GoPsiImplUtil.joinPsiElementText(o.getLeftHandExprList().getExpressionList());
String right = GoPsiImplUtil.joinPsiElementText(o.getExpressionList());
holder.registerProblem(o, left + " = " + right + " used as value", GENERIC_ERROR_OR_WARNING, new GoAssignmentToComparisonQuickFix());
}
}
@Override
public void visitShortVarDeclaration(@NotNull GoShortVarDeclaration o) {
PsiElement parent = o.getParent();
if (parent != null) {
PsiElement gradParent = parent.getParent();
if (gradParent instanceof GoIfStatement && ((GoIfStatement) gradParent).getExpression() == null) {
String left = GoPsiImplUtil.joinPsiElementText(o.getVarDefinitionList());
String right = GoPsiImplUtil.joinPsiElementText(o.getRightExpressionsList());
holder.registerProblem(o, left + " := " + right + " used as value", GENERIC_ERROR_OR_WARNING, new GoAssignmentToComparisonQuickFix());
}
}
}
};
}
use of com.goide.psi.GoVisitor in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoReceiverNamesInspection method buildGoVisitor.
@NotNull
@Override
protected GoVisitor buildGoVisitor(@NotNull ProblemsHolder holder, @NotNull LocalInspectionToolSession session) {
return new GoVisitor() {
@Override
public void visitReceiver(@NotNull GoReceiver o) {
if (genericNamesSet.contains(o.getName())) {
PsiElement identifier = o.getIdentifier();
if (identifier == null)
return;
holder.registerProblem(identifier, "Receiver has generic name", new GoRenameQuickFix(o));
}
}
};
}
use of com.goide.psi.GoVisitor in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoUnusedConstInspection method buildGoVisitor.
@NotNull
@Override
protected GoVisitor buildGoVisitor(@NotNull ProblemsHolder holder, @NotNull LocalInspectionToolSession session) {
return new GoVisitor() {
@Override
public void visitConstDefinition(@NotNull GoConstDefinition o) {
if (o.isBlank())
return;
if (ReferencesSearch.search(o, o.getUseScope()).findFirst() == null) {
String constName = o.getName();
holder.registerProblem(o, "Unused constant <code>#ref</code> #loc", ProblemHighlightType.LIKE_UNUSED_SYMBOL, new GoDeleteConstDefinitionQuickFix(constName));
}
}
};
}
Aggregations