Search in sources :

Example 76 with JSClass

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

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

the class FlexUnitSupport method getSuiteTestClasses.

public Collection<JSClass> getSuiteTestClasses(JSClass suiteClass) {
    if (!SUITE_RUNNER.equals(getCustomRunner(suiteClass)))
        return Collections.emptyList();
    Collection<JSClass> result = new ArrayList<>();
    for (JSField field : suiteClass.getFields()) {
        if (field.getAttributeList() == null)
            continue;
        if (field.getAttributeList().hasModifier(JSAttributeList.ModifierType.STATIC))
            continue;
        if (field.getAttributeList().getAccessType() != JSAttributeList.AccessType.PUBLIC)
            continue;
        final PsiElement typeElement = field.getTypeElement();
        if (!(typeElement instanceof JSReferenceExpression))
            continue;
        final PsiElement type = ((JSReferenceExpression) typeElement).resolve();
        if (!(type instanceof JSClass))
            continue;
        result.add((JSClass) type);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 78 with JSClass

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

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

the class FlexUnitMethodReturnTypeInspection method visitPotentialTestMethod.

protected void visitPotentialTestMethod(JSFunction method, ProblemsHolder holder, FlexUnitSupport support) {
    if (FlexUnitSupport.getCustomRunner((JSClass) method.getParent()) != null)
        return;
    if (method.getKind() != JSFunction.FunctionKind.SIMPLE)
        return;
    if (support.isFlexUnit1Subclass((JSClass) method.getParent()) || support.isFlunitSubclass((JSClass) method.getParent())) {
        return;
    }
    final JSType returnType = method.getReturnType();
    if (returnType != null && !(returnType instanceof JSVoidType)) {
        final ASTNode nameIdentifier = method.findNameIdentifier();
        if (nameIdentifier != null) {
            LocalQuickFix[] fix = canFix(method) ? new LocalQuickFix[] { new ChangeTypeFix(method, "void", "javascript.fix.set.method.return.type") } : LocalQuickFix.EMPTY_ARRAY;
            holder.registerProblem(nameIdentifier.getPsi(), FlexBundle.message("flexunit.inspection.testmethodreturntype.message"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, fix);
        }
    }
}
Also used : ChangeTypeFix(com.intellij.lang.javascript.validation.fixes.ChangeTypeFix) JSType(com.intellij.lang.javascript.psi.JSType) ASTNode(com.intellij.lang.ASTNode) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) JSVoidType(com.intellij.lang.javascript.psi.types.primitives.JSVoidType)

Example 80 with JSClass

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

the class FlexUnitSupport method getSupport.

private static FlexUnitSupport getSupport(final GlobalSearchScope searchScope) {
    PsiElement flexUnit1TestClass = ActionScriptClassResolver.findClassByQNameStatic(FLEX_UNIT_1_TESTCASE_CLASS, searchScope);
    if (!(flexUnit1TestClass instanceof JSClass))
        return null;
    PsiElement flexUnit1TestSuiteClass = ActionScriptClassResolver.findClassByQNameStatic(FLEX_UNIT_1_TESTSUITE_CLASS, searchScope);
    if (!(flexUnit1TestSuiteClass instanceof JSClass)) {
        LOG.warn(FLEX_UNIT_1_TESTCASE_CLASS + " class is present but " + FLEX_UNIT_1_TESTSUITE_CLASS + " is not");
        return null;
    }
    boolean flexUnit4Present = ActionScriptClassResolver.findClassByQNameStatic(FLEX_UNIT_4_CORE_CLASS, searchScope) instanceof JSClass;
    PsiElement flunitTestClass = flexUnit4Present ? ActionScriptClassResolver.findClassByQNameStatic(FLUNIT_TESTCASE_CLASS, searchScope) : null;
    PsiElement flunitTestSuiteClass = (flunitTestClass instanceof JSClass) ? (JSClass) ActionScriptClassResolver.findClassByQNameStatic(FLUNIT_TESTSUITE_CLASS, searchScope) : null;
    return new FlexUnitSupport((JSClass) flexUnit1TestClass, (JSClass) flexUnit1TestSuiteClass, (JSClass) flunitTestClass, (JSClass) flunitTestSuiteClass, flexUnit4Present);
}
Also used : JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) 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