Search in sources :

Example 1 with JSFunction

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

the class FlexHierarchyTest method doJSCallHierarchyTest.

private void doJSCallHierarchyTest(final String hierarchyType, final String classFqn, final String methodName, final String scope, final String... fileNames) throws Exception {
    doHierarchyTest(() -> {
        final JSClass jsClass = (JSClass) JSDialectSpecificHandlersFactory.forLanguage(JavaScriptSupportLoader.ECMA_SCRIPT_L4).getClassResolver().findClassByQName(classFqn, GlobalSearchScope.moduleScope(myModule));
        assert jsClass != null;
        final JSFunction jsFunction = jsClass.findFunctionByName(methodName);
        assert jsFunction != null;
        if (CallHierarchyBrowserBase.CALLEE_TYPE.equals(hierarchyType)) {
            return new JSCalleeMethodsTreeStructure(myProject, jsFunction, scope);
        } else if (CallHierarchyBrowserBase.CALLER_TYPE.equals(hierarchyType)) {
            return new JSCallerMethodsTreeStructure(myProject, jsFunction, scope);
        }
        throw new IllegalArgumentException("Wrong hierarchy type: " + hierarchyType);
    }, fileNames);
}
Also used : JSCalleeMethodsTreeStructure(com.intellij.lang.javascript.hierarchy.call.JSCalleeMethodsTreeStructure) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSCallerMethodsTreeStructure(com.intellij.lang.javascript.hierarchy.call.JSCallerMethodsTreeStructure) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 2 with JSFunction

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

the class FlexHierarchyTest method doJSMethodHierarchyTest.

private void doJSMethodHierarchyTest(final String classFqn, final String methodName, final boolean hideClassesWhereMethodNotImplemented, final String... fileNames) throws Exception {
    final HierarchyBrowserManager.State state = HierarchyBrowserManager.getInstance(myProject).getState();
    final boolean oldState = state.HIDE_CLASSES_WHERE_METHOD_NOT_IMPLEMENTED;
    state.HIDE_CLASSES_WHERE_METHOD_NOT_IMPLEMENTED = hideClassesWhereMethodNotImplemented;
    doHierarchyTest(() -> {
        final JSClass jsClass = (JSClass) JSDialectSpecificHandlersFactory.forLanguage(JavaScriptSupportLoader.ECMA_SCRIPT_L4).getClassResolver().findClassByQName(classFqn, GlobalSearchScope.moduleScope(myModule));
        assert jsClass != null;
        final JSFunction jsFunction = jsClass.findFunctionByName(methodName);
        assert jsFunction != null;
        return new JSMethodHierarchyTreeStructure(myProject, jsFunction);
    }, fileNames);
    state.HIDE_CLASSES_WHERE_METHOD_NOT_IMPLEMENTED = oldState;
}
Also used : JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSMethodHierarchyTreeStructure(com.intellij.lang.javascript.hierarchy.method.JSMethodHierarchyTreeStructure) HierarchyBrowserManager(com.intellij.ide.hierarchy.HierarchyBrowserManager) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 3 with JSFunction

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

the class ActionScriptCompletionInTextFieldTest method testChangeSignatureReturnType.

@JSTestOptions({ JSTestOption.WithFlexSdk })
public void testChangeSignatureReturnType() throws Exception {
    configureByFiles(null, BASE_PATH + getTestName(false) + "_2.js2");
    JSFunction function = createFakeFunction();
    JSExpressionCodeFragment fragment = JSChangeSignatureDialog.createReturnTypeCodeFragment(new JSMethodDescriptor(function, false).getReturnType(), function, JavaScriptSupportLoader.ECMA_SCRIPT_L4);
    String[] included = new String[] { "Z111", "Z222", "int", "String", "uint", "Number", "EventDispatcher", "void", "*" };
    String[] excluded = ArrayUtil.mergeArrays(DEFALUT_VALUES, "public", "function", "while");
    checkTextFieldCompletion(fragment, included, excluded, "Z111", BASE_PATH + getTestName(false) + ".txt");
}
Also used : JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSMethodDescriptor(com.intellij.lang.javascript.refactoring.changeSignature.JSMethodDescriptor) JSExpressionCodeFragment(com.intellij.lang.javascript.psi.JSExpressionCodeFragment) JSTestOptions(com.intellij.lang.javascript.JSTestOptions)

Example 4 with JSFunction

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

