From 214b81e2a4aed6cb7062e45f2d4dbe5efdd5a98c Mon Sep 17 00:00:00 2001 From: Carsten Hammer Date: Sun, 10 Nov 2024 19:32:01 +0100 Subject: [PATCH] using different options does not work, committing anyway --- .../corext/fix/helper/ChangeBehavior.java | 15 +++++----- .../Java10/ExplicitEncodingCleanUpTest.java | 28 ++++++++++++++++++- .../quickfix/rules/AbstractEclipseJava.java | 5 ++++ 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ChangeBehavior.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ChangeBehavior.java index 781064af1f7..11fec4d01d9 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ChangeBehavior.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ChangeBehavior.java @@ -46,34 +46,33 @@ protected Expression computeCharsetASTNode(final CompilationUnitRewrite cuRewrit @Override protected String computeCharsetforPreview() { - String insert= ""; //$NON-NLS-1$ - insert= "Charset.defaultCharset()"; //$NON-NLS-1$ + String insert= "Charset.defaultCharset()"; //$NON-NLS-1$ return insert; } }, ENFORCE_UTF8() { @Override protected Expression computeCharsetASTNode(final CompilationUnitRewrite cuRewrite, AST ast, String charset) { - Expression callToCharsetDefaultCharset= null; - callToCharsetDefaultCharset= addCharsetUTF8(cuRewrite, ast, charset); + Expression callToCharsetDefaultCharset= addCharsetUTF8(cuRewrite, ast, charset); return callToCharsetDefaultCharset; } @Override protected String computeCharsetforPreview() { - String insert= ""; //$NON-NLS-1$ - insert= "StandardCharsets.UTF_8"; //$NON-NLS-1$ + String insert= "StandardCharsets.UTF_8"; //$NON-NLS-1$ return insert; } }, ENFORCE_UTF8_AGGREGATE() { @Override protected Expression computeCharsetASTNode(final CompilationUnitRewrite cuRewrite, AST ast, String charset) { - Expression callToCharsetDefaultCharset= null; /** * @TODO not implemented */ - return callToCharsetDefaultCharset; + FieldAccess callToCharsetUTF8 = ast.newFieldAccess(); + callToCharsetUTF8.setName(ast.newSimpleName("ENCODING_UTF_8")); // Verwendet die statische Konstante //$NON-NLS-1$ + callToCharsetUTF8.setExpression(ast.newSimpleName("StandardCharsets")); //$NON-NLS-1$ + return callToCharsetUTF8; } @Override diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java10/ExplicitEncodingCleanUpTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java10/ExplicitEncodingCleanUpTest.java index 16402c3022d..08e509c664b 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java10/ExplicitEncodingCleanUpTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java10/ExplicitEncodingCleanUpTest.java @@ -1927,11 +1927,37 @@ void method(String filename) { @ParameterizedTest @EnumSource(ExplicitEncodingPatterns.class) - public void testExplicitEncodingParametrized(ExplicitEncodingPatterns test) throws CoreException { + public void testExplicitEncodingParametrizedKeepBehavior(ExplicitEncodingPatterns test) throws CoreException { IPackageFragment pack= context.getfSourceFolder().createPackageFragment("test1", false, null); ICompilationUnit cu= pack.createCompilationUnit("E1.java", test.given, false, null); context.enable(CleanUpConstants.EXPLICITENCODING_CLEANUP); context.enable(CleanUpConstants.EXPLICITENCODING_KEEP_BEHAVIOR); + context.disable(CleanUpConstants.EXPLICITENCODING_INSERT_UTF8); + context.disable(CleanUpConstants.EXPLICITENCODING_AGGREGATE_TO_UTF8); + context.assertRefactoringResultAsExpected(new ICompilationUnit[] { cu }, new String[] { test.expected }, null); + } + + @ParameterizedTest + @EnumSource(ExplicitEncodingPatterns.class) + public void testExplicitEncodingParametrizedPreferUTF8(ExplicitEncodingPatterns test) throws CoreException { + IPackageFragment pack= context.getfSourceFolder().createPackageFragment("test1", false, null); + ICompilationUnit cu= pack.createCompilationUnit("E1.java", test.given, false, null); + context.enable(CleanUpConstants.EXPLICITENCODING_CLEANUP); + context.disable(CleanUpConstants.EXPLICITENCODING_KEEP_BEHAVIOR); + context.enable(CleanUpConstants.EXPLICITENCODING_INSERT_UTF8); + context.disable(CleanUpConstants.EXPLICITENCODING_AGGREGATE_TO_UTF8); + context.assertRefactoringResultAsExpected(new ICompilationUnit[] { cu }, new String[] { test.expected }, null); + } + + @ParameterizedTest + @EnumSource(ExplicitEncodingPatterns.class) + public void testExplicitEncodingParametrizedAggregateUTF8(ExplicitEncodingPatterns test) throws CoreException { + IPackageFragment pack= context.getfSourceFolder().createPackageFragment("test1", false, null); + ICompilationUnit cu= pack.createCompilationUnit("E1.java", test.given, false, null); + context.enable(CleanUpConstants.EXPLICITENCODING_CLEANUP); + context.disable(CleanUpConstants.EXPLICITENCODING_KEEP_BEHAVIOR); + context.disable(CleanUpConstants.EXPLICITENCODING_INSERT_UTF8); + context.enable(CleanUpConstants.EXPLICITENCODING_AGGREGATE_TO_UTF8); context.assertRefactoringResultAsExpected(new ICompilationUnit[] { cu }, new String[] { test.expected }, null); } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/rules/AbstractEclipseJava.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/rules/AbstractEclipseJava.java index 1eed95d8822..074fd548006 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/rules/AbstractEclipseJava.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/rules/AbstractEclipseJava.java @@ -475,6 +475,11 @@ public void enable(String key) throws CoreException { commitProfile(); } + public void disable(String key) throws CoreException { + fProfile.getSettings().put(key, CleanUpOptions.FALSE); + commitProfile(); + } + private void commitProfile() throws CoreException { List profiles= CleanUpPreferenceUtil.getBuiltInProfiles(); profiles.add(fProfile);