Search in sources :

Example 26 with JSFunction

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));
    };
}
Also used : JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) ArrayList(java.util.ArrayList) List(java.util.List) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) JSParameterInfo(com.intellij.lang.javascript.refactoring.changeSignature.JSParameterInfo)

Example 27 with JSFunction

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);
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSFunction(com.intellij.lang.javascript.psi.JSFunction) PsiElement(com.intellij.psi.PsiElement)

Example 28 with 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();
}
Also used : JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSParameter(com.intellij.lang.javascript.psi.JSParameter)

Example 29 with JSFunction

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());
}
Also used : JSFunction(com.intellij.lang.javascript.psi.JSFunction)

Example 30 with JSFunction

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;
}
Also used : JSFunction(com.intellij.lang.javascript.psi.JSFunction) PsiElement(com.intellij.psi.PsiElement) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Nullable(org.jetbrains.annotations.Nullable)

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