GP-126 added cumulative analysis task times to stored Program

Information
This commit is contained in:
ghidra1 2020-08-28 19:54:42 -04:00
parent 36e9e6dd66
commit 79c99b01fd
7 changed files with 359 additions and 54 deletions

View file

@ -144,63 +144,25 @@ public abstract class AbstractOptions implements Options {
}
Option currentOption = valueMap.get(optionName);
if (currentOption == null) {
if (currentOption == null ||
!isCompatibleOption(currentOption, type, defaultValue, editor)) {
Option option =
createRegisteredOption(optionName, type, description, help, defaultValue, editor);
valueMap.put(optionName, option);
return;
}
Option newOption = null;
if (currentOption.isRegistered()) {
// Registered again
newOption =
copyRegisteredOption(currentOption, type, description, defaultValue, help, editor);
}
else {
// option was accessed, but not registered
newOption =
createRegisteredOption(optionName, type, description, help, defaultValue, editor);
currentOption.updateRegistration(description, help, defaultValue, editor);
}
copyCurrentValue(currentOption, newOption);
valueMap.put(optionName, newOption);
}
protected void copyCurrentValue(Option currentOption, Option newOption) {
if (currentOption.isDefault()) {
return; // don't copy the current value if it is just the old default.
private boolean isCompatibleOption(Option option, OptionType type, Object defaultValue,
PropertyEditor editor) {
if (option.getOptionType() != type) {
return false;
}
Object currentValue = currentOption.getCurrentValue();
OptionType type = currentOption.getOptionType();
if (!isNullable(type) && currentValue == null) {
return; // not allowed to be null
}
// null is allowed; null can represent a valid 'cleared' state
newOption.setCurrentValue(currentValue);
}
private Option copyRegisteredOption(Option currentOption, OptionType type,
String description, Object defaultValue, HelpLocation help, PropertyEditor editor) {
// We probably don't need to do anything special if we are re-registering an option,
// which is what the below code handles
String oldDescription = currentOption.getDescription();
HelpLocation oldHelp = currentOption.getHelpLocation();
Object oldDefaultValue = currentOption.getDefaultValue();
PropertyEditor oldEditor = currentOption.getPropertyEditor();
String newDescripiton = oldDescription == null ? description : oldDescription;
HelpLocation newHelpLocation = oldHelp == null ? help : oldHelp;
Object newDefaultValue = oldDefaultValue == null ? defaultValue : oldDefaultValue;
PropertyEditor newEditor = oldEditor == null ? editor : oldEditor;
String optionName = currentOption.getName();
return createRegisteredOption(optionName, type, newDescripiton, newHelpLocation,
newDefaultValue, newEditor);
Object optionValue = option.getValue(null);
return optionValue == null || defaultValue == null ||
optionValue.getClass().equals(defaultValue.getClass());
}
@Override

View file

@ -20,6 +20,7 @@ import java.beans.*;
import java.util.HashSet;
import java.util.Set;
import ghidra.framework.Application;
import ghidra.util.SystemUtilities;
public class EditorState implements PropertyChangeListener {
@ -146,7 +147,9 @@ public class EditorState implements PropertyChangeListener {
editor.removePropertyChangeListener(this);
editor = new ErrorPropertyEditor(
"Ghidra does not know how to use PropertyEditor: " + editor.getClass().getName(), null);
Application.getName() + " does not know how to use PropertyEditor: " +
editor.getClass().getName(),
null);
return editor.getCustomEditor();
}

View file

@ -24,13 +24,13 @@ import utilities.util.reflection.ReflectionUtilities;
public abstract class Option {
private final String name;
private final Object defaultValue;
private Object defaultValue;
private boolean isRegistered;
private final String description;
private final HelpLocation helpLocation;
private final OptionType optionType;
private String description;
private HelpLocation helpLocation;
private OptionType optionType;
private final PropertyEditor propertyEditor;
private PropertyEditor propertyEditor;
private String inceptionInformation;
protected Option(String name, OptionType optionType, String description,
@ -48,6 +48,25 @@ public abstract class Option {
}
}
/**
* Update any null registration information using the specified updated information.
* This assumption is that multiple registrations for the same option may be partial
* but will be compatible. No compatibility checks are performed between existing
* registration and update registration info.
* @param updatedDescription updated option description (will be ignored if description previously set)
* @param updatedHelp updated option help location (will be ignored if help location previously set)
* @param updatedDefaultValue updated option default-value (will be ignored if default-value previously set)
* @param updatedEditor updated option editor (will be ignored if editor previously set)
*/
final void updateRegistration(String updatedDescription, HelpLocation updatedHelp,
Object updatedDefaultValue, PropertyEditor updatedEditor) {
description = description != null ? description : updatedDescription;
helpLocation = helpLocation != null ? helpLocation : updatedHelp;
defaultValue = defaultValue != null ? defaultValue : updatedDefaultValue;
propertyEditor = propertyEditor != null ? propertyEditor : updatedEditor;
isRegistered = true;
}
public abstract Object getCurrentValue();
public abstract void doSetCurrentValue(Object value);