I write the following code,
\documentclass[10pt, twocolumn, twoside, journal]{IEEEtran}
\usepackage{amsmath, amsfonts, amssymb, color, enumerate, amsthm, graphicx}
\usepackage{tikz, subcaption, cite}
\usepackage{color, xcolor, soul, bm}
\usepackage{marginnote}
\usepackage[normalem]{ulem}
\newtheorem{problem}{Problem}
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}{Corollary}
\newtheorem{assumption}{Assumption}
\newtheorem{proposition}{Proposition}
\newtheorem{lemma}{Lemma}
\newtheorem{remark}{Remark}
\newtheorem{definition}{Definition}
\newtheorem{example}{Example}
\usepackage{epsfig}
\usepackage{psfrag}
\DeclareMathOperator{\diag}{diag}
\usepackage{tcolorbox}
\newcommand{\JW}[1]{{\color{red}#1}}
\usepackage{algorithm}
\usepackage{algpseudocode}
\allowdisplaybreaks
\def\endtheorem{\hspace*{\fill}~\IEEEQEDopen\par\endtrivlist\unskip}
\def\endlemma{\hspace*{\fill}~\IEEEQEDopen\par\endtrivlist\unskip}
\def\endproposition{\hspace*{\fill}~\IEEEQEDopen\par\endtrivlist\unskip}
\def\endexample{\hspace*{\fill}~\IEEEQEDopen\par\endtrivlist\unskip}
\def\endremark{\hspace*{\fill}~\IEEEQEDopen\par\endtrivlist\unskip}
\def\enddefinition{\hspace*{\fill}~\IEEEQEDopen\par\endtrivlist\unskip}
\begin{document}
\title{My title}
\author{Mohammad}
\newcommand{\ty}{\color{yellow}}
\newcommand{\tb}{\color{blue}}
\newcommand{\tr}{\color{red}}
\newcommand{\tg}{\color{green}}
\maketitle
\thispagestyle{empty}
%\pagestyle{empty}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{abstract}
My abstract
\end{abstract}
\begin{IEEEkeywords}
key words
\end{IEEEkeywords}
\begin{lemma}
This is my lemma and when the text happens to end near the right margin the symbol will be flushed left, not right.
\end{lemma}
\end{document}
I do see that a same question has been answered here: How do I make all the theorem-alike environments have an ending symbol?
But I would like to know what the problem is with my \def commands and if I can fix them. If not please let me know an alternative.