How to find super interface?

java

(N.N.) #1

I am writing custom rule on java.
For example we have such situation:

public interface DocV extends VersionOf<Doc> {
<...methods...>
}

The task is: to check DocV that it has all methods, that Doc has. Doc is public abstract class.

My current problem: I can’t get even Doc from DocV. I tried ((ParameterizedTypeTree) clazz.superInterfaces().get(0)) – it returns VersionOf. In debug I see that it has in children Doc, but there is no api to call children… even so, this Doc is InternalSyntaxToken, without its methods…

I also tried to find in context.getSemanticModel() – the same.


(Nicolas Peru) #2

Hi,

This information has not (yet?) been made available publicly in semantic API : https://jira.sonarsource.com/browse/SONARJAVA-1871

So you wont’ be able to check this with a custom rule as of today.

However I am puzzled by such a rule, shouldn’t you consider having a common interface between your two types to enforce this at compiler level ?


(N.N.) #3

Hi @Nicolas_Peru!
Thanks for info. It’s a pity.
What about class loaders? How can I load class by myself using sonar api?
In my situation Doc and DocV are located in the same package.

It is a long story and restricted by NDA, but some words: this configuration used for versioning DTOs.