Skip to content

Support enum value references in constructor arguments#14

Merged
johnsonlee merged 1 commit intomainfrom
claude/enum-value-reference-equxh
Jan 30, 2026
Merged

Support enum value references in constructor arguments#14
johnsonlee merged 1 commit intomainfrom
claude/enum-value-reference-equxh

Conversation

@johnsonlee
Copy link
Owner

@johnsonlee johnsonlee commented Jan 30, 2026

Summary

Add support for tracking and extracting enum constant references when one enum's constructor takes another enum as an argument. This enables proper analysis of cross-enum dependencies in Java code.

Changes

  • New EnumValueReference data class in Node.kt: Represents a reference from one enum's constructor argument to another enum constant (e.g., Priority.HIGH)

  • Enhanced SootUpAdapter:

    • Added tracking of static field reads to detect enum constant references in bytecode patterns like $stack1 = getstatic Priority.HIGH
    • Extended extractValueFromArg() to handle direct JFieldRef arguments in constructor calls
    • Validates that field type matches declaring class to correctly identify enum constants
  • Test fixtures: Added three new enum test classes:

    • Priority: Simple enum with primitive constructor arguments
    • TaskConfig: Enum with another enum as constructor argument
    • TaskConfigWithId: Enum with mixed arguments (primitive + enum reference)
  • Comprehensive test suite (EnumValueReferenceTest):

    • Verifies extraction of single enum references from TaskConfig
    • Tests mixed constructor arguments (int + enum reference) in TaskConfigWithId
    • Regression test ensuring primitive enum values still extract correctly

Implementation Details

The solution detects the bytecode pattern where enum constants are loaded via getstatic instructions and passed to enum constructors. The EnumValueReference object stores both the fully qualified enum class name and the constant name, allowing downstream analysis to resolve cross-enum relationships.

When one enum's constructor takes another enum constant as argument
(e.g., TaskConfig.URGENT(Priority.HIGH)), the bytecode uses a getstatic
field reference (JFieldRef) which was previously not tracked by the enum
value extractor. The value was silently lost as null.

- Add EnumValueReference data class to represent cross-enum references
- Track JFieldRef assignments in extractEnumValues() for enum constant
  field reads (where field type == declaring class)
- Handle JFieldRef in extractValueFromArg() for direct field references
  in constructor arguments
- Add test enums (Priority, TaskConfig, TaskConfigWithId) and test cases

https://claude.ai/code/session_01GCAdzvUbK32TnWEKvkV7TG
@johnsonlee johnsonlee merged commit 4b1586c into main Jan 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants