Search in sources :

Example 1 with GoUnaryExpr

use of com.goide.psi.GoUnaryExpr 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);
                }
            }
        }
    };
}
Also used : GoUnaryExpr(com.goide.psi.GoUnaryExpr) GoPointerType(com.goide.psi.GoPointerType) GoReceiver(com.goide.psi.GoReceiver) GoReferenceExpression(com.goide.psi.GoReferenceExpression) NotNull(org.jetbrains.annotations.NotNull) GoVisitor(com.goide.psi.GoVisitor) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GoPointerType (com.goide.psi.GoPointerType)1 GoReceiver (com.goide.psi.GoReceiver)1 GoReferenceExpression (com.goide.psi.GoReferenceExpression)1 GoUnaryExpr (com.goide.psi.GoUnaryExpr)1 GoVisitor (com.goide.psi.GoVisitor)1 PsiElement (com.intellij.psi.PsiElement)1 NotNull (org.jetbrains.annotations.NotNull)1