From 3f18345fbcaca61abf79de6597e377880099eea5 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Fri, 28 Jan 2011 10:27:37 +0100 Subject: [PATCH] add helper methods to Qualifiers + do not accept null parameters --- .../org/sonar/api/resources/Qualifiers.java | 77 +++++++++++++++---- .../sonar/api/resources/QualifiersTest.java | 8 -- 2 files changed, 63 insertions(+), 22 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Qualifiers.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Qualifiers.java index cc3fca65827..800c4863dbd 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Qualifiers.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Qualifiers.java @@ -72,33 +72,82 @@ public final class Qualifiers { // ugly, should be replaced by "natures" public static final String UNIT_TEST_FILE = "UTS"; + /** + * @param resource not nullable + */ public static boolean isView(final Resource resource, final boolean acceptSubViews) { - boolean isView = false; - if (resource != null) { - isView = StringUtils.equals(VIEW, resource.getQualifier()); - if (!isView && acceptSubViews) { - isView = StringUtils.equals(SUBVIEW, resource.getQualifier()); - } + boolean isView = StringUtils.equals(VIEW, resource.getQualifier()); + if (!isView && acceptSubViews) { + isView = StringUtils.equals(SUBVIEW, resource.getQualifier()); } + return isView; } + /** + * @param resource not nullable + */ public static boolean isSubview(final Resource resource) { - return resource != null && StringUtils.equals(SUBVIEW, resource.getScope()); + return StringUtils.equals(SUBVIEW, resource.getScope()); } + /** + * @param resource not nullable + */ public static boolean isProject(final Resource resource, final boolean acceptModules) { - boolean isProject = false; - if (resource != null) { - isProject = StringUtils.equals(PROJECT, resource.getQualifier()); - if (!isProject && acceptModules) { - isProject = StringUtils.equals(MODULE, resource.getQualifier()); - } + boolean isProject = StringUtils.equals(PROJECT, resource.getQualifier()); + if (!isProject && acceptModules) { + isProject = StringUtils.equals(MODULE, resource.getQualifier()); } return isProject; } + /** + * @param resource not nullable + */ public static boolean isModule(final Resource resource) { - return resource != null && StringUtils.equals(MODULE, resource.getQualifier()); + return StringUtils.equals(MODULE, resource.getQualifier()); + } + + /** + * @param resource not nullable + */ + public static boolean isDirectory(final Resource resource) { + return StringUtils.equals(DIRECTORY, resource.getQualifier()); + } + + /** + * @param resource not nullable + */ + public static boolean isPackage(final Resource resource) { + return StringUtils.equals(PACKAGE, resource.getQualifier()); + } + + /** + * @param resource not nullable + */ + public static boolean isFile(final Resource resource) { + return StringUtils.equals(FILE, resource.getQualifier()); + } + + /** + * @param resource not nullable + */ + public static boolean isClass(final Resource resource) { + return StringUtils.equals(CLASS, resource.getQualifier()); + } + + /** + * @param resource not nullable + */ + public static boolean isMethod(final Resource resource) { + return StringUtils.equals(METHOD, resource.getQualifier()); + } + + /** + * @param resource not nullable + */ + public static boolean isParagraph(final Resource resource) { + return StringUtils.equals(PARAGRAPH, resource.getQualifier()); } } \ No newline at end of file diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/QualifiersTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/QualifiersTest.java index a0a58d7f6b6..5927017cd95 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/QualifiersTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/QualifiersTest.java @@ -26,14 +26,6 @@ import static org.junit.Assert.assertThat; public class QualifiersTest { - @Test - public void testNullValues() { - assertThat(Qualifiers.isView(null, true), is(false)); - assertThat(Qualifiers.isView(null, false), is(false)); - assertThat(Qualifiers.isProject(null, true), is(false)); - assertThat(Qualifiers.isProject(null, false), is(false)); - } - @Test public void testRootView() { View root = View.createRootView(); -- 2.39.5