aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-01-28 10:27:37 +0100
committersimonbrandhof <simon.brandhof@gmail.com>2011-01-28 13:18:46 +0100
commit3f18345fbcaca61abf79de6597e377880099eea5 (patch)
treecc8123f87e28663164bfaa82cd5e0953ba7bba53 /sonar-plugin-api
parentec4d0e0ddcc24e2169e3ec82b04a0734979dbc65 (diff)
downloadsonarqube-3f18345fbcaca61abf79de6597e377880099eea5.tar.gz
sonarqube-3f18345fbcaca61abf79de6597e377880099eea5.zip
add helper methods to Qualifiers + do not accept null parameters
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/Qualifiers.java77
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/QualifiersTest.java8
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
@@ -27,14 +27,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();
assertThat(Qualifiers.isView(root, true), is(true));