Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ignored test for jdt.ui issue 120 #122

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ private static boolean validate(final WhileLoopToChangeHit hit) {
});
return !hit.isInvalid;
}

private static String computeNextVarname(WhileStatement whilestatement) {
String name= null;
Expression exp= whilestatement.getExpression();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5817,6 +5817,85 @@ void m(List<String> strings) {
new HashSet<>(Arrays.asList(FixMessages.Java50Fix_ConvertToEnhancedForLoop_description)));
}

@Test
public void testWhileIssue120_WithOptionVarUsed() throws Exception {
IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null);
String sample= "" //
+ "package test;\n"
+ "import java.util.*;\n"
+ "public class Test {\n"
+ " private static <K, V> List<V> method(Map<K, List<V>> map) {\n"
+ " List<V> results = new ArrayList<>();\n"
+ " Iterator<List<V>> iterator = map.values().iterator();\n"
+ " while (iterator.hasNext()) {\n"
+ " results.addAll(iterator.next());\n"
+ " }\n"
+ " return results;\n"
+ " }\n"
+ "}\n";
ICompilationUnit cu1= pack.createCompilationUnit("Test.java", sample, false, null);

enable(CleanUpConstants.CONTROL_STATEMENTS_CONVERT_FOR_LOOP_TO_ENHANCED,
CleanUpConstants.CONTROL_STATEMENTS_CONVERT_FOR_LOOP_ONLY_IF_LOOP_VAR_USED);

sample= "" //
+ "package test;\n"
+ "import java.util.*;\n"
+ "public class Test {\n"
+ " private static <K, V> List<V> method(Map<K, List<V>> map) {\n"
+ " List<V> results = new ArrayList<>();\n"
+ " Iterator<List<V>> iterator = map.values().iterator();\n"
+ " while (iterator.hasNext()) {\n"
+ " results.addAll(iterator.next());\n"
+ " }\n"
+ " return results;\n"
+ " }\n"
+ "}\n";
String expected1= sample;

assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 },
new HashSet<>(Arrays.asList(FixMessages.Java50Fix_ConvertToEnhancedForLoop_description)));
}

@Test
public void testWhileIssue120_WithoutOptionVarUsed() throws Exception {
IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null);
String sample= "" //
+ "package test;\n"
+ "import java.util.*;\n"
+ "public class Test {\n"
+ " private static <K, V> List<V> method(Map<K, List<V>> map) {\n"
+ " List<V> results = new ArrayList<>();\n"
+ " Iterator<List<V>> iterator = map.values().iterator();\n"
+ " while (iterator.hasNext()) {\n"
+ " results.addAll(iterator.next());\n"
+ " }\n"
+ " return results;\n"
+ " }\n"
+ "}\n";
ICompilationUnit cu1= pack.createCompilationUnit("Test.java", sample, false, null);

enable(CleanUpConstants.CONTROL_STATEMENTS_CONVERT_FOR_LOOP_TO_ENHANCED);

sample= "" //
+ "package test;\n"
+ "import java.util.*;\n"
+ "public class Test {\n"
+ " private static <K, V> List<V> method(Map<K, List<V>> map) {\n"
+ " List<V> results = new ArrayList<>();\n"
+ " Iterator<List<V>> iterator = map.values().iterator();\n"
+ " while (iterator.hasNext()) {\n"
+ " results.addAll(iterator.next());\n"
+ " }\n"
+ " return results;\n"
+ " }\n"
+ "}\n";
String expected1= sample;

assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 },
new HashSet<>(Arrays.asList(FixMessages.Java50Fix_ConvertToEnhancedForLoop_description)));
}

@Test
public void testWhileSubtype() throws Exception {
IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ protected void enable(String key) throws CoreException {
commitProfile();
}

protected void enable(String... keys) throws CoreException {
for(String key:keys) {
fProfile.getSettings().put(key, CleanUpOptions.TRUE);
}
commitProfile();
}

private void commitProfile() throws CoreException {
List<Profile> profiles= CleanUpPreferenceUtil.getBuiltInProfiles();
profiles.add(fProfile);
Expand Down