use of org.eclipse.jdt.ls.core.internal.handlers.InferSelectionHandler.InferSelectionParams in project eclipse.jdt.ls by eclipse.
the class InferSelectionHandlerTest method testInferSelectionWhenExtractVariable.
@Test
public void testInferSelectionWhenExtractVariable() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" public int foo() {\n");
buf.append(" boolean b1 = true;\n");
buf.append(" boolean b2 = false;\n");
buf.append(" boolean b3 = true && !b2;\n");
buf.append(" boolean b4 = b3 || /*|*/b2 && b1;\n");
buf.append(" if ((b1||b4) && (b2||b3))\n");
buf.append(" return 1;\n");
buf.append(" \n");
buf.append(" return 0;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
Range selection = getVerticalBarRange(cu);
CodeActionParams params = CodeActionUtil.constructCodeActionParams(cu, selection);
InferSelectionParams inferParams = new InferSelectionParams(RefactorProposalUtility.EXTRACT_VARIABLE_COMMAND, params);
List<SelectionInfo> infos = InferSelectionHandler.inferSelectionsForRefactor(inferParams);
Assert.assertNotNull(infos);
Assert.assertEquals(infos.size(), 3);
Assert.assertEquals(infos.get(0).name, "b2");
Assert.assertEquals(infos.get(0).length, 2);
Assert.assertEquals(infos.get(1).name, "b2 && b1");
Assert.assertEquals(infos.get(1).length, 8);
Assert.assertEquals(infos.get(2).name, "b3 || b2 && b1");
Assert.assertEquals(infos.get(2).length, 19);
}
use of org.eclipse.jdt.ls.core.internal.handlers.InferSelectionHandler.InferSelectionParams in project eclipse.jdt.ls by eclipse.
the class InferSelectionHandlerTest method testInferSelectionWhenExtractField.
@Test
public void testInferSelectionWhenExtractField() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" private String test = \"test\";\n");
buf.append(" public int foo() {\n");
buf.append(" int hashCode = this./*|*/test.hashCode();\n");
buf.append(" return 0;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
Range selection = getVerticalBarRange(cu);
CodeActionParams params = CodeActionUtil.constructCodeActionParams(cu, selection);
InferSelectionParams inferParams = new InferSelectionParams(RefactorProposalUtility.EXTRACT_FIELD_COMMAND, params);
List<SelectionInfo> infos = InferSelectionHandler.inferSelectionsForRefactor(inferParams);
Assert.assertNotNull(infos);
Assert.assertEquals(infos.size(), 2);
Assert.assertEquals(infos.get(0).name, "this.test");
Assert.assertEquals(infos.get(0).length, 14);
Assert.assertEquals(infos.get(1).name, "this.test.hashCode()");
Assert.assertEquals(infos.get(1).length, 25);
}
use of org.eclipse.jdt.ls.core.internal.handlers.InferSelectionHandler.InferSelectionParams in project eclipse.jdt.ls by eclipse.
the class InferSelectionHandlerTest method testInferSelectionWhenExtractConstant.
@Test
public void testInferSelectionWhenExtractConstant() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" public int foo() {\n");
buf.append(" boolean b1 = true;\n");
buf.append(" boolean b2 = false;\n");
buf.append(" boolean b3 = /*|*/true || false;\n");
buf.append(" boolean b4 = b3 || b2 && b1;\n");
buf.append(" if ((b1||b4) && (b2||b3))\n");
buf.append(" return 1;\n");
buf.append(" \n");
buf.append(" return 0;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
Range selection = getVerticalBarRange(cu);
CodeActionParams params = CodeActionUtil.constructCodeActionParams(cu, selection);
InferSelectionParams inferParams = new InferSelectionParams(RefactorProposalUtility.EXTRACT_CONSTANT_COMMAND, params);
List<SelectionInfo> infos = InferSelectionHandler.inferSelectionsForRefactor(inferParams);
Assert.assertNotNull(infos);
Assert.assertEquals(infos.size(), 2);
Assert.assertEquals(infos.get(0).name, "true");
Assert.assertEquals(infos.get(0).length, 4);
Assert.assertEquals(infos.get(1).name, "true || false");
Assert.assertEquals(infos.get(1).length, 13);
}
use of org.eclipse.jdt.ls.core.internal.handlers.InferSelectionHandler.InferSelectionParams in project eclipse.jdt.ls by eclipse.
the class InferSelectionHandlerTest method testInferSelectionWhenExtractMethod.
@Test
public void testInferSelectionWhenExtractMethod() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" public int foo() {\n");
buf.append(" boolean b1 = true;\n");
buf.append(" boolean b2 = false;\n");
buf.append(" boolean b3 = true && !b2;\n");
buf.append(" if (b1 && (/*|*/b2 || b3))\n");
buf.append(" return 1;\n");
buf.append(" \n");
buf.append(" return 0;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
Range selection = getVerticalBarRange(cu);
CodeActionParams params = CodeActionUtil.constructCodeActionParams(cu, selection);
InferSelectionParams inferParams = new InferSelectionParams(RefactorProposalUtility.EXTRACT_METHOD_COMMAND, params);
List<SelectionInfo> infos = InferSelectionHandler.inferSelectionsForRefactor(inferParams);
Assert.assertNotNull(infos);
Assert.assertEquals(infos.size(), 3);
Assert.assertEquals(infos.get(0).name, "b2");
Assert.assertEquals(infos.get(0).length, 2);
Assert.assertEquals(infos.get(1).name, "b2 || b3");
Assert.assertEquals(infos.get(1).length, 8);
Assert.assertEquals(infos.get(2).name, "b1 && (b2 || b3)");
Assert.assertEquals(infos.get(2).length, 21);
}
Aggregations