Search in sources :

Example 66 with JSClass

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

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

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

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

the class FlexValue method findJSClass.

@Nullable
private static JSClass findJSClass(final Project project, @Nullable final Module module, final String typeFromFlexValueResult) {
    String type = getType(typeFromFlexValueResult);
    if (type != null) {
        if (isGenericVector(type)) {
            type = VECTOR;
        }
        final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project);
        PsiElement jsClass = ActionScriptClassResolver.findClassByQName(type, jsIndex, module);
        if (!(jsClass instanceof JSClass) && type.endsWith("$")) {
            // fdb adds '$' to class name in case of static context
            jsClass = ActionScriptClassResolver.findClassByQName(type.substring(0, type.length() - 1), jsIndex, module);
        }
        if (!(jsClass instanceof JSClass) && module != null) {
            // probably this class came from dynamically loaded module that is not in moduleWithDependenciesAndLibrariesScope(module)
            final GlobalSearchScope scope = ProjectScope.getAllScope(project);
            jsClass = ActionScriptClassResolver.findClassByQNameStatic(type, scope);
            if (!(jsClass instanceof JSClass) && type.endsWith("$")) {
                jsClass = ActionScriptClassResolver.findClassByQNameStatic(type.substring(0, type.length() - 1), scope);
            }
        }
        return jsClass instanceof JSClass ? (JSClass) jsClass : null;
    }
    return null;
}
Also used : JavaScriptIndex(com.intellij.lang.javascript.index.JavaScriptIndex) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) MxmlJSClass(com.intellij.javascript.flex.mxml.MxmlJSClass) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 70 with JSClass

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

the class FlashRunnerParameters method doCheck.

private void doCheck(final Pair<Module, FlexBuildConfiguration> moduleAndBC) throws RuntimeConfigurationError {
    final FlexBuildConfiguration bc = moduleAndBC.second;
    final Sdk sdk = bc.getSdk();
    if (sdk == null) {
        throw new RuntimeConfigurationError(FlexCommonBundle.message("sdk.not.set.for.bc.0.of.module.1", bc.getName(), moduleAndBC.first.getName()));
    }
    if (myOverrideMainClass) {
        if (myOverriddenMainClass.isEmpty()) {
            throw new RuntimeConfigurationError(FlexBundle.message("main.class.not.set"));
        }
        PsiElement clazz = ActionScriptClassResolver.findClassByQNameStatic(myOverriddenMainClass, moduleAndBC.first.getModuleScope(true));
        if (!(clazz instanceof JSClass)) {
            throw new RuntimeConfigurationError(FlexBundle.message("main.class.not.found", myOverriddenMainClass, bc.getName()));
        }
        if (myOverriddenOutputFileName.isEmpty()) {
            throw new RuntimeConfigurationError(FlexBundle.message("output.file.name.not.specified"));
        }
        if (!myOverriddenOutputFileName.toLowerCase().endsWith(".swf")) {
            throw new RuntimeConfigurationError(FlexBundle.message("output.file.must.have.swf.extension"));
        }
    } else {
        if (bc.getOutputType() != OutputType.Application) {
            throw new RuntimeConfigurationError(FlexBundle.message("bc.does.not.produce.app", getBCName(), getModuleName()));
        }
    }
    switch(bc.getTargetPlatform()) {
        case Web:
            if (myLaunchUrl) {
                if (myUrl.isEmpty())
                    throw new RuntimeConfigurationError(FlexBundle.message("flex.run.config.url.not.set"));
                try {
                    if (BrowserUtil.getURL(myUrl) == null)
                        throw new RuntimeConfigurationError(FlexBundle.message("flex.run.config.incorrect.url"));
                } catch (MalformedURLException e) {
                    throw new RuntimeConfigurationError(FlexBundle.message("flex.run.config.incorrect.url"));
                }
            //if (myLauncherParameters.getLauncherType() == LauncherParameters.LauncherType.Player) {
            //  throw new RuntimeConfigurationError(FlexBundle.message("flex.run.config.url.can.not.be.run.with.flash.player"));
            //}
            }
            if (myLauncherParameters.getLauncherType() == LauncherParameters.LauncherType.Player) {
                if (StringUtil.isEmptyOrSpaces(myLauncherParameters.getPlayerPath())) {
                    throw new RuntimeConfigurationError(FlexBundle.message("path.to.flash.player.not.set"));
                }
                if (!new File(myLauncherParameters.getPlayerPath()).exists()) {
                    throw new RuntimeConfigurationError(FlexBundle.message("flash.player.not.found", myLauncherParameters.getPresentableText()));
                }
            }
            checkDebuggerSdk();
            break;
        case Desktop:
            checkAdlAndAirRuntime(sdk);
            if (bc.getOutputType() == OutputType.Application) {
                checkCustomDescriptor(bc.getAirDesktopPackagingOptions(), getBCName(), getModuleName());
            }
            break;
        case Mobile:
            switch(myMobileRunTarget) {
                case Emulator:
                    checkAdlAndAirRuntime(sdk);
                    if (bc.getOutputType() == OutputType.Application) {
                        switch(myAppDescriptorForEmulator) {
                            case Android:
                                checkCustomDescriptor(bc.getAndroidPackagingOptions(), getBCName(), getModuleName());
                                break;
                            case IOS:
                                checkCustomDescriptor(bc.getIosPackagingOptions(), getBCName(), getModuleName());
                                break;
                        }
                    }
                    break;
                case AndroidDevice:
                    if (bc.getOutputType() == OutputType.Application) {
                        checkCustomDescriptor(bc.getAndroidPackagingOptions(), getBCName(), getModuleName());
                    }
                    break;
                case iOSSimulator:
                    if (bc.getOutputType() == OutputType.Application) {
                        checkCustomDescriptor(bc.getIosPackagingOptions(), getBCName(), getModuleName());
                    }
                    if (!SystemInfo.isMac) {
                        throw new RuntimeConfigurationError(FlexBundle.message("ios.simulator.on.mac.only.warning"));
                    }
                    if (myIOSSimulatorSdkPath.isEmpty()) {
                        throw new RuntimeConfigurationError(FlexBundle.message("ios.simulator.sdk.not.set"));
                    } else if (!new File(FileUtil.toSystemDependentName(myIOSSimulatorSdkPath)).isDirectory()) {
                        throw new RuntimeConfigurationError(FlexBundle.message("ios.simulator.sdk.not.found", FileUtil.toSystemDependentName(myIOSSimulatorSdkPath)));
                    }
                    break;
                case iOSDevice:
                    if (bc.getOutputType() == OutputType.Application) {
                        checkCustomDescriptor(bc.getIosPackagingOptions(), getBCName(), getModuleName());
                    }
                    break;
            }
            break;
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Sdk(com.intellij.openapi.projectRoots.Sdk) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) PsiElement(com.intellij.psi.PsiElement)

Aggregations

JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)141 PsiElement (com.intellij.psi.PsiElement)65 Nullable (org.jetbrains.annotations.Nullable)27 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)23 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)22 JSFunction (com.intellij.lang.javascript.psi.JSFunction)18 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)18 Module (com.intellij.openapi.module.Module)17 XmlFile (com.intellij.psi.xml.XmlFile)17 Project (com.intellij.openapi.project.Project)16 PsiFile (com.intellij.psi.PsiFile)16 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)15 ArrayList (java.util.ArrayList)14 PsiDirectory (com.intellij.psi.PsiDirectory)11 XmlTag (com.intellij.psi.xml.XmlTag)11 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)8 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)8 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)7