import a.b.c.AnInterface;
public class AClass implements AnInterface {
// something to check here that is not important in the context of this post
}
public class MyCheck extends IssuableSubscriptionVisitor { //... @Override public void visitNode(final Tree tree) { //... if (tree.is(Kind.CLASS) { ClassTree classTree = (ClassTree) tree; boolean implementsSelectedInterface = false; for (TypeTree superInterface : classTree.superInterfaces()) { // Alternative 1. the following line requires that the interface code is on the classpath, if it isn't the type is unknown if (superInterface.symbolType().isSubtypeOf("a.b.c.AnInterface")) { implementsSelectedInterface = true; } // Alternative 2. the toString() method returns the simple name of the interface, without the package... and then I don't know how to retrieve the package name if ("AnInterface".equals(superInterface.toString())) { implementsSelectedInterface = true; } } if (importsSelectedInterface && implementsSelectedInterface) { // Alternative 3. works but is ugly : also visit the import node //... } } } //...}ClassTree classTree = (ClassTree) tree;if (classTree.symbol().type().isSubtypeOf("a.b.c.AnInterface")) { // do somthing}class MyClass1 implements AnInterface {}
class MyClass2 implements a.b.c.AnInterface {}
class MyClass3 implements AnInterface, Closeable {}
class MyClass4 extends MyClass1 {}--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/7ea5dfd5-fea6-4e56-8b5f-a6109ac9804c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.