jhipster / jhipster-core

JHipster Domain Language, used by JHipster UML and JDL-Studio to generate entities
Apache License 2.0
346 stars 116 forks source link

Order between annotation and javadoc is significant and can lead to missing javadoc or crash #369

Closed murdos closed 4 years ago

murdos commented 4 years ago
Overview of the issue

While doing some tests with the customs annotations from https://github.com/jhipster/jhipster-core/pull/349 from master version, I noticed several issues related to the order of javadoc and annotations:

On entity level:

Works:

@dto(mapstruct)
/** entity javadoc */
entity A {
  /** field javadoc */ name String
}

However with the following jdl, the javadoc is silently dropped:

/** entity javadoc */
@dto(mapstruct)
entity A {
  /** field javadoc */ name String
}

On field level:

Works:

/** entity javadoc */
entity A {
  @id /** field javadoc */ name String
}

Crashes:

/** entity javadoc */
entity A {
  /** field javadoc */ 
  @id name String
}

with the error:

INFO! The JDL is being parsed.
error: Error message:
    MismatchedTokenException: Expecting token of type --> NAME <-- but found --> '@' <--
    at line: 4, column: 3
SyntaxError: Error: MismatchedTokenException: Expecting token of type --> NAME <-- but found --> '@' <--
    at line: 4, column: 3
Error while parsing applications and entities from the JDL SyntaxError: Error: MismatchedTokenException: Expecting token of type --> NAME <-- but found --> '@' <--
    at line: 4, column: 3
SyntaxError: Error: MismatchedTokenException: Expecting token of type --> NAME <-- but found --> '@' <--
Motivation for or Use Case

Similarly to what’s possible in Java, it should be possible to add javadoc before annotation and the other way round. The javadoc should not be silently dropped or makes the parser crashes.

Reproduce the error

See above

Related issues
Suggest a Fix

No idea! 😁

JHipster Version(s)

6.3.0 with jhipster-core master

JHipster configuration
Entity configuration(s) entityName.json files generated in the .jhipster directory
Browsers and Operating System
MathieuAA commented 4 years ago

Outch, thanks for reporting this one. I'll see about this this week-end

MathieuAA commented 4 years ago

For the entity issue:

For the field issue:

murdos commented 4 years ago

Thanks, case 2 is indeed more fluent. Just wondering: is there's any technical difficulty in support both cases? I saw that for fields there are already 2 different places for javadoc according to documentation:

entity A {
  name String /** My super field */
}

and

entity A {
  /** My super field */ name String
}
MathieuAA commented 4 years ago

Nop, not if whitespaces are involved. As they are ignored, the placement is whatever you want it to be