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