Search in sources :

Example 41 with JSClass

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

the class FlexUnitSuiteInspectionBase method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new FlexUnitInspectionVisitor() {

        @Override
        public void visitJSClass(JSClass aClass) {
            FlexUnitSupport support = getFlexUnitSupport(aClass);
            if (support == null || !support.isSuite(aClass))
                return;
            visitSuite(aClass, holder, support);
        }
    };
}
Also used : FlexUnitSupport(com.intellij.lang.javascript.flex.flexunit.FlexUnitSupport) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) NotNull(org.jetbrains.annotations.NotNull)

Example 42 with JSClass

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

the class ActionScriptTypeChecker method checkExpressionIsAssignableToVariable.

@Override
public void checkExpressionIsAssignableToVariable(JSVariable p, final JSExpression expr, PsiFile containingFile, @PropertyKey(resourceBundle = JSBundle.BUNDLE) String problemKey, boolean allowChangeVariableTypeFix) {
    final JSType type = p.getType();
    Pair<Annotation, String> annotationAndExprType = checkExpressionIsAssignableToType(expr, type, problemKey, allowChangeVariableTypeFix ? p : null);
    if (annotationAndExprType != null && p.getParent() instanceof JSParameterList && expr.getParent() instanceof JSArgumentList && !JSCommonTypeNames.VOID_TYPE_NAME.equals(annotationAndExprType.second)) {
        JSFunction method = (JSFunction) p.getParent().getParent();
        JSFunction topMethod = JSInheritanceUtil.findTopMethods(method).iterator().next();
        annotationAndExprType.first.registerFix(new ChangeSignatureFix(topMethod, (JSArgumentList) expr.getParent()));
    }
    PsiElement _fun;
    if (annotationAndExprType == null && type != null && FUNCTION_CLASS_NAME.equals(type.getResolvedTypeText()) && p instanceof JSParameter && isAddEventListenerMethod((JSFunction) p.getParent().getParent()) && ((expr instanceof JSReferenceExpression && (_fun = ((JSReferenceExpression) expr).resolve()) instanceof JSFunction) || (expr instanceof JSFunctionExpression && (_fun = expr) != null))) {
        JSFunction fun = (JSFunction) _fun;
        JSParameterList parameterList = fun.getParameterList();
        if (parameterList != null) {
            JSParameter[] parameters = parameterList.getParameterVariables();
            boolean invalidArgs = parameters.length == 0;
            if (!invalidArgs && parameters.length > 1) {
                for (int i = parameters.length - 1; i > 0; --i) {
                    if (!parameters[i].isRest() && parameters[i].getInitializer() == null) {
                        invalidArgs = true;
                        break;
                    }
                }
            }
            Computable.NotNullCachedComputable<JSParameterList> expectedParameterListForEventListener = new Computable.NotNullCachedComputable<JSParameterList>() {

                @NotNull
                @Override
                protected JSParameterList internalCompute() {
                    JSClass jsClass = calcNontrivialExpectedEventType(expr);
                    ASTNode treeFromText = JSChangeUtil.createJSTreeFromText(expr.getProject(), "function f(event:" + (jsClass != null ? jsClass.getQualifiedName() : FlexCommonTypeNames.FLASH_EVENT_FQN) + ") {}", JavaScriptSupportLoader.ECMA_SCRIPT_L4);
                    return ((JSFunction) treeFromText.getPsi()).getParameterList();
                }
            };
            if (invalidArgs) {
                PsiElement expr_;
                if (expr instanceof JSFunctionExpression) {
                    expr_ = ((JSFunctionExpression) expr).getParameterList();
                } else {
                    expr_ = expr;
                }
                registerProblem(expr_, JSBundle.message("javascript.callback.signature.mismatch"), ProblemHighlightType.WEAK_WARNING, new ChangeSignatureFix(fun, expectedParameterListForEventListener));
            } else {
                final JSClass expectedEventClass = calcNontrivialExpectedEventType(expr);
                JSType paramType = parameters[0].getType();
                final String actualParameterType = paramType != null ? paramType.getResolvedTypeText() : null;
                if (expectedEventClass == null) {
                    if (!JSResolveUtil.isAssignableType(FlexCommonTypeNames.FLASH_EVENT_FQN, actualParameterType, parameters[0]) && !JSResolveUtil.isAssignableType(FlexCommonTypeNames.STARLING_EVENT_FQN, actualParameterType, parameters[0])) {
                        registerProblem(expr instanceof JSFunctionExpression ? parameters[0] : expr, JSBundle.message("javascript.callback.signature.mismatch"), ProblemHighlightType.WEAK_WARNING, new ChangeSignatureFix(fun, expectedParameterListForEventListener));
                    }
                } else {
                    if (!JSResolveUtil.isAssignableType(actualParameterType, expectedEventClass.getQualifiedName(), parameters[0])) {
                        registerProblem(expr instanceof JSFunctionExpression ? parameters[0] : expr, JSBundle.message("javascript.callback.signature.mismatch.event.class", expectedEventClass.getQualifiedName()), ProblemHighlightType.WEAK_WARNING, new ChangeSignatureFix(fun, expectedParameterListForEventListener));
                    }
                }
            }
        }
    }
}
Also used : ChangeSignatureFix(com.intellij.lang.javascript.validation.fixes.ChangeSignatureFix) Annotation(com.intellij.lang.annotation.Annotation) ASTNode(com.intellij.lang.ASTNode) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) Computable(com.intellij.openapi.util.Computable)

Example 43 with JSClass

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

the class JSImplicitlyInternalDeclarationInspection method process.

private static void process(final JSNamedElement node, final ProblemsHolder holder) {
    if (!DialectDetector.isActionScript(node))
        return;
    JSFunction fun = PsiTreeUtil.getParentOfType(node, JSFunction.class);
    if (fun != null)
        return;
    ASTNode nameIdentifier = node.findNameIdentifier();
    if (nameIdentifier == null)
        return;
    JSClass clazz = JSResolveUtil.getClassOfContext(node);
    if (clazz == null) {
        PsiElement parent = JSResolveUtil.findParent(node);
        if (!(parent instanceof JSPackageStatement))
            return;
    }
    JSAttributeList attributeList = ((JSAttributeListOwner) node).getAttributeList();
    JSAttributeList.AccessType accessType = attributeList != null ? attributeList.getAccessType() : null;
    if (accessType == JSAttributeList.AccessType.PACKAGE_LOCAL && attributeList.findAccessTypeElement() == null && attributeList.getNamespaceElement() == null && !JSResolveUtil.isConstructorFunction(node)) {
        holder.registerProblem(nameIdentifier.getPsi(), FlexBundle.message("js.implicitly.internal.declaration.problem"), new LocalQuickFix() {

            @NotNull
            @Override
            public String getFamilyName() {
                return FlexBundle.message("js.implicitly.internal.declaration.problem.add.internal.fix");
            }

            @Override
            public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
                PsiElement anchor = descriptor.getPsiElement();
                JSChangeVisibilityUtil.setVisibility((JSAttributeListOwner) anchor.getParent(), JSAttributeList.AccessType.PACKAGE_LOCAL);
            }
        });
    }
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) JSPackageStatement(com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) ASTNode(com.intellij.lang.ASTNode) JSAttributeListOwner(com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 44 with JSClass

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

the class ActionScriptGenerateDelegatesHandler method findCandidateFields.

private static Collection<JSField> findCandidateFields(JSClass clazz) {
    Collection<JSField> result = new ArrayList<>();
    for (JSField field : clazz.getFields()) {
        JSType type = field.getType();
        JSClass fieldType = type != null ? type.resolveClass() : null;
        if (fieldType != null && !ArrayUtil.contains(fieldType.getQualifiedName(), PRIMITIVE_TYPES) && !JSInheritanceUtil.isParentClass(clazz, fieldType, false)) {
            result.add(field);
        }
    }
    return result;
}
Also used : JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 45 with JSClass

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

the class ActionScriptGenerateEventHandler method isEventClass.

public static boolean isEventClass(final JSClass jsClass) {
    final PsiElement eventClass = ActionScriptClassResolver.findClassByQNameStatic(FlexCommonTypeNames.FLASH_EVENT_FQN, jsClass);
    if ((eventClass instanceof JSClass) && JSInheritanceUtil.isParentClass(jsClass, (JSClass) eventClass)) {
        return true;
    }
    final PsiElement eventClass2 = ActionScriptClassResolver.findClassByQNameStatic(FlexCommonTypeNames.STARLING_EVENT_FQN, jsClass);
    if ((eventClass2 instanceof JSClass) && JSInheritanceUtil.isParentClass(jsClass, (JSClass) eventClass2)) {
        return true;
    }
    return false;
}
Also used : JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement)

Aggregations

JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)141 PsiElement (com.intellij.psi.PsiElement)65 Nullable (org.jetbrains.annotations.Nullable)27 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)23 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)22 JSFunction (com.intellij.lang.javascript.psi.JSFunction)18 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)18 Module (com.intellij.openapi.module.Module)17 XmlFile (com.intellij.psi.xml.XmlFile)17 Project (com.intellij.openapi.project.Project)16 PsiFile (com.intellij.psi.PsiFile)16 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)15 ArrayList (java.util.ArrayList)14 PsiDirectory (com.intellij.psi.PsiDirectory)11 XmlTag (com.intellij.psi.xml.XmlTag)11 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)8 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)8 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)7