Skip to content

Concrete values for enums #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Damtev opened this issue May 24, 2022 · 0 comments · Fixed by #19
Closed

Concrete values for enums #18

Damtev opened this issue May 24, 2022 · 0 comments · Fixed by #19
Assignees
Labels
ctg-enhancement New feature, improvement or change request

Comments

@Damtev
Copy link
Member

Damtev commented May 24, 2022

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.

@Damtev Damtev added ctg-enhancement New feature, improvement or change request Priority: Medium labels May 24, 2022
@Damtev Damtev self-assigned this May 24, 2022
@Damtev Damtev moved this to Todo in UTBot Java May 24, 2022
@Damtev Damtev moved this from Todo to In Progress in UTBot Java May 25, 2022
@denis-fokin denis-fokin changed the title Support concrete values for enums Concrete values for enums May 27, 2022
Repository owner moved this from In Progress to Done in UTBot Java May 29, 2022
This was referenced Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ctg-enhancement New feature, improvement or change request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants