Class DataTypeMerger<T extends DataType>

java.lang.Object
ghidra.program.database.data.merge.DataTypeMerger<T>
Type Parameters:
T - The specific type of datatype being merged.
Direct Known Subclasses:
EnumMerger, StructureMerger, UnionMerger

public abstract class DataTypeMerger<T extends DataType> extends Object
Base class for datatype mergers. Note that these mergers are non interactive and can only merge datatypes that have no conflicting internal components or settings.

The basic pattern is to create a merger with the two datatypes to be merged and then call the merge() method to produce the new datatype that is the merger of the two original datatypes. The new datatype will have the same name and category path of the first original datatype.

Even if the merge is able to successfully complete and return a new datatype, the merge may have associated warnings that can be retrieved by calling getWarnings(). The intent is that the warning messages can be presented to the user before applying the new datatype.

Typically, after merging the two datatypes, the client will replace the first datatype with the merged datatype (it already has the same name and category). Then all uses of the second datatype will be replaced with updated first datatype.

  • Field Details

    • working

      protected T extends DataType working
    • other

      protected T extends DataType other
  • Constructor Details

    • DataTypeMerger

      protected DataTypeMerger(T dt1, T dt2)
  • Method Details

    • merge

      public final T merge() throws DataTypeMergeException
      Merge the two datatypes that this object was created with into a new datatype.
      Returns:
      the the new merged datatype.
      Throws:
      DataTypeMergeException - thrown if the merge was unable to complete due to some conflict.
    • doMerge

      protected abstract void doMerge() throws DataTypeMergeException
      Throws:
      DataTypeMergeException
    • getWarnings

      public List<String> getWarnings()
      Returns any warnings that were generated by a call to the merge() method.
      Returns:
      any warnings that were generated by a call to the merge() method
    • hasWarnings

      public boolean hasWarnings()
      Returns true if there are any warnings.
      Returns:
      true if there are any warnings
    • warning

      protected void warning(String message)
      Adds a warning to the list of warnings.
      Parameters:
      message - the warning message to add
    • error

      protected void error(String message) throws DataTypeMergeException
      Generates a DataTypeMergeException with the given error message.
      Parameters:
      message - the error message
      Throws:
      DataTypeMergeException - with the given message
    • join

      protected String join(String comment1, String comment2)
      Joins two comment strings unless they are identical or one is null or blank.
      Parameters:
      comment1 - the first comment
      comment2 - the second comment
      Returns:
      a new string with the two non-blank, non-identical commments joined by a space.
    • pickBestTypeForMerge

      protected DataType pickBestTypeForMerge(DataType type1, DataType type2)
    • canUpgrade

      protected boolean canUpgrade(DataType from, DataType to)
      Checks if one datatype can can be upgraded to a another during a merge operation. In this context, upgrade means that one datatype is often a stand-in for another because there wasn't initially enough information to get the correct type. For example, any undefined type of some size is a stand-in for any other datatype of that size, so undefined types can always be upgraded to another type of the same size. Another case is integer types are often mistaken for pointers, integer types can be upgraded to pointers.
      Parameters:
      from - the datatype to test if it can be updated
      to - the dataType to that is the possible upgrade
      Returns:
      true if typically the from dataType can be reasonably upgraded to the to datatype
    • mergeDescription

      protected void mergeDescription()