From 0f1d64fe649fb32efe820242071310910215c18b Mon Sep 17 00:00:00 2001 From: Carsten Hammer Date: Sat, 14 Sep 2024 17:19:05 +0200 Subject: [PATCH] add missing implementation detail in LambdaASTVisitor what fixes tests --- .../jdt/internal/common/LambdaASTVisitor.java | 22 +++++++++---------- ...ByteArrayOutputStreamExplicitEncoding.java | 2 -- .../fix/helper/FormatterExplicitEncoding.java | 4 +++- .../InputStreamReaderExplicitEncoding.java | 4 +++- .../OutputStreamWriterExplicitEncoding.java | 4 +++- .../fix/helper/ScannerExplicitEncoding.java | 4 +++- .../fix/helper/StringExplicitEncoding.java | 4 +++- .../corext/fix/CleanUpConstantsOptions.java | 2 ++ 8 files changed, 27 insertions(+), 19 deletions(-) diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/common/LambdaASTVisitor.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/common/LambdaASTVisitor.java index b054d145223..e7e8ca6cd59 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/common/LambdaASTVisitor.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/common/LambdaASTVisitor.java @@ -193,6 +193,16 @@ public boolean visit(CharacterLiteral node) { @Override public boolean visit(ClassInstanceCreation node) { if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.ClassInstanceCreation)) { + Map map=(Map) this.helperVisitor.getSupplierData().get(VisitorEnum.ClassInstanceCreation); + if(map != null) { + Class typeof=(Class) map.get(HelperVisitor.TYPEOF); + if(typeof!=null) { + ITypeBinding binding= node.resolveTypeBinding(); + if (!typeof.getSimpleName().equals(binding.getName())) { + return true; + } + } + } return ((BiPredicate) (this.helperVisitor.predicatemap .get(VisitorEnum.ClassInstanceCreation))).test(node, this.helperVisitor.dataholder); } @@ -496,18 +506,6 @@ public boolean visit(MethodDeclaration node) { return true; } -// @Override -// public boolean visit(MethodInvocation node) { -// if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.MethodInvocation)) { -// String data=(String) this.helperVisitor.getSupplierData().get(VisitorEnum.MethodInvocation); -// if (data!= null && !node.getName().getIdentifier().equals(data)) { -// return true; -// } -// return ((BiPredicate) (this.helperVisitor.predicatemap.get(VisitorEnum.MethodInvocation))).test(node, this.helperVisitor.dataholder); -// } -// return true; -// } - @Override public boolean visit(MethodInvocation node) { if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.MethodInvocation)) { 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 6457995cba0..1c3d9b3ae4d 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 @@ -84,7 +84,6 @@ private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set< nd.visited=argstring3; holder.put(visited,nd); operations.add(fixcore.rewrite(visited, cb, holder)); - nodesprocessed.add(visited); return false; } if (ASTNodes.usesGivenSignature(visited, ByteArrayOutputStream.class.getCanonicalName(), METHOD_TOSTRING)) { @@ -94,7 +93,6 @@ private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set< nd2.visited=visited; holder.put(visited,nd2); operations.add(fixcore.rewrite(visited, cb, holder)); - nodesprocessed.add(visited); return false; } return false; 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 e4b1b0c5441..b0f62b175bc 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 @@ -87,6 +87,7 @@ private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, nd.replace=true; nd.visited=argstring3; holder.put(visited,nd); + operations.add(fixcore.rewrite(visited, cb, holder)); break; case 1: Nodedata nd2=new Nodedata(); @@ -94,11 +95,12 @@ private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, nd2.replace=false; nd2.visited=visited; holder.put(visited,nd2); + operations.add(fixcore.rewrite(visited, cb, holder)); break; default: break; } - operations.add(fixcore.rewrite(visited, cb, holder)); + return false; } 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 c5c0e9ff58c..1b78383774e 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 @@ -68,6 +68,7 @@ private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, nd.replace=true; nd.visited=argstring3; holder.put(visited,nd); + operations.add(fixcore.rewrite(visited, cb, holder)); break; case 1: Nodedata nd2=new Nodedata(); @@ -75,11 +76,12 @@ private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, nd2.replace=false; nd2.visited=visited; holder.put(visited,nd2); + operations.add(fixcore.rewrite(visited, cb, holder)); break; default: break; } - operations.add(fixcore.rewrite(visited, cb, holder)); + return false; } 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 ddc174ab78e..502daa7b3d1 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 @@ -80,6 +80,7 @@ private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, nd.replace=true; nd.visited=argstring3; holder.put(visited,nd); + operations.add(fixcore.rewrite(visited, cb, holder)); break; case 1: Nodedata nd2=new Nodedata(); @@ -87,11 +88,12 @@ private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, nd2.replace=false; nd2.visited=visited; holder.put(visited,nd2); + operations.add(fixcore.rewrite(visited, cb, holder)); break; default: break; } - operations.add(fixcore.rewrite(visited, cb, holder)); + return false; } 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 21d1432d35e..5e3637b63d4 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 @@ -78,6 +78,7 @@ private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set< nd.replace=true; nd.visited=argstring4; holder.put(visited,nd); + operations.add(fixcore.rewrite(visited, cb, holder)); break; case 2: if(!(arguments.get(1) instanceof StringLiteral)) { @@ -92,12 +93,13 @@ private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set< nd2.replace=true; nd2.visited=argstring3; holder.put(visited,nd2); + operations.add(fixcore.rewrite(visited, cb, holder)); break; case 1: default: break; } - operations.add(fixcore.rewrite(visited, cb, holder)); + return false; } 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 a1475b85285..b7d90074e9d 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 @@ -73,6 +73,7 @@ private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set< nd.replace=true; nd.visited=argstring4; holder.put(visited,nd); + operations.add(fixcore.rewrite(visited, cb, holder)); break; case 2: if(!(arguments.get(1) instanceof StringLiteral)) { @@ -87,12 +88,13 @@ private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set< nd2.replace=true; nd2.visited=argstring3; holder.put(visited,nd2); + operations.add(fixcore.rewrite(visited, cb, holder)); break; case 1: default: break; } - operations.add(fixcore.rewrite(visited, cb, holder)); + return false; } diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstantsOptions.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstantsOptions.java index 58b2b812db7..a95b90eab52 100644 --- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstantsOptions.java +++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstantsOptions.java @@ -206,6 +206,7 @@ private static void setEclipseDefaultSettings(CleanUpOptions options) { options.setOption(CONTROL_STATEMENTS_CONVERT_FOR_LOOP_ONLY_IF_LOOP_VAR_USED, CleanUpOptions.TRUE); options.setOption(CONTROL_STATEMENTS_USE_ADD_ALL, CleanUpOptions.FALSE); options.setOption(EXPLICITENCODING_CLEANUP, CleanUpOptions.FALSE); + options.setOption(EXPLICITENCODING_KEEP_BEHAVIOR, CleanUpOptions.TRUE); } private static void setSaveParticipantSettings(CleanUpOptions options) { @@ -392,6 +393,7 @@ private static void setSaveParticipantSettings(CleanUpOptions options) { options.setOption(CONTROL_STATEMENTS_CONVERT_FOR_LOOP_ONLY_IF_LOOP_VAR_USED, CleanUpOptions.FALSE); options.setOption(CONTROL_STATEMENTS_USE_ADD_ALL, CleanUpOptions.FALSE); options.setOption(EXPLICITENCODING_CLEANUP, CleanUpOptions.FALSE); + options.setOption(EXPLICITENCODING_KEEP_BEHAVIOR, CleanUpOptions.TRUE); } public static void initDefaults(IPreferenceStore store) {