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

Wrong javax import statement causing compilation error #3320

Closed
gibahjoe opened this issue Apr 10, 2020 · 5 comments · Fixed by #3341
Closed

Wrong javax import statement causing compilation error #3320

gibahjoe opened this issue Apr 10, 2020 · 5 comments · Fixed by #3341

Comments

@gibahjoe
Copy link
Contributor

gibahjoe commented Apr 10, 2020

Hello,

thank you for this great tool.

The generated code for a class that declares a javax validation annotation on its parameter has wrong import statement which causes compile time errors. This only seems to be an issue with javax annotations such as @Valid and @NotNull

for a declaration of

public void testThatValidAnnotationImportsAreCreated(@Valid @NotNull RandomDto randomDto) 
{
        
throw new IllegalArgumentException("An Error has occurred");

 }

The import generated is

import com.example.processor.src.other.@javax.validation.Valid

@javax.validation.constraints.NotNull

RandomDto;

instead of

import com.example.processor.src.other.RandomDto;

import javax.validation.Valid;

import javax.validation.constraints.NotNull;

this is related to issue #1773 and #1774

Tested on Spoon 8.1.0 and 8.2.0-beta2 running java 8

My launcher config is

  SpoonAPI launcher = new Launcher();

  Environment environment = launcher.getEnvironment();

  environment.setNoClasspath(true);

  environment.setAutoImports(true);

  launcher.addInputResource(s);

  launcher.setSourceOutputDirectory(sourceOutputDirectory);

  ClassProcessor processor = new ClassProcessor();

  launcher.addProcessor(processor);

  launcher.process();

  launcher.prettyprint();
@monperrus
Copy link
Collaborator

monperrus commented Apr 12, 2020 via email

gibahjoe added a commit to gibahjoe/spoon that referenced this issue Apr 12, 2020
@gibahjoe
Copy link
Contributor Author

check #3323

Its not a failing testcase, just take a look at the generated source file

@gibahjoe
Copy link
Contributor Author

any update?

@monperrus
Copy link
Collaborator

monperrus commented Apr 21, 2020 via email

@gibahjoe
Copy link
Contributor Author

I am happy to try. If you could point me to where the imports are being generated. or anything related

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