use of com.intellij.lang.javascript.psi.JSFunction in project intellij-plugins by JetBrains.
the class JSCreateMethodActionBase method prepare.
@Override
public Runnable prepare(Object element, DiagramBuilder builder) {
final JSClass clazz = (JSClass) element;
if (!JSRefactoringUtil.checkReadOnlyStatus(clazz, null, getTemplatePresentation().getText()))
return null;
final JSFunction fakeMethod = JSCreateMethodDialog.createFakeMethod(clazz, createFakeMethodText(clazz), false);
final JSCreateMethodDialog dialog = new JSCreateMethodDialog(clazz, fakeMethod, isForceConstructor());
if (!dialog.showAndGet()) {
return null;
}
return () -> {
final JSFunction method = dialog.createMethod();
importType(clazz, dialog.getReturnTypeText());
for (JSParameterInfo param : dialog.getParameters()) {
importType(clazz, param.getTypeText());
}
final PsiElement added = JSRefactoringUtil.addMemberToTargetClass(clazz, method);
final List<FormatFixer> formatters = new ArrayList<>();
formatters.add(FormatFixer.create(added, FormatFixer.Mode.Reformat));
formatters.addAll(ECMAScriptImportOptimizer.executeNoFormat(clazz.getContainingFile()));
FormatFixer.fixAll(FormatFixer.merge(formatters));
};
}
use of com.intellij.lang.javascript.psi.JSFunction in project intellij-plugins by JetBrains.
the class JstdResolveTest method testResolveTestCaseFunction.
public void testResolveTestCaseFunction() throws Exception {
String fileText = "Test<ref>Case('', {});";
JSReferenceExpression ref = (JSReferenceExpression) configureByFileText(fileText, "sample.js");
final PsiElement resolved = doResolve(ref);
assertTrue(resolved instanceof JSFunction);
}
use of com.intellij.lang.javascript.psi.JSFunction in project intellij-plugins by JetBrains.
the class CodeContext method hasDefaultConstructor.
public static boolean hasDefaultConstructor(@NotNull final JSClass jsClass) {
final JSFunction constructor = jsClass.getConstructor();
final JSParameter[] parameters = constructor == null ? null : constructor.getParameterVariables();
return parameters == null || parameters.length == 0 || parameters[0].isOptional() || parameters[0].isRest();
}
use of com.intellij.lang.javascript.psi.JSFunction in project intellij-plugins by JetBrains.
the class ActionScriptHighlightingTest method checkSetProperty.
private static void checkSetProperty(final PsiElement at) {
final JSFunction parentOfType = PsiTreeUtil.getParentOfType(at, JSFunction.class, false);
assertNotNull(parentOfType);
assertTrue(parentOfType.isSetProperty());
}
use of com.intellij.lang.javascript.psi.JSFunction in project intellij-plugins by JetBrains.
the class JstdTestStructure method newPropertyBasedTestStructure.
@Nullable
public static JstdTestStructure newPropertyBasedTestStructure(@NotNull JSProperty jsProperty) {
PsiElement testMethodNameDeclaration = JsPsiUtils.getPropertyNamePsiElement(jsProperty);
if (testMethodNameDeclaration == null) {
return null;
}
JSFunction testMethodBody = jsProperty.tryGetFunctionInitializer();
String testName = StringUtil.stripQuotesAroundValue(testMethodNameDeclaration.getText());
if (checkTestName(testName)) {
return new JstdTestStructure(testName, testMethodNameDeclaration, null, testMethodBody, jsProperty);
}
return null;
}
Aggregations