Bug 568009 - Rollback
Change-Id: I5bb25c1c1fbb9c19890bc1d9fd6308a63126119d
Signed-off-by: Fabrice Tiercelin <fabrice.tiercelin@yahoo.fr>
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.java
index 687fefd..21def18 100644
--- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.java
+++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.java
@@ -68,9 +68,6 @@
public static String CodeStyleMultiFix_ConvertSingleStatementInControlBodyToBlock_description;
public static String CodeStyleCleanUp_addDefaultSerialVersionId_description;
- public static String CodeStyleCleanUp_AtomicObject_description;
- public static String CodeStyleCleanUp_AtomicObject_declaration;
- public static String CodeStyleCleanUp_AtomicObject_usage;
public static String CodeStyleCleanUp_PullUpAssignment_description;
public static String CodeStyleCleanUp_ElseIf_description;
public static String CodeStyleCleanUp_numberSuffix_description;
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.properties b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.properties
index ffa52c2..e937936 100644
--- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.properties
+++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.properties
@@ -32,9 +32,6 @@
CodeStyleMultiFix_ChangeIndirectAccessToStaticToDirect=Change indirect accesses to static members to direct accesses (accesses through subtypes)
CodeStyleCleanUp_addDefaultSerialVersionId_description=Add missing serial version ID (default 1L)
-CodeStyleCleanUp_AtomicObject_description=Use atomic objects as reference
-CodeStyleCleanUp_AtomicObject_declaration=Use atomic objects declaration
-CodeStyleCleanUp_AtomicObject_usage=Use atomic objects usage
CodeStyleCleanUp_PullUpAssignment_description=Pull up assignment
CodeStyleCleanUp_ElseIf_description=Combine nested 'if' statement in 'else' block to 'else if'
CodeStyleCleanUp_numberSuffix_description=Use uppercase for long literal suffix
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstants.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstants.java
index d4f221a..466868a 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstants.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstants.java
@@ -1617,18 +1617,6 @@
public static final String ADD_MISSING_SERIAL_VERSION_ID_DEFAULT= "cleanup.add_default_serial_version_id"; //$NON-NLS-1$
/**
- * Replace an array with one index by an atomic object.
- * <p>
- * Possible values: {TRUE, FALSE}
- * <p>
- *
- * @see CleanUpOptionsCore#TRUE
- * @see CleanUpOptionsCore#FALSE
- * @since 4.18
- */
- public static final String ATOMIC_OBJECT= "cleanup.atomic_object"; //$NON-NLS-1$
-
- /**
* Moves assignments inside an if condition above the if node.
* <p>
* Possible values: {TRUE, FALSE}
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest1d8.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest1d8.java
index 2f88e96..07dff2a 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest1d8.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest1d8.java
@@ -59,385 +59,6 @@
}
@Test
- public void testUseAtomicObject() throws Exception {
- IPackageFragment pack= fSourceFolder.createPackageFragment("test1", false, null);
- String input= "" //
- + "package test1;\n" //
- + "\n" //
- + "import java.util.Date;\n" //
- + "import java.util.function.Supplier;\n" //
- + "\n" //
- + "public class E {\n" //
- + " public static boolean useAtomicBoolean() {\n" //
- + " // Keep this comment\n" //
- + " boolean[] booleanRef= new boolean[1];\n" //
- + " // Keep this comment also\n" //
- + " Runnable runnable = () -> booleanRef[0] = true;\n" //
- + " runnable.run();\n" //
- + " // Keep this comment too\n" //
- + " return booleanRef[0];\n" //
- + " }\n" //
- + "\n" //
- + " public static int useAtomicInteger() {\n" //
- + " // Keep this comment\n" //
- + " int[] intRef= new int[1];\n" //
- + " // Keep this comment also\n" //
- + " Runnable runnable = () -> intRef[0] = 42;\n" //
- + " runnable.run();\n" //
- + " // Keep this comment too\n" //
- + " return intRef[0];\n" //
- + " }\n" //
- + "\n" //
- + " public static long useAtomicLong() {\n" //
- + " // Keep this comment\n" //
- + " long[] longRef= new long[1];\n" //
- + " // Keep this comment also\n" //
- + " Runnable runnable = () -> longRef[0] = 42;\n" //
- + " runnable.run();\n" //
- + " // Keep this comment too\n" //
- + " return longRef[0];\n" //
- + " }\n" //
- + "\n" //
- + " public static Date useAtomicReference() {\n" //
- + " // Keep this comment\n" //
- + " Date[] dateRef= new Date[1];\n" //
- + " // Keep this comment also\n" //
- + " Runnable runnable = () -> dateRef[0] = new Date();\n" //
- + " runnable.run();\n" //
- + " // Keep this comment too\n" //
- + " return dateRef[0];\n" //
- + " }\n" //
- + "\n" //
- + " public static Long useAtomicLongObject() {\n" //
- + " // Keep this comment\n" //
- + " Long[] longRef = new Long[1];\n" //
- + " // Keep this comment also\n" //
- + " Runnable runnable = () -> longRef[0] = Long.valueOf(0);\n" //
- + " runnable.run();\n" //
- + " // Keep this comment too\n" //
- + " return longRef[0];\n" //
- + " }\n" //
- + "\n" //
- + " public static boolean useInitializedAtomicBoolean() {\n" //
- + " // Keep this comment\n" //
- + " boolean[] booleanRef= new boolean[] {true};\n" //
- + " // Keep this comment also\n" //
- + " Runnable runnable = () -> booleanRef[0] = true;\n" //
- + " runnable.run();\n" //
- + " // Keep this comment too\n" //
- + " return booleanRef[0];\n" //
- + " }\n" //
- + "\n" //
- + " public static String useNonInitializedAtomicString() {\n" //
- + " // Keep this comment\n" //
- + " String[] stringRef= new String[] {null};\n" //
- + " // Keep this comment also\n" //
- + " Runnable runnable = () -> stringRef[0] = \"foo\";\n" //
- + " runnable.run();\n" //
- + " // Keep this comment too\n" //
- + " return stringRef[0];\n" //
- + " }\n" //
- + "\n" //
- + " public static Date useAtomicReferenceInAnonymousClass() {\n" //
- + " // Keep this comment\n" //
- + " Date[] dateRef= new Date[1];\n" //
- + " // Keep this comment also\n" //
- + " Runnable runnable = new Runnable() {\n" //
- + " @Override\n" //
- + " public void run() {\n" //
- + " dateRef[0] = new Date();\n" //
- + " }\n" //
- + " };\n" //
- + " runnable.run();\n" //
- + " // Keep this comment too\n" //
- + " return dateRef[0];\n" //
- + " }\n" //
- + "\n" //
- + " public static Date useAtomicReferenceOnExtraDimension() {\n" //
- + " // Keep this comment\n" //
- + " Date dateRef[]= new Date[1];\n" //
- + " // Keep this comment also\n" //
- + " Runnable runnable = () -> dateRef[0] = new Date();\n" //
- + " runnable.run();\n" //
- + " // Keep this comment too\n" //
- + " return dateRef[0];\n" //
- + " }\n" //
- + "}\n";
- ICompilationUnit cu= pack.createCompilationUnit("E.java", input, false, null);
-
- enable(CleanUpConstants.ATOMIC_OBJECT);
-
- String output= "" //
- + "package test1;\n" //
- + "\n" //
- + "import java.util.Date;\n" //
- + "import java.util.concurrent.atomic.AtomicBoolean;\n" //
- + "import java.util.concurrent.atomic.AtomicInteger;\n" //
- + "import java.util.concurrent.atomic.AtomicLong;\n" //
- + "import java.util.concurrent.atomic.AtomicReference;\n" //
- + "import java.util.function.Supplier;\n" //
- + "\n" //
- + "public class E {\n" //
- + " public static boolean useAtomicBoolean() {\n" //
- + " // Keep this comment\n" //
- + " AtomicBoolean booleanRef= new AtomicBoolean();\n" //
- + " // Keep this comment also\n" //
- + " Runnable runnable = () -> booleanRef.set(true);\n" //
- + " runnable.run();\n" //
- + " // Keep this comment too\n" //
- + " return booleanRef.get();\n" //
- + " }\n" //
- + "\n" //
- + " public static int useAtomicInteger() {\n" //
- + " // Keep this comment\n" //
- + " AtomicInteger intRef= new AtomicInteger();\n" //
- + " // Keep this comment also\n" //
- + " Runnable runnable = () -> intRef.set(42);\n" //
- + " runnable.run();\n" //
- + " // Keep this comment too\n" //
- + " return intRef.get();\n" //
- + " }\n" //
- + "\n" //
- + " public static long useAtomicLong() {\n" //
- + " // Keep this comment\n" //
- + " AtomicLong longRef= new AtomicLong();\n" //
- + " // Keep this comment also\n" //
- + " Runnable runnable = () -> longRef.set(42);\n" //
- + " runnable.run();\n" //
- + " // Keep this comment too\n" //
- + " return longRef.get();\n" //
- + " }\n" //
- + "\n" //
- + " public static Date useAtomicReference() {\n" //
- + " // Keep this comment\n" //
- + " AtomicReference<Date> dateRef= new AtomicReference<>();\n" //
- + " // Keep this comment also\n" //
- + " Runnable runnable = () -> dateRef.set(new Date());\n" //
- + " runnable.run();\n" //
- + " // Keep this comment too\n" //
- + " return dateRef.get();\n" //
- + " }\n" //
- + "\n" //
- + " public static Long useAtomicLongObject() {\n" //
- + " // Keep this comment\n" //
- + " AtomicReference<Long> longRef = new AtomicReference<>();\n" //
- + " // Keep this comment also\n" //
- + " Runnable runnable = () -> longRef.set(Long.valueOf(0));\n" //
- + " runnable.run();\n" //
- + " // Keep this comment too\n" //
- + " return longRef.get();\n" //
- + " }\n" //
- + "\n" //
- + " public static boolean useInitializedAtomicBoolean() {\n" //
- + " // Keep this comment\n" //
- + " AtomicBoolean booleanRef= new AtomicBoolean(true);\n" //
- + " // Keep this comment also\n" //
- + " Runnable runnable = () -> booleanRef.set(true);\n" //
- + " runnable.run();\n" //
- + " // Keep this comment too\n" //
- + " return booleanRef.get();\n" //
- + " }\n" //
- + "\n" //
- + " public static String useNonInitializedAtomicString() {\n" //
- + " // Keep this comment\n" //
- + " AtomicReference<String> stringRef= new AtomicReference<>();\n" //
- + " // Keep this comment also\n" //
- + " Runnable runnable = () -> stringRef.set(\"foo\");\n" //
- + " runnable.run();\n" //
- + " // Keep this comment too\n" //
- + " return stringRef.get();\n" //
- + " }\n" //
- + "\n" //
- + " public static Date useAtomicReferenceInAnonymousClass() {\n" //
- + " // Keep this comment\n" //
- + " AtomicReference<Date> dateRef= new AtomicReference<>();\n" //
- + " // Keep this comment also\n" //
- + " Runnable runnable = new Runnable() {\n" //
- + " @Override\n" //
- + " public void run() {\n" //
- + " dateRef.set(new Date());\n" //
- + " }\n" //
- + " };\n" //
- + " runnable.run();\n" //
- + " // Keep this comment too\n" //
- + " return dateRef.get();\n" //
- + " }\n" //
- + "\n" //
- + " public static Date useAtomicReferenceOnExtraDimension() {\n" //
- + " // Keep this comment\n" //
- + " AtomicReference<Date> dateRef= new AtomicReference<>();\n" //
- + " // Keep this comment also\n" //
- + " Runnable runnable = () -> dateRef.set(new Date());\n" //
- + " runnable.run();\n" //
- + " // Keep this comment too\n" //
- + " return dateRef.get();\n" //
- + " }\n" //
- + "}\n";
-
- assertGroupCategoryUsed(new ICompilationUnit[] { cu }, new HashSet<>(Arrays.asList(
- MultiFixMessages.CodeStyleCleanUp_AtomicObject_usage+" "+2,
- MultiFixMessages.CodeStyleCleanUp_AtomicObject_usage+" "+1,
- MultiFixMessages.CodeStyleCleanUp_AtomicObject_declaration)));
- assertRefactoringResultAsExpected(new ICompilationUnit[] { cu }, new String[] { output });
- }
-
- @Test
- public void testDoNotUseAtomicObject() throws Exception {
- IPackageFragment pack= fSourceFolder.createPackageFragment("test1", false, null);
- String sample= "" //
- + "package test1;\n" //
- + "\n" //
- + "import java.util.Date;\n" //
- + "import java.util.function.Supplier;\n" //
- + "\n" //
- + "public class E {\n" //
- + " public static int doNotRefactorIncrementalAssignment() {\n" //
- + " int[] intRef= new int[1];\n" //
- + " Runnable runnable = () -> intRef[0] += 42;\n" //
- + " runnable.run();\n" //
- + " return intRef[0];\n" //
- + " }\n" //
- + "\n" //
- + " public static int doNotRefactorDecrementalAssignment() {\n" //
- + " int[] numberRef= new int[1];\n" //
- + " Runnable runnable = () -> numberRef[0] -= 42;\n" //
- + " runnable.run();\n" //
- + " return numberRef[0];\n" //
- + " }\n" //
- + "\n" //
- + " public static short doNotRefactorShortArray() {\n" //
- + " short[] shortRef= new short[1];\n" //
- + " Runnable runnable = () -> shortRef[0] = 42;\n" //
- + " runnable.run();\n" //
- + " return shortRef[0];\n" //
- + " }\n" //
- + "\n" //
- + " public static void doNotRefactorVoidArray() {\n" //
- + " Date[] dateRef= new Date[] {};\n" //
- + " Runnable runnable = () -> {\n" //
- + " dateRef[0] = new Date();\n" //
- + " };\n" //
- + " System.out.println(dateRef[0]);\n" //
- + " }\n" //
- + "\n" //
- + " public static void doNotRefactorBadlyInitializedArray() {\n" //
- + " Date[] dateReference= new Date[] {new Date(), new Date()};\n" //
- + " Runnable runnable = () -> {\n" //
- + " dateReference[0] = new Date();\n" //
- + " };\n" //
- + " System.out.println(dateReference[0]);\n" //
- + " }\n" //
- + "\n" //
- + " public static Date doNotTouchUnknownPurpose() {\n" //
- + " Date[] dateRef= new Date[1];\n" //
- + " dateRef[0] = new Date();\n" //
- + " return dateRef[0];\n" //
- + " }\n" //
- + "\n" //
- + " public static void doNotTouchUnknownPurposeInLambda() {\n" //
- + " Runnable runnable = () -> {\n" //
- + " Date[] dateRef= new Date[1];\n" //
- + " dateRef[0] = new Date();\n" //
- + " System.out.println(dateRef[0]);\n" //
- + " };\n" //
- + " }\n" //
- + "\n" //
- + " public static Date doNotRefactorGreatArray() {\n" //
- + " Date[] dateRef= new Date[2];\n" //
- + " Runnable runnable = () -> dateRef[0] = new Date();\n" //
- + " runnable.run();\n" //
- + " return dateRef[0];\n" //
- + " }\n" //
- + "\n" //
- + " public static Date doNotRefactorEmptyArray() {\n" //
- + " Date[] dateRef= new Date[0];\n" //
- + " Runnable runnable = () -> dateRef[0] = new Date();\n" //
- + " runnable.run();\n" //
- + " return dateRef[0];\n" //
- + " }\n" //
- + "\n" //
- + " public static Date doNotRefactorWrongIndex() {\n" //
- + " Date[] dateRef= new Date[1];\n" //
- + " Runnable runnable = () -> dateRef[1] = new Date();\n" //
- + " runnable.run();\n" //
- + " return dateRef[0];\n" //
- + " }\n" //
- + "\n" //
- + " public static Date doNotRefactorAnotherWrongIndex() {\n" //
- + " Date[] dateRef= new Date[1];\n" //
- + " Runnable runnable = () -> dateRef[0] = new Date();\n" //
- + " runnable.run();\n" //
- + " return dateRef[1];\n" //
- + " }\n" //
- + "\n" //
- + " public static Date doNotRefactorSeveralDimensionArray() {\n" //
- + " Date[][] dateRef= new Date[1][1];\n" //
- + " Runnable runnable = () -> dateRef[0][0] = new Date();\n" //
- + " runnable.run();\n" //
- + " return dateRef[0][0];\n" //
- + " }\n" //
- + "\n" //
- + " public static Date[][] doNotRefactorSeveralDeclarations() {\n" //
- + " Date[][] dateRef= new Date[1][1], iAmHereToo= null;\n" //
- + " Runnable runnable = () -> dateRef[0][0] = new Date();\n" //
- + " runnable.run();\n" //
- + " System.out.println(dateRef[0]);\n" //
- + " return iAmHereToo;\n" //
- + " }\n" //
- + "\n" //
- + " public static void doNotRefactorReturnedAssignment() {\n" //
- + " Date[][] dateRef= new Date[1][1];\n" //
- + " Supplier<Date> supplier = () -> dateRef[0][0] = new Date();\n" //
- + " supplier.get();\n" //
- + " System.out.println(dateRef[0]);\n" //
- + " }\n" //
- + "\n" //
- + " public static void doNotRefactorReadAssignment() {\n" //
- + " Date[][] dateRef= new Date[1][1];\n" //
- + " Runnable runnable = () -> {\n" //
- + " if ((dateRef[0][0] = new Date()) != null)\n" //
- + " System.out.println(\"Filled\");\n" //
- + " };\n" //
- + " runnable.run();\n" //
- + " System.out.println(dateRef[0]);\n" //
- + " }\n" //
- + "\n" //
- + " public static int doNotRefactorIncrementalRead() {\n" //
- + " int[] intRef= new int[1];\n" //
- + " Runnable runnable = () -> intRef[0] = 42;\n" //
- + " runnable.run();\n" //
- + " return intRef[0]++;\n" //
- + " }\n" //
- + "\n" //
- + " public static int doNotRefactorDecrementalRead() {\n" //
- + " int[] intRef= new int[1];\n" //
- + " Runnable runnable = () -> intRef[0] = 42;\n" //
- + " runnable.run();\n" //
- + " return intRef[0]--;\n" //
- + " }\n" //
- + "\n" //
- + " public static int doNotRefactorPreincrementalRead() {\n" //
- + " int[] intRef= new int[1];\n" //
- + " Runnable runnable = () -> intRef[0] = 42;\n" //
- + " runnable.run();\n" //
- + " return ++intRef[0];\n" //
- + " }\n" //
- + "\n" //
- + " public static int doNotRefactorPredecrementalRead() {\n" //
- + " int[] intRef= new int[1];\n" //
- + " Runnable runnable = () -> intRef[0] = 42;\n" //
- + " runnable.run();\n" //
- + " return --intRef[0];\n" //
- + " }\n" //
- + "}\n";
- ICompilationUnit cu= pack.createCompilationUnit("E.java", sample, false, null);
-
- enable(CleanUpConstants.ATOMIC_OBJECT);
-
- assertRefactoringHasNoChange(new ICompilationUnit[] { cu });
- }
-
- @Test
public void testConvertToLambda01() throws Exception {
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
String sample= "" //
diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstantsOptions.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstantsOptions.java
index 63b3900..35f5914 100644
--- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstantsOptions.java
+++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstantsOptions.java
@@ -61,7 +61,6 @@
options.setOption(EXPRESSIONS_USE_PARENTHESES_NEVER, CleanUpOptions.TRUE);
options.setOption(EXPRESSIONS_USE_PARENTHESES_ALWAYS, CleanUpOptions.FALSE);
options.setOption(CHECK_SIGN_OF_BITWISE_OPERATION, CleanUpOptions.FALSE);
- options.setOption(ATOMIC_OBJECT, CleanUpOptions.FALSE);
options.setOption(PULL_UP_ASSIGNMENT, CleanUpOptions.FALSE);
options.setOption(ELSE_IF, CleanUpOptions.FALSE);
@@ -202,7 +201,6 @@
options.setOption(EXPRESSIONS_USE_PARENTHESES_NEVER, CleanUpOptions.TRUE);
options.setOption(EXPRESSIONS_USE_PARENTHESES_ALWAYS, CleanUpOptions.FALSE);
options.setOption(CHECK_SIGN_OF_BITWISE_OPERATION, CleanUpOptions.FALSE);
- options.setOption(ATOMIC_OBJECT, CleanUpOptions.FALSE);
options.setOption(PULL_UP_ASSIGNMENT, CleanUpOptions.FALSE);
options.setOption(ELSE_IF, CleanUpOptions.FALSE);
diff --git a/org.eclipse.jdt.ui/plugin.xml b/org.eclipse.jdt.ui/plugin.xml
index a778c7d..24c0632 100644
--- a/org.eclipse.jdt.ui/plugin.xml
+++ b/org.eclipse.jdt.ui/plugin.xml
@@ -7097,14 +7097,9 @@
runAfter="org.eclipse.jdt.ui.cleanup.lambda_and_method_ref">
</cleanUp>
<cleanUp
- class="org.eclipse.jdt.internal.ui.fix.AtomicObjectCleanUp"
- id="org.eclipse.jdt.ui.cleanup.atomic_object"
- runAfter="org.eclipse.jdt.ui.cleanup.bitwise_conditional_expression">
- </cleanUp>
- <cleanUp
class="org.eclipse.jdt.internal.ui.fix.PullUpAssignmentCleanUp"
id="org.eclipse.jdt.ui.cleanup.pull_up_assignment"
- runAfter="org.eclipse.jdt.ui.cleanup.atomic_object">
+ runAfter="org.eclipse.jdt.ui.cleanup.bitwise_conditional_expression">
</cleanUp>
<cleanUp
class="org.eclipse.jdt.internal.ui.fix.NumberSuffixCleanUp"
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/AtomicObjectCleanUp.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/AtomicObjectCleanUp.java
deleted file mode 100644
index abd8190..0000000
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/AtomicObjectCleanUp.java
+++ /dev/null
@@ -1,375 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2020 Fabrice TIERCELIN and others.
- *
- * 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:
- * Fabrice TIERCELIN - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jdt.internal.ui.fix;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.eclipse.core.runtime.CoreException;
-
-import org.eclipse.text.edits.TextEditGroup;
-
-import org.eclipse.jdt.core.ICompilationUnit;
-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.AnonymousClassDeclaration;
-import org.eclipse.jdt.core.dom.ArrayAccess;
-import org.eclipse.jdt.core.dom.ArrayCreation;
-import org.eclipse.jdt.core.dom.Assignment;
-import org.eclipse.jdt.core.dom.Block;
-import org.eclipse.jdt.core.dom.ClassInstanceCreation;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.Expression;
-import org.eclipse.jdt.core.dom.ExpressionStatement;
-import org.eclipse.jdt.core.dom.ITypeBinding;
-import org.eclipse.jdt.core.dom.IVariableBinding;
-import org.eclipse.jdt.core.dom.LambdaExpression;
-import org.eclipse.jdt.core.dom.MethodInvocation;
-import org.eclipse.jdt.core.dom.NullLiteral;
-import org.eclipse.jdt.core.dom.ParameterizedType;
-import org.eclipse.jdt.core.dom.PostfixExpression;
-import org.eclipse.jdt.core.dom.PrefixExpression;
-import org.eclipse.jdt.core.dom.SimpleName;
-import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
-import org.eclipse.jdt.core.dom.Type;
-import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
-import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
-import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
-import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
-import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
-
-import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory;
-import org.eclipse.jdt.internal.corext.dom.ASTNodes;
-import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
-import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFix;
-import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFix.CompilationUnitRewriteOperation;
-import org.eclipse.jdt.internal.corext.fix.LinkedProposalModel;
-import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
-import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
-
-import org.eclipse.jdt.ui.cleanup.CleanUpRequirements;
-import org.eclipse.jdt.ui.cleanup.ICleanUpFix;
-import org.eclipse.jdt.ui.text.java.IProblemLocation;
-
-/**
- * A fix that replaces an array with one index by an atomic object.
- */
-public class AtomicObjectCleanUp extends AbstractMultiFix {
- public AtomicObjectCleanUp() {
- this(Collections.emptyMap());
- }
-
- public AtomicObjectCleanUp(Map<String, String> options) {
- super(options);
- }
-
- @Override
- public CleanUpRequirements getRequirements() {
- boolean requireAST= isEnabled(CleanUpConstants.ATOMIC_OBJECT);
- return new CleanUpRequirements(requireAST, false, false, null);
- }
-
- @Override
- public String[] getStepDescriptions() {
- if (isEnabled(CleanUpConstants.ATOMIC_OBJECT)) {
- return new String[] { MultiFixMessages.CodeStyleCleanUp_AtomicObject_description };
- }
-
- return new String[0];
- }
-
- @Override
- public String getPreview() {
- if (isEnabled(CleanUpConstants.ATOMIC_OBJECT)) {
- return "AtomicBoolean booleanRef= new AtomicBoolean();\n" //$NON-NLS-1$
- + "Runnable runnable = () -> booleanRef.set(true);\n" //$NON-NLS-1$
- + "runnable.run();\n" //$NON-NLS-1$
- + "boolean b = booleanRef.get();\n"; //$NON-NLS-1$
- }
-
- return "boolean[] booleanRef= new boolean[1];\n" //$NON-NLS-1$
- + "Runnable runnable = () -> booleanRef[0] = true;\n" //$NON-NLS-1$
- + "runnable.run();\n" //$NON-NLS-1$
- + "boolean b = booleanRef[0];\n"; //$NON-NLS-1$
- }
-
- @Override
- protected ICleanUpFix createFix(CompilationUnit unit) throws CoreException {
- if (!isEnabled(CleanUpConstants.ATOMIC_OBJECT) || !JavaModelUtil.is50OrHigher(unit.getJavaElement().getJavaProject())) {
- return null;
- }
-
- final List<CompilationUnitRewriteOperation> rewriteOperations= new ArrayList<>();
-
- unit.accept(new ASTVisitor() {
- @Override
- public boolean visit(final Block node) {
- ArrayOccurrencesVisitor arrayOccurrencesVisitor= new ArrayOccurrencesVisitor(node);
- node.accept(arrayOccurrencesVisitor);
- return arrayOccurrencesVisitor.result;
- }
-
- final class ArrayOccurrencesVisitor extends ASTVisitor {
- private final Block startNode;
- private boolean result= true;
-
- public ArrayOccurrencesVisitor(final Block startNode) {
- this.startNode= startNode;
- }
-
- @Override
- public boolean visit(final Block node) {
- return startNode == node;
- }
-
- @Override
- public boolean visit(final VariableDeclarationStatement node) {
- if (node.fragments().size() != 1) {
- return true;
- }
-
- VariableDeclarationFragment fragment= (VariableDeclarationFragment) node.fragments().get(0);
- return visitVariable(node.getType(), fragment.resolveBinding(), fragment.extraDimensions(), fragment.getName(), fragment.getInitializer());
- }
-
- @Override
- public boolean visit(final VariableDeclarationExpression node) {
- if (node.fragments().size() != 1) {
- return true;
- }
-
- VariableDeclarationFragment fragment= (VariableDeclarationFragment) node.fragments().get(0);
- return visitVariable(node.getType(), fragment.resolveBinding(), fragment.extraDimensions(), fragment.getName(), fragment.getInitializer());
- }
-
- @Override
- public boolean visit(final SingleVariableDeclaration node) {
- return visitVariable(node.getType(), node.resolveBinding(), node.extraDimensions(), node.getName(), node.getInitializer());
- }
-
- private boolean visitVariable(final Type type, final IVariableBinding variableBinding, final List<?> variableDimensions, final SimpleName declaration, final Expression initializer) {
- ArrayCreation arrayCreation= ASTNodes.as(initializer, ArrayCreation.class);
-
- if (result
- && arrayCreation != null
- && (arrayCreation.getInitializer() != null
- ? arrayCreation.getInitializer().expressions().size() == 1
- : arrayCreation.dimensions().size() == 1 && Long.valueOf(1L).equals(ASTNodes.getIntegerLiteral((Expression) arrayCreation.dimensions().get(0))))
- && type != null
- && type.resolveBinding() != null
- && (type.resolveBinding().isArray()
- ? variableDimensions.isEmpty() && type.resolveBinding().getDimensions() == 1 && equalNotNull(type.resolveBinding().getElementType(), arrayCreation.getType().getElementType().resolveBinding())
- : variableDimensions.size() == 1 && equalNotNull(type.resolveBinding(), arrayCreation.getType().getElementType().resolveBinding()))
- && !ASTNodes.hasType(arrayCreation.getType().getElementType().resolveBinding(),
- double.class.getCanonicalName(),
- float.class.getCanonicalName(),
- short.class.getCanonicalName(),
- char.class.getCanonicalName(),
- byte.class.getCanonicalName())) {
- VarDefinitionsUsesVisitor varOccurrencesVisitor= new VarDefinitionsUsesVisitor(variableBinding,
- startNode, true);
-
- List<SimpleName> reads= varOccurrencesVisitor.getReads();
- List<SimpleName> writes= varOccurrencesVisitor.getWrites();
- writes.remove(declaration);
-
- if (writes.isEmpty()) {
- Set<Assignment> assignmentReads= new HashSet<>();
- Set<ArrayAccess> accessReads= new HashSet<>();
-
- for (SimpleName simpleName : reads) {
- if (!isReadValid(simpleName, assignmentReads, accessReads)) {
- return true;
- }
- }
-
- boolean hasOneWriteInDynamicCode= false;
-
- for (Assignment assignmentRead : assignmentReads) {
- ASTNode dynamicCode= ASTNodes.getFirstAncestorOrNull(assignmentRead, LambdaExpression.class, AnonymousClassDeclaration.class);
-
- if (dynamicCode != null && ASTNodes.isParent(dynamicCode, startNode)) {
- hasOneWriteInDynamicCode= true;
- break;
- }
- }
-
- if (hasOneWriteInDynamicCode) {
- rewriteOperations.add(new AtomicObjectOperation(type, variableDimensions, arrayCreation, assignmentReads, accessReads));
-
- result= false;
- return false;
- }
- }
- }
-
- return true;
- }
-
- private boolean equalNotNull(ITypeBinding elementType, ITypeBinding resolveBinding) {
- return elementType != null && Objects.equals(elementType, resolveBinding);
- }
-
- private boolean isReadValid(final SimpleName simpleName, final Set<Assignment> assignmentReads, final Set<ArrayAccess> accessReads) {
- if (simpleName.getParent() instanceof ArrayAccess
- && simpleName.getLocationInParent() == ArrayAccess.ARRAY_PROPERTY) {
- ArrayAccess arrayAccess= (ArrayAccess) simpleName.getParent();
-
- if (Long.valueOf(0L).equals(ASTNodes.getIntegerLiteral(arrayAccess.getIndex()))) {
- if (arrayAccess.getParent() instanceof Assignment
- && arrayAccess.getLocationInParent() == Assignment.LEFT_HAND_SIDE_PROPERTY) {
- Assignment assignment= (Assignment) arrayAccess.getParent();
-
- if (ASTNodes.hasOperator(assignment, Assignment.Operator.ASSIGN)
- && (assignment.getParent() instanceof ExpressionStatement
- || assignment.getParent() instanceof LambdaExpression && assignment.getLocationInParent() == LambdaExpression.BODY_PROPERTY)) {
- assignmentReads.add(assignment);
- return true;
- }
- } else if ((!(arrayAccess.getParent() instanceof PrefixExpression)
- || !ASTNodes.hasOperator((PrefixExpression) arrayAccess.getParent(), PrefixExpression.Operator.INCREMENT, PrefixExpression.Operator.DECREMENT))
- && (!(arrayAccess.getParent() instanceof PostfixExpression)
- || !ASTNodes.hasOperator((PostfixExpression) arrayAccess.getParent(), PostfixExpression.Operator.INCREMENT, PostfixExpression.Operator.DECREMENT))) {
- accessReads.add(arrayAccess);
- return true;
- }
- }
- }
-
- return false;
- }
- }
- });
-
- if (rewriteOperations.isEmpty()) {
- return null;
- }
-
- return new CompilationUnitRewriteOperationsFix(MultiFixMessages.CodeStyleCleanUp_AtomicObject_description, unit,
- rewriteOperations.toArray(new CompilationUnitRewriteOperation[0]));
- }
-
- @Override
- public boolean canFix(final ICompilationUnit compilationUnit, final IProblemLocation problem) {
- return false;
- }
-
- @Override
- protected ICleanUpFix createFix(final CompilationUnit unit, final IProblemLocation[] problems) throws CoreException {
- return null;
- }
-
- private static class AtomicObjectOperation extends CompilationUnitRewriteOperation {
- private final Type type;
- private final List<?> variableDimensions;
- private final ArrayCreation arrayCreation;
- private final Set<Assignment> assignmentReads;
- private final Set<ArrayAccess> accessReads;
-
- public AtomicObjectOperation(final Type type, final List<?> variableDimensions, final ArrayCreation arrayCreation, final Set<Assignment> assignmentReads, final Set<ArrayAccess> accessReads) {
- this.type= type;
- this.variableDimensions= variableDimensions;
- this.arrayCreation= arrayCreation;
- this.assignmentReads= assignmentReads;
- this.accessReads= accessReads;
- }
-
- @Override
- public void rewriteAST(final CompilationUnitRewrite cuRewrite, final LinkedProposalModel linkedModel) throws CoreException {
- ASTRewrite rewrite= cuRewrite.getASTRewrite();
- AST ast= cuRewrite.getRoot().getAST();
- ImportRewrite importRewrite= cuRewrite.getImportRewrite();
- TextEditGroup groupdeclaration= createTextEditGroup(MultiFixMessages.CodeStyleCleanUp_AtomicObject_declaration, cuRewrite);
-
- Class<?> atomicClass;
- Type objectClass= null;
- if (ASTNodes.hasType(arrayCreation.getType().getElementType().resolveBinding(), boolean.class.getCanonicalName())) {
- atomicClass= AtomicBoolean.class;
- } else if (ASTNodes.hasType(arrayCreation.getType().getElementType().resolveBinding(), int.class.getCanonicalName())) {
- atomicClass= AtomicInteger.class;
- } else if (ASTNodes.hasType(arrayCreation.getType().getElementType().resolveBinding(), long.class.getCanonicalName())) {
- atomicClass= AtomicLong.class;
- } else {
- atomicClass= AtomicReference.class;
- objectClass= arrayCreation.getType().getElementType();
- }
-
- String atomicClassNameText= importRewrite.addImport(atomicClass.getCanonicalName());
- Type atomicInstance= ast.newSimpleType(ASTNodeFactory.newName(ast, atomicClassNameText));
-
- if (objectClass != null) {
- ParameterizedType newParameterizedType= ast.newParameterizedType(atomicInstance);
-
- if (!JavaModelUtil.is1d7OrHigher(((CompilationUnit) type.getRoot()).getJavaElement().getJavaProject())) {
- newParameterizedType.typeArguments().add(rewrite.createCopyTarget(objectClass));
- }
-
- atomicInstance= newParameterizedType;
- }
-
- ClassInstanceCreation newAtomicObject= ast.newClassInstanceCreation();
- newAtomicObject.setType(atomicInstance);
-
- if (arrayCreation.getInitializer() != null
- && !ASTNodes.is((Expression) arrayCreation.getInitializer().expressions().get(0), NullLiteral.class)) {
- List<Expression> arguments= newAtomicObject.arguments();
- arguments.add(ASTNodes.createMoveTarget(rewrite, (Expression) arrayCreation.getInitializer().expressions().get(0)));
- }
-
- ASTNodes.replaceButKeepComment(rewrite, arrayCreation, newAtomicObject, groupdeclaration);
-
- for (Object variableDimension : variableDimensions) {
- rewrite.remove((ASTNode) variableDimension, groupdeclaration);
- }
-
- Type atomicType= ast.newSimpleType(ASTNodeFactory.newName(ast, atomicClassNameText));
-
- if (objectClass != null) {
- ParameterizedType newParameterizedType= ast.newParameterizedType(atomicType);
- newParameterizedType.typeArguments().add(rewrite.createCopyTarget(objectClass));
- atomicInstance= newParameterizedType;
- }
-
- ASTNodes.replaceButKeepComment(rewrite, type, atomicInstance, groupdeclaration);
-
- int i=1;
- for (ArrayAccess accessRead : accessReads) {
- MethodInvocation newMethodInvocation= ast.newMethodInvocation();
- newMethodInvocation.setExpression(ASTNodes.createMoveTarget(rewrite, accessRead.getArray()));
- newMethodInvocation.setName(ast.newSimpleName("get")); //$NON-NLS-1$
- TextEditGroup groupusage= createTextEditGroup(MultiFixMessages.CodeStyleCleanUp_AtomicObject_usage+" "+Integer.toString(i++), cuRewrite); //$NON-NLS-1$
- ASTNodes.replaceButKeepComment(rewrite, accessRead, newMethodInvocation, groupusage);
- }
-
- for (Assignment assignmentRead : assignmentReads) {
- MethodInvocation newMethodInvocation= ast.newMethodInvocation();
- newMethodInvocation.setExpression(ASTNodes.createMoveTarget(rewrite, ((ArrayAccess) assignmentRead.getLeftHandSide()).getArray()));
- newMethodInvocation.setName(ast.newSimpleName("set")); //$NON-NLS-1$
- newMethodInvocation.arguments().add(ASTNodes.createMoveTarget(rewrite, assignmentRead.getRightHandSide()));
- TextEditGroup groupusage= createTextEditGroup(MultiFixMessages.CodeStyleCleanUp_AtomicObject_usage+" "+Integer.toString(i++), cuRewrite); //$NON-NLS-1$
- ASTNodes.replaceButKeepComment(rewrite, assignmentRead, newMethodInvocation, groupusage);
- }
- }
- }
-}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java
index 4fe82cc..1c19cfb 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java
@@ -67,7 +67,6 @@
public static String CodeStyleTabPage_GroupName_Expressions;
public static String CodeStyleTabPage_CheckboxName_CheckSignOfBitwiseOperation;
- public static String CodeStyleTabPage_CheckboxName_AtomicObject;
public static String CodeStyleTabPage_CheckboxName_PullUpAssignment;
public static String CodeStyleTabPage_CheckboxName_ElseIf;
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties
index bc4e9a6..5fee04e 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties
@@ -41,7 +41,6 @@
CodeStyleTabPage_CheckboxName_ElseIf=C&ombine nested 'if' statement in 'else' block to 'else if'
CodeStyleTabPage_GroupName_Expressions=Expressions
CodeStyleTabPage_CheckboxName_CheckSignOfBitwiseOperation=&Compare with != 0 for bitwise expressions (use it carefully, it may alter the behavior)
-CodeStyleTabPage_CheckboxName_AtomicObject=Use atomic objects as reference (1.5 or higher)
CodeStyleTabPage_CheckboxName_PullUpAssignment=Pull up assignment
CodeStyleTabPage_GroupName_NumberLiteral=Number literals
CodeStyleTabPage_CheckboxName_NumberSuffix=Use &uppercase for long literal suffix
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CodeStyleTabPage.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CodeStyleTabPage.java
index 577df74..7b4ed2e 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CodeStyleTabPage.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CodeStyleTabPage.java
@@ -22,7 +22,6 @@
import org.eclipse.jdt.internal.ui.fix.AbstractCleanUp;
import org.eclipse.jdt.internal.ui.fix.AddAllCleanUp;
-import org.eclipse.jdt.internal.ui.fix.AtomicObjectCleanUp;
import org.eclipse.jdt.internal.ui.fix.BitwiseConditionalExpressionCleanup;
import org.eclipse.jdt.internal.ui.fix.ControlStatementsCleanUp;
import org.eclipse.jdt.internal.ui.fix.ConvertLoopCleanUp;
@@ -51,7 +50,6 @@
new ElseIfCleanUp(values),
new ExpressionsCleanUp(values),
new BitwiseConditionalExpressionCleanup(values),
- new AtomicObjectCleanUp(values),
new PullUpAssignmentCleanUp(values),
new NumberSuffixCleanUp(values),
new VariableDeclarationCleanUp(values),
@@ -104,9 +102,6 @@
final CheckboxPreference bitwiseComparison= createCheckboxPref(expressionsGroup, numColumns, CleanUpMessages.CodeStyleTabPage_CheckboxName_CheckSignOfBitwiseOperation, CleanUpConstants.CHECK_SIGN_OF_BITWISE_OPERATION, CleanUpModifyDialog.FALSE_TRUE);
registerPreference(bitwiseComparison);
- final CheckboxPreference atomicObject= createCheckboxPref(expressionsGroup, numColumns, CleanUpMessages.CodeStyleTabPage_CheckboxName_AtomicObject, CleanUpConstants.ATOMIC_OBJECT, CleanUpModifyDialog.FALSE_TRUE);
- registerPreference(atomicObject);
-
final CheckboxPreference pullUpAssignmentPref= createCheckboxPref(expressionsGroup, numColumns, CleanUpMessages.CodeStyleTabPage_CheckboxName_PullUpAssignment, CleanUpConstants.PULL_UP_ASSIGNMENT, CleanUpModifyDialog.FALSE_TRUE);
registerPreference(pullUpAssignmentPref);