Skip to content

Commit

Permalink
Fully-qualified class names vs. new import statements (#503)
Browse files Browse the repository at this point in the history
Co-authored-by: rjust <[email protected]>
  • Loading branch information
jose and rjust authored Nov 30, 2023
1 parent c0ee713 commit 2e6db91
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 144 deletions.
2 changes: 1 addition & 1 deletion framework/bug-mining/Patch-Minimization-Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ Code refactoring may consist of one or more of the following:

### 2. Compiler directives and annotations

1. __Changes made to import statements that are not relevant to the bug fix should be removed__
1. __Changes made to import statements that are not relevant to the bug fix should be removed__
Although removing changes involving import statements might create new warnings of `unused import statements`, import statements would not communicate anything about the bug or the bug fix since they would only be necessary to support functions. It is also worth noting that these import statements could be completely removed by using the fully qualified function names.

2. __Changes made to @override statements can be removed under some circumstances__
Expand Down
14 changes: 3 additions & 11 deletions framework/projects/Cli/patches/3.src.patch
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
diff --git a/src/java/org/apache/commons/cli/TypeHandler.java b/src/java/org/apache/commons/cli/TypeHandler.java
index 0a0aa72..1ddde5b 100644
index 0a0aa72..addf90b 100644
--- a/src/java/org/apache/commons/cli/TypeHandler.java
+++ b/src/java/org/apache/commons/cli/TypeHandler.java
@@ -22,6 +22,7 @@ import java.net.URL;

import java.util.Date;

+import org.apache.commons.lang.math.NumberUtils;
/**
* This is a temporary implementation. TypeHandler will handle the
* pluggableness of OptionTypes and it will direct all of these types
@@ -158,17 +159,7 @@ public class TypeHandler {
@@ -158,17 +158,7 @@ public class TypeHandler {
{
try
{
Expand All @@ -25,7 +17,7 @@ index 0a0aa72..1ddde5b 100644
- return Long.valueOf(str);
- }
- }
+ return NumberUtils.createNumber(str);
+ return org.apache.commons.lang.math.NumberUtils.createNumber(str);
}
catch (NumberFormatException nfe)
{
14 changes: 3 additions & 11 deletions framework/projects/Cli/patches/36.src.patch
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,15 @@ index dc6d5db..322053f 100644
/** the name of the selected option */
private String selected;
diff --git a/src/main/java/org/apache/commons/cli/Options.java b/src/main/java/org/apache/commons/cli/Options.java
index 796fe5c..0ee4eea 100644
index 796fe5c..721baaf 100644
--- a/src/main/java/org/apache/commons/cli/Options.java
+++ b/src/main/java/org/apache/commons/cli/Options.java
@@ -21,6 +21,7 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
@@ -57,7 +58,7 @@ public class Options implements Serializable
@@ -57,7 +57,7 @@ public class Options implements Serializable
private final List<Object> requiredOpts = new ArrayList<Object>();

/** a map of the option groups */
- private final Map<String, OptionGroup> optionGroups = new LinkedHashMap<String, OptionGroup>();
+ private final Map<String, OptionGroup> optionGroups = new HashMap<String, OptionGroup>();
+ private final Map<String, OptionGroup> optionGroups = new java.util.HashMap<String, OptionGroup>();

/**
* Add the specified option group.
30 changes: 11 additions & 19 deletions framework/projects/Closure/patches/153.src.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/src/com/google/javascript/jscomp/Normalize.java b/src/com/google/javascript/jscomp/Normalize.java
index c14ac8f1..4c99858e 100644
index c14ac8f..4c99858 100644
--- a/src/com/google/javascript/jscomp/Normalize.java
+++ b/src/com/google/javascript/jscomp/Normalize.java
@@ -628,7 +628,6 @@ class Normalize implements CompilerPass {
Expand Down Expand Up @@ -54,18 +54,10 @@ index c14ac8f1..4c99858e 100644
}

diff --git a/src/com/google/javascript/jscomp/SyntacticScopeCreator.java b/src/com/google/javascript/jscomp/SyntacticScopeCreator.java
index eb6e1eab..04bafcf0 100644
index eb6e1ea..9494792 100644
--- a/src/com/google/javascript/jscomp/SyntacticScopeCreator.java
+++ b/src/com/google/javascript/jscomp/SyntacticScopeCreator.java
@@ -20,6 +20,7 @@ import com.google.common.base.Preconditions;
import com.google.javascript.rhino.JSDocInfo;
import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.Token;
+import com.google.javascript.rhino.jstype.JSType;


/**
@@ -91,7 +92,7 @@ class SyntacticScopeCreator implements ScopeCreator {
@@ -91,7 +91,7 @@ class SyntacticScopeCreator implements ScopeCreator {
// been declared in the outer scope.
String fnName = fnNameNode.getString();
if (!fnName.isEmpty() && NodeUtil.isFunctionExpression(n)) {
Expand All @@ -74,7 +66,7 @@ index eb6e1eab..04bafcf0 100644
}

// Args: Declare function variables
@@ -99,7 +100,7 @@ class SyntacticScopeCreator implements ScopeCreator {
@@ -99,7 +99,7 @@ class SyntacticScopeCreator implements ScopeCreator {
for (Node a = args.getFirstChild(); a != null;
a = a.getNext()) {
Preconditions.checkState(a.getType() == Token.NAME);
Expand All @@ -83,7 +75,7 @@ index eb6e1eab..04bafcf0 100644
}

// Body
@@ -121,7 +122,9 @@ class SyntacticScopeCreator implements ScopeCreator {
@@ -121,7 +121,9 @@ class SyntacticScopeCreator implements ScopeCreator {
for (Node child = n.getFirstChild();
child != null;) {
Node next = child.getNext();
Expand All @@ -94,7 +86,7 @@ index eb6e1eab..04bafcf0 100644
child = next;
}
return;
@@ -136,7 +139,7 @@ class SyntacticScopeCreator implements ScopeCreator {
@@ -136,7 +138,7 @@ class SyntacticScopeCreator implements ScopeCreator {
// This is invalid, but allow it so the checks can catch it.
return;
}
Expand All @@ -103,7 +95,7 @@ index eb6e1eab..04bafcf0 100644
return; // should not examine function's children

case Token.CATCH:
@@ -148,7 +151,7 @@ class SyntacticScopeCreator implements ScopeCreator {
@@ -148,7 +150,7 @@ class SyntacticScopeCreator implements ScopeCreator {
final Node var = n.getFirstChild();
final Node block = var.getNext();

Expand All @@ -112,7 +104,7 @@ index eb6e1eab..04bafcf0 100644
scanVars(block, n);
return; // only one child to scan

@@ -174,7 +177,8 @@ class SyntacticScopeCreator implements ScopeCreator {
@@ -174,7 +176,8 @@ class SyntacticScopeCreator implements ScopeCreator {
*/
interface RedeclarationHandler {
void onRedeclaration(
Expand All @@ -122,7 +114,7 @@ index eb6e1eab..04bafcf0 100644
}

/**
@@ -182,8 +186,8 @@ class SyntacticScopeCreator implements ScopeCreator {
@@ -182,8 +185,8 @@ class SyntacticScopeCreator implements ScopeCreator {
*/
private class DefaultRedeclarationHandler implements RedeclarationHandler {
public void onRedeclaration(
Expand All @@ -133,14 +125,14 @@ index eb6e1eab..04bafcf0 100644

// Don't allow multiple variables to be declared at the top level scope
if (scope.isGlobal()) {
@@ -228,17 +232,16 @@ class SyntacticScopeCreator implements ScopeCreator {
@@ -228,17 +231,16 @@ class SyntacticScopeCreator implements ScopeCreator {
* @param n The node corresponding to the variable name.
* @param declaredType The variable's type, according to JSDoc
*/
- private void declareVar(Node n) {
- Preconditions.checkState(n.getType() == Token.NAME);
+ private void declareVar(String name, Node n, Node parent,
+ Node gramps, JSType declaredType,
+ Node gramps, com.google.javascript.rhino.jstype.JSType declaredType,
+ Node nodeWithLineNumber) {

- CompilerInput input = compiler.getInput(sourceName);
Expand Down
18 changes: 5 additions & 13 deletions framework/projects/Closure/patches/158.src.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java b/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java
index e2e102c6..3a7f427f 100644
index e2e102c..3a7f427 100644
--- a/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java
+++ b/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java
@@ -194,11 +194,12 @@ abstract class AbstractCommandLineRunner<A extends Compiler,
Expand Down Expand Up @@ -79,7 +79,7 @@ index e2e102c6..3a7f427f 100644
- }
}
diff --git a/src/com/google/javascript/jscomp/CommandLineRunner.java b/src/com/google/javascript/jscomp/CommandLineRunner.java
index b1a7472a..d9a381b5 100644
index b1a7472..d9a381b 100644
--- a/src/com/google/javascript/jscomp/CommandLineRunner.java
+++ b/src/com/google/javascript/jscomp/CommandLineRunner.java
@@ -23,7 +23,6 @@ import com.google.common.collect.Maps;
Expand Down Expand Up @@ -200,25 +200,17 @@ index b1a7472a..d9a381b5 100644
.setCharset(flags.charset)
.setManageClosureDependencies(flags.manage_closure_dependencies)
diff --git a/src/com/google/javascript/jscomp/DiagnosticGroups.java b/src/com/google/javascript/jscomp/DiagnosticGroups.java
index cf0beda1..271492f2 100644
index cf0beda..d2d38c5 100644
--- a/src/com/google/javascript/jscomp/DiagnosticGroups.java
+++ b/src/com/google/javascript/jscomp/DiagnosticGroups.java
@@ -20,6 +20,7 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;

+import java.util.List;
import java.util.Map;

/**
@@ -182,10 +183,12 @@ public class DiagnosticGroups {
@@ -182,10 +182,12 @@ public class DiagnosticGroups {
/**
* Adds warning levels by name.
*/
- void setWarningLevel(CompilerOptions options,
- String name, CheckLevel level) {
+ void setWarningLevels(CompilerOptions options,
+ List<String> diagnosticGroups, CheckLevel level) {
+ java.util.List<String> diagnosticGroups, CheckLevel level) {
+ for (String name : diagnosticGroups) {
DiagnosticGroup group = forName(name);
Preconditions.checkNotNull(group, "No warning class for name: " + name);
Expand Down
15 changes: 4 additions & 11 deletions framework/projects/JacksonDatabind/patches/63.src.patch
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
diff --git a/src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java b/src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java
index 00896eab5..e8bd1e268 100644
index 00896ea..482622b 100644
--- a/src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java
+++ b/src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java
@@ -7,6 +7,7 @@ import java.util.*;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.*;
+import com.fasterxml.jackson.databind.util.ClassUtil;

/**
* Checked exception used to signal fatal problems with mapping of
@@ -127,22 +128,12 @@ public class JsonMappingException
@@ -127,22 +127,12 @@ public class JsonMappingException
// butt-ugly for arrays.
// 06-Oct-2016, tatu: as per [databind#1403], `getSimpleName()` not so good
// as it drops enclosing class. So let's try bit different approach
Expand All @@ -24,7 +16,8 @@ index 00896eab5..e8bd1e268 100644
- sb.append("[]");
- }
- /* was:
String pkgName = ClassUtil.getPackageName(cls);
- String pkgName = ClassUtil.getPackageName(cls);
+ String pkgName = com.fasterxml.jackson.databind.util.ClassUtil.getPackageName(cls);
if (pkgName != null) {
sb.append(pkgName);
sb.append('.');
Expand Down
76 changes: 20 additions & 56 deletions framework/projects/JxPath/patches/7.src.patch
Original file line number Diff line number Diff line change
@@ -1,103 +1,67 @@
diff --git a/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationGreaterThan.java b/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationGreaterThan.java
index 4d8c2c4..af667db 100644
index 4d8c2c4..3a053d4 100644
--- a/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationGreaterThan.java
+++ b/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationGreaterThan.java
@@ -16,6 +16,8 @@
*/
package org.apache.commons.jxpath.ri.compiler;

+import org.apache.commons.jxpath.ri.EvalContext;
+import org.apache.commons.jxpath.ri.InfoSetUtil;
/**
* Implementation of Expression for the operation "&gt;".
*
@@ -28,8 +30,10 @@ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression
@@ -28,8 +28,10 @@ public class CoreOperationGreaterThan extends CoreOperationRelationalExpression
super(new Expression[] { arg1, arg2 });
}

- protected boolean evaluateCompare(int compare) {
- return compare > 0;
+ public Object computeValue(EvalContext context) {
+ double l = InfoSetUtil.doubleValue(args[0].computeValue(context));
+ double r = InfoSetUtil.doubleValue(args[1].computeValue(context));
+ public Object computeValue(org.apache.commons.jxpath.ri.EvalContext context) {
+ double l = org.apache.commons.jxpath.ri.InfoSetUtil.doubleValue(args[0].computeValue(context));
+ double r = org.apache.commons.jxpath.ri.InfoSetUtil.doubleValue(args[1].computeValue(context));
+ return l > r ? Boolean.TRUE : Boolean.FALSE;
}

public String getSymbol() {
diff --git a/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationGreaterThanOrEqual.java b/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationGreaterThanOrEqual.java
index c3d5720..42b4ec2 100644
index c3d5720..b9f156c 100644
--- a/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationGreaterThanOrEqual.java
+++ b/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationGreaterThanOrEqual.java
@@ -16,6 +16,8 @@
*/
package org.apache.commons.jxpath.ri.compiler;

+import org.apache.commons.jxpath.ri.EvalContext;
+import org.apache.commons.jxpath.ri.InfoSetUtil;
/**
* Implementation of Expression for the operation "&gt;=".
*
@@ -29,8 +31,10 @@ public class CoreOperationGreaterThanOrEqual extends
@@ -29,8 +29,10 @@ public class CoreOperationGreaterThanOrEqual extends
super(new Expression[] { arg1, arg2 });
}

- protected boolean evaluateCompare(int compare) {
- return compare >= 0;
+ public Object computeValue(EvalContext context) {
+ double l = InfoSetUtil.doubleValue(args[0].computeValue(context));
+ double r = InfoSetUtil.doubleValue(args[1].computeValue(context));
+ public Object computeValue(org.apache.commons.jxpath.ri.EvalContext context) {
+ double l = org.apache.commons.jxpath.ri.InfoSetUtil.doubleValue(args[0].computeValue(context));
+ double r = org.apache.commons.jxpath.ri.InfoSetUtil.doubleValue(args[1].computeValue(context));
+ return l >= r ? Boolean.TRUE : Boolean.FALSE;
}

public String getSymbol() {
diff --git a/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationLessThan.java b/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationLessThan.java
index 4c0d9ce..e0da347 100644
index 4c0d9ce..374f772 100644
--- a/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationLessThan.java
+++ b/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationLessThan.java
@@ -16,6 +16,8 @@
*/
package org.apache.commons.jxpath.ri.compiler;

+import org.apache.commons.jxpath.ri.EvalContext;
+import org.apache.commons.jxpath.ri.InfoSetUtil;
/**
* Implementation of Expression for the operation "&lt;".
*
@@ -28,8 +30,10 @@ public class CoreOperationLessThan extends CoreOperationRelationalExpression {
@@ -28,8 +28,10 @@ public class CoreOperationLessThan extends CoreOperationRelationalExpression {
super(new Expression[] { arg1, arg2 });
}

- protected boolean evaluateCompare(int compare) {
- return compare < 0;
+ public Object computeValue(EvalContext context) {
+ double l = InfoSetUtil.doubleValue(args[0].computeValue(context));
+ double r = InfoSetUtil.doubleValue(args[1].computeValue(context));
+ public Object computeValue(org.apache.commons.jxpath.ri.EvalContext context) {
+ double l = org.apache.commons.jxpath.ri.InfoSetUtil.doubleValue(args[0].computeValue(context));
+ double r = org.apache.commons.jxpath.ri.InfoSetUtil.doubleValue(args[1].computeValue(context));
+ return l < r ? Boolean.TRUE : Boolean.FALSE;
}

public String getSymbol() {
diff --git a/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationLessThanOrEqual.java b/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationLessThanOrEqual.java
index 7940ecb..becf2e7 100644
index 7940ecb..db562d8 100644
--- a/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationLessThanOrEqual.java
+++ b/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationLessThanOrEqual.java
@@ -16,6 +16,8 @@
*/
package org.apache.commons.jxpath.ri.compiler;

+import org.apache.commons.jxpath.ri.EvalContext;
+import org.apache.commons.jxpath.ri.InfoSetUtil;
/**
* Implementation of Expression for the operation "&lt;=".
*
@@ -29,8 +31,10 @@ public class CoreOperationLessThanOrEqual extends
@@ -29,8 +29,10 @@ public class CoreOperationLessThanOrEqual extends
super(new Expression[] { arg1, arg2 });
}

- protected boolean evaluateCompare(int compare) {
- return compare <= 0;
+ public Object computeValue(EvalContext context) {
+ double l = InfoSetUtil.doubleValue(args[0].computeValue(context));
+ double r = InfoSetUtil.doubleValue(args[1].computeValue(context));
+ public Object computeValue(org.apache.commons.jxpath.ri.EvalContext context) {
+ double l = org.apache.commons.jxpath.ri.InfoSetUtil.doubleValue(args[0].computeValue(context));
+ double r = org.apache.commons.jxpath.ri.InfoSetUtil.doubleValue(args[1].computeValue(context));
+ return l <= r ? Boolean.TRUE : Boolean.FALSE;
}

Expand Down
Loading

0 comments on commit 2e6db91

Please sign in to comment.