Skip to content

Commit

Permalink
fix compilation error because of non static definition of method
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenartur committed Aug 11, 2024
1 parent 89ecbe5 commit 1d5beed
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,48 +48,36 @@ public class FileReaderExplicitEncoding extends AbstractExplicitEncoding<ClassIn

@Override
public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set<CompilationUnitRewriteOperation> operations, Set<ASTNode> nodesprocessed,ChangeBehavior cb) {
HelperVisitor.callClassInstanceCreationVisitor(FileReader.class, compilationUnit, datah, nodesprocessed, (visited, holder_a) -> {
List<ASTNode> 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<CompilationUnitRewriteOperation> operations, Set<ASTNode> nodesprocessed, ChangeBehavior cb,
ClassInstanceCreation visited, ReferenceHolder<String, Object> holder) {
List<ASTNode> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompilationUnitRewriteOperation> operations, Set<ASTNode> nodesprocessed, ChangeBehavior cb,
ClassInstanceCreation visited, ReferenceHolder<String, Object> holder) {
List<ASTNode> arguments= visited.arguments();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompilationUnitRewriteOperation> operations, Set<ASTNode> nodesprocessed, ChangeBehavior cb,
ClassInstanceCreation visited, ReferenceHolder<String, Object> holder) {
List<ASTNode> arguments= visited.arguments();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 1d5beed

Please sign in to comment.