Search in sources :

Example 6 with JSAttributeNameValuePair

use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair in project intellij-plugins by JetBrains.

the class ActionScriptGenerateEventHandler method getEventType.

@Nullable
public static String getEventType(final XmlAttribute xmlAttribute) {
    final XmlAttributeDescriptor descriptor = xmlAttribute == null ? null : xmlAttribute.getDescriptor();
    final PsiElement declaration = descriptor instanceof AnnotationBackedDescriptor ? descriptor.getDeclaration() : null;
    final PsiElement declarationParent = declaration == null ? null : declaration.getParent();
    if (declaration instanceof JSAttributeNameValuePair && (((JSAttributeNameValuePair) declaration).getName() == null || "name".equals(((JSAttributeNameValuePair) declaration).getName())) && declarationParent instanceof JSAttribute && "Event".equals(((JSAttribute) declarationParent).getName())) {
        return ((AnnotationBackedDescriptor) descriptor).getType();
    }
    return null;
}
Also used : XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) JSAttribute(com.intellij.lang.javascript.psi.ecmal4.JSAttribute) JSAttributeNameValuePair(com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with JSAttributeNameValuePair

use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair in project intellij-plugins by JetBrains.

the class ActionScriptAnnotatingVisitor method visitJSAttributeNameValuePair.

@Override
public void visitJSAttributeNameValuePair(@NotNull final JSAttributeNameValuePair attributeNameValuePair) {
    final boolean ok = checkReferences(attributeNameValuePair);
    if (!ok)
        return;
    // check if attribute value must be FQN of a class class inherited from some other class
    if (attributeNameValuePair.getValueNode() == null)
        return;
    final PsiElement parent = attributeNameValuePair.getParent();
    final XmlElementDescriptor descriptor = parent instanceof JSAttributeImpl ? ((JSAttributeImpl) parent).getBackedDescriptor() : null;
    final String attributeName = StringUtil.notNullize(attributeNameValuePair.getName(), JSAttributeNameValuePair.DEFAULT);
    final XmlAttributeDescriptor attributeDescriptor = descriptor == null ? null : descriptor.getAttributeDescriptor(attributeName, null);
    final String baseClassFqns = attributeDescriptor == null ? null : attributeDescriptor.getDefaultValue();
    if (baseClassFqns != null && !StringUtil.isEmptyOrSpaces(baseClassFqns)) {
        final PsiReference[] references = attributeNameValuePair.getReferences();
        PsiReference lastReference = references.length > 0 ? references[0] : null;
        for (final PsiReference reference : references) {
            if (reference.getRangeInElement().getEndOffset() > lastReference.getRangeInElement().getEndOffset()) {
                lastReference = reference;
            }
        }
        final PsiElement resolved = lastReference != null ? lastReference.resolve() : null;
        if (resolved instanceof JSClass) {
            boolean correctClass = false;
            final Collection<String> resolvedBaseClasses = new ArrayList<>();
            final GlobalSearchScope scope = JSResolveUtil.getResolveScope(attributeNameValuePair);
            for (String baseClassFqn : StringUtil.split(baseClassFqns, ",")) {
                if ("Object".equals(baseClassFqn)) {
                    correctClass = true;
                    break;
                }
                final PsiElement baseClass = ActionScriptClassResolver.findClassByQNameStatic(baseClassFqn, attributeNameValuePair);
                if (baseClass instanceof JSClass) {
                    resolvedBaseClasses.add(baseClassFqn);
                    if (JSInheritanceUtil.isParentClass((JSClass) resolved, (JSClass) baseClass, false, scope)) {
                        correctClass = true;
                        break;
                    }
                }
            }
            if (!correctClass) {
                final String classesForMessage = resolvedBaseClasses.isEmpty() ? StringUtil.replace(baseClassFqns, ",", ", ") : StringUtil.join(resolvedBaseClasses, ", ");
                myHolder.createErrorAnnotation(calcRangeForReferences(lastReference), JSBundle.message("javascript.expected.class.or.descendant", classesForMessage));
            }
        } else if (resolved != attributeNameValuePair) {
            // for some reason int and uint are resolved to self-reference JSResolveUtil.MyResolveResult() instead of usual JSClass
            myHolder.createErrorAnnotation(attributeNameValuePair.getValueNode(), JSBundle.message("javascript.qualified.class.name.expected"));
        }
    }
}
Also used : JSAttributeImpl(com.intellij.lang.javascript.psi.ecmal4.impl.JSAttributeImpl) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 8 with JSAttributeNameValuePair

use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair in project intellij-plugins by JetBrains.

the class FlexCssPropertyDescriptor method findStyleAttributesInClassOrSuper.

private boolean findStyleAttributesInClassOrSuper(@NotNull JSClass c, @NotNull Set<JSClass> visited, @NotNull Map<PsiElement, PairInfo> navElement2pair) {
    if (!visited.add(c))
        return false;
    JSAttributeNameValuePair result = null;
    String qName = c.getQualifiedName();
    if (myClassNames.contains(qName) || checkIncludes(c)) {
        MyMetaDataProcessor processor = new MyMetaDataProcessor();
        FlexUtils.processMetaAttributesForClass(c, processor);
        result = processor.myResult;
    }
    PsiElement navElement = result != null ? result.getNavigationElement() : null;
    if (result == null || navElement == null) {
        boolean found = false;
        for (JSClass superClass : c.getSupers()) {
            found = found || findStyleAttributesInClassOrSuper(superClass, visited, navElement2pair);
        }
        if (found)
            return true;
    }
    if (result != null) {
        navElement2pair.put(navElement != null ? navElement : result, new PairInfo(result, qName));
        return true;
    }
    return false;
}
Also used : JSAttributeNameValuePair(com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 9 with JSAttributeNameValuePair

use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair in project intellij-plugins by JetBrains.

the class FlexCssPropertyDescriptor method findStyleAttributesInFile.

private boolean findStyleAttributesInFile(@NotNull JSFile jsFile, @NotNull Set<JSFile> visited, @NotNull Map<PsiElement, PairInfo> navElement2pair) {
    if (!visited.add(jsFile))
        return false;
    JSAttributeNameValuePair result = null;
    String fileName = jsFile.getName();
    if (myFileNames.contains(fileName)) {
        MyMetaDataProcessor processor = new MyMetaDataProcessor();
        FlexUtils.processMetaAttributesForClass(jsFile, processor);
        result = processor.myResult;
    }
    PsiElement navElement = result != null ? result.getNavigationElement() : null;
    if (result != null) {
        navElement2pair.put(navElement != null ? navElement : result, new PairInfo(result, fileName));
        return true;
    }
    return false;
}
Also used : JSAttributeNameValuePair(com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair) PsiElement(com.intellij.psi.PsiElement)

Example 10 with JSAttributeNameValuePair

use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair in project intellij-plugins by JetBrains.

the class FlexCompilationUtils method replaceMacros.

private static String replaceMacros(final String wrapperText, final String outputFileName, final String targetPlayer, @Nullable final JSClass mainClass) {
    final Map<String, String> replacementMap = new THashMap<>();
    replacementMap.put(FlexCommonUtils.SWF_MACRO, outputFileName);
    replacementMap.put(FlexCommonUtils.TITLE_MACRO, outputFileName);
    replacementMap.put(FlexCommonUtils.APPLICATION_MACRO, outputFileName);
    replacementMap.put(FlexCommonUtils.BG_COLOR_MACRO, "#ffffff");
    replacementMap.put(FlexCommonUtils.WIDTH_MACRO, "100%");
    replacementMap.put(FlexCommonUtils.HEIGHT_MACRO, "100%");
    final List<String> versionParts = StringUtil.split(targetPlayer, ".");
    replacementMap.put(FlexCommonUtils.VERSION_MAJOR_MACRO, versionParts.size() >= 1 ? versionParts.get(0) : "0");
    replacementMap.put(FlexCommonUtils.VERSION_MINOR_MACRO, versionParts.size() >= 2 ? versionParts.get(1) : "0");
    replacementMap.put(FlexCommonUtils.VERSION_REVISION_MACRO, versionParts.size() >= 3 ? versionParts.get(2) : "0");
    final Ref<JSAttribute> swfMetadataRef = new Ref<>();
    final PsiFile psiFile = mainClass == null ? null : mainClass.getContainingFile();
    if (psiFile instanceof XmlFile) {
        final XmlTag rootTag = ((XmlFile) psiFile).getRootTag();
        if (rootTag != null) {
            final String ns = rootTag.getPrefixByNamespace(JavaScriptSupportLoader.MXML_URI3) == null ? JavaScriptSupportLoader.MXML_URI : JavaScriptSupportLoader.MXML_URI3;
            for (XmlTag tag : rootTag.findSubTags(FlexPredefinedTagNames.METADATA, ns)) {
                JSResolveUtil.processInjectedFileForTag(tag, new JSResolveUtil.JSInjectedFilesVisitor() {

                    @Override
                    protected void process(final JSFile file) {
                        for (PsiElement elt : file.getChildren()) {
                            if (elt instanceof JSAttributeList) {
                                final JSAttribute swfMetadata = ((JSAttributeList) elt).findAttributeByName("SWF");
                                if (swfMetadataRef.isNull() && swfMetadata != null) {
                                    swfMetadataRef.set(swfMetadata);
                                    return;
                                }
                            }
                        }
                    }
                });
            }
        }
    } else {
        final JSAttributeList attributeList = mainClass == null ? null : mainClass.getAttributeList();
        swfMetadataRef.set(attributeList == null ? null : attributeList.findAttributeByName("SWF"));
    }
    if (!swfMetadataRef.isNull()) {
        final JSAttribute swfMetadata = swfMetadataRef.get();
        final JSAttributeNameValuePair titleAttr = swfMetadata.getValueByName(FlexCommonUtils.TITLE_ATTR);
        ContainerUtil.putIfNotNull(FlexCommonUtils.TITLE_MACRO, titleAttr == null ? null : titleAttr.getSimpleValue(), replacementMap);
        final JSAttributeNameValuePair bgColorAttr = swfMetadata.getValueByName(FlexCommonUtils.BG_COLOR_ATTR);
        ContainerUtil.putIfNotNull(FlexCommonUtils.BG_COLOR_MACRO, bgColorAttr == null ? null : bgColorAttr.getSimpleValue(), replacementMap);
        final JSAttributeNameValuePair widthAttr = swfMetadata.getValueByName(FlexCommonUtils.WIDTH_ATTR);
        ContainerUtil.putIfNotNull(FlexCommonUtils.WIDTH_MACRO, widthAttr == null ? null : widthAttr.getSimpleValue(), replacementMap);
        final JSAttributeNameValuePair heightAttr = swfMetadata.getValueByName(FlexCommonUtils.HEIGHT_ATTR);
        ContainerUtil.putIfNotNull(FlexCommonUtils.HEIGHT_MACRO, heightAttr == null ? null : heightAttr.getSimpleValue(), replacementMap);
    }
    return FlexCommonUtils.replace(wrapperText, replacementMap);
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) XmlFile(com.intellij.psi.xml.XmlFile) JSResolveUtil(com.intellij.lang.javascript.psi.resolve.JSResolveUtil) Ref(com.intellij.openapi.util.Ref) THashMap(gnu.trove.THashMap) JSAttribute(com.intellij.lang.javascript.psi.ecmal4.JSAttribute) JSAttributeNameValuePair(com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair) PsiFile(com.intellij.psi.PsiFile) JSFile(com.intellij.lang.javascript.psi.JSFile) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

JSAttributeNameValuePair (com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair)12 JSAttribute (com.intellij.lang.javascript.psi.ecmal4.JSAttribute)7 PsiElement (com.intellij.psi.PsiElement)6 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)4 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)3 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)3 NotNull (org.jetbrains.annotations.NotNull)3 InvalidPropertyException (com.intellij.flex.uiDesigner.InvalidPropertyException)2 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)2 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)2 JSFile (com.intellij.lang.javascript.psi.JSFile)2 JSFunction (com.intellij.lang.javascript.psi.JSFunction)2 Ref (com.intellij.openapi.util.Ref)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Nullable (org.jetbrains.annotations.Nullable)2 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 LocalQuickFixProvider (com.intellij.codeInspection.LocalQuickFixProvider)1 FlexCssPropertyDescriptor (com.intellij.javascript.flex.css.FlexCssPropertyDescriptor)1 AnnotationBackedDescriptorImpl (com.intellij.javascript.flex.mxml.schema.AnnotationBackedDescriptorImpl)1 CodeContext (com.intellij.javascript.flex.mxml.schema.CodeContext)1