import bblfsh_sonar_checks.utils as utils import bblfsh def check(uast): findings = [] cl_nodes = bblfsh.filter(uast, "//*[@roleDeclaration and @roleType]//SimpleType" "[@internalRole='superInterfaceTypes']//Identifier[@Name='Cloneable']/" "parent::*/parent::TypeDeclaration") for cl in cl_nodes: jc = utils.JClass(cl) for method in jc.methods: if method.name == 'clone' and 'public' in method.modifiers and\ method.return_ and method.return_.type_name == 'Object' and\ not method.arguments: break else: findings.append({"msg": "Class {} implementing Cloneable should have a clone() method", "pos": cl.start_position}) return findings if __name__ == '__main__': utils.run_default_fixture(__file__, check)
import bblfsh_sonar_checks.utils as utils import bblfsh def check(uast): findings = [] calls = bblfsh.filter( uast, "//MethodInvocation/" "Identifier[@roleCall and @roleReceiver and @Name='Arrays']/parent::MethodInvocation/" "Identifier[@roleCall and @roleCallee and @Name='asList']/parent::MethodInvocation" ) for c in calls: child_args = bblfsh.filter(c, "//*[@roleArgument and @roleLiteral]") if len(list(child_args)): findings.append({ "msg": "Don't use slow Arrays.asList with primitives", "pos": c.start_position }) return findings if __name__ == '__main__': utils.run_default_fixture(__file__, check)
def test_1000_own_fixtures(self): for lang, checks in self.check_funcs.items(): for check_path, check_func in checks.items(): res = run_default_fixture(check_path, check_func, silent=True) self.assertGreater(len(res), 0)