Search in sources :

Example 1 with PreferenceElement

use of org.jetbrains.android.dom.xml.PreferenceElement in project android by JetBrains.

the class AndroidCompletionContributor method addAndroidPrefixElement.

private static void addAndroidPrefixElement(PsiElement position, PsiElement parent, CompletionResultSet resultSet) {
    if (position.getText().startsWith(SdkConstants.ANDROID_NS_NAME_PREFIX)) {
        return;
    }
    final PsiElement grandparent = parent.getParent();
    if (!(grandparent instanceof XmlTag)) {
        return;
    }
    final DomElement element = DomManager.getDomManager(grandparent.getProject()).getDomElement((XmlTag) grandparent);
    if (!(element instanceof LayoutElement) && !(element instanceof PreferenceElement)) {
        return;
    }
    final String prefix = ((XmlTag) grandparent).getPrefixByNamespace(SdkConstants.NS_RESOURCES);
    if (prefix == null || prefix.length() < 3) {
        return;
    }
    final LookupElementBuilder e = LookupElementBuilder.create(prefix + ":").withTypeText("[Namespace Prefix]", true);
    resultSet.addElement(PrioritizedLookupElement.withPriority(e, Double.MAX_VALUE));
}
Also used : LayoutElement(org.jetbrains.android.dom.layout.LayoutElement) PreferenceElement(org.jetbrains.android.dom.xml.PreferenceElement) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) PsiElement(com.intellij.psi.PsiElement)

Aggregations

LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 PsiElement (com.intellij.psi.PsiElement)1 LayoutElement (org.jetbrains.android.dom.layout.LayoutElement)1 PreferenceElement (org.jetbrains.android.dom.xml.PreferenceElement)1