diff options
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java | 13 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/resources/FileTest.java | 10 |
2 files changed, 21 insertions, 2 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java index a07c226a73b..4f655cf5b51 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java @@ -194,12 +194,23 @@ public abstract class Resource implements Serializable { public abstract String getDescription(); /** - * @return the language of the resource. Only {@link File}s have a non null value. + * @return the language of the resource. Only {@link File}s may have a non null value. + * @deprecated since 5.1 use {@link #language()} */ + @Deprecated @CheckForNull public abstract Language getLanguage(); /** + * @return the language of the resource. Only {@link File}s may have a non null value. + */ + @CheckForNull + public String language() { + Language l = getLanguage(); + return l != null ? l.getKey() : null; + } + + /** * @return the scope */ public abstract String getScope(); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/FileTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/FileTest.java index b73ddc3fd3c..dbd04f48202 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/FileTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/FileTest.java @@ -89,6 +89,7 @@ public class FileTest { File file = new File("toto.sql"); assertThat(file.getDeprecatedKey(), is("toto.sql")); assertThat(file.getName(), is("toto.sql")); + assertThat(file.language()).isNull(); assertThat(file.getParent().getDeprecatedKey(), is(Directory.ROOT)); assertThat(file.getScope(), is(Resource.SCOPE_ENTITY)); assertThat(file.getQualifier(), is(Resource.QUALIFIER_FILE)); @@ -106,12 +107,19 @@ public class FileTest { @Test public void setLanguage() { - Language lang = mock(Language.class); + Language lang = new AbstractLanguage("java", "Java") { + + @Override + public String[] getFileSuffixes() { + return null; + } + }; File file = new File(lang, "Foo.java"); assertThat(file.getLanguage(), is(lang)); file = new File(lang, "org/sonar", "Foo.java"); assertThat(file.getLanguage(), is(lang)); + assertThat(file.language()).isEqualTo("java"); assertThat(file.getParent().getLanguage(), nullValue()); } |