Skip to content

Commit

Permalink
fix preview method
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenartur committed Sep 11, 2024
1 parent 31c7bdc commit 84199ae
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ public UseExplicitEncodingCleanUpCore(final Map<String, String> options) {
public UseExplicitEncodingCleanUpCore() {
}

@Override
public CleanUpRequirements getRequirements() {
return new CleanUpRequirements(requireAST(), false, false, null);
}

public boolean requireAST() {
return isEnabled(EXPLICITENCODING_CLEANUP);
return isEnabled(EXPLICITENCODING_CLEANUP)&& !computeFixSet().isEmpty();
}
@Override
public ICleanUpFix createFix(final CleanUpContext context) throws CoreException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ public void rewrite(UseExplicitEncodingFixCore upp,final MethodInvocation visite
@Override
public String getPreview(boolean afterRefactoring,ChangeBehavior cb) {
if(afterRefactoring) {
return "Reader r=\"Channels.newReader(ch,StandardCharsets.UTF_8)\";\n"+ //$NON-NLS-1$
return "Reader r=Channels.newReader(ch,StandardCharsets.UTF_8);\n"+ //$NON-NLS-1$
""; //$NON-NLS-1$
}
return "Reader r=\"Channels.newReader(ch,\"UTF-8\")\";\n"+ //$NON-NLS-1$
return "Reader r=Channels.newReader(ch,\"UTF-8\");\n"+ //$NON-NLS-1$
""; //$NON-NLS-1$
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ public void rewrite(UseExplicitEncodingFixCore upp,final MethodInvocation visite
@Override
public String getPreview(boolean afterRefactoring,ChangeBehavior cb) {
if(afterRefactoring) {
return "Writer w=\"Channels.newWriter(ch, StandardCharsets.UTF_8)\";\n"+ //$NON-NLS-1$
return "Writer w=Channels.newWriter(ch, StandardCharsets.UTF_8);\n"+ //$NON-NLS-1$
""; //$NON-NLS-1$
}
return "Writer w=\"Channels.newWriter(ch, \"UTF-8\")\";\n"+ //$NON-NLS-1$
return "Writer w=Channels.newWriter(ch, \"UTF-8\");\n"+ //$NON-NLS-1$
""; //$NON-NLS-1$
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ 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$
return "Charset s=StandardCharsets.UTF_8;\n"+ //$NON-NLS-1$
""; //$NON-NLS-1$
}
return "Charset s=\"Charset.forName(\"UTF-8\")\";\n"+ //$NON-NLS-1$
return "Charset s=Charset.forName(\"UTF-8\");\n"+ //$NON-NLS-1$
""; //$NON-NLS-1$
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ public void rewrite(UseExplicitEncodingFixCore upp,final MethodInvocation visite
@Override
public String getPreview(boolean afterRefactoring,ChangeBehavior cb) {
if(afterRefactoring) {
return "Properties p=\"new Properties()\";\n"+ //$NON-NLS-1$
return "Properties p=new Properties();\n"+ //$NON-NLS-1$
"p.storeToXML(java.io.OutputStream,String,"+computeCharsetforPreview(cb)+");\n"; //$NON-NLS-1$ //$NON-NLS-2$
}
return "Properties p=\"new Properties()\";\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$
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ public void rewrite(UseExplicitEncodingFixCore upp,final MethodInvocation visite
@Override
public String getPreview(boolean afterRefactoring,ChangeBehavior cb) {
if(afterRefactoring) {
return "\"java.net.URLDecoder.decode(\"asdf\", StandardCharsets.UTF_8)\";\n"+ //$NON-NLS-1$
return "java.net.URLDecoder.decode(\"asdf\", StandardCharsets.UTF_8);\n"+ //$NON-NLS-1$
""; //$NON-NLS-1$
}
return "\"java.net.URLDecoder.decode(\"asdf\", \"UTF-8\")\";\n"+ //$NON-NLS-1$
return "java.net.URLDecoder.decode(\"asdf\", \"UTF-8\");\n"+ //$NON-NLS-1$
""; //$NON-NLS-1$
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ public void rewrite(UseExplicitEncodingFixCore upp,final MethodInvocation visite
@Override
public String getPreview(boolean afterRefactoring,ChangeBehavior cb) {
if(afterRefactoring) {
return "\"java.net.URLEncoder.encode(\"asdf\", StandardCharsets.UTF_8)\";\n"+ //$NON-NLS-1$
return "java.net.URLEncoder.encode(\"asdf\", StandardCharsets.UTF_8);\n"+ //$NON-NLS-1$
""; //$NON-NLS-1$
}
return "\"java.net.URLEncoder.encode(\"asdf\", \"UTF-8\")\";\n"+ //$NON-NLS-1$
return "java.net.URLEncoder.encode(\"asdf\", \"UTF-8\");\n"+ //$NON-NLS-1$
""; //$NON-NLS-1$
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.jdt.internal.ui.fix;

import java.util.Collections;
import java.util.Map;

/**
Expand All @@ -25,4 +26,8 @@ public class UseExplicitEncodingCleanUp extends AbstractCleanUpCoreWrapper<UseEx
public UseExplicitEncodingCleanUp(final Map<String, String> options) {
super(options, new UseExplicitEncodingCleanUpCore());
}

public UseExplicitEncodingCleanUp() {
this(Collections.EMPTY_MAP);
}
}

0 comments on commit 84199ae

Please sign in to comment.