Skip to content

Commit

Permalink
using different options does not work, committing anyway
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenartur committed Nov 10, 2024
1 parent 8888252 commit 214b81e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Profile> profiles= CleanUpPreferenceUtil.getBuiltInProfiles();
profiles.add(fProfile);
Expand Down

0 comments on commit 214b81e

Please sign in to comment.