Search in sources :

Example 1 with CreateSetterByMxmlAttributeFix

use of com.intellij.lang.javascript.validation.fixes.CreateSetterByMxmlAttributeFix in project intellij-plugins by JetBrains.

the class FlexUndefinedElementFixProvider method createFixes.

@Nullable
@Override
public IntentionAction[] createFixes(@NotNull XmlAttribute attribute) {
    if (!JavaScriptSupportLoader.isFlexMxmFile(attribute.getContainingFile()))
        return null;
    final String name = attribute.getName();
    if (!JSRefactoringUtil.isValidIdentifier(name, attribute.getProject())) {
        return IntentionAction.EMPTY_ARRAY;
    }
    final XmlElementDescriptor descriptor = attribute.getParent().getDescriptor();
    final PsiElement declaration = descriptor instanceof ClassBackedElementDescriptor ? descriptor.getDeclaration() : null;
    final VirtualFile virtualFile = declaration == null ? null : declaration.getContainingFile().getVirtualFile();
    if (virtualFile == null || ProjectRootManager.getInstance(declaration.getProject()).getFileIndex().getSourceRootForFile(virtualFile) == null) {
        return IntentionAction.EMPTY_ARRAY;
    }
    if (declaration instanceof JSClass || declaration instanceof XmlFile && JavaScriptSupportLoader.isFlexMxmFile((XmlFile) declaration)) {
        final String attributeValue = attribute.getValue();
        final FixAndIntentionAction fix1 = new CreateFieldByMxmlAttributeFix(name, attributeValue);
        fix1.registerElementRefForFix(attribute, null);
        final FixAndIntentionAction fix2 = new CreateSetterByMxmlAttributeFix(name, attributeValue);
        fix2.registerElementRefForFix(attribute, null);
        final FixAndIntentionAction fix3 = new CreateEventMetadataByMxmlAttributeFix(name);
        fix3.registerElementRefForFix(attribute, null);
        return new IntentionAction[] { fix1, fix2, fix3 };
    }
    return IntentionAction.EMPTY_ARRAY;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) FixAndIntentionAction(com.intellij.lang.javascript.validation.fixes.FixAndIntentionAction) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) FixAndIntentionAction(com.intellij.lang.javascript.validation.fixes.FixAndIntentionAction) CreateFieldByMxmlAttributeFix(com.intellij.lang.javascript.validation.fixes.CreateFieldByMxmlAttributeFix) CreateEventMetadataByMxmlAttributeFix(com.intellij.lang.javascript.validation.fixes.CreateEventMetadataByMxmlAttributeFix) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) CreateSetterByMxmlAttributeFix(com.intellij.lang.javascript.validation.fixes.CreateSetterByMxmlAttributeFix) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)1 CreateEventMetadataByMxmlAttributeFix (com.intellij.lang.javascript.validation.fixes.CreateEventMetadataByMxmlAttributeFix)1 CreateFieldByMxmlAttributeFix (com.intellij.lang.javascript.validation.fixes.CreateFieldByMxmlAttributeFix)1 CreateSetterByMxmlAttributeFix (com.intellij.lang.javascript.validation.fixes.CreateSetterByMxmlAttributeFix)1 FixAndIntentionAction (com.intellij.lang.javascript.validation.fixes.FixAndIntentionAction)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 XmlFile (com.intellij.psi.xml.XmlFile)1 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)1 Nullable (org.jetbrains.annotations.Nullable)1