IDEA-172425 Fix minor issues after review (IDEA-CR-29936)
authorVitaliy.Bibaev <vitaliy.bibaev@jetbrains.com>
Thu, 1 Mar 2018 10:06:31 +0000 (13:06 +0300)
committerVitaliy.Bibaev <vitaliy.bibaev@jetbrains.com>
Thu, 1 Mar 2018 10:06:31 +0000 (13:06 +0300)
java/java-impl/src/com/intellij/refactoring/extractMethodObject/ExtractLightMethodObjectHandler.java
java/java-impl/src/com/intellij/refactoring/extractMethodObject/PsiReflectionAccessUtil.java
java/java-impl/src/com/intellij/refactoring/extractMethodObject/reflect/ReflectionAccessMethodBuilder.java
java/java-tests/testSrc/com/intellij/java/refactoring/ExtractMethodObject4DebuggerTest.java

index ad1719f69c23b78ce3801ce9f7f6db81e12df80e..1ba69a12ea7e4619c56152ce1654225c8489a012 100644 (file)
@@ -68,14 +68,6 @@ public class ExtractLightMethodObjectHandler {
     }
   }
 
-  @Nullable
-  public static ExtractedData extractLightMethodObject(final Project project,
-                                                       @Nullable PsiElement originalContext,
-                                                       @NotNull final PsiCodeFragment fragment,
-                                                       final String methodName) throws PrepareFailedException {
-    return extractLightMethodObject(project, originalContext, fragment, methodName, false);
-  }
-
   @Nullable
   public static ExtractedData extractLightMethodObject(final Project project,
                                                        @Nullable PsiElement originalContext,
index f52fa99b5b1e30caf72fa4f82b86aa5f62ecd384..263dd80d47ef3a05d000fa3c20fb48e894c9026e 100644 (file)
@@ -3,13 +3,11 @@ package com.intellij.refactoring.extractMethodObject;
 
 import com.intellij.psi.*;
 import com.intellij.psi.util.PsiUtil;
-import one.util.streamex.StreamEx;
+import com.intellij.psi.util.TypeConversionUtil;
 import org.jetbrains.annotations.Contract;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.Set;
-
 /**
  * @author Vitaliy.Bibaev
  */
@@ -65,18 +63,9 @@ public class PsiReflectionAccessUtil {
     return psiClass == null ? null : psiClass.getQualifiedName();
   }
 
-  private static final Set<String> PRIMITIVE_TYPES = StreamEx.of("byte", "short", "int", "long", "float", "double", "boolean", "char")
-                                                             .toImmutableSet();
-
   @NotNull
   @Contract(pure = true)
   public static String classForName(@NotNull String typeName) {
-    return PRIMITIVE_TYPES.contains(typeName) ? typeName + ".class" : "java.lang.Class.forName(\"" + typeName + "\")";
-  }
-
-  @NotNull
-  @Contract(pure = true)
-  public static String escape(String str) {
-    return "\"" + str + "\"";
+    return TypeConversionUtil.isPrimitive(typeName) ? typeName + ".class" : "java.lang.Class.forName(\"" + typeName + "\")";
   }
 }
index c196477e14508d8ac83883a0bbce3f50d7128a3f..5f6ec802e14ce0559ce6e431325e5304e1c291c3 100644 (file)
@@ -1,6 +1,7 @@
 // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
 package com.intellij.refactoring.extractMethodObject.reflect;
 
+import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.psi.*;
 import com.intellij.psi.util.ClassUtil;
 import com.intellij.psi.util.PsiUtil;
@@ -174,7 +175,7 @@ public class ReflectionAccessMethodBuilder {
     public String getMemberLookupBlock() {
       return "while (member == null) {\n" +
              "  try {\n" +
-             "    member = klass.getDeclaredField(" + PsiReflectionAccessUtil.escape(myFieldName) + ");\n" +
+             "    member = klass.getDeclaredField(" + StringUtil.wrapWithDoubleQuote(myFieldName) + ");\n" +
              "  }\n" +
              "  catch(java.lang.NoSuchFieldException e) {\n" +
              "    klass = klass.getSuperclass();\n" +
@@ -213,7 +214,7 @@ public class ReflectionAccessMethodBuilder {
     @Override
     public String getMemberLookupBlock() {
       String args = StreamEx.of(myParameters).skip(1).map(x -> PsiReflectionAccessUtil.classForName(x.jvmTypeName))
-                            .prepend(PsiReflectionAccessUtil.escape(myMethodName))
+                            .prepend(StringUtil.wrapWithDoubleQuote(myMethodName))
                             .joining(", ", "(", ")");
       return "while (member == null) {\n" +
              "  try {\n" +
index c470370328dae2f953ea56c32167091ce509e587..dec6518bcba64d04fc9522415db301f9b05cccf9 100644 (file)
@@ -46,7 +46,7 @@ public class ExtractMethodObject4DebuggerTest extends LightRefactoringTestCase {
     final JavaCodeFragmentFactory fragmentFactory = JavaCodeFragmentFactory.getInstance(getProject());
     final JavaCodeFragment fragment = codeBlock ? fragmentFactory.createCodeBlockCodeFragment(evaluatedText, context, false) : fragmentFactory.createExpressionCodeFragment(evaluatedText, context, null, false);
     final ExtractLightMethodObjectHandler.ExtractedData extractedData =
-      ExtractLightMethodObjectHandler.extractLightMethodObject(getProject(), context, fragment, "test");
+      ExtractLightMethodObjectHandler.extractLightMethodObject(getProject(), context, fragment, "test", false);
     assertNotNull(extractedData);
     assertEquals(expectedCallSite, extractedData.getGeneratedCallText());
     final PsiClass innerClass = extractedData.getGeneratedInnerClass();