Skip to content

Commit

Permalink
Fixed parsing of comment before imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Feb 22, 2024
1 parent 7e63d7b commit d7d7b1b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -928,14 +928,18 @@ protected Module parseModule(List<Comment> comments) {
final int missingEndHeader = readMissingString(MODULE_HEADER_END);
final int endHeaderPosition = currentPosition;
skipSpaces();
List<Comment> elementComments = parseCommentsOrModuleElementDocumentations();
skipSpaces();
final List<Import> imports = new ArrayList<Import>();
Import imported = parseImport();
while (imported != null) {
imports.add(imported);
skipSpaces();
elementComments = parseCommentsOrModuleElementDocumentations();
skipSpaces();
imported = parseImport();
}
final List<ModuleElement> moduleElements = parseModuleElements();
final List<ModuleElement> moduleElements = parseModuleElements(elementComments);
final int endPosition = currentPosition;
final boolean missingParenthesis = missingOpenParenthesis != -1 || missingCloseParenthesis != -1;
if (missingParenthesis || missingEPackage != -1 || missingEndHeader != -1) {
Expand Down Expand Up @@ -1072,16 +1076,15 @@ protected Documentation getLastDocumentation(List<Comment> comments) {
*
* @return the created {@link List} of {@link ModuleElement}
*/
protected List<ModuleElement> parseModuleElements() {
protected List<ModuleElement> parseModuleElements(List<Comment> comments) {
final List<ModuleElement> res = new ArrayList<ModuleElement>();

ModuleElement moduleElement;
List<Comment> localComments = comments;
do {
skipSpaces();
final List<Comment> comments = parseCommentsOrModuleElementDocumentations();
res.addAll(comments);
final Documentation documentation = getLastDocumentation(comments);
final Template template = parseTemplate(documentation, hasMain(comments));
res.addAll(localComments);
final Documentation documentation = getLastDocumentation(localComments);
final Template template = parseTemplate(documentation, hasMain(localComments));
if (template != null) {
moduleElement = template;
} else {
Expand All @@ -1090,6 +1093,8 @@ protected List<ModuleElement> parseModuleElements() {
if (moduleElement != null) {
res.add(moduleElement);
}
skipSpaces();
localComments = parseCommentsOrModuleElementDocumentations();
} while (moduleElement != null);

return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@

[import <<beforeImportModuleReference>>org::eclipse::acceleo::<<betweenImportModuleReference>>AcceleoPackage<<afterImportModuleReference>>/]

[comment a simple comment<<commentBeforeEnd>>/]
[comment /]
[**
*/]
[import <<beforeImportModuleReference>>org::eclipse::acceleo::<<betweenImportModuleReference>>AcceleoPackage<<afterImportModuleReference>>/]

[**
* My query has a nice comment.
* <<queryComment>>@param myParam the input EPackage<<queryCommentAfterParameters>>
*/]
<<moduleElementAndImport>>


[query <<queryVisibility>>public <<queryName>>myQuery<<queryOpenParenthesis>>(<<queryVariableName>>myParam <<queryVariableColon>>: <<queryVariableType>>ecore::EPackage<<queryCloseParenthesis>>) <<queryColon>>: <<queryType>>ecore::EClassifier <<queryEqual>>= <<queryExpression>>myParam.<<queryExpressionAfterDot>>eClassifiers->first()<<queryEndHeader>> <<queryEndHeaderAfterSpace>>/]

[**
Expand Down

0 comments on commit d7d7b1b

Please sign in to comment.