Test fixes

This commit is contained in:
dragonmacher 2023-04-24 09:10:19 -04:00
parent 81fb75498d
commit 4c83a38dc8
2 changed files with 12 additions and 18 deletions

View file

@ -40,7 +40,6 @@ import ghidra.program.model.mem.MemoryAccessException;
import ghidra.program.util.BytesFieldLocation; import ghidra.program.util.BytesFieldLocation;
import ghidra.program.util.ProgramLocation; import ghidra.program.util.ProgramLocation;
import ghidra.util.HelpLocation; import ghidra.util.HelpLocation;
import ghidra.util.Msg;
/** /**
* Generates Bytes Fields. * Generates Bytes Fields.
@ -212,8 +211,8 @@ public class BytesFieldFactory extends FieldFactory {
boolean addDelimiter = extraLength != 0; boolean addDelimiter = extraLength != 0;
buildAttributedByteValues(elements, 0, bytes, length, 0, ListingColors.BYTES, addDelimiter); buildAttributedByteValues(elements, 0, bytes, length, 0, ListingColors.BYTES, addDelimiter);
if (addDelimiter) { if (addDelimiter) {
buildAttributedByteValues(elements, groupLength, alignmentBytes, buildAttributedByteValues(elements, groupLength, alignmentBytes, alignmentBytes.length,
alignmentBytes.length, residual, ListingColors.BYTES_ALIGNMENT, false); residual, ListingColors.BYTES_ALIGNMENT, false);
} }
return ListingTextField.createPackedTextField(this, proxy, elements, startX + varWidth, return ListingTextField.createPackedTextField(this, proxy, elements, startX + varWidth,
@ -321,9 +320,6 @@ public class BytesFieldFactory extends FieldFactory {
@Override @Override
public ProgramLocation getProgramLocation(int row, int col, ListingField bf) { public ProgramLocation getProgramLocation(int row, int col, ListingField bf) {
Msg.debug(this, "Bytes - getProgLoc() - row / col: " + row + " / " + col);
Object obj = bf.getProxy().getObject(); Object obj = bf.getProxy().getObject();
if (!(obj instanceof CodeUnit) || row < 0 || col < 0) { if (!(obj instanceof CodeUnit) || row < 0 || col < 0) {
return null; return null;
@ -363,9 +359,9 @@ public class BytesFieldFactory extends FieldFactory {
} }
/** /**
* Computes how many bytes the the given column position represents. Normally this is just the * Computes how many bytes the the given column position represents. Normally this is just the
* column position / 2 (since each byte consists of two chars). There is a special case when * column position / 2 (since each byte consists of two chars). There is a special case when
* the col position is just past the last char of the token. In this case, we want to return * the col position is just past the last char of the token. In this case, we want to return
* the number of bytes in a token - 1; * the number of bytes in a token - 1;
*/ */
private int getByteIndexInToken(int col) { private int getByteIndexInToken(int col) {
@ -377,9 +373,9 @@ public class BytesFieldFactory extends FieldFactory {
/** /**
* Computes the character offset for a BytesFieldLocation based on the character column the * Computes the character offset for a BytesFieldLocation based on the character column the
* cursor is at in the token. BytesFieldLocation character offsets are always as if the group * cursor is at in the token. BytesFieldLocation character offsets are always as if the group
* size is 1. So for all positions except the last byte, it is just the column modulo 2. For * size is 1. So for all positions except the last byte, it is just the column modulo 2. For
* the last byte, we have to account for any columns past the last char. In this case, we have * the last byte, we have to account for any columns past the last char. In this case, we have
* to subtract off 2 for every byte before the last byte. * to subtract off 2 for every byte before the last byte.
*/ */
private int computeCharOffset(int col) { private int computeCharOffset(int col) {
@ -443,8 +439,7 @@ public class BytesFieldFactory extends FieldFactory {
} }
@Override @Override
public FieldFactory newInstance(FieldFormatModel formatModel, public FieldFactory newInstance(FieldFormatModel formatModel, ListingHighlightProvider provider,
ListingHighlightProvider provider,
ToolOptions displayOptions, ToolOptions fieldOptions) { ToolOptions displayOptions, ToolOptions fieldOptions) {
return new BytesFieldFactory(formatModel, provider, displayOptions, fieldOptions); return new BytesFieldFactory(formatModel, provider, displayOptions, fieldOptions);
} }

View file

@ -37,8 +37,8 @@ public class ErrorListingField extends ListingTextField {
public ErrorListingField(FieldFactory ff, ProxyObj<?> proxy, int varWidth, Throwable t) { public ErrorListingField(FieldFactory ff, ProxyObj<?> proxy, int varWidth, Throwable t) {
super(ff, proxy, null, createHighlightFactory()); super(ff, proxy, null, createHighlightFactory());
this.field = createField(ff, proxy, varWidth);
this.t = t; this.t = t;
this.field = createField(ff, proxy, varWidth);
} }
private static ListingFieldHighlightFactoryAdapter createHighlightFactory() { private static ListingFieldHighlightFactoryAdapter createHighlightFactory() {
@ -46,9 +46,8 @@ public class ErrorListingField extends ListingTextField {
} }
private ClippingTextField createField(FieldFactory ff, ProxyObj<?> proxy, int varWidth) { private ClippingTextField createField(FieldFactory ff, ProxyObj<?> proxy, int varWidth) {
ClippingTextField textField = ClippingTextField textField = new ClippingTextField(ff.getStartX() + varWidth,
new ClippingTextField(ff.getStartX() + varWidth, ff.getWidth(), ff.getWidth(), createElement(ff, t), hlFactory);
createElement(ff, t), hlFactory);
return textField; return textField;
} }