<commit_before>package org.intellij.ibatis.dom.converters.abator;

import com.intellij.codeInsight.lookup.LookupValueFactory;
import com.intellij.javaee.dataSource.DatabaseTableData;
import com.intellij.javaee.dataSource.DatabaseTableFieldData;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.xml.XmlAttributeValue;
import com.intellij.util.xml.ConvertContext;
import com.intellij.util.xml.Converter;
import com.intellij.util.xml.CustomReferenceConverter;
import com.intellij.util.xml.GenericDomValue;
import org.intellij.ibatis.dom.abator.Table;
import org.intellij.ibatis.provider.XmlAttributeValuePsiReference;
import org.intellij.ibatis.util.IbatisConstants;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

/**
 * table column converter
 */
public class TableColumnConverter extends Converter<DatabaseTableFieldData> implements CustomReferenceConverter<DatabaseTableFieldData> {
    public DatabaseTableFieldData fromString(@Nullable @NonNls String s, ConvertContext convertContext) {
        Table tableElement = convertContext.getInvocationElement().getParentOfType(Table.class, false);
        if (tableElement != null) {
            DatabaseTableData databaseTable = tableElement.getTableName().getValue();
            if (databaseTable != null) {
                return databaseTable.findColumnByName(s);
            }
        }
        return null;
    }

    public String toString(@Nullable DatabaseTableFieldData databaseTableFieldData, ConvertContext convertContext) {
        if (databaseTableFieldData != null)
            return databaseTableFieldData.getName();
        return null;
    }

    @NotNull
    public PsiReference[] createReferences(GenericDomValue<DatabaseTableFieldData> genericDomValue, final PsiElement psiElement, ConvertContext convertContext) {
        final Table tableElement = convertContext.getInvocationElement().getParentOfType(Table.class, false);
        if (tableElement != null) {
            final DatabaseTableData databaseTable = tableElement.getTableName().getValue();
            if (databaseTable != null) {
                return new PsiReference[]{new XmlAttributeValuePsiReference((XmlAttributeValue) psiElement) {
                    public Object[] getVariants() {
                        List<Object> variants = new ArrayList<Object>();
                        for (DatabaseTableFieldData field : databaseTable.getFields()) {
                            if (field.isPrimary()) {       //pk<commit_msg>fix api error<commit_after>package org.intellij.ibatis.dom.converters.abator;

import com.intellij.codeInsight.lookup.LookupValueFactory;
import com.intellij.javaee.dataSource.DatabaseTableData;
import com.intellij.javaee.dataSource.DatabaseTableFieldData;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.xml.XmlAttributeValue;
import com.intellij.util.xml.ConvertContext;
import com.intellij.util.xml.Converter;
import com.intellij.util.xml.CustomReferenceConverter;
import com.intellij.util.xml.GenericDomValue;
import org.intellij.ibatis.dom.abator.Table;
import org.intellij.ibatis.provider.XmlAttributeValuePsiReference;
import org.intellij.ibatis.util.IbatisConstants;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

/**
 * table column converter
 */
public class TableColumnConverter extends Converter<DatabaseTableFieldData> implements CustomReferenceConverter<DatabaseTableFieldData> {
    public DatabaseTableFieldData fromString(@Nullable @NonNls String s, ConvertContext convertContext) {
        Table tableElement = convertContext.getInvocationElement().getParentOfType(Table.class, false);
        if (tableElement != null) {
            DatabaseTableData databaseTable = tableElement.getTableName().getValue();
            if (databaseTable != null) {
                return databaseTable.findColumnByName(s);
            }
        }
        return null;
    }

    public String toString(@Nullable DatabaseTableFieldData databaseTableFieldData, ConvertContext convertContext) {
        if (databaseTableFieldData != null)
            return databaseTableFieldData.getName();
        return null;
    }

    @NotNull
    public PsiReference[] createReferences(GenericDomValue<DatabaseTableFieldData> genericDomValue, final PsiElement psiElement, ConvertContext convertContext) {
        final Table tableElement = convertContext.getInvocationElement().getParentOfType(Table.class, false);
        if (tableElement != null) {
            final DatabaseTableData databaseTable = tableElement.getTableName().getValue();
            if (databaseTable != null) {
                return new PsiReference[]{new XmlAttributeValuePsiReference((XmlAttributeValue) psiElement) {
                    public Object[] getVariants() {
                        List<Object> variants = new ArrayList<Object>();
                        for (DatabaseTableFieldData field : databaseTable.getColumns()) {
                            if (field.isPrimary()) {       //pk
{'fraction_non_alphanumeric': 0.08817407757805108, 'fraction_numerical': 0.0, 'mean_word_length': 3.8098271155595995, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '5218923', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1364, 'n_words': 263}