use of com.goide.psi.impl.GoReferenceExpressionImpl in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoAssignmentNilWithoutExplicitTypeInspection method buildGoVisitor.
@NotNull
@Override
protected GoVisitor buildGoVisitor(@NotNull ProblemsHolder holder, @NotNull LocalInspectionToolSession session) {
return new GoVisitor() {
@Override
public void visitVarDeclaration(@NotNull GoVarDeclaration o) {
for (GoVarSpec spec : o.getVarSpecList()) {
checkVar(spec);
}
}
@Override
public void visitShortVarDeclaration(@NotNull GoShortVarDeclaration o) {
checkVar(o);
}
@Override
public void visitConstDeclaration(@NotNull GoConstDeclaration o) {
for (GoConstSpec spec : o.getConstSpecList()) {
checkConst(spec);
}
}
private void checkVar(@NotNull GoVarSpec spec) {
if (spec.getType() != null)
return;
checkExpressions(spec.getRightExpressionsList());
}
private void checkConst(@NotNull GoConstSpec spec) {
if (spec.getType() != null)
return;
checkExpressions(spec.getExpressionList());
}
private void checkExpressions(@NotNull List<GoExpression> expressions) {
for (GoExpression expr : expressions) {
if (expr instanceof GoReferenceExpressionImpl) {
GoReferenceExpressionImpl ref = (GoReferenceExpressionImpl) expr;
PsiElement resolve = ref.resolve();
if (ref.getIdentifier().textMatches(GoConstants.NIL) && resolve != null && GoPsiImplUtil.builtin(resolve)) {
holder.registerProblem(expr, "Cannot assign nil without explicit type", GENERIC_ERROR_OR_WARNING);
}
}
}
}
};
}
Aggregations