GitHub PullRequestReviewCommentEvent at 2014-02-21 04:17:40
Repository: jcabi-github
Actor: yegor256
Payload: {"comment":{"url":"https://api.github.com/repos/jcabi/jcabi-github/pulls/comments/9935951","id":9935951,"diff_hunk":"@@ -0,0 +1,108 @@\n+/**\n+ * Copyright (c) 2013-2014, JCabi.com\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met: 1) Redistributions of source code must retain the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer. 2) Redistributions in binary form must reproduce the above\n+ * copyright notice, this list of conditions and the following\n+ * disclaimer in the documentation and/or other materials provided\n+ * with the distribution. 3) Neither the name of the jcabi.com nor\n+ * the names of its contributors may be used to endorse or promote\n+ * products derived from this software without specific prior written\n+ * permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT\n+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL\n+ * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n+ * OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+package com.jcabi.github;\n+\n+import com.google.common.base.Predicate;\n+import com.google.common.collect.Iterables;\n+import java.util.LinkedList;\n+import java.util.List;\n+import java.util.Set;\n+import org.junit.rules.TestRule;\n+import org.junit.runner.Description;\n+import org.junit.runners.model.Statement;\n+import org.reflections.Reflections;\n+import org.reflections.scanners.ResourcesScanner;\n+import org.reflections.scanners.SubTypesScanner;\n+import org.reflections.util.ClasspathHelper;\n+import org.reflections.util.ConfigurationBuilder;\n+import org.reflections.util.FilterBuilder;\n+\n+/**\n+ * Utility class which provides convenient methods for annotations check etc.\n+ * @author Paul Polishchuk (ppol@ua.fm)\n+ * @version $Id$\n+ * @checkstyle ClassDataAbstractionCouplingCheck (500 lines)\n+ */\n+public final class ClasspathRule implements TestRule {\n+\n+    /**\n+     * Provides all classes in package 'com.jcabi.github'.\n+     * @return Classes\n+     */\n+    public Iterable<Class<?>> allTypes() {\n+        final List<ClassLoader> classloaders = new LinkedList<ClassLoader>();\n+        classloaders.add(ClasspathHelper.contextClassLoader());\n+        classloaders.add(ClasspathHelper.staticClassLoader());\n+        final Set<Class<?>> all = new Reflections(\n+            new ConfigurationBuilder()\n+                .setScanners(new SubTypesScanner(false), new ResourcesScanner())\n+                .setUrls(\n+                    ClasspathHelper.forClassLoader(\n+                        classloaders.toArray(","path":"src/test/java/com/jcabi/github/ClasspathRule.java","position":68,"original_position":68,"commit_id":"5c1c854ada1740f3973b35e66198f9b4eedaffa9","original_commit_id":"5c1c854ada1740f3973b35e66198f9b4eedaffa9","user":{"login":"yegor256","id":526301,"avatar_url":"https://gravatar.com/avatar/70942ffdd8084b5a51e17e3c0996d53c?d=https%3A%2F%2Fidenticons.github.com%2F6bf5588e99f203473873966318476660.png&r=x","gravatar_id":"70942ffdd8084b5a51e17e3c0996d53c","url":"https://api.github.com/users/yegor256","html_url":"https://github.com/yegor256","followers_url":"https://api.github.com/users/yegor256/followers","following_url":"https://api.github.com/users/yegor256/following{/other_user}","gists_url":"https://api.github.com/users/yegor256/gists{/gist_id}","starred_url":"https://api.github.com/users/yegor256/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yegor256/subscriptions","organizations_url":"https://api.github.com/users/yegor256/orgs","repos_url":"https://api.github.com/users/yegor256/repos","events_url":"https://api.github.com/users/yegor256/events{/privacy}","received_events_url":"https://api.github.com/users/yegor256/received_events","type":"User","site_admin":false},"body":"why not use a list of classloaders right here? you're writing more lines that needed :) look:\r\n\r\n```java\r\nreturn Iterables.filter(\r\n    new Reflections(\r\n        new ConfigurationBuilder()\r\n            .setScanners(new SubTypesScanner(false), new ResourcesScanner())\r\n            .setUrls(\r\n                ClasspathHelper.forClassLoader(\r\n                    Arrays.asList(\r\n                        ClasspathHelper.contextClassLoader(),\r\n                        ClasspathHelper.staticClassLoader()\r\n                    )\r\n                )\r\n            ).filterInputsBy(\r\n                new FilterBuilder().include(\r\n                    FilterBuilder.prefix(\"com.jcabi.github\")\r\n                )\r\n            )\r\n    ).getSubTypesOf(Object.class),\r\n    new Predicate<Class<?>>() {\r\n        @Override\r\n        public boolean apply(final Class<?> input) {\r\n            final String name = input.getName();\r\n            // @checkstyle BooleanExpressionComplexityCheck (10 lines)\r\n            return !name.endsWith(\"Test\")\r\n                && !name.endsWith(\"ITCase\")\r\n                && !name.endsWith(\"ClasspathRule\")\r\n                && (input.getEnclosingClass() == null\r\n                || name.endsWith(\"Smart\")));\r\n        }\r\n    }\r\n);\r\n```\r\n\r\nisn't it more readable?","created_at":"2014-02-21T04:17:40Z","updated_at":"2014-02-21T04:17:40Z","html_url":"https://github.com/jcabi/jcabi-github/pull/543#discussion_r9935951","pull_request_url":"https://api.github.com/repos/jcabi/jcabi-github/pulls/543","_links":{"self":{"href":"https://api.github.com/repos/jcabi/jcabi-github/pulls/comments/9935951"},"html":{"href":"https://github.com/jcabi/jcabi-github/pull/543#discussion_r9935951"},"pull_request":{"href":"https://api.github.com/repos/jcabi/jcabi-github/pulls/543"}}}}