Skip to content

Commit

Permalink
add tests for Java 8
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenartur committed Sep 15, 2024
1 parent c8f90f3 commit 88c7fb7
Show file tree
Hide file tree
Showing 9 changed files with 914 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public class ByteArrayOutputStreamExplicitEncoding extends AbstractExplicitEncod

@Override
public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set<CompilationUnitRewriteOperation> operations, Set<ASTNode> nodesprocessed,ChangeBehavior cb) {
if (!JavaModelUtil.is10OrHigher(compilationUnit.getJavaElement().getJavaProject())) {
/**
* For Java 9 and older just do nothing
*/
return;
}
ReferenceHolder<ASTNode, Object> holder= new ReferenceHolder<>();
HelperVisitor.callMethodInvocationVisitor(ByteArrayOutputStream.class, METHOD_TOSTRING, compilationUnit, holder, nodesprocessed, (visited, aholder) -> processFoundNode(fixcore, operations, nodesprocessed, cb, visited, aholder));
}
Expand Down Expand Up @@ -102,12 +108,6 @@ public void rewrite(UseExplicitEncodingFixCore upp,final MethodInvocation visite
TextEditGroup group,ChangeBehavior cb, ReferenceHolder<ASTNode, Object> data) {
ASTRewrite rewrite= cuRewrite.getASTRewrite();
AST ast= cuRewrite.getRoot().getAST();
if (!JavaModelUtil.is10OrHigher(cuRewrite.getCu().getJavaProject())) {
/**
* For Java 9 and older just do nothing
*/
return;
}
ASTNode callToCharsetDefaultCharset= computeCharsetASTNode(cuRewrite, ast, cb, ((Nodedata) data.get(visited)).encoding);
/**
* Add Charset.defaultCharset().displayName() as second (last) parameter of "toString()" call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public class ChannelsNewReaderExplicitEncoding extends AbstractExplicitEncoding<

@Override
public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set<CompilationUnitRewriteOperation> operations, Set<ASTNode> nodesprocessed,ChangeBehavior cb) {
if (!JavaModelUtil.is10OrHigher(compilationUnit.getJavaElement().getJavaProject())) {
/**
* For Java 9 and older just do nothing
*/
return;
}
ReferenceHolder<ASTNode, Object> datah= new ReferenceHolder<>();
HelperVisitor.callMethodInvocationVisitor(Channels.class, METHOD_NEW_READER, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, nodesprocessed, cb, visited, holder));
}
Expand Down Expand Up @@ -79,12 +85,6 @@ public void rewrite(UseExplicitEncodingFixCore upp,final MethodInvocation visite
TextEditGroup group,ChangeBehavior cb, ReferenceHolder<ASTNode, Object> data) {
ASTRewrite rewrite= cuRewrite.getASTRewrite();
AST ast= cuRewrite.getRoot().getAST();
if (!JavaModelUtil.is10OrHigher(cuRewrite.getCu().getJavaProject())) {
/**
* For Java 9 and older just do nothing
*/
return;
}
ASTNode callToCharsetDefaultCharset= computeCharsetASTNode(cuRewrite, ast, cb, ((Nodedata) data.get(visited)).encoding);
/**
* Add Charset.defaultCharset() as second (last) parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public class ChannelsNewWriterExplicitEncoding extends AbstractExplicitEncoding<

@Override
public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set<CompilationUnitRewriteOperation> operations, Set<ASTNode> nodesprocessed,ChangeBehavior cb) {
if (!JavaModelUtil.is10OrHigher(compilationUnit.getJavaElement().getJavaProject())) {
/**
* For Java 9 and older just do nothing
*/
return;
}
ReferenceHolder<ASTNode, Object> datah= new ReferenceHolder<>();
HelperVisitor.callMethodInvocationVisitor(Channels.class, METHOD_NEW_WRITER, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, nodesprocessed, cb, visited, holder));
}
Expand Down Expand Up @@ -78,12 +84,6 @@ public void rewrite(UseExplicitEncodingFixCore upp,final MethodInvocation visite
TextEditGroup group,ChangeBehavior cb, ReferenceHolder<ASTNode, Object> data) {
ASTRewrite rewrite= cuRewrite.getASTRewrite();
AST ast= cuRewrite.getRoot().getAST();
if (!JavaModelUtil.is10OrHigher(cuRewrite.getCu().getJavaProject())) {
/**
* For Java 9 and older just do nothing
*/
return;
}
ASTNode callToCharsetDefaultCharset= computeCharsetASTNode(cuRewrite, ast, cb, ((Nodedata) data.get(visited)).encoding);
/**
* Add Charset.defaultCharset() as second (last) parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public class PrintWriterExplicitEncoding extends AbstractExplicitEncoding<ClassI

@Override
public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set<CompilationUnitRewriteOperation> operations, Set<ASTNode> nodesprocessed,ChangeBehavior cb) {
if (!JavaModelUtil.is10OrHigher(compilationUnit.getJavaElement().getJavaProject())) {
/**
* For Java 9 and older just do nothing
*/
return;
}
ReferenceHolder<ASTNode, Object> datah= new ReferenceHolder<>();
HelperVisitor.callClassInstanceCreationVisitor(PrintWriter.class, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, nodesprocessed, cb, visited, holder));
}
Expand All @@ -71,12 +77,6 @@ public void rewrite(UseExplicitEncodingFixCore upp,final ClassInstanceCreation v
TextEditGroup group,ChangeBehavior cb, ReferenceHolder<ASTNode, Object> data) {
ASTRewrite rewrite= cuRewrite.getASTRewrite();
AST ast= cuRewrite.getRoot().getAST();
if (!JavaModelUtil.is10OrHigher(cuRewrite.getCu().getJavaProject())) {
/**
* For Java 9 and older just do nothing
*/
return;
}
ASTNode callToCharsetDefaultCharset= computeCharsetASTNode(cuRewrite, ast, cb, (String) data.get(visited));
/**
* new FileOutputStream(<filename>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public class ScannerExplicitEncoding extends AbstractExplicitEncoding<ClassInsta

@Override
public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set<CompilationUnitRewriteOperation> operations, Set<ASTNode> nodesprocessed,ChangeBehavior cb) {
if (!JavaModelUtil.is10OrHigher(compilationUnit.getJavaElement().getJavaProject())) {
/**
* For Java 9 and older just do nothing
*/
return;
}
ReferenceHolder<ASTNode, Object> datah= new ReferenceHolder<>();
HelperVisitor.callClassInstanceCreationVisitor(Scanner.class, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, nodesprocessed, cb, visited, holder));
}
Expand Down Expand Up @@ -118,12 +124,6 @@ public void rewrite(UseExplicitEncodingFixCore upp,final ClassInstanceCreation v
TextEditGroup group,ChangeBehavior cb, ReferenceHolder<ASTNode, Object> data) {
ASTRewrite rewrite= cuRewrite.getASTRewrite();
AST ast= cuRewrite.getRoot().getAST();
if (!JavaModelUtil.is10OrHigher(cuRewrite.getCu().getJavaProject())) {
/**
* For Java 9 and older just do nothing
*/
return;
}
ASTNode callToCharsetDefaultCharset= computeCharsetASTNode(cuRewrite, ast, cb, ((Nodedata) data.get(visited)).encoding);
/**
* Add Charset.defaultCharset() as second (last) parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public class StringExplicitEncoding extends AbstractExplicitEncoding<ClassInstan

@Override
public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set<CompilationUnitRewriteOperation> operations, Set<ASTNode> nodesprocessed,ChangeBehavior cb) {
if (!JavaModelUtil.is10OrHigher(compilationUnit.getJavaElement().getJavaProject())) {
/**
* For Java 9 and older just do nothing
*/
return;
}
ReferenceHolder<ASTNode, Object> datah= new ReferenceHolder<>();
HelperVisitor.callClassInstanceCreationVisitor(String.class, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, nodesprocessed, cb, visited, holder));
}
Expand Down Expand Up @@ -103,12 +109,6 @@ public void rewrite(UseExplicitEncodingFixCore upp,final ClassInstanceCreation v
TextEditGroup group,ChangeBehavior cb, ReferenceHolder<ASTNode, Object> data) {
ASTRewrite rewrite= cuRewrite.getASTRewrite();
AST ast= cuRewrite.getRoot().getAST();
if (!JavaModelUtil.is10OrHigher(cuRewrite.getCu().getJavaProject())) {
/**
* For Java 9 and older just do nothing
*/
return;
}
ASTNode callToCharsetDefaultCharset= computeCharsetASTNode(cuRewrite, ast, cb, ((Nodedata) data.get(visited)).encoding);
/**
* Add Charset.defaultCharset() as second (last) parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public class URLDecoderDecodeExplicitEncoding extends AbstractExplicitEncoding<M

@Override
public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set<CompilationUnitRewriteOperation> operations, Set<ASTNode> nodesprocessed,ChangeBehavior cb) {
if (!JavaModelUtil.is10OrHigher(compilationUnit.getJavaElement().getJavaProject())) {
/**
* For Java 9 and older just do nothing
*/
return;
}
ReferenceHolder<ASTNode, Object> datah= new ReferenceHolder<>();
HelperVisitor.callMethodInvocationVisitor(URLDecoder.class, METHOD_DECODE, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, nodesprocessed, cb, visited, holder));
}
Expand Down Expand Up @@ -110,12 +116,6 @@ public void rewrite(UseExplicitEncodingFixCore upp,final MethodInvocation visite
TextEditGroup group,ChangeBehavior cb, ReferenceHolder<ASTNode, Object> data) {
ASTRewrite rewrite= cuRewrite.getASTRewrite();
AST ast= cuRewrite.getRoot().getAST();
if (!JavaModelUtil.is10OrHigher(cuRewrite.getCu().getJavaProject())) {
/**
* For Java 9 and older just do nothing
*/
return;
}
ASTNode callToCharsetDefaultCharset= computeCharsetASTNode(cuRewrite, ast, cb, ((Nodedata) data.get(visited)).encoding);
/**
* Add Charset.defaultCharset() or StandardCharsets.UTF_8 as second (last) parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public class URLEncoderEncodeExplicitEncoding extends AbstractExplicitEncoding<M

@Override
public void find(UseExplicitEncodingFixCore fixcore, CompilationUnit compilationUnit, Set<CompilationUnitRewriteOperation> operations, Set<ASTNode> nodesprocessed,ChangeBehavior cb) {
if (!JavaModelUtil.is10OrHigher(compilationUnit.getJavaElement().getJavaProject())) {
/**
* For Java 9 and older just do nothing
*/
return;
}
ReferenceHolder<ASTNode, Object> datah= new ReferenceHolder<>();
HelperVisitor.callMethodInvocationVisitor(URLEncoder.class, METHOD_ENCODE, compilationUnit, datah, nodesprocessed, (visited, holder) -> processFoundNode(fixcore, operations, nodesprocessed, cb, visited, holder));
}
Expand Down Expand Up @@ -110,12 +116,6 @@ public void rewrite(UseExplicitEncodingFixCore upp,final MethodInvocation visite
TextEditGroup group,ChangeBehavior cb, ReferenceHolder<ASTNode, Object> data) {
ASTRewrite rewrite= cuRewrite.getASTRewrite();
AST ast= cuRewrite.getRoot().getAST();
if (!JavaModelUtil.is10OrHigher(cuRewrite.getCu().getJavaProject())) {
/**
* For Java 9 and older just do nothing
*/
return;
}
ASTNode callToCharsetDefaultCharset= computeCharsetASTNode(cuRewrite, ast, cb, ((Nodedata) data.get(visited)).encoding);
/**
* Add Charset.defaultCharset() as second (last) parameter
Expand Down
Loading

0 comments on commit 88c7fb7

Please sign in to comment.