<commit_before>package com.vaadin.components.gwt.polymer.client;

import java.util.HashSet;
import java.util.Set;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;

public abstract class Polymer {

    private static Set<String> urlImported = new HashSet<>();

    /**
     * Ensures that the tagName has been registered, otherwise injects
     * the appropriate &lt;import&gt; tag in the document header.
     *
     * It loads the component from following the convention:
     * bower_components/tagName/tagName.html
     */
    public static void ensureTag(String tagName) {
        ensureHTMLImport(tagName + "/" + tagName + ".html");
    }

    /**
     * Ensures that the tagName has been registered, otherwise injects
     * the appropriate &lt;import&gt; tag in the document header.
     *
     * @param tagName
     * @param url component path relative to bower_components folder
     */
    public static void ensureTag(String tagName, String src) {
        ensureHTMLImport(src);
    }

    /**
     * Inserts the appropriate &lt;import&gt; of a component given by url.
     *
     * Note that bower_components will be prefixed to the url always.
     *
     * @param url component path relative to bower_components folder
     */
    public static void ensureHTMLImport(String url) {
        String href = "bower_components/" + url;
        if (!urlImported.contains(href)) {
            Element link = Document.get().createLinkElement();
            link.setAttribute("rel", "import");
            link.setAttribute("href", GWT.getModuleBaseForStaticFiles() + href);
            Document.get().getHead().appendChild(link);
            urlImported.add(href);
        }
    }

    /**
     * Returns a new instance of the Element. It loads the webcomponent
     * from the bower_components/src url if it was not loaded yet.
     */
    public static <T> T createElement(String tagName, String src) {
        ensureTag(tagName);
        return (T)Document.get().createElement(tagName);
    }

    /**
     * Returns a new instance of the Element. It loads the webcomponent
     * from the bower_components/tagName/tagName.html url if not loaded yet.
     */
    public static <T> T createElement(String tagName) {
        ensureTag(tagName);
        return (T)Document.get().createElement(tagName);
    }

    /**
     * Returns the JsInterop instance of Document
     */
    public static com.vaadin.components.gwt.polymer.client.webapi.Document getDocument() {
        return (com.vaadin.components.gwt.polymer.client.webapi.Document)Document.get();
    }
}<commit_msg>use src based on tagname when src is null<commit_after>package com.vaadin.components.gwt.polymer.client;

import java.util.HashSet;
import java.util.Set;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;

public abstract class Polymer {

    private static Set<String> urlImported = new HashSet<>();

    /**
     * Ensures that the tagName has been registered, otherwise injects
     * the appropriate &lt;import&gt; tag in the document header.
     *
     * It loads the component from following the convention:
     * bower_components/tagName/tagName.html
     */
    public static void ensureTag(String tagName) {
        ensureTag(tagName, null);
    }

    /**
     * Ensures that the tagName has been registered, otherwise injects
     * the appropriate &lt;import&gt; tag in the document header.
     *
     * @param tagName
     * @param url component path relative to bower_components folder.
     *        if null it imports bower_components/tagName/tagName.html
     */
    public static void ensureTag(String tagName, String src) {
        ensureHTMLImport(src == null ? tagName + "/" + tagName + ".html" : src);
    }

    /**
     * Inserts the appropriate &lt;import&gt; of a component given by url.
     *
     * Note that bower_components will be prefixed to the url always.
     *
     * @param url component path relative to bower_components folder
     */
    public static void ensureHTMLImport(String url) {
        String href = "bower_components/" + url;
        if (!urlImported.contains(href)) {
            Element link = Document.get().createLinkElement();
            link.setAttribute("rel", "import");
            link.setAttribute("href", GWT.getModuleBaseForStaticFiles() + href);
            Document.get().getHead().appendChild(link);
            urlImported.add(href);
        }
    }

    /**
     * Returns a new instance of the Element. It loads the webcomponent
     * from the bower_components/src url if it was not loaded yet.
     */
    public static <T> T createElement(String tagName, String src) {
        ensureTag(tagName, src);
        return (T)Document.get().createElement(tagName);
    }

    /**
     * Returns a new instance of the Element. It loads the webcomponent
     * from the bower_components/tagName/tagName.html url if not loaded yet.
     */
    public static <T> T createElement(String tagName) {
        return createElement(tagName, null);
    }

    /**
     * Returns the JsInterop instance of Document
     */
    public static com.vaadin.components.gwt.polymer.client.webapi.Document getDocument() {
        return (com.vaadin.components.gwt.polymer.client.webapi.Document)Document.get();
    }
}
{'fraction_non_alphanumeric': 0.10092592592592593, 'fraction_numerical': 0.0, 'mean_word_length': 2.742896742896743, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1560954', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1505, 'n_words': 442}