From 2a64cf2a77384077a155f7a6baf25d35ca2ff7e0 Mon Sep 17 00:00:00 2001 From: Ryan Kurtz Date: Thu, 5 Dec 2019 14:34:03 -0500 Subject: [PATCH] GT-3354: Removing some Guava --- .../core/searchmem/AbstractMemSearchTest.java | 11 +++---- .../CompareFunctionSizesScript.java | 8 ++--- .../FindPotentialDecompilerProblems.java | 4 +-- .../java/docking/actions/KeyBindingUtils.java | 11 +++---- .../docking/test/AbstractDockingTest.java | 6 ++-- .../filechooser/GhidraFileChooserTest.java | 12 ++++--- .../java/ghidra/util/NumericUtilities.java | 9 +++--- .../src/main/java/util/CollectionUtils.java | 32 +++---------------- .../test/java/util/CollectionUtilsTest.java | 17 +--------- .../main/ImportGhidraToolsDialog.java | 8 ++--- .../sleigh/expr/OperandValueSolver.java | 7 ++-- .../sleigh/expr/RecursiveDescentSolver.java | 4 +-- .../assembler/sleigh/expr/SolverHint.java | 11 +++---- .../sem/AssemblyConstructorSemantic.java | 15 ++++----- .../sleigh/sem/AssemblyResolution.java | 22 ++++++------- .../sem/AssemblyResolvedConstructor.java | 32 ++++++++----------- .../sleigh/sem/AssemblyResolvedError.java | 4 +-- .../sleigh/sem/AssemblyTreeResolver.java | 20 ++++++------ .../program/database/code/StringDiff.java | 4 +-- .../assembler/sleigh/parse/ParserTest.java | 9 ++---- 20 files changed, 91 insertions(+), 155 deletions(-) diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchmem/AbstractMemSearchTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchmem/AbstractMemSearchTest.java index 86b9361e56..6e57c3ad42 100644 --- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchmem/AbstractMemSearchTest.java +++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchmem/AbstractMemSearchTest.java @@ -19,7 +19,8 @@ import static org.junit.Assert.*; import java.awt.Container; import java.awt.Window; -import java.util.*; +import java.util.List; +import java.util.Map; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -27,8 +28,6 @@ import javax.swing.*; import org.junit.After; -import com.google.common.collect.Lists; - import docking.action.DockingActionIf; import docking.test.AbstractDockingTest; import docking.widgets.fieldpanel.support.Highlight; @@ -47,6 +46,7 @@ import ghidra.test.AbstractProgramBasedTest; import ghidra.util.Msg; import ghidra.util.search.memory.MemSearchResult; import ghidra.util.table.GhidraTable; +import util.CollectionUtils; /** * Base class for memory search tests. @@ -192,7 +192,7 @@ public abstract class AbstractMemSearchTest extends AbstractProgramBasedTest { AddressSet addressSet = runSwing(() -> markers.getAddressSet()); AddressIterator it = addressSet.getAddresses(true); - List
list = Lists.newArrayList((Iterator
) it); + List
list = CollectionUtils.asStream(it).collect(Collectors.toList()); assertListEqualUnordered("Search markers not correctly generated", expected, list); } @@ -208,8 +208,7 @@ public abstract class AbstractMemSearchTest extends AbstractProgramBasedTest { protected void performSearchTest(List
expected, String buttonText) throws Exception { - for (int i = 0; i < expected.size(); i++) { - Address addr = expected.get(i); + for (Address addr : expected) { pressSearchButton(buttonText); assertEquals("Found", getStatusText()); cb.updateNow(); diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/CompareFunctionSizesScript.java b/Ghidra/Features/Decompiler/ghidra_scripts/CompareFunctionSizesScript.java index 5d7ce6223b..3ef0029662 100644 --- a/Ghidra/Features/Decompiler/ghidra_scripts/CompareFunctionSizesScript.java +++ b/Ghidra/Features/Decompiler/ghidra_scripts/CompareFunctionSizesScript.java @@ -25,7 +25,7 @@ import java.util.*; -import com.google.common.collect.Iterators; +import org.apache.commons.collections4.IteratorUtils; import ghidra.app.decompiler.*; import ghidra.app.decompiler.parallel.*; @@ -53,12 +53,12 @@ public class CompareFunctionSizesScript extends GhidraScript { throws Exception { InstructionIterator instIter = currentProgram.getListing().getInstructions( results.getFunction().getBody(), true); - int numInstructions = Iterators.size(instIter); + int numInstructions = IteratorUtils.size(instIter); //indicate failure of decompilation by having 0 high pcode ops int numHighOps = 0; if (results.getHighFunction() != null && results.getHighFunction().getPcodeOps() != null) { - numHighOps = Iterators.size(results.getHighFunction().getPcodeOps()); + numHighOps = IteratorUtils.size(results.getHighFunction().getPcodeOps()); } return new FuncBodyData(results.getFunction(), numInstructions, numHighOps); } @@ -66,7 +66,7 @@ public class CompareFunctionSizesScript extends GhidraScript { Set funcsToDecompile = new HashSet<>(); FunctionIterator fIter = currentProgram.getFunctionManager().getFunctionsNoStubs(true); - Iterators.addAll(funcsToDecompile, fIter); + fIter.forEach(e -> funcsToDecompile.add(e)); if (funcsToDecompile.isEmpty()) { popup("No functions to decompile!"); diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/FindPotentialDecompilerProblems.java b/Ghidra/Features/Decompiler/ghidra_scripts/FindPotentialDecompilerProblems.java index 5cfe62e662..ee704f35d1 100644 --- a/Ghidra/Features/Decompiler/ghidra_scripts/FindPotentialDecompilerProblems.java +++ b/Ghidra/Features/Decompiler/ghidra_scripts/FindPotentialDecompilerProblems.java @@ -26,8 +26,6 @@ import java.util.*; -import com.google.common.collect.Iterators; - import ghidra.app.decompiler.*; import ghidra.app.decompiler.parallel.*; import ghidra.app.script.GhidraScript; @@ -71,7 +69,7 @@ public class FindPotentialDecompilerProblems extends GhidraScript { Set funcsToDecompile = new HashSet<>(); FunctionIterator fIter = currentProgram.getFunctionManager().getFunctionsNoStubs(true); - Iterators.addAll(funcsToDecompile, fIter); + fIter.forEach(e -> funcsToDecompile.add(e)); if (funcsToDecompile.isEmpty()) { popup("No functions to decompile!"); diff --git a/Ghidra/Framework/Docking/src/main/java/docking/actions/KeyBindingUtils.java b/Ghidra/Framework/Docking/src/main/java/docking/actions/KeyBindingUtils.java index 0ccf9c1202..de613c3ac2 100644 --- a/Ghidra/Framework/Docking/src/main/java/docking/actions/KeyBindingUtils.java +++ b/Ghidra/Framework/Docking/src/main/java/docking/actions/KeyBindingUtils.java @@ -22,6 +22,7 @@ import java.awt.KeyboardFocusManager; import java.awt.event.*; import java.io.*; import java.util.*; +import java.util.stream.Collectors; import javax.swing.*; @@ -32,8 +33,6 @@ import org.jdom.*; import org.jdom.input.SAXBuilder; import org.jdom.output.XMLOutputter; -import com.google.common.collect.Sets; - import docking.DockingTool; import docking.DockingUtils; import docking.action.*; @@ -493,10 +492,10 @@ public class KeyBindingUtils { */ public static Set getActions(Set allActions, String owner, String name) { - - Set ownerMatch = - Sets.filter(allActions, action -> action.getOwner().equals(owner)); - return Sets.filter(ownerMatch, action -> action.getName().equals(name)); + return allActions.stream() + .filter(a -> a.getOwner().equals(owner)) + .filter(a -> a.getName().equals(name)) + .collect(Collectors.toSet()); } /** diff --git a/Ghidra/Framework/Docking/src/main/java/docking/test/AbstractDockingTest.java b/Ghidra/Framework/Docking/src/main/java/docking/test/AbstractDockingTest.java index ef0c86bb0e..7b5ba78afe 100644 --- a/Ghidra/Framework/Docking/src/main/java/docking/test/AbstractDockingTest.java +++ b/Ghidra/Framework/Docking/src/main/java/docking/test/AbstractDockingTest.java @@ -37,8 +37,6 @@ import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.junit.*; -import com.google.common.collect.Sets; - import docking.*; import docking.action.DockingActionIf; import docking.action.ToggleDockingActionIf; @@ -1137,7 +1135,9 @@ public abstract class AbstractDockingTest extends AbstractGenericTest { public static Set getActionsByOwnerAndName(DockingTool tool, String owner, String name) { Set ownerActions = tool.getDockingActionsByOwnerName(owner); - return Sets.filter(ownerActions, action -> action.getName().equals(name)); + return ownerActions.stream() + .filter(action -> action.getName().equals(name)) + .collect(Collectors.toSet()); } /** diff --git a/Ghidra/Framework/Docking/src/test.slow/java/docking/widgets/filechooser/GhidraFileChooserTest.java b/Ghidra/Framework/Docking/src/test.slow/java/docking/widgets/filechooser/GhidraFileChooserTest.java index 7c961dec23..9b3acfcfff 100644 --- a/Ghidra/Framework/Docking/src/test.slow/java/docking/widgets/filechooser/GhidraFileChooserTest.java +++ b/Ghidra/Framework/Docking/src/test.slow/java/docking/widgets/filechooser/GhidraFileChooserTest.java @@ -36,6 +36,7 @@ import java.util.concurrent.atomic.AtomicReference; import javax.swing.*; import javax.swing.table.JTableHeader; +import org.apache.commons.collections4.IteratorUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; @@ -43,8 +44,6 @@ import org.apache.logging.log4j.*; import org.apache.logging.log4j.core.config.Configurator; import org.junit.*; -import com.google.common.collect.Iterables; - import docking.*; import docking.action.DockingAction; import docking.test.AbstractDockingTest; @@ -1755,7 +1754,8 @@ public class GhidraFileChooserTest extends AbstractDockingTest { CompletableFuture> results = showMultiSelectionChooser(files.parent, FILES_ONLY); - selectFiles(Iterables.concat(files.files, files.dirs)); + selectFiles(CollectionUtils.asIterable( + IteratorUtils.chainedIterator(files.files.iterator(), files.dirs.iterator()))); pressOk(); assertChooserHidden(); @@ -1769,11 +1769,13 @@ public class GhidraFileChooserTest extends AbstractDockingTest { CompletableFuture> results = showMultiSelectionChooser(files.parent, GhidraFileChooserMode.FILES_AND_DIRECTORIES); - selectFiles(Iterables.concat(files.files, files.dirs)); + selectFiles(CollectionUtils.asIterable( + IteratorUtils.chainedIterator(files.files.iterator(), files.dirs.iterator()))); pressOk(); assertChooserHidden(); - assertChosen(results, Iterables.concat(files.files, files.dirs)); // dirs are dropped + assertChosen(results, CollectionUtils.asIterable( + IteratorUtils.chainedIterator(files.files.iterator(), files.dirs.iterator()))); // dirs are dropped } //================================================================================================== diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/NumericUtilities.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/NumericUtilities.java index 2d68a46be0..d19c0ab9a3 100644 --- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/NumericUtilities.java +++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/NumericUtilities.java @@ -18,11 +18,14 @@ package ghidra.util; import java.math.BigInteger; import java.util.*; import java.util.concurrent.atomic.AtomicLong; -import java.util.stream.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apache.commons.collections4.IteratorUtils; import org.apache.commons.lang3.StringUtils; +import util.CollectionUtils; + public final class NumericUtilities { public static final BigInteger MAX_UNSIGNED_LONG = new BigInteger("ffffffffffffffff", 16); public static final BigInteger MAX_SIGNED_LONG = new BigInteger("7fffffffffffffff", 16); @@ -694,9 +697,7 @@ public final class NumericUtilities { * @return hex string representation */ public static String convertBytesToString(Iterable bytes, String delimiter) { - - Stream stream = StreamSupport.stream(bytes.spliterator(), false); - return convertBytesToString(stream, delimiter); + return convertBytesToString(CollectionUtils.asStream(bytes), delimiter); } /** diff --git a/Ghidra/Framework/Generic/src/main/java/util/CollectionUtils.java b/Ghidra/Framework/Generic/src/main/java/util/CollectionUtils.java index 75052f966c..8e4c1651e2 100644 --- a/Ghidra/Framework/Generic/src/main/java/util/CollectionUtils.java +++ b/Ghidra/Framework/Generic/src/main/java/util/CollectionUtils.java @@ -24,24 +24,18 @@ import org.apache.commons.collections4.IteratorUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import com.google.common.collect.*; - /** * A collection of utility methods that prevent you from having to do unsafe casts of * {@link Collection} classes due to runtime type erasure. * - *

Be sure to check Guava and Apache collection utils before using this class, as they are - * standard utilities and often more efficient. + *

Be sure to check Apache collection utils before using this class, as it's a + * standard utility and often more efficient. * *

Some examples: *

    - *
  1. {@link Iterators}
  2. - *
  3. {@link Iterables}
  4. *
  5. {@link org.apache.commons.collections4.CollectionUtils}
  6. *
  7. {@link IterableUtils}
  8. *
  9. {@link IteratorUtils}
  10. - *
  11. {@link Maps}
  12. - *
  13. {@link Sets}
  14. *
  15. {@link StringUtils#join(Iterable, char)} - for pretty printing collections with newlines
  16. *
  17. Apache CollectionUtils.collect(Collection, Transformer) - to turn a * collection in to collection of strings when the default toString() is lacking
  18. @@ -404,21 +398,6 @@ public class CollectionUtils { return () -> iterator; } - /** - * Combines all collections passed-in, using {@link Iterables}, into a pass-through - * (not creating a new collection) Iterable. - * - *

    This is just a convenience method for {@link Iterables#concat(Iterable)} - * - * @param iterables the iterables to combine - * @return the iterable - */ - @SafeVarargs - public static Iterable asIterable(Iterable... iterables) { - Iterable concat = Iterables.concat(iterables); - return concat; - } - /** * Turns the given iterator into a stream * @@ -430,16 +409,15 @@ public class CollectionUtils { } /** - * Combines all iterables passed-in, using {@link Iterables}, into a pass-through - * (not creating a new collection) Stream. + * Combines all iterables passed-in into a pass-through (not creating a new collection) Stream. * * @param iterables the iterables to combine * @return the stream */ @SafeVarargs public static Stream asStream(Iterable... iterables) { - Iterable concat = Iterables.concat(iterables); - Stream s = StreamSupport.stream(concat.spliterator(), false); + Stream s = Stream.of(iterables) + .flatMap(e -> StreamSupport.stream(e.spliterator(), false)); return s; } diff --git a/Ghidra/Framework/Generic/src/test/java/util/CollectionUtilsTest.java b/Ghidra/Framework/Generic/src/test/java/util/CollectionUtilsTest.java index 6f47eca37a..6d3da36ef6 100644 --- a/Ghidra/Framework/Generic/src/test/java/util/CollectionUtilsTest.java +++ b/Ghidra/Framework/Generic/src/test/java/util/CollectionUtilsTest.java @@ -15,7 +15,7 @@ */ package util; -import static org.hamcrest.collection.IsIn.isOneOf; +import static org.hamcrest.collection.IsIn.*; import static org.junit.Assert.*; import java.util.*; @@ -225,21 +225,6 @@ public class CollectionUtilsTest { assertEquals("One", iterator.next()); } - @Test - public void testAsIterable_Collections() { - - List original = Arrays.asList("One", "Two", "Three", "Four"); - Collection a = Arrays.asList(original.get(0), original.get(1)); - Collection b = Arrays.asList(original.get(2)); - Collection c = Collections.emptyList(); - Collection d = Arrays.asList(original.get(3)); - Iterable iterable = CollectionUtils.asIterable(a, b, c, d); - - List result = new ArrayList<>(); - iterable.forEach(s -> result.add(s)); - assertEquals(original, result); - } - @Test public void testAsList_UnknownToType() { List list = new ArrayList<>(); diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/ImportGhidraToolsDialog.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/ImportGhidraToolsDialog.java index b8c7f30a44..f755211924 100644 --- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/ImportGhidraToolsDialog.java +++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/ImportGhidraToolsDialog.java @@ -20,12 +20,11 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.*; import java.util.List; +import java.util.stream.Stream; import javax.swing.*; import javax.swing.border.TitledBorder; -import com.google.common.collect.Iterables; - import docking.DialogComponentProvider; import docking.options.editor.ButtonPanelFactory; import docking.tool.ToolConstants; @@ -163,9 +162,8 @@ class ImportGhidraToolsDialog extends DialogComponentProvider { Set defaultTools = ToolUtils.getDefaultApplicationTools(); Set extraTools = ToolUtils.getExtraApplicationTools(); - Iterable defaultToolNames = - Iterables.transform(defaultTools, ToolTemplate::getPath); - Iterable extraToolNames = Iterables.transform(extraTools, ToolTemplate::getPath); + Stream defaultToolNames = defaultTools.stream().map(ToolTemplate::getPath); + Stream extraToolNames = extraTools.parallelStream().map(ToolTemplate::getPath); int elementCount = defaultTools.size() + extraTools.size(); tools = new String[elementCount]; diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/expr/OperandValueSolver.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/expr/OperandValueSolver.java index a471a3f4e1..23add124ca 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/expr/OperandValueSolver.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/expr/OperandValueSolver.java @@ -15,10 +15,7 @@ */ package ghidra.app.plugin.assembler.sleigh.expr; -import java.util.Map; -import java.util.Set; - -import com.google.common.collect.ImmutableList; +import java.util.*; import ghidra.app.plugin.assembler.sleigh.sem.*; import ghidra.app.plugin.processors.sleigh.Constructor; @@ -79,7 +76,7 @@ public class OperandValueSolver extends AbstractExpressionSolver { AssemblyResolvedError err = (AssemblyResolvedError) result; return AssemblyResolution.error(err.getError(), "Solution to " + sym.getName() + " := " + goal + " = " + patexp, - ImmutableList.of(result)); + List.of(result)); } // TODO: Shifting here seems like a hack to me. // I assume this only comes at the top of an expression diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/expr/RecursiveDescentSolver.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/expr/RecursiveDescentSolver.java index 32761ab058..e2d785f45a 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/expr/RecursiveDescentSolver.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/expr/RecursiveDescentSolver.java @@ -17,8 +17,6 @@ package ghidra.app.plugin.assembler.sleigh.expr; import java.util.*; -import com.google.common.collect.ImmutableSet; - import ghidra.app.plugin.assembler.sleigh.sem.AssemblyResolution; import ghidra.app.plugin.assembler.sleigh.sem.AssemblyResolvedConstructor; import ghidra.app.plugin.assembler.sleigh.util.DbgTimer; @@ -157,7 +155,7 @@ public class RecursiveDescentSolver { public AssemblyResolution solve(PatternExpression exp, MaskedLong goal, Map vals, Map res, AssemblyResolvedConstructor cur, String description) throws NeedsBackfillException { - return solve(exp, goal, vals, res, cur, ImmutableSet.of(), description); + return solve(exp, goal, vals, res, cur, Set.of(), description); } /** diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/expr/SolverHint.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/expr/SolverHint.java index e915330f98..8ec0067a98 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/expr/SolverHint.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/expr/SolverHint.java @@ -15,9 +15,7 @@ */ package ghidra.app.plugin.assembler.sleigh.expr; -import java.util.Set; - -import com.google.common.collect.ImmutableSet; +import java.util.*; /** * A type for solver hints @@ -34,9 +32,8 @@ import com.google.common.collect.ImmutableSet; */ public interface SolverHint { static Set with(Set set, SolverHint... plus) { - ImmutableSet.Builder hints = ImmutableSet.builder(); - hints.addAll(set); - hints.add(plus); - return hints.build(); + Set hints = new HashSet<>(set); + hints.addAll(Set.of(plus)); + return Collections.unmodifiableSet(hints); } } diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyConstructorSemantic.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyConstructorSemantic.java index 4c37c2e4ba..ac2c5e1350 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyConstructorSemantic.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyConstructorSemantic.java @@ -17,9 +17,6 @@ package ghidra.app.plugin.assembler.sleigh.sem; import java.util.*; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; - import ghidra.app.plugin.assembler.sleigh.expr.MaskedLong; import ghidra.app.plugin.assembler.sleigh.expr.RecursiveDescentSolver; import ghidra.app.plugin.assembler.sleigh.grammars.AssemblyProduction; @@ -42,10 +39,10 @@ public class AssemblyConstructorSemantic implements Comparable patterns = new HashSet<>(); protected final Constructor cons; - protected final ImmutableList indices; + protected final List indices; // A set initialized on first access with forbidden patterns added - protected ImmutableSet upatterns; + protected Set upatterns; /** * Build a new SLEIGH constructor semantic @@ -55,7 +52,7 @@ public class AssemblyConstructorSemantic implements Comparable indices) { this.cons = cons; - this.indices = ImmutableList.copyOf(indices); + this.indices = Collections.unmodifiableList(indices); } public void addPattern(DisjointPattern pat) { @@ -106,7 +103,7 @@ public class AssemblyConstructorSemantic implements Comparable getOperandIndices() { + public List getOperandIndices() { return indices; } @@ -135,7 +132,7 @@ public class AssemblyConstructorSemantic implements Comparable vals, Map opvals) { diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyResolution.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyResolution.java index 86c171c0f8..19464d47b3 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyResolution.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyResolution.java @@ -18,8 +18,6 @@ package ghidra.app.plugin.assembler.sleigh.sem; import java.util.List; import java.util.Map; -import com.google.common.collect.ImmutableList; - import ghidra.app.plugin.assembler.sleigh.expr.MaskedLong; import ghidra.app.plugin.processors.sleigh.expression.PatternExpression; import ghidra.app.plugin.processors.sleigh.pattern.DisjointPattern; @@ -34,7 +32,7 @@ import ghidra.app.plugin.processors.sleigh.pattern.DisjointPattern; */ public abstract class AssemblyResolution implements Comparable { protected final String description; - protected final ImmutableList children; + protected final List children; private boolean hashed = false; private int hash; @@ -55,9 +53,9 @@ public abstract class AssemblyResolution implements Comparable children) { + AssemblyResolution(String description, List children) { this.description = description; - this.children = children == null ? ImmutableList.of() : children; + this.children = children == null ? List.of() : children; } /* ******************************************************************************************** @@ -77,33 +75,33 @@ public abstract class AssemblyResolution implements Comparable sel) { + List sel) { return new AssemblyResolvedConstructor(description, sel, ins, ctx, null, null); } /** * Build an instruction-only successful resolution result - * @see #resolved(AssemblyPatternBlock, AssemblyPatternBlock, String, ImmutableList) + * @see #resolved(AssemblyPatternBlock, AssemblyPatternBlock, String, List) * @param ins the instruction pattern block * @param description a description of the resolution * @param children the children selected to resolve this constructor, or null * @return the new resolution */ public static AssemblyResolvedConstructor instrOnly(AssemblyPatternBlock ins, - String description, ImmutableList children) { + String description, List children) { return resolved(ins, AssemblyPatternBlock.nop(), description, children); } /** * Build a context-only successful resolution result - * @see #resolved(AssemblyPatternBlock, AssemblyPatternBlock, String, ImmutableList) + * @see #resolved(AssemblyPatternBlock, AssemblyPatternBlock, String, List) * @param ctx the context pattern block * @param description a description of the resolution * @param children the children selected to resolve this constructor, or null * @return the new resolution */ public static AssemblyResolvedConstructor contextOnly(AssemblyPatternBlock ctx, - String description, ImmutableList children) { + String description, List children) { return resolved(AssemblyPatternBlock.nop(), ctx, description, children); } @@ -141,7 +139,7 @@ public abstract class AssemblyResolution implements Comparable sel) { + List sel) { return resolved(AssemblyPatternBlock.nop(), AssemblyPatternBlock.nop(), description, sel); } @@ -153,7 +151,7 @@ public abstract class AssemblyResolution implements Comparable children) { + List children) { return new AssemblyResolvedError(description, children, error); } diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyResolvedConstructor.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyResolvedConstructor.java index 4c410c0ab4..f7ca45bb80 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyResolvedConstructor.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyResolvedConstructor.java @@ -24,15 +24,11 @@ import org.apache.commons.collections4.IteratorUtils; import org.apache.commons.collections4.Predicate; import org.apache.commons.lang3.StringUtils; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; - import ghidra.app.plugin.assembler.AssemblySelector; import ghidra.app.plugin.assembler.sleigh.expr.MaskedLong; import ghidra.app.plugin.assembler.sleigh.expr.RecursiveDescentSolver; import ghidra.app.plugin.processors.sleigh.ConstructState; import ghidra.app.plugin.processors.sleigh.ContextOp; -import ghidra.util.StringUtilities; /** * A {@link AssemblyResolution} indicating successful application of a constructor @@ -57,8 +53,8 @@ public class AssemblyResolvedConstructor extends AssemblyResolution { protected final AssemblyPatternBlock ins; protected final AssemblyPatternBlock ctx; - protected final ImmutableSet backfills; - protected final ImmutableSet forbids; + protected final Set backfills; + protected final Set forbids; @Override protected int computeHash() { @@ -98,14 +94,14 @@ public class AssemblyResolvedConstructor extends AssemblyResolution { * @see AssemblyResolution#resolved(AssemblyPatternBlock, AssemblyPatternBlock, String, List) */ AssemblyResolvedConstructor(String description, - ImmutableList children, AssemblyPatternBlock ins, - AssemblyPatternBlock ctx, ImmutableSet backfills, - ImmutableSet forbids) { + List children, AssemblyPatternBlock ins, + AssemblyPatternBlock ctx, Set backfills, + Set forbids) { super(description, children); this.ins = ins; this.ctx = ctx; - this.backfills = backfills == null ? ImmutableSet.of() : backfills; - this.forbids = forbids == null ? ImmutableSet.of() : forbids; + this.backfills = backfills == null ? Set.of() : backfills; + this.forbids = forbids == null ? Set.of() : forbids; } /** @@ -120,7 +116,7 @@ public class AssemblyResolvedConstructor extends AssemblyResolution { * @return the decoded resolution */ public static AssemblyResolvedConstructor fromString(String str, String description, - ImmutableList children) { + List children) { AssemblyPatternBlock ins = null; if (str.startsWith(INS)) { int end = str.indexOf(SEP); @@ -172,7 +168,7 @@ public class AssemblyResolvedConstructor extends AssemblyResolution { newForbids.add(f.shift(amt)); } return new AssemblyResolvedConstructor(description, children, newIns, ctx, - ImmutableSet.copyOf(newBackfills), ImmutableSet.copyOf(newForbids)); + Collections.unmodifiableSet(newBackfills), Collections.unmodifiableSet(newForbids)); } /** @@ -214,7 +210,7 @@ public class AssemblyResolvedConstructor extends AssemblyResolution { } } return new AssemblyResolvedConstructor(description, children, ins, ctx, backfills, - ImmutableSet.copyOf(newForbids)); + Collections.unmodifiableSet(newForbids)); } /** @@ -270,7 +266,7 @@ public class AssemblyResolvedConstructor extends AssemblyResolution { Set newForbids = new HashSet<>(this.forbids); newForbids.addAll(that.forbids); return new AssemblyResolvedConstructor(description, children, newIns, newCtx, - ImmutableSet.copyOf(newBackfills), ImmutableSet.copyOf(newForbids)); + Collections.unmodifiableSet(newBackfills), Collections.unmodifiableSet(newForbids)); } /** @@ -282,7 +278,7 @@ public class AssemblyResolvedConstructor extends AssemblyResolution { Set newBackfills = new HashSet<>(this.backfills); newBackfills.add(bf); return new AssemblyResolvedConstructor(description, children, ins, ctx, - ImmutableSet.copyOf(newBackfills), forbids); + Collections.unmodifiableSet(newBackfills), forbids); } /** @@ -294,7 +290,7 @@ public class AssemblyResolvedConstructor extends AssemblyResolution { Set combForbids = new HashSet<>(this.forbids); combForbids.addAll(more); return new AssemblyResolvedConstructor(description, children, ins, ctx, backfills, - ImmutableSet.copyOf(more)); + Collections.unmodifiableSet(more)); } /** @@ -446,7 +442,7 @@ public class AssemblyResolvedConstructor extends AssemblyResolution { newForbids.add((AssemblyResolvedConstructor) t); } return new AssemblyResolvedConstructor(description, children, ins, ctx, backfills, - ImmutableSet.copyOf(newForbids)); + Collections.unmodifiableSet(newForbids)); } /** diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyResolvedError.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyResolvedError.java index d606ca3962..24517fc328 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyResolvedError.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyResolvedError.java @@ -17,8 +17,6 @@ package ghidra.app.plugin.assembler.sleigh.sem; import java.util.List; -import com.google.common.collect.ImmutableList; - /** * A {@link AssemblyResolution} indicating the occurrence of a (usually semantic) error * @@ -49,7 +47,7 @@ public class AssemblyResolvedError extends AssemblyResolution { /** * @see AssemblyResolution#error(String, String, List) */ - AssemblyResolvedError(String description, ImmutableList children, + AssemblyResolvedError(String description, List children, String error) { super(description, children); AssemblyTreeResolver.dbg.println(error); diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyTreeResolver.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyTreeResolver.java index 40e6c0fc59..7498971747 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyTreeResolver.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/assembler/sleigh/sem/AssemblyTreeResolver.java @@ -19,7 +19,6 @@ import java.util.*; import org.apache.commons.collections4.IteratorUtils; -import com.google.common.collect.ImmutableList; import com.google.common.collect.Sets; import ghidra.app.plugin.assembler.sleigh.SleighAssemblerBuilder; @@ -109,7 +108,7 @@ public class AssemblyTreeResolver { if (rc.hasBackfills()) { ret.add(AssemblyResolution.error("Solution is incomplete", "failed backfill", - ImmutableList.of(rc))); + List.of(rc))); continue; } AssemblyResolvedConstructor ctx = @@ -117,7 +116,7 @@ public class AssemblyTreeResolver { AssemblyResolvedConstructor check = rc.combine(ctx); if (null == check) { ret.add(AssemblyResolution.error("Incompatible context", "resolving", - ImmutableList.of(rc))); + List.of(rc))); continue; } rc = check; @@ -178,12 +177,11 @@ public class AssemblyTreeResolver { intoNext.add(child); while (!path.isEmpty()) { AssemblyConstructorSemantic sem = path.pollLast(); - ImmutableList substs = - ImmutableList.of((AssemblyParseTreeNode) branch); + List substs = List.of((AssemblyParseTreeNode) branch); // 1 for (final AssemblyResolvedConstructor res : intoNext) { - ImmutableList sel = ImmutableList.of(res); - collected.absorb(resolveSelectedChildren(rec, substs, sel, ImmutableList.of(sem))); + List sel = List.of(res); + collected.absorb(resolveSelectedChildren(rec, substs, sel, List.of(sem))); } intoNext.clear(); // 2 @@ -249,7 +247,7 @@ public class AssemblyTreeResolver { * @return the results */ protected AssemblyResolutionResults resolveSelectedChildren(AssemblyProduction prod, - List substs, ImmutableList sel, + List substs, List sel, Collection semantics) { try (DbgCtx dc = dbg.start("Selecting: " + IteratorUtils.toString(sel.iterator(), @@ -503,12 +501,12 @@ public class AssemblyTreeResolver { // This is also where the shifting will happen. Collection semantics = grammar.getSemantics(prod); for (List sel : Sets.cartesianProduct(childRes)) { - results.absorb( - resolveSelectedChildren(prod, substs, ImmutableList.copyOf(sel), semantics)); + results.absorb(resolveSelectedChildren(prod, substs, + Collections.unmodifiableList(sel), semantics)); } if (!childErr.isEmpty()) { results.add(AssemblyResolution.error("Child errors", "Resolving " + prod, - ImmutableList.copyOf(childErr))); + Collections.unmodifiableList(childErr))); } return results; } diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/StringDiff.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/StringDiff.java index f96f4a6032..ec9bb7062a 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/StringDiff.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/StringDiff.java @@ -15,7 +15,7 @@ */ package ghidra.program.database.code; -import com.google.common.base.Objects; +import java.util.Objects; /** * Container object that holds a start and end position within a string. A list of StringDiffs @@ -105,7 +105,7 @@ public class StringDiff { } StringDiff other = (StringDiff) obj; - if (!Objects.equal(text, other.text)) { + if (!Objects.equals(text, other.text)) { return false; } if (start != other.start) { diff --git a/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/app/plugin/assembler/sleigh/parse/ParserTest.java b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/app/plugin/assembler/sleigh/parse/ParserTest.java index 91ad1aaf8a..d3f237f542 100644 --- a/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/app/plugin/assembler/sleigh/parse/ParserTest.java +++ b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/app/plugin/assembler/sleigh/parse/ParserTest.java @@ -15,8 +15,7 @@ */ package ghidra.app.plugin.assembler.sleigh.parse; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.io.PrintStream; import java.util.*; @@ -25,8 +24,6 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.junit.Test; -import com.google.common.collect.ImmutableSet; - import ghidra.app.plugin.assembler.sleigh.grammars.*; import ghidra.app.plugin.assembler.sleigh.symbol.*; import ghidra.app.plugin.assembler.sleigh.tree.*; @@ -522,7 +519,7 @@ public class ParserTest { assertTrue(res instanceof AssemblyParseErrorResult); AssemblyParseErrorResult err = (AssemblyParseErrorResult) res; Collection sug = err.getSuggestions(); - assertEquals(ImmutableSet.builder().add("b").build(), sug); + assertEquals(Set.of("b"), sug); } } @@ -542,7 +539,7 @@ public class ParserTest { assertTrue(res instanceof AssemblyParseErrorResult); AssemblyParseErrorResult err = (AssemblyParseErrorResult) res; Collection sug = err.getSuggestions(); - assertEquals(ImmutableSet.builder().add(" ").build(), sug); + assertEquals(Set.of(" "), sug); } }