Search in sources :

Example 16 with JSFunction

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

the class FlexClassMemberNode method update.

@Override
protected void update(PresentationData presentation) {
    String text;
    JSElement value = getValue();
    if (value == null || !value.isValid()) {
        return;
    }
    if (value instanceof JSFunction) {
        text = JSFormatUtil.formatMethod(((JSFunction) value), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.TYPE_AFTER, PsiFormatUtilBase.SHOW_TYPE);
    } else if (value instanceof JSVariable) {
        text = JSFormatUtil.formatField(((JSVariable) value), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.TYPE_AFTER);
    } else {
        text = value.getName();
    }
    presentation.setPresentableText(text);
    presentation.setIcon(value.getIcon(Iconable.ICON_FLAG_VISIBILITY));
}
Also used : JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSElement(com.intellij.lang.javascript.psi.JSElement) JSVariable(com.intellij.lang.javascript.psi.JSVariable)

Example 17 with JSFunction

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

the class JSCreateMethodDialog method validateAndCommitData.

@Override
protected String validateAndCommitData() {
    String error = super.validateAndCommitData();
    if (error != null) {
        return error;
    }
    JSFunction existingMethod = JSInheritanceUtil.findMethodInClass(createMethod(), myTargetClass, true);
    if (existingMethod != null && existingMethod.getAttributeList().hasModifier(JSAttributeList.ModifierType.STATIC) == (myStaticCb != null && myStaticCb.isSelected())) {
        boolean contains = existingMethod.getParent() == myTargetClass;
        String message = JSBundle.message("class.already.contains.method.warning", myTargetClass.getQualifiedName(), Integer.valueOf(contains ? 1 : 2), getMethodName());
        if (Messages.showYesNoDialog(myProject, message, getTitle(), Messages.getQuestionIcon()) != Messages.YES) {
            return EXIT_SILENTLY;
        }
    }
    return null;
}
Also used : JSFunction(com.intellij.lang.javascript.psi.JSFunction)

Example 18 with JSFunction

use of com.intellij.lang.javascript.psi.JSFunction 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 19 with JSFunction

use of com.intellij.lang.javascript.psi.JSFunction 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 20 with JSFunction

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

Aggregations

JSFunction (com.intellij.lang.javascript.psi.JSFunction)33 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)13 PsiElement (com.intellij.psi.PsiElement)11 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)8 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)6 Nullable (org.jetbrains.annotations.Nullable)5 ArrayList (java.util.ArrayList)4 JSVariable (com.intellij.lang.javascript.psi.JSVariable)3 Module (com.intellij.openapi.module.Module)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiDirectory (com.intellij.psi.PsiDirectory)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 List (java.util.List)3 NotNull (org.jetbrains.annotations.NotNull)3 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)2 ASTNode (com.intellij.lang.ASTNode)2 JavaScriptSupportLoader (com.intellij.lang.javascript.JavaScriptSupportLoader)2 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)2 FlexUnitSupport (com.intellij.lang.javascript.flex.flexunit.FlexUnitSupport)2