the class ActionScriptResolveTest method testResolveInClass.

public void testResolveInClass() throws Exception {
    String fileText = "class A { function get aaa() {} function foo() {\n" + "  var aaa = a<ref>aa;\n}" + "}";
    JSReferenceExpression ref = (JSReferenceExpression) configureByFileText(fileText, "sample.js2");
    assertTrue(ref.resolve() instanceof JSFunction);
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSFunction(com.intellij.lang.javascript.psi.JSFunction)

Example 5 with JSFunction

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

the class FlexResolveHelper method importClass.

public boolean importClass(final PsiScopeProcessor processor, final PsiNamedElement file) {
    // there is no need to process package stuff at function level
    if (file instanceof JSFunction)
        return true;
    if (file instanceof XmlBackedJSClassImpl) {
        if (!processInlineComponentsInScope((XmlBackedJSClassImpl) file, inlineComponent -> processor.execute(inlineComponent, ResolveState.initial()))) {
            return false;
        }
    }
    final String packageQualifierText = JSResolveUtil.findPackageStatementQualifier(file);
    final Project project = file.getProject();
    GlobalSearchScope scope = JSResolveUtil.getResolveScope(file);
    final MxmlAndFxgFilesProcessor filesProcessor = new MxmlAndFxgFilesProcessor() {

        final PsiManager manager = PsiManager.getInstance(project);

        public void addDependency(final PsiDirectory directory) {
        }

        public boolean processFile(final VirtualFile file, final VirtualFile root) {
            final PsiFile xmlFile = manager.findFile(file);
            if (!(xmlFile instanceof XmlFile))
                return true;
            return processor.execute(XmlBackedJSClassFactory.getXmlBackedClass((XmlFile) xmlFile), ResolveState.initial());
        }
    };
    PsiFile containingFile = file.getContainingFile();
    boolean completion = containingFile.getOriginalFile() != containingFile;
    if (completion) {
        return processAllMxmlAndFxgFiles(scope, project, filesProcessor, null);
    } else {
        if (packageQualifierText != null && packageQualifierText.length() > 0) {
            if (!processMxmlAndFxgFilesInPackage(scope, project, packageQualifierText, filesProcessor))
                return false;
        }
        return processMxmlAndFxgFilesInPackage(scope, project, "", filesProcessor);
    }
}
Also used : XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) JavaScriptSupportLoader(com.intellij.lang.javascript.JavaScriptSupportLoader) XmlFile(com.intellij.psi.xml.XmlFile) JSChangeUtil(com.intellij.lang.javascript.psi.impl.JSChangeUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) FilenameIndex(com.intellij.psi.search.FilenameIndex) ContainerUtil(com.intellij.util.containers.ContainerUtil) ResolveProcessor(com.intellij.lang.javascript.psi.resolve.ResolveProcessor) DirectoryIndex(com.intellij.openapi.roots.impl.DirectoryIndex) Query(com.intellij.util.Query) Project(com.intellij.openapi.project.Project) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) JSResolveHelper(com.intellij.lang.javascript.flex.JSResolveHelper) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) CssString(com.intellij.psi.css.CssString) JSFile(com.intellij.lang.javascript.psi.JSFile) XmlTag(com.intellij.psi.xml.XmlTag) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) com.intellij.lang.javascript.psi.ecmal4(com.intellij.lang.javascript.psi.ecmal4) JSImportHandlingUtil(com.intellij.lang.javascript.psi.resolve.JSImportHandlingUtil) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) JSResolveUtil(com.intellij.lang.javascript.psi.resolve.JSResolveUtil) StringUtil(com.intellij.openapi.util.text.StringUtil) Collection(java.util.Collection) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JSPsiImplUtils(com.intellij.lang.javascript.psi.impl.JSPsiImplUtils) ImportUtils(com.intellij.lang.javascript.flex.ImportUtils) ASTNode(com.intellij.lang.ASTNode) Nullable(org.jetbrains.annotations.Nullable) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) Processor(com.intellij.util.Processor) MxmlJSClassProvider(com.intellij.javascript.flex.mxml.MxmlJSClassProvider) com.intellij.psi(com.intellij.psi) Ref(com.intellij.openapi.util.Ref) VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) XmlFile(com.intellij.psi.xml.XmlFile) CssString(com.intellij.psi.css.CssString) Project(com.intellij.openapi.project.Project) JSFunction(com.intellij.lang.javascript.psi.JSFunction) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

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