Refactor LanguageMetdata::extensions usages
This commit is contained in:
parent
8aaef01ed8
commit
a283615299
@ -8,6 +8,7 @@ import static net.sourceforge.pmd.util.CollectionUtil.setOf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -269,7 +270,7 @@ public abstract class LanguageModuleBase implements Language {
|
||||
|
||||
/**
|
||||
* Record the {@linkplain Language#getExtensions() extensions}
|
||||
* assigned to the language. Parameters should not start with a period
|
||||
* assigned to the language. Extensions should not start with a period
|
||||
* {@code .}.
|
||||
*
|
||||
* @param e1 First extensions
|
||||
@ -283,6 +284,25 @@ public abstract class LanguageModuleBase implements Language {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Record the {@linkplain Language#getExtensions() extensions}
|
||||
* assigned to the language. Extensions should not start with a period
|
||||
* {@code .}. At least one extension must be provided.
|
||||
*
|
||||
* @param extensions the extensions
|
||||
*
|
||||
* @throws NullPointerException If any extension is null
|
||||
* @throws IllegalArgumentException If no extensions are provided
|
||||
*/
|
||||
public LanguageMetadata extensions(Collection<String> extensions) {
|
||||
this.extensions = new ArrayList<>(new HashSet<>(extensions));
|
||||
AssertionUtil.requireContainsNoNullValue("extensions", this.extensions);
|
||||
if (this.extensions.isEmpty()) {
|
||||
throw new IllegalArgumentException("At least one extension is required.");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new version by its name.
|
||||
*
|
||||
|
@ -21,7 +21,7 @@ public final class HtmlLanguageModule extends SimpleLanguageModuleBase {
|
||||
|
||||
public HtmlLanguageModule() {
|
||||
super(LanguageMetadata.withId(TERSE_NAME).name(NAME)
|
||||
.extensions(EXTENSIONS.get(0), EXTENSIONS.subList(0, EXTENSIONS.size()).toArray(new String[0]))
|
||||
.extensions(EXTENSIONS)
|
||||
.addVersion("4")
|
||||
.addDefaultVersion("5"),
|
||||
new HtmlHandler());
|
||||
|
@ -25,7 +25,7 @@ public class EcmascriptLanguageModule extends SimpleLanguageModuleBase {
|
||||
public static final List<String> EXTENSIONS = listOf("js");
|
||||
|
||||
public EcmascriptLanguageModule() {
|
||||
super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions(EXTENSIONS.get(0))
|
||||
super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions(EXTENSIONS)
|
||||
.addVersion("3")
|
||||
.addVersion("5")
|
||||
.addVersion("6", "ES6", "ES2015")
|
||||
|
@ -23,7 +23,7 @@ public class JspLanguageModule extends SimpleLanguageModuleBase {
|
||||
|
||||
public JspLanguageModule() {
|
||||
super(LanguageMetadata.withId(TERSE_NAME).name(NAME).shortName("JSP")
|
||||
.extensions(EXTENSIONS.get(0), EXTENSIONS.toArray(new String[0]))
|
||||
.extensions(EXTENSIONS)
|
||||
.addVersion("2")
|
||||
.addDefaultVersion("3"),
|
||||
new JspHandler());
|
||||
|
@ -32,7 +32,8 @@ public class KotlinLanguageModule extends SimpleLanguageModuleBase {
|
||||
* Create a new instance of Kotlin Language Module.
|
||||
*/
|
||||
public KotlinLanguageModule() {
|
||||
super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions(EXTENSIONS.get(0), EXTENSIONS.toArray(new String[0]))
|
||||
super(LanguageMetadata.withId(TERSE_NAME).name(NAME)
|
||||
.extensions(EXTENSIONS)
|
||||
.addVersion("1.6")
|
||||
.addDefaultVersion("1.7"),
|
||||
new KotlinHandler());
|
||||
|
@ -19,7 +19,7 @@ public class ModelicaLanguageModule extends SimpleLanguageModuleBase {
|
||||
|
||||
public ModelicaLanguageModule() {
|
||||
super(LanguageMetadata.withId(TERSE_NAME).name(NAME)
|
||||
.extensions(EXTENSIONS.get(0))
|
||||
.extensions(EXTENSIONS)
|
||||
.addVersion("3.4")
|
||||
.addDefaultVersion("3.5"),
|
||||
new ModelicaHandler());
|
||||
|
@ -34,7 +34,7 @@ public class PLSQLLanguageModule extends SimpleLanguageModuleBase {
|
||||
super(
|
||||
LanguageMetadata.withId(TERSE_NAME)
|
||||
.name(NAME)
|
||||
.extensions(EXTENSIONS.get(0), EXTENSIONS.toArray(new String[0]))
|
||||
.extensions(EXTENSIONS)
|
||||
.addVersion("11g")
|
||||
.addVersion("12c_Release_1", "12.1")
|
||||
.addVersion("12c_Release_2", "12.2")
|
||||
|
@ -35,7 +35,8 @@ public class ScalaLanguageModule extends SimpleLanguageModuleBase {
|
||||
* Create a new instance of Scala Language Module.
|
||||
*/
|
||||
public ScalaLanguageModule() {
|
||||
super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions(EXTENSIONS.get(0))
|
||||
super(LanguageMetadata.withId(TERSE_NAME).name(NAME)
|
||||
.extensions(EXTENSIONS)
|
||||
.addVersion("2.10")
|
||||
.addVersion("2.11")
|
||||
.addVersion("2.12")
|
||||
|
@ -29,7 +29,7 @@ public class SwiftLanguageModule extends SimpleLanguageModuleBase {
|
||||
*/
|
||||
public SwiftLanguageModule() {
|
||||
super(LanguageMetadata.withId(TERSE_NAME).name(NAME)
|
||||
.extensions(EXTENSIONS.get(0))
|
||||
.extensions(EXTENSIONS)
|
||||
.addVersion("4.2")
|
||||
.addVersion("5.0")
|
||||
.addVersion("5.1")
|
||||
|
@ -31,9 +31,10 @@ public class VfLanguageModule extends SimpleLanguageModuleBase {
|
||||
}
|
||||
|
||||
private static LanguageMetadata createMetdata() {
|
||||
LanguageMetadata languageMetadata = LanguageMetadata.withId(TERSE_NAME).name(NAME)
|
||||
.extensions(EXTENSIONS.get(0), EXTENSIONS.toArray(new String[0]))
|
||||
.dependsOnLanguage(ApexLanguageModule.TERSE_NAME);
|
||||
LanguageMetadata languageMetadata =
|
||||
LanguageMetadata.withId(TERSE_NAME).name(NAME)
|
||||
.extensions(EXTENSIONS)
|
||||
.dependsOnLanguage(ApexLanguageModule.TERSE_NAME);
|
||||
// use the same versions as in Apex
|
||||
int lastVersion = ApexLanguageModule.VERSIONS.size() - 1;
|
||||
ApexLanguageModule.VERSIONS.subList(0, lastVersion).forEach(languageMetadata::addVersion);
|
||||
|
@ -23,7 +23,7 @@ public class XmlLanguageModule extends SimpleLanguageModuleBase {
|
||||
|
||||
public XmlLanguageModule() {
|
||||
super(LanguageMetadata.withId(TERSE_NAME).name(NAME)
|
||||
.extensions(EXTENSIONS.get(0))
|
||||
.extensions(EXTENSIONS)
|
||||
.addVersion("1.0")
|
||||
.addDefaultVersion("1.1"),
|
||||
new XmlHandler());
|
||||
|
Loading…
x
Reference in New Issue
Block a user