Test fixes

This commit is contained in:
dragonmacher 2024-11-12 14:10:11 -05:00
parent 7e0a96e477
commit 4df6f7e7c7
2 changed files with 53 additions and 38 deletions

View File

@ -39,25 +39,25 @@ import ghidra.util.exception.AssertException;
*/ */
public class DataTypeDropDownSelectionDataModel implements DropDownTextFieldDataModel<DataType> { public class DataTypeDropDownSelectionDataModel implements DropDownTextFieldDataModel<DataType> {
private final DataTypeManager dtm; // preferred data type manager private final DataTypeManager preferredDtm; // preferred data type manager; may be null
private final DataTypeManagerService dataTypeService; private final DataTypeManagerService dataTypeService;
public DataTypeDropDownSelectionDataModel(ServiceProvider serviceProvider) { public DataTypeDropDownSelectionDataModel(ServiceProvider serviceProvider) {
this.dtm = null; this.preferredDtm = null;
this.dataTypeService = getDataTypeService(serviceProvider); this.dataTypeService = getDataTypeService(serviceProvider);
} }
/** /**
* Creates a new instance. * Creates a new instance.
* *
* @param dtm the preferred {@link DataTypeManager}. Data types that are found in multiple * @param preferredDtm the preferred {@link DataTypeManager}. Data types that are found in
* data type managers will be pruned to just the ones already in the preferred data type * multiple data type managers will be pruned to just the ones already in the preferred data
* manager. * type manager.
* @param dataTypeService {@link DataTypeManagerService} * @param dataTypeService {@link DataTypeManagerService}
*/ */
public DataTypeDropDownSelectionDataModel(DataTypeManager dtm, public DataTypeDropDownSelectionDataModel(DataTypeManager preferredDtm,
DataTypeManagerService dataTypeService) { DataTypeManagerService dataTypeService) {
this.dtm = dtm; this.preferredDtm = preferredDtm;
this.dataTypeService = dataTypeService; this.dataTypeService = dataTypeService;
} }
@ -98,54 +98,64 @@ public class DataTypeDropDownSelectionDataModel implements DropDownTextFieldData
/** /**
* Remove any unwanted data type items, like arrays. * Remove any unwanted data type items, like arrays.
*/ */
private List<DataType> filterDataTypeList(List<DataType> dataTypeList) { private List<DataType> filterDataTypeList(List<DataType> dtList) {
// build lookups for data types that are in the preferred dtm, but may have come from // Build lookups for data types that are in the preferred dtm, but may have come from
// another DTM. In the second step, duplicate data types will be omitted from the // another dtm. In the second step, duplicate data types will be omitted from the
// final results, in favor of the data type that is already in the preferred dtm. // final results, in favor of the data type that is already in the preferred dtm.
Set<UniversalID> preferredUIDs = new HashSet<>(); Set<UniversalID> preferredUids = new HashSet<>();
Set<Class<?>> preferredBuiltins = new HashSet<>(); Set<Class<?>> preferredBuiltins = new HashSet<>();
for (DataType dt : dataTypeList) { for (DataType dt : dtList) {
DataType baseDT = DataTypeUtilities.getBaseDataType(dt); DataType baseDt = DataTypeUtilities.getBaseDataType(dt);
if (isFromPreferredDTM(baseDT)) { if (!isFromPreferredDtm(baseDt)) {
if (baseDT instanceof BuiltInDataType) { continue;
preferredBuiltins.add(baseDT.getClass()); }
}
else if (baseDT.getUniversalID() != null) { if (baseDt instanceof BuiltInDataType) {
preferredUIDs.add(baseDT.getUniversalID()); preferredBuiltins.add(baseDt.getClass());
} }
else if (baseDt.getUniversalID() != null) {
preferredUids.add(baseDt.getUniversalID());
} }
} }
List<DataType> matchingList = new ArrayList<>(dataTypeList.size()); List<DataType> matchingList = new ArrayList<>(dtList.size());
for (DataType dataType : dataTypeList) { for (DataType dt : dtList) {
if (dataType instanceof Array) { if (dt instanceof Array) {
continue; continue;
} }
DataType baseDT = DataTypeUtilities.getBaseDataType(dataType); DataType baseDt = DataTypeUtilities.getBaseDataType(dt);
if (dtm != null && !isFromPreferredDTM(baseDT)) { if (baseDt == null) {
if (baseDT instanceof BuiltInDataType && continue;
preferredBuiltins.contains(baseDT.getClass())) { }
if (preferredDtm != null && !isFromPreferredDtm(baseDt)) {
if (baseDt instanceof BuiltInDataType &&
preferredBuiltins.contains(baseDt.getClass())) {
continue; continue;
} }
if (baseDT.getUniversalID() != null && if (baseDt.getUniversalID() != null &&
preferredUIDs.contains(baseDT.getUniversalID())) { preferredUids.contains(baseDt.getUniversalID())) {
continue; continue;
} }
} }
matchingList.add(dataType); matchingList.add(dt);
} }
return matchingList; return matchingList;
} }
private boolean isFromPreferredDTM(DataType dt) { private boolean isFromPreferredDtm(DataType dt) {
if (dtm != null) { if (dt == null) {
DataTypeManager altDTM = dtm instanceof CompositeViewerDataTypeManager compDTM return false;
? compDTM.getOriginalDataTypeManager() }
if (preferredDtm != null) {
DataTypeManager altDtm = preferredDtm instanceof CompositeViewerDataTypeManager compDtm
? compDtm.getOriginalDataTypeManager()
: null; : null;
DataTypeManager dtDTM = dt.getDataTypeManager(); DataTypeManager dtDtm = dt.getDataTypeManager();
return dtDTM == dtm || dtDTM == altDTM; return dtDtm == preferredDtm || dtDtm == altDtm;
} }
return false; return false;
} }

View File

@ -4,9 +4,9 @@
* 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.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -181,6 +181,11 @@ public class StubThemeManager extends ThemeManager {
return false; return false;
} }
@Override
public boolean isUsingAquaUI() {
return false;
}
@Override @Override
public boolean isUsingNimbusUI() { public boolean isUsingNimbusUI() {
return false; return false;