diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java
index 0c6b16e94a11..1bd2f37620e6 100644
--- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java
+++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java
@@ -353,14 +353,9 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
try {
text = file.getText().subSequence(startOffset, endOffset).toString();
String prefix = null;
- String stripped = text;
if (startLiteralExpression != null) {
final int startExpressionOffset = startLiteralExpression.getTextOffset();
- if (startOffset == startExpressionOffset) {
- if (StringUtil.startsWithChar(text, '\"') || StringUtil.startsWithChar(text, '\'')) {
- stripped = text.substring(1);
- }
- } else if (startOffset == startExpressionOffset + 1) {
+ if (startOffset == startExpressionOffset + 1) {
text = "\"" + text;
} else if (startOffset > startExpressionOffset + 1){
prefix = "\" + ";
@@ -371,11 +366,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
String suffix = null;
if (endLiteralExpression != null) {
final int endExpressionOffset = endLiteralExpression.getTextOffset() + endLiteralExpression.getTextLength();
- if (endOffset == endExpressionOffset ) {
- if (StringUtil.endsWithChar(stripped, '\"') || StringUtil.endsWithChar(stripped, '\'')) {
- stripped = stripped.substring(0, stripped.length() - 1);
- }
- } else if (endOffset == endExpressionOffset - 1) {
+ if (endOffset == endExpressionOffset - 1) {
text += "\"";
} else if (endOffset < endExpressionOffset - 1) {
suffix = " + \"";
@@ -383,24 +374,6 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
}
}
- boolean primitive = false;
- if (stripped.equals("true") || stripped.equals("false")) {
- primitive = true;
- }
- else {
- try {
- Integer.parseInt(stripped);
- primitive = true;
- }
- catch (NumberFormatException e1) {
- //then not primitive
- }
- }
-
- if (primitive) {
- text = stripped;
- }
-
if (literalExpression != null && text.equals(literalExpression.getText())) return literalExpression;
final PsiElement parent = literalExpression != null ? literalExpression : elementAt;
diff --git a/java/java-tests/testData/refactoring/introduceConstant/PartialStringLiteralConvertibleToInt.java b/java/java-tests/testData/refactoring/introduceConstant/PartialStringLiteralConvertibleToInt.java
new file mode 100644
index 000000000000..703db8121018
--- /dev/null
+++ b/java/java-tests/testData/refactoring/introduceConstant/PartialStringLiteralConvertibleToInt.java
@@ -0,0 +1,5 @@
+class Test {
+ void foo() {
+ String s = "5+5";
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/refactoring/introduceConstant/PartialStringLiteralConvertibleToInt_after.java b/java/java-tests/testData/refactoring/introduceConstant/PartialStringLiteralConvertibleToInt_after.java
new file mode 100644
index 000000000000..265a1f949ceb
--- /dev/null
+++ b/java/java-tests/testData/refactoring/introduceConstant/PartialStringLiteralConvertibleToInt_after.java
@@ -0,0 +1,7 @@
+class Test {
+ public static final String xxx = "+5";
+
+ void foo() {
+ String s = "5" + xxx;
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/refactoring/introduceConstant/StringLiteralConvertibleToInt.java b/java/java-tests/testData/refactoring/introduceConstant/StringLiteralConvertibleToInt.java
new file mode 100644
index 000000000000..540dbb0b0c92
--- /dev/null
+++ b/java/java-tests/testData/refactoring/introduceConstant/StringLiteralConvertibleToInt.java
@@ -0,0 +1,8 @@
+class Test {
+ void print(Stirng s) {
+ }
+
+ void foo() {
+ print("5");
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/refactoring/introduceConstant/StringLiteralConvertibleToInt_after.java b/java/java-tests/testData/refactoring/introduceConstant/StringLiteralConvertibleToInt_after.java
new file mode 100644
index 000000000000..c624b14f7faa
--- /dev/null
+++ b/java/java-tests/testData/refactoring/introduceConstant/StringLiteralConvertibleToInt_after.java
@@ -0,0 +1,10 @@
+class Test {
+ public static final String xxx = "5";
+
+ void print(Stirng s) {
+ }
+
+ void foo() {
+ print(xxx);
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/refactoring/introduceVariable/SubPrimitiveLiteral.after.java b/java/java-tests/testData/refactoring/introduceVariable/SubPrimitiveLiteral.after.java
index 63c604c9c62e..714a0a66a301 100644
--- a/java/java-tests/testData/refactoring/introduceVariable/SubPrimitiveLiteral.after.java
+++ b/java/java-tests/testData/refactoring/introduceVariable/SubPrimitiveLiteral.after.java
@@ -1,6 +1,6 @@
class A {
public void test() {
- boolean str = true;
+ String str = "true";
String s = "ss" + str;
}
}
\ No newline at end of file
diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceConstantTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceConstantTest.java
index 4baa4bdb3ca9..b92d69600d9f 100644
--- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceConstantTest.java
+++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceConstantTest.java
@@ -75,6 +75,18 @@ public class IntroduceConstantTest extends LightCodeInsightTestCase {
checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
+ public void testPartialStringLiteralConvertibleToInt() throws Exception {
+ configureByFile(BASE_PATH + getTestName(false) + ".java");
+ new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null);
+ checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
+ }
+
+ public void testStringLiteralConvertibleToInt() throws Exception {
+ configureByFile(BASE_PATH + getTestName(false) + ".java");
+ new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null);
+ checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
+ }
+
public void testPartialStringLiteralQualified() throws Exception {
configureByFile(BASE_PATH + getTestName(false) + ".java");
final PsiClass psiClass = ((PsiJavaFile)getFile()).getClasses()[0];
diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableTest.java
index 20d4e611be87..fbe86084b54a 100644
--- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableTest.java
+++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableTest.java
@@ -250,7 +250,7 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
}
public void testSubPrimitiveLiteral() {
- doTest(new MockIntroduceVariableHandler("str", false, false, false, "boolean"));
+ doTest(new MockIntroduceVariableHandler("str", false, false, false, CommonClassNames.JAVA_LANG_STRING));
}
public void testArrayFromVarargs() {