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();
}
}
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;
}
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;
}
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);
}
}
}
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);
}
Aggregations