GP-5742 Cleanup preferred CommentType enum use. Changed SARIF data component comment JSON serialization from int to String.

This commit is contained in:
ghidra1 2025-06-06 17:58:07 -04:00
parent 4a65e9af3b
commit 8c441250f5
211 changed files with 4627 additions and 4860 deletions

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -38,12 +38,12 @@ import ghidra.util.task.TaskMonitor;
public abstract class CommentMarkupType extends VTMarkupType {
protected abstract int getCodeUnitCommentType();
public CommentMarkupType(String name) {
super(name);
}
protected abstract CommentType getCodeUnitCommentType();
protected abstract ProgramLocation getLocation(VTAssociation association, Address address,
boolean isSource);
@ -105,7 +105,7 @@ public abstract class CommentMarkupType extends VTMarkupType {
}
private String getSourceComment(VTAssociation association, Address sourceAddress) {
int commentType = getCodeUnitCommentType();
CommentType commentType = getCodeUnitCommentType();
Listing sourceListing = getSourceListing(association);
return sourceListing.getComment(commentType, sourceAddress);
}
@ -131,7 +131,7 @@ public abstract class CommentMarkupType extends VTMarkupType {
throw new VersionTrackingApplyException("No value applied");
}
String originalDestinationComment = originalDestinationValue.getString();
int commentType = getCodeUnitCommentType();
CommentType commentType = getCodeUnitCommentType();
Listing destinationListing = getDestinationListing(markupItem.getAssociation());
String comment = destinationListing.getComment(commentType, destinationAddress);
if (!StringUtils.equals(originalDestinationComment, comment)) {
@ -179,7 +179,7 @@ public abstract class CommentMarkupType extends VTMarkupType {
comment = StringUtilities.mergeStrings(destinationComment, sourceComment);
}
int commentType = getCodeUnitCommentType();
CommentType commentType = getCodeUnitCommentType();
Listing destinationListing = getDestinationListing(markupItem.getAssociation());
destinationListing.setComment(destinationAddress, commentType, comment);
return true;
@ -187,7 +187,7 @@ public abstract class CommentMarkupType extends VTMarkupType {
private String getDestinationComment(VTAssociation association, Address destinationAddress) {
if (destinationAddress != null && destinationAddress != Address.NO_ADDRESS) {
int commentType = getCodeUnitCommentType();
CommentType commentType = getCodeUnitCommentType();
Listing destinationListing = getDestinationListing(association);
return destinationListing.getComment(commentType, destinationAddress);
}

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -22,8 +22,7 @@ import ghidra.feature.vt.gui.util.VTMatchApplyChoices.CommentChoices;
import ghidra.framework.options.Options;
import ghidra.framework.options.ToolOptions;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.listing.Program;
import ghidra.program.model.listing.*;
import ghidra.program.util.EolCommentFieldLocation;
import ghidra.program.util.ProgramLocation;
@ -44,8 +43,8 @@ public class EolCommentMarkupType extends CommentMarkupType {
}
@Override
protected int getCodeUnitCommentType() {
return CodeUnit.EOL_COMMENT;
protected CommentType getCodeUnitCommentType() {
return CommentType.EOL;
}
@Override
@ -92,8 +91,8 @@ public class EolCommentMarkupType extends CommentMarkupType {
CommentChoices.APPEND_TO_EXISTING);
break;
case ADD_AS_PRIMARY:
throw new IllegalArgumentException(getDisplayName() +
" markup items cannot perform an Add As Primary action.");
throw new IllegalArgumentException(
getDisplayName() + " markup items cannot perform an Add As Primary action.");
case REPLACE_DEFAULT_ONLY:
throw new IllegalArgumentException(getDisplayName() +
" markup items cannot perform a Replace Default Only action.");

View file

@ -24,7 +24,7 @@ import ghidra.feature.vt.gui.util.VTOptionDefines;
import ghidra.framework.options.Options;
import ghidra.framework.options.ToolOptions;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.listing.CommentType;
import ghidra.program.model.listing.Program;
import ghidra.program.util.PlateFieldLocation;
import ghidra.program.util.ProgramLocation;
@ -46,8 +46,8 @@ public class PlateCommentMarkupType extends CommentMarkupType {
}
@Override
protected int getCodeUnitCommentType() {
return CodeUnit.PLATE_COMMENT;
protected CommentType getCodeUnitCommentType() {
return CommentType.PLATE;
}
@Override

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -17,12 +17,13 @@ package ghidra.feature.vt.api.markuptype;
import ghidra.feature.vt.api.main.VTAssociation;
import ghidra.feature.vt.api.main.VTMarkupItemApplyActionType;
import ghidra.feature.vt.gui.util.*;
import ghidra.feature.vt.gui.util.VTMatchApplyChoices;
import ghidra.feature.vt.gui.util.VTMatchApplyChoices.CommentChoices;
import ghidra.feature.vt.gui.util.VTOptionDefines;
import ghidra.framework.options.Options;
import ghidra.framework.options.ToolOptions;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.listing.CommentType;
import ghidra.program.model.listing.Program;
import ghidra.program.util.PostCommentFieldLocation;
import ghidra.program.util.ProgramLocation;
@ -44,8 +45,8 @@ public class PostCommentMarkupType extends CommentMarkupType {
}
@Override
protected int getCodeUnitCommentType() {
return CodeUnit.POST_COMMENT;
protected CommentType getCodeUnitCommentType() {
return CommentType.POST;
}
@Override
@ -91,8 +92,8 @@ public class PostCommentMarkupType extends CommentMarkupType {
options.setEnum(VTOptionDefines.POST_COMMENT, CommentChoices.APPEND_TO_EXISTING);
break;
case ADD_AS_PRIMARY:
throw new IllegalArgumentException(getDisplayName() +
" markup items cannot perform an Add As Primary action.");
throw new IllegalArgumentException(
getDisplayName() + " markup items cannot perform an Add As Primary action.");
case REPLACE_DEFAULT_ONLY:
throw new IllegalArgumentException(getDisplayName() +
" markup items cannot perform a Replace Default Only action.");

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -17,12 +17,13 @@ package ghidra.feature.vt.api.markuptype;
import ghidra.feature.vt.api.main.VTAssociation;
import ghidra.feature.vt.api.main.VTMarkupItemApplyActionType;
import ghidra.feature.vt.gui.util.*;
import ghidra.feature.vt.gui.util.VTMatchApplyChoices;
import ghidra.feature.vt.gui.util.VTMatchApplyChoices.CommentChoices;
import ghidra.feature.vt.gui.util.VTOptionDefines;
import ghidra.framework.options.Options;
import ghidra.framework.options.ToolOptions;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.listing.CommentType;
import ghidra.program.model.listing.Program;
import ghidra.program.util.CommentFieldLocation;
import ghidra.program.util.ProgramLocation;
@ -44,8 +45,8 @@ public class PreCommentMarkupType extends CommentMarkupType {
}
@Override
protected int getCodeUnitCommentType() {
return CodeUnit.PRE_COMMENT;
protected CommentType getCodeUnitCommentType() {
return CommentType.PRE;
}
@Override
@ -57,7 +58,7 @@ public class PreCommentMarkupType extends CommentMarkupType {
Program program =
isSource ? getSourceProgram(association) : getDestinationProgram(association);
return new CommentFieldLocation(program, address, null, null, CodeUnit.PRE_COMMENT, 0, 0);
return new CommentFieldLocation(program, address, null, null, CommentType.PRE, 0, 0);
}
@Override
@ -91,8 +92,8 @@ public class PreCommentMarkupType extends CommentMarkupType {
options.setEnum(VTOptionDefines.PRE_COMMENT, CommentChoices.APPEND_TO_EXISTING);
break;
case ADD_AS_PRIMARY:
throw new IllegalArgumentException(getDisplayName() +
" markup items cannot perform an Add As Primary action.");
throw new IllegalArgumentException(
getDisplayName() + " markup items cannot perform an Add As Primary action.");
case REPLACE_DEFAULT_ONLY:
throw new IllegalArgumentException(getDisplayName() +
" markup items cannot perform a Replace Default Only action.");

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -17,12 +17,13 @@ package ghidra.feature.vt.api.markuptype;
import ghidra.feature.vt.api.main.VTAssociation;
import ghidra.feature.vt.api.main.VTMarkupItemApplyActionType;
import ghidra.feature.vt.gui.util.*;
import ghidra.feature.vt.gui.util.VTMatchApplyChoices;
import ghidra.feature.vt.gui.util.VTMatchApplyChoices.CommentChoices;
import ghidra.feature.vt.gui.util.VTOptionDefines;
import ghidra.framework.options.Options;
import ghidra.framework.options.ToolOptions;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.listing.CommentType;
import ghidra.program.model.listing.Program;
import ghidra.program.util.FunctionRepeatableCommentFieldLocation;
import ghidra.program.util.ProgramLocation;
@ -44,8 +45,8 @@ public class RepeatableCommentMarkupType extends CommentMarkupType {
}
@Override
protected int getCodeUnitCommentType() {
return CodeUnit.REPEATABLE_COMMENT;
protected CommentType getCodeUnitCommentType() {
return CommentType.REPEATABLE;
}
@Override
@ -92,8 +93,8 @@ public class RepeatableCommentMarkupType extends CommentMarkupType {
CommentChoices.APPEND_TO_EXISTING);
break;
case ADD_AS_PRIMARY:
throw new IllegalArgumentException(getDisplayName() +
" markup items cannot perform an Add As Primary action.");
throw new IllegalArgumentException(
getDisplayName() + " markup items cannot perform an Add As Primary action.");
case REPLACE_DEFAULT_ONLY:
throw new IllegalArgumentException(getDisplayName() +
" markup items cannot perform a Replace Default Only action.");

View file

@ -15,32 +15,16 @@
*/
package ghidra.feature.vt.api;
import static ghidra.feature.vt.db.VTTestUtils.addr;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static ghidra.feature.vt.db.VTTestUtils.*;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.*;
import ghidra.app.cmd.disassemble.DisassembleCommand;
import ghidra.feature.vt.api.db.VTSessionDB;
import ghidra.feature.vt.api.main.VTAssociation;
import ghidra.feature.vt.api.main.VTAssociationStatus;
import ghidra.feature.vt.api.main.VTAssociationType;
import ghidra.feature.vt.api.main.VTMatch;
import ghidra.feature.vt.api.main.VTMatchInfo;
import ghidra.feature.vt.api.main.VTMatchSet;
import ghidra.feature.vt.api.main.VTProgramCorrelator;
import ghidra.feature.vt.api.main.VTScore;
import ghidra.feature.vt.api.main.VTSession;
import ghidra.feature.vt.api.main.*;
import ghidra.feature.vt.api.util.VTAssociationStatusException;
import ghidra.feature.vt.api.util.VTOptions;
import ghidra.feature.vt.db.VTTestUtils;
@ -55,13 +39,7 @@ import ghidra.program.database.ProgramDB;
import ghidra.program.database.function.OverlappingFunctionException;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSet;
import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.listing.CodeUnitIterator;
import ghidra.program.model.listing.Data;
import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.FunctionManager;
import ghidra.program.model.listing.Listing;
import ghidra.program.model.listing.Program;
import ghidra.program.model.listing.*;
import ghidra.program.model.mem.MemoryAccessException;
import ghidra.program.model.symbol.SourceType;
import ghidra.program.model.symbol.Symbol;
@ -246,7 +224,7 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
// run auto VT which would normally accept the match we blocked
ToolOptions vtOptions = getVTToolOptions(tool);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 1.0);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 10.0);
@ -298,10 +276,10 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
// run auto VT
ToolOptions vtOptions = getVTToolOptions(tool);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 1.0);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 10.0);
runAutoVTCommand(vtOptions);
// Now test that the correct matches were created based on the duplicate functions we created
@ -348,10 +326,10 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
// run auto VT
ToolOptions vtOptions = getVTToolOptions(tool);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 1.0);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 10.0);
runAutoVTCommand(vtOptions);
// Now test that the correct matches were created based on the duplicate functions we created
@ -388,10 +366,10 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
// run auto VT
ToolOptions vtOptions = getVTToolOptions(tool);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 1.0);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 10.0);
runAutoVTCommand(vtOptions);
// Test to make sure that they weren't matched by something else first so we can
@ -461,10 +439,10 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
// run auto VT
ToolOptions vtOptions = getVTToolOptions(tool);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 1.0);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 10.0);
runAutoVTCommand(vtOptions);
// Test to make sure that they weren't matched by something else first so we can
@ -619,10 +597,10 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
// run auto VT
ToolOptions vtOptions = getVTToolOptions(tool);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 1.0);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 10.0);
runAutoVTCommand(vtOptions);
// Test to make sure that they weren't matched by something else first so we can
@ -671,16 +649,16 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
while (sourceCodeUnits.hasNext()) {
CodeUnit cu = sourceCodeUnits.next();
Address addr = cu.getAddress();
sourceListing.setComment(addr, CodeUnit.EOL_COMMENT, "Test Comment " + numComments++);
sourceListing.setComment(addr, CommentType.EOL, "Test Comment " + numComments++);
}
sourceProgram.endTransaction(startTransaction, true);
// run Auto VT
ToolOptions vtOptions = getVTToolOptions(tool);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 1.0);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 10.0);
runAutoVTCommand(vtOptions);
// Check that the match we are interested in got accepted
@ -698,7 +676,7 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
CodeUnit cu = destCodeUnits.next();
Address addr = cu.getAddress();
assertEquals("Test Comment " + numComments++,
destListing.getComment(CodeUnit.EOL_COMMENT, addr));
destListing.getComment(CommentType.EOL, addr));
}
}
@ -731,16 +709,16 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
while (sourceCodeUnits.hasNext()) {
CodeUnit cu = sourceCodeUnits.next();
Address addr = cu.getAddress();
sourceListing.setComment(addr, CodeUnit.EOL_COMMENT, "Test Comment " + numComments++);
sourceListing.setComment(addr, CommentType.EOL, "Test Comment " + numComments++);
}
sourceProgram.endTransaction(startTransaction, true);
// run Auto VT
ToolOptions vtOptions = getVTToolOptions(tool);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 1.0);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 10.0);
runAutoVTCommand(vtOptions);
// Check that the match we are interested in got accepted
@ -758,7 +736,7 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
CodeUnit cu = destCodeUnits.next();
Address addr = cu.getAddress();
assertEquals("Test Comment " + numComments++,
destListing.getComment(CodeUnit.EOL_COMMENT, addr));
destListing.getComment(CommentType.EOL, addr));
}
}
@ -794,7 +772,7 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
while (codeUnits.hasNext()) {
CodeUnit cu = codeUnits.next();
Address addr = cu.getAddress();
sourceListing.setComment(addr, CodeUnit.EOL_COMMENT, "Test Comment " + numComments++);
sourceListing.setComment(addr, CommentType.EOL, "Test Comment " + numComments++);
}
sourceProgram.endTransaction(startTransaction, true);
@ -805,7 +783,7 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
// Now run the AutoVT command with lower confidence thresholds to allow the match we want to
// test in as a match
ToolOptions vtOptions = getVTToolOptions(tool);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 0.5);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 1.0);
@ -833,12 +811,12 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
CodeUnit cu = codeUnitsDestTop.next();
Address addr = cu.getAddress();
assertEquals("Test Comment " + numComments++,
destListing.getComment(CodeUnit.EOL_COMMENT, addr));
destListing.getComment(CommentType.EOL, addr));
}
// Now check the one that should not have a comment at all
assertEquals(null,
destListing.getComment(CodeUnit.EOL_COMMENT, addr("0x4119af", destinationProgram)));
destListing.getComment(CommentType.EOL, addr("0x4119af", destinationProgram)));
// Now get the bottom section
AddressSet bottomAddressSet = destinationProgram.getAddressFactory()
@ -852,7 +830,7 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
while (codeUnitsDestBottom.hasNext()) {
CodeUnit cu = codeUnitsDestBottom.next();
Address addr = cu.getAddress();
assertEquals(destListing.getComment(CodeUnit.EOL_COMMENT, addr),
assertEquals(destListing.getComment(CommentType.EOL, addr),
"Test Comment " + numComments++);
}
}
@ -872,14 +850,13 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
// Score .999999 and confidence 10.0 (log10 confidence 2.0) and up
ToolOptions vtOptions = getVTToolOptions(tool);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 0.999999999);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 10.0);
vtOptions.setBoolean(VTOptionDefines.CREATE_IMPLIED_MATCHES_OPTION, true);
vtOptions.setBoolean(VTOptionDefines.APPLY_IMPLIED_MATCHES_OPTION, true);
vtOptions.setInt(VTOptionDefines.MIN_VOTES_OPTION, 3);
vtOptions.setInt(VTOptionDefines.MAX_CONFLICTS_OPTION, 0);
runAutoVTCommand(vtOptions);
@ -900,7 +877,6 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
VTAssociation association = match.getAssociation();
int numConflicts = association.getRelatedAssociations().size() - 1;
// if not min vote count or has conflicts - make sure not accepted match
if (association.getVoteCount() < 3 || numConflicts > 0) {
assertEquals(VTAssociationStatus.AVAILABLE, matchStatus);
@ -926,11 +902,11 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
// Score .999999 and confidence 10.0 (log10 confidence 2.0) and up
ToolOptions vtOptions = getVTToolOptions(tool);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 0.999999999);
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 10.0);
vtOptions.setBoolean(VTOptionDefines.CREATE_IMPLIED_MATCHES_OPTION, false);
runAutoVTCommand(vtOptions);
assertTrue(session.getImpliedMatchSet().getMatchCount() == 0);
@ -1171,8 +1147,7 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
private void runAutoVTCommand(ToolOptions options) {
AutoVersionTrackingTask task =
new AutoVersionTrackingTask(session, options);
AutoVersionTrackingTask task = new AutoVersionTrackingTask(session, options);
TaskLauncher.launch(task);
waitForSession();
}
@ -1184,9 +1159,7 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
private VTMatchSet getVTMatchSet(VTSession vtSession, String correlatorName) {
List<VTMatchSet> matchSets = vtSession.getMatchSets();
Iterator<VTMatchSet> iterator = matchSets.iterator();
while (iterator.hasNext()) {
VTMatchSet matches = iterator.next();
for (VTMatchSet matches : matchSets) {
if (matches.getProgramCorrelatorInfo().getName().equals(correlatorName)) {
return matches;
}
@ -1200,9 +1173,7 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
VTMatchSet matches = getVTMatchSet(vtSession, correlatorName);
Msg.info(this, score + " " + confidence);
Iterator<VTMatch> it = matches.getMatches().iterator();
while (it.hasNext()) {
VTMatch match = it.next();
for (VTMatch match : matches.getMatches()) {
VTAssociationStatus status = match.getAssociation().getStatus();
if (status.equals(VTAssociationStatus.ACCEPTED)) {
Msg.info(this,
@ -1223,9 +1194,7 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
VTMatchSet matches = getVTMatchSet(vtSession, correlatorName);
int count = 0;
Iterator<VTMatch> it = matches.getMatches().iterator();
while (it.hasNext()) {
VTMatch match = it.next();
for (VTMatch match : matches.getMatches()) {
VTAssociationStatus status = match.getAssociation().getStatus();
if (status.equals(VTAssociationStatus.ACCEPTED)) {
count++;
@ -1239,9 +1208,7 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
VTMatchSet matches = getVTMatchSet(vtSession, correlatorName);
Iterator<VTMatch> it = matches.getMatches().iterator();
while (it.hasNext()) {
VTMatch match = it.next();
for (VTMatch match : matches.getMatches()) {
if (match.getSourceAddress().equals(sourceAddress) &&
match.getDestinationAddress().equals(destinationAddress)) {
return match.getAssociation().getStatus();
@ -1253,9 +1220,7 @@ public class VTAutoVersionTrackingTest extends AbstractGhidraHeadedIntegrationTe
private VTMatch getMatch(VTMatchSet matches, Address sourceAddress,
Address destinationAddress) {
Iterator<VTMatch> it = matches.getMatches().iterator();
while (it.hasNext()) {
VTMatch match = it.next();
for (VTMatch match : matches.getMatches()) {
if (match.getSourceAddress().equals(sourceAddress) &&
match.getDestinationAddress().equals(destinationAddress)) {
return match;

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -177,39 +177,39 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testApplyMatchEOLComments_Ignore() throws Exception {
doTestApplyCommentMatch_Ignore(CodeUnit.EOL_COMMENT, VTOptionDefines.END_OF_LINE_COMMENT,
doTestApplyCommentMatch_Ignore(CommentType.EOL, VTOptionDefines.END_OF_LINE_COMMENT,
CommentChoices.EXCLUDE);
}
@Test
public void testApplyMatchPreComments_Ignore() throws Exception {
doTestApplyCommentMatch_Ignore(CodeUnit.PRE_COMMENT, VTOptionDefines.PRE_COMMENT,
doTestApplyCommentMatch_Ignore(CommentType.PRE, VTOptionDefines.PRE_COMMENT,
CommentChoices.EXCLUDE);
}
@Test
public void testApplyMatchPostComments_Ignore() throws Exception {
doTestApplyCommentMatch_Ignore(CodeUnit.POST_COMMENT, VTOptionDefines.POST_COMMENT,
doTestApplyCommentMatch_Ignore(CommentType.POST, VTOptionDefines.POST_COMMENT,
CommentChoices.EXCLUDE);
}
@Test
public void testApplyMatchPlateComments_Ignore() throws Exception {
doTestApplyCommentMatch_Ignore(CodeUnit.PLATE_COMMENT, VTOptionDefines.PLATE_COMMENT,
doTestApplyCommentMatch_Ignore(CommentType.PLATE, VTOptionDefines.PLATE_COMMENT,
CommentChoices.EXCLUDE);
}
@Test
public void testApplyMatchRepeatableComments_Ignore() throws Exception {
doTestApplyCommentMatch_Ignore(CodeUnit.REPEATABLE_COMMENT,
VTOptionDefines.REPEATABLE_COMMENT, CommentChoices.EXCLUDE);
doTestApplyCommentMatch_Ignore(CommentType.REPEATABLE, VTOptionDefines.REPEATABLE_COMMENT,
CommentChoices.EXCLUDE);
}
private void doTestApplyCommentMatch_Ignore(int codeUnitCommentType,
private void doTestApplyCommentMatch_Ignore(CommentType codeUnitCommentType,
String vtCommentOptionDefine, CommentChoices commentChoice) throws Exception {
String sourceComment = "Hi mom replace";
Address sourceAddress = addr("0x01002cf5", sourceProgram);
@ -249,39 +249,39 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testApplyMatchEOLComments_Append() throws Exception {
doTestApplyCommentMatch_Append(CodeUnit.EOL_COMMENT, VTOptionDefines.END_OF_LINE_COMMENT,
doTestApplyCommentMatch_Append(CommentType.EOL, VTOptionDefines.END_OF_LINE_COMMENT,
CommentChoices.APPEND_TO_EXISTING);
}
@Test
public void testApplyMatchPreComments_Append() throws Exception {
doTestApplyCommentMatch_Append(CodeUnit.PRE_COMMENT, VTOptionDefines.PRE_COMMENT,
doTestApplyCommentMatch_Append(CommentType.PRE, VTOptionDefines.PRE_COMMENT,
CommentChoices.APPEND_TO_EXISTING);
}
@Test
public void testApplyMatchPostComments_Append() throws Exception {
doTestApplyCommentMatch_Append(CodeUnit.POST_COMMENT, VTOptionDefines.POST_COMMENT,
doTestApplyCommentMatch_Append(CommentType.POST, VTOptionDefines.POST_COMMENT,
CommentChoices.APPEND_TO_EXISTING);
}
@Test
public void testApplyMatchPlateComments_Append() throws Exception {
doTestApplyCommentMatch_Append(CodeUnit.PLATE_COMMENT, VTOptionDefines.PLATE_COMMENT,
doTestApplyCommentMatch_Append(CommentType.PLATE, VTOptionDefines.PLATE_COMMENT,
CommentChoices.APPEND_TO_EXISTING);
}
@Test
public void testApplyMatchRepeatableComments_Append() throws Exception {
doTestApplyCommentMatch_Append(CodeUnit.REPEATABLE_COMMENT,
VTOptionDefines.REPEATABLE_COMMENT, CommentChoices.APPEND_TO_EXISTING);
doTestApplyCommentMatch_Append(CommentType.REPEATABLE, VTOptionDefines.REPEATABLE_COMMENT,
CommentChoices.APPEND_TO_EXISTING);
}
private void doTestApplyCommentMatch_Append(int codeUnitCommentType,
private void doTestApplyCommentMatch_Append(CommentType codeUnitCommentType,
String vtCommentOptionDefine, CommentChoices commentChoice) throws Exception {
String sourceComment = "Hi mom replace";
String destinationComment = "Hi dad replace";
@ -326,39 +326,39 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testApplyMatchEOLComments_Overwrite() throws Exception {
doTestApplyCommentMatch_Overwrite(CodeUnit.EOL_COMMENT, VTOptionDefines.END_OF_LINE_COMMENT,
doTestApplyCommentMatch_Overwrite(CommentType.EOL, VTOptionDefines.END_OF_LINE_COMMENT,
CommentChoices.OVERWRITE_EXISTING);
}
@Test
public void testApplyMatchPreComments_Overwrite() throws Exception {
doTestApplyCommentMatch_Overwrite(CodeUnit.PRE_COMMENT, VTOptionDefines.PRE_COMMENT,
doTestApplyCommentMatch_Overwrite(CommentType.PRE, VTOptionDefines.PRE_COMMENT,
CommentChoices.OVERWRITE_EXISTING);
}
@Test
public void testApplyMatchPostComments_Overwrite() throws Exception {
doTestApplyCommentMatch_Overwrite(CodeUnit.POST_COMMENT, VTOptionDefines.POST_COMMENT,
doTestApplyCommentMatch_Overwrite(CommentType.POST, VTOptionDefines.POST_COMMENT,
CommentChoices.OVERWRITE_EXISTING);
}
@Test
public void testApplyMatchPlateComments_Overwrite() throws Exception {
doTestApplyCommentMatch_Overwrite(CodeUnit.PLATE_COMMENT, VTOptionDefines.PLATE_COMMENT,
doTestApplyCommentMatch_Overwrite(CommentType.PLATE, VTOptionDefines.PLATE_COMMENT,
CommentChoices.OVERWRITE_EXISTING);
}
@Test
public void testApplyMatchRepeatableComments_Overwrite() throws Exception {
doTestApplyCommentMatch_Overwrite(CodeUnit.REPEATABLE_COMMENT,
doTestApplyCommentMatch_Overwrite(CommentType.REPEATABLE,
VTOptionDefines.REPEATABLE_COMMENT, CommentChoices.OVERWRITE_EXISTING);
}
private void doTestApplyCommentMatch_Overwrite(int codeUnitCommentType,
private void doTestApplyCommentMatch_Overwrite(CommentType codeUnitCommentType,
String vtCommentOptionDefine, CommentChoices commentChoice) throws Exception {
String sourceComment = "Hi mom replace";
String destinationComment = "Hi dad replace";
@ -1062,8 +1062,8 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
String sourceComment = "Hi mom replace";
String destinationComment = "Hi dad replace";
Address commentAddress = addr("0x01002d06", sourceProgram);
setComment(sourceProgram, commentAddress, CodeUnit.EOL_COMMENT, sourceComment);
setComment(destinationProgram, commentAddress, CodeUnit.EOL_COMMENT, destinationComment);
setComment(sourceProgram, commentAddress, CommentType.EOL, sourceComment);
setComment(destinationProgram, commentAddress, CommentType.EOL, destinationComment);
MatchInfo matchInfo = controller.getMatchInfo(match);
Collection<VTMarkupItem> markupItems = matchInfo.getAppliableMarkupItems(TaskMonitor.DUMMY);
@ -1087,7 +1087,7 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
String expectedComment = destinationComment + "\n" + sourceComment;
Listing destinationListing = destinationProgram.getListing();
String comment = destinationListing.getComment(CodeUnit.EOL_COMMENT, commentAddress);
String comment = destinationListing.getComment(CommentType.EOL, commentAddress);
assertEquals("Comment was not applied", expectedComment, comment);
//
@ -1108,7 +1108,7 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
expectedComment = destinationComment + "\n" + sourceComment;
destinationListing = destinationProgram.getListing();
comment = destinationListing.getComment(CodeUnit.EOL_COMMENT, commentAddress);
comment = destinationListing.getComment(CommentType.EOL, commentAddress);
assertEquals("Comment was not applied", expectedComment, comment);
//
@ -1121,7 +1121,7 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
assertTrue("New symbol does not match the source symbol",
SystemUtilities.isArrayEqual(expectedSymbols, newSymbols));
comment = destinationListing.getComment(CodeUnit.EOL_COMMENT, commentAddress);
comment = destinationListing.getComment(CommentType.EOL, commentAddress);
assertEquals("Comment was not unpplied", destinationComment, comment);
}
@ -2069,7 +2069,7 @@ public class VTMatchApplyTest extends AbstractGhidraHeadedIntegrationTest {
}
}
private void setComment(Program program, Address address, int codeUnitCommentType,
private void setComment(Program program, Address address, CommentType codeUnitCommentType,
String comment) {
Listing listing = program.getListing();

View file

@ -88,7 +88,7 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
// Test a function match created by the Exact Bytes Match correlator.
createSession(TEST_SOURCE_PROGRAM_NAME, TEST_DESTINATION_PROGRAM_NAME);
vtTestEnv.showTool();
addComment(CodeUnit.EOL_COMMENT, "0x0041222b", "Exact bytes comment.");
addComment(CommentType.EOL, "0x0041222b", "Exact bytes comment.");
runCorrelator(new ExactMatchBytesProgramCorrelatorFactory());
selectMatch("0x00412210", "0x004121f0");
@ -103,7 +103,7 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
// Test a function match created by the Exact Mnemonics Match correlator.
createSession(TEST_SOURCE_PROGRAM_NAME, TEST_DESTINATION_PROGRAM_NAME);
vtTestEnv.showTool();
addComment(CodeUnit.PRE_COMMENT, "0x00412988", "Exact mnemonics comment.");
addComment(CommentType.PRE, "0x00412988", "Exact mnemonics comment.");
runCorrelator(new ExactMatchMnemonicsProgramCorrelatorFactory());
selectMatch("0x00412950", "0x00412930");
@ -118,7 +118,7 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
// Test a function match created by the Exact Instructions Match correlator.
createSession(TEST_SOURCE_PROGRAM_NAME, TEST_DESTINATION_PROGRAM_NAME);
vtTestEnv.showTool();
addComment(CodeUnit.POST_COMMENT, "0x004129a2", "Exact instructions comment.");
addComment(CommentType.POST, "0x004129a2", "Exact instructions comment.");
runCorrelator(new ExactMatchInstructionsProgramCorrelatorFactory());
selectMatch("0x00412950", "0x00412930");
@ -134,8 +134,8 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
// two programs are for the same language and processor.
createSession(TEST_SOURCE_PROGRAM_NAME, TEST_DESTINATION_PROGRAM_NAME);
vtTestEnv.showTool();
addComment(CodeUnit.EOL_COMMENT, "0x004126dd", "Similar name eol comment.");
addComment(CodeUnit.PRE_COMMENT, "0x004126d7", "Similar name pre comment.");
addComment(CommentType.EOL, "0x004126dd", "Similar name eol comment.");
addComment(CommentType.PRE, "0x004126d7", "Similar name pre comment.");
runCorrelator(new SimilarSymbolNameProgramCorrelatorFactory());
selectMatch("0x00412690", "0x00412720");
@ -158,8 +158,7 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
vtTestEnv.showTool();
// add source comment
addComment(CodeUnit.PLATE_COMMENT, "0x00401003",
"Similar name plate comment not at entry.");
addComment(CommentType.PLATE, "0x00401003", "Similar name plate comment not at entry.");
// create correlation run
runCorrelator(new SimilarSymbolNameProgramCorrelatorFactory());
@ -187,7 +186,7 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
Program p2 = buildProgram3("language3");
createSession(p1, p2);
vtTestEnv.showTool();
addComment(CodeUnit.EOL_COMMENT, "0x00401003", "Similar name eol comment.");
addComment(CommentType.EOL, "0x00401003", "Similar name eol comment.");
runCorrelator(new SimilarSymbolNameProgramCorrelatorFactory());
selectMatch("0x00401000", "0x00402000");
@ -208,8 +207,8 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
Program p2 = buildProgram2("language2");
createSession(p1, p2);
vtTestEnv.showTool();
addComment(CodeUnit.PLATE_COMMENT, "0x00401000", "First plate comment.");
addComment(CodeUnit.PLATE_COMMENT, "0x00401003", "Second plate comment.");
addComment(CommentType.PLATE, "0x00401000", "First plate comment.");
addComment(CommentType.PLATE, "0x00401003", "Second plate comment.");
runCorrelator(new SimilarSymbolNameProgramCorrelatorFactory());
selectMatch("0x00401000", "0x00402000");
@ -237,8 +236,8 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
Program p2 = buildProgram3("language3");
createSession(p1, p2);
vtTestEnv.showTool();
addComment(CodeUnit.PLATE_COMMENT, "0x00401000", "First plate comment.");
addComment(CodeUnit.PLATE_COMMENT, "0x00401003", "Second plate comment.");
addComment(CommentType.PLATE, "0x00401000", "First plate comment.");
addComment(CommentType.PLATE, "0x00401003", "Second plate comment.");
runCorrelator(new SimilarSymbolNameProgramCorrelatorFactory());
selectMatch("0x00401000", "0x00402000");
@ -268,7 +267,7 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
function.setName("MyFunctionAB", SourceType.USER_DEFINED);
Listing listing = p.getListing();
CodeUnit cu = listing.getCodeUnitAt(function.getEntryPoint());
cu.setComment(CodeUnit.EOL_COMMENT, "A sample end of line comment");
cu.setComment(CommentType.EOL, "A sample end of line comment");
});
p.addConsumer(vtTestEnv);
@ -443,7 +442,7 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest
* @param sourceAddressString the source address of the markup
* @param comment the comment to be added at the source address
*/
private void addComment(int commentType, String sourceAddressString, String comment) {
private void addComment(CommentType commentType, String sourceAddressString, String comment) {
Address srcAddress = addr(sourceAddressString, sourceProgram);
int txID = sourceProgram.startTransaction("Add Comment");
boolean commit = false;

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -15,8 +15,8 @@
*/
package ghidra.feature.vt.api.markupitem;
import static ghidra.feature.vt.db.VTTestUtils.addr;
import static org.junit.Assert.assertTrue;
import static ghidra.feature.vt.db.VTTestUtils.*;
import static org.junit.Assert.*;
import java.util.List;
@ -29,7 +29,7 @@ import ghidra.feature.vt.api.main.VTMatch;
import ghidra.feature.vt.api.markuptype.EolCommentMarkupType;
import ghidra.feature.vt.api.util.VTOptions;
import ghidra.feature.vt.gui.task.ApplyMarkupItemTask;
import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.listing.CommentType;
import ghidra.util.task.TaskMonitor;
public class ApplyMultipleMarkupItemsTest extends AbstractVTMarkupItemTest {
@ -38,8 +38,8 @@ public class ApplyMultipleMarkupItemsTest extends AbstractVTMarkupItemTest {
@Before
public void setUp() throws Exception {
super.setUp();
sourceBuilder.createComment("1002248", "Comment 1", CodeUnit.EOL_COMMENT);
sourceBuilder.createComment("100224b", "Comment 2", CodeUnit.EOL_COMMENT);
sourceBuilder.createComment("1002248", "Comment 1", CommentType.EOL);
sourceBuilder.createComment("100224b", "Comment 2", CommentType.EOL);
sourceProgram = sourceBuilder.getProgram();
}

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -15,11 +15,9 @@
*/
package ghidra.feature.vt.api.markupitem;
import static ghidra.feature.vt.api.main.VTMarkupItemApplyActionType.ADD;
import static ghidra.feature.vt.api.main.VTMarkupItemApplyActionType.REPLACE;
import static ghidra.feature.vt.db.VTTestUtils.addr;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static ghidra.feature.vt.api.main.VTMarkupItemApplyActionType.*;
import static ghidra.feature.vt.db.VTTestUtils.*;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
@ -41,8 +39,8 @@ public class CommentMarkupItemTest extends AbstractVTMarkupItemTest {
super();
}
@Test
public void testFindAndApplyMarkupItem_Merge_WithNonNullDestinationValue() throws Exception {
@Test
public void testFindAndApplyMarkupItem_Merge_WithNonNullDestinationValue() throws Exception {
String sourceComment = "Hi mom merge";
String destinationComment = "Hi dad merge";
String appliedComment = destinationComment + '\n' + sourceComment;
@ -52,15 +50,14 @@ public class CommentMarkupItemTest extends AbstractVTMarkupItemTest {
setComment(sourceProgram, sourceComment, commentAddress);
setComment(destinationProgram, destinationComment, commentAddress);
CommentValidator validator =
new CommentValidator("0x01002cf5", "0x01002cf5", commentAddress, sourceComment,
destinationComment, appliedComment, CodeUnit.EOL_COMMENT,
CommentChoices.APPEND_TO_EXISTING);
CommentValidator validator = new CommentValidator("0x01002cf5", "0x01002cf5",
commentAddress, sourceComment, destinationComment, appliedComment, CommentType.EOL,
CommentChoices.APPEND_TO_EXISTING);
doTestFindAndApplyMarkupItem(validator);
}
@Test
public void testFindAndApplyMarkupItem_Merge_WithNullDestinationValue() throws Exception {
@Test
public void testFindAndApplyMarkupItem_Merge_WithNullDestinationValue() throws Exception {
String sourceComment = "Hi mom merge";
String destinationComment = null;
String appliedComment = sourceComment;
@ -70,15 +67,14 @@ public class CommentMarkupItemTest extends AbstractVTMarkupItemTest {
setComment(sourceProgram, sourceComment, commentAddress);
setComment(destinationProgram, destinationComment, commentAddress);
CommentValidator validator =
new CommentValidator("0x01002cf5", "0x01002cf5", commentAddress, sourceComment,
destinationComment, appliedComment, CodeUnit.EOL_COMMENT,
CommentChoices.APPEND_TO_EXISTING);
CommentValidator validator = new CommentValidator("0x01002cf5", "0x01002cf5",
commentAddress, sourceComment, destinationComment, appliedComment, CommentType.EOL,
CommentChoices.APPEND_TO_EXISTING);
doTestFindAndApplyMarkupItem(validator);
}
@Test
public void testFindAndApplyMarkupItem_Replace_WithNonNullDestinationValue() throws Exception {
@Test
public void testFindAndApplyMarkupItem_Replace_WithNonNullDestinationValue() throws Exception {
String sourceComment = "Hi mom merge";
String destinationComment = "Hi dad merge";
String appliedComment = sourceComment;
@ -88,15 +84,14 @@ public class CommentMarkupItemTest extends AbstractVTMarkupItemTest {
setComment(sourceProgram, sourceComment, commentAddress);
setComment(destinationProgram, destinationComment, commentAddress);
CommentValidator validator =
new CommentValidator("0x01002cf5", "0x01002cf5", commentAddress, sourceComment,
destinationComment, appliedComment, CodeUnit.EOL_COMMENT,
CommentChoices.OVERWRITE_EXISTING);
CommentValidator validator = new CommentValidator("0x01002cf5", "0x01002cf5",
commentAddress, sourceComment, destinationComment, appliedComment, CommentType.EOL,
CommentChoices.OVERWRITE_EXISTING);
doTestFindAndApplyMarkupItem(validator);
}
@Test
public void testFindAndApplyMarkupItem_Replace_WithNullDestinationValue() throws Exception {
@Test
public void testFindAndApplyMarkupItem_Replace_WithNullDestinationValue() throws Exception {
String sourceComment = "Hi mom merge";
String destinationComment = null;
String appliedComment = sourceComment;
@ -106,15 +101,14 @@ public class CommentMarkupItemTest extends AbstractVTMarkupItemTest {
setComment(sourceProgram, sourceComment, commentAddress);
setComment(destinationProgram, destinationComment, commentAddress);
CommentValidator validator =
new CommentValidator("0x01002cf5", "0x01002cf5", commentAddress, sourceComment,
destinationComment, appliedComment, CodeUnit.EOL_COMMENT,
CommentChoices.OVERWRITE_EXISTING);
CommentValidator validator = new CommentValidator("0x01002cf5", "0x01002cf5",
commentAddress, sourceComment, destinationComment, appliedComment, CommentType.EOL,
CommentChoices.OVERWRITE_EXISTING);
doTestFindAndApplyMarkupItem(validator);
}
@Test
public void testFindAndApplyMarkupItem_IgnoreAction() throws Exception {
@Test
public void testFindAndApplyMarkupItem_IgnoreAction() throws Exception {
String sourceComment = "Hi mom merge";
String destinationComment = null;
String appliedComment = destinationComment; // the comment is not applied
@ -126,7 +120,7 @@ public class CommentMarkupItemTest extends AbstractVTMarkupItemTest {
CommentValidator validator =
new CommentValidator("0x01002cf5", "0x01002cf5", commentAddress, sourceComment,
destinationComment, appliedComment, CodeUnit.EOL_COMMENT, CommentChoices.EXCLUDE);
destinationComment, appliedComment, CommentType.EOL, CommentChoices.EXCLUDE);
doTestFindAndApplyMarkupItem(validator);
}
@ -139,7 +133,7 @@ public class CommentMarkupItemTest extends AbstractVTMarkupItemTest {
int transaction = -1;
try {
transaction = program.startTransaction("Test - Add Comment: " + comment);
listing.setComment(address, CodeUnit.EOL_COMMENT, comment);
listing.setComment(address, CommentType.EOL, comment);
}
finally {
program.endTransaction(transaction, true);
@ -158,12 +152,12 @@ public class CommentMarkupItemTest extends AbstractVTMarkupItemTest {
private final String sourceComment;
private final String destinationComment;
private final String appliedComment;
private final int commentType;
private final CommentType commentType;
private CommentChoices commentChoice;
CommentValidator(String sourceFunctionAddress, String destinationFunctionAddress,
Address commentAddress, String sourceComment, String destinationComment,
String appliedComment, int commentType, CommentChoices commentChoice) {
String appliedComment, CommentType commentType, CommentChoices commentChoice) {
this.commentChoice = commentChoice;
this.sourceFunctionAddress = addr(sourceFunctionAddress, sourceProgram);
this.destinationFunctionAddress = addr(destinationFunctionAddress, destinationProgram);
@ -244,15 +238,15 @@ public class CommentMarkupItemTest extends AbstractVTMarkupItemTest {
private String getOptionName() {
switch (commentType) {
case CodeUnit.EOL_COMMENT:
case EOL:
return VTOptionDefines.END_OF_LINE_COMMENT;
case CodeUnit.PLATE_COMMENT:
case PLATE:
return VTOptionDefines.PLATE_COMMENT;
case CodeUnit.POST_COMMENT:
case POST:
return VTOptionDefines.POST_COMMENT;
case CodeUnit.PRE_COMMENT:
case PRE:
return VTOptionDefines.PRE_COMMENT;
case CodeUnit.REPEATABLE_COMMENT:
case REPEATABLE:
return VTOptionDefines.REPEATABLE_COMMENT;
default:
return null;

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -164,36 +164,36 @@ public class ForceApplyOfExcludedMarkupTest extends AbstractFunctionSignatureMar
@Test
public void testForceApplyForExcludedPlateComment() throws Exception {
genericTestForceApplyForExcludedComment(PlateCommentMarkupType.class,
CodeUnit.PLATE_COMMENT, PLATE_COMMENT);
genericTestForceApplyForExcludedComment(PlateCommentMarkupType.class, CommentType.PLATE,
PLATE_COMMENT);
}
@Test
public void testForceApplyForExcludedPreComment() throws Exception {
genericTestForceApplyForExcludedComment(PreCommentMarkupType.class, CodeUnit.PRE_COMMENT,
genericTestForceApplyForExcludedComment(PreCommentMarkupType.class, CommentType.PRE,
PRE_COMMENT);
}
@Test
public void testForceApplyForExcludedEOLComment() throws Exception {
genericTestForceApplyForExcludedComment(EolCommentMarkupType.class, CodeUnit.EOL_COMMENT,
genericTestForceApplyForExcludedComment(EolCommentMarkupType.class, CommentType.EOL,
END_OF_LINE_COMMENT);
}
@Test
public void testForceApplyForExcludeRepeatableComment() throws Exception {
genericTestForceApplyForExcludedComment(RepeatableCommentMarkupType.class,
CodeUnit.REPEATABLE_COMMENT, REPEATABLE_COMMENT);
CommentType.REPEATABLE, REPEATABLE_COMMENT);
}
@Test
public void testForceApplyForExcludedPostComment() throws Exception {
genericTestForceApplyForExcludedComment(PostCommentMarkupType.class, CodeUnit.POST_COMMENT,
genericTestForceApplyForExcludedComment(PostCommentMarkupType.class, CommentType.POST,
POST_COMMENT);
}
private void genericTestForceApplyForExcludedComment(
Class<? extends CommentMarkupType> commentMarkupClass, int commentType,
Class<? extends CommentMarkupType> commentMarkupClass, CommentType commentType,
String vtOptionName) throws Exception {
useMatch("0x00411ab0", "0x00411a90");
@ -230,7 +230,7 @@ public class ForceApplyOfExcludedMarkupTest extends AbstractFunctionSignatureMar
//----------------------------
protected void checkComments(final int commentType, final Address sourceAddr,
protected void checkComments(CommentType commentType, final Address sourceAddr,
final String expectedSourceComment, final Address destinationAddr,
final String expectedDestinationComment) {
@ -283,7 +283,7 @@ public class ForceApplyOfExcludedMarkupTest extends AbstractFunctionSignatureMar
return null;
}
protected void checkCommentStatus(VTMatch match, int commentType,
protected void checkCommentStatus(VTMatch match, CommentType commentType,
VTMarkupItemStatus expectedStatus) {
VTMarkupItem markupItem = getCommentMarkup(match, commentType);
if (expectedStatus == null && markupItem == null) {
@ -293,33 +293,33 @@ public class ForceApplyOfExcludedMarkupTest extends AbstractFunctionSignatureMar
checkMarkupStatus(markupItem, expectedStatus);
}
protected VTMarkupItem getCommentMarkup(VTMatch match, int commentType) {
protected VTMarkupItem getCommentMarkup(VTMatch match, CommentType commentType) {
MatchInfo matchInfo = controller.getMatchInfo(match);
Collection<VTMarkupItem> appliableMarkupItems =
matchInfo.getAppliableMarkupItems(TaskMonitor.DUMMY);
for (VTMarkupItem vtMarkupItem : appliableMarkupItems) {
switch (commentType) {
case CodeUnit.PLATE_COMMENT:
case PLATE:
if (vtMarkupItem.getMarkupType() instanceof PlateCommentMarkupType) {
return vtMarkupItem;
}
continue;
case CodeUnit.PRE_COMMENT:
case PRE:
if (vtMarkupItem.getMarkupType() instanceof PreCommentMarkupType) {
return vtMarkupItem;
}
continue;
case CodeUnit.EOL_COMMENT:
case EOL:
if (vtMarkupItem.getMarkupType() instanceof EolCommentMarkupType) {
return vtMarkupItem;
}
continue;
case CodeUnit.REPEATABLE_COMMENT:
case REPEATABLE:
if (vtMarkupItem.getMarkupType() instanceof RepeatableCommentMarkupType) {
return vtMarkupItem;
}
continue;
case CodeUnit.POST_COMMENT:
case POST:
if (vtMarkupItem.getMarkupType() instanceof PostCommentMarkupType) {
return vtMarkupItem;
}
@ -336,7 +336,8 @@ public class ForceApplyOfExcludedMarkupTest extends AbstractFunctionSignatureMar
waitOnPossibleBackgroundProcessing();
}
protected void setComment(Program program, Address address, int commentType, String comment) {
protected void setComment(Program program, Address address, CommentType commentType,
String comment) {
int transaction = -1;
try {
transaction = program.startTransaction("Test - Set Comment: " + address.toString(true));