Marcus34
Marcus34

Reputation: 1

Xtend the function createResource gives error "converting URI to URI"

I want to generate a Resource variable (which points to a file on the disk) in xtend. This variable will be used in the foreach and in the function compile.

Code:

    override doGenerate(Resource resource, ResourceSet input, IFileSystemAccess2 fsa, IGeneratorContext context) {

    allResources = input.resources.map(r|r.allContents.toIterable.filter(CmlProgram)).flatten
    
    this.fsa = fsa
    
    var BecomeRichestPath = "C:\\path\\to\\file";
    var file = new File(BecomeRichestPath).toURI()
    LOG.info("URI: " + file)
    var r = input.createResource(file) <---------- error here

    for (p : resource.allContents.toIterable.filter(CmlProgram)) {
            
        if (!p.contracts.empty) {
            fsa.generateFile("/" + resource.URI.trimFileExtension.segmentsList.last + ".sol", p.compile)
            println("Count: " + p.eAllContents().size())
        }           
    }
}

To do so I use the function createResource() listed here Despite everything when compiling I get the error:

Type mismatch: cannot convert from URI to URI during compilation.

And I cannot make a sense of it.

This is the list of import that i use:

    import org.eclipse.emf.ecore.EObject
    import org.eclipse.emf.ecore.resource.Resource
    import org.eclipse.emf.ecore.resource.ResourceSet
    import org.eclipse.xtext.EcoreUtil2
    import org.eclipse.xtext.generator.IFileSystemAccess2
    import org.eclipse.xtext.generator.IGeneratorContext

Upvotes: 0

Views: 82

Answers (1)

Marcus34
Marcus34

Reputation: 1

Found the problem, apparently there are 2 types of URI:

  1. java.net.URI
  2. org.eclipse.emf.common.util.URI

The function createResource() need this type of URI to avoid the conversion error.

The code to work needs a new import

import org.eclipse.emf.common.util.URI

And the functiuon call needs to be modified into

var r = input.createResource(URI.createURI(file.toString))

Upvotes: 0

Related Questions