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
*/
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));
@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());
}