Skip to content

Kotlin/Java: enum constants are not extracted as nodes — "where is ErrorCode.X used" is unanswerable #1700

Description

@jerryliurui

Environment

  • graphify 0.9.7 (PyPI graphifyy), macOS, Python 3.10
  • Extraction invoked directly via graphify.extract.extract(files, parallel=False)

Summary

Enum constants are not extracted as nodes in either Kotlin or Java. The enum class itself gets a node, but its members (ChatType.SYSTEM, ErrorCode.GAME_DONE, …) do not exist anywhere in the graph, so queries like "where is this error code used" / "who branches on ChatType.SYSTEM" are unanswerable — the constant name simply isn't in the node table.

Reproducer (3 files)

ChatType.kt

package demo

enum class ChatType {
    NORMAL,
    GROUP,
    SYSTEM
}

TypeCheck.kt

package demo

class TypeCheck {
    fun isSystem(type: ChatType): Boolean {
        return type == ChatType.SYSTEM
    }
}

ErrorCode.java

package demo;

public enum ErrorCode {
    OK(0),
    GAME_DONE(1001);

    private final int code;

    ErrorCode(int code) {
        this.code = code;
    }
}

Current behavior (0.9.7)

Complete node list for the three files:

chattype_kt_chattype        (file)
chattype_chattype           (enum class — no children besides the file)
typecheck                   (file)
typecheck_typecheck         (class)
typecheck_typecheck_issystem (method)
boolean
errorcode                   (file)
errorcode_errorcode         (enum class)

NORMAL / GROUP / SYSTEM / OK / GAME_DONE appear nowhere. TypeCheck.isSystem gets a references edge to the ChatType class, but the fact that it specifically tests SYSTEM is lost. (Aside: the Java enum also emits its errorcode --contains--> errorcode_errorcode edge twice.)

Expected

Enum constants extracted as child nodes of the enum class (analogous to methods), e.g.:

chattype_chattype --constant--> chattype_chattype_system
typecheck_typecheck_issystem --references--> chattype_chattype_system

Even without the usage edge, just having the constant as a searchable node would let downstream tooling find the definition and fall back to text search for usages.

Real-world impact

Hit twice in one week on two different production codebases: (1) a Java backend where a newly added error-code constant (the subject of the change) couldn't be located in the graph at all — the class was indexed, the constant wasn't; (2) an Android app where "which places branch on the SYSTEM chat type" (the exact subject of a bugfix commit) had no graph answer. Enum-driven branching (message types, error codes, feature states) is one of the most common "find all usages before changing behavior" queries in app/backend codebases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions