Search in sources :

Example 1 with JSSuperExpression

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

the class ActionScriptFunctionSignatureChecker method checkConstructorCall.

@Override
public void checkConstructorCall(@NotNull JSCallExpression node, @NotNull JSClass target) {
    if (node instanceof JSNewExpression || node.getMethodExpression() instanceof JSSuperExpression) {
        final JSArgumentList argumentList = node.getArgumentList();
        final JSExpression[] expressions = argumentList != null ? argumentList.getArguments() : JSExpression.EMPTY_ARRAY;
        if (expressions.length > 0) {
            final ActionScriptCreateConstructorFix fix = ActionScriptCreateConstructorFix.createIfApplicable(node);
            registerProblem(node, JSBundle.message("javascript.invalid.number.of.parameters", "0"), fix != null ? new LocalQuickFix[] { fix } : LocalQuickFix.EMPTY_ARRAY);
        }
    } else {
        reportProblemIfNotExpectedCountOfParameters(node, 1, "one");
    }
}
Also used : ActionScriptCreateConstructorFix(com.intellij.lang.javascript.validation.fixes.ActionScriptCreateConstructorFix) JSSuperExpression(com.intellij.lang.javascript.psi.ecmal4.JSSuperExpression) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix)

Example 2 with JSSuperExpression

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

the class ActionScriptCreateConstructorFix method createIfApplicable.

@Nullable
public static ActionScriptCreateConstructorFix createIfApplicable(final JSCallExpression node) {
    final JSClass clazz;
    final JSReferenceExpression reference;
    if (node instanceof JSNewExpression) {
        JSExpression methodExpression = node.getMethodExpression();
        if (!(methodExpression instanceof JSReferenceExpression)) {
            return null;
        }
        PsiElement resolved = ((JSReferenceExpression) methodExpression).resolve();
        if (!(resolved instanceof JSClass) || resolved instanceof XmlBackedJSClass || ((JSClass) resolved).isInterface()) {
            return null;
        }
        clazz = (JSClass) resolved;
        reference = (JSReferenceExpression) methodExpression;
    } else {
        JSExpression methodExpression = node.getMethodExpression();
        if (!(methodExpression instanceof JSSuperExpression)) {
            return null;
        }
        JSClass containingClass = JSResolveUtil.getClassOfContext(node);
        if (containingClass == null) {
            return null;
        }
        clazz = containingClass.getSuperClasses()[0];
        if (clazz.isInterface()) {
            return null;
        }
        reference = (JSReferenceExpression) clazz.findNameIdentifier().getPsi();
    }
    return new ActionScriptCreateConstructorFix(clazz, reference, node);
}
Also used : XmlBackedJSClass(com.intellij.lang.javascript.psi.ecmal4.XmlBackedJSClass) JSSuperExpression(com.intellij.lang.javascript.psi.ecmal4.JSSuperExpression) XmlBackedJSClass(com.intellij.lang.javascript.psi.ecmal4.XmlBackedJSClass) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JSSuperExpression (com.intellij.lang.javascript.psi.ecmal4.JSSuperExpression)2 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)1 XmlBackedJSClass (com.intellij.lang.javascript.psi.ecmal4.XmlBackedJSClass)1 ActionScriptCreateConstructorFix (com.intellij.lang.javascript.validation.fixes.ActionScriptCreateConstructorFix)1 PsiElement (com.intellij.psi.PsiElement)1 Nullable (org.jetbrains.annotations.Nullable)1