Search in sources :

Example 21 with JSFunction

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

the class FlexUnitRunnerParameters method doCheck.

private void doCheck(final Project project, final Pair<Module, FlexBuildConfiguration> moduleAndBC) throws RuntimeConfigurationError {
    if (DumbService.getInstance(project).isDumb())
        return;
    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()));
    }
    switch(bc.getTargetPlatform()) {
        case Web:
            break;
        case Desktop:
            FlashRunnerParameters.checkAdlAndAirRuntime(sdk);
            if (bc.getOutputType() == OutputType.Application) {
                FlashRunnerParameters.checkCustomDescriptor(bc.getAirDesktopPackagingOptions(), getBCName(), getModuleName());
            }
            break;
        case Mobile:
            FlashRunnerParameters.checkAdlAndAirRuntime(sdk);
            switch(myAppDescriptorForEmulator) {
                case Android:
                    if (bc.getOutputType() == OutputType.Application) {
                        FlashRunnerParameters.checkCustomDescriptor(bc.getAndroidPackagingOptions(), getBCName(), getModuleName());
                    }
                    break;
                case IOS:
                    if (bc.getOutputType() == OutputType.Application) {
                        FlashRunnerParameters.checkCustomDescriptor(bc.getIosPackagingOptions(), getBCName(), getModuleName());
                    }
                    break;
            }
            break;
    }
    final FlexUnitSupport support = FlexUnitSupport.getSupport(bc, moduleAndBC.first);
    if (support == null) {
        throw new RuntimeConfigurationError(FlexBundle.message("flexunit.not.found.for.bc", bc.getName()));
    }
    if (!support.flexUnit4Present && bc.isPureAs()) {
        throw new RuntimeConfigurationError(FlexBundle.message("cant.execute.flexunit1.for.pure.as.bc"));
    }
    final GlobalSearchScope searchScope = FlexUtils.getModuleWithDependenciesAndLibrariesScope(moduleAndBC.first, bc, true);
    switch(getScope()) {
        case Class:
            getClassToTest(getClassName(), searchScope, support, true);
            break;
        case Method:
            final JSClass classToTest = getClassToTest(getClassName(), searchScope, support, false);
            if (StringUtil.isEmpty(getMethodName())) {
                throw new RuntimeConfigurationError(FlexBundle.message("no.test.method.specified"));
            }
            final JSFunction methodToTest = classToTest.findFunctionByNameAndKind(getMethodName(), JSFunction.FunctionKind.SIMPLE);
            if (methodToTest == null || !support.isTestMethod(methodToTest)) {
                throw new RuntimeConfigurationError(FlexBundle.message("method.not.valid", getMethodName()));
            }
            break;
        case Package:
            if (!JSUtils.packageExists(getPackageName(), searchScope)) {
                throw new RuntimeConfigurationError(FlexBundle.message("package.not.valid", getPackageName()));
            }
            break;
        default:
            assert false : "Unknown scope: " + getScope();
    }
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JSFunction(com.intellij.lang.javascript.psi.JSFunction) FlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration) ModifiableFlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration) Sdk(com.intellij.openapi.projectRoots.Sdk) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 22 with JSFunction

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

the class FlexUnitRunConfiguration method getRefactoringElementListener.

@Override
public RefactoringElementListener getRefactoringElementListener(final PsiElement element) {
    final FlexUnitRunnerParameters params = getRunnerParameters();
    final Module module = ModuleManager.getInstance(getProject()).findModuleByName(params.getModuleName());
    if (!(element instanceof PsiDirectoryContainer) && !(element instanceof JSPackage) && !(element instanceof JSPackageStatement) && (module == null || !module.equals(ModuleUtilCore.findModuleForPsiElement(element)))) {
        return null;
    }
    switch(params.getScope()) {
        case Method:
            if (element instanceof JSFunction) {
                final PsiElement parent = element.getParent();
                if (parent instanceof JSClass && Comparing.strEqual(((JSClass) parent).getQualifiedName(), params.getClassName()) && Comparing.strEqual(((JSFunction) element).getName(), params.getMethodName())) {
                    return new FlexRunConfigRefactoringListener.JSFunctionRefactoringListener(this);
                }
            }
        // no break here!
        case Class:
            if (element instanceof PsiDirectory && FlashRunConfiguration.containsClass(module, ((PsiDirectory) element), params.getClassName())) {
                return new FlexRunConfigRefactoringListener.PsiDirectoryRefactoringListener(this);
            }
            final JSClass jsClass = FlexRefactoringListenerProvider.getJSClass(element);
            if (jsClass != null && Comparing.strEqual(jsClass.getQualifiedName(), params.getClassName())) {
                return new FlexRunConfigRefactoringListener.JSClassRefactoringListener(this);
            }
        // no break here!
        case Package:
            final String currentPackage = params.getScope() == FlexUnitRunnerParameters.Scope.Package ? params.getPackageName() : StringUtil.getPackageName(params.getClassName());
            if ((element instanceof PsiDirectoryContainer || element instanceof JSPackage || element instanceof JSPackageStatement) && Comparing.strEqual(FlexRefactoringListenerProvider.getPackageName(element), currentPackage)) {
                return new FlexRunConfigRefactoringListener.PackageRefactoringListener(this);
            }
    }
    return null;
}
Also used : JSPackageStatement(com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement) JSFunction(com.intellij.lang.javascript.psi.JSFunction) PsiDirectory(com.intellij.psi.PsiDirectory) PsiDirectoryContainer(com.intellij.psi.PsiDirectoryContainer) JSPackage(com.intellij.lang.javascript.psi.ecmal4.JSPackage) Module(com.intellij.openapi.module.Module) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 23 with JSFunction

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

