GT-2832 - fix Data Type Preview to allow string data types.

This commit is contained in:
dev747368 2019-04-24 16:48:29 -04:00
parent 49ae6ec0f9
commit e8343999d4
3 changed files with 43 additions and 26 deletions

View File

@ -282,7 +282,7 @@ public class DataTypePreviewPlugin extends ProgramPlugin {
dtm = activeProgram.getDataTypeManager(); dtm = activeProgram.getDataTypeManager();
} }
DataTypeSelectionDialog d = new DataTypeSelectionDialog(tool, dtm, Integer.MAX_VALUE, DataTypeSelectionDialog d = new DataTypeSelectionDialog(tool, dtm, Integer.MAX_VALUE,
AllowedDataTypes.FIXED_LENGTH); AllowedDataTypes.STRINGS_AND_FIXED_LENGTH);
tool.showDialog(d, provider); tool.showDialog(d, provider);
DataType dt = d.getUserChosenDataType(); DataType dt = d.getUserChosenDataType();
if (dt != null) { if (dt != null) {

View File

@ -1,6 +1,5 @@
/* ### /* ###
* IP: GHIDRA * IP: GHIDRA
* REVIEWED: YES
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -323,7 +322,7 @@ public class DataTypeSelectionEditor extends AbstractCellEditor {
// then changed the text field text. // then changed the text field text.
DataType selectedDataType = selectionField.getSelectedValue(); DataType selectedDataType = selectionField.getSelectedValue();
if (selectedDataType != null && selectionField.getText().equals(selectedDataType.getName())) { if (selectedDataType != null && selectionField.getText().equals(selectedDataType.getName())) {
DataTypeParser.checkAllowableType(selectedDataType, allowedDataTypes); DataTypeParser.ensureIsAllowableType(selectedDataType, allowedDataTypes);
return true; return true;
} }

View File

@ -41,7 +41,11 @@ public class DataTypeParser {
/** /**
* Only Fixed-length data-types * Only Fixed-length data-types
*/ */
FIXED_LENGTH FIXED_LENGTH,
/**
* Only Fixed-length data types and string data types
*/
STRINGS_AND_FIXED_LENGTH
} }
private DataTypeManager sourceDataTypeManager; // may be null private DataTypeManager sourceDataTypeManager; // may be null
@ -144,30 +148,44 @@ public class DataTypeParser {
} }
/** /**
* Validate the specified data-type dt against the specified allowedTypes. * Throws exception if the data type does not match the specified {@link AllowedDataTypes}.
* @param dt data-type *
* @param allowedTypes * @param dt {@link DataType} to check
* @param allowedTypes {@link AllowedDataTypes enum} specifying what category of data types are ok
* @throws InvalidDataTypeException if dt violates the specified allowedTypes * @throws InvalidDataTypeException if dt violates the specified allowedTypes
*/ */
public static void checkAllowableType(DataType dt, AllowedDataTypes allowedTypes) public static void ensureIsAllowableType(DataType dt, AllowedDataTypes allowedTypes)
throws InvalidDataTypeException { throws InvalidDataTypeException {
if (allowedTypes == AllowedDataTypes.DYNAMIC) { switch (allowedTypes) {
if (dt instanceof FactoryDataType) { case DYNAMIC:
throw new InvalidDataTypeException("factory data-type not allowed"); if (dt instanceof FactoryDataType) {
} throw new InvalidDataTypeException("factory data-type not allowed");
} }
else if (allowedTypes == AllowedDataTypes.SIZABLE_DYNAMIC) { break;
if (dt instanceof FactoryDataType) { case SIZABLE_DYNAMIC:
throw new InvalidDataTypeException("factory data-type not allowed"); if (dt instanceof FactoryDataType) {
} throw new InvalidDataTypeException("factory data-type not allowed");
if (dt instanceof Dynamic && !((Dynamic) dt).canSpecifyLength()) { }
throw new InvalidDataTypeException("non-sizable data-type not allowed"); if (dt instanceof Dynamic && !((Dynamic) dt).canSpecifyLength()) {
} throw new InvalidDataTypeException("non-sizable data-type not allowed");
} }
else if (allowedTypes == AllowedDataTypes.FIXED_LENGTH) { break;
if (dt.getLength() < 0) { case FIXED_LENGTH:
throw new InvalidDataTypeException("fixed-length data-type required"); if (dt.getLength() < 0) {
} throw new InvalidDataTypeException("fixed-length data-type required");
}
break;
case STRINGS_AND_FIXED_LENGTH:
if (dt.getLength() < 0 && !(dt instanceof AbstractStringDataType)) {
throw new InvalidDataTypeException("fixed-length or string data-type required");
}
break;
case ALL:
// do nothing
break;
default:
throw new InvalidDataTypeException(
"unknown data type allowance specified: " + allowedTypes);
} }
} }
@ -221,7 +239,7 @@ public class DataTypeParser {
catch (IllegalArgumentException e) { catch (IllegalArgumentException e) {
throw new InvalidDataTypeException(e.getMessage()); throw new InvalidDataTypeException(e.getMessage());
} }
checkAllowableType(dt, allowedTypes); ensureIsAllowableType(dt, allowedTypes);
return dt; return dt;
} }