Search in sources :

Example 6 with JSAttribute

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

the class ActionScriptSmartCompletionContributor method getEventsMap.

public static Map<String, String> getEventsMap(JSClass clazzToProcess) {
    if (clazzToProcess == null)
        return Collections.emptyMap();
    final Map<String, String> eventsMap = new THashMap<>();
    class EventsDataCollector extends ResolveProcessor implements ActionScriptResolveUtil.MetaDataProcessor {

        public EventsDataCollector() {
            super(null);
            setToProcessHierarchy(true);
            setToProcessMembers(false);
            setTypeContext(true);
            setLocalResolve(true);
        }

        @Override
        public boolean process(@NotNull final JSAttribute jsAttribute) {
            if ("Event".equals(jsAttribute.getName())) {
                final JSAttributeNameValuePair eventAttr = jsAttribute.getValueByName("name");
                JSAttributeNameValuePair typeAttr = jsAttribute.getValueByName("type");
                if (eventAttr != null && typeAttr != null) {
                    final String simpleValue = eventAttr.getSimpleValue();
                    if (simpleValue != null) {
                        eventsMap.put(simpleValue, typeAttr.getSimpleValue());
                    }
                }
            }
            return true;
        }

        @Override
        public boolean handleOtherElement(final PsiElement el, final PsiElement context, final Ref<PsiElement> continuePassElement) {
            return true;
        }

        @Override
        public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
            if (element instanceof JSClass) {
                ActionScriptResolveUtil.processMetaAttributesForClass(element, this, true);
            }
            return true;
        }
    }
    final EventsDataCollector eventsDataCollector = new EventsDataCollector();
    if (clazzToProcess instanceof XmlBackedJSClassImpl) {
        XmlFile file = (XmlFile) clazzToProcess.getParent().getContainingFile();
        if (file != null && JavaScriptSupportLoader.isFlexMxmFile(file)) {
            final XmlDocument xmlDocument = file.getDocument();
            final XmlTag rootTag = xmlDocument == null ? null : xmlDocument.getRootTag();
            final XmlTag[] tags = rootTag == null ? XmlTag.EMPTY : MxmlJSClass.findLanguageSubTags(rootTag, FlexPredefinedTagNames.METADATA);
            JSResolveUtil.JSInjectedFilesVisitor injectedFilesVisitor = new JSResolveUtil.JSInjectedFilesVisitor() {

                @Override
                protected void process(JSFile file) {
                    for (PsiElement element : file.getChildren()) {
                        if (element instanceof JSAttributeList) {
                            ActionScriptResolveUtil.processAttributeList(eventsDataCollector, null, (JSAttributeList) element, true, true);
                        }
                    }
                }
            };
            for (XmlTag tag : tags) {
                JSResolveUtil.processInjectedFileForTag(tag, injectedFilesVisitor);
            }
        }
    }
    clazzToProcess.processDeclarations(eventsDataCollector, ResolveState.initial(), clazzToProcess, clazzToProcess);
    return eventsMap;
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) XmlFile(com.intellij.psi.xml.XmlFile) XmlDocument(com.intellij.psi.xml.XmlDocument) NotNull(org.jetbrains.annotations.NotNull) ResolveState(com.intellij.psi.ResolveState) 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) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) MxmlJSClass(com.intellij.javascript.flex.mxml.MxmlJSClass) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 7 with JSAttribute

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

the class FlexUnitSupport method getCustomRunner.

/**
   * @return [RunWith] metadata default attribute value. Can be <code>null</code>, empty string or whatever.
   */
@Nullable
public static String getCustomRunner(JSClass clazz) {
    final JSAttribute[] attrs = clazz.getAttributeList().getAttributesByName(RUN_WITH_ATTRIBUTE);
    if (attrs.length == 0)
        return null;
    final JSAttributeNameValuePair attr = attrs[0].getValueByName(null);
    return attr == null ? null : attr.getSimpleValue();
}
Also used : JSAttribute(com.intellij.lang.javascript.psi.ecmal4.JSAttribute) JSAttributeNameValuePair(com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with JSAttribute

use of com.intellij.lang.javascript.psi.ecmal4.JSAttribute 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 9 with JSAttribute

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

the class MyImplicitUsageProvider method isImplicitUsage.

@Override
public boolean isImplicitUsage(PsiElement element) {
    if (!(element instanceof JSFunction)) {
        return false;
    }
    final JSFunction method = (JSFunction) element;
    final String methodName = method.getName();
    if (methodName == null || !Character.isUpperCase(methodName.charAt(0)) || !(method.getParent() instanceof JSClass) || method.getParent() instanceof XmlBackedJSClassImpl) {
        return false;
    }
    final JSClass clazz = (JSClass) method.getParent();
    if (!ActionScriptClassResolver.isParentClass(clazz, "com.intellij.flex.uiDesigner.TestCase")) {
        return false;
    }
    final JSAttributeList attributeList = method.getAttributeList();
    if (attributeList == null || attributeList.getAccessType() != JSAttributeList.AccessType.PUBLIC) {
        return false;
    }
    final VirtualFile projectBaseDir = element.getProject().getBaseDir();
    if (projectBaseDir == null) {
        return false;
    }
    File testSourcePath = new File(projectBaseDir.getPath(), RELATIVE_TEST_DATA_PATH);
    if (!testSourcePath.exists()) {
        testSourcePath = new File(projectBaseDir.getPath(), "flex/tools/flex-ui-designer/" + RELATIVE_TEST_DATA_PATH);
        assert testSourcePath.exists();
    }
    final JSAttributeList classAttributeList = clazz.getAttributeList();
    if (classAttributeList != null) {
        final JSAttribute testAnnotation = classAttributeList.findAttributeByName("Test");
        if (testAnnotation == null) {
            return false;
        }
        return new File(testSourcePath, testAnnotation.getValueByName("dir").getSimpleValue() + File.separatorChar + methodName + ".mxml").exists();
    }
    return false;
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSAttribute(com.intellij.lang.javascript.psi.ecmal4.JSAttribute) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 10 with JSAttribute

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

the class FlexAttributeReferenceProvider method getBundleRefsCheckingParent.

private static PsiReference[] getBundleRefsCheckingParent(JSAttributeNameValuePairImpl element) {
    JSAttribute attribute = (JSAttribute) element.getParent();
    @NonNls final String parentName = attribute.getName();
    if (!FlexAnnotationNames.RESOURCE.equals(parentName))
        return PsiReference.EMPTY_ARRAY;
    return FlexPropertiesSupport.getResourceBundleReference(element, ourBundleInfoProvider);
}
Also used : NonNls(org.jetbrains.annotations.NonNls) JSAttribute(com.intellij.lang.javascript.psi.ecmal4.JSAttribute)

Aggregations

JSAttribute (com.intellij.lang.javascript.psi.ecmal4.JSAttribute)12 JSAttributeNameValuePair (com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair)9 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)4 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiElement (com.intellij.psi.PsiElement)3 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)3 NonNls (org.jetbrains.annotations.NonNls)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 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)2 JSFunction (com.intellij.lang.javascript.psi.JSFunction)2 JSReferenceSet (com.intellij.lang.javascript.psi.impl.JSReferenceSet)2 Ref (com.intellij.openapi.util.Ref)2 TextRange (com.intellij.openapi.util.TextRange)2 Nullable (org.jetbrains.annotations.Nullable)2 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 LocalQuickFixProvider (com.intellij.codeInspection.LocalQuickFixProvider)1