Skip to content

Concrete values for enums #18

@Damtev

Description

@Damtev

We now analyze enum classes static initializers as many others - with a complete analysis of $VALUES array initialization, static fields for enum constants, ordinal, names, etc. But often this analysis is unnecessary - most of the enums do not have complex logic and could be just extracted from runtime. Such extraction can highly improve performance for methods with enum usage.

Actual behavior
Enum values are not processed concretely, and UtBotJava generate 0 executions for method useEnumInDifficultIf below:

public int useEnumInDifficultIf(String s) {
    if ("TRYIF".equalsIgnoreCase(s)) {
        final ManyConstantsEnum[] values = ManyConstantsEnum.values();
        return foo(values[0]);
    } else {
        final ManyConstantsEnum b = B;
        return foo(b);
    }
}

private int foo(ManyConstantsEnum e) {
    if (e.equals(A)) {
        return 1;
    } else {
        return 2;
    }
}

enum ManyConstantsEnum {
    A, B, C, D, E, F, G, H, I, J, K
}

Expected behavior:
Simple enums are processed concretely, and 2 executions with 1 and 2 returned values are generated for method useEnumInDifficultIf.

Metadata

Metadata

Assignees

Labels

ctg-enhancementNew feature, improvement or change request

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions