From 9e9dbb1bba13ad3f329b896e2477e116486623c7 Mon Sep 17 00:00:00 2001 From: Carsten Hammer Date: Mon, 6 Jan 2025 20:28:55 +0100 Subject: [PATCH 1/3] add junit 3 test (disabled) --- .../corext/fix/helper/AbstractTool.java | 6 +- .../quickfix/Java8/JUnit3CleanupCases.java | 173 ++++++++++++++++++ .../Java8/JUnitMigrationCleanUpTest.java | 25 +++ 3 files changed, 200 insertions(+), 4 deletions(-) create mode 100644 sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnit3CleanupCases.java diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java index 4ead720..ca8c5d0 100644 --- a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java +++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java @@ -967,12 +967,12 @@ protected boolean isLifecycleMethod(MethodDeclaration method, String methodName) return methodName.equals(method.getName().getIdentifier()); } - private boolean isStringType(Expression expression, Class classType) { + protected boolean isStringType(Expression expression, Class classType) { ITypeBinding typeBinding = expression.resolveTypeBinding(); return typeBinding != null && classType.getCanonicalName().equals(typeBinding.getQualifiedName()); } - private boolean isSubtypeOf(ITypeBinding subtype, ITypeBinding supertype) { + protected boolean isSubtypeOf(ITypeBinding subtype, ITypeBinding supertype) { return subtype != null && supertype != null && (isTypeOrSubtype(subtype, supertype.getQualifiedName()) || implementsInterface(subtype, supertype)); @@ -1262,8 +1262,6 @@ public void reorderParameters(MethodInvocation node, ASTRewrite rewriter, TextEd } } - - private void replaceFieldWithExtensionDeclaration(ClassInstanceCreation classInstanceCreation, String nestedClassName, boolean fieldStatic, ASTRewrite rewriter, AST ast, TextEditGroup group, ImportRewrite importRewriter) { diff --git a/sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnit3CleanupCases.java b/sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnit3CleanupCases.java new file mode 100644 index 0000000..a472ac4 --- /dev/null +++ b/sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnit3CleanupCases.java @@ -0,0 +1,173 @@ +package org.eclipse.jdt.ui.tests.quickfix.Java8; + +/*- + * #%L + * Sandbox junit cleanup test + * %% + * Copyright (C) 2024 hammer + * %% + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License, v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is + * available at https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + * #L% + */ + +enum JUnit3CleanupCases{ + Junit3Case( + """ +package test; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class MyTest extends TestCase { + + public MyTest(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + // Setup vor jedem Test + } + + @Override + protected void tearDown() throws Exception { + // Aufräumen nach jedem Test + } + + public static Test suite() { + TestSuite suite = new TestSuite(); + suite.addTest(new MyTest("testBasicAssertions")); + suite.addTest(new MyTest("testArrayAssertions")); + suite.addTest(new MyTest("testWithAssume")); + suite.addTest(new MyTest("testAssertThat")); + suite.addTest(new MyTest("testEqualityWithDelta")); + suite.addTest(new MyTest("testFail")); + return suite; + } + + public void testBasicAssertions() { + assertEquals("Values should match", 42, 42); + assertTrue("Condition should be true", true); + assertFalse("Condition should be false", false); + assertNull("Should be null", null); + assertNotNull("Should not be null", new Object()); + } + + public void testArrayAssertions() { + int[] expected = {1, 2, 3}; + int[] actual = {1, 2, 3}; + assertEquals("Arrays should match", expected.length, actual.length); + for (int i = 0; i < expected.length; i++) { + assertEquals("Array element mismatch at index " + i, expected[i], actual[i]); + } + } + + public void testWithAssume() { + assumeTrue("Precondition failed", true); + assumeFalse("Precondition not met", false); + } + + public void testAssertThat() { + assertEquals("Value should match", 42, 42); // Ersatz für assertThat in JUnit 3 + } + + public void testEqualityWithDelta() { + assertEquals("Floating point equality with delta", 0.1 + 0.2, 0.3, 0.0001); + } + + public void testFail() { + fail("This test should fail with a message."); + } +} + + """ + , + """ +package test; + +import static org.junit.jupiter.api.Assertions.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.jupiter.api.Assumptions.*; + +import org.junit.jupiter.api.*; + +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class MyTest { + + @BeforeEach + public void setUp() throws Exception { + // Setup vor jedem Test + } + + @AfterEach + public void tearDown() throws Exception { + // Aufräumen nach jedem Test + } + + @Test + @Order(1) + public void testBasicAssertions() { + assertEquals(42, 42, "Values should match"); + assertTrue(true, "Condition should be true"); + assertFalse(false, "Condition should be false"); + assertNull(null, "Should be null"); + assertNotNull(new Object(), "Should not be null"); + } + + @Test + @Order(2) + public void testArrayAssertions() { + int[] expected = {1, 2, 3}; + int[] actual = {1, 2, 3}; + assertArrayEquals(expected, actual, "Arrays should match"); + } + + @Test + @Order(3) + public void testWithAssume() { + assumeTrue(true, "Precondition failed"); + assumeFalse(false, "Precondition not met"); + } + + @Test + @Order(4) + public void testAssertThat() { + assertThat("Value should match", 42, is(42)); + } + + @Test + @Order(5) + public void testEqualityWithDelta() { + assertEquals(0.3, 0.1 + 0.2, 0.0001, "Floating point equality with delta"); + } + + @Test + @Order(6) + public void testFail() { + fail("This test should fail with a message."); + } +} + + """ + ); //$NON-NLS-1$ + + String given; + String expected; + + JUnit3CleanupCases(String given, String expected) { + this.given=given; + this.expected=expected; + } + } diff --git a/sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnitMigrationCleanUpTest.java b/sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnitMigrationCleanUpTest.java index 8b63233..ff0df05 100644 --- a/sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnitMigrationCleanUpTest.java +++ b/sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnitMigrationCleanUpTest.java @@ -39,6 +39,7 @@ import org.eclipse.jdt.core.IPackageFragmentRoot; import org.eclipse.jdt.junit.JUnitCore; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedTest; @@ -87,6 +88,30 @@ public void testJUnitCleanupParametrized(JUnitCleanupCases test) throws CoreExce context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RUNWITH); context4junit4.assertRefactoringResultAsExpected(new ICompilationUnit[] {cu}, new String[] {test.expected}, null); } + + @Disabled + @ParameterizedTest + @EnumSource(JUnit3CleanupCases.class) + public void testJUnit3CleanupParametrized(JUnit3CleanupCases test) throws CoreException { + IPackageFragment pack= fRootJUnit4.createPackageFragment("test", true, null); + ICompilationUnit cu= pack.createCompilationUnit("MyTest.java", test.given, true, null); //$NON-NLS-1$ + context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP); + context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSERT); + context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSUME); + context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_SUITE); + context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORE); + context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTER); + context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORECLASS); + context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTERCLASS); + context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_IGNORE); + context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_TEST); + context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETEMPORARYFOLDER); + context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETESTNAME); + context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RULEEXTERNALRESOURCE); +// context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_EXTERNALRESOURCE); + context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RUNWITH); + context4junit4.assertRefactoringResultAsExpected(new ICompilationUnit[] {cu}, new String[] {test.expected}, null); + } enum NOJUnitCleanupCases { From 88fb2f6cbf82c07d09896191ba323471c97a6c5e Mon Sep 17 00:00:00 2001 From: Carsten Hammer Date: Wed, 8 Jan 2025 21:09:10 +0100 Subject: [PATCH 2/3] add first implementation --- .../corext/fix2/MYCleanUpConstants.java | 8 + .../corext/fix/JUnitCleanUpFixCore.java | 2 + .../corext/fix/helper/AbstractTool.java | 10 +- .../corext/fix/helper/AssertJUnitPlugin.java | 9 - .../corext/fix/helper/TestJUnit3Plugin.java | 283 ++++++++++++++++++ .../jdt/internal/ui/fix/JUnitCleanUpCore.java | 38 ++- .../preferences/cleanup/CleanUpMessages.java | 3 + .../cleanup/CleanUpMessages.properties | 5 +- .../DefaultCleanUpOptionsInitializer.java | 3 + .../cleanup/SandboxCodeTabPage.java | 21 +- .../SaveActionCleanUpOptionsInitializer.java | 3 + .../quickfix/Java8/JUnit3CleanupCases.java | 4 +- .../Java8/JUnitMigrationCleanUpTest.java | 26 +- 13 files changed, 373 insertions(+), 42 deletions(-) create mode 100644 sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/TestJUnit3Plugin.java diff --git a/sandbox_common/src/org/sandbox/jdt/internal/corext/fix2/MYCleanUpConstants.java b/sandbox_common/src/org/sandbox/jdt/internal/corext/fix2/MYCleanUpConstants.java index 1a9aef8..6d9f13d 100644 --- a/sandbox_common/src/org/sandbox/jdt/internal/corext/fix2/MYCleanUpConstants.java +++ b/sandbox_common/src/org/sandbox/jdt/internal/corext/fix2/MYCleanUpConstants.java @@ -83,6 +83,10 @@ public class MYCleanUpConstants { * */ public static final String JUNIT_CLEANUP= "cleanup.junitcleanup"; //$NON-NLS-1$ + /** + * + */ + public static final String JUNIT3_CLEANUP= "cleanup.junit3cleanup"; //$NON-NLS-1$ /** * */ @@ -119,6 +123,10 @@ public class MYCleanUpConstants { * */ public static final String JUNIT_CLEANUP_4_TEST= "cleanup.junitcleanup_4_test"; //$NON-NLS-1$ + /** + * + */ + public static final String JUNIT_CLEANUP_3_TEST= "cleanup.junitcleanup_3_test"; //$NON-NLS-1$ /** * */ diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/JUnitCleanUpFixCore.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/JUnitCleanUpFixCore.java index c193aba..45747bf 100644 --- a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/JUnitCleanUpFixCore.java +++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/JUnitCleanUpFixCore.java @@ -47,6 +47,7 @@ import org.sandbox.jdt.internal.corext.fix.helper.RuleTemporayFolderJUnitPlugin; import org.sandbox.jdt.internal.corext.fix.helper.RuleTestnameJUnitPlugin; import org.sandbox.jdt.internal.corext.fix.helper.RunWithJUnitPlugin; +import org.sandbox.jdt.internal.corext.fix.helper.TestJUnit3Plugin; import org.sandbox.jdt.internal.corext.fix.helper.TestJUnitPlugin; import org.sandbox.jdt.internal.ui.fix.MultiFixMessages; @@ -55,6 +56,7 @@ public enum JUnitCleanUpFixCore { BEFORE(new BeforeJUnitPlugin()), AFTER(new AfterJUnitPlugin()), TEST(new TestJUnitPlugin()), + TEST3(new TestJUnit3Plugin()), BEFORECLASS(new BeforeClassJUnitPlugin()), AFTERCLASS(new AfterClassJUnitPlugin()), IGNORE(new IgnoreJUnitPlugin()), diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java index ca8c5d0..6b4a9fd 100644 --- a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java +++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java @@ -40,6 +40,8 @@ import java.util.Collection; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.eclipse.core.filebuffers.FileBuffers; import org.eclipse.core.filebuffers.ITextFileBuffer; @@ -182,6 +184,12 @@ public abstract class AbstractTool { private static final String BEFORE_EACH_CALLBACK= "BeforeEachCallback"; protected static final String ORG_JUNIT_JUPITER_API_EXTENSION_EXTEND_WITH= "org.junit.jupiter.api.extension.ExtendWith"; + protected static final Set twoparam= Set.of("assertEquals", "assertNotEquals", "assertArrayEquals", + "assertSame","assertNotSame","assertThat"); + protected static final Set oneparam= Set.of("assertTrue", "assertFalse", "assertNull", "assertNotNull"); + private static final Set noparam= Set.of("fail"); + protected static final Set allassertionmethods= Stream.of(twoparam, oneparam, noparam).flatMap(Set::stream) + .collect(Collectors.toSet()); public static Collection getUsedVariableNames(ASTNode node) { CompilationUnit root= (CompilationUnit) node.getRoot(); @@ -978,7 +986,7 @@ protected boolean isSubtypeOf(ITypeBinding subtype, ITypeBinding supertype) { && (isTypeOrSubtype(subtype, supertype.getQualifiedName()) || implementsInterface(subtype, supertype)); } - private boolean isTypeOrSubtype(ITypeBinding typeBinding, String qualifiedName) { + protected boolean isTypeOrSubtype(ITypeBinding typeBinding, String qualifiedName) { while (typeBinding != null) { if (qualifiedName.equals(typeBinding.getQualifiedName())) { return true; diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AssertJUnitPlugin.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AssertJUnitPlugin.java index 2593f81..12cffe7 100644 --- a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AssertJUnitPlugin.java +++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AssertJUnitPlugin.java @@ -34,8 +34,6 @@ */ import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; @@ -60,13 +58,6 @@ */ public class AssertJUnitPlugin extends AbstractTool> { - static final Set twoparam= Set.of("assertEquals", "assertNotEquals", "assertArrayEquals", - "assertSame","assertNotSame","assertThat"); - static final Set oneparam= Set.of("assertTrue", "assertFalse", "assertNull", "assertNotNull"); - private static final Set noparam= Set.of("fail"); - private static final Set allassertionmethods= Stream.of(twoparam, oneparam, noparam).flatMap(Set::stream) - .collect(Collectors.toSet()); - @Override public void find(JUnitCleanUpFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed) { diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/TestJUnit3Plugin.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/TestJUnit3Plugin.java new file mode 100644 index 0000000..1e2a0d6 --- /dev/null +++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/TestJUnit3Plugin.java @@ -0,0 +1,283 @@ +/******************************************************************************* + * Copyright (c) 2021 Carsten Hammer. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Carsten Hammer + *******************************************************************************/ +package org.sandbox.jdt.internal.corext.fix.helper; + +import java.util.List; + +/*- + * #%L + * Sandbox junit cleanup + * %% + * Copyright (C) 2024 hammer + * %% + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License, v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is + * available at https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + * #L% + */ + +import java.util.Set; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.ASTVisitor; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.Expression; +import org.eclipse.jdt.core.dom.MarkerAnnotation; +import org.eclipse.jdt.core.dom.MethodDeclaration; +import org.eclipse.jdt.core.dom.MethodInvocation; +import org.eclipse.jdt.core.dom.Modifier; +import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.Type; +import org.eclipse.jdt.core.dom.TypeDeclaration; +import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; +import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; +import org.eclipse.jdt.core.dom.rewrite.ListRewrite; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; +import org.eclipse.text.edits.TextEditGroup; +import org.sandbox.jdt.internal.common.HelperVisitor; +import org.sandbox.jdt.internal.common.ReferenceHolder; +import org.sandbox.jdt.internal.corext.fix.JUnitCleanUpFixCore; + +/** + * + * + */ +public class TestJUnit3Plugin extends AbstractTool> { + + @Override + public void find(JUnitCleanUpFixCore fixcore, CompilationUnit compilationUnit, + Set operations, Set nodesprocessed) { + ReferenceHolder dataholder= new ReferenceHolder<>(); + HelperVisitor.callTypeDeclarationVisitor("junit.framework.TestCase", compilationUnit, dataholder, + nodesprocessed, + (visited, aholder) -> processFoundNode(fixcore, operations, visited, aholder, nodesprocessed)); + } + + private boolean processFoundNode(JUnitCleanUpFixCore fixcore, + Set operations, TypeDeclaration node, + ReferenceHolder dataholder, Set nodesprocessed) { + if (!nodesprocessed.contains(node)) { + boolean nothingtochange= true; + for (MethodDeclaration method : node.getMethods()) { + if (!isTestMethod(method)) { + nothingtochange= false; + } + } + if (nothingtochange) { + return false; + } + + nodesprocessed.add(node); + JunitHolder mh= new JunitHolder(); + mh.minv= node; + dataholder.put(dataholder.size(), mh); + operations.add(fixcore.rewrite(dataholder)); + } + return false; + } + + private void correctAssertionOrder(MethodInvocation node, ASTRewrite rewriter, AST ast, TextEditGroup group) { + String methodName = node.getName().getIdentifier(); + + // Prüfe, ob es sich um eine bekannte Assertion handelt + if ("assertEquals".equals(methodName) || "assertArrayEquals".equals(methodName)) { + List arguments = node.arguments(); + if (arguments.size() == 3) { + // Reorganisiere die Reihenfolge: message, expected, actual -> expected, actual, message + Expression expected = (Expression) arguments.get(1); + Expression actual = (Expression) arguments.get(2); + Expression message = (Expression) arguments.get(0); + + ListRewrite listRewrite = rewriter.getListRewrite(node, MethodInvocation.ARGUMENTS_PROPERTY); + listRewrite.replace((ASTNode) arguments.get(0), expected, group); + listRewrite.replace((ASTNode) arguments.get(1), actual, group); + listRewrite.replace((ASTNode) arguments.get(2), message, group); + } + } + } + + private boolean isTestMethod(MethodDeclaration method) { + // Konstruktoren ausschließen + if (method.isConstructor()) { + return false; + } + + String methodName = method.getName().getIdentifier(); + + // Prüfen auf typische JUnit 3-Testmethoden + if (methodName.startsWith("test")) { + return true; + } + + // Prüfen auf alternative Namensschemata + if (methodName.endsWith("_test") || methodName.startsWith("should") || methodName.contains("Test")) { + return true; + } + + // Zusätzliche Bedingungen: public, void, keine Parameter + return Modifier.isPublic(method.getModifiers()) && "void".equals(method.getReturnType2().toString()) + && method.parameters().isEmpty(); + } + + + @Override + void process2Rewrite(TextEditGroup group, ASTRewrite rewriter, AST ast, ImportRewrite importRewriter, + JunitHolder mh) { + TypeDeclaration node= mh.getTypeDeclaration(); + // Remove `extends TestCase` + Type superclass= node.getSuperclassType(); + if (superclass != null && "TestCase".equals(superclass.toString())) { + rewriter.remove(node.getSuperclassType(), group); + } + + for (MethodDeclaration method : node.getMethods()) { + if (isSetupMethod(method)) { + convertToAnnotation(method, "BeforeEach", importRewriter, rewriter, ast, group); + } else if (isTeardownMethod(method)) { + convertToAnnotation(method, "AfterEach", importRewriter, rewriter, ast, group); + } else if (isTestMethod(method)) { + addAnnotationToMethod(method, "Test", importRewriter, rewriter, ast, group); + } + + // Bearbeite Assertions und Assumptions in allen relevanten Methoden + if (method.getBody() != null) { + rewriteAssertionsAndAssumptions(method, rewriter, ast, group,importRewriter); + } + } + + } + + private void rewriteAssertionsAndAssumptions(MethodDeclaration method, ASTRewrite rewriter, AST ast, TextEditGroup group, ImportRewrite importRewriter) { + method.accept(new ASTVisitor() { + @Override + public boolean visit(MethodInvocation node) { + // Überprüfen, ob das MethodBinding aufgelöst werden kann + if (node.resolveMethodBinding() != null) { + String fullyQualifiedName = node.resolveMethodBinding().getDeclaringClass().getQualifiedName(); + + if ("junit.framework.Assert".equals(fullyQualifiedName) || "junit.framework.Assume".equals(fullyQualifiedName)) { +// correctAssertionOrder(node, rewriter, ast, group); + + reorderParameters(node, rewriter, group, oneparam, twoparam); +// SimpleName newQualifier= ast.newSimpleName(ASSERTIONS); +// Expression expression= assertexpression; +// if (expression != null) { +// ASTNodes.replaceButKeepComment(rewriter, expression, newQualifier, group); +// } + + + + + // Ändere den Qualifier (z.B. Assert.assertEquals -> Assertions.assertEquals) + rewriter.set(node.getExpression(), SimpleName.IDENTIFIER_PROPERTY, "Assertions", group); +// ASTNodes.replaceButKeepComment(rewriter, expression, newQualifier, group); + + // Passe Importe an + addImportForAssertion(node.getName().getIdentifier(), ast, rewriter, group, importRewriter); + } + } + + return super.visit(node); + } + }); + } + + + private void addImportForAssertion(String assertionMethod, AST ast, ASTRewrite rewriter, TextEditGroup group, ImportRewrite importRewriter) { + String importToAdd = null; + + switch (assertionMethod) { + case "assertEquals": + case "assertArrayEquals": + case "assertTrue": + case "assertFalse": + case "assertNull": + case "assertNotNull": + importToAdd = "org.junit.jupiter.api.Assertions"; + break; + case "assumeTrue": + case "assumeFalse": + case "assumeNotNull": + importToAdd = "org.junit.jupiter.api.Assumptions"; + break; + case "assertThat": + importToAdd = "org.hamcrest.MatcherAssert"; + break; + } + + if (importToAdd != null) { + importRewriter.addImport(importToAdd); + } + } + + + private boolean isSetupMethod(MethodDeclaration method) { + return "setUp".equals(method.getName().getIdentifier()) && method.parameters().isEmpty() + && method.getReturnType2() == null; + } + + private boolean isTeardownMethod(MethodDeclaration method) { + return "tearDown".equals(method.getName().getIdentifier()) && method.parameters().isEmpty() + && method.getReturnType2() == null; + } + + private void convertToAnnotation(MethodDeclaration method, String annotation, ImportRewrite importRewrite, + ASTRewrite rewrite, AST ast, TextEditGroup group) { + // Add annotation + ListRewrite modifiers= rewrite.getListRewrite(method, MethodDeclaration.MODIFIERS2_PROPERTY); + MarkerAnnotation newMarkerAnnotation= ast.newMarkerAnnotation(); + newMarkerAnnotation.setTypeName(ast.newSimpleName(annotation)); + modifiers.insertFirst(newMarkerAnnotation, group); + importRewrite.addImport("org.junit.jupiter.api." + annotation.substring(1)); + } + + private void addAnnotationToMethod(MethodDeclaration method, String annotation, ImportRewrite importRewrite, + ASTRewrite rewrite, AST ast, TextEditGroup group) { +// Füge die Annotation zum Methodenkopf hinzu + ListRewrite modifiers= rewrite.getListRewrite(method, MethodDeclaration.MODIFIERS2_PROPERTY); + MarkerAnnotation newMarkerAnnotation= ast.newMarkerAnnotation(); + newMarkerAnnotation.setTypeName(ast.newSimpleName(annotation)); // annotation sollte nur den Namen enthalten, z. + // B. "Test" + modifiers.insertFirst(newMarkerAnnotation, group); + +// Import der Annotation hinzufügen + importRewrite.addImport("org.junit.jupiter.api." + annotation); + } + + @Override + public String getPreview(boolean afterRefactoring) { + if (afterRefactoring) { + return """ + import org.junit.jupiter.api.Test; + """; //$NON-NLS-1$ + } + return """ + import junit.framework.TestCase; + """; //$NON-NLS-1$ + } + + @Override + public String toString() { + return "TestCase"; //$NON-NLS-1$ + } +} diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/JUnitCleanUpCore.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/JUnitCleanUpCore.java index c469b37..a238412 100644 --- a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/JUnitCleanUpCore.java +++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/JUnitCleanUpCore.java @@ -34,6 +34,7 @@ */ import static org.sandbox.jdt.internal.corext.fix2.MYCleanUpConstants.JUNIT_CLEANUP; +import static org.sandbox.jdt.internal.corext.fix2.MYCleanUpConstants.JUNIT3_CLEANUP; import static org.sandbox.jdt.internal.ui.fix.MultiFixMessages.JUnitCleanUpFix_refactor; import static org.sandbox.jdt.internal.ui.fix.MultiFixMessages.JUnitCleanUp_description; @@ -76,7 +77,7 @@ public CleanUpRequirements getRequirements() { } public boolean requireAST() { - return isEnabled(JUNIT_CLEANUP); + return isEnabled(JUNIT_CLEANUP)||isEnabled(JUNIT3_CLEANUP); } @Override @@ -86,7 +87,7 @@ public ICleanUpFix createFix(final CleanUpContext context) throws CoreException return null; } EnumSet computeFixSet= computeFixSet(); - if (!isEnabled(JUNIT_CLEANUP) || computeFixSet.isEmpty() + if (!(isEnabled(JUNIT_CLEANUP)||isEnabled(JUNIT3_CLEANUP)) || computeFixSet.isEmpty() || !JavaModelUtil.is1d8OrHigher(compilationUnit.getJavaElement().getJavaProject())) { return null; } @@ -102,7 +103,7 @@ public ICleanUpFix createFix(final CleanUpContext context) throws CoreException @Override public String[] getStepDescriptions() { List result= new ArrayList<>(); - if (isEnabled(JUNIT_CLEANUP)) { + if ((isEnabled(JUNIT_CLEANUP)||isEnabled(JUNIT3_CLEANUP))) { result.add(Messages.format(JUnitCleanUp_description, new Object[] { String.join(",", //$NON-NLS-1$ computeFixSet().stream().map(JUnitCleanUpFixCore::toString).collect(Collectors.toList())) })); } @@ -113,15 +114,16 @@ public String[] getStepDescriptions() { public String getPreview() { StringBuilder sb= new StringBuilder(); EnumSet computeFixSet= computeFixSet(); - EnumSet.allOf(JUnitCleanUpFixCore.class).forEach(e -> sb.append(e.getPreview(computeFixSet.contains(e)))); + allOfJunit4().forEach(e -> sb.append(e.getPreview(computeFixSet.contains(e)))); return sb.toString(); } - - private EnumSet computeFixSet() { - EnumSet fixSet = isEnabled(JUNIT_CLEANUP) - ? EnumSet.allOf(JUnitCleanUpFixCore.class) + EnumSet fixSetJunit4 = isEnabled(JUNIT_CLEANUP) + ? allOfJunit4() + : EnumSet.noneOf(JUnitCleanUpFixCore.class); + EnumSet fixSetJunit3 = isEnabled(JUNIT3_CLEANUP) + ? allOfJunit3() : EnumSet.noneOf(JUnitCleanUpFixCore.class); Map cleanupMappings = Map.ofEntries( Map.entry(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSERT, JUnitCleanUpFixCore.ASSERT), @@ -131,6 +133,7 @@ private EnumSet computeFixSet() { Map.entry(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTERCLASS, JUnitCleanUpFixCore.AFTERCLASS), Map.entry(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORECLASS, JUnitCleanUpFixCore.BEFORECLASS), Map.entry(MYCleanUpConstants.JUNIT_CLEANUP_4_TEST, JUnitCleanUpFixCore.TEST), + Map.entry(MYCleanUpConstants.JUNIT_CLEANUP_3_TEST, JUnitCleanUpFixCore.TEST3), Map.entry(MYCleanUpConstants.JUNIT_CLEANUP_4_IGNORE, JUnitCleanUpFixCore.IGNORE), Map.entry(MYCleanUpConstants.JUNIT_CLEANUP_4_RUNWITH, JUnitCleanUpFixCore.RULETEMPORARYFOLDER), Map.entry(MYCleanUpConstants.JUNIT_CLEANUP_4_EXTERNALRESOURCE, JUnitCleanUpFixCore.EXTERNALRESOURCE), @@ -138,11 +141,26 @@ private EnumSet computeFixSet() { Map.entry(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETESTNAME, JUnitCleanUpFixCore.RULETESTNAME), Map.entry(MYCleanUpConstants.JUNIT_CLEANUP_4_RULEEXTERNALRESOURCE, JUnitCleanUpFixCore.RULEEXTERNALRESOURCE) ); + EnumSet fixSetcombined=EnumSet.copyOf(fixSetJunit4); + fixSetcombined.addAll(fixSetJunit3); + cleanupMappings.forEach((config, fix) -> { if (!isEnabled(config)) { - fixSet.remove(fix); + fixSetcombined.remove(fix); } }); - return fixSet; + return fixSetcombined; + } + + private EnumSet allOfJunit4() { + EnumSet allOf= EnumSet.allOf(JUnitCleanUpFixCore.class); + allOf.remove(JUnitCleanUpFixCore.TEST3); + return allOf; + } + + private EnumSet allOfJunit3() { + EnumSet allOf= EnumSet.noneOf(JUnitCleanUpFixCore.class); + allOf.add(JUnitCleanUpFixCore.TEST3); + return allOf; } } diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java index a494c59..4af7797 100644 --- a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java +++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java @@ -52,6 +52,9 @@ public class CleanUpMessages { public static String JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_RULEEXTERNALRESOURCE; public static String JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_EXTERNALRESOURCE; public static String JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_RUNWITH; + public static String JavaFeatureTabPage_GroupName_JUnit3; + public static String JavaFeatureTabPage_CheckboxName_JUNIT3_CLEANUP; + public static String JavaFeatureTabPage_CheckboxName_JUNIT3_CLEANUP_TEST; static { diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties index 82e54ac..d39e150 100644 --- a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties +++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties @@ -31,4 +31,7 @@ JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_RULETESTNAME=Rule Testname JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_RULEEXTERNALRESOURCE=RuleExternalResource JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_EXTERNALRESOURCE=ExternalResource JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_RUNWITH=RunWith -JavaFeatureTabPage_GroupName_JUnit=JUnit +JavaFeatureTabPage_GroupName_JUnit=JUnit4 +JavaFeatureTabPage_CheckboxName_JUNIT3_CLEANUP=JUNIT3_CLEANUP +JavaFeatureTabPage_CheckboxName_JUNIT3_CLEANUP_TEST=Test +JavaFeatureTabPage_GroupName_JUnit3=JUnit3 diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/DefaultCleanUpOptionsInitializer.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/DefaultCleanUpOptionsInitializer.java index fa595c5..cc2e267 100644 --- a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/DefaultCleanUpOptionsInitializer.java +++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/DefaultCleanUpOptionsInitializer.java @@ -55,5 +55,8 @@ public void setDefaultOptions(CleanUpOptions options) { options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_RULEEXTERNALRESOURCE, CleanUpOptions.FALSE); options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_EXTERNALRESOURCE, CleanUpOptions.FALSE); options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_RUNWITH, CleanUpOptions.FALSE); + + options.setOption(MYCleanUpConstants.JUNIT3_CLEANUP, CleanUpOptions.FALSE); + options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_3_TEST, CleanUpOptions.FALSE); } } diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/SandboxCodeTabPage.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/SandboxCodeTabPage.java index df0ddf2..341019b 100644 --- a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/SandboxCodeTabPage.java +++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/SandboxCodeTabPage.java @@ -79,7 +79,6 @@ protected void doCreatePreferences(Composite composite, int numColumns) { final CheckboxPreference junit_test= createCheckboxPref(junitGroup, numColumns-1, CleanUpMessages.JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_TEST, MYCleanUpConstants.JUNIT_CLEANUP_4_TEST, FALSE_TRUE); - intent(junitGroup); final CheckboxPreference junit_before= createCheckboxPref(junitGroup, numColumns-1, CleanUpMessages.JavaFeatureTabPage_CheckboxName_JUNIT_CLEANUP_BEFORE, MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORE, @@ -131,7 +130,25 @@ protected void doCreatePreferences(Composite composite, int numColumns) { junit_externalresource, junit_runwith}); intent(junitGroup); - registerPreference(junitcb); + + Group junit3Group= createGroup(numColumns, composite, CleanUpMessages.JavaFeatureTabPage_GroupName_JUnit3); + final CheckboxPreference junit3cb= createCheckboxPref(junit3Group, numColumns, + CleanUpMessages.JavaFeatureTabPage_CheckboxName_JUNIT3_CLEANUP, MYCleanUpConstants.JUNIT3_CLEANUP, + FALSE_TRUE); + intent(junit3Group); + + final CheckboxPreference junit3_test= createCheckboxPref(junit3Group, numColumns-1, + CleanUpMessages.JavaFeatureTabPage_CheckboxName_JUNIT3_CLEANUP_TEST, MYCleanUpConstants.JUNIT_CLEANUP_3_TEST, + FALSE_TRUE); + + intent(junit3Group); + + + registerSlavePreference(junit3cb, new CheckboxPreference[] { + junit3_test + }); + intent(junit3Group); + registerPreference(junit3cb); } } diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/SaveActionCleanUpOptionsInitializer.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/SaveActionCleanUpOptionsInitializer.java index 3f2fe41..fa30f77 100644 --- a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/SaveActionCleanUpOptionsInitializer.java +++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/preferences/cleanup/SaveActionCleanUpOptionsInitializer.java @@ -55,5 +55,8 @@ public void setDefaultOptions(CleanUpOptions options) { options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_RULEEXTERNALRESOURCE, CleanUpOptions.FALSE); options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_EXTERNALRESOURCE, CleanUpOptions.FALSE); options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_4_RUNWITH, CleanUpOptions.FALSE); + + options.setOption(MYCleanUpConstants.JUNIT3_CLEANUP, CleanUpOptions.FALSE); + options.setOption(MYCleanUpConstants.JUNIT_CLEANUP_3_TEST, CleanUpOptions.FALSE); } } diff --git a/sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnit3CleanupCases.java b/sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnit3CleanupCases.java index a472ac4..28ca176 100644 --- a/sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnit3CleanupCases.java +++ b/sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnit3CleanupCases.java @@ -74,8 +74,8 @@ public void testArrayAssertions() { } public void testWithAssume() { - assumeTrue("Precondition failed", true); - assumeFalse("Precondition not met", false); +// assumeTrue("Precondition failed", true); +// assumeFalse("Precondition not met", false); } public void testAssertThat() { diff --git a/sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnitMigrationCleanUpTest.java b/sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnitMigrationCleanUpTest.java index ff0df05..d267b46 100644 --- a/sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnitMigrationCleanUpTest.java +++ b/sandbox_junit_cleanup_test/src/org/eclipse/jdt/ui/tests/quickfix/Java8/JUnitMigrationCleanUpTest.java @@ -51,17 +51,22 @@ public class JUnitMigrationCleanUpTest { + @RegisterExtension + AbstractEclipseJava context4junit3= new EclipseJava17(); + @RegisterExtension AbstractEclipseJava context4junit4= new EclipseJava17(); @RegisterExtension AbstractEclipseJava context4junit5= new EclipseJava17(); + IPackageFragmentRoot fRootJUnit3; IPackageFragmentRoot fRootJUnit4; IPackageFragmentRoot fRootJUnit5; @BeforeEach public void setup() throws CoreException { + fRootJUnit3= context4junit3.createClasspathForJUnit(JUnitCore.JUNIT3_CONTAINER_PATH); fRootJUnit4= context4junit4.createClasspathForJUnit(JUnitCore.JUNIT4_CONTAINER_PATH); fRootJUnit5= context4junit5.createClasspathForJUnit(JUnitCore.JUNIT5_CONTAINER_PATH); } @@ -93,24 +98,11 @@ public void testJUnitCleanupParametrized(JUnitCleanupCases test) throws CoreExce @ParameterizedTest @EnumSource(JUnit3CleanupCases.class) public void testJUnit3CleanupParametrized(JUnit3CleanupCases test) throws CoreException { - IPackageFragment pack= fRootJUnit4.createPackageFragment("test", true, null); + IPackageFragment pack= fRootJUnit3.createPackageFragment("test", true, null); ICompilationUnit cu= pack.createCompilationUnit("MyTest.java", test.given, true, null); //$NON-NLS-1$ - context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP); - context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSERT); - context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSUME); - context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_SUITE); - context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORE); - context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTER); - context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORECLASS); - context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTERCLASS); - context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_IGNORE); - context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_TEST); - context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETEMPORARYFOLDER); - context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETESTNAME); - context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RULEEXTERNALRESOURCE); -// context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_EXTERNALRESOURCE); - context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RUNWITH); - context4junit4.assertRefactoringResultAsExpected(new ICompilationUnit[] {cu}, new String[] {test.expected}, null); + context4junit3.enable(MYCleanUpConstants.JUNIT3_CLEANUP); + context4junit3.enable(MYCleanUpConstants.JUNIT_CLEANUP_3_TEST); + context4junit3.assertRefactoringResultAsExpected(new ICompilationUnit[] {cu}, new String[] {test.expected}, null); } enum NOJUnitCleanupCases { From 178d6d1b4aa5f8cd05d7b2448168f88170688763 Mon Sep 17 00:00:00 2001 From: Carsten Hammer Date: Sat, 18 Jan 2025 10:39:21 +0100 Subject: [PATCH 3/3] Checks for Java 8 have been removed from jdt --- .../jdt/internal/ui/fix/UseFunctionalCallCleanUpCore.java | 5 +++-- .../org/sandbox/jdt/internal/ui/fix/JFaceCleanUpCore.java | 4 ++-- .../org/sandbox/jdt/internal/ui/fix/JUnitCleanUpCore.java | 7 ++++--- .../internal/ui/fix/UseIteratorToForLoopCleanUpCore.java | 4 ++-- .../org/sandbox/jdt/internal/ui/fix/XMLCleanUpCore.java | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/sandbox_functional_converter/src/org/sandbox/jdt/internal/ui/fix/UseFunctionalCallCleanUpCore.java b/sandbox_functional_converter/src/org/sandbox/jdt/internal/ui/fix/UseFunctionalCallCleanUpCore.java index bd50fba..cecb6f0 100644 --- a/sandbox_functional_converter/src/org/sandbox/jdt/internal/ui/fix/UseFunctionalCallCleanUpCore.java +++ b/sandbox_functional_converter/src/org/sandbox/jdt/internal/ui/fix/UseFunctionalCallCleanUpCore.java @@ -31,7 +31,6 @@ import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore; import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; -import org.eclipse.jdt.internal.corext.util.JavaModelUtil; import org.eclipse.jdt.internal.corext.util.Messages; import org.eclipse.jdt.internal.ui.fix.AbstractCleanUp; import org.eclipse.jdt.ui.cleanup.CleanUpContext; @@ -63,7 +62,9 @@ public ICleanUpFix createFix(final CleanUpContext context) throws CoreException return null; } EnumSet computeFixSet = computeFixSet(); - if (!isEnabled(USEFUNCTIONALLOOP_CLEANUP) || computeFixSet.isEmpty() || !JavaModelUtil.is1d8OrHigher(compilationUnit.getJavaElement().getJavaProject())) { + if (!isEnabled(USEFUNCTIONALLOOP_CLEANUP) || computeFixSet.isEmpty() +// || !JavaModelUtil.is1d8OrHigher(compilationUnit.getJavaElement().getJavaProject()) + ) { return null; } Set operations = new LinkedHashSet<>(); diff --git a/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/ui/fix/JFaceCleanUpCore.java b/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/ui/fix/JFaceCleanUpCore.java index 2ec9166..3f535e5 100644 --- a/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/ui/fix/JFaceCleanUpCore.java +++ b/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/ui/fix/JFaceCleanUpCore.java @@ -31,7 +31,6 @@ import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore; import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; -import org.eclipse.jdt.internal.corext.util.JavaModelUtil; import org.eclipse.jdt.internal.corext.util.Messages; import org.eclipse.jdt.internal.ui.fix.AbstractCleanUp; import org.eclipse.jdt.ui.cleanup.CleanUpContext; @@ -66,7 +65,8 @@ public ICleanUpFix createFix(final CleanUpContext context) throws CoreException } EnumSet computeFixSet= computeFixSet(); if (!isEnabled(JFACE_CLEANUP) || computeFixSet.isEmpty() - || !JavaModelUtil.is1d8OrHigher(compilationUnit.getJavaElement().getJavaProject())) { +// || !JavaModelUtil.is1d8OrHigher(compilationUnit.getJavaElement().getJavaProject()) + ) { return null; } Set operations= new LinkedHashSet<>(); diff --git a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/JUnitCleanUpCore.java b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/JUnitCleanUpCore.java index a238412..8a6fe0a 100644 --- a/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/JUnitCleanUpCore.java +++ b/sandbox_junit_cleanup/src/org/sandbox/jdt/internal/ui/fix/JUnitCleanUpCore.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.sandbox.jdt.internal.ui.fix; +import static org.sandbox.jdt.internal.corext.fix2.MYCleanUpConstants.JUNIT3_CLEANUP; + /*- * #%L * Sandbox junit cleanup @@ -34,7 +36,6 @@ */ import static org.sandbox.jdt.internal.corext.fix2.MYCleanUpConstants.JUNIT_CLEANUP; -import static org.sandbox.jdt.internal.corext.fix2.MYCleanUpConstants.JUNIT3_CLEANUP; import static org.sandbox.jdt.internal.ui.fix.MultiFixMessages.JUnitCleanUpFix_refactor; import static org.sandbox.jdt.internal.ui.fix.MultiFixMessages.JUnitCleanUp_description; @@ -51,7 +52,6 @@ import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore; import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; -import org.eclipse.jdt.internal.corext.util.JavaModelUtil; import org.eclipse.jdt.internal.corext.util.Messages; import org.eclipse.jdt.internal.ui.fix.AbstractCleanUp; import org.eclipse.jdt.ui.cleanup.CleanUpContext; @@ -88,7 +88,8 @@ public ICleanUpFix createFix(final CleanUpContext context) throws CoreException } EnumSet computeFixSet= computeFixSet(); if (!(isEnabled(JUNIT_CLEANUP)||isEnabled(JUNIT3_CLEANUP)) || computeFixSet.isEmpty() - || !JavaModelUtil.is1d8OrHigher(compilationUnit.getJavaElement().getJavaProject())) { +// || !JavaModelUtil.is1d8OrHigher(compilationUnit.getJavaElement().getJavaProject()) + ) { return null; } Set operations= new LinkedHashSet<>(); diff --git a/sandbox_tools/src/org/sandbox/jdt/internal/ui/fix/UseIteratorToForLoopCleanUpCore.java b/sandbox_tools/src/org/sandbox/jdt/internal/ui/fix/UseIteratorToForLoopCleanUpCore.java index 26c63df..cee48be 100644 --- a/sandbox_tools/src/org/sandbox/jdt/internal/ui/fix/UseIteratorToForLoopCleanUpCore.java +++ b/sandbox_tools/src/org/sandbox/jdt/internal/ui/fix/UseIteratorToForLoopCleanUpCore.java @@ -32,7 +32,6 @@ import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore; import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; -import org.eclipse.jdt.internal.corext.util.JavaModelUtil; import org.eclipse.jdt.internal.corext.util.Messages; import org.eclipse.jdt.internal.ui.fix.AbstractCleanUp; import org.eclipse.jdt.ui.cleanup.CleanUpContext; @@ -65,7 +64,8 @@ public ICleanUpFix createFix(final CleanUpContext context) throws CoreException } EnumSet computeFixSet= computeFixSet(); if (!isEnabled(CONTROL_STATEMENTS_CONVERT_FOR_LOOP_TO_ENHANCED) || computeFixSet.isEmpty() - || !JavaModelUtil.is1d8OrHigher(compilationUnit.getJavaElement().getJavaProject())) { +// || !JavaModelUtil.is1d8OrHigher(compilationUnit.getJavaElement().getJavaProject()) + ) { return null; } Set operations= new LinkedHashSet<>(); diff --git a/sandbox_xml_cleanup/src/org/sandbox/jdt/internal/ui/fix/XMLCleanUpCore.java b/sandbox_xml_cleanup/src/org/sandbox/jdt/internal/ui/fix/XMLCleanUpCore.java index e2c1f8a..9384b98 100644 --- a/sandbox_xml_cleanup/src/org/sandbox/jdt/internal/ui/fix/XMLCleanUpCore.java +++ b/sandbox_xml_cleanup/src/org/sandbox/jdt/internal/ui/fix/XMLCleanUpCore.java @@ -31,7 +31,6 @@ import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore; import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; -import org.eclipse.jdt.internal.corext.util.JavaModelUtil; import org.eclipse.jdt.internal.corext.util.Messages; import org.eclipse.jdt.internal.ui.fix.AbstractCleanUp; import org.eclipse.jdt.ui.cleanup.CleanUpContext; @@ -66,7 +65,8 @@ public ICleanUpFix createFix(final CleanUpContext context) throws CoreException } EnumSet computeFixSet= computeFixSet(); if (!isEnabled(XML_CLEANUP) || computeFixSet.isEmpty() - || !JavaModelUtil.is1d8OrHigher(compilationUnit.getJavaElement().getJavaProject())) { +// || !JavaModelUtil.is1d8OrHigher(compilationUnit.getJavaElement().getJavaProject()) + ) { return null; } Set operations= new LinkedHashSet<>();