the class FlexPullUpTest method performAction.

private void performAction(String from, String to, final int docCommentPolicy, String[] expectedConflicts, final String[] toPullUp) {
    final JSClassResolver resolver = JSDialectSpecificHandlersFactory.forLanguage(JavaScriptSupportLoader.ECMA_SCRIPT_L4).getClassResolver();
    final JSClass sourceClass = (JSClass) resolver.findClassByQName(from, GlobalSearchScope.projectScope(getProject()));
    assertNotNull("source class not found: " + sourceClass, sourceClass);
    final JSClass targetClass = (JSClass) resolver.findClassByQName(to, GlobalSearchScope.projectScope(getProject()));
    assertNotNull("target class not found: " + targetClass, targetClass);
    assertTrue("Source should be a subclass of target", JSInheritanceUtil.isParentClass(sourceClass, targetClass));
    final List<JSMemberInfo> memberInfos = getMemberInfos(toPullUp, sourceClass, false);
    final JSMemberInfo[] infosArray = JSMemberInfo.getSelected(memberInfos, sourceClass, Conditions.alwaysTrue());
    MultiMap<PsiElement, String> conflicts = JSPullUpConflictsUtil.checkConflicts(infosArray, sourceClass, targetClass, new JSInterfaceContainmentVerifier() {

        @Override
        public boolean checkedInterfacesContain(JSFunction psiMethod) {
            return JSPullUpHelper.checkedInterfacesContain(memberInfos, psiMethod);
        }
    }, JSVisibilityUtil.DEFAULT_OPTIONS);
    ArrayList<String> messages = new ArrayList<>(conflicts.values());
    for (int i = 0; i < messages.size(); i++) {
        messages.set(i, messages.get(i).replaceAll("<[^>]+>", ""));
    }
    assertSameElements(messages, expectedConflicts);
    if (conflicts.isEmpty()) {
        WriteCommandAction.runWriteCommandAction(null, () -> {
            new JSPullUpHelper(sourceClass, targetClass, infosArray, docCommentPolicy).moveMembersToBase();
            myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
        });
        FileDocumentManager.getInstance().saveAllDocuments();
    }
}
Also used : JSClassResolver(com.intellij.lang.javascript.psi.resolve.JSClassResolver) ArrayList(java.util.ArrayList) JSMemberInfo(com.intellij.lang.javascript.refactoring.util.JSMemberInfo) JSPullUpHelper(com.intellij.lang.javascript.refactoring.memberPullUp.JSPullUpHelper) JSInterfaceContainmentVerifier(com.intellij.lang.javascript.refactoring.util.JSInterfaceContainmentVerifier) PostprocessReformattingAspect(com.intellij.psi.impl.source.PostprocessReformattingAspect) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 24 with JSFunction

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

the class ActionScriptResolveTest method testResolveOfGetProperty.

public void testResolveOfGetProperty() throws Exception {
    String fileText = "class A { public function get foo() : String { return \"foo\"; } }\n" + "function zzz() {\n" + "var a : A;\n" + "a.f<ref>oo" + "}";
    PsiReference ref = configureByFileText(fileText, "sample.js2");
    PsiElement resolved = ref.resolve();
    assertTrue(resolved instanceof JSFunction);
}
Also used : JSFunction(com.intellij.lang.javascript.psi.JSFunction) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement)

Example 25 with JSFunction

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

the class ActionScriptImplementedMethodProcessor method processMembers.

@Override
protected void processMembers(@NotNull List<PsiElement> results) {
    JSFunctionCollector functionsCollector = null;
    for (PsiElement _function : results) {
        if (!(_function instanceof JSFunction)) {
            continue;
        }
        final JSFunction function = (JSFunction) _function;
        final String name = function.getName();
        if (name == null)
            continue;
        if (functionsCollector == null) {
            functionsCollector = collectVisibleFunctions();
        }
        JSFunction o = functionsCollector.findFunctionWithTheSameKind(name, function.getKind());
        if (o == null) {
            if (JSPsiImplUtils.isGetterOrSetter(function)) {
                JSVariable var = (JSVariable) JSInheritanceUtil.findMember(name, myJsClass, Fields, null, true);
                if (var != null && ActionScriptResolveUtil.fieldIsImplicitAccessorMethod(function, var)) {
                    continue;
                }
            }
            addNonImplementedFunction(function);
        } else {
            addImplementedFunction(function, o);
        }
    }
}
Also used : JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSVariable(com.intellij.lang.javascript.psi.JSVariable) PsiElement(com.intellij.psi.PsiElement)

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