I'm trying to build an extension for Sonar, using Scala. I need to extend the following Java interface:
public interface Decorator extends BatchExtension, CheckProject {
void decorate(Resource resource, DecoratorContext context);
}
but Resource type is actually defined like:
public abstract class Resource<PARENT extends Resource>
I know I can workaround creating a Java raw super-class. I'd like to stick to Scala-only, also know if there's a solution I'm missing, and whether there's an improvement I could suggest to SonarSource people to make on their side (on using raw types).
I've read there were issues with this, and some workarounds for some cases, but none seemed to apply here (a workaround, an apparently fixed ticket, also there's ticket 2091...)
I have no idea about an answer, but if I write
I get an error
Which seems wrong to me, because I would think the actual type bounds should be more like
Resource[_ <: Resource[_ <: Resource[... ...]]
(AnyRef
wouldn't be appropriate as an upper bound).After some trial and error and looking at the error messages, I came up with this which compiles:
I'm not sure whether it will allow you to implement what you need. I looked at Resource, and it could represent
File
which extendsResource<Directory>
or sometimes be an erased (raw?) type that just extendsResource
like forDirectory
.Edit: thinking about it some more, the
forSome
can be eliminated - this compiles too: