use of com.goide.psi.GoReferenceExpression in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoSimplifyBoolExprQuickFix method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
if (!(startElement instanceof GoBinaryExpr))
return;
GoBinaryExpr o = (GoBinaryExpr) startElement;
boolean and = o instanceof GoAndExpr;
List<GoExpression> elements = GoBoolExpressionsInspection.collect(o, and);
List<GoExpression> toRemove = ContainerUtil.newSmartList();
for (int i = 0; i < elements.size(); i++) {
GoExpression l = elements.get(i);
if (l instanceof GoReferenceExpression && (l.textMatches("true") || l.textMatches("false")) && GoPsiImplUtil.builtin(((GoReferenceExpression) l).resolve())) {
boolean trueExpr = l.textMatches("true");
if (and ^ !trueExpr) {
toRemove.add(l);
} else {
replaceExpressionByBoolConst(o, project, !and);
return;
}
}
for (int j = i + 1; j < elements.size(); j++) {
GoExpression r = elements.get(j);
if (GoBoolExpressionsInspection.isEqualsWithNot(l, r) || GoBoolExpressionsInspection.isEqualsWithNot(r, l)) {
replaceExpressionByBoolConst(o, project, !and);
}
if (GoExpressionUtil.identical(l, r))
toRemove.add(l);
// todo expr evaluating! x != c1 || x != c2 (c1, c2 const, c1 != c2)
}
}
if (!toRemove.isEmpty()) {
removeRedundantExpressions(o, project, elements, toRemove, and);
}
}
use of com.goide.psi.GoReferenceExpression 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);
}
}
}
};
}
Aggregations