Search in sources :

Example 1 with GoReceiver

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

Example 2 with GoReceiver

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

Example 3 with GoReceiver

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

the class GoTestRunLineMarkerProvider method getInfo.

@Nullable
@Override
public Info getInfo(PsiElement e) {
    if (e != null && e.getNode().getElementType() == GoTypes.IDENTIFIER) {
        PsiElement parent = e.getParent();
        PsiFile file = e.getContainingFile();
        if (!GoTestFinder.isTestFile(file)) {
            return null;
        }
        if (GoRunUtil.isPackageContext(e)) {
            return new Info(AllIcons.RunConfigurations.TestState.Run_run, TOOLTIP_PROVIDER, ExecutorAction.getActions(0));
        } else if (parent instanceof GoFunctionOrMethodDeclaration) {
            GoTestFunctionType functionType = GoTestFunctionType.fromName(((GoFunctionOrMethodDeclaration) parent).getName());
            if (functionType != null) {
                if (parent instanceof GoFunctionDeclaration) {
                    return getInfo(GoTestLocator.PROTOCOL + "://" + ((GoFunctionDeclaration) parent).getName(), e.getProject());
                } else if (parent instanceof GoMethodDeclaration) {
                    GoReceiver receiver = ((GoMethodDeclaration) parent).getReceiver();
                    PsiElement receiverIdentifier = receiver != null ? receiver.getIdentifier() : null;
                    String receiverText = receiverIdentifier != null ? receiverIdentifier.getText() + "." : "";
                    return getInfo(GoTestLocator.PROTOCOL + "://" + receiverText + ((GoMethodDeclaration) parent).getName(), e.getProject());
                }
            }
        }
    }
    return null;
}
Also used : GoFunctionDeclaration(com.goide.psi.GoFunctionDeclaration) GoMethodDeclaration(com.goide.psi.GoMethodDeclaration) GoReceiver(com.goide.psi.GoReceiver) PsiFile(com.intellij.psi.PsiFile) GoFunctionOrMethodDeclaration(com.goide.psi.GoFunctionOrMethodDeclaration) TestStateInfo(com.intellij.execution.testframework.sm.runner.states.TestStateInfo) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GoReceiver (com.goide.psi.GoReceiver)3 PsiElement (com.intellij.psi.PsiElement)3 GoVisitor (com.goide.psi.GoVisitor)2 NotNull (org.jetbrains.annotations.NotNull)2 GoFunctionDeclaration (com.goide.psi.GoFunctionDeclaration)1 GoFunctionOrMethodDeclaration (com.goide.psi.GoFunctionOrMethodDeclaration)1 GoMethodDeclaration (com.goide.psi.GoMethodDeclaration)1 GoPointerType (com.goide.psi.GoPointerType)1 GoReferenceExpression (com.goide.psi.GoReferenceExpression)1 GoUnaryExpr (com.goide.psi.GoUnaryExpr)1 GoRenameQuickFix (com.goide.quickfix.GoRenameQuickFix)1 TestStateInfo (com.intellij.execution.testframework.sm.runner.states.TestStateInfo)1 PsiFile (com.intellij.psi.PsiFile)1 Nullable (org.jetbrains.annotations.Nullable)1