Convert Groovy File representation to IFile

  • Hello,

    I was playing with your example locating system prints. It starts like this:

    def files = resources.filesMatching(".*\\.java")
    for( file in files ) {

    What I'd like to do is this:

    element = JavaCore.create(file)

    but of course, file is not of type IFile. What do you recommend? (by the way, would it be unreasonable for the concrete type of file to implement IFile? I'm new to Groovy, so if this isn't groovy-tastic, that's fine too.

    • James E. Ervin
      James E. Ervin

      If you open up the outline view in the Monkey editor and select the flat view instead of the hierarchical view, you will see that resources is of type net.sf.groovyMonkey.dom.resources.Resources.  Open up the source code ( you have added your plugins to java search right? ) by using Eclipse's open type.  Following the code you can see that resources is a Java list of net.sf.groovyMonkey.dom.resources.File instances.  Opening that type you can see that there is a method for File called getEclipseObject() that will return what you want. 

      Resources is a legacy from the original Eclipse Monkey and is implemented not in the manner that I would choose to do so.  So if you rewrite your line above as:

      def element = JavaCore.create( file.eclipseObject )

      I think you will find that it will work correctly.

      Thanks for trying Groovy Monkey, drop me a line if you will about how you are using or thinking about using Groovy Monkey.  I would love to make notes so that when I get a moment again, I can make some improvements.