Search in sources :

Example 1 with JavaFxBuiltInAttributeDescriptor

use of org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxBuiltInAttributeDescriptor in project intellij-community by JetBrains.

the class JavaFxExpandAttributeIntention method isAvailable.

@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
    if (element instanceof XmlToken && ((XmlToken) element).getTokenType() == XmlTokenType.XML_NAME) {
        final PsiElement parent = element.getParent();
        if (parent instanceof XmlAttribute) {
            final XmlAttributeDescriptor descriptor = ((XmlAttribute) parent).getDescriptor();
            if (descriptor instanceof JavaFxPropertyAttributeDescriptor && !(descriptor instanceof JavaFxBuiltInAttributeDescriptor)) {
                PsiType tagType = null;
                final PsiElement declaration = descriptor.getDeclaration();
                if (declaration instanceof PsiMember) {
                    tagType = PropertyUtil.getPropertyType((PsiMember) declaration);
                }
                PsiClass tagClass = PsiUtil.resolveClassInType(tagType instanceof PsiPrimitiveType ? ((PsiPrimitiveType) tagType).getBoxedType(parent) : tagType);
                if ((tagClass != null && JavaFxPsiUtil.isAbleToInstantiate(tagClass)) || descriptor instanceof JavaFxStaticSetterAttributeDescriptor) {
                    setText("Expand '" + ((XmlAttribute) parent).getName() + "' to tag");
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : JavaFxStaticSetterAttributeDescriptor(org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxStaticSetterAttributeDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) JavaFxBuiltInAttributeDescriptor(org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxBuiltInAttributeDescriptor) JavaFxPropertyAttributeDescriptor(org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxPropertyAttributeDescriptor)

Aggregations

XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)1 JavaFxBuiltInAttributeDescriptor (org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxBuiltInAttributeDescriptor)1 JavaFxPropertyAttributeDescriptor (org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxPropertyAttributeDescriptor)1 JavaFxStaticSetterAttributeDescriptor (org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxStaticSetterAttributeDescriptor)1