diff --git a/sandbox_common/src/org/sandbox/jdt/internal/common/LambdaASTVisitor.java b/sandbox_common/src/org/sandbox/jdt/internal/common/LambdaASTVisitor.java index ea4682c0..f95b2f11 100644 --- a/sandbox_common/src/org/sandbox/jdt/internal/common/LambdaASTVisitor.java +++ b/sandbox_common/src/org/sandbox/jdt/internal/common/LambdaASTVisitor.java @@ -18,18 +18,19 @@ import java.util.function.BiPredicate; import org.eclipse.jdt.core.dom.*; + import org.eclipse.jdt.internal.corext.dom.ASTNodes; /** * * @author chammer * - * @param - * @param - * @param + * @param - type that extends HelpVisitorProvider that provides {@code HelperVisitor} + * @param - type that HelperVisitor uses as map key type + * @param - type that HelperVisitor uses as map value type * @since 1.15 */ -@SuppressWarnings({ "unchecked", "restriction" }) +@SuppressWarnings({ "unchecked" }) public class LambdaASTVisitor, V, T> extends ASTVisitor { /** * @@ -37,7 +38,7 @@ public class LambdaASTVisitor, V, T> exte private final HelperVisitor helperVisitor; /** - * @param helperVisitor + * @param helperVisitor - HelperVisitor */ LambdaASTVisitor(HelperVisitor helperVisitor) { super(false); @@ -520,25 +521,12 @@ public boolean visit(MethodInvocation node) { } Class typeof=(Class) map.get(HelperVisitor.TYPEOF); String[] parameterTypesQualifiedNames=(String[]) map.get(HelperVisitor.PARAMTYPENAMES); - + if(typeof!=null) { -// Name sn= ASTNodes.as(node.getExpression(), Name.class); -// if (sn == null) { -// return true; -// } -// IBinding ibinding= sn.resolveBinding(); -// IVariableBinding vb=(IVariableBinding) ibinding; -// if(vb!=null) { -// ITypeBinding binding= vb.getType(); -// if ((binding != null) && !typeof.getSimpleName().equals(binding.getName())) { -// return true; -// } -// } - if(parameterTypesQualifiedNames==null) { if (ASTNodes.usesGivenSignature(node, typeof.getCanonicalName(), data)) { return ((BiPredicate) (this.helperVisitor.predicatemap.get(VisitorEnum.MethodInvocation))).test(node, this.helperVisitor.dataholder); - } + } } else if (ASTNodes.usesGivenSignature(node, typeof.getCanonicalName(), data, parameterTypesQualifiedNames)) { return ((BiPredicate) (this.helperVisitor.predicatemap.get(VisitorEnum.MethodInvocation))).test(node, this.helperVisitor.dataholder); @@ -712,14 +700,14 @@ public boolean visit(QualifiedType node) { return true; } - @Override - public boolean visit(ModuleQualifiedName node) { - if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.ModuleQualifiedName)) { - return ((BiPredicate) (this.helperVisitor.predicatemap.get(VisitorEnum.ModuleQualifiedName))) - .test(node, this.helperVisitor.dataholder); - } - return true; - } +// @Override +// public boolean visit(ModuleQualifiedName node) { +// if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.ModuleQualifiedName)) { +// return ((BiPredicate) (this.helperVisitor.predicatemap.get(VisitorEnum.ModuleQualifiedName))) +// .test(node, this.helperVisitor.dataholder); +// } +// return true; +// } @Override public boolean visit(RequiresDirective node) { @@ -1054,7 +1042,7 @@ public boolean visit(YieldStatement node) { public void endVisit(AnnotationTypeDeclaration node) { if (this.helperVisitor.consumermap.containsKey(VisitorEnum.AnnotationTypeDeclaration)) { ((BiConsumer) (this.helperVisitor.consumermap.get(VisitorEnum.AnnotationTypeDeclaration))) - .accept(node, this.helperVisitor.dataholder); + .accept(node, this.helperVisitor.dataholder); } } @@ -1070,7 +1058,7 @@ public void endVisit(AnnotationTypeMemberDeclaration node) { public void endVisit(AnonymousClassDeclaration node) { if (this.helperVisitor.consumermap.containsKey(VisitorEnum.AnonymousClassDeclaration)) { ((BiConsumer) (this.helperVisitor.consumermap.get(VisitorEnum.AnonymousClassDeclaration))) - .accept(node, this.helperVisitor.dataholder); + .accept(node, this.helperVisitor.dataholder); } } @@ -1175,7 +1163,7 @@ public void endVisit(CharacterLiteral node) { public void endVisit(ClassInstanceCreation node) { if (this.helperVisitor.consumermap.containsKey(VisitorEnum.ClassInstanceCreation)) { ((BiConsumer) (this.helperVisitor.consumermap.get(VisitorEnum.ClassInstanceCreation))) - .accept(node, this.helperVisitor.dataholder); + .accept(node, this.helperVisitor.dataholder); } } @@ -1191,7 +1179,7 @@ public void endVisit(CompilationUnit node) { public void endVisit(ConditionalExpression node) { if (this.helperVisitor.consumermap.containsKey(VisitorEnum.ConditionalExpression)) { ((BiConsumer) (this.helperVisitor.consumermap.get(VisitorEnum.ConditionalExpression))) - .accept(node, this.helperVisitor.dataholder); + .accept(node, this.helperVisitor.dataholder); } } @@ -1199,7 +1187,7 @@ public void endVisit(ConditionalExpression node) { public void endVisit(ConstructorInvocation node) { if (this.helperVisitor.consumermap.containsKey(VisitorEnum.ConstructorInvocation)) { ((BiConsumer) (this.helperVisitor.consumermap.get(VisitorEnum.ConstructorInvocation))) - .accept(node, this.helperVisitor.dataholder); + .accept(node, this.helperVisitor.dataholder); } } @@ -1253,7 +1241,7 @@ public void endVisit(EnhancedForStatement node) { public void endVisit(EnumConstantDeclaration node) { if (this.helperVisitor.consumermap.containsKey(VisitorEnum.EnumConstantDeclaration)) { ((BiConsumer) (this.helperVisitor.consumermap.get(VisitorEnum.EnumConstantDeclaration))) - .accept(node, this.helperVisitor.dataholder); + .accept(node, this.helperVisitor.dataholder); } } @@ -1277,7 +1265,7 @@ public void endVisit(ExportsDirective node) { public void endVisit(ExpressionMethodReference node) { if (this.helperVisitor.consumermap.containsKey(VisitorEnum.ExpressionMethodReference)) { ((BiConsumer) (this.helperVisitor.consumermap.get(VisitorEnum.ExpressionMethodReference))) - .accept(node, this.helperVisitor.dataholder); + .accept(node, this.helperVisitor.dataholder); } } @@ -1447,16 +1435,6 @@ public void endVisit(MethodInvocation node) { if (!ASTNodes.usesGivenSignature(node, typeof.getCanonicalName(), data)) { return; } -// Name sn= ASTNodes.as(node.getExpression(), Name.class); -// if (sn == null) { -// return; -// } -// IBinding ibinding= sn.resolveBinding(); -// IVariableBinding vb=(IVariableBinding) ibinding; -// ITypeBinding binding= vb.getType(); -// if ((binding != null) && !typeof.getSimpleName().equals(binding.getName())) { -// return; -// } } } ((BiConsumer) (this.helperVisitor.consumermap.get(VisitorEnum.MethodInvocation))).accept(node, @@ -1545,7 +1523,7 @@ public void endVisit(ParameterizedType node) { public void endVisit(ParenthesizedExpression node) { if (this.helperVisitor.consumermap.containsKey(VisitorEnum.ParenthesizedExpression)) { ((BiConsumer) (this.helperVisitor.consumermap.get(VisitorEnum.ParenthesizedExpression))) - .accept(node, this.helperVisitor.dataholder); + .accept(node, this.helperVisitor.dataholder); } } @@ -1652,7 +1630,7 @@ public void endVisit(SimpleType node) { public void endVisit(SingleMemberAnnotation node) { if (this.helperVisitor.consumermap.containsKey(VisitorEnum.SingleMemberAnnotation)) { ((BiConsumer) (this.helperVisitor.consumermap.get(VisitorEnum.SingleMemberAnnotation))) - .accept(node, this.helperVisitor.dataholder); + .accept(node, this.helperVisitor.dataholder); } } @@ -1660,7 +1638,7 @@ public void endVisit(SingleMemberAnnotation node) { public void endVisit(SingleVariableDeclaration node) { if (this.helperVisitor.consumermap.containsKey(VisitorEnum.SingleVariableDeclaration)) { ((BiConsumer) (this.helperVisitor.consumermap.get(VisitorEnum.SingleVariableDeclaration))) - .accept(node, this.helperVisitor.dataholder); + .accept(node, this.helperVisitor.dataholder); } } @@ -1675,7 +1653,7 @@ public void endVisit(StringLiteral node) { public void endVisit(SuperConstructorInvocation node) { if (this.helperVisitor.consumermap.containsKey(VisitorEnum.SuperConstructorInvocation)) { ((BiConsumer) (this.helperVisitor.consumermap.get(VisitorEnum.SuperConstructorInvocation))) - .accept(node, this.helperVisitor.dataholder); + .accept(node, this.helperVisitor.dataholder); } } @@ -1691,7 +1669,7 @@ public void endVisit(SuperFieldAccess node) { public void endVisit(SuperMethodInvocation node) { if (this.helperVisitor.consumermap.containsKey(VisitorEnum.SuperMethodInvocation)) { ((BiConsumer) (this.helperVisitor.consumermap.get(VisitorEnum.SuperMethodInvocation))) - .accept(node, this.helperVisitor.dataholder); + .accept(node, this.helperVisitor.dataholder); } } @@ -1730,7 +1708,7 @@ public void endVisit(SwitchStatement node) { public void endVisit(SynchronizedStatement node) { if (this.helperVisitor.consumermap.containsKey(VisitorEnum.SynchronizedStatement)) { ((BiConsumer) (this.helperVisitor.consumermap.get(VisitorEnum.SynchronizedStatement))) - .accept(node, this.helperVisitor.dataholder); + .accept(node, this.helperVisitor.dataholder); } } @@ -1790,7 +1768,7 @@ public void endVisit(TypeDeclaration node) { public void endVisit(TypeDeclarationStatement node) { if (this.helperVisitor.consumermap.containsKey(VisitorEnum.TypeDeclarationStatement)) { ((BiConsumer) (this.helperVisitor.consumermap.get(VisitorEnum.TypeDeclarationStatement))) - .accept(node, this.helperVisitor.dataholder); + .accept(node, this.helperVisitor.dataholder); } } diff --git a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/UseExplicitEncodingFixCore.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/UseExplicitEncodingFixCore.java index 8bf311e2..495d1880 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/UseExplicitEncodingFixCore.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/UseExplicitEncodingFixCore.java @@ -25,6 +25,7 @@ import org.eclipse.jdt.internal.corext.dom.ASTNodes; import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.fix.LinkedProposalModelCore; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.Messages; @@ -81,21 +82,21 @@ public String getPreview(boolean i, ChangeBehavior cb) { return explicitencoding.getPreview(i,cb); } /** - * Compute set of CompilationUnitRewriteOperation to refactor supported situations using default encoding to make use of explicit calls + * Compute set of CompilationUnitRewriteOperationWithSourceRange to refactor supported situations using default encoding to make use of explicit calls * * @param compilationUnit unit to search in * @param operations set of all CompilationUnitRewriteOperations created already * @param nodesprocessed list to remember nodes already processed * @param cb distinguish if you want to keep the same behavior or get code independent of environment */ - public void findOperations(final CompilationUnit compilationUnit,final Set operations,final Set nodesprocessed, ChangeBehavior cb) { + public void findOperations(final CompilationUnit compilationUnit,final Set operations,final Set nodesprocessed, ChangeBehavior cb) { explicitencoding.find(this, compilationUnit, operations, nodesprocessed, cb); } - public CompilationUnitRewriteOperation rewrite(final ASTNode visited, ChangeBehavior cb, ReferenceHolder data) { - return new CompilationUnitRewriteOperation() { + public CompilationUnitRewriteOperationWithSourceRange rewrite(final ASTNode visited, ChangeBehavior cb, ReferenceHolder data) { + return new CompilationUnitRewriteOperationWithSourceRange() { @Override - public void rewriteAST(final CompilationUnitRewrite cuRewrite, final LinkedProposalModelCore linkedModel) throws CoreException { + public void rewriteASTInternal(final CompilationUnitRewrite cuRewrite, final LinkedProposalModelCore linkedModel) throws CoreException { TextEditGroup group= createTextEditGroup(Messages.format(MultiFixMessages.ExplicitEncodingCleanUp_description,new Object[] {UseExplicitEncodingFixCore.this.toString(), cb.toString()}), cuRewrite); cuRewrite.getASTRewrite().setTargetSourceRangeComputer(computer); explicitencoding.rewrite(UseExplicitEncodingFixCore.this, visited, cuRewrite, group, cb, data); diff --git a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractExplicitEncoding.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractExplicitEncoding.java index c751c566..a847c998 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractExplicitEncoding.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractExplicitEncoding.java @@ -21,8 +21,6 @@ import java.util.Map; import java.util.Set; -import org.eclipse.text.edits.TextEditGroup; - import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; @@ -31,10 +29,10 @@ import org.eclipse.jdt.core.dom.MethodInvocation; import org.eclipse.jdt.core.dom.Name; import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; - import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; +import org.eclipse.text.edits.TextEditGroup; import org.sandbox.jdt.internal.common.ReferenceHolder; import org.sandbox.jdt.internal.corext.fix.UseExplicitEncodingFixCore; @@ -51,7 +49,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; @@ -63,7 +61,7 @@ static class Nodedata { protected static final String ENCODING = "encoding"; //$NON-NLS-1$ protected static final String REPLACE = "replace"; //$NON-NLS-1$ - public abstract void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed, ChangeBehavior cb); + public abstract void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed, ChangeBehavior cb); public abstract void rewrite(UseExplicitEncodingFixCore useExplicitEncodingFixCore, T visited, CompilationUnitRewrite cuRewrite, @@ -72,7 +70,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 +78,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 +93,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/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/ByteArrayOutputStreamExplicitEncoding.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/ByteArrayOutputStreamExplicitEncoding.java index eb44d1a7..e5ec3c84 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/ByteArrayOutputStreamExplicitEncoding.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/ByteArrayOutputStreamExplicitEncoding.java @@ -32,7 +32,7 @@ import org.sandbox.jdt.internal.common.ReferenceHolder; import org.eclipse.jdt.internal.corext.dom.ASTNodes; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; @@ -60,7 +60,7 @@ public class ByteArrayOutputStreamExplicitEncoding extends AbstractExplicitEncoding { @Override - public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { + public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { if (!JavaModelUtil.is10OrHigher(compilationUnit.getJavaElement().getJavaProject())) { /** * For Java 9 and older just do nothing @@ -71,7 +71,7 @@ public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilation HelperVisitor.callMethodInvocationVisitor(ByteArrayOutputStream.class, METHOD_TOSTRING, compilationUnit, holder, nodesprocessed, (visited, aholder) -> processFoundNode(fixcore, operations, cb, visited, aholder)); } - private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set operations, + private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set operations, ChangeBehavior cb, MethodInvocation visited, ReferenceHolder holder) { List arguments= visited.arguments(); @@ -125,13 +125,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; } @@ -152,4 +152,9 @@ public String getPreview(boolean afterRefactoring,ChangeBehavior cb) { } """; //$NON-NLS-1$ } + + @Override + public String toString() { + return "ba.toString()"; //$NON-NLS-1$ + } } diff --git a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/ChannelsNewReaderExplicitEncoding.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/ChannelsNewReaderExplicitEncoding.java index 26719909..d745022f 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/ChannelsNewReaderExplicitEncoding.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/ChannelsNewReaderExplicitEncoding.java @@ -32,7 +32,7 @@ import org.sandbox.jdt.internal.common.HelperVisitor; import org.sandbox.jdt.internal.common.ReferenceHolder; import org.eclipse.jdt.internal.corext.dom.ASTNodes; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; import org.sandbox.jdt.internal.corext.fix.UseExplicitEncodingFixCore; @@ -49,7 +49,7 @@ public class ChannelsNewReaderExplicitEncoding extends AbstractExplicitEncoding { @Override - public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { + public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { if (!JavaModelUtil.is10OrHigher(compilationUnit.getJavaElement().getJavaProject())) { /** * For Java 9 and older just do nothing @@ -61,7 +61,7 @@ public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilation } private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, - Set operations, ChangeBehavior cb, + Set operations, ChangeBehavior cb, MethodInvocation visited, ReferenceHolder holder) { List arguments= visited.arguments(); if (ASTNodes.usesGivenSignature(visited, Channels.class.getCanonicalName(), METHOD_NEW_READER, ReadableByteChannel.class.getCanonicalName(),String.class.getCanonicalName())) { @@ -106,4 +106,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/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/ChannelsNewWriterExplicitEncoding.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/ChannelsNewWriterExplicitEncoding.java index fb91142f..e3f36a16 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/ChannelsNewWriterExplicitEncoding.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/ChannelsNewWriterExplicitEncoding.java @@ -20,8 +20,6 @@ import java.util.List; import java.util.Set; -import org.eclipse.text.edits.TextEditGroup; - import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; @@ -29,13 +27,13 @@ import org.eclipse.jdt.core.dom.StringLiteral; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; import org.eclipse.jdt.core.dom.rewrite.ListRewrite; - -import org.sandbox.jdt.internal.common.HelperVisitor; -import org.sandbox.jdt.internal.common.ReferenceHolder; import org.eclipse.jdt.internal.corext.dom.ASTNodes; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; +import org.eclipse.text.edits.TextEditGroup; +import org.sandbox.jdt.internal.common.HelperVisitor; +import org.sandbox.jdt.internal.common.ReferenceHolder; import org.sandbox.jdt.internal.corext.fix.UseExplicitEncodingFixCore; /** * Java 10 @@ -48,7 +46,7 @@ public class ChannelsNewWriterExplicitEncoding extends AbstractExplicitEncoding { @Override - public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { + public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { if (!JavaModelUtil.is10OrHigher(compilationUnit.getJavaElement().getJavaProject())) { /** * For Java 9 and older just do nothing @@ -60,7 +58,7 @@ public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilation } private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, - Set operations, ChangeBehavior cb, + Set operations, ChangeBehavior cb, MethodInvocation visited, ReferenceHolder holder) { List arguments= visited.arguments(); if (ASTNodes.usesGivenSignature(visited, Channels.class.getCanonicalName(), METHOD_NEW_WRITER, WritableByteChannel.class.getCanonicalName(),String.class.getCanonicalName())) { @@ -105,4 +103,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/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/CharsetForNameExplicitEncoding.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/CharsetForNameExplicitEncoding.java index 60e008b9..887a5751 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/CharsetForNameExplicitEncoding.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/CharsetForNameExplicitEncoding.java @@ -19,20 +19,17 @@ import java.util.List; import java.util.Set; -import org.eclipse.text.edits.TextEditGroup; - import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.MethodInvocation; import org.eclipse.jdt.core.dom.StringLiteral; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; - - import org.eclipse.jdt.internal.corext.dom.ASTNodes; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; +import org.eclipse.text.edits.TextEditGroup; import org.sandbox.jdt.internal.common.HelperVisitor; import org.sandbox.jdt.internal.common.ReferenceHolder; import org.sandbox.jdt.internal.corext.fix.UseExplicitEncodingFixCore; @@ -50,7 +47,7 @@ public class CharsetForNameExplicitEncoding extends AbstractExplicitEncoding { @Override - public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { + public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { if (!JavaModelUtil.is18OrHigher(compilationUnit.getJavaElement().getJavaProject())) { /** * For Java 17 and older just do nothing @@ -62,7 +59,7 @@ public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilation } private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, - Set operations, ChangeBehavior cb, + Set operations, ChangeBehavior cb, MethodInvocation visited, ReferenceHolder holder) { List arguments= visited.arguments(); if (!ASTNodes.usesGivenSignature(visited, Charset.class.getCanonicalName(), METHOD_FOR_NAME, String.class.getCanonicalName())) { @@ -95,10 +92,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/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/FileReaderExplicitEncoding.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/FileReaderExplicitEncoding.java index cea771e4..90aa2409 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/FileReaderExplicitEncoding.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/FileReaderExplicitEncoding.java @@ -19,20 +19,17 @@ import java.util.List; import java.util.Set; -import org.eclipse.text.edits.TextEditGroup; - import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ClassInstanceCreation; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.StringLiteral; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; - - import org.eclipse.jdt.internal.corext.dom.ASTNodes; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; +import org.eclipse.text.edits.TextEditGroup; import org.sandbox.jdt.internal.common.HelperVisitor; import org.sandbox.jdt.internal.common.ReferenceHolder; import org.sandbox.jdt.internal.corext.fix.UseExplicitEncodingFixCore; @@ -49,13 +46,13 @@ public class FileReaderExplicitEncoding extends AbstractExplicitEncoding { @Override - public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { + public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { ReferenceHolder datah= new ReferenceHolder<>(); HelperVisitor.callClassInstanceCreationVisitor(FileReader.class, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, cb, visited, holder)); } private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, - Set operations, ChangeBehavior cb, + Set operations, ChangeBehavior cb, ClassInstanceCreation visited, ReferenceHolder holder) { List arguments= visited.arguments(); switch (arguments.size()) { @@ -114,4 +111,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/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/FileWriterExplicitEncoding.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/FileWriterExplicitEncoding.java index ff435504..61f20d99 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/FileWriterExplicitEncoding.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/FileWriterExplicitEncoding.java @@ -18,18 +18,16 @@ import java.io.OutputStreamWriter; import java.util.Set; -import org.eclipse.text.edits.TextEditGroup; - import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ClassInstanceCreation; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; - import org.eclipse.jdt.internal.corext.dom.ASTNodes; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; +import org.eclipse.text.edits.TextEditGroup; import org.sandbox.jdt.internal.common.HelperVisitor; import org.sandbox.jdt.internal.common.ReferenceHolder; import org.sandbox.jdt.internal.corext.fix.UseExplicitEncodingFixCore; @@ -45,12 +43,12 @@ public class FileWriterExplicitEncoding extends AbstractExplicitEncoding { @Override - public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { + public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { ReferenceHolder datah= new ReferenceHolder<>(); HelperVisitor.callClassInstanceCreationVisitor(FileWriter.class, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, cb, visited, holder)); } - private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set operations, + private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set operations, ChangeBehavior cb, ClassInstanceCreation visited, ReferenceHolder holder) { operations.add(fixcore.rewrite(visited, cb, holder)); @@ -93,4 +91,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/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/FormatterExplicitEncoding.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/FormatterExplicitEncoding.java index 5cf73994..7b6ccfbf 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/FormatterExplicitEncoding.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/FormatterExplicitEncoding.java @@ -17,8 +17,6 @@ import java.util.List; import java.util.Set; -import org.eclipse.text.edits.TextEditGroup; - import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ClassInstanceCreation; @@ -26,10 +24,10 @@ import org.eclipse.jdt.core.dom.StringLiteral; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; import org.eclipse.jdt.core.dom.rewrite.ListRewrite; - -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; +import org.eclipse.text.edits.TextEditGroup; import org.sandbox.jdt.internal.common.HelperVisitor; import org.sandbox.jdt.internal.common.ReferenceHolder; import org.sandbox.jdt.internal.corext.fix.UseExplicitEncodingFixCore; @@ -69,13 +67,13 @@ public class FormatterExplicitEncoding extends AbstractExplicitEncoding { @Override - public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { + public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { ReferenceHolder datah= new ReferenceHolder<>(); HelperVisitor.callClassInstanceCreationVisitor(Formatter.class, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, cb, visited, holder)); } private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, - Set operations, ChangeBehavior cb, + Set operations, ChangeBehavior cb, ClassInstanceCreation visited, ReferenceHolder holder) { List arguments= visited.arguments(); switch (arguments.size()) { @@ -139,4 +137,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/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/InputStreamReaderExplicitEncoding.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/InputStreamReaderExplicitEncoding.java index 466f4820..6a03e258 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/InputStreamReaderExplicitEncoding.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/InputStreamReaderExplicitEncoding.java @@ -17,8 +17,6 @@ import java.util.List; import java.util.Set; -import org.eclipse.text.edits.TextEditGroup; - import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ClassInstanceCreation; @@ -26,10 +24,10 @@ import org.eclipse.jdt.core.dom.StringLiteral; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; import org.eclipse.jdt.core.dom.rewrite.ListRewrite; - -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; +import org.eclipse.text.edits.TextEditGroup; import org.sandbox.jdt.internal.common.HelperVisitor; import org.sandbox.jdt.internal.common.ReferenceHolder; import org.sandbox.jdt.internal.corext.fix.UseExplicitEncodingFixCore; @@ -45,13 +43,13 @@ public class InputStreamReaderExplicitEncoding extends AbstractExplicitEncoding { @Override - public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { + public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { ReferenceHolder datah= new ReferenceHolder<>(); HelperVisitor.callClassInstanceCreationVisitor(InputStreamReader.class, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, cb, visited, holder)); } private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, - Set operations, ChangeBehavior cb, + Set operations, ChangeBehavior cb, ClassInstanceCreation visited, ReferenceHolder holder) { List arguments= visited.arguments(); switch (arguments.size()) { @@ -115,4 +113,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/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/OutputStreamWriterExplicitEncoding.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/OutputStreamWriterExplicitEncoding.java index 9bbcad35..bff5e6bc 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/OutputStreamWriterExplicitEncoding.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/OutputStreamWriterExplicitEncoding.java @@ -17,8 +17,6 @@ import java.util.List; import java.util.Set; -import org.eclipse.text.edits.TextEditGroup; - import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ClassInstanceCreation; @@ -26,10 +24,10 @@ import org.eclipse.jdt.core.dom.StringLiteral; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; import org.eclipse.jdt.core.dom.rewrite.ListRewrite; - -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; +import org.eclipse.text.edits.TextEditGroup; import org.sandbox.jdt.internal.common.HelperVisitor; import org.sandbox.jdt.internal.common.ReferenceHolder; import org.sandbox.jdt.internal.corext.fix.UseExplicitEncodingFixCore; @@ -57,13 +55,13 @@ public class OutputStreamWriterExplicitEncoding extends AbstractExplicitEncoding { @Override - public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { + public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { ReferenceHolder datah= new ReferenceHolder<>(); HelperVisitor.callClassInstanceCreationVisitor(OutputStreamWriter.class, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, cb, visited, holder)); } private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, - Set operations, ChangeBehavior cb, + Set operations, ChangeBehavior cb, ClassInstanceCreation visited, ReferenceHolder holder) { List arguments= visited.arguments(); switch (arguments.size()) { @@ -127,4 +125,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/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/PrintStreamExplicitEncoding.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/PrintStreamExplicitEncoding.java index c71dd555..41def82a 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/PrintStreamExplicitEncoding.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/PrintStreamExplicitEncoding.java @@ -20,19 +20,17 @@ import java.util.List; import java.util.Set; -import org.eclipse.text.edits.TextEditGroup; - import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ClassInstanceCreation; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.StringLiteral; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; - import org.eclipse.jdt.internal.corext.dom.ASTNodes; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; +import org.eclipse.text.edits.TextEditGroup; import org.sandbox.jdt.internal.common.HelperVisitor; import org.sandbox.jdt.internal.common.ReferenceHolder; import org.sandbox.jdt.internal.corext.fix.UseExplicitEncodingFixCore; @@ -55,12 +53,12 @@ public class PrintStreamExplicitEncoding extends AbstractExplicitEncoding { @Override - public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { + public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { ReferenceHolder datah= new ReferenceHolder<>(); HelperVisitor.callClassInstanceCreationVisitor(PrintStream.class, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, cb, visited, holder)); } - private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set operations, + private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set operations, ChangeBehavior cb, ClassInstanceCreation visited, ReferenceHolder holder) { List arguments= visited.arguments(); @@ -142,4 +140,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/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/PrintWriterExplicitEncoding.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/PrintWriterExplicitEncoding.java index 2df39d9f..54d0f05c 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/PrintWriterExplicitEncoding.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/PrintWriterExplicitEncoding.java @@ -19,18 +19,16 @@ import java.io.PrintWriter; import java.util.Set; -import org.eclipse.text.edits.TextEditGroup; - import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ClassInstanceCreation; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; - import org.eclipse.jdt.internal.corext.dom.ASTNodes; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; +import org.eclipse.text.edits.TextEditGroup; import org.sandbox.jdt.internal.common.HelperVisitor; import org.sandbox.jdt.internal.common.ReferenceHolder; import org.sandbox.jdt.internal.corext.fix.UseExplicitEncodingFixCore; @@ -54,7 +52,7 @@ public class PrintWriterExplicitEncoding extends AbstractExplicitEncoding { @Override - public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { + public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { if (!JavaModelUtil.is10OrHigher(compilationUnit.getJavaElement().getJavaProject())) { /** * For Java 9 and older just do nothing @@ -65,7 +63,7 @@ public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilation HelperVisitor.callClassInstanceCreationVisitor(PrintWriter.class, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, cb, visited, holder)); } - private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set operations, + private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set operations, ChangeBehavior cb, ClassInstanceCreation visited, ReferenceHolder holder) { operations.add(fixcore.rewrite(visited, cb, holder)); @@ -108,4 +106,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/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/PropertiesStoreToXMLExplicitEncoding.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/PropertiesStoreToXMLExplicitEncoding.java index a48b0646..8da7868b 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/PropertiesStoreToXMLExplicitEncoding.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/PropertiesStoreToXMLExplicitEncoding.java @@ -19,8 +19,6 @@ import java.util.Properties; import java.util.Set; -import org.eclipse.text.edits.TextEditGroup; - import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; @@ -28,10 +26,10 @@ import org.eclipse.jdt.core.dom.StringLiteral; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; import org.eclipse.jdt.core.dom.rewrite.ListRewrite; - -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; +import org.eclipse.text.edits.TextEditGroup; import org.sandbox.jdt.internal.common.HelperVisitor; import org.sandbox.jdt.internal.common.ReferenceHolder; import org.sandbox.jdt.internal.corext.fix.UseExplicitEncodingFixCore; @@ -48,13 +46,13 @@ public class PropertiesStoreToXMLExplicitEncoding extends AbstractExplicitEncoding { @Override - public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { + public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { ReferenceHolder datah= new ReferenceHolder<>(); HelperVisitor.callMethodInvocationVisitor(Properties.class, METHOD_STORE_TO_XML, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, cb, visited, holder)); } private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, - Set operations, ChangeBehavior cb, + Set operations, ChangeBehavior cb, MethodInvocation visited, ReferenceHolder holder) { List arguments= visited.arguments(); switch (arguments.size()) { @@ -114,9 +112,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/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/ScannerExplicitEncoding.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/ScannerExplicitEncoding.java index 8ebcf168..6c6fb13a 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/ScannerExplicitEncoding.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/ScannerExplicitEncoding.java @@ -17,8 +17,6 @@ import java.util.Scanner; import java.util.Set; -import org.eclipse.text.edits.TextEditGroup; - import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ClassInstanceCreation; @@ -26,10 +24,10 @@ import org.eclipse.jdt.core.dom.StringLiteral; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; import org.eclipse.jdt.core.dom.rewrite.ListRewrite; - -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; +import org.eclipse.text.edits.TextEditGroup; import org.sandbox.jdt.internal.common.HelperVisitor; import org.sandbox.jdt.internal.common.ReferenceHolder; import org.sandbox.jdt.internal.corext.fix.UseExplicitEncodingFixCore; @@ -58,7 +56,7 @@ public class ScannerExplicitEncoding extends AbstractExplicitEncoding { @Override - public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { + public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { if (!JavaModelUtil.is10OrHigher(compilationUnit.getJavaElement().getJavaProject())) { /** * For Java 9 and older just do nothing @@ -69,7 +67,7 @@ public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilation HelperVisitor.callClassInstanceCreationVisitor(Scanner.class, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, cb, visited, holder)); } - private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set operations, + private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set operations, ChangeBehavior cb, ClassInstanceCreation visited, ReferenceHolder holder) { List arguments= visited.arguments(); @@ -139,8 +137,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/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/StringExplicitEncoding.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/StringExplicitEncoding.java index c9031205..149e891d 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/StringExplicitEncoding.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/StringExplicitEncoding.java @@ -16,8 +16,6 @@ import java.util.List; import java.util.Set; -import org.eclipse.text.edits.TextEditGroup; - import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ClassInstanceCreation; @@ -25,10 +23,10 @@ import org.eclipse.jdt.core.dom.StringLiteral; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; import org.eclipse.jdt.core.dom.rewrite.ListRewrite; - -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; +import org.eclipse.text.edits.TextEditGroup; import org.sandbox.jdt.internal.common.HelperVisitor; import org.sandbox.jdt.internal.common.ReferenceHolder; import org.sandbox.jdt.internal.corext.fix.UseExplicitEncodingFixCore; @@ -50,7 +48,7 @@ public class StringExplicitEncoding extends AbstractExplicitEncoding { @Override - public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { + public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { if (!JavaModelUtil.is10OrHigher(compilationUnit.getJavaElement().getJavaProject())) { /** * For Java 9 and older just do nothing @@ -61,7 +59,7 @@ public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilation HelperVisitor.callClassInstanceCreationVisitor(String.class, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, cb, visited, holder)); } - private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set operations, + private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set operations, ChangeBehavior cb, ClassInstanceCreation visited, ReferenceHolder holder) { List arguments= visited.arguments(); @@ -128,4 +126,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/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/StringGetBytesExplicitEncoding.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/StringGetBytesExplicitEncoding.java index 8089c7c1..7ec86ce0 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/StringGetBytesExplicitEncoding.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/StringGetBytesExplicitEncoding.java @@ -18,8 +18,6 @@ import java.util.List; import java.util.Set; -import org.eclipse.text.edits.TextEditGroup; - import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; @@ -27,10 +25,10 @@ import org.eclipse.jdt.core.dom.StringLiteral; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; import org.eclipse.jdt.core.dom.rewrite.ListRewrite; - -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; +import org.eclipse.text.edits.TextEditGroup; import org.sandbox.jdt.internal.common.HelperVisitor; import org.sandbox.jdt.internal.common.ReferenceHolder; import org.sandbox.jdt.internal.corext.fix.UseExplicitEncodingFixCore; @@ -46,13 +44,13 @@ public class StringGetBytesExplicitEncoding extends AbstractExplicitEncoding { @Override - public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { + public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { ReferenceHolder datah= new ReferenceHolder<>(); HelperVisitor.callMethodInvocationVisitor(String.class, METHOD_GET_BYTES, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, cb, visited, holder)); } private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, - Set operations, ChangeBehavior cb, + Set operations, ChangeBehavior cb, MethodInvocation visited, ReferenceHolder holder) { List arguments= visited.arguments(); switch (arguments.size()) { @@ -116,4 +114,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/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/URLDecoderDecodeExplicitEncoding.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/URLDecoderDecodeExplicitEncoding.java index 4f35a64f..38767d77 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/URLDecoderDecodeExplicitEncoding.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/URLDecoderDecodeExplicitEncoding.java @@ -31,6 +31,7 @@ import org.eclipse.jdt.internal.corext.dom.ASTNodes; import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; import org.sandbox.jdt.internal.common.HelperVisitor; @@ -62,7 +63,7 @@ public class URLDecoderDecodeExplicitEncoding extends AbstractExplicitEncoding { @Override - public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { + public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { if (!JavaModelUtil.is10OrHigher(compilationUnit.getJavaElement().getJavaProject())) { /** * For Java 9 and older just do nothing @@ -74,7 +75,7 @@ public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilation } private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, - Set operations, ChangeBehavior cb, + Set operations, ChangeBehavior cb, MethodInvocation visited, ReferenceHolder holder) { List arguments= visited.arguments(); if (ASTNodes.usesGivenSignature(visited, URLDecoder.class.getCanonicalName(), METHOD_DECODE, String.class.getCanonicalName(),String.class.getCanonicalName())) { @@ -93,13 +94,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 +138,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/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/URLEncoderEncodeExplicitEncoding.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/URLEncoderEncodeExplicitEncoding.java index 419ba106..a051648b 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/URLEncoderEncodeExplicitEncoding.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/corext/fix/helper/URLEncoderEncodeExplicitEncoding.java @@ -31,6 +31,7 @@ import org.eclipse.jdt.internal.corext.dom.ASTNodes; import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; import org.sandbox.jdt.internal.common.HelperVisitor; @@ -62,7 +63,7 @@ public class URLEncoderEncodeExplicitEncoding extends AbstractExplicitEncoding { @Override - public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { + public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set operations, Set nodesprocessed,ChangeBehavior cb) { if (!JavaModelUtil.is10OrHigher(compilationUnit.getJavaElement().getJavaProject())) { /** * For Java 9 and older just do nothing @@ -74,7 +75,7 @@ public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilation } private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, - Set operations, ChangeBehavior cb, + Set operations, ChangeBehavior cb, MethodInvocation visited, ReferenceHolder holder) { List arguments= visited.arguments(); if (ASTNodes.usesGivenSignature(visited, URLEncoder.class.getCanonicalName(), METHOD_ENCODE, String.class.getCanonicalName(),String.class.getCanonicalName())) { @@ -93,13 +94,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 +138,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/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/ui/fix/UseExplicitEncodingCleanUpCore.java b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/ui/fix/UseExplicitEncodingCleanUpCore.java index 4e6c7999..10b710d0 100644 --- a/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/ui/fix/UseExplicitEncodingCleanUpCore.java +++ b/sandbox_encoding_quickfix/src/org/sandbox/jdt/internal/ui/fix/UseExplicitEncodingCleanUpCore.java @@ -32,9 +32,8 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFix; import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.util.Messages; import org.eclipse.jdt.internal.ui.fix.AbstractCleanUp; import org.eclipse.jdt.ui.cleanup.CleanUpContext; @@ -70,26 +69,26 @@ public ICleanUpFix createFix(final CleanUpContext context) throws CoreException } ChangeBehavior cb= computeRefactorDeepth(); - Set operations= new LinkedHashSet<>(); + Set operations= new LinkedHashSet<>(); Set nodesprocessed= new HashSet<>(); computeFixSet.forEach(i->i.findOperations(compilationUnit,operations,nodesprocessed,cb)); if (operations.isEmpty()) { return null; } - return new CompilationUnitRewriteOperationsFix(ExplicitEncodingCleanUpFix_refactor, - compilationUnit, operations.toArray(new CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation[0])); + return new CompilationUnitRewriteOperationsFixCore(ExplicitEncodingCleanUpFix_refactor, + compilationUnit, operations.toArray(new CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange[0])); } 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; } @@ -121,4 +120,4 @@ private EnumSet computeFixSet() { } return fixSet; } -} \ No newline at end of file +} diff --git a/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/corext/fix/JfaceCleanUpFixCore.java b/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/corext/fix/JfaceCleanUpFixCore.java index e73dad4f..3eb37428 100644 --- a/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/corext/fix/JfaceCleanUpFixCore.java +++ b/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/corext/fix/JfaceCleanUpFixCore.java @@ -19,7 +19,7 @@ import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.fix.LinkedProposalModelCore; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.refactoring.util.TightSourceRangeComputer; @@ -57,15 +57,15 @@ public String getPreview(boolean i) { * loop var used within */ public void findOperations(final CompilationUnit compilationUnit, - final Set operations, final Set nodesprocessed, + final Set operations, final Set nodesprocessed, boolean createForOnlyIfVarUsed) { jfacefound.find(this, compilationUnit, operations, nodesprocessed, createForOnlyIfVarUsed); } - public CompilationUnitRewriteOperation rewrite(final ReferenceHolder hit) { - return new CompilationUnitRewriteOperation() { + public CompilationUnitRewriteOperationWithSourceRange rewrite(final ReferenceHolder hit) { + return new CompilationUnitRewriteOperationWithSourceRange() { @Override - public void rewriteAST(final CompilationUnitRewrite cuRewrite, final LinkedProposalModelCore linkedModel) + public void rewriteASTInternal(final CompilationUnitRewrite cuRewrite, final LinkedProposalModelCore linkedModel) throws CoreException { TextEditGroup group= createTextEditGroup(MultiFixMessages.JFaceCleanUp_description, cuRewrite); TightSourceRangeComputer rangeComputer; diff --git a/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java b/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java index be6bc1fb..6f8562fe 100644 --- a/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java +++ b/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java @@ -23,7 +23,7 @@ import org.eclipse.jdt.core.dom.Name; import org.eclipse.jdt.internal.corext.dom.AbortSearchException; import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.text.edits.TextEditGroup; import org.sandbox.jdt.internal.corext.fix.JfaceCleanUpFixCore; @@ -44,7 +44,7 @@ protected static boolean isOfType(ITypeBinding typeBinding, String typename) { } public abstract void find(JfaceCleanUpFixCore fixcore, CompilationUnit compilationUnit, - Set operations, Set nodesprocessed, + Set operations, Set nodesprocessed, boolean createForIfVarNotUsed); public abstract void rewrite(JfaceCleanUpFixCore useExplicitEncodingFixCore, T holder, diff --git a/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/JFacePlugin.java b/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/JFacePlugin.java index da2e5742..b130a0e9 100644 --- a/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/JFacePlugin.java +++ b/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/JFacePlugin.java @@ -34,7 +34,7 @@ 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.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.text.edits.TextEditGroup; import org.sandbox.jdt.internal.common.ASTProcessor; @@ -86,7 +86,7 @@ public static class MonitorHolder { @Override public void find(JfaceCleanUpFixCore fixcore, CompilationUnit compilationUnit, - Set operations, Set nodesprocessed, + Set operations, Set nodesprocessed, boolean createForOnlyIfVarUsed) { int i = 0; ReferenceHolder dataholder = new ReferenceHolder<>(); diff --git a/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/ui/fix/JFaceCleanUpCore.java b/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/ui/fix/JFaceCleanUpCore.java index 7bf2f4f0..2ec9166a 100644 --- a/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/ui/fix/JFaceCleanUpCore.java +++ b/sandbox_jface_cleanup/src/org/sandbox/jdt/internal/ui/fix/JFaceCleanUpCore.java @@ -30,7 +30,7 @@ import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; import org.eclipse.jdt.internal.corext.util.Messages; import org.eclipse.jdt.internal.ui.fix.AbstractCleanUp; @@ -69,7 +69,7 @@ public ICleanUpFix createFix(final CleanUpContext context) throws CoreException || !JavaModelUtil.is1d8OrHigher(compilationUnit.getJavaElement().getJavaProject())) { return null; } - Set operations= new LinkedHashSet<>(); + Set operations= new LinkedHashSet<>(); Set nodesprocessed= new HashSet<>(); computeFixSet.forEach(i -> i.findOperations(compilationUnit, operations, nodesprocessed, true)); @@ -77,7 +77,7 @@ public ICleanUpFix createFix(final CleanUpContext context) throws CoreException return null; } return new CompilationUnitRewriteOperationsFixCore(JFaceCleanUpFix_refactor, compilationUnit, - operations.toArray(new CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation[0])); + operations.toArray(new CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange[0])); } @Override diff --git a/sandbox_platform_helper/src/org/sandbox/jdt/internal/corext/fix/SimplifyPlatformStatusFixCore.java b/sandbox_platform_helper/src/org/sandbox/jdt/internal/corext/fix/SimplifyPlatformStatusFixCore.java index 97937585..790f6ced 100644 --- a/sandbox_platform_helper/src/org/sandbox/jdt/internal/corext/fix/SimplifyPlatformStatusFixCore.java +++ b/sandbox_platform_helper/src/org/sandbox/jdt/internal/corext/fix/SimplifyPlatformStatusFixCore.java @@ -21,7 +21,7 @@ import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.rewrite.TargetSourceRangeComputer; import org.eclipse.jdt.internal.corext.dom.ASTNodes; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.fix.LinkedProposalModelCore; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.util.Messages; @@ -61,15 +61,15 @@ public String getPreview(boolean i) { * @throws CoreException */ public void findOperations(final CompilationUnit compilationUnit, - final Set operations, final Set nodesprocessed) + final Set operations, final Set nodesprocessed) throws CoreException { platformstatus.find(this, compilationUnit, operations, nodesprocessed); } - public CompilationUnitRewriteOperation rewrite(final ClassInstanceCreation visited, ReferenceHolder holder) { - return new CompilationUnitRewriteOperation() { + public CompilationUnitRewriteOperationWithSourceRange rewrite(final ClassInstanceCreation visited, ReferenceHolder holder) { + return new CompilationUnitRewriteOperationWithSourceRange() { @Override - public void rewriteAST(final CompilationUnitRewrite cuRewrite, final LinkedProposalModelCore linkedModel) + public void rewriteASTInternal(final CompilationUnitRewrite cuRewrite, final LinkedProposalModelCore linkedModel) throws CoreException { TextEditGroup group= createTextEditGroup( Messages.format(MultiFixMessages.PlatformStatusCleanUp_description, diff --git a/sandbox_platform_helper/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractSimplifyPlatformStatus.java b/sandbox_platform_helper/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractSimplifyPlatformStatus.java index 6ecb260e..d7071057 100644 --- a/sandbox_platform_helper/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractSimplifyPlatformStatus.java +++ b/sandbox_platform_helper/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractSimplifyPlatformStatus.java @@ -31,7 +31,7 @@ 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.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.refactoring.structure.ImportRemover; import org.eclipse.text.edits.TextEditGroup; @@ -69,7 +69,7 @@ protected static Name addImport(String typeName, final CompilationUnitRewrite cu public abstract String getPreview(boolean afterRefactoring); public void find(SimplifyPlatformStatusFixCore fixcore, CompilationUnit compilationUnit, - Set operations, Set nodesprocessed) throws CoreException { + Set operations, Set nodesprocessed) throws CoreException { try { ReferenceHolder dataholder= new ReferenceHolder<>(); HelperVisitor.callClassInstanceCreationVisitor(Status.class, compilationUnit, dataholder, nodesprocessed, (visited, holder) -> { diff --git a/sandbox_platform_helper/src/org/sandbox/jdt/internal/ui/fix/SimplifyPlatformStatusCleanUpCore.java b/sandbox_platform_helper/src/org/sandbox/jdt/internal/ui/fix/SimplifyPlatformStatusCleanUpCore.java index 933f26a7..e0f63ece 100644 --- a/sandbox_platform_helper/src/org/sandbox/jdt/internal/ui/fix/SimplifyPlatformStatusCleanUpCore.java +++ b/sandbox_platform_helper/src/org/sandbox/jdt/internal/ui/fix/SimplifyPlatformStatusCleanUpCore.java @@ -30,7 +30,7 @@ import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; import org.eclipse.jdt.internal.corext.util.Messages; import org.eclipse.jdt.internal.ui.fix.AbstractCleanUp; @@ -67,7 +67,7 @@ public ICleanUpFix createFix(final CleanUpContext context) throws CoreException || !JavaModelUtil.is9OrHigher(compilationUnit.getJavaElement().getJavaProject())) { return null; } - Set operations= new LinkedHashSet<>(); + Set operations= new LinkedHashSet<>(); Set nodesprocessed= new HashSet<>(); for (var i : computeFixSet) { i.findOperations(compilationUnit, operations, nodesprocessed); @@ -76,7 +76,7 @@ public ICleanUpFix createFix(final CleanUpContext context) throws CoreException return null; } return new CompilationUnitRewriteOperationsFixCore(PlatformStatusCleanUpFix_refactor, compilationUnit, - operations.toArray(new CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation[0])); + operations.toArray(new CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange[0])); } @Override diff --git a/sandbox_tools/src/org/sandbox/jdt/internal/corext/fix/UseIteratorToForLoopFixCore.java b/sandbox_tools/src/org/sandbox/jdt/internal/corext/fix/UseIteratorToForLoopFixCore.java index 8cdfccfe..375befa8 100644 --- a/sandbox_tools/src/org/sandbox/jdt/internal/corext/fix/UseIteratorToForLoopFixCore.java +++ b/sandbox_tools/src/org/sandbox/jdt/internal/corext/fix/UseIteratorToForLoopFixCore.java @@ -19,7 +19,7 @@ import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.fix.LinkedProposalModelCore; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.refactoring.util.TightSourceRangeComputer; @@ -56,15 +56,15 @@ public String getPreview(boolean i) { * loop var used within */ public void findOperations(final CompilationUnit compilationUnit, - final Set operations, final Set nodesprocessed, + final Set operations, final Set nodesprocessed, boolean createForOnlyIfVarUsed) { iteratortofor.find(this, compilationUnit, operations, nodesprocessed, createForOnlyIfVarUsed); } - public CompilationUnitRewriteOperation rewrite(final WhileLoopToChangeHit hit) { - return new CompilationUnitRewriteOperation() { + public CompilationUnitRewriteOperationWithSourceRange rewrite(final WhileLoopToChangeHit hit) { + return new CompilationUnitRewriteOperationWithSourceRange() { @Override - public void rewriteAST(final CompilationUnitRewrite cuRewrite, final LinkedProposalModelCore linkedModel) + public void rewriteASTInternal(final CompilationUnitRewrite cuRewrite, final LinkedProposalModelCore linkedModel) throws CoreException { TextEditGroup group= createTextEditGroup(MultiFixMessages.ToolsCleanUp_description, cuRewrite); TightSourceRangeComputer rangeComputer; diff --git a/sandbox_tools/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java b/sandbox_tools/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java index 2bc9f931..7db37b6a 100644 --- a/sandbox_tools/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java +++ b/sandbox_tools/src/org/sandbox/jdt/internal/corext/fix/helper/AbstractTool.java @@ -23,7 +23,7 @@ import org.eclipse.jdt.core.dom.Name; import org.eclipse.jdt.internal.corext.dom.AbortSearchException; import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.text.edits.TextEditGroup; import org.sandbox.jdt.internal.corext.fix.UseIteratorToForLoopFixCore; @@ -44,7 +44,7 @@ protected static boolean isOfType(ITypeBinding typeBinding, String typename) { } public abstract void find(UseIteratorToForLoopFixCore fixcore, CompilationUnit compilationUnit, - Set operations, Set nodesprocessed, + Set operations, Set nodesprocessed, boolean createForIfVarNotUsed); public abstract void rewrite(UseIteratorToForLoopFixCore useExplicitEncodingFixCore, T holder, diff --git a/sandbox_tools/src/org/sandbox/jdt/internal/corext/fix/helper/WhileToForEach.java b/sandbox_tools/src/org/sandbox/jdt/internal/corext/fix/helper/WhileToForEach.java index e6d9661e..77e264a7 100644 --- a/sandbox_tools/src/org/sandbox/jdt/internal/corext/fix/helper/WhileToForEach.java +++ b/sandbox_tools/src/org/sandbox/jdt/internal/corext/fix/helper/WhileToForEach.java @@ -53,7 +53,7 @@ import org.eclipse.jdt.internal.corext.dom.ASTNodes; import org.eclipse.jdt.internal.corext.dom.AbortSearchException; import org.eclipse.jdt.internal.corext.dom.Bindings; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.fix.ConvertLoopOperation; import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; import org.eclipse.jdt.internal.corext.refactoring.structure.ImportRemover; @@ -72,7 +72,7 @@ public class WhileToForEach extends AbstractTool { @Override public void find(UseIteratorToForLoopFixCore fixcore, CompilationUnit compilationUnit, - Set operations, Set nodesprocessed, + Set operations, Set nodesprocessed, boolean createForOnlyIfVarUsed) { ReferenceHolder dataholder= new ReferenceHolder<>(); Map operationsMap= new LinkedHashMap<>(); diff --git a/sandbox_tools/src/org/sandbox/jdt/internal/ui/fix/UseIteratorToForLoopCleanUpCore.java b/sandbox_tools/src/org/sandbox/jdt/internal/ui/fix/UseIteratorToForLoopCleanUpCore.java index 7071bb63..26c63dfd 100644 --- a/sandbox_tools/src/org/sandbox/jdt/internal/ui/fix/UseIteratorToForLoopCleanUpCore.java +++ b/sandbox_tools/src/org/sandbox/jdt/internal/ui/fix/UseIteratorToForLoopCleanUpCore.java @@ -31,7 +31,7 @@ import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore; -import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; import org.eclipse.jdt.internal.corext.util.Messages; import org.eclipse.jdt.internal.ui.fix.AbstractCleanUp; @@ -68,7 +68,7 @@ public ICleanUpFix createFix(final CleanUpContext context) throws CoreException || !JavaModelUtil.is1d8OrHigher(compilationUnit.getJavaElement().getJavaProject())) { return null; } - Set operations= new LinkedHashSet<>(); + Set operations= new LinkedHashSet<>(); Set nodesprocessed= new HashSet<>(); computeFixSet.forEach(i -> i.findOperations(compilationUnit, operations, nodesprocessed, isEnabled(CONTROL_STATEMENTS_CONVERT_FOR_LOOP_ONLY_IF_LOOP_VAR_USED))); @@ -76,7 +76,7 @@ public ICleanUpFix createFix(final CleanUpContext context) throws CoreException return null; } return new CompilationUnitRewriteOperationsFixCore(ToolsCleanUpFix_refactor, compilationUnit, - operations.toArray(new CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation[0])); + operations.toArray(new CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange[0])); } @Override