GT-3354: Removing some Guava

This commit is contained in:
Ryan Kurtz 2019-12-05 14:34:03 -05:00
parent 3a6c3312fe
commit 2a64cf2a77
20 changed files with 91 additions and 155 deletions

View file

@ -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<OperandValue> {
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

View file

@ -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<String, Long> vals,
Map<Integer, Object> 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);
}
/**

View file

@ -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<SolverHint> with(Set<SolverHint> set, SolverHint... plus) {
ImmutableSet.Builder<SolverHint> hints = ImmutableSet.builder();
hints.addAll(set);
hints.add(plus);
return hints.build();
Set<SolverHint> hints = new HashSet<>(set);
hints.addAll(Set.of(plus));
return Collections.unmodifiableSet(hints);
}
}

View file

@ -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<AssemblyConstruct
protected final Set<AssemblyResolvedConstructor> patterns = new HashSet<>();
protected final Constructor cons;
protected final ImmutableList<Integer> indices;
protected final List<Integer> indices;
// A set initialized on first access with forbidden patterns added
protected ImmutableSet<AssemblyResolvedConstructor> upatterns;
protected Set<AssemblyResolvedConstructor> upatterns;
/**
* Build a new SLEIGH constructor semantic
@ -55,7 +52,7 @@ public class AssemblyConstructorSemantic implements Comparable<AssemblyConstruct
*/
public AssemblyConstructorSemantic(Constructor cons, List<Integer> 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<AssemblyConstruct
* Get the list of operand indices in print piece order
* @return the list
*/
public ImmutableList<Integer> getOperandIndices() {
public List<Integer> getOperandIndices() {
return indices;
}
@ -135,7 +132,7 @@ public class AssemblyConstructorSemantic implements Comparable<AssemblyConstruct
AssemblyResolvedConstructor fpat = withComputedForbids(pat);
result.add(fpat);
}
upatterns = ImmutableSet.copyOf(result);
upatterns = Collections.unmodifiableSet(result);
}
/**
@ -239,7 +236,7 @@ public class AssemblyConstructorSemantic implements Comparable<AssemblyConstruct
* reverse, the context is solved immediately before applying the selected constructor
* patterns.
*
* @see AssemblyTreeResolver#resolveSelectedChildren(AssemblyProduction, List, ImmutableList, Collection)
* @see AssemblyTreeResolver#resolveSelectedChildren(AssemblyProduction, List, List, Collection)
*/
public AssemblyResolution solveContextChanges(AssemblyResolvedConstructor res,
Map<String, Long> vals, Map<Integer, Object> opvals) {

View file

@ -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<AssemblyResolution> {
protected final String description;
protected final ImmutableList<? extends AssemblyResolution> children;
protected final List<? extends AssemblyResolution> children;
private boolean hashed = false;
private int hash;
@ -55,9 +53,9 @@ public abstract class AssemblyResolution implements Comparable<AssemblyResolutio
* @param description a textual description used as part of {@link #toString()}
* @param children for record keeping, any children used in constructing this resolution
*/
AssemblyResolution(String description, ImmutableList<? extends AssemblyResolution> children) {
AssemblyResolution(String description, List<? extends AssemblyResolution> 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<AssemblyResolutio
*/
public static AssemblyResolvedConstructor resolved(AssemblyPatternBlock ins,
AssemblyPatternBlock ctx, String description,
ImmutableList<? extends AssemblyResolution> sel) {
List<? extends AssemblyResolution> 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<AssemblyResolution> children) {
String description, List<AssemblyResolution> 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<AssemblyResolution> children) {
String description, List<AssemblyResolution> children) {
return resolved(AssemblyPatternBlock.nop(), ctx, description, children);
}
@ -141,7 +139,7 @@ public abstract class AssemblyResolution implements Comparable<AssemblyResolutio
* @return the new resolution
*/
public static AssemblyResolvedConstructor nop(String description,
ImmutableList<? extends AssemblyResolution> sel) {
List<? extends AssemblyResolution> sel) {
return resolved(AssemblyPatternBlock.nop(), AssemblyPatternBlock.nop(), description, sel);
}
@ -153,7 +151,7 @@ public abstract class AssemblyResolution implements Comparable<AssemblyResolutio
* @return the new resolution
*/
public static AssemblyResolvedError error(String error, String description,
ImmutableList<? extends AssemblyResolution> children) {
List<? extends AssemblyResolution> children) {
return new AssemblyResolvedError(description, children, error);
}

View file

@ -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<AssemblyResolvedBackfill> backfills;
protected final ImmutableSet<AssemblyResolvedConstructor> forbids;
protected final Set<AssemblyResolvedBackfill> backfills;
protected final Set<AssemblyResolvedConstructor> 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<? extends AssemblyResolution> children, AssemblyPatternBlock ins,
AssemblyPatternBlock ctx, ImmutableSet<AssemblyResolvedBackfill> backfills,
ImmutableSet<AssemblyResolvedConstructor> forbids) {
List<? extends AssemblyResolution> children, AssemblyPatternBlock ins,
AssemblyPatternBlock ctx, Set<AssemblyResolvedBackfill> backfills,
Set<AssemblyResolvedConstructor> 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<AssemblyResolution> children) {
List<AssemblyResolution> 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<AssemblyResolvedConstructor> 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<AssemblyResolvedBackfill> 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<AssemblyResolvedConstructor> 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));
}
/**

View file

@ -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<? extends AssemblyResolution> children,
AssemblyResolvedError(String description, List<? extends AssemblyResolution> children,
String error) {
super(description, children);
AssemblyTreeResolver.dbg.println(error);

View file

@ -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<AssemblyParseTreeNode> substs =
ImmutableList.of((AssemblyParseTreeNode) branch);
List<AssemblyParseTreeNode> substs = List.of((AssemblyParseTreeNode) branch);
// 1
for (final AssemblyResolvedConstructor res : intoNext) {
ImmutableList<AssemblyResolvedConstructor> sel = ImmutableList.of(res);
collected.absorb(resolveSelectedChildren(rec, substs, sel, ImmutableList.of(sem)));
List<AssemblyResolvedConstructor> 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<AssemblyParseTreeNode> substs, ImmutableList<AssemblyResolvedConstructor> sel,
List<AssemblyParseTreeNode> substs, List<AssemblyResolvedConstructor> sel,
Collection<AssemblyConstructorSemantic> 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<AssemblyConstructorSemantic> semantics = grammar.getSemantics(prod);
for (List<AssemblyResolvedConstructor> 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;
}

View file

@ -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) {

View file

@ -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<String> 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<String> sug = err.getSuggestions();
assertEquals(ImmutableSet.builder().add(" ").build(), sug);
assertEquals(Set.of(" "), sug);
}
}