copy to final: effectifely final is enough fot java 8 (IDEA-152934); change wording

This commit is contained in:
Anna Kozlova
2016-03-14 17:48:06 +01:00
parent e31a812438
commit a54e0ed47e
13 changed files with 21 additions and 17 deletions
@@ -26,6 +26,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.controlFlow.ControlFlowUtil;
import com.intellij.psi.util.PsiTreeUtil;
@@ -70,7 +71,7 @@ public class VariableAccessFromInnerClassFix implements IntentionAction {
message = "make.final.transform.to.one.element.array";
break;
case COPY_TO_FINAL:
return QuickFixBundle.message("make.final.copy.to.temp", myVariable.getName());
return QuickFixBundle.message("make.final.copy.to.temp", myVariable.getName(), (!PsiUtil.isLanguageLevel8OrHigher(myContext) ? "" : "effectively ") + "final");
default:
return "";
}
@@ -197,13 +198,16 @@ public class VariableAccessFromInnerClassFix implements IntentionAction {
private void copyToFinal() throws IncorrectOperationException {
PsiManager psiManager = myContext.getManager();
PsiElementFactory factory = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory();
final Project project = psiManager.getProject();
PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
PsiExpression initializer = factory.createExpressionFromText(myVariable.getName(), myContext);
String newName = suggestNewName(psiManager.getProject(), myVariable);
String newName = suggestNewName(project, myVariable);
PsiType type = myVariable.getType();
PsiDeclarationStatement copyDecl = factory.createVariableDeclarationStatement(newName, type, initializer);
PsiVariable newVariable = (PsiVariable)copyDecl.getDeclaredElements()[0];
PsiUtil.setModifierProperty(newVariable, PsiModifier.FINAL, true);
final boolean mustBeFinal =
!PsiUtil.isLanguageLevel8OrHigher(myContext) || CodeStyleSettingsManager.getSettings(project).GENERATE_FINAL_LOCALS;
PsiUtil.setModifierProperty(newVariable, PsiModifier.FINAL, mustBeFinal);
PsiElement statement = getStatementToInsertBefore();
if (statement == null) return;
PsiExpression newExpression = factory.createExpressionFromText(newName, myVariable);
@@ -1,4 +1,4 @@
// "Copy 'a' to temp final variable" "true"
// "Copy 'a' to final temp variable" "true"
public class DoubleTrouble {
public void test() {
int a = 1;
@@ -1,4 +1,4 @@
// "Copy 'i' to temp final variable" "true"
// "Copy 'i' to final temp variable" "true"
import java.io.*;
class a {
@@ -1,4 +1,4 @@
// "Copy 'o' to temp final variable" "true"
// "Copy 'o' to final temp variable" "true"
class Test1 {
void foo(){}
{
@@ -1,4 +1,4 @@
// "Copy 'i' to temp final variable" "true"
// "Copy 'i' to final temp variable" "true"
class ParamTypeBug {
private static String strings[] = new String[]{ "a", "b", "c" };
@@ -1,4 +1,4 @@
// "Copy 'a' to temp final variable" "true"
// "Copy 'a' to final temp variable" "true"
public class DoubleTrouble {
public void test() {
int a = 1;
@@ -1,4 +1,4 @@
// "Copy 'i' to temp final variable" "true"
// "Copy 'i' to final temp variable" "true"
import java.io.*;
class a {
@@ -1,4 +1,4 @@
// "Copy 'i' to temp final variable" "false"
// "Copy 'i' to final temp variable" "false"
interface I {
int f();
}
@@ -1,4 +1,4 @@
// "Copy 'o' to temp final variable" "true"
// "Copy 'o' to final temp variable" "true"
class Test1 {
void foo(){}
{
@@ -1,4 +1,4 @@
// "Copy 'i' to temp final variable" "true"
// "Copy 'i' to final temp variable" "true"
class ParamTypeBug {
private static String strings[] = new String[]{ "a", "b", "c" };
@@ -1,9 +1,9 @@
// "Copy 'a' to temp final variable" "true"
// "Copy 'a' to effectively final temp variable" "true"
class Test {
public void test() {
int a = 1;
a = 2;
final int finalA = a;
int finalA = a;
Runnable r = () -> {
System.out.println(finalA);
};
@@ -1,4 +1,4 @@
// "Copy 'a' to temp final variable" "true"
// "Copy 'a' to effectively final temp variable" "true"
class Test {
public void test() {
int a = 1;
@@ -171,7 +171,7 @@ fix.super.method.return.type.text=Make ''{0}'' return ''{1}''
surround.with.try.catch.fix=Surround with try/catch
make.final.family=Make Final
make.final.text=Make {0} final
make.final.copy.to.temp=Copy ''{0}'' to temp final variable
make.final.copy.to.temp=Copy ''{0}'' to {1} temp variable
make.final.transform.to.one.element.array=Transform {0} into final one element array
fix.variable.type.family=Fix Variable Type
fix.variable.type.text=Change {0} ''{1}'' type to ''{2}''