From 31bc5dcc63b6e84d35a750ded5a6603f67435683 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 21 Aug 2016 22:21:52 +0200 Subject: [PATCH] sonar JavaScript plugin: use always interfaces. 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 | 1 + .../checks/AngularJSRootOnEventSubscriptionCheck.java | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Sonar/Plugins/sonar-custom-javascript-plugin/pom.xml b/Sonar/Plugins/sonar-custom-javascript-plugin/pom.xml index 9dabcfe..9f3b843 100644 --- a/Sonar/Plugins/sonar-custom-javascript-plugin/pom.xml +++ b/Sonar/Plugins/sonar-custom-javascript-plugin/pom.xml @@ -33,6 +33,7 @@ org.sonarsource.javascript sonar-javascript-plugin + sonar-plugin ${javascript.plugin.version} diff --git a/Sonar/Plugins/sonar-custom-javascript-plugin/src/main/java/de/example/custom/javascript/checks/AngularJSRootOnEventSubscriptionCheck.java b/Sonar/Plugins/sonar-custom-javascript-plugin/src/main/java/de/example/custom/javascript/checks/AngularJSRootOnEventSubscriptionCheck.java index daf5f76..b441d2c 100644 --- a/Sonar/Plugins/sonar-custom-javascript-plugin/src/main/java/de/example/custom/javascript/checks/AngularJSRootOnEventSubscriptionCheck.java +++ b/Sonar/Plugins/sonar-custom-javascript-plugin/src/main/java/de/example/custom/javascript/checks/AngularJSRootOnEventSubscriptionCheck.java @@ -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."); } } } -- 2.1.4