side effects warning: make format reusable

This commit is contained in:
Anna.Kozlova
2017-04-18 17:00:55 +02:00
parent fb9c4114a3
commit 206115ba2c
2 changed files with 35 additions and 44 deletions
@@ -35,6 +35,7 @@ import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
@@ -148,25 +149,13 @@ public class AccessStaticViaInstanceFix extends LocalQuickFixAndIntentionActionO
@Override
protected String sideEffectsDescription() {
if (canCopeWithSideEffects) {
return "<html><body>" +
" There are possible side effects found in expression '" +
qualifierExpression.getText() +
"'<br>" +
" You can:<ul><li><b>Remove</b> class reference along with whole expressions involved, or</li>" +
" <li><b>Transform</b> qualified expression into the statement on its own.<br>" +
" That is,<br>" +
" <table border=1><tr><td><code>" +
myExpression.getText() +
"</code></td></tr></table><br> becomes: <br>" +
" <table border=1><tr><td><code>" +
qualifierExpression.getText() +
";<br>" +
qualifiedWithClassName.getText() +
" </code></td></tr></table></li>" +
" </body></html>";
return MessageFormat.format(getFormatString(),
"expression '" + qualifierExpression.getText() + "'",
myExpression.getText(), //before text
qualifierExpression.getText() + ";<br>" + qualifiedWithClassName.getText());//after text
}
return "<html><body> There are possible side effects found in expression '" + qualifierExpression.getText() + "'<br>" +
"You can:<ul><li><b>Remove</b> class reference along with whole expressions involved, or</li></body></html>";
"You can <b>Remove</b> class reference along with whole expressions involved</body></html>";
}
};
dialog.show();
@@ -124,35 +124,37 @@ public class SideEffectWarningDialog extends DialogWrapper {
return panel;
}
protected String getFormatString() {
return "<html>\n" +
"<body>\n" +
"There are possible side effects found in {0}<br>\n" +
"You can:\n" +
"<br>\n" +
"-&nbsp;<b>Remove</b> variable usages along with all expressions involved, or<br>\n" +
"-&nbsp;<b>Transform</b> expressions assigned to variable into the statements on their own.<br>\n" +
"<div style=\"padding-left: 0.6cm;\">\n" +
" That is,<br>\n" +
" <table border=\"0\">\n" +
" <tr>\n" +
" <td><code>{1};</code></td>\n" +
" </tr>\n" +
" </table>\n" +
" becomes: <br>\n" +
" <table border=\"0\">\n" +
" <tr>\n" +
" <td><code>{2};</code></td>\n" +
" </tr>\n" +
" </table>\n" +
"</div>\n" +
"</body>\n" +
"</html>";
}
protected String sideEffectsDescription() {
if (myCanCopeWithSideEffects) {
String format = "<html>\n" +
"<body>\n" +
"There are possible side effects found in expressions assigned to the variable ''{0}''<br>\n" +
"You can:\n" +
"<br>\n" +
"-&nbsp;<b>Remove</b> variable usages along with all expressions involved, or<br>\n" +
"-&nbsp;<b>Transform</b> expressions assigned to variable into the statements on their own.<br>\n" +
"<div style=\"padding-left: 0.6cm;\">\n" +
" That is,<br>\n" +
" <table border=\"0\">\n" +
" <tr>\n" +
" <td><code>{1} {0} = {2};</code></td>\n" +
" </tr>\n" +
" </table>\n" +
" becomes: <br>\n" +
" <table border=\"0\">\n" +
" <tr>\n" +
" <td><code>{3};</code></td>\n" +
" </tr>\n" +
" </table>\n" +
"</div>\n" +
"</body>\n" +
"</html>";
return MessageFormat.format(format,
myVariable.getName(),
myVariable.getType().getPresentableText(),
myBeforeText,
return MessageFormat.format(getFormatString(),
"expressions assigned to the variable '" + myVariable.getName() + "'",
myVariable.getType().getPresentableText() + " " + myVariable.getName() + " = " + myBeforeText,
myAfterText);
}
else {