Search in sources :

Example 1 with JavaFxClassTagDescriptorBase

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

the class JavaFxPsiUtil method isClassAcceptable.

public static boolean isClassAcceptable(@Nullable XmlTag targetTag, @Nullable final PsiClass fromClass, @NotNull BiConsumer<String, Validator.ValidationHost.ErrorType> messageConsumer) {
    if (targetTag == null || fromClass == null || !fromClass.isValid()) {
        return true;
    }
    final XmlElementDescriptor tagDescriptor = targetTag.getDescriptor();
    if (tagDescriptor instanceof JavaFxPropertyTagDescriptor) {
        final PsiClass containingClass = ((JavaFxPropertyTagDescriptor) tagDescriptor).getPsiClass();
        final PsiType targetType = getWritablePropertyType(containingClass, tagDescriptor.getDeclaration());
        return canCoerce(targetType, fromClass, targetTag, messageConsumer);
    } else if (tagDescriptor instanceof JavaFxClassTagDescriptorBase) {
        final PsiElement tagDeclaration = tagDescriptor.getDeclaration();
        if (tagDeclaration instanceof PsiClass) {
            PsiClass defaultPropertyOwnerClass = (PsiClass) tagDeclaration;
            final XmlAttribute factoryAttr = targetTag.getAttribute(FxmlConstants.FX_FACTORY);
            if (factoryAttr != null) {
                defaultPropertyOwnerClass = getFactoryProducedClass((PsiClass) tagDeclaration, factoryAttr.getValue());
            }
            final PsiType targetType = getDefaultPropertyExpectedType(defaultPropertyOwnerClass);
            if (targetType != null) {
                return canCoerce(targetType, fromClass, targetTag, messageConsumer);
            }
            if (!isObservableCollection(defaultPropertyOwnerClass)) {
                return noDefaultPropertyError(messageConsumer);
            }
        }
    }
    return true;
}
Also used : JavaFxClassTagDescriptorBase(org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxClassTagDescriptorBase) JavaFxPropertyTagDescriptor(org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxPropertyTagDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 2 with JavaFxClassTagDescriptorBase

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

the class JavaFxCollapseSubTagToAttributeIntention method isAvailable.

@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
    if (element instanceof XmlToken && ((XmlToken) element).getTokenType() == XmlTokenType.XML_NAME && element.getParent() instanceof XmlTag) {
        final XmlTag tag = (XmlTag) element.getParent();
        for (XmlTag xmlTag : tag.getSubTags()) {
            if (xmlTag.getAttribute(FxmlConstants.FX_VALUE) == null)
                return false;
        }
        final XmlTag parentTag = tag.getParentTag();
        if (parentTag != null && tag.getDescriptor() instanceof JavaFxPropertyTagDescriptor && parentTag.getDescriptor() instanceof JavaFxClassTagDescriptorBase) {
            setText("Collapse tag '" + tag.getName() + "' to attribute");
            return true;
        }
    }
    return false;
}
Also used : JavaFxClassTagDescriptorBase(org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxClassTagDescriptorBase) JavaFxPropertyTagDescriptor(org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxPropertyTagDescriptor) XmlToken(com.intellij.psi.xml.XmlToken) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

JavaFxClassTagDescriptorBase (org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxClassTagDescriptorBase)2 JavaFxPropertyTagDescriptor (org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxPropertyTagDescriptor)2 XmlTag (com.intellij.psi.xml.XmlTag)1 XmlToken (com.intellij.psi.xml.XmlToken)1 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)1