Skip to content
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

Test Code isn't human readable because enums and static values are fully qualified #162

Closed
ocean7 opened this issue Mar 4, 2015 · 5 comments · Fixed by #183
Closed

Test Code isn't human readable because enums and static values are fully qualified #162

ocean7 opened this issue Mar 4, 2015 · 5 comments · Fixed by #183

Comments

@ocean7
Copy link

ocean7 commented Mar 4, 2015

We're using spoon to generate some documentation. As part of this effort we're actually including some of the Java code in a generated website. We use CtMethod.getBody().toString() to get the code associated with a special annotated method. The string returned from this method has enums and other static variables fully qualified. Can this be disabled? The actual code itself (that's parsed by spoon) doesn't use fully qualified names to refer to enums (it relies on Java import mechanism). Could spoon by default return a faithful copy of the actual code?

@GerardPaligot
Copy link
Contributor

You can generate your source code with the option --with-imports from the launcher. This should centralize all imports in the header of your classes and no more use fully qualified names in your source code. But this option is a little bit experimental.

@ocean7
Copy link
Author

ocean7 commented Mar 4, 2015

This doesn't seem to work. Tried passing this option to the Launcher ctor:

    private static SpoonCompiler createSpoonCompiler(final Factory factory) {
        Launcher launcher = new Launcher() {
            @Override
            public Factory createFactory() {
                return factory;
            }
        };
        launcher.setArgs(new String[] { "--with-imports" });
        return launcher.createCompiler();
    }

@GerardPaligot
Copy link
Contributor

You seems to use directly a compiler and not the launcher. Test something like this:

private static SpoonCompiler createSpoonCompiler(final Factory factory) {
    Launcher launcher = new Launcher() {
        @Override
        public Factory createFactory() {
            return factory;
        }
    };
    factory.getEnvironment().setAutoImports(true);
    return launcher.createCompiler();
}

@ocean7
Copy link
Author

ocean7 commented Mar 19, 2015

Yes, this doesn't work either.

Actually creating the factory and the launcher like:

StandardEnvironment spoonEnvironment = new StandardEnvironment();
        spoonEnvironment.setComplianceLevel(8);
        spoonEnvironment.setVerbose(true);
        spoonEnvironment.setAutoImports(true);

        Factory factory = new FactoryImpl(new DefaultCoreFactory(), spoonEnvironment);

@GerardPaligot
Copy link
Contributor

@ocean7 In the next snapshot (or release), you can print any elements with imports.

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 a pull request may close this issue.

2 participants