From bd56b087204aae44674e896cc54c8c85bbf22f39 Mon Sep 17 00:00:00 2001 From: Carsten Hammer Date: Sun, 6 Oct 2024 21:06:14 +0200 Subject: [PATCH] change formatting and move cleanup to codestyle page --- .../internal/ui/fix/MultiFixMessages.properties | 2 +- .../ui/fix/UseExplicitEncodingCleanUpCore.java | 8 ++++---- .../corext/fix/UseExplicitEncodingFixCore.java | 5 +++++ .../fix/helper/AbstractExplicitEncoding.java | 14 +++++++------- .../ByteArrayOutputStreamExplicitEncoding.java | 11 ++++++++--- .../helper/ChannelsNewReaderExplicitEncoding.java | 5 +++++ .../helper/ChannelsNewWriterExplicitEncoding.java | 5 +++++ .../helper/CharsetForNameExplicitEncoding.java | 11 +++++++---- .../fix/helper/FileReaderExplicitEncoding.java | 5 +++++ .../fix/helper/FileWriterExplicitEncoding.java | 5 +++++ .../fix/helper/FormatterExplicitEncoding.java | 5 +++++ .../helper/InputStreamReaderExplicitEncoding.java | 5 +++++ .../OutputStreamWriterExplicitEncoding.java | 5 +++++ .../fix/helper/PrintStreamExplicitEncoding.java | 5 +++++ .../fix/helper/PrintWriterExplicitEncoding.java | 5 +++++ .../PropertiesStoreToXMLExplicitEncoding.java | 7 ++++++- .../fix/helper/ScannerExplicitEncoding.java | 7 ++++++- .../corext/fix/helper/StringExplicitEncoding.java | 5 +++++ .../helper/StringGetBytesExplicitEncoding.java | 5 +++++ .../helper/URLDecoderDecodeExplicitEncoding.java | 11 ++++++++--- .../helper/URLEncoderEncodeExplicitEncoding.java | 11 ++++++++--- .../ui/preferences/cleanup/CleanUpMessages.java | 2 +- .../cleanup/CleanUpMessages.properties | 4 ++-- .../ui/preferences/cleanup/CodeStyleTabPage.java | 15 ++++++++++++++- .../preferences/cleanup/JavaFeatureTabPage.java | 13 +------------ 25 files changed, 133 insertions(+), 43 deletions(-) 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 41d13e79511..a0afb8e83bf 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 @@ -191,5 +191,5 @@ StringBufferToStringBuilderCleanUp_description=Convert StringBuffer to StringBui StringConcatToTextBlockCleanUp_description=Convert String concatenation to Text Block StringConcatToTextBlockStringBuffer_description=Convert String/StringBuffer/StringBuilder concatenation to Text Block StringBuilderForLocalVarsOnlyCleanUp_description=Convert StringBuffer to StringBuilder for local variables -ExplicitEncodingCleanUp_description=Fix reliance on default encoding ''{0}'' using {1} +ExplicitEncodingCleanUp_description=Set explicit encoding or default encoding where applicable on methods ''{0}'' using {1} ExplicitEncodingCleanUpFix_refactor=Use explicit encoding \ No newline at end of file diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/UseExplicitEncodingCleanUpCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/UseExplicitEncodingCleanUpCore.java index c574bf256e0..e9fbd9a2728 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/UseExplicitEncodingCleanUpCore.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/UseExplicitEncodingCleanUpCore.java @@ -82,15 +82,15 @@ public ICleanUpFix createFix(final CleanUpContext context) throws CoreException } private ChangeBehavior computeRefactorDeepth() { - ChangeBehavior cb=ChangeBehavior.KEEP; + ChangeBehavior cb=ChangeBehavior.KEEP_BEHAVIOR; if(isEnabled(EXPLICITENCODING_KEEP_BEHAVIOR)) { - cb=ChangeBehavior.KEEP; + cb=ChangeBehavior.KEEP_BEHAVIOR; } if(isEnabled(EXPLICITENCODING_INSERT_UTF8)) { - cb=ChangeBehavior.USE_UTF8; + cb=ChangeBehavior.ENFORCE_UTF8; } if(isEnabled(EXPLICITENCODING_AGGREGATE_TO_UTF8)) { - cb=ChangeBehavior.USE_UTF8_AGGREGATE; + cb=ChangeBehavior.ENFORCE_UTF8_AGGREGATE; } return cb; } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/UseExplicitEncodingFixCore.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/UseExplicitEncodingFixCore.java index 1465dba8088..941eb6f21ce 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/UseExplicitEncodingFixCore.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/UseExplicitEncodingFixCore.java @@ -112,4 +112,9 @@ public SourceRange computeSourceRange(final ASTNode nodeWithComment) { return super.computeSourceRange(nodeWithComment); } }; + + @Override + public String toString() { + return explicitencoding.toString(); + } } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/AbstractExplicitEncoding.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/AbstractExplicitEncoding.java index c54bf25591c..66da3437fe9 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/AbstractExplicitEncoding.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/AbstractExplicitEncoding.java @@ -51,7 +51,7 @@ public abstract class AbstractExplicitEncoding { "US-ASCII", "US_ASCII" //$NON-NLS-1$ //$NON-NLS-2$ ); static Set encodings=encodingmap.keySet(); - public enum ChangeBehavior {KEEP, USE_UTF8, USE_UTF8_AGGREGATE} + public enum ChangeBehavior {KEEP_BEHAVIOR, ENFORCE_UTF8, ENFORCE_UTF8_AGGREGATE} static class Nodedata { public boolean replace; @@ -72,7 +72,7 @@ public abstract void rewrite(UseExplicitEncodingFixCore useExplicitEncodingFixCo protected static Expression computeCharsetASTNode(final CompilationUnitRewrite cuRewrite, AST ast, ChangeBehavior cb, String charset) { Expression callToCharsetDefaultCharset=null; switch(cb) { - case KEEP: + case KEEP_BEHAVIOR: if(charset!=null) { callToCharsetDefaultCharset= addCharsetUTF8(cuRewrite, ast,charset); } else { @@ -80,11 +80,11 @@ protected static Expression computeCharsetASTNode(final CompilationUnitRewrite c callToCharsetDefaultCharset= addCharsetComputation(cuRewrite, ast); } break; - case USE_UTF8_AGGREGATE: + case ENFORCE_UTF8_AGGREGATE: /** * @TODO not implemented */ - case USE_UTF8: + case ENFORCE_UTF8: // needs Java 1.7 callToCharsetDefaultCharset= addCharsetUTF8(cuRewrite, ast,charset); break; @@ -95,13 +95,13 @@ protected static Expression computeCharsetASTNode(final CompilationUnitRewrite c protected static String computeCharsetforPreview(ChangeBehavior cb) { String insert=""; //$NON-NLS-1$ switch(cb) { - case KEEP: + case KEEP_BEHAVIOR: insert="Charset.defaultCharset()"; //$NON-NLS-1$ break; - case USE_UTF8_AGGREGATE: + case ENFORCE_UTF8_AGGREGATE: // insert="charset_constant"; //$NON-NLS-1$ //$FALL-THROUGH$ - case USE_UTF8: + case ENFORCE_UTF8: insert="StandardCharsets.UTF_8"; //$NON-NLS-1$ break; } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ByteArrayOutputStreamExplicitEncoding.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ByteArrayOutputStreamExplicitEncoding.java index a59c139a214..f1491bf72f3 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ByteArrayOutputStreamExplicitEncoding.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ByteArrayOutputStreamExplicitEncoding.java @@ -126,13 +126,13 @@ public void rewrite(UseExplicitEncodingFixCore upp,final MethodInvocation visite public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { String insert=""; //$NON-NLS-1$ switch(cb) { - case KEEP: + case KEEP_BEHAVIOR: insert="Charset.defaultCharset().displayName()"; //$NON-NLS-1$ break; - case USE_UTF8_AGGREGATE: + case ENFORCE_UTF8_AGGREGATE: // insert="charset_constant"; //$NON-NLS-1$ //$FALL-THROUGH$ - case USE_UTF8: + case ENFORCE_UTF8: insert="StandardCharsets.UTF_8.displayName()"; //$NON-NLS-1$ break; } @@ -153,4 +153,9 @@ public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { } """; //$NON-NLS-1$ } + + @Override + public String toString() { + return "ba.toString()"; //$NON-NLS-1$ + } } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ChannelsNewReaderExplicitEncoding.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ChannelsNewReaderExplicitEncoding.java index 38895a7f167..46bd05fba4c 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ChannelsNewReaderExplicitEncoding.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ChannelsNewReaderExplicitEncoding.java @@ -107,4 +107,9 @@ public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { return "Reader r=Channels.newReader(ch,\"UTF-8\");\n"+ //$NON-NLS-1$ ""; //$NON-NLS-1$ } + + @Override + public String toString() { + return "Channels.newReader(ch,StandardCharsets.UTF_8)"; //$NON-NLS-1$ + } } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ChannelsNewWriterExplicitEncoding.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ChannelsNewWriterExplicitEncoding.java index faf000d04f1..de94b63b93d 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ChannelsNewWriterExplicitEncoding.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ChannelsNewWriterExplicitEncoding.java @@ -105,4 +105,9 @@ public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { return "Writer w=Channels.newWriter(ch, \"UTF-8\");\n"+ //$NON-NLS-1$ ""; //$NON-NLS-1$ } + + @Override + public String toString() { + return "Channels.newWriter(ch,StandardCharsets.UTF_8)"; //$NON-NLS-1$ + } } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/CharsetForNameExplicitEncoding.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/CharsetForNameExplicitEncoding.java index ab7fbed52a7..2f00f09355c 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/CharsetForNameExplicitEncoding.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/CharsetForNameExplicitEncoding.java @@ -94,10 +94,13 @@ public void rewrite(UseExplicitEncodingFixCore upp,final MethodInvocation visite @Override public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { if(afterRefactoring) { - return "Charset s=StandardCharsets.UTF_8;\n"+ //$NON-NLS-1$ - ""; //$NON-NLS-1$ + return "Charset s=StandardCharsets.UTF_8;\n"; //$NON-NLS-1$ } - return "Charset s=Charset.forName(\"UTF-8\");\n"+ //$NON-NLS-1$ - ""; //$NON-NLS-1$ + return "Charset s=Charset.forName(\"UTF-8\");\n"; //$NON-NLS-1$ + } + + @Override + public String toString() { + return "Charset.forName(\"UTF-8\")"; //$NON-NLS-1$ } } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/FileReaderExplicitEncoding.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/FileReaderExplicitEncoding.java index 2ddf1e08dc0..0b50c196a33 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/FileReaderExplicitEncoding.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/FileReaderExplicitEncoding.java @@ -113,4 +113,9 @@ public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { } return "Reader r=new FileReader(inputfile);\n"; //$NON-NLS-1$ } + + @Override + public String toString() { + return "new FileReader(inputfile)"; //$NON-NLS-1$ + } } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/FileWriterExplicitEncoding.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/FileWriterExplicitEncoding.java index d4840ca4370..b58b12da3a0 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/FileWriterExplicitEncoding.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/FileWriterExplicitEncoding.java @@ -93,4 +93,9 @@ public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { } return "Writer w=new FileWriter(outputfile);\n"; //$NON-NLS-1$ } + + @Override + public String toString() { + return "new FileWriter(outputfile)"; //$NON-NLS-1$ + } } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/FormatterExplicitEncoding.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/FormatterExplicitEncoding.java index ecd34a7c9d4..7bf792321ed 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/FormatterExplicitEncoding.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/FormatterExplicitEncoding.java @@ -139,4 +139,9 @@ public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { } return "Formatter r=new java.util.Formatter(out);\n"; //$NON-NLS-1$ } + + @Override + public String toString() { + return "new java.util.Formatter(out)"; //$NON-NLS-1$ + } } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/InputStreamReaderExplicitEncoding.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/InputStreamReaderExplicitEncoding.java index 87c20ff6553..9a1ff633145 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/InputStreamReaderExplicitEncoding.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/InputStreamReaderExplicitEncoding.java @@ -115,4 +115,9 @@ public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { } return "Reader r=new InputStreamReader(in);\nInputStreamReader is=new InputStreamReader(new FileInputStream(\"\"), StandardCharsets.UTF_8);\n"; //$NON-NLS-1$ } + + @Override + public String toString() { + return "new InputStreamReader(in)"; //$NON-NLS-1$ + } } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/OutputStreamWriterExplicitEncoding.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/OutputStreamWriterExplicitEncoding.java index 62a94b26529..6062c57af40 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/OutputStreamWriterExplicitEncoding.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/OutputStreamWriterExplicitEncoding.java @@ -127,4 +127,9 @@ public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { } return "Writer w = new OutputStreamWriter(out);\nOutputStreamWriter os=new OutputStreamWriter(new FileOutputStream(\"\"), \"UTF-8\");\n"; //$NON-NLS-1$ } + + @Override + public String toString() { + return "new OutputStreamWriter(out)"; //$NON-NLS-1$ + } } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/PrintStreamExplicitEncoding.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/PrintStreamExplicitEncoding.java index 8701f915b71..ad7989986e0 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/PrintStreamExplicitEncoding.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/PrintStreamExplicitEncoding.java @@ -142,4 +142,9 @@ public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { Stream w=new PrintStream(new File("out.txt"),"UTF-8"); """; //$NON-NLS-1$ } + + @Override + public String toString() { + return "new PrintStream(\"out.txt\")"; //$NON-NLS-1$ + } } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/PrintWriterExplicitEncoding.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/PrintWriterExplicitEncoding.java index c49960c0465..075acf9db0a 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/PrintWriterExplicitEncoding.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/PrintWriterExplicitEncoding.java @@ -108,4 +108,9 @@ public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { } return "Writer w=new PrintWriter(outputfile);\n"; //$NON-NLS-1$ } + + @Override + public String toString() { + return "new PrintWriter(outputfile)"; //$NON-NLS-1$ + } } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/PropertiesStoreToXMLExplicitEncoding.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/PropertiesStoreToXMLExplicitEncoding.java index 19cfc7828d1..f2a56b6b9f5 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/PropertiesStoreToXMLExplicitEncoding.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/PropertiesStoreToXMLExplicitEncoding.java @@ -114,9 +114,14 @@ public void rewrite(UseExplicitEncodingFixCore upp,final MethodInvocation visite public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { if(afterRefactoring) { return "Properties p=new Properties();\n"+ //$NON-NLS-1$ - "p.storeToXML(java.io.OutputStream,String,"+computeCharsetforPreview(cb)+");\n"; //$NON-NLS-1$ //$NON-NLS-2$ + "p.storeToXML(java.io.OutputStream,String,StandardCharsets.UTF_8);\n"; //$NON-NLS-1$ } return "Properties p=new Properties();\n"+ //$NON-NLS-1$ "p.storeToXML(java.io.OutputStream,String,\"UTF-8\");\n"; //$NON-NLS-1$ } + + @Override + public String toString() { + return "Properties.storeToXML()"; //$NON-NLS-1$ + } } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ScannerExplicitEncoding.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ScannerExplicitEncoding.java index 1baf95c0be2..16da136c1e9 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ScannerExplicitEncoding.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/ScannerExplicitEncoding.java @@ -139,8 +139,13 @@ public void rewrite(UseExplicitEncodingFixCore upp,final ClassInstanceCreation v @Override public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { if(afterRefactoring) { - return "new java.util.Scanner(\"asdf\","+computeCharsetforPreview(cb)+");\n"; //$NON-NLS-1$ //$NON-NLS-2$ + return "new java.util.Scanner(\"asdf\",StandardCharsets.UTF_8);\n"; //$NON-NLS-1$ } return "new java.util.Scanner(\"asdf\", \"UTF-8\");\n"; //$NON-NLS-1$ } + + @Override + public String toString() { + return "new java.util.Scanner()"; //$NON-NLS-1$ + } } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/StringExplicitEncoding.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/StringExplicitEncoding.java index ac7d5c4368c..3fdfa9de16d 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/StringExplicitEncoding.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/StringExplicitEncoding.java @@ -128,4 +128,9 @@ public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { } return "String s=new String(byte[],\"UTF-8\");\n"; //$NON-NLS-1$ } + + @Override + public String toString() { + return "new String(byte[])"; //$NON-NLS-1$ + } } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/StringGetBytesExplicitEncoding.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/StringGetBytesExplicitEncoding.java index ec16add8e6f..1abc5448bd2 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/StringGetBytesExplicitEncoding.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/StringGetBytesExplicitEncoding.java @@ -116,4 +116,9 @@ public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { return "String s=\"asdf\";\n"+ //$NON-NLS-1$ "byte[] bytes= s.getBytes();\n"; //$NON-NLS-1$ } + + @Override + public String toString() { + return "String.getBytes()"; //$NON-NLS-1$ + } } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/URLDecoderDecodeExplicitEncoding.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/URLDecoderDecodeExplicitEncoding.java index 8dc154ad0e1..3c1bfce46a9 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/URLDecoderDecodeExplicitEncoding.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/URLDecoderDecodeExplicitEncoding.java @@ -93,13 +93,13 @@ private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, if (ASTNodes.usesGivenSignature(visited, URLDecoder.class.getCanonicalName(), METHOD_DECODE, String.class.getCanonicalName())) { Nodedata nd=new Nodedata(); switch(cb) { - case KEEP: + case KEEP_BEHAVIOR: nd.encoding=null; break; - case USE_UTF8: + case ENFORCE_UTF8: nd.encoding="UTF_8"; //$NON-NLS-1$ break; - case USE_UTF8_AGGREGATE: + case ENFORCE_UTF8_AGGREGATE: break; } nd.replace=false; @@ -137,4 +137,9 @@ public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { return "java.net.URLDecoder.decode(\"asdf\", \"UTF-8\");\n"+ //$NON-NLS-1$ ""; //$NON-NLS-1$ } + + @Override + public String toString() { + return "URLDecoder.decode()"; //$NON-NLS-1$ + } } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/URLEncoderEncodeExplicitEncoding.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/URLEncoderEncodeExplicitEncoding.java index 02139a81f1f..65f3c97dbd7 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/URLEncoderEncodeExplicitEncoding.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/helper/URLEncoderEncodeExplicitEncoding.java @@ -93,13 +93,13 @@ private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, if (ASTNodes.usesGivenSignature(visited, URLEncoder.class.getCanonicalName(), METHOD_ENCODE, String.class.getCanonicalName())) { Nodedata nd=new Nodedata(); switch(cb) { - case KEEP: + case KEEP_BEHAVIOR: nd.encoding=null; break; - case USE_UTF8: + case ENFORCE_UTF8: nd.encoding="UTF_8"; //$NON-NLS-1$ break; - case USE_UTF8_AGGREGATE: + case ENFORCE_UTF8_AGGREGATE: break; } nd.replace=false; @@ -137,4 +137,9 @@ public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { return "java.net.URLEncoder.encode(\"asdf\", \"UTF-8\");\n"+ //$NON-NLS-1$ ""; //$NON-NLS-1$ } + + @Override + public String toString() { + return "URLEncoder.encode()"; //$NON-NLS-1$ + } } 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 3d2b702ac56..018329b9205 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 @@ -241,7 +241,7 @@ public class CleanUpMessages extends NLS { public static String JavaFeatureTabPage_CheckboxName_StringBufferBuilderToTextBlock; - public static String JavaFeatureTabPage_GroupName_Java1d6; + public static String JavaFeatureTabPage_GroupName_Encoding; public static String JavaFeatureTabPage_CheckboxName_ExplicitEncoding; public static String JavaFeatureTabPage_RadioName_Keep_Behavior; public static String JavaFeatureTabPage_RadioName_Insert_UTF8; 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 5f0e0fd8c71..1f970689a52 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 @@ -218,8 +218,8 @@ JavaFeatureTabPage_CheckboxName_ConstantsForSystemProperty_PathSeparator=Path se JavaFeatureTabPage_CheckboxName_ConstantsForSystemProperty_JavaVersionProperty=Java Version property JavaFeatureTabPage_CheckboxName_ConstantsForSystemProperty_JavaVersionSpecProperty=Java Spec Version property -JavaFeatureTabPage_CheckboxName_ExplicitEncoding=Fix reliance on default encoding +JavaFeatureTabPage_CheckboxName_ExplicitEncoding=Set explicit encoding JavaFeatureTabPage_RadioName_Aggregate_to_UTF8=Insert/replace to make use of UTF-8 instead of platform encoding.\n Try to use single constant per project. JavaFeatureTabPage_RadioName_Insert_UTF8=Insert/replace to make use of UTF-8 instead of platform encoding. JavaFeatureTabPage_RadioName_Keep_Behavior=Don't change behavior - just insert/replace code to make usage of platform encoding visible. -JavaFeatureTabPage_GroupName_Java1d6=Java 6 \ No newline at end of file +JavaFeatureTabPage_GroupName_Encoding=Encoding \ No newline at end of file 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 d19506b5fdc..f2625912292 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 @@ -33,6 +33,7 @@ import org.eclipse.jdt.internal.ui.fix.ReduceIndentationCleanUp; import org.eclipse.jdt.internal.ui.fix.SimplifyBooleanIfElseCleanUpCore; import org.eclipse.jdt.internal.ui.fix.SwitchCleanUpCore; +import org.eclipse.jdt.internal.ui.fix.UseExplicitEncodingCleanUp; import org.eclipse.jdt.internal.ui.fix.VariableDeclarationCleanUpCore; public final class CodeStyleTabPage extends AbstractCleanUpTabPage { @@ -53,7 +54,8 @@ protected AbstractCleanUp[] createPreviewCleanUps(Map values) { new InstanceofCleanUp(values), new VariableDeclarationCleanUpCore(values), new SimplifyBooleanIfElseCleanUpCore(values), - new LambdaExpressionAndMethodRefCleanUp(values) + new LambdaExpressionAndMethodRefCleanUp(values), + new UseExplicitEncodingCleanUp(values) }; } @@ -122,5 +124,16 @@ protected void doCreatePreferences(Composite composite, int numColumns) { CheckboxPreference simplifyLambdaExpressionAndMethodRef= createCheckboxPref(functionalInterfacesGroup, numColumns, CleanUpMessages.CodeStyleTabPage_CheckboxName_SimplifyLambdaExpressionAndMethodRefSyntax, CleanUpConstants.SIMPLIFY_LAMBDA_EXPRESSION_AND_METHOD_REF, CleanUpModifyDialog.FALSE_TRUE); registerPreference(simplifyLambdaExpressionAndMethodRef); + + Group encodingGroup= createGroup(numColumns, composite, CleanUpMessages.JavaFeatureTabPage_GroupName_Encoding); + final CheckboxPreference explicit_encoding= createCheckboxPref(encodingGroup, numColumns, CleanUpMessages.JavaFeatureTabPage_CheckboxName_ExplicitEncoding, CleanUpConstants.EXPLICITENCODING_CLEANUP, CleanUpModifyDialog.FALSE_TRUE); + intent(encodingGroup); + final RadioPreference useKeep_Behavior= createRadioPref(encodingGroup, numColumns - 1, CleanUpMessages.JavaFeatureTabPage_RadioName_Keep_Behavior, CleanUpConstants.EXPLICITENCODING_KEEP_BEHAVIOR, CleanUpModifyDialog.FALSE_TRUE); + intent(encodingGroup); + final RadioPreference useINSERT_UTF8= createRadioPref(encodingGroup, numColumns - 1, CleanUpMessages.JavaFeatureTabPage_RadioName_Insert_UTF8, CleanUpConstants.EXPLICITENCODING_INSERT_UTF8, CleanUpModifyDialog.FALSE_TRUE); + intent(encodingGroup); + final RadioPreference useAGGREGATE_TO_UTF8= createRadioPref(encodingGroup, numColumns - 1, CleanUpMessages.JavaFeatureTabPage_RadioName_Aggregate_to_UTF8, CleanUpConstants.EXPLICITENCODING_AGGREGATE_TO_UTF8, CleanUpModifyDialog.FALSE_TRUE); + registerSlavePreference(explicit_encoding, new RadioPreference[] {useKeep_Behavior, useINSERT_UTF8, useAGGREGATE_TO_UTF8}); + } } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/JavaFeatureTabPage.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/JavaFeatureTabPage.java index 25a8e4ae5d5..5177bb63761 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/JavaFeatureTabPage.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/JavaFeatureTabPage.java @@ -36,7 +36,6 @@ import org.eclipse.jdt.internal.ui.fix.TryWithResourceCleanUp; import org.eclipse.jdt.internal.ui.fix.TypeParametersCleanUp; import org.eclipse.jdt.internal.ui.fix.UnboxingCleanUp; -import org.eclipse.jdt.internal.ui.fix.UseExplicitEncodingCleanUp; import org.eclipse.jdt.internal.ui.fix.VarCleanUpCore; public final class JavaFeatureTabPage extends AbstractCleanUpTabPage { @@ -60,8 +59,7 @@ protected AbstractCleanUp[] createPreviewCleanUps(final Map valu new ConvertLoopCleanUp(values), new AutoboxingCleanUp(values), new UnboxingCleanUp(values), - new ConstantsForSystemPropertyCleanUp(values), - new UseExplicitEncodingCleanUp(values) + new ConstantsForSystemPropertyCleanUp(values) }; } @@ -154,15 +152,6 @@ protected void doCreatePreferences(final Composite composite, final int numColum CheckboxPreference unboxing= createCheckboxPref(java1d5Group, numColumns, CleanUpMessages.JavaFeatureTabPage_CheckboxName_Unboxing, CleanUpConstants.USE_UNBOXING, CleanUpModifyDialog.FALSE_TRUE); registerPreference(unboxing); - Group java1d6Group= createGroup(numColumns, composite, CleanUpMessages.JavaFeatureTabPage_GroupName_Java1d6); - final CheckboxPreference explicit_encoding= createCheckboxPref(java1d6Group, numColumns, CleanUpMessages.JavaFeatureTabPage_CheckboxName_ExplicitEncoding, CleanUpConstants.EXPLICITENCODING_CLEANUP, CleanUpModifyDialog.FALSE_TRUE); - intent(java1d6Group); - final RadioPreference useBlockAlwaysPref= createRadioPref(java1d6Group, numColumns - 1, CleanUpMessages.JavaFeatureTabPage_RadioName_Keep_Behavior, CleanUpConstants.EXPLICITENCODING_KEEP_BEHAVIOR, CleanUpModifyDialog.FALSE_TRUE); - intent(java1d6Group); - final RadioPreference useBlockJDTStylePref= createRadioPref(java1d6Group, numColumns - 1, CleanUpMessages.JavaFeatureTabPage_RadioName_Insert_UTF8, CleanUpConstants.EXPLICITENCODING_INSERT_UTF8, CleanUpModifyDialog.FALSE_TRUE); - intent(java1d6Group); - final RadioPreference useBlockNeverPref= createRadioPref(java1d6Group, numColumns - 1, CleanUpMessages.JavaFeatureTabPage_RadioName_Aggregate_to_UTF8, CleanUpConstants.EXPLICITENCODING_AGGREGATE_TO_UTF8, CleanUpModifyDialog.FALSE_TRUE); - registerSlavePreference(explicit_encoding, new RadioPreference[] {useBlockAlwaysPref, useBlockJDTStylePref, useBlockNeverPref}); } }