All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.sdorra.spotter.language.hbs Maven / Gradle / Ivy

There is a newer version: 3.0.1
Show newest version
/**
* The MIT License
*
* Copyright 2017 Sebastian Sdorra
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package {{package}};

import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.HashMap;
import java.util.Optional;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;

import javax.annotation.Generated;

/**
 * Enum of all known languages of the linguist project.
 *
 * Generated from {{ url }}.
 */
@Generated(
  value = "generated by spotter-maven-plugin",
  comments = "generated from githubs linguist languages.yml version {{ version }}",
  date = "{{ date }}"
)
public enum Language {

    {{#each languages}}
    {{#ek this.key}}{{/ek}}(
        "{{this.key}}",
        "{{this.value.type}}",
        "{{this.value.color}}",
        new String[]{ {{#each this.value.aliases}}"{{this}}"{{^@last}}, {{/@last}}{{/each}} },
        new String[]{ {{#each this.value.extensions}}"{{this}}"{{^@last}}, {{/@last}}{{/each}} },
        new String[]{ {{#each this.value.filenames}}"{{this}}"{{^@last}}, {{/@last}}{{/each}} },
        new String[]{ {{#each this.value.interpreters}}"{{this}}"{{^@last}}, {{/@last}}{{/each}} },
        {{#mode this.value.aceMode}}{{/mode}},
        {{#mode this.value.codemirrorMode}}{{/mode}}
    ){{^@last}}, {{/@last}}{{#@last}};{{/@last}}{{/each}}

    public static final String VERSION = "{{ version }}";

    private static final LanguageMap BY_FILENAME = new LanguageMap();
    private static final LanguageMap BY_EXTENSION = new LanguageMap();
    private static final LanguageMap BY_ALIAS = new LanguageMap();
    private static final LanguageMap BY_INTERPRETER = new LanguageMap();

    static {
        for (Language language : values()) {
            for ( String extension : language.extensions ) {
                BY_EXTENSION.put(extension, language);
            }
            for ( String filename : language.filenames ) {
                BY_FILENAME.put(filename, language);
            }

            BY_ALIAS.put(language.name.toLowerCase(Locale.ENGLISH), language);
            for ( String alias : language.aliases ) {
                BY_ALIAS.put(alias, language);
            }

            for ( String interpreter : language.interpreters ) {
                BY_INTERPRETER.put(interpreter, language);
            }
        }
    }

    public static List getByFilename(String filename) {
        return BY_FILENAME.get(filename);
    }

    public static List getByExtension(String extension) {
        return BY_EXTENSION.get(extension);
    }

    public static List getByAlias(String alias) {
        return BY_ALIAS.get(alias);
    }

    public static List getByInterpreter(String interpreter) {
        return BY_INTERPRETER.get(interpreter);
    }

    private String name;
    private String type;
    private String color;
    private String[] aliases;
    private String[] extensions;
    private String[] filenames;
    private String[] interpreters;
    private String aceMode;
    private String codemirrorMode;

    private Language(
        String name,
        String type,
        String color,
        String[] aliases,
        String[] extensions,
        String[] filenames,
        String[] interpreters,
        String aceMode,
        String codemirrorMode
    ){
        this.name = name;
        this.type = type;
        this.color = color;
        this.aliases = aliases;
        this.extensions = extensions;
        this.filenames = filenames;
        this.interpreters = interpreters;
        this.aceMode = aceMode;
        this.codemirrorMode = codemirrorMode;
    }

    public String getName() {
        return name;
    }

    public String getType() {
        return type;
    }

    public String getColor() {
        return color;
    }

    public String[] getExtensions() {
        return Arrays.copyOf(extensions, extensions.length);
    }

    public String[] getFilenames() {
        return Arrays.copyOf(filenames, filenames.length);
    }

    public String[] getAliases() {
        return Arrays.copyOf(aliases, aliases.length);
    }

    public String[] getInterpreters() {
        return Arrays.copyOf(interpreters, interpreters.length);
    }

    public Optional getAceMode() {
        return Optional.ofNullable(aceMode);
    }

    public Optional getCodemirrorMode() {
        return Optional.ofNullable(codemirrorMode);
    }

    private static class LanguageMap {

        private final Map> map = new HashMap<>();

        public List get(String key) {
            List values = map.get(key);
            if (values != null) {
                return Collections.unmodifiableList(values);
            }
            return Collections.emptyList();
        }

        public void put(String key, Language lang) {
            List values = map.get(key);
            if (values == null) {
                values = new ArrayList<>();
                map.put(key, values);
            }
            values.add(lang);
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy