[
https://issues.apache.org/jira/browse/GROOVY-9577?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17119072#comment-17119072
]
Eric Milles commented on GROOVY-9577:
-------------------------------------
There are two issues here. 1) the order is not maintained by ModuleNode and 2)
duplicated imports from the source are not represented in the model.
Groovy-Eclipse has managed this by using [a separate List to store the "raw"
imports|https://github.com/groovy/groovy-eclipse/blob/425273cc235fe8a00c207ff8cbbb955d7830ffea/base/org.codehaus.groovy30/src/org/codehaus/groovy/ast/ModuleNode.java#L59]
and [returning it from
getImports()|https://github.com/groovy/groovy-eclipse/blob/425273cc235fe8a00c207ff8cbbb955d7830ffea/base/org.codehaus.groovy30/src/org/codehaus/groovy/ast/ModuleNode.java#L137].
> ModuleNode should use LinkedHashMap for imports Map
> ---------------------------------------------------
>
> Key: GROOVY-9577
> URL: https://issues.apache.org/jira/browse/GROOVY-9577
> Project: Groovy
> Issue Type: Bug
> Components: ast builder
> Affects Versions: 3.0.4
> Reporter: Damir Murat
> Priority: Major
>
> One of last statements in AstBuilder.visitImportDeclaration() are
> {code:java}
> moduleNode.addImport(alias, classNode, annotationNodeList);
> importNode = last(moduleNode.getImports());
> {code}
> Since ModuleNode.imports is a HashMap, last() method return unpredictable
> result.
> I guess this can be fixed by changing the implementation of
> ModuleNode.imports into LinkedHashMap instead of HashMap as is currently.
> I stumbled on this while trying to use CodeNarc with the latest Groovy.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)