<commit_before>package com.github.shiraji.databindinglayout.intentions

import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiFile
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.xml.XmlAttribute
import com.intellij.psi.xml.XmlFile
import com.intellij.psi.xml.XmlTag

fun getPointingXmlAttribute(editor: Editor?, file: PsiFile?): XmlAttribute? {
    if (file !is XmlFile) return null
    val rootTag = file.rootTag ?: return null
    val rootTagName = rootTag.name
    if (rootTagName != "layout" || rootTag.getAttribute("xmlns:android") == null) return null
    val offset = editor?.caretModel?.offset ?: return null
    val psiElement = file.findElementAt(offset)
    return PsiTreeUtil.getParentOfType(psiElement, XmlAttribute::class.java)
}

fun XmlAttribute.isLayoutTag() = "layout" == PsiTreeUtil.getParentOfType(this, XmlTag::class.java)?.name

fun XmlAttribute.hasDatabindingExpression(): Boolean {
    val value = value ?: return false
    return value.startsWith("@{") && value.endsWith("}")
}<commit_msg>Add checking if the tag has 2-way databinding syntax<commit_after>package com.github.shiraji.databindinglayout.intentions

import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiFile
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.xml.XmlAttribute
import com.intellij.psi.xml.XmlFile
import com.intellij.psi.xml.XmlTag

fun getPointingXmlAttribute(editor: Editor?, file: PsiFile?): XmlAttribute? {
    if (file !is XmlFile) return null
    val rootTag = file.rootTag ?: return null
    val rootTagName = rootTag.name
    if (rootTagName != "layout" || rootTag.getAttribute("xmlns:android") == null) return null
    val offset = editor?.caretModel?.offset ?: return null
    val psiElement = file.findElementAt(offset)
    return PsiTreeUtil.getParentOfType(psiElement, XmlAttribute::class.java)
}

fun XmlAttribute.isLayoutTag() = "layout" == PsiTreeUtil.getParentOfType(this, XmlTag::class.java)?.name

fun XmlAttribute.hasDatabindingExpression(): Boolean {
    val value = value ?: return false
    return value.startsWith("@{") && value.endsWith("}")
}

fun XmlAttribute.has2WayDatabindingExpression(): Boolean {
    val value = value ?: return false
    return value.startsWith("@={") && value.endsWith("}")
}
{'fraction_non_alphanumeric': 0.1204714098646879, 'fraction_numerical': 0.0008729812309035355, 'mean_word_length': 5.161290322580645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '3756277', 'n_tokens_mistral': 738, 'n_tokens_neox': 725, 'n_words': 155}