Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore case with 3 and 4 parameters only 5 parameter case #51

Merged
merged 13 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.HashMap;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IStatus;
Expand All @@ -30,7 +31,6 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.osgi.util.NLS;
import org.eclipse.text.edits.TextEdit;
import org.eclipse.core.runtime.IConfigurationElement;

public class CodeCleanupApplication implements IApplication {
private static final String ARG_CONFIG = "-config"; //$NON-NLS-1$
Expand Down Expand Up @@ -178,7 +178,7 @@ private void formatFile(File file, CodeFormatter codeFormatter) {
try (BufferedWriter out = new BufferedWriter(new FileWriter(file,StandardCharsets.UTF_8));){
out.write(doc.get());
out.flush();
}
}
} catch (IOException e) {
String errorMessage = Messages.bind(Messages.CaughtException, "IOException", e.getLocalizedMessage()); //$NON-NLS-1$
Util.log(e, errorMessage);
Expand Down Expand Up @@ -388,7 +388,7 @@ private void formatDirTree(File dir, CodeFormatter codeFormatter) {
}
}

public static CodeFormatter createCodeFormatter(Map options, int mode) {
private static CodeFormatter createCodeFormatter(Map options, int mode) {
if (options == null) options = JavaCore.getOptions();
Map currentOptions = new HashMap(options);
if (mode == M_FORMAT_NEW) {
Expand All @@ -403,14 +403,12 @@ public static CodeFormatter createCodeFormatter(Map options, int mode) {
IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(JavaCore.PLUGIN_ID,
JavaCore.JAVA_FORMATTER_EXTENSION_POINT_ID);
if (extension != null) {
IExtension[] extensions = extension.getExtensions();
for (int i = 0; i < extensions.length; i++) {
IConfigurationElement[] configElements = extensions[i].getConfigurationElements();
for (int j = 0; j < configElements.length; j++) {
String initializerID = configElements[j].getAttribute("id"); //$NON-NLS-1$
for (IExtension extension2 : extension.getExtensions()) {
for (IConfigurationElement configElement : extension2.getConfigurationElements()) {
String initializerID = configElement.getAttribute("id"); //$NON-NLS-1$
if (initializerID != null && initializerID.equals(formatterId)) {
try {
Object execExt = configElements[j].createExecutableExtension("class"); //$NON-NLS-1$
Object execExt = configElement.createExecutableExtension("class"); //$NON-NLS-1$
if (execExt instanceof CodeFormatter) {
CodeFormatter formatter = (CodeFormatter) execExt;
formatter.setOptions(currentOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public void find(SimplifyPlatformStatusFixCore fixcore, CompilationUnit compilat
@Override
public boolean visit(final ClassInstanceCreation visited) {
if (nodesprocessed.contains(visited) || (
(visited.arguments().size() != 3)
&& (visited.arguments().size() != 4)
&& (visited.arguments().size() != 5)
// (visited.arguments().size() != 3)&&
// (visited.arguments().size() != 4)&&
(visited.arguments().size() != 5)
)) {
return false;
}
Expand Down Expand Up @@ -115,7 +115,8 @@ public void rewrite(SimplifyPlatformStatusFixCore upp, final ClassInstanceCreati
staticCall.setName(ast.newSimpleName(methodname));
List<ASTNode> arguments= visited.arguments();
List<ASTNode> staticCallArguments= staticCall.arguments();
int positionmessage= arguments.size() == 5 ? 3 : 2;
// int positionmessage= arguments.size() == 5 ? 3 : 2;
int positionmessage= 3;
staticCallArguments.add(ASTNodes.createMoveTarget(rewrite,
ASTNodes.getUnparenthesedExpression(arguments.get(positionmessage))));
ASTNode node2= arguments.get(2);
Expand All @@ -130,12 +131,14 @@ public void rewrite(SimplifyPlatformStatusFixCore upp, final ClassInstanceCreati
}
break;
case 4:
ASTNode node= arguments.get(3);
if (!node.toString().equals("null")) { //$NON-NLS-1$
staticCallArguments.add(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(node)));
}
// return;
// ASTNode node= arguments.get(3);
// if (!node.toString().equals("null")) { //$NON-NLS-1$
// staticCallArguments.add(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(node)));
// }
break;
case 3:
// return;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,10 @@ public class Java9CleanUpTest {

enum PlatformStatusPatterns {

STATUSWARNING3("package test1;\n"
+ "import org.eclipse.core.runtime.IStatus;\n"
+ "import org.eclipse.core.runtime.Status;\n"
+ "public class E1 {\n"
+ " IStatus status = new Status(IStatus.WARNING, \"plugin id\",\"important message\");\n"
+ "}",

"package test1;\n"
+ "import org.eclipse.core.runtime.IStatus;\n"
+ "import org.eclipse.core.runtime.Status;\n"
+ "public class E1 {\n"
+ " IStatus status = Status.warning(\"important message\");\n"
+ "}"),
STATUSWARNING4("package test1;\n"
STATUSWARNING5("package test1;\n"
+ "import org.eclipse.core.runtime.IStatus;\n"
+ "import org.eclipse.core.runtime.Status;\n"
+ "public class E1 {\n"
+ " IStatus status = new Status(IStatus.WARNING, \"plugin id\", \"important message\", null);\n"
+ " void bla(Throwable e) {\n"
+ " IStatus status = new Status(IStatus.WARNING, \"plugin id\", IStatus.OK, \"important message\", e);\n"
+ " }\n"
Expand All @@ -43,17 +29,16 @@ enum PlatformStatusPatterns {
+ "import org.eclipse.core.runtime.IStatus;\n"
+ "import org.eclipse.core.runtime.Status;\n"
+ "public class E1 {\n"
+ " IStatus status = Status.warning(\"important message\");\n"
+ " void bla(Throwable e) {\n"
+ " IStatus status = Status.warning(\"important message\", e);\n"
+ " }\n"
+ "}"),
STATUSWARNING5("package test1;\n"
STATUSERROR5("package test1;\n"
+ "import org.eclipse.core.runtime.IStatus;\n"
+ "import org.eclipse.core.runtime.Status;\n"
+ "public class E1 {\n"
+ " void bla(Throwable e) {\n"
+ " IStatus status = new Status(IStatus.WARNING, \"plugin id\", IStatus.OK, \"important message\", e);\n"
+ " IStatus status = new Status(IStatus.ERROR, \"plugin id\", IStatus.OK, \"important message\", e);\n"
+ " }\n"
+ "}",

Expand All @@ -62,34 +47,25 @@ enum PlatformStatusPatterns {
+ "import org.eclipse.core.runtime.Status;\n"
+ "public class E1 {\n"
+ " void bla(Throwable e) {\n"
+ " IStatus status = Status.warning(\"important message\", e);\n"
+ " IStatus status = Status.error(\"important message\", e);\n"
+ " }\n"
+ "}"),
STATUSERROR("package test1;\n"
STATUSINFO5("package test1;\n"
+ "import org.eclipse.core.runtime.IStatus;\n"
+ "import org.eclipse.core.runtime.Status;\n"
+ "public class E1 {\n"
+ " IStatus status = new Status(IStatus.ERROR, \"plugin id\", \"important message\", null);\n"
+ "}",

"package test1;\n"
+ "import org.eclipse.core.runtime.IStatus;\n"
+ "import org.eclipse.core.runtime.Status;\n"
+ "public class E1 {\n"
+ " IStatus status = Status.error(\"important message\");\n"
+ "}"),
STATUSINFO("package test1;\n"
+ "import org.eclipse.core.runtime.IStatus;\n"
+ "import org.eclipse.core.runtime.Status;\n"
+ "public class E1 {\n"
+ " IStatus status = new Status(IStatus.INFO, \"plugin id\", \"important message\", null);\n"
+ " void bla(Throwable e) {\n"
+ " IStatus status = new Status(IStatus.INFO, \"plugin id\", IStatus.OK, \"important message\", e);\n"
+ " }\n"
+ "}",

"package test1;\n"
+ "import org.eclipse.core.runtime.IStatus;\n"
+ "import org.eclipse.core.runtime.Status;\n"
+ "public class E1 {\n"
+ " IStatus status = Status.info(\"important message\");\n"
+ " void bla(Throwable e) {\n"
+ " IStatus status = Status.info(\"important message\", e);\n"
+ " }\n"
+ "}");

PlatformStatusPatterns(String given, String expected) {
Expand All @@ -109,7 +85,15 @@ public void testPlatformStatusParametrized(PlatformStatusPatterns test) throws C
context.assertRefactoringResultAsExpected(new ICompilationUnit[] {cu}, new String[] {test.expected}, null);
}


@ParameterizedTest
@EnumSource(PlatformStatusPatternsDontTouch.class)
public void testPlatformStatus_donttouch(PlatformStatusPatternsDontTouch test) throws CoreException {

Check warning

Code scanning / PMD

The JUnit 5 test method name 'testXMLCleanup_donttouch' doesn't match '[a-z][a-zA-Z0-9]*' Warning test

The JUnit 5 test method name 'testPlatformStatus_donttouch' doesn't match '[a-z][a-zA-Z0-9]*'

Check warning

Code scanning / Pmd (reported by Codacy)

The JUnit 5 test method name 'testPlatformStatus_donttouch' doesn't match '[a-z][a-zA-Z0-9]*' Warning test

The JUnit 5 test method name 'testPlatformStatus_donttouch' doesn't match '[a-z][a-zA-Z0-9]*'

Check notice

Code scanning / Pmd (reported by Codacy)

JUnit tests should include assert() or fail() Note test

JUnit tests should include assert() or fail()
Fixed Show fixed Hide fixed
IPackageFragment pack= context.fSourceFolder.createPackageFragment("test1", false, null);
ICompilationUnit cu= pack.createCompilationUnit("E1.java", test.given, false, null);
context.enable(MYCleanUpConstants.SIMPLIFY_STATUS_CLEANUP);
context.assertRefactoringHasNoChange(new ICompilationUnit[] { cu });
}

enum PlatformStatusPatternsDontTouch {

SIMPLE("package test1;\n" //
Expand All @@ -120,11 +104,45 @@ enum PlatformStatusPatternsDontTouch {
+ "import java.io.FileInputStream;\n"
+ "import java.io.FileNotFoundException;\n" //
+ "import java.io.UnsupportedEncodingException;\n" //
+ "public class E2 {\n" //
+ "public class E1 {\n" //
+ " void method() throws UnsupportedEncodingException, IOException {\n" //
+ " }\n" //
+ "}\n")
// ,
// STATUSWARNING3("package test1;\n"
// + "import org.eclipse.core.runtime.IStatus;\n"
// + "import org.eclipse.core.runtime.Status;\n"
// + "public class E1 {\n"
// + " void bla(Throwable e) {\n"
// + " IStatus status = new Status(IStatus.WARNING, \"plugin id\",\"important message\");\n"
// + " }\n"
// + "}"),
// STATUSWARNING4("package test1;\n"
// + "import org.eclipse.core.runtime.IStatus;\n"
// + "import org.eclipse.core.runtime.Status;\n"
// + "public class E1 {\n"
// + " IStatus status = new Status(IStatus.WARNING, \"plugin id\", \"important message\", null);\n"
// + " void bla(Throwable e) {\n"
// + " IStatus status = new Status(IStatus.WARNING, \"plugin id\", IStatus.OK, \"important message\", e);\n"
// + " }\n"
// + "}"),
// STATUSERROR4("package test1;\n"
// + "import org.eclipse.core.runtime.IStatus;\n"
// + "import org.eclipse.core.runtime.Status;\n"
// + "public class E1 {\n"
// + " void bla(Throwable e) {\n"
// + " IStatus status = new Status(IStatus.ERROR, \"plugin id\", \"important message\", null);\n"
// + " }\n"
// + "}"),
// STATUSINFO4("package test1;\n"
// + "import org.eclipse.core.runtime.IStatus;\n"
// + "import org.eclipse.core.runtime.Status;\n"
// + "public class E1 {\n"
// + " void bla(Throwable e) {\n"
// + " IStatus status = new Status(IStatus.INFO, \"plugin id\", \"important message\", null);\n"
// + " }\n"
// + "}")
// ,
// WRONGSECONDPARAM("package test1;\n"
// + "import org.eclipse.core.runtime.IStatus;\n"
// + "import org.eclipse.core.runtime.Status;\n"
Expand All @@ -142,13 +160,4 @@ enum PlatformStatusPatternsDontTouch {

String given;
}

@ParameterizedTest
@EnumSource(PlatformStatusPatternsDontTouch.class)
public void testPlatformStatus_donttouch(PlatformStatusPatternsDontTouch test) throws CoreException {
IPackageFragment pack= context.fSourceFolder.createPackageFragment("test1", false, null);
ICompilationUnit cu= pack.createCompilationUnit("E2.java", test.given, false, null);
context.enable(MYCleanUpConstants.SIMPLIFY_STATUS_CLEANUP);
context.assertRefactoringHasNoChange(new ICompilationUnit[] { cu });
}
}