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));
}
}
};
}
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);
}
}
}
};
}
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;
}
Aggregations