Package com.pnfsoftware.jeb.core.units
Class UnitUtil
java.lang.Object
com.pnfsoftware.jeb.core.units.UnitUtil
Utility methods for
units.-
Method Summary
Modifier and TypeMethodDescriptionstatic StringbuildFullyQualifiedCandidateUnitPath(String candidateUnitName, IUnitCreator parent, boolean includeArtifact, String separator) Build the fully-qualified path of a potential unit whose only the name is provided.static StringBuild a unit path of the artifact name and its parent units, such as:artifact > unit > unit > ...static StringbuildFullyQualifiedUnitPath(IUnit unit, boolean includeArtifact, String separator) Build a fully-qualified unit path.buildFullyQualifiedUnitPathList(IUnitCreator unit, boolean includeArtifact) Build a fully-qualified unit path as list of unit names.static StringdebuggerProperty(IEnginesContext engctx, String codeType, String propertyName) Generate a fully-qualified property name used by adecompiler unit.static StringdecompilerProperty(IEnginesContext engctx, String codeType, String propertyName) Generate a fully-qualified property name used by adecompiler unit.filterDescendants(IUnit base, int maxDepth, IUnitFilter filter) Retrieve a list of descendants of the provided unit that pass the provided filter test and do not exceeded the maximum depth.Retrieve matching units from all currently loaded projects.static <T extends IUnitCreator>
TfindAncestor(IUnit unit, Class<T> c, boolean strict) static <T extends IUnit>
TRetrieve a child unit by name and type.static IUnitfindChildByFormatType(IUnit base, String formatType, int index) Retrieve a child unit by format type.static IUnitfindChildByName(IUnit base, String name, int index) Retrieve a child unit by name.static <T extends IUnit>
TfindChildByType(IUnit base, Class<T> classtype, boolean exactClasstype, int index) Retrieve a child unit by type.findChildren(IUnit base, String name, Class<T> c, boolean strict) Retrieve child units by name and type.findChildrenByFormatType(IUnit base, String formatType) Retrieve child units by format type.findChildrenByName(IUnit base, String name) Retrieve child units by name.findChildrenByType(IUnit base, Class<T> classtype, boolean exactClasstype) Retrieve child units by type.findDescendants(ILiveArtifact base, int level, String name, Class<T> c, boolean strict) Retrieve descendant units of an artifact by name and type.findDescendants(IUnit base, int maxDepth, String name, Class<T> classtype, boolean exactClasstype) Convenience function to find descendant units by type and/or name.findDescendantsByFormatType(IUnit base, int level, String formatType) Retrieve descendant units by format type.findDescendantsByFormatType(IUnit base, String formatType) Retrieve descendant units by format type.findDescendantsByName(IUnit base, int maxDepth, String name) Retrieve a list of descendant units of the provided unit that have the provided name.findDescendantsByName(IUnit base, String name) Retrieve descendant units by name.findDescendantsByType(IUnit base, int maxDepth, Class<T> classtype, boolean exactClasstype) Retrieve a list of descendant units of the provided unit that are of the provided classtype (exact or derived) and do not exceeded the maximum depth.findDescendantsByType(IUnit base, Class<T> classtype, boolean exactClasstype) Retrieve descendant units by type.static IUnitfindFirstChildByFormatType(IUnit base, String formatType) Retrieve the first child unit by format type.static IUnitfindFirstChildByName(IUnit base, String name) Retrieve the first child unit by name.static <T extends IUnit>
TfindFirstChildByType(IUnit base, Class<T> classtype, boolean exactClasstype) Retrieve the first child unit by type.getUnitsFromPathList(IRuntimeProject prj, List<String> path) Retrieve the targetsIUnitfrom its path (built frombuildFullyQualifiedUnitPathList(IUnitCreator, boolean)for example).static booleanisAncestorOf(IUnit unit, IUnit expectedAncestor) Determine whether a unit is a descendant of another unit.static booleanisAncestorOf(IUnit unit, IUnit expectedAncestor, boolean strictAncestor) Determine whether a unit is a descendant of another unit.static booleanisTopLevelUnit(IUnit unit) Determine whether a unit is directly attached to an artifact.static voidlogError(IUnit unit, String address, boolean recordNotification, ILogger logger, String format, Object... params) Log an error and optionally record a unit notification.static voidlogException(IUnit unit, ILogger logger, Exception e) Log an exception and optionally record a unit notification.static voidLog an internal message.static voidlogInfo(IUnit unit, String address, boolean recordNotification, ILogger logger, String format, Object... params) Log an informational message and optionally record a unit notification.static voidLog a trace message.static voidlogWarn(IUnit unit, String address, boolean recordNotification, ILogger logger, String format, Object... params) Log a warning and optionally record a unit notification.static voidnotifyGenericChange(IUnit unit) Issue a genericJ.UnitChangeevent to all listeners of the provided unit.static IUnitRetrieve a unit rooted in the provided base, and whose relative path from that base consists of the provided path elements.static IUnitretrieveProcessed(boolean processIfUnprocessed, IUnit base, String... pathElements) Retrieve a unit rooted in the provided base, and whose relative path from that base consists of the provided path elements.static StringunitProperty(IEnginesContext engctx, String unitType, String propertyName) Generate a fully-qualified property name used by aunit.static StringunitProperty(IUnitIdentifier ident, String propertyName) Generate a fully-qualified property name used by aunit.static StringunitProperty(IUnit unit, String propertyName) Generate a fully-qualified property name used by aunit.
-
Method Details
-
notifyGenericChange
Issue a genericJ.UnitChangeevent to all listeners of the provided unit.- Parameters:
unit- a unit
-
logI
public static void logI(IUnit unit, String address, ILogger logger, String format, Object... params) Log an internal message.- Parameters:
unit- optional unitaddress- optional unit addresslogger- loggerformat- message formatparams- format parameters
-
logTrace
public static void logTrace(IUnit unit, String address, ILogger logger, String format, Object... params) Log a trace message.- Parameters:
unit- optional unitaddress- optional unit addresslogger- loggerformat- message formatparams- format parameters
-
logInfo
public static void logInfo(IUnit unit, String address, boolean recordNotification, ILogger logger, String format, Object... params) Log an informational message and optionally record a unit notification.- Parameters:
unit- optional unitaddress- optional unit addressrecordNotification- true to record a persistent notificationlogger- loggerformat- message formatparams- format parameters
-
logWarn
public static void logWarn(IUnit unit, String address, boolean recordNotification, ILogger logger, String format, Object... params) Log a warning and optionally record a unit notification.- Parameters:
unit- optional unitaddress- optional unit addressrecordNotification- true to record a persistent notificationlogger- loggerformat- message formatparams- format parameters
-
logError
public static void logError(IUnit unit, String address, boolean recordNotification, ILogger logger, String format, Object... params) Log an error and optionally record a unit notification.- Parameters:
unit- optional unitaddress- optional unit addressrecordNotification- true to record a persistent notificationlogger- loggerformat- message formatparams- format parameters
-
logException
Log an exception and optionally record a unit notification.- Parameters:
unit- optional unitlogger- loggere- exception to log
-
filterDescendants
Retrieve a list of descendants of the provided unit that pass the provided filter test and do not exceeded the maximum depth.- Parameters:
base- base unitmaxDepth- use -1 to go as deep as possiblefilter- optional unit filter- Returns:
- matching descendants
-
findDescendantsByType
public static <T extends IUnit> List<T> findDescendantsByType(IUnit base, int maxDepth, Class<T> classtype, boolean exactClasstype) Retrieve a list of descendant units of the provided unit that are of the provided classtype (exact or derived) and do not exceeded the maximum depth.- Type Parameters:
T- unit type- Parameters:
base- base unitmaxDepth- use -1 to go as deep as possibleclasstype- wanted classtypeexactClasstype- if true, only units of the exact classtype will be returned- Returns:
- matching descendants
-
findChildrenByType
public static <T extends IUnit> List<T> findChildrenByType(IUnit base, Class<T> classtype, boolean exactClasstype) Retrieve child units by type.- Type Parameters:
T- unit type- Parameters:
base- base unitclasstype- wanted class typeexactClasstype- true for exact class matches- Returns:
- matching children
-
findChildByType
public static <T extends IUnit> T findChildByType(IUnit base, Class<T> classtype, boolean exactClasstype, int index) Retrieve a child unit by type.- Type Parameters:
T- unit type- Parameters:
base- base unitclasstype- wanted class typeexactClasstype- true for exact class matchesindex- result index- Returns:
- matching child, or null if none
-
findFirstChildByType
public static <T extends IUnit> T findFirstChildByType(IUnit base, Class<T> classtype, boolean exactClasstype) Retrieve the first child unit by type.- Type Parameters:
T- unit type- Parameters:
base- base unitclasstype- wanted class typeexactClasstype- true for exact class matches- Returns:
- matching child, or null if none
-
findDescendantsByType
public static <T extends IUnit> List<T> findDescendantsByType(IUnit base, Class<T> classtype, boolean exactClasstype) Retrieve descendant units by type.- Type Parameters:
T- unit type- Parameters:
base- base unitclasstype- wanted class typeexactClasstype- true for exact class matches- Returns:
- matching descendants
-
findDescendantsByName
Retrieve a list of descendant units of the provided unit that have the provided name.- Parameters:
base- base unitmaxDepth- use -1 to go as deep as possiblename- wanted unit name- Returns:
- matching descendants
-
findDescendantsByName
Retrieve descendant units by name.- Parameters:
base- base unitname- wanted unit name- Returns:
- matching descendants
-
findChildrenByName
Retrieve child units by name.- Parameters:
base- base unitname- wanted unit name- Returns:
- matching children
-
findChildByName
Retrieve a child unit by name.- Parameters:
base- base unitname- wanted unit nameindex- result index- Returns:
- matching child, or null if none
-
findFirstChildByName
Retrieve the first child unit by name.- Parameters:
base- base unitname- wanted unit name- Returns:
- matching child, or null if none
-
retrieve
Retrieve a unit rooted in the provided base, and whose relative path from that base consists of the provided path elements.- Parameters:
base- a root unitpathElements- 1 or more sub-unit names- Returns:
- the unit corresponding to the last path element, null if not found - the unit may not have been processed
-
retrieveProcessed
public static IUnit retrieveProcessed(boolean processIfUnprocessed, IUnit base, String... pathElements) Retrieve a unit rooted in the provided base, and whose relative path from that base consists of the provided path elements. The returned unit is guaranteed to be processed.- Parameters:
processIfUnprocessed- attempt to process the unit if it is unprocessedbase- root unitpathElements- sub-unit names- Returns:
- a unit (processed) or null
-
findDescendants
public static <T extends IUnit> List<T> findDescendants(IUnit base, int maxDepth, String name, Class<T> classtype, boolean exactClasstype) Convenience function to find descendant units by type and/or name.- Type Parameters:
T- unit type- Parameters:
base- base unitmaxDepth- use -1 to go as deep as possiblename- optional unit nameclasstype- optional unit typeexactClasstype- true for exact class matches- Returns:
- matching descendants
-
findChildren
public static <T extends IUnit> List<T> findChildren(IUnit base, String name, Class<T> c, boolean strict) Retrieve child units by name and type.- Type Parameters:
T- unit type- Parameters:
base- base unitname- optional unit namec- optional unit typestrict- true for exact class matches- Returns:
- matching children
-
findChild
public static <T extends IUnit> T findChild(IUnit base, String name, Class<T> c, boolean strict, int index) Retrieve a child unit by name and type.- Type Parameters:
T- unit type- Parameters:
base- base unitname- optional unit namec- optional unit typestrict- true for exact class matchesindex- result index- Returns:
- matching child, or null if none
-
findDescendants
public static <T extends IUnit> List<T> findDescendants(ILiveArtifact base, int level, String name, Class<T> c, boolean strict) Retrieve descendant units of an artifact by name and type.- Type Parameters:
T- unit type- Parameters:
base- base artifactlevel- maximum depth, or -1 for no limitname- optional unit namec- optional unit typestrict- true for exact class matches- Returns:
- matching descendants
-
findAll
Retrieve matching units from all currently loaded projects.- Type Parameters:
T- unit type- Parameters:
name- optional unit namec- optional unit typestrict- true for exact class matches- Returns:
- matching units
-
findDescendantsByFormatType
public static <T extends IUnit> List<T> findDescendantsByFormatType(IUnit base, int level, String formatType) Retrieve descendant units by format type.- Type Parameters:
T- unit type- Parameters:
base- base unitlevel- maximum depth, or -1 for no limitformatType- wanted format type- Returns:
- matching descendants
-
findDescendantsByFormatType
Retrieve descendant units by format type.- Parameters:
base- base unitformatType- wanted format type- Returns:
- matching descendants
-
findChildrenByFormatType
Retrieve child units by format type.- Parameters:
base- base unitformatType- wanted format type- Returns:
- matching children
-
findChildByFormatType
Retrieve a child unit by format type.- Parameters:
base- base unitformatType- wanted format typeindex- result index- Returns:
- matching child, or null if none
-
findFirstChildByFormatType
Retrieve the first child unit by format type.- Parameters:
base- base unitformatType- wanted format type- Returns:
- matching child, or null if none
-
findAncestor
- Type Parameters:
T- ancestor type- Parameters:
unit- a children elementc- the class to match. Can be an interface.strict- if true, only units of the exact classtype will be returned- Returns:
- the closest ancestor that matches, or null if not found
-
isAncestorOf
Determine whether a unit is a descendant of another unit.- Parameters:
unit- candidate descendantexpectedAncestor- expected ancestor- Returns:
- true if the ancestor relationship exists
-
isAncestorOf
Determine whether a unit is a descendant of another unit.- Parameters:
unit- candidate descendantexpectedAncestor- expected ancestorstrictAncestor- true to require a strict ancestor- Returns:
- true if the ancestor relationship exists
-
buildFullyQualifiedCandidateUnitPath
public static String buildFullyQualifiedCandidateUnitPath(String candidateUnitName, IUnitCreator parent, boolean includeArtifact, String separator) Build the fully-qualified path of a potential unit whose only the name is provided.- Parameters:
candidateUnitName- candidate unit nameparent- parent unit or artifactincludeArtifact- true to include the artifact nameseparator- path separator- Returns:
- fully-qualified candidate path
-
buildFullyQualifiedUnitPath
public static String buildFullyQualifiedUnitPath(IUnit unit, boolean includeArtifact, String separator) Build a fully-qualified unit path.- Parameters:
unit- unitincludeArtifact- true to include the artifact nameseparator- path separator- Returns:
- fully-qualified unit path
-
buildFullyQualifiedUnitPathList
public static List<String> buildFullyQualifiedUnitPathList(IUnitCreator unit, boolean includeArtifact) Build a fully-qualified unit path as list of unit names.- Parameters:
unit- unit or artifactincludeArtifact- true to include the artifact name- Returns:
- path elements
-
buildFullyQualifiedUnitPath
Build a unit path of the artifact name and its parent units, such as:artifact > unit > unit > ... > unit- Parameters:
unit- unit- Returns:
- fully-qualified unit path
-
isTopLevelUnit
Determine whether a unit is directly attached to an artifact.- Parameters:
unit- unit- Returns:
- true if the unit is top-level
-
unitProperty
Generate a fully-qualified property name used by aunit.- Parameters:
ident- a unit identifierpropertyName- simple property name- Returns:
- a FQ name
-
unitProperty
Generate a fully-qualified property name used by aunit.- Parameters:
unit- a unitpropertyName- simple property name- Returns:
- a FQ name
-
unitProperty
Generate a fully-qualified property name used by aunit.- Parameters:
engctx- JEB engines contextunitType- unit typepropertyName- simple property name- Returns:
- a FQ name
-
decompilerProperty
public static String decompilerProperty(IEnginesContext engctx, String codeType, String propertyName) Generate a fully-qualified property name used by adecompiler unit.- Parameters:
engctx- JEB engines contextcodeType- code unit type (not a decompiler unit)propertyName- simple property name- Returns:
- a fully-qualified property name, or null if the property namespace cannot be found
-
debuggerProperty
Generate a fully-qualified property name used by adecompiler unit.- Parameters:
engctx- JEB engines contextcodeType- code unit type (not a debugger unit)propertyName- simple property name- Returns:
- a fully-qualified property name, or null if the property namespace cannot be found
-
getUnitsFromPathList
Retrieve the targetsIUnitfrom its path (built frombuildFullyQualifiedUnitPathList(IUnitCreator, boolean)for example). Note that result target will be unique in most of the cases.- Parameters:
prj- runtime projectpath- path elements- Returns:
- matching units
-