Skip to content

Commit

Permalink
GT-3350: Consistently ordered classpath and ExtensionPoint priorities
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmkurtz committed Dec 3, 2019
1 parent 7ab75e4 commit 8f00152
Show file tree
Hide file tree
Showing 52 changed files with 339 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

import java.awt.Color;
import java.math.BigInteger;
import java.util.*;
import java.util.ArrayList;
import java.util.List;

import docking.widgets.fieldpanel.field.*;
import docking.widgets.fieldpanel.support.FieldLocation;
Expand All @@ -43,7 +44,7 @@ private static synchronized List<ExternalDisassembler> getAvailableDisassemblers
availableDisassemblers = new ArrayList<>();

// find the available external disassemblers
Set<ExternalDisassembler> extDisassemblers =
List<ExternalDisassembler> extDisassemblers =
ClassSearcher.getInstances(ExternalDisassembler.class);

for (ExternalDisassembler disassember : extDisassemblers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void run() throws Exception {
addPlugin(moduleName, pluginDescription);
}

Set<Analyzer> instances = ClassSearcher.getInstances(Analyzer.class);
List<Analyzer> instances = ClassSearcher.getInstances(Analyzer.class);
for (Analyzer analyzer : instances) {
Class<? extends Analyzer> clazz = analyzer.getClass();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private void initializeAnalyzers() {

Options options = currentProgram.getOptions(Program.ANALYSIS_PROPERTIES);

Set<Class<? extends Analyzer>> classes = ClassSearcher.getClasses(Analyzer.class);
List<Class<? extends Analyzer>> classes = ClassSearcher.getClasses(Analyzer.class);
for (Class<? extends Analyzer> element : classes) {
Analyzer analyzer;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package ghidra.app.cmd.label;

import java.util.Set;
import java.util.List;

import ghidra.app.util.demangler.*;
import ghidra.framework.cmd.BackgroundCommand;
Expand All @@ -33,7 +33,7 @@ public class DemanglerCmd extends BackgroundCommand {
private String mangled;
private String result;
private DemangledObject demangledObject;
private static Set<Demangler> demanglers;
private static List<Demangler> demanglers;
private DemanglerOptions options;

public DemanglerCmd(Address addr, String mangled) {
Expand Down Expand Up @@ -138,7 +138,7 @@ public DemangledObject getDemangledObject() {
return demangledObject;
}

private static Set<Demangler> getDemanglers() {
private static List<Demangler> getDemanglers() {
if (demanglers == null) {
demanglers = ClassSearcher.getInstances(Demangler.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private void initializeAnalyzers() {
taskArray = new AnalysisTaskList[] { byteTasks, instructionTasks, functionTasks,
functionModifierChangedTasks, functionSignatureChangedTasks, dataTasks };

Set<Analyzer> analyzers = ClassSearcher.getInstances(Analyzer.class);
List<Analyzer> analyzers = ClassSearcher.getInstances(Analyzer.class);
for (Analyzer analyzer : analyzers) {
if (!analyzer.canAnalyze(program)) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
import ghidra.program.model.mem.Memory;
import ghidra.program.model.mem.MemoryAccessException;
import ghidra.program.model.util.MemoryByteIterator;
import ghidra.util.classfinder.ExtensionPoint;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;

/**
* This class is used for the computation of various basic checksums.
*/
@ExtensionPoint.Exclude(reason = "Subclasses will get picked up by extension points.")
public class BasicChecksumAlgorithm extends ChecksumAlgorithm {
public abstract class BasicChecksumAlgorithm extends ChecksumAlgorithm {

/**
* The byte sizes that are supported by the basic checksum algorithm.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

import java.awt.BorderLayout;
import java.awt.Color;
import java.util.*;
import java.util.ArrayList;
import java.util.List;

import javax.swing.*;

Expand Down Expand Up @@ -63,7 +64,7 @@ public ComputeChecksumsProvider(ComputeChecksumsPlugin plugin) {
super(plugin.getTool(), "Checksum Generator", plugin.getName(), ProgramContextAction.class);

setHelpLocation(new HelpLocation("ComputeChecksumsPlugin", "Generate_Checksum_Help"));
Set<ChecksumAlgorithm> algorithms = ClassSearcher.getInstances(ChecksumAlgorithm.class);
List<ChecksumAlgorithm> algorithms = ClassSearcher.getInstances(ChecksumAlgorithm.class);
checksums.addAll(algorithms);

this.plugin = plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
import ghidra.program.model.mem.Memory;
import ghidra.program.model.mem.MemoryAccessException;
import ghidra.program.model.util.MemoryByteIterator;
import ghidra.util.classfinder.ExtensionPoint;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;

/**
* This class is used for the computation of various digest checksums that are provided
* by java. These checksums do not have options associated with them.
*/
@ExtensionPoint.Exclude(reason = "Subclasses will get picked up by extension points.")
public class DigestChecksumAlgorithm extends ChecksumAlgorithm {
public abstract class DigestChecksumAlgorithm extends ChecksumAlgorithm {

MessageDigest digester;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void actionPerformed(ActionContext context) {
*/
private void exportToC(GTree gTree, DataTypeManager programDataTypeMgr) {

Set<Class<? extends AnnotationHandler>> classes =
List<Class<? extends AnnotationHandler>> classes =
ClassSearcher.getClasses(AnnotationHandler.class);

List<AnnotationHandler> list = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private List<CodeComparisonPanel<? extends FieldPanelCoordinator>> getCodeCompar
@SuppressWarnings({ "rawtypes", "unchecked" })
private Set<CodeComparisonPanel<? extends FieldPanelCoordinator>> createAllPossibleCodeComparisonPanels() {
Set<CodeComparisonPanel<? extends FieldPanelCoordinator>> instances = new HashSet<>();
Set<Class<? extends CodeComparisonPanel>> classes =
List<Class<? extends CodeComparisonPanel>> classes =
ClassSearcher.getClasses(CodeComparisonPanel.class);
for (Class<? extends CodeComparisonPanel> panelClass : classes) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ private static void findDataTypeMatchesOutsideOfListing(
Accumulator<LocationReference> accumulator, Program program, DataType dataType,
String fieldName, TaskMonitor monitor) throws CancelledException {

Set<DataTypeReferenceFinder> finders =
List<DataTypeReferenceFinder> finders =
ClassSearcher.getInstances(DataTypeReferenceFinder.class);

Consumer<DataTypeReference> callback = ref -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
public class OverviewColorPlugin extends ProgramPlugin {
public static final String HELP_TOPIC = "OverviewPlugin";
private static final String ACTIVE_SERVICES = "ActiveServices";
private Set<OverviewColorService> allServices;
private List<OverviewColorService> allServices;
private Map<OverviewColorService, OverviewColorComponent> activeServices =
new LinkedHashMap<>(); // maintain the left to right order of the active overview bars.
private CodeViewerService codeViewerService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,26 @@
*/
package ghidra.app.plugin.core.validator;

import java.lang.reflect.Constructor;
import java.util.*;

import docking.ActionContext;
import docking.action.DockingAction;
import docking.action.MenuData;
import docking.tool.ToolConstants;
import docking.widgets.conditiontestpanel.ConditionTester;
import ghidra.app.CorePluginPackage;
import ghidra.app.context.ProgramActionContext;
import ghidra.app.context.ProgramContextAction;
import ghidra.app.plugin.PluginCategoryNames;
import ghidra.app.plugin.core.analysis.validator.PostAnalysisValidator;
import ghidra.framework.plugintool.*;
import ghidra.framework.plugintool.util.*;
import ghidra.framework.plugintool.util.PluginStatus;
import ghidra.program.model.listing.Program;
import ghidra.util.HelpLocation;
import ghidra.util.Msg;
import ghidra.util.classfinder.ClassSearcher;

import java.lang.reflect.Constructor;
import java.util.*;

import docking.ActionContext;
import docking.action.DockingAction;
import docking.action.MenuData;
import docking.tool.ToolConstants;
import docking.widgets.conditiontestpanel.ConditionTester;

/**
* Display a pop-up dialog to run PostAnalysisValidator tests on the Program
* that is currently open in the tool.
Expand Down Expand Up @@ -117,7 +116,7 @@ private void validate(Program program) {
private List<ConditionTester> getConditionTests(Program program) {
List<ConditionTester> list = new ArrayList<ConditionTester>();

Set<Class<? extends PostAnalysisValidator>> validatorClasses =
List<Class<? extends PostAnalysisValidator>> validatorClasses =
ClassSearcher.getClasses(PostAnalysisValidator.class);
for (Class<? extends PostAnalysisValidator> validatorClass : validatorClasses) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package ghidra.app.util.demangler;

import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -39,7 +38,7 @@ public class DemanglerUtil {
* @return the demangled object or null
*/
public static DemangledObject demangle(String mangled) {
Set<Demangler> demanglers = getDemanglers();
List<Demangler> demanglers = getDemanglers();
for (Demangler demangler : demanglers) {
try {
// not sure if we should be doing all symbols, but this is what it used to do
Expand All @@ -65,7 +64,7 @@ public static DemangledObject demangle(String mangled) {
* @return the demangled object or null
*/
public static DemangledObject demangle(Program program, String mangled) {
Set<Demangler> demanglers = getDemanglers();
List<Demangler> demanglers = getDemanglers();
for (Demangler demangler : demanglers) {
try {
if (!demangler.canDemangle(program)) {
Expand All @@ -91,7 +90,7 @@ public static DemangledObject demangle(Program program, String mangled) {
*
* @return a list of all demanglers
*/
private static Set<Demangler> getDemanglers() {
private static List<Demangler> getDemanglers() {
return ClassSearcher.getInstances(Demangler.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static Map<String, AnnotatedStringHandler> createAnnotatedStringHandlerM
Map<String, AnnotatedStringHandler> map = new HashMap<>();

// find all instances of AnnotatedString
Set<AnnotatedStringHandler> instances =
List<AnnotatedStringHandler> instances =
ClassSearcher.getInstances(AnnotatedStringHandler.class);

for (AnnotatedStringHandler instance : instances) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/
package ghidra.app.util.viewer.format;

import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import org.jdom.Element;
Expand Down Expand Up @@ -139,7 +140,7 @@ private void notifyServicesChanged() {
private void getFactorys() {
ClassFilter filter = new ClassExclusionFilter(DummyFieldFactory.class,
SpacerFieldFactory.class, SubDataFieldFactory.class);
Set<FieldFactory> instances = ClassSearcher.getInstances(FieldFactory.class, filter);
List<FieldFactory> instances = ClassSearcher.getInstances(FieldFactory.class, filter);
List<FieldFactory> list = new ArrayList<>();
for (FieldFactory fieldFactory : instances) {
if (fieldFactory instanceof SpacerFieldFactory) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,18 +15,17 @@
*/
package ghidra.app.util.viewer.util;

import java.awt.event.MouseEvent;
import java.util.*;

import docking.widgets.fieldpanel.support.FieldLocation;
import ghidra.app.nav.Navigatable;
import ghidra.app.services.*;
import ghidra.app.util.viewer.field.*;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.program.util.ProgramLocation;
import ghidra.util.classfinder.ClassSearcher;

import java.awt.event.MouseEvent;
import java.util.*;

import docking.widgets.fieldpanel.support.FieldLocation;

/**
* Helper class to navigate to an address when user double clicks in a
* Field. This class will find {@link FieldMouseHandlerExtension}s by using the {@link ClassSearcher}.
Expand Down Expand Up @@ -84,7 +82,7 @@ private Map<Class<?>, List<FieldMouseHandler>> initializeFieldMouseHandlers() {
new HashMap<Class<?>, List<FieldMouseHandler>>();

// find all instances of AnnotatedString
Set<FieldMouseHandlerExtension> instances =
List<FieldMouseHandlerExtension> instances =
ClassSearcher.getInstances(FieldMouseHandlerExtension.class);
for (FieldMouseHandlerExtension fieldMouseHandler : instances) {
addHandler(map, fieldMouseHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package ghidra.framework;

import java.io.File;
import java.util.Set;
import java.util.List;

import generic.jar.ResourceFile;
import ghidra.GhidraClassLoader;
Expand Down Expand Up @@ -111,7 +111,7 @@ private void locateCACertsFile() {
}

private void performModuleInitialization() {
Set<ModuleInitializer> instances = ClassSearcher.getInstances(ModuleInitializer.class);
List<ModuleInitializer> instances = ClassSearcher.getInstances(ModuleInitializer.class);
for (ModuleInitializer initializer : instances) {
monitor.setMessage("Initializing " + initializer.getName() + "...");
initializer.run();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,12 +15,13 @@
*/
package ghidra.framework.analysis;

import java.util.ArrayList;
import java.util.List;

import ghidra.app.services.Analyzer;
import ghidra.program.model.listing.Program;
import ghidra.util.classfinder.ClassSearcher;

import java.util.*;

public class AnalysisRecipeBuilder {

private static List<Class<? extends Analyzer>> classes;
Expand All @@ -39,7 +39,7 @@ public static AnalysisRecipe getRecipe(Program program) {

private static AnalysisRecipe buildDefaultRecipe(Program program) {
List<Analyzer> analyzerList = new ArrayList<Analyzer>();
Set<Analyzer> anayzers = ClassSearcher.getInstances(Analyzer.class);
List<Analyzer> anayzers = ClassSearcher.getInstances(Analyzer.class);
for (Analyzer analyzer : anayzers) {
if (analyzer.canAnalyze(program)) {
analyzerList.add(analyzer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import ghidra.program.util.ProgramLocation;
import ghidra.program.util.ProgramSelection;
import ghidra.util.Msg;
import ghidra.util.classfinder.ExtensionPoint;
import ghidra.util.classfinder.ExtensionPointProperties;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;

@ExtensionPoint.Exclude(reason = "requires explicit instantiation to wrap a script")
@ExtensionPointProperties(exclude = true) // exclude class from extension point discovery because it has to be directly instantiated in order to wrap the supplied script
public class GhidraScriptAnalyzerAdapter extends AbstractAnalyzer {

private ResourceFile scriptFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static org.junit.Assert.*;

import java.util.List;
import java.util.Set;

import org.junit.*;

Expand Down Expand Up @@ -88,7 +87,7 @@ public void testOnlyFrontendablePluginsAreAvailable() {
count++;
}

Set<Class<? extends FrontEndable>> classes = ClassSearcher.getClasses(FrontEndable.class);
List<Class<? extends FrontEndable>> classes = ClassSearcher.getClasses(FrontEndable.class);
assertEquals(count, classes.size());
}

Expand Down
Loading

0 comments on commit 8f00152

Please sign in to comment.