Search in sources :

Example 61 with XmlElementDescriptor

use of com.intellij.xml.XmlElementDescriptor 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)

Example 62 with XmlElementDescriptor

use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.

the class FlexMxmlNSDescriptor method getRootElementsDescriptors.

@NotNull
public XmlElementDescriptor[] getRootElementsDescriptors(@Nullable final XmlDocument document) {
    XmlElementDescriptor[] elementDescriptors = CodeContext.getContext(namespace, module).getDescriptorsWithAllowedDeclaration();
    ArrayList<XmlElementDescriptor> results = new ArrayList<>(elementDescriptors.length);
    final XmlTag rootTag = document == null ? null : document.getRootTag();
    // sorry for this hacky way to determine if this is root tag name completion or not
    final boolean isRootTagCompletion = rootTag != null && rootTag.getName().endsWith(CompletionInitializationContext.DUMMY_IDENTIFIER_TRIMMED);
    for (XmlElementDescriptor elementDescriptor : elementDescriptors) {
        if (isRootTagCompletion) {
            if (!isLegalRootElementDescriptor(elementDescriptor)) {
                continue;
            }
            if (elementDescriptor instanceof MxmlBackedElementDescriptor) {
                final PsiElement declaration = elementDescriptor.getDeclaration();
                final PsiFile containingFile = document.getContainingFile();
                if (declaration != null && containingFile != null && declaration.equals(containingFile.getOriginalFile())) {
                    // do not suggest root tag referencing to this mxml file itself 
                    continue;
                }
            }
        }
        String name = elementDescriptor.getName();
        if (name.length() > 0)
            /*&& Character.isUpperCase(name.charAt(0))*/
            results.add(elementDescriptor);
    }
    return results.toArray(new XmlElementDescriptor[results.size()]);
}
Also used : ArrayList(java.util.ArrayList) PsiFile(com.intellij.psi.PsiFile) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 63 with XmlElementDescriptor

use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.

the class FlexMxmlNSDescriptor method hasElementDescriptorWithName.

public boolean hasElementDescriptorWithName(String name, String className) {
    final CodeContext context = CodeContext.getContext(namespace, module);
    XmlElementDescriptor descriptor = context.getElementDescriptor(name, (XmlTag) null);
    if (descriptor instanceof ClassBackedElementDescriptor) {
        return ((ClassBackedElementDescriptor) descriptor).className.equals(className);
    }
    return false;
}
Also used : XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 64 with XmlElementDescriptor

use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.

the class FlexAttributeReferenceProvider method valueRefs.

public static PsiReference[] valueRefs(JSAttributeNameValuePairImpl element, String name) {
    final JSAttributeImpl jsAttribute = (JSAttributeImpl) element.getParent();
    final XmlElementDescriptor descriptor = jsAttribute.getBackedDescriptor();
    final XmlAttributeDescriptor attributeDescriptor = descriptor == null ? null : descriptor.getAttributeDescriptor(StringUtil.notNullize(name, JSAttributeNameValuePair.DEFAULT), null);
    if (name == null) {
        return getDefaultPropertyRefs(element, attributeDescriptor);
    }
    final String baseClassFqns = attributeDescriptor == null ? null : attributeDescriptor.getDefaultValue();
    if (baseClassFqns != null) {
        return getClassRefs(element, baseClassFqns);
    } else if ("source".equals(name)) {
        return getPathRefsCheckingParent(element);
    } else if ("key".equals(name)) {
        return getPropertyRefsCheckingParent(element);
    } else if (BUNDLE_ATTR_NAME.equals(name)) {
        return getBundleRefsCheckingParent(element);
    } else if (attributeDescriptor != null && attributeDescriptor.isEnumerated()) {
        final String[] enumeratedValues = attributeDescriptor.getEnumeratedValues();
        final TextRange range = getValueRange(element);
        if (enumeratedValues != null && enumeratedValues.length > 0 && range != null) {
            return new PsiReference[] { new EnumeratedAttributeValueReference(element, range, enumeratedValues) };
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
Also used : JSAttributeImpl(com.intellij.lang.javascript.psi.ecmal4.impl.JSAttributeImpl) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 65 with XmlElementDescriptor

use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.

the class FlexCssElementDescriptorProvider method getSimpleSelectors.

@NotNull
public String[] getSimpleSelectors(@NotNull PsiElement context) {
    Module module = findModuleForPsiElement(context);
    if (module == null) {
        return ArrayUtil.EMPTY_STRING_ARRAY;
    }
    CodeContext codeContext = CodeContext.getContext(JavaScriptSupportLoader.MXML_URI, module);
    XmlElementDescriptor[] descriptors = codeContext.getDescriptorsWithAllowedDeclaration();
    String[] selectors = new String[descriptors.length + 1];
    selectors[0] = "global";
    int i = 1;
    for (XmlElementDescriptor descriptor : descriptors) {
        selectors[i++] = descriptor.getName();
    }
    return selectors;
}
Also used : CodeContext(com.intellij.javascript.flex.mxml.schema.CodeContext) Module(com.intellij.openapi.module.Module) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)159 XmlTag (com.intellij.psi.xml.XmlTag)88 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)60 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)54 PsiElement (com.intellij.psi.PsiElement)23 XmlFile (com.intellij.psi.xml.XmlFile)23 Nullable (org.jetbrains.annotations.Nullable)23 AnyXmlElementDescriptor (com.intellij.xml.impl.schema.AnyXmlElementDescriptor)22 PsiFile (com.intellij.psi.PsiFile)11 ArrayList (java.util.ArrayList)11 XmlAttribute (com.intellij.psi.xml.XmlAttribute)10 NotNull (org.jetbrains.annotations.NotNull)10 ClassBackedElementDescriptor (com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor)7 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)7 Project (com.intellij.openapi.project.Project)7 HtmlTag (com.intellij.psi.html.HtmlTag)7 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)5 XmlDocument (com.intellij.psi.xml.XmlDocument)5 DElementPattern (org.kohsuke.rngom.digested.DElementPattern)5 InvalidPropertyException (com.intellij.flex.uiDesigner.InvalidPropertyException)4