The import aliasing solution proposed by Jochen is immediately usable.  There 
was a typo, which may hinder understanding.


import someType as SomeType
class someType {
    private SomeType someFunction() {
    }
}

The parser can handle lowerCase name for the class, but not for return type of 
a method — and possibly other places.  If you have a lowerCase type name, then 
for methods that use it, introduce the import as above and use the aliased 
UpperCase name.  In this example, anywhere you use "someType" as a return type, 
not just within someType itself would need this.

As for fixing the parser to handle this safely and efficiently, that is quite a 
large piece of work.


________________________________
From: Saravanan Palanichamy <chava...@gmail.com>
Sent: Sunday, June 1, 2025 1:40 AM
To: dev@groovy.apache.org <dev@groovy.apache.org>; Milles, Eric (TR Technology) 
<eric.mil...@thomsonreuters.com>
Subject: [EXT] https://issues.apache.org/jira/browse/GROOVY-11670

External Email: Use caution with links and attachments.

Hello Other Groovy Devs & Eric Miles

I thought an email will be a better way to communicate intent with this ticket 
I raised

https://issues.apache.org/jira/browse/GROOVY-11670<https://urldefense.com/v3/__https://issues.apache.org/jira/browse/GROOVY-11670__;!!GFN0sa3rsbfR8OLyAw!aqpIHoixls33OFmZABk0FaRzPo0N8c99yABbnNqOVtkBZxxjhfI7rRdev16tkisEqefzyvf3YFFgJkCz5O3vw9c$>

This is my current setup

  *   I have a bunch of java files, all of which work fine when compiled with 
JavaC
  *   Lets say one file is named aLowerCaseClassName.java and it has a function 
build() that returns a new instance of aLowerCaseClassName
  *   Lets say another file uses this class and has a method customBuild() that 
also returns a new instance of aLowerCaseClassName

I am trying to compile all these files with Groovy (to apply AST 
transformations) and I see these problems

  *   both build methods will cause a parsing error as detailed in the jira 
ticket
  *   errors go away if I just rename the class starting with a capital letter. 
But this is not an option as I cannot change the Java code, so I have to do 
something as part of the groovy compile process

Eric, you suggested in the ticket that I can use import aliasing, I want to 
understand this better

  *   I assume the lower case class name is a problem only for return types? 
Will this work for other places? (generics, parameter types, field names etc)
  *   I assume that I will have to do this import aliasing in every file where 
I use this class name
  *   I will then have to change all class type uses in that file to use the 
uppercase class name (if it's just return types, then should I just change 
that?)
  *   I also assume that this change will have to be done before the groovy 
compiler gets a hold of this file? I assume probably through a string reader 
source that I create for the file after some regex replacements maybe?

Are my assumptions right? Are there simpler ways to fix this on my side?

regards
Saravanan

Reply via email to