mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Extract variable to chained method call
This commit is contained in:
@@ -2,7 +2,7 @@ class C {
|
||||
{
|
||||
int[] a = new int[1];
|
||||
a[1] = 42;
|
||||
int x = a[1];
|
||||
System.out.println(x);
|
||||
int i = a[1];
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import java.util.List;
|
||||
|
||||
public class StreamExtract {
|
||||
void test(List<String> list) {
|
||||
list.stream().forEach(s -> System.out.println(
|
||||
new StringBuilder().append(String.forma<caret>t("[%s]", s))
|
||||
.append("oops")
|
||||
.append("argh")
|
||||
));
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import java.util.List;
|
||||
|
||||
public class StreamExtract {
|
||||
void test(List<String> list) {
|
||||
list.stream().map(s -> String.format("[%s]", s)).forEach(format -> System.out.println(
|
||||
new StringBuilder().append(format)
|
||||
.append("oops")
|
||||
.append("argh")
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import java.util.List;
|
||||
|
||||
public class StreamExtract {
|
||||
void test(List<String> list) {
|
||||
list.stream().mapToInt(x -> x.length() + 10 * x.l<caret>ength()).forEach(System.out::println);
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import java.util.List;
|
||||
|
||||
public class StreamExtract {
|
||||
void test(List<String> list) {
|
||||
list.stream().mapToInt(String::length).map(length -> length + 10 * length).forEach(System.out::println);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import java.util.List;
|
||||
|
||||
public class StreamExtract {
|
||||
void test(List<String> list) {
|
||||
list.stream().forEach(s -> System.out.println(s.t<caret>oLowerCase()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import java.util.List;
|
||||
|
||||
public class StreamExtract {
|
||||
void test(List<String> list) {
|
||||
list.stream().map(String::toLowerCase).forEach(s1 -> System.out.println(s1));
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
class C {
|
||||
{
|
||||
int[] a = new int[1];
|
||||
int x = a[1];
|
||||
x = 42;
|
||||
System.out.println(x);
|
||||
int i = a[1];
|
||||
i = 42;
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -54,7 +54,7 @@ public abstract class AbstractJavaInplaceIntroduceTest extends AbstractInplaceIn
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return IdeaTestUtil.getMockJdk17();
|
||||
return IdeaTestUtil.getMockJdk18();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+24
-12
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,7 +31,7 @@ import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.introduce.inplace.AbstractInplaceIntroducer;
|
||||
import com.intellij.refactoring.introduce.inplace.OccurrencesChooser;
|
||||
import com.intellij.refactoring.introduceVariable.IntroduceVariableBase;
|
||||
import com.intellij.refactoring.introduceVariable.IntroduceVariableHandler;
|
||||
import com.intellij.testFramework.MapDataContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -117,7 +117,7 @@ public class InplaceIntroduceVariableTest extends AbstractJavaInplaceIntroduceTe
|
||||
}
|
||||
|
||||
public void testPlaceInsideLambdaBodyMultipleOccurrences1() throws Exception {
|
||||
doTestReplaceChoice(OccurrencesChooser.ReplaceChoice.ALL, new Pass<AbstractInplaceIntroducer>() {
|
||||
doTestReplaceChoice(IntroduceVariableBase.JavaReplaceChoice.ALL, new Pass<AbstractInplaceIntroducer>() {
|
||||
@Override
|
||||
public void pass(AbstractInplaceIntroducer inplaceIntroduceFieldPopup) {
|
||||
type("expr");
|
||||
@@ -190,19 +190,31 @@ public class InplaceIntroduceVariableTest extends AbstractJavaInplaceIntroduceTe
|
||||
}
|
||||
|
||||
public void testWritable() throws Exception {
|
||||
doTestReplaceChoice(OccurrencesChooser.ReplaceChoice.ALL);
|
||||
doTestReplaceChoice(IntroduceVariableBase.JavaReplaceChoice.ALL);
|
||||
}
|
||||
|
||||
public void testNoWritable() throws Exception {
|
||||
doTestReplaceChoice(OccurrencesChooser.ReplaceChoice.NO_WRITE);
|
||||
doTestReplaceChoice(IntroduceVariableBase.JavaReplaceChoice.NO_WRITE);
|
||||
}
|
||||
|
||||
public void testAllInsertFinal() throws Exception {
|
||||
doTestReplaceChoice(OccurrencesChooser.ReplaceChoice.ALL);
|
||||
doTestReplaceChoice(IntroduceVariableBase.JavaReplaceChoice.ALL);
|
||||
}
|
||||
|
||||
public void testAllIncomplete() throws Exception {
|
||||
doTestReplaceChoice(OccurrencesChooser.ReplaceChoice.ALL);
|
||||
doTestReplaceChoice(IntroduceVariableBase.JavaReplaceChoice.ALL);
|
||||
}
|
||||
|
||||
public void testStreamSimple() throws Exception {
|
||||
doTestReplaceChoice(IntroduceVariableBase.JavaReplaceChoice.CHAIN);
|
||||
}
|
||||
|
||||
public void testStreamMultiple() throws Exception {
|
||||
doTestReplaceChoice(IntroduceVariableBase.JavaReplaceChoice.CHAIN_ALL);
|
||||
}
|
||||
|
||||
public void testStreamMultiline() throws Exception {
|
||||
doTestReplaceChoice(IntroduceVariableBase.JavaReplaceChoice.CHAIN);
|
||||
}
|
||||
|
||||
public void testBrokenFormattingWithInValidation() throws Exception {
|
||||
@@ -273,11 +285,11 @@ public class InplaceIntroduceVariableTest extends AbstractJavaInplaceIntroduceTe
|
||||
}
|
||||
}
|
||||
|
||||
private void doTestReplaceChoice(OccurrencesChooser.ReplaceChoice choice) {
|
||||
private void doTestReplaceChoice(IntroduceVariableBase.JavaReplaceChoice choice) {
|
||||
doTestReplaceChoice(choice, null);
|
||||
}
|
||||
|
||||
private void doTestReplaceChoice(OccurrencesChooser.ReplaceChoice choice, Pass<AbstractInplaceIntroducer> pass) {
|
||||
private void doTestReplaceChoice(IntroduceVariableBase.JavaReplaceChoice choice, Pass<AbstractInplaceIntroducer> pass) {
|
||||
String name = getTestName(true);
|
||||
configureByFile(getBasePath() + name + getExtension());
|
||||
final boolean enabled = getEditor().getSettings().isVariableInplaceRenameEnabled();
|
||||
@@ -318,9 +330,9 @@ public class InplaceIntroduceVariableTest extends AbstractJavaInplaceIntroduceTe
|
||||
}
|
||||
|
||||
public static class MyIntroduceVariableHandler extends IntroduceVariableHandler implements MyIntroduceHandler {
|
||||
private OccurrencesChooser.ReplaceChoice myChoice = null;
|
||||
private JavaReplaceChoice myChoice = null;
|
||||
|
||||
public void setChoice(OccurrencesChooser.ReplaceChoice choice) {
|
||||
public void setChoice(JavaReplaceChoice choice) {
|
||||
myChoice = choice;
|
||||
}
|
||||
|
||||
@@ -335,7 +347,7 @@ public class InplaceIntroduceVariableTest extends AbstractJavaInplaceIntroduceTe
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OccurrencesChooser.ReplaceChoice getOccurrencesChoice() {
|
||||
protected JavaReplaceChoice getOccurrencesChoice() {
|
||||
return myChoice;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,7 +23,6 @@ import com.intellij.psi.CommonClassNames;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.refactoring.introduce.inplace.OccurrencesChooser;
|
||||
import com.intellij.refactoring.introduceVariable.InputValidator;
|
||||
import com.intellij.refactoring.introduceVariable.IntroduceVariableBase;
|
||||
import com.intellij.refactoring.introduceVariable.IntroduceVariableSettings;
|
||||
@@ -365,7 +364,7 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
|
||||
boolean declareFinalIfAll,
|
||||
boolean anyAssignmentLHS,
|
||||
InputValidator validator,
|
||||
PsiElement anchor, final OccurrencesChooser.ReplaceChoice replaceChoice) {
|
||||
PsiElement anchor, final JavaReplaceChoice replaceChoice) {
|
||||
final PsiType type = typeSelectorManager.getDefaultType();
|
||||
assertTrue(type.getPresentableText(), type.getPresentableText().equals(expectedTypeName));
|
||||
assertEquals("path", IntroduceVariableBase.getSuggestedName(type, expr).names[0]);
|
||||
@@ -384,7 +383,7 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
|
||||
boolean declareFinalIfAll,
|
||||
boolean anyAssignmentLHS,
|
||||
InputValidator validator,
|
||||
PsiElement anchor, final OccurrencesChooser.ReplaceChoice replaceChoice) {
|
||||
PsiElement anchor, final JavaReplaceChoice replaceChoice) {
|
||||
final PsiType type = typeSelectorManager.getDefaultType();
|
||||
assertTrue(type.getPresentableText(), type.getPresentableText().equals("B"));
|
||||
return super.getSettings(project, editor, expr, occurrences, typeSelectorManager, declareFinalIfAll, anyAssignmentLHS,
|
||||
@@ -552,7 +551,7 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
|
||||
boolean declareFinalIfAll,
|
||||
boolean anyAssignmentLHS,
|
||||
InputValidator validator,
|
||||
PsiElement anchor, final OccurrencesChooser.ReplaceChoice replaceChoice) {
|
||||
PsiElement anchor, final JavaReplaceChoice replaceChoice) {
|
||||
final PsiType[] types = typeSelectorManager.getTypesForAll();
|
||||
assertTrue(types[0].getPresentableText(), types[0].getPresentableText().equals("B"));
|
||||
assertTrue(types[1].getPresentableText(), types[1].getPresentableText().equals("A"));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,12 +20,10 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.refactoring.introduce.inplace.OccurrencesChooser;
|
||||
import com.intellij.refactoring.introduceVariable.InputValidator;
|
||||
import com.intellij.refactoring.introduceVariable.IntroduceVariableBase;
|
||||
import com.intellij.refactoring.introduceVariable.IntroduceVariableSettings;
|
||||
import com.intellij.refactoring.ui.TypeSelectorManagerImpl;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -66,7 +64,7 @@ class MockIntroduceVariableHandler extends IntroduceVariableBase {
|
||||
final boolean declareFinalIfAll,
|
||||
boolean anyAssignmentLHS,
|
||||
InputValidator validator,
|
||||
PsiElement anchor, final OccurrencesChooser.ReplaceChoice replaceChoice) {
|
||||
PsiElement anchor, final JavaReplaceChoice replaceChoice) {
|
||||
final PsiType type = myLookForType ? findType(typeSelectorManager.getTypesForAll(), typeSelectorManager.getDefaultType())
|
||||
: typeSelectorManager.getDefaultType();
|
||||
assertTrue(type.getInternalCanonicalText(), type.getInternalCanonicalText().equals(myExpectedTypeCanonicalName));
|
||||
|
||||
Reference in New Issue
Block a user