<commit_before>/*
 * Copyright (C) 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.co.reecedunn.intellij.plugin.xquery.ast.impl;

import com.intellij.lang.ASTFactory;
import com.intellij.psi.impl.source.tree.*;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.IFileElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import uk.co.reecedunn.intellij.plugin.xquery.lexer.XQueryTokenType;
import uk.co.reecedunn.intellij.plugin.xquery.parser.XQueryElementType;

public class XQueryASTFactory extends ASTFactory {
    @Override
    @Nullable
    public CompositeElement createComposite(final IElementType type) {
        if (type instanceof IFileElementType) {
            return new FileElement(type, null);
        } else if (type == XQueryElementType.STRING_LITERAL) {
            return new XQueryStringLiteralImpl(type);
        } else if (type == XQueryElementType.QNAME) {
            return new XQueryQNameImpl(type);
        } else if (type == XQueryElementType.COMMENT) {
            return new XQueryCommentImpl(type);
        } else if (type == XQueryElementType.DIR_COMMENT_CONSTRUCTOR) {
            return new XQueryDirCommentConstructorImpl(type);
        }

        return new CompositeElement(type);
    }

    @Override
    @Nullable
    public LeafElement createLeaf(@NotNull final IElementType type, @NotNull CharSequence text) {
        if (type == XQueryTokenType.COMMENT ||
            type == XQueryTokenType.XML_COMMENT) {
            return new PsiCommentImpl(type, text);
        } else if (type == XQueryTokenType.INTEGER_LITERAL ||
                   type == XQueryTokenType.DECIMAL_LITERAL ||
                   type == XQueryTokenType.DOUBLE_LITERAL) {
            return new XQueryNumericLiteralImpl(type, text);
        } else if (type == XQueryTokenType.PREDEFINED_ENTITY_REFERENCE) {
            return new XQueryPredefinedEntityRefImpl(type, text);
        } else if (type == XQueryTokenType.CHARACTER_REFERENCE) {
            return new XQueryCharRefImpl(type, text);
        } else if (type == XQueryTokenType.STRING_LITERAL_ESCAPED_CHARACTER) {
            return new XQueryEscapeCharacterImpl(type, text);
        } else if (type == XQueryTokenType.NCNAME) {
            return new XQueryNCNameImpl(type, text);
        } else if (type == XQueryTokenType.QNAME_PREFIX) {
            return new XQueryQNamePrefixImpl(type, text);
        }

        return new LeafPsiElement(type, text);
    }
}
<commit_msg>Don't create a FileElement object in XQueryASTFactory.createComposite as this logic is not called.<commit_after>/*
 * Copyright (C) 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.co.reecedunn.intellij.plugin.xquery.ast.impl;

import com.intellij.lang.ASTFactory;
import com.intellij.psi.impl.source.tree.*;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import uk.co.reecedunn.intellij.plugin.xquery.lexer.XQueryTokenType;
import uk.co.reecedunn.intellij.plugin.xquery.parser.XQueryElementType;

public class XQueryASTFactory extends ASTFactory {
    @Override
    @Nullable
    public CompositeElement createComposite(final IElementType type) {
        if (type == XQueryElementType.STRING_LITERAL) {
            return new XQueryStringLiteralImpl(type);
        } else if (type == XQueryElementType.QNAME) {
            return new XQueryQNameImpl(type);
        } else if (type == XQueryElementType.COMMENT) {
            return new XQueryCommentImpl(type);
        } else if (type == XQueryElementType.DIR_COMMENT_CONSTRUCTOR) {
            return new XQueryDirCommentConstructorImpl(type);
        }

        return new CompositeElement(type);
    }

    @Override
    @Nullable
    public LeafElement createLeaf(@NotNull final IElementType type, @NotNull CharSequence text) {
        if (type == XQueryTokenType.COMMENT ||
            type == XQueryTokenType.XML_COMMENT) {
            return new PsiCommentImpl(type, text);
        } else if (type == XQueryTokenType.INTEGER_LITERAL ||
                   type == XQueryTokenType.DECIMAL_LITERAL ||
                   type == XQueryTokenType.DOUBLE_LITERAL) {
            return new XQueryNumericLiteralImpl(type, text);
        } else if (type == XQueryTokenType.PREDEFINED_ENTITY_REFERENCE) {
            return new XQueryPredefinedEntityRefImpl(type, text);
        } else if (type == XQueryTokenType.CHARACTER_REFERENCE) {
            return new XQueryCharRefImpl(type, text);
        } else if (type == XQueryTokenType.STRING_LITERAL_ESCAPED_CHARACTER) {
            return new XQueryEscapeCharacterImpl(type, text);
        } else if (type == XQueryTokenType.NCNAME) {
            return new XQueryNCNameImpl(type, text);
        } else if (type == XQueryTokenType.QNAME_PREFIX) {
            return new XQueryQNamePrefixImpl(type, text);
        }

        return new LeafPsiElement(type, text);
    }
}

{'fraction_non_alphanumeric': 0.08661025385764062, 'fraction_numerical': 0.002654720424755268, 'mean_word_length': 3.168741355463347, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3440389', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1705, 'n_words': 457}