From 1d5beed586a171caa5a2480ff8da1b7ee3fbefd0 Mon Sep 17 00:00:00 2001 From: Carsten Hammer Date: Sun, 11 Aug 2024 14:39:26 +0200 Subject: [PATCH] fix compilation error because of non static definition of method --- .../helper/FileReaderExplicitEncoding.java | 62 ++++++++----------- .../InputStreamReaderExplicitEncoding.java | 2 +- .../OutputStreamWriterExplicitEncoding.java | 2 +- .../StringGetBytesExplicitEncoding.java | 6 +- 4 files changed, 31 insertions(+), 41 deletions(-) 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 3a208eec..eb141b28 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 @@ -48,48 +48,36 @@ public class FileReaderExplicitEncoding extends AbstractExplicitEncoding operations, Set nodesprocessed,ChangeBehavior cb) { - HelperVisitor.callClassInstanceCreationVisitor(FileReader.class, compilationUnit, datah, nodesprocessed, (visited, holder_a) -> { - List arguments= visited.arguments(); - if(nodesprocessed.contains(visited) || (arguments.size()>2)) { + HelperVisitor.callClassInstanceCreationVisitor(FileReader.class, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, nodesprocessed, cb, visited, holder)); + } + + private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, + Set operations, Set nodesprocessed, ChangeBehavior cb, + ClassInstanceCreation visited, ReferenceHolder holder) { + List arguments= visited.arguments(); + if(nodesprocessed.contains(visited) || (arguments.size()>2)) { + return false; + } + switch (arguments.size()) { + case 1: + break; + case 2: + if(!(arguments.get(1) instanceof StringLiteral)) { return false; } - switch (arguments.size()) { - case 1: - break; - case 2: - if(!(arguments.get(1) instanceof StringLiteral)) { - return false; - } - StringLiteral argstring3= (StringLiteral) arguments.get(1); - if (!("UTF-8".equals(argstring3.getLiteralValue()))) { //$NON-NLS-1$ - return false; - } - holder_a.put(ENCODING,StandardCharsets.UTF_8); - holder_a.put(REPLACE,argstring3); - break; - default: + StringLiteral argstring3= (StringLiteral) arguments.get(1); + if (!("UTF-8".equals(argstring3.getLiteralValue()))) { //$NON-NLS-1$ return false; } - operations.add(fixcore.rewrite(visited, cb, holder_a)); - nodesprocessed.add(visited); + holder.put(ENCODING,StandardCharsets.UTF_8); + holder.put(REPLACE,argstring3); + break; + default: return false; - }); - -// compilationUnit.accept(new ASTVisitor() { -// @Override -// public boolean visit(final ClassInstanceCreation visited) { -// if(nodesprocessed.contains(visited)) { -// return false; -// } -// ITypeBinding binding= visited.resolveTypeBinding(); -// if (FileReader.class.getSimpleName().equals(binding.getName())) { -// operations.add(fixcore.rewrite(visited, cb, datah)); -// nodesprocessed.add(visited); -// return false; -// } -// return true; -// } -// }); + } + operations.add(fixcore.rewrite(visited, cb, holder)); + nodesprocessed.add(visited); + return false; } @Override 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 84eb5906..8f19a092 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 @@ -45,7 +45,7 @@ public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilation HelperVisitor.callClassInstanceCreationVisitor(InputStreamReader.class, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, nodesprocessed, cb, visited, holder)); } - private boolean processFoundNode(UseExplicitEncodingFixCore fixcore, + private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set operations, Set nodesprocessed, ChangeBehavior cb, ClassInstanceCreation visited, ReferenceHolder holder) { List arguments= visited.arguments(); 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 03f70fed..d1450560 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 @@ -48,7 +48,7 @@ public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilation HelperVisitor.callClassInstanceCreationVisitor(OutputStreamWriter.class, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, nodesprocessed, cb, visited, holder)); } - private boolean processFoundNode(UseExplicitEncodingFixCore fixcore, + private static boolean processFoundNode(UseExplicitEncodingFixCore fixcore, Set operations, Set nodesprocessed, ChangeBehavior cb, ClassInstanceCreation visited, ReferenceHolder holder) { List arguments= visited.arguments(); 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 7ff909ca..fe944e8d 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 @@ -69,8 +69,10 @@ private boolean processFoundNode(UseExplicitEncodingFixCore fixcore, holder.put(ENCODING,StandardCharsets.UTF_8); holder.put(REPLACE,argstring3); break; - default: + case 0: break; + default: + return false; } operations.add(fixcore.rewrite(visited, cb, datah)); nodesprocessed.add(visited); @@ -91,7 +93,7 @@ public void rewrite(UseExplicitEncodingFixCore upp,final MethodInvocation visite ASTNode callToCharsetDefaultCharset= computeCharsetASTNode(cuRewrite, cb, ast, (Charset) data.get(ENCODING)); // ListRewrite listRewrite= rewrite.getListRewrite(visited, MethodInvocation.ARGUMENTS_PROPERTY); // listRewrite.insertLast(callToCharsetDefaultCharset, group); - + ListRewrite listRewrite= rewrite.getListRewrite(visited, MethodInvocation.ARGUMENTS_PROPERTY); if(data.get(ENCODING)!= null) { listRewrite.replace((ASTNode) data.get(REPLACE), callToCharsetDefaultCharset, group);