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

Duplicity in package-info.java when templates are used #921

Closed
pvojtechovsky opened this issue Oct 30, 2016 · 5 comments
Closed

Duplicity in package-info.java when templates are used #921

pvojtechovsky opened this issue Oct 30, 2016 · 5 comments

Comments

@pvojtechovsky
Copy link
Collaborator

The package-info.java with this content

/**
 * This is test
 * JavaDoc.
 */
@Deprecated
package spoon.test.pkg;

prints this not compilable output

/**
 * This is test
 * JavaDoc.
 *//**
 * This is test
 * JavaDoc.
 */@java.lang.Deprecated
@java.lang.Deprecated
package spoon.test.pkg;

when templates are added to the Launcher

See this branch with test to reproduce the problem.

What way do you prefer to contribute new test?
A) branch like this?
B) branch like this + PR?

@monperrus
Copy link
Collaborator

If you have a PR with a fix, it's always better :-)

@pvojtechovsky
Copy link
Collaborator Author

It looks like FileCompiler.getCompilationUnits() always compiles sources and templates

    public CompilationUnit[] getCompilationUnits() {
        List<SpoonFile> files = new ArrayList<>();
        files.addAll(jdtCompiler.sources.getAllJavaFiles());
        files.addAll(jdtCompiler.templates.getAllJavaFiles());

but may be it should compile only the required java files - these which are sent as input to

JDTBatchCompiler.getUnits(List<SpoonFile> files)

I mean stacktrace like this

    at spoon.support.compiler.jdt.FileCompiler.getCompilationUnits(FileCompiler.java:54)
    at spoon.support.compiler.jdt.JDTBatchCompiler.getUnits(JDTBatchCompiler.java:117)
    at spoon.support.compiler.jdt.FileCompiler.getUnits(FileCompiler.java:1)
    at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.****buildSources OR buildTemplates****(JDTBasedSpoonCompiler.java:380)
    at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:116)
    at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:99)
    at spoon.Launcher.buildModel(Launcher.java:712)
    at spoon.test.pkg.PackageTest.testAnnotationInPackageInfoWhenTemplatesCompiled(PackageTest.java:120)

@monperrus
Copy link
Collaborator

but may be it should compile only the required java files - these which are sent as input to

it makes sense

@pvojtechovsky
Copy link
Collaborator Author

@monperrus could you please explain the comment "they have to be done all at once"?

class JDTBatchCompiler {
...
    public CompilationUnitDeclaration[] getUnits(List<SpoonFile> files) {
...
        // they have to be done all at once
        final CompilationUnitDeclaration[] result = treeBuilderCompiler.buildUnits(getCompilationUnits());

Or can I found some concept of compiler in some documentation/issue/PR?
I am trying to understand how compilation works. But it changes a lot in history and it is hard for me to understand, what is feature and what is a bug.

On one side You agree that "it makes sense" to compile only required java files, but on the other side, there is comment they have to be done all at once. So I have feeling like compiler needs all sources and all templates together at one time, otherwise (I am guessing!) it will produce compilation errors - missing classes, etc. What is your experience please?

@monperrus
Copy link
Collaborator

Hi Pavel,

Are you trying to travel from the surface of Spoon to the deepest and
darkest parts in a few days? You're brave :-)

As far as I remember, I put this comment after having tried to put the
buildUnits inside the for loop after and realized that this was not an
option. Why? I don't remember.

What's sure is that "all at once" referred to the model, not to the
templates. They are conceptually separated and should be parseable
separately.

pvojtechovsky added a commit to pvojtechovsky/spoon that referenced this issue Nov 3, 2016


The calling of compiler was optimized. The correct encoding for input
files is used
pvojtechovsky added a commit to pvojtechovsky/spoon that referenced this issue Nov 6, 2016
It is variant which uses non abstract JDTBatchCompiler
pvojtechovsky added a commit to pvojtechovsky/spoon that referenced this issue Nov 7, 2016
It is variant which uses non abstract JDTBatchCompiler
pvojtechovsky added a commit to pvojtechovsky/spoon that referenced this issue Nov 7, 2016
It is variant which uses non abstract JDTBatchCompiler
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

No branches or pull requests

2 participants