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 8 commits
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 @@
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 All @@ -195,11 +195,11 @@
int index = 0;
final int argCount = argsArray.length;

final int DEFAULT_MODE = 0;

Check failure on line 198 in sandbox_cleanup_application/src/org/sandbox/jdt/core/cleanupapp/CodeCleanupApplication.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

The final local variable name 'DEFAULT_MODE' doesn't match '[a-z][a-zA-Z0-9]*'

Configurable naming conventions for local variable declarations and other locally-scoped variables. This rule reports variable declarations which do not match the regex that applies to their specific kind (e.g. final variable, or catch-clause parameter). Each regex can be configured through properties. By default this rule uses the standard Java naming convention (Camel case). LocalVariableNamingConventions (Priority: 1, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#localvariablenamingconventions
final int CONFIG_MODE = 1;

Check failure on line 199 in sandbox_cleanup_application/src/org/sandbox/jdt/core/cleanupapp/CodeCleanupApplication.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

The final local variable name 'CONFIG_MODE' doesn't match '[a-z][a-zA-Z0-9]*'

Configurable naming conventions for local variable declarations and other locally-scoped variables. This rule reports variable declarations which do not match the regex that applies to their specific kind (e.g. final variable, or catch-clause parameter). Each regex can be configured through properties. By default this rule uses the standard Java naming convention (Camel case). LocalVariableNamingConventions (Priority: 1, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#localvariablenamingconventions

int mode = DEFAULT_MODE;
final int INITIAL_SIZE = 1;

Check failure on line 202 in sandbox_cleanup_application/src/org/sandbox/jdt/core/cleanupapp/CodeCleanupApplication.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

The final local variable name 'INITIAL_SIZE' doesn't match '[a-z][a-zA-Z0-9]*'

Configurable naming conventions for local variable declarations and other locally-scoped variables. This rule reports variable declarations which do not match the regex that applies to their specific kind (e.g. final variable, or catch-clause parameter). Each regex can be configured through properties. By default this rule uses the standard Java naming convention (Camel case). LocalVariableNamingConventions (Priority: 1, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#localvariablenamingconventions
int fileCounter = 0;

File[] filesToFormat = new File[INITIAL_SIZE];
Expand All @@ -208,7 +208,7 @@
String currentArg = argsArray[index++];

switch(mode) {
default:

Check warning on line 211 in sandbox_cleanup_application/src/org/sandbox/jdt/core/cleanupapp/CodeCleanupApplication.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

The default label should be the last label in a switch statement

By convention, the default label should be the last label in a switch statement. DefaultLabelNotLastInSwitchStmt (Priority: 3, Ruleset: Best Practices) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_bestpractices.html#defaultlabelnotlastinswitchstmt
break;
case DEFAULT_MODE :
if (PDE_LAUNCH.equals(currentArg)) {
Expand All @@ -216,7 +216,7 @@
}
if (ARG_HELP.equals(currentArg)) {
displayHelp();
return null;

Check failure on line 219 in sandbox_cleanup_application/src/org/sandbox/jdt/core/cleanupapp/CodeCleanupApplication.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

Return an empty collection rather than null.

For any method that returns an collection (such as an array, Collection or Map), it is better to return an empty one rather than a null reference. This removes the need for null checking all results and avoids inadvertent NullPointerExceptions. See Effective Java, 3rd Edition, Item 54: Return empty collections or arrays instead of null ReturnEmptyCollectionRatherThanNull (Priority: 1, Ruleset: Error Prone) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_errorprone.html#returnemptycollectionratherthannull
}
if (ARG_VERBOSE.equals(currentArg)) {
this.verbose = true;
Expand All @@ -234,7 +234,7 @@
File file = new File(currentArg);
if (file.exists()) {
if (filesToFormat.length == fileCounter) {
System.arraycopy(filesToFormat, 0, (filesToFormat = new File[fileCounter * 2]), 0, fileCounter);

Check warning on line 237 in sandbox_cleanup_application/src/org/sandbox/jdt/core/cleanupapp/CodeCleanupApplication.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

Useless parentheses.

Parenthesized expressions are used to override the default operator precedence rules. Parentheses whose removal would not change the relative nesting of operators are unnecessary, because they don't change the semantics of the enclosing expression. Some parentheses that strictly speaking are unnecessary, may still be considered useful for readability. This rule allows to ignore violations on two kinds of unnecessary parentheses: - "Clarifying" parentheses, which separate operators of difference precedence. While unnecessary, they make precedence rules explicit, which may be useful for rarely used operators. For example: ```java (a + b) & c // is equivalent to `a + b & c`, but probably clearer ``` Unset the property `ignoreClarifying` to report them. - "Balancing" parentheses, which are unnecessary but visually balance out another pair of parentheses around an equality operator. For example, those two expressions are equivalent: ```java (a == null) != (b == null) a == null != (b == null) ``` The parentheses on the right are required, and the parentheses on the left are just more visually pleasing. Unset the property `ignoreBalancing` to report them. UselessParentheses (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#uselessparentheses
}
filesToFormat[fileCounter++] = file;
} else {
Expand All @@ -248,7 +248,7 @@
Messages.bind(Messages.CommandLineErrorFile, canonicalPath):
Messages.bind(Messages.CommandLineErrorFileTryFullPath, canonicalPath);
displayHelp(errorMsg);
return null;

Check failure on line 251 in sandbox_cleanup_application/src/org/sandbox/jdt/core/cleanupapp/CodeCleanupApplication.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

Return an empty collection rather than null.

For any method that returns an collection (such as an array, Collection or Map), it is better to return an empty one rather than a null reference. This removes the need for null checking all results and avoids inadvertent NullPointerExceptions. See Effective Java, 3rd Edition, Item 54: Return empty collections or arrays instead of null ReturnEmptyCollectionRatherThanNull (Priority: 1, Ruleset: Error Prone) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_errorprone.html#returnemptycollectionratherthannull
}
break;
case CONFIG_MODE :
Expand All @@ -256,7 +256,7 @@
this.options = readConfig(currentArg);
if (this.options == null) {
displayHelp(Messages.bind(Messages.CommandLineErrorConfig, currentArg));
return null;

Check failure on line 259 in sandbox_cleanup_application/src/org/sandbox/jdt/core/cleanupapp/CodeCleanupApplication.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

Return an empty collection rather than null.

For any method that returns an collection (such as an array, Collection or Map), it is better to return an empty one rather than a null reference. This removes the need for null checking all results and avoids inadvertent NullPointerExceptions. See Effective Java, 3rd Edition, Item 54: Return empty collections or arrays instead of null ReturnEmptyCollectionRatherThanNull (Priority: 1, Ruleset: Error Prone) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_errorprone.html#returnemptycollectionratherthannull
}
mode = DEFAULT_MODE;
continue loop;
Expand All @@ -265,7 +265,7 @@

if (mode == CONFIG_MODE || this.options == null) {
displayHelp(Messages.bind(Messages.CommandLineErrorNoConfigFile));
return null;

Check failure on line 268 in sandbox_cleanup_application/src/org/sandbox/jdt/core/cleanupapp/CodeCleanupApplication.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

Return an empty collection rather than null.

For any method that returns an collection (such as an array, Collection or Map), it is better to return an empty one rather than a null reference. This removes the need for null checking all results and avoids inadvertent NullPointerExceptions. See Effective Java, 3rd Edition, Item 54: Return empty collections or arrays instead of null ReturnEmptyCollectionRatherThanNull (Priority: 1, Ruleset: Error Prone) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_errorprone.html#returnemptycollectionratherthannull
}
if (this.quiet && this.verbose) {
displayHelp(
Expand All @@ -273,14 +273,14 @@
Messages.CommandLineErrorQuietVerbose,
new String[] { ARG_QUIET, ARG_VERBOSE }
));
return null;

Check failure on line 276 in sandbox_cleanup_application/src/org/sandbox/jdt/core/cleanupapp/CodeCleanupApplication.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

Return an empty collection rather than null.

For any method that returns an collection (such as an array, Collection or Map), it is better to return an empty one rather than a null reference. This removes the need for null checking all results and avoids inadvertent NullPointerExceptions. See Effective Java, 3rd Edition, Item 54: Return empty collections or arrays instead of null ReturnEmptyCollectionRatherThanNull (Priority: 1, Ruleset: Error Prone) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_errorprone.html#returnemptycollectionratherthannull
}
if (fileCounter == 0) {
displayHelp(Messages.bind(Messages.CommandLineErrorFileDir));
return null;

Check failure on line 280 in sandbox_cleanup_application/src/org/sandbox/jdt/core/cleanupapp/CodeCleanupApplication.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

Return an empty collection rather than null.

For any method that returns an collection (such as an array, Collection or Map), it is better to return an empty one rather than a null reference. This removes the need for null checking all results and avoids inadvertent NullPointerExceptions. See Effective Java, 3rd Edition, Item 54: Return empty collections or arrays instead of null ReturnEmptyCollectionRatherThanNull (Priority: 1, Ruleset: Error Prone) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_errorprone.html#returnemptycollectionratherthannull
}
if (filesToFormat.length != fileCounter) {
System.arraycopy(filesToFormat, 0, (filesToFormat = new File[fileCounter]), 0, fileCounter);

Check warning on line 283 in sandbox_cleanup_application/src/org/sandbox/jdt/core/cleanupapp/CodeCleanupApplication.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

Useless parentheses.

Parenthesized expressions are used to override the default operator precedence rules. Parentheses whose removal would not change the relative nesting of operators are unnecessary, because they don't change the semantics of the enclosing expression. Some parentheses that strictly speaking are unnecessary, may still be considered useful for readability. This rule allows to ignore violations on two kinds of unnecessary parentheses: - "Clarifying" parentheses, which separate operators of difference precedence. While unnecessary, they make precedence rules explicit, which may be useful for rarely used operators. For example: ```java (a + b) & c // is equivalent to `a + b & c`, but probably clearer ``` Unset the property `ignoreClarifying` to report them. - "Balancing" parentheses, which are unnecessary but visually balance out another pair of parentheses around an equality operator. For example, those two expressions are equivalent: ```java (a == null) != (b == null) a == null != (b == null) ``` The parentheses on the right are required, and the parentheses on the left are just more visually pleasing. Unset the property `ignoreBalancing` to report them. UselessParentheses (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#uselessparentheses
}
return filesToFormat;
}
Expand Down Expand Up @@ -315,7 +315,7 @@
Util.log(e, errorMessage);
System.err.println(errorMessage);
}
return null;

Check failure on line 318 in sandbox_cleanup_application/src/org/sandbox/jdt/core/cleanupapp/CodeCleanupApplication.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

Return an empty collection rather than null.

For any method that returns an collection (such as an array, Collection or Map), it is better to return an empty one rather than a null reference. This removes the need for null checking all results and avoids inadvertent NullPointerExceptions. See Effective Java, 3rd Edition, Item 54: Return empty collections or arrays instead of null ReturnEmptyCollectionRatherThanNull (Priority: 1, Ruleset: Error Prone) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_errorprone.html#returnemptycollectionratherthannull
}

/**
Expand Down Expand Up @@ -377,7 +377,7 @@

File[] files = dir.listFiles();
if (files == null)
return;

Check warning on line 380 in sandbox_cleanup_application/src/org/sandbox/jdt/core/cleanupapp/CodeCleanupApplication.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

This statement should have braces

Enforce a policy for braces on control statements. It is recommended to use braces on 'if ... else' statements and loop statements, even if they are optional. This usually makes the code clearer, and helps prepare the future when you need to add another statement. That said, this rule lets you control which statements are required to have braces via properties. From 6.2.0 on, this rule supersedes WhileLoopMustUseBraces, ForLoopMustUseBraces, IfStmtMustUseBraces, and IfElseStmtMustUseBraces. ControlStatementBraces (Priority: 3, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#controlstatementbraces

for (File file : files) {
if (file.isDirectory()) {
Expand All @@ -388,8 +388,8 @@
}
}

public static CodeFormatter createCodeFormatter(Map options, int mode) {
private static CodeFormatter createCodeFormatter(Map options, int mode) {
if (options == null) options = JavaCore.getOptions();

Check warning on line 392 in sandbox_cleanup_application/src/org/sandbox/jdt/core/cleanupapp/CodeCleanupApplication.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

This statement should have braces

Enforce a policy for braces on control statements. It is recommended to use braces on 'if ... else' statements and loop statements, even if they are optional. This usually makes the code clearer, and helps prepare the future when you need to add another statement. That said, this rule lets you control which statements are required to have braces via properties. From 6.2.0 on, this rule supersedes WhileLoopMustUseBraces, ForLoopMustUseBraces, IfStmtMustUseBraces, and IfElseStmtMustUseBraces. ControlStatementBraces (Priority: 3, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#controlstatementbraces
Map currentOptions = new HashMap(options);
if (mode == M_FORMAT_NEW) {
// disable the option for not formatting comments starting on first column
Expand All @@ -403,14 +403,12 @@
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 @@ -22,7 +22,7 @@
import java.util.function.BiConsumer;
import java.util.function.BiPredicate;

import org.eclipse.jdt.core.dom.*;

Check warning on line 25 in sandbox_common/src/org/sandbox/jdt/internal/common/HelperVisitor.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

Unused import 'org.eclipse.jdt.core.dom.*'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport

/**
* This class allows to use Lambda expressions for building up your visitor processing
Expand Down Expand Up @@ -365,6 +365,20 @@
return predicatemap.put(VisitorEnum.ClassInstanceCreation, bs);
}

/**
*
* @param typeof
* @param bs
* @return old BiPredicate assigned for nodetype
*/
public BiPredicate<? extends ASTNode, E> addClassInstanceCreation(Class<?> typeof, BiPredicate<ClassInstanceCreation, E> bs) {
Map<String, Object> map = Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>(TYPEOF, typeof)
);
predicatedata.put(VisitorEnum.ClassInstanceCreation, map);
return predicatemap.put(VisitorEnum.ClassInstanceCreation, bs);
}

/**
*
* @param bs
Expand Down Expand Up @@ -3332,7 +3346,7 @@
* @param bs
* @param bc
*/
public static <V, T> void callVisitor(ASTNode cu, EnumSet<VisitorEnum> myset, ReferenceHolder<V, T> dataholder, Set<ASTNode> nodesprocessed,

Check warning on line 3349 in sandbox_common/src/org/sandbox/jdt/internal/common/HelperVisitor.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

Avoid using implementation types like 'EnumSet'; use the interface instead

Excessive coupling to implementation types (e.g., `HashSet`) limits your ability to use alternate implementations in the future as requirements change. Whenever available, declare variables and parameters using a more general type (e.g, `Set`). This rule reports uses of concrete collection types. User-defined types that should be treated the same as interfaces can be configured with the property `allowedTypes`. LooseCoupling (Priority: 3, Ruleset: Best Practices) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_bestpractices.html#loosecoupling
BiPredicate<ASTNode, ReferenceHolder<V, T>> bs, BiConsumer<ASTNode, ReferenceHolder<V, T>> bc) {

HelperVisitor<ReferenceHolder<V,T>, V, T> hv= new HelperVisitor<>(nodesprocessed, dataholder);
Expand All @@ -3352,7 +3366,7 @@
* @param nodesprocessed
* @param bs
*/
public static <V, T> void callVisitor(ASTNode cu, EnumSet<VisitorEnum> myset, ReferenceHolder<V, T> dataholder, Set<ASTNode> nodesprocessed,

Check warning on line 3369 in sandbox_common/src/org/sandbox/jdt/internal/common/HelperVisitor.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

Avoid using implementation types like 'EnumSet'; use the interface instead

Excessive coupling to implementation types (e.g., `HashSet`) limits your ability to use alternate implementations in the future as requirements change. Whenever available, declare variables and parameters using a more general type (e.g, `Set`). This rule reports uses of concrete collection types. User-defined types that should be treated the same as interfaces can be configured with the property `allowedTypes`. LooseCoupling (Priority: 3, Ruleset: Best Practices) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_bestpractices.html#loosecoupling
BiPredicate<ASTNode, ReferenceHolder<V, T>> bs) {

HelperVisitor<ReferenceHolder<V, T>,V,T> hv= new HelperVisitor<>(nodesprocessed, dataholder);
Expand Down Expand Up @@ -3670,6 +3684,24 @@
hv.addClassInstanceCreation(bs);
hv.build(node);
}

/**
*
* @param <V>
* @param <T>
* @param class1
* @param node
* @param dataholder
* @param nodesprocessed
* @param bs
*/
public static <V, T> void callClassInstanceCreationVisitor(Class<?> class1, ASTNode node, ReferenceHolder<V, T> dataholder, Set<ASTNode> nodesprocessed,
BiPredicate<ClassInstanceCreation, ReferenceHolder<V, T>> bs) {

HelperVisitor<ReferenceHolder<V, T>,V,T> hv= new HelperVisitor<>(nodesprocessed, dataholder);
hv.addClassInstanceCreation(class1, bs);
hv.build(node);
}

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
import org.eclipse.jdt.internal.corext.util.Messages;
import org.eclipse.text.edits.TextEditGroup;
import org.sandbox.jdt.internal.common.ReferenceHolder;
import org.sandbox.jdt.internal.corext.fix.helper.AbstractSimplifyPlatformStatus;
import org.sandbox.jdt.internal.corext.fix.helper.StatusErrorSimplifyPlatformStatus;
import org.sandbox.jdt.internal.corext.fix.helper.StatusInfoSimplifyPlatformStatus;
Expand All @@ -38,15 +39,15 @@ public enum SimplifyPlatformStatusFixCore {
STATUSERROR(new StatusErrorSimplifyPlatformStatus()),
STATUSINFO(new StatusInfoSimplifyPlatformStatus());

AbstractSimplifyPlatformStatus<ASTNode> explicitencoding;
AbstractSimplifyPlatformStatus<ASTNode> platformstatus;

@SuppressWarnings("unchecked")
SimplifyPlatformStatusFixCore(AbstractSimplifyPlatformStatus<? extends ASTNode> explicitencoding) {
this.explicitencoding= (AbstractSimplifyPlatformStatus<ASTNode>) explicitencoding;
this.platformstatus= (AbstractSimplifyPlatformStatus<ASTNode>) explicitencoding;
}

public String getPreview(boolean i) {
return explicitencoding.getPreview(i);
return platformstatus.getPreview(i);
}

/**
Expand All @@ -62,10 +63,10 @@ public String getPreview(boolean i) {
public void findOperations(final CompilationUnit compilationUnit,
final Set<CompilationUnitRewriteOperation> operations, final Set<ASTNode> nodesprocessed)
throws CoreException {
explicitencoding.find(this, compilationUnit, operations, nodesprocessed);
platformstatus.find(this, compilationUnit, operations, nodesprocessed);
}

public CompilationUnitRewriteOperation rewrite(final ClassInstanceCreation visited) {
public CompilationUnitRewriteOperation rewrite(final ClassInstanceCreation visited, ReferenceHolder<ASTNode, Object> holder) {
return new CompilationUnitRewriteOperation() {
@Override
public void rewriteAST(final CompilationUnitRewrite cuRewrite, final LinkedProposalModelCore linkedModel)
Expand All @@ -75,7 +76,7 @@ public void rewriteAST(final CompilationUnitRewrite cuRewrite, final LinkedPropo
new Object[] { SimplifyPlatformStatusFixCore.this.toString() }),
cuRewrite);
cuRewrite.getASTRewrite().setTargetSourceRangeComputer(computer);
explicitencoding.rewrite(SimplifyPlatformStatusFixCore.this, visited, cuRewrite, group);
platformstatus.rewrite(SimplifyPlatformStatusFixCore.this, visited, cuRewrite, group, holder);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@

import java.util.List;
import java.util.Set;
//import java.util.function.BiPredicate;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.core.dom.QualifiedName;
Expand All @@ -37,6 +35,8 @@
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
import org.eclipse.jdt.internal.corext.refactoring.structure.ImportRemover;
import org.eclipse.text.edits.TextEditGroup;
import org.sandbox.jdt.internal.common.HelperVisitor;
import org.sandbox.jdt.internal.common.ReferenceHolder;
import org.sandbox.jdt.internal.corext.fix.SimplifyPlatformStatusFixCore;

/**
Expand All @@ -61,7 +61,7 @@
* @return simple name of a class if the import was added and fully qualified
* name if there was a conflict
*/
protected Name addImport(String typeName, final CompilationUnitRewrite cuRewrite, AST ast) {
protected static Name addImport(String typeName, final CompilationUnitRewrite cuRewrite, AST ast) {
String importedName= cuRewrite.getImportRewrite().addImport(typeName);
return ast.newName(importedName);
}
Expand All @@ -71,37 +71,49 @@
public void find(SimplifyPlatformStatusFixCore fixcore, CompilationUnit compilationUnit,
Set<CompilationUnitRewriteOperation> operations, Set<ASTNode> nodesprocessed) throws CoreException {
try {
compilationUnit.accept(new ASTVisitor() {
@Override
public boolean visit(final ClassInstanceCreation visited) {
if (nodesprocessed.contains(visited) || (
(visited.arguments().size() != 3)
&& (visited.arguments().size() != 4)
&& (visited.arguments().size() != 5)
)) {
return false;
}

ITypeBinding binding= visited.resolveTypeBinding();
if ((binding != null) && (Status.class.getSimpleName().equals(binding.getName()))) {
List<Expression> arguments= visited.arguments();
if (istatus.equals(arguments.get(0).toString())) {
operations.add(fixcore.rewrite(visited));
nodesprocessed.add(visited);
return false;
}
}

return true;
ReferenceHolder<ASTNode, Object> dataholder= new ReferenceHolder<>();
HelperVisitor.callClassInstanceCreationVisitor(Status.class, compilationUnit, dataholder, nodesprocessed, (visited, holder) -> {
if (nodesprocessed.contains(visited) || (
// (visited.arguments().size() != 3)&&
// (visited.arguments().size() != 4)&&
(visited.arguments().size() != 5)
)) {
Comment on lines +76 to +80

Check warning

Code scanning / PMD

Useless parentheses. Warning

Useless parentheses.
return false;
}
/**
* new Status(INFO, callerClass, OK, message, null);
* new Status(WARNING, callerClass, OK, message, null);
* new Status(WARNING, callerClass, OK, message, exception);
* new Status(ERROR, callerClass, OK, message, null);
* new Status(ERROR, callerClass, OK, message, exception);
*
*
* IStatus status = new Status(IStatus.WARNING, "plugin id", IStatus.OK, "important message", e);
* IStatus status = new Status(IStatus.WARNING, "plugin id", "important message", null);
* IStatus status = new Status(IStatus.WARNING, "plugin id", "important message");
*/
List<Expression> arguments= visited.arguments();
QualifiedName argstring3 = (QualifiedName) arguments.get(2);
if (!"IStatus.OK".equals(argstring3.toString())) { //$NON-NLS-1$
return false;
}
// QualifiedName argstring5 = (QualifiedName) arguments.get(4);
QualifiedName argstring1 = (QualifiedName) arguments.get(0);
String mybinding= argstring1.getFullyQualifiedName();

Check warning

Code scanning / PMD

Avoid unused local variables such as 'element'. Warning

Avoid unused local variables such as 'mybinding'.

Check notice

Code scanning / Pmd (reported by Codacy)

Avoid unused local variables such as 'mybinding'. Note

Avoid unused local variables such as 'mybinding'.
if (istatus.equals(argstring1.toString())) {
operations.add(fixcore.rewrite(visited,holder));
nodesprocessed.add(visited);
return false;
}
return true;
});
} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR, "sandbox_platform_helper", "Problem in find", e)); //$NON-NLS-1$ //$NON-NLS-2$
throw new CoreException(Status.error("Problem in find", e)); //$NON-NLS-1$
}
}

public void rewrite(SimplifyPlatformStatusFixCore upp, final ClassInstanceCreation visited,
final CompilationUnitRewrite cuRewrite, TextEditGroup group) {
final CompilationUnitRewrite cuRewrite, TextEditGroup group, ReferenceHolder<ASTNode, Object> holder) {
ASTRewrite rewrite= cuRewrite.getASTRewrite();
AST ast= cuRewrite.getRoot().getAST();
ImportRewrite importRewrite= cuRewrite.getImportRewrite();
Expand All @@ -115,7 +127,8 @@
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 +143,14 @@
}
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
Loading
Loading