sonar JavaScript plugin: use always interfaces.
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 21 Aug 2016 20:21:52 +0000 (22:21 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 21 Aug 2016 20:21:52 +0000 (22:21 +0200)
Otherwise problems with cast because implementations are loaded in different class loaders and my
plugin is not able to see the class loader where the instance was created :/

Sonar/Plugins/sonar-custom-javascript-plugin/pom.xml
Sonar/Plugins/sonar-custom-javascript-plugin/src/main/java/de/example/custom/javascript/checks/AngularJSRootOnEventSubscriptionCheck.java

index 9dabcfe..9f3b843 100644 (file)
@@ -33,6 +33,7 @@
   <dependency>
       <groupId>org.sonarsource.javascript</groupId>
       <artifactId>sonar-javascript-plugin</artifactId>
+      <type>sonar-plugin</type>
       <version>${javascript.plugin.version}</version>
   </dependency>
       <dependency>
index daf5f76..b441d2c 100644 (file)
@@ -3,11 +3,11 @@ package de.example.custom.javascript.checks;
 import java.util.List;
 
 import org.sonar.check.Rule;
-import org.sonar.javascript.tree.impl.expression.CallExpressionTreeImpl;
-import org.sonar.javascript.tree.impl.expression.DotMemberExpressionTreeImpl;
-import org.sonar.javascript.tree.impl.expression.IdentifierTreeImpl;
 import org.sonar.plugins.javascript.api.tree.Tree;
 import org.sonar.plugins.javascript.api.tree.Tree.Kind;
+import org.sonar.plugins.javascript.api.tree.expression.CallExpressionTree;
+import org.sonar.plugins.javascript.api.tree.expression.DotMemberExpressionTree;
+import org.sonar.plugins.javascript.api.tree.expression.IdentifierTree;
 import org.sonar.plugins.javascript.api.visitors.SubscriptionVisitorCheck;
 
 import com.google.common.collect.ImmutableList;
@@ -22,15 +22,15 @@ public class AngularJSRootOnEventSubscriptionCheck extends SubscriptionVisitorCh
 
        @Override
        public void visitNode(Tree tree) {
-               CallExpressionTreeImpl callExpression = (CallExpressionTreeImpl) tree;
-               if (callExpression.callee() instanceof DotMemberExpressionTreeImpl) {
-                       DotMemberExpressionTreeImpl callee = (DotMemberExpressionTreeImpl) callExpression.callee();
-                       if (callee.object() instanceof IdentifierTreeImpl) {
-                               IdentifierTreeImpl object = (IdentifierTreeImpl) callee.object();
+               CallExpressionTree callExpression = (CallExpressionTree) tree;
+               if (callExpression.callee() instanceof DotMemberExpressionTree) {
+                       DotMemberExpressionTree callee = (DotMemberExpressionTree) callExpression.callee();
+                       if (callee.object() instanceof IdentifierTree) {
+                               IdentifierTree object = (IdentifierTree) callee.object();
                                String objectName = object.name();
                                String calleeName = callee.property().name();
                                if ("$rootScope".equals(objectName) && "$on".equals(calleeName)) {
-                                       addIssue(callExpression.getFirstToken(), "Do not use $rootScope.$on because it leaks the Controller instance.");
+                                       addIssue(tree, "Do not use $rootScope.$on because it leaks the Controller instance.");
                                }
                        }
                }