Search in sources :

Example 11 with JSAttributeList

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

the class CreateFlexUnitTestDialog method createUIComponents.

private void createUIComponents() {
    final Module module = ModuleUtil.findModuleForPsiElement(myContextClass);
    assert module != null;
    myPackageCombo = JSReferenceEditor.forPackageName(StringUtil.getPackageName(myContextClass.getQualifiedName()), module.getProject(), null, getTestClassPackageScope(module), RefactoringBundle.message("choose.destination.package"));
    final Condition<JSClass> filter = jsClass -> {
        final JSAttributeList attributeList = jsClass.getAttributeList();
        return !jsClass.isInterface() && attributeList != null && !attributeList.hasModifier(JSAttributeList.ModifierType.FINAL);
    };
    mySuperClassField = JSReferenceEditor.forClassName("", module.getProject(), null, getSuperClassScope(module), null, filter, JSBundle.message("choose.super.class.title"));
    final List<JSMemberInfo> memberInfos = new ArrayList<>();
    JSMemberInfo.extractClassMembers(myContextClass, memberInfos, new MemberInfoBase.Filter<JSAttributeListOwner>() {

        public boolean includeMember(final JSAttributeListOwner member) {
            final JSAttributeList attributeList = member.getAttributeList();
            return member instanceof JSFunction && ((JSFunction) member).getKind() != JSFunction.FunctionKind.CONSTRUCTOR && attributeList != null && attributeList.getAccessType() == JSAttributeList.AccessType.PUBLIC;
        }
    });
    myMemberSelectionPanel = new JSMemberSelectionPanel("Generate test methods for:", memberInfos, null);
}
Also used : ActionListener(java.awt.event.ActionListener) VirtualFile(com.intellij.openapi.vfs.VirtualFile) JSMemberInfo(com.intellij.lang.javascript.refactoring.util.JSMemberInfo) RefactoringBundle(com.intellij.refactoring.RefactoringBundle) NullableComputable(com.intellij.openapi.util.NullableComputable) JSAttributeListOwner(com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner) ActionScriptClassResolver(com.intellij.javascript.flex.resolve.ActionScriptClassResolver) PsiManager(com.intellij.psi.PsiManager) ArrayList(java.util.ArrayList) ContentEntry(com.intellij.openapi.roots.ContentEntry) CodeInsightBundle(com.intellij.codeInsight.CodeInsightBundle) ModuleUtil(com.intellij.openapi.module.ModuleUtil) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) JSRefactoringUtil(com.intellij.lang.javascript.refactoring.util.JSRefactoringUtil) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) PsiElement(com.intellij.psi.PsiElement) Conditions(com.intellij.openapi.util.Conditions) FileUtil(com.intellij.openapi.util.io.FileUtil) Module(com.intellij.openapi.module.Module) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) JSReferenceEditor(com.intellij.lang.javascript.refactoring.ui.JSReferenceEditor) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) ThreeState(com.intellij.util.ThreeState) MarkRootActionBase(com.intellij.ide.projectView.actions.MarkRootActionBase) StringUtil(com.intellij.openapi.util.text.StringUtil) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) IOException(java.io.IOException) MemberInfoBase(com.intellij.refactoring.classMembers.MemberInfoBase) ActionEvent(java.awt.event.ActionEvent) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) JSMemberSelectionPanel(com.intellij.lang.javascript.refactoring.ui.JSMemberSelectionPanel) Nullable(org.jetbrains.annotations.Nullable) JSFunction(com.intellij.lang.javascript.psi.JSFunction) List(java.util.List) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) ApplicationManager(com.intellij.openapi.application.ApplicationManager) VfsUtil(com.intellij.openapi.vfs.VfsUtil) PsiDirectory(com.intellij.psi.PsiDirectory) JSBundle(com.intellij.lang.javascript.JSBundle) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) ArrayList(java.util.ArrayList) JSMemberInfo(com.intellij.lang.javascript.refactoring.util.JSMemberInfo) MemberInfoBase(com.intellij.refactoring.classMembers.MemberInfoBase) JSMemberSelectionPanel(com.intellij.lang.javascript.refactoring.ui.JSMemberSelectionPanel) JSFunction(com.intellij.lang.javascript.psi.JSFunction) Module(com.intellij.openapi.module.Module) JSAttributeListOwner(com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 12 with JSAttributeList

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

the class NodeClassInfo method getNodeClassInfo.

static NodeClassInfo getNodeClassInfo(@NotNull final JSClass jsClass) {
    final JSAttributeList classAttributes = jsClass.getAttributeList();
    final boolean dynamic = classAttributes != null && classAttributes.hasModifier(JSAttributeList.ModifierType.DYNAMIC);
    final Map<String, Icon> ownStaticFields = new THashMap<>();
    final Map<String, Icon> ownStaticProperties = new THashMap<>();
    final Map<String, Icon> ownFields = new THashMap<>();
    final Map<String, Icon> ownProperties = new THashMap<>();
    final Map<String, Icon> inheritedStaticFields = new THashMap<>();
    final Map<String, Icon> inheritedStaticProperties = new THashMap<>();
    final Map<String, Icon> inheritedFields = new THashMap<>();
    final Map<String, Icon> inheritedProperties = new THashMap<>();
    fillMapsForClass(jsClass, ownStaticFields, ownStaticProperties, ownFields, ownProperties);
    fillMapsForSupersRecursively(jsClass, new THashSet<>(), inheritedStaticFields, inheritedStaticProperties, inheritedFields, inheritedProperties);
    return new NodeClassInfo(normalizeIfVector(jsClass.getQualifiedName()), dynamic, ownStaticFields, ownStaticProperties, ownFields, ownProperties, inheritedStaticFields, inheritedStaticProperties, inheritedFields, inheritedProperties);
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) THashMap(gnu.trove.THashMap)

Example 13 with JSAttributeList

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

the class NodeClassInfo method fillMapsForClass.

private static void fillMapsForClass(final JSClass jsClass, final Map<String, Icon> staticFields, final Map<String, Icon> staticProperties, final Map<String, Icon> fields, final Map<String, Icon> properties) {
    for (final JSField variable : jsClass.getFields()) {
        final JSAttributeList varAttributes = variable.getAttributeList();
        if (varAttributes != null && varAttributes.hasModifier(JSAttributeList.ModifierType.STATIC)) {
            staticFields.put(variable.getName(), variable.getIcon(Iconable.ICON_FLAG_VISIBILITY));
        } else {
            fields.put(variable.getName(), variable.getIcon(Iconable.ICON_FLAG_VISIBILITY));
        }
    }
    for (final JSFunction function : jsClass.getFunctions()) {
        if (function.getKind() == JSFunction.FunctionKind.GETTER && function.getName() != null) {
            final JSAttributeList functionAttributes = function.getAttributeList();
            if (functionAttributes != null && functionAttributes.hasModifier(JSAttributeList.ModifierType.STATIC)) {
                staticProperties.put(function.getName(), function.getIcon(Iconable.ICON_FLAG_VISIBILITY));
            } else {
                properties.put(function.getName(), function.getIcon(Iconable.ICON_FLAG_VISIBILITY));
            }
        }
    }
    if (jsClass instanceof MxmlJSClass) {
        final PsiFile file = jsClass.getContainingFile();
        final XmlFile xmlFile = file instanceof XmlFile ? (XmlFile) file : null;
        final XmlTag rootTag = xmlFile == null ? null : xmlFile.getRootTag();
        if (rootTag != null) {
            processSubtagsRecursively(rootTag, tag -> {
                final String id = tag.getAttributeValue("id");
                if (id != null) {
                    fields.put(id, tag.getIcon(Iconable.ICON_FLAG_VISIBILITY));
                }
                return !MxmlJSClass.isTagThatAllowsAnyXmlContent(tag);
            });
        }
    }
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) XmlFile(com.intellij.psi.xml.XmlFile) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSField(com.intellij.lang.javascript.psi.JSField) PsiFile(com.intellij.psi.PsiFile) MxmlJSClass(com.intellij.javascript.flex.mxml.MxmlJSClass) XmlTag(com.intellij.psi.xml.XmlTag)

Example 14 with JSAttributeList

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

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

JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)22 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)13 PsiElement (com.intellij.psi.PsiElement)12 JSFunction (com.intellij.lang.javascript.psi.JSFunction)5 JSAttributeListOwner (com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner)5 NotNull (org.jetbrains.annotations.NotNull)5 JSAttribute (com.intellij.lang.javascript.psi.ecmal4.JSAttribute)4 JSAttributeNameValuePair (com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair)4 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)3 JSFile (com.intellij.lang.javascript.psi.JSFile)3 XmlFile (com.intellij.psi.xml.XmlFile)3 XmlTag (com.intellij.psi.xml.XmlTag)3 THashMap (gnu.trove.THashMap)3 ASTNode (com.intellij.lang.ASTNode)2 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)2 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)2 JSPackageStatement (com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement)2 Module (com.intellij.openapi.module.Module)2 TextRange (com.intellij.openapi.util.TextRange)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2