Search in sources :

Example 46 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass 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 47 with JSClass

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

the class PropertyProcessor method processClass.

// see ClassProperty test
private void processClass(XmlElementValueProvider valueProvider) throws InvalidPropertyException {
    JSClass jsClass = valueProvider.getJsClass();
    // IDEA-73537, cannot use only valueProvider.getJsClass()
    if (jsClass == null) {
        String trimmed = valueProvider.getTrimmed();
        XmlElement exceptionElement = valueProvider.getElement();
        if (trimmed.isEmpty() && valueProvider.getElement() instanceof XmlTag) {
            // case 1, fx:Class
            final XmlTag propertyTag = (XmlTag) valueProvider.getElement();
            final XmlTag[] propertyTagSubTags = propertyTag.getSubTags();
            if (propertyTagSubTags.length == 1) {
                final XmlTag contentTag = propertyTagSubTags[0];
                exceptionElement = contentTag;
                final XmlElementDescriptor contentTagDescriptor = contentTag.getDescriptor();
                if (contentTagDescriptor instanceof ClassBackedElementDescriptor && AsCommonTypeNames.CLASS.equals(contentTagDescriptor.getQualifiedName())) {
                    trimmed = contentTag.getValue().getTrimmedText();
                }
            }
        }
        if (trimmed.isEmpty()) {
            throw new InvalidPropertyException(exceptionElement, "invalid.class.value");
        }
        final Module module = ModuleUtilCore.findModuleForPsiElement(valueProvider.getElement());
        if (module != null) {
            jsClass = (JSClass) ActionScriptClassResolver.findClassByQNameStatic(trimmed, module.getModuleWithDependenciesAndLibrariesScope(false));
        }
        if (jsClass == null) {
            throw new InvalidPropertyException(exceptionElement, "unresolved.class", trimmed);
        }
    }
    if (InjectionUtil.isProjectComponent(jsClass)) {
        if (ActionScriptClassResolver.isParentClass(jsClass, "spark.components.View")) {
            int projectComponentFactoryId = getProjectComponentFactoryId(jsClass);
            assert projectComponentFactoryId != -1;
            writer.projectClassReference(projectComponentFactoryId);
        } else {
            throw new InvalidPropertyException(valueProvider.getElement(), "class.reference.support.only.skin.class.or.view", jsClass.getQualifiedName());
        }
    } else {
        writer.classReference(jsClass.getQualifiedName());
    }
}
Also used : ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) Module(com.intellij.openapi.module.Module) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 48 with JSClass

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

the class PropertyProcessor method writeClassFactory.

private void writeClassFactory(XmlElementValueProvider valueProvider) throws InvalidPropertyException {
    if (valueProvider instanceof XmlTagValueProvider) {
        XmlTag tag = ((XmlTagValueProvider) valueProvider).getTag();
        XmlTag[] subTags = tag.getSubTags();
        if (subTags.length > 0) {
            processFxComponent(subTags[0], true);
            return;
        }
    }
    String className = valueProvider.getTrimmed();
    if (writeFxComponentReferenceIfProcessed(className) || writeReferenceIfReferenced(className)) {
        return;
    }
    final JSClass jsClass = valueProvider.getJsClass();
    if (jsClass == null) {
        throw new InvalidPropertyException(valueProvider.getElement(), "unresolved.class", valueProvider.getTrimmed());
    }
    final Trinity<Integer, String, Condition<AnnotationBackedDescriptor>> effectiveClassInfo;
    final PsiElement parent = jsClass.getNavigationElement().getParent();
    if (parent instanceof XmlTag && MxmlUtil.isComponentLanguageTag((XmlTag) parent)) {
        // if referenced by inner class name, but inner fx component is not yet processed
        if (parent.getContainingFile().equals(valueProvider.getElement().getContainingFile())) {
            processFxComponent((XmlTag) parent, false);
            return;
        } else {
            effectiveClassInfo = new Trinity<>(-1, "mx.core.UIComponent", null);
        }
    } else {
        effectiveClassInfo = MxmlUtil.computeEffectiveClass(valueProvider.getElement(), jsClass, mxmlWriter.projectComponentReferenceCounter, false);
    }
    if (effectiveClassInfo.first == -1) {
        if (effectiveClassInfo.second != null) {
            if (effectiveClassInfo.second.equals("mx.core.UIComponent")) {
                PsiMetaData psiMetaData = valueProvider.getPsiMetaData();
                if (psiMetaData != null && psiMetaData.getName().equals("itemRenderer") && MxmlUtil.isPropertyOfSparkDataGroup((AnnotationBackedDescriptor) psiMetaData)) {
                    className = MxmlUtil.UNKNOWN_ITEM_RENDERER_CLASS_NAME;
                } else {
                    className = MxmlUtil.UNKNOWN_COMPONENT_CLASS_NAME;
                }
            } else {
                className = effectiveClassInfo.second;
            }
        }
        writeNonProjectUnreferencedClassFactory(className);
    } else {
        writer.documentFactoryReference(effectiveClassInfo.first);
    }
}
Also used : Condition(com.intellij.openapi.util.Condition) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) PsiMetaData(com.intellij.psi.meta.PsiMetaData) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 49 with JSClass

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

the class CreateJSSubclassIntention method invoke.

@Override
public void invoke(@NotNull final Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
    final JSClass jsClass = PsiTreeUtil.getParentOfType(element, JSClass.class);
    if (jsClass == null)
        return;
    final PsiElement parent = jsClass.getParent();
    if (!(parent instanceof JSPackageStatement))
        return;
    final JSPackageStatement jsPackageStatement = (JSPackageStatement) parent;
    final String defaultTemplateName = ActionScriptCreateClassOrInterfaceFix.ACTION_SCRIPT_CLASS_WITH_SUPERS_TEMPLATE_NAME;
    final String className;
    final String packageName;
    final String templateName;
    final PsiDirectory targetDirectory;
    final Collection<String> interfaces;
    final Map<String, Object> templateAttributes;
    final JSClass superClass;
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        className = suggestSubclassName(jsClass.getName());
        packageName = "foo";
        templateName = defaultTemplateName;
        targetDirectory = WriteAction.compute(() -> ActionScriptCreateClassOrInterfaceFix.findOrCreateDirectory(packageName, jsPackageStatement));
        interfaces = jsClass.isInterface() ? Collections.singletonList(jsClass.getQualifiedName()) : Collections.emptyList();
        templateAttributes = Collections.emptyMap();
        superClass = jsClass.isInterface() ? null : jsClass;
    } else {
        CreateClassParameters p = ActionScriptCreateClassOrInterfaceFix.createAndShow(defaultTemplateName, jsClass, suggestSubclassName(jsClass.getName()), true, jsPackageStatement.getQualifiedName(), jsClass, JSBundle.message("new.actionscript.class.dialog.title"), () -> ActionScriptCreateClassOrInterfaceFix.getApplicableTemplates(ActionScriptCreateClassOrInterfaceFix.ACTIONSCRIPT_TEMPLATES_EXTENSIONS, project));
        if (p == null)
            return;
        className = p.getClassName();
        packageName = p.getPackageName();
        templateName = p.getTemplateName();
        targetDirectory = p.getTargetDirectory();
        superClass = ActionScriptCreateClassOrInterfaceFix.calcClass(p.getSuperclassFqn(), element);
        interfaces = p.getInterfacesFqns();
        templateAttributes = new HashMap<>(p.getTemplateAttributes());
    }
    JSClass createdClass = ActionScriptCreateClassOrInterfaceFix.createClass(templateName, className, packageName, superClass, interfaces, targetDirectory, getTitle(jsClass), true, templateAttributes, aClass -> {
        if (aClass != null && !aClass.isInterface() && (jsClass.isInterface() || !interfaces.isEmpty())) {
            new MyImplementMethodsHandler(aClass).execute();
        }
    });
    if (createdClass != null) {
        createdClass.navigate(true);
    }
}
Also used : CreateClassParameters(com.intellij.lang.javascript.validation.fixes.CreateClassParameters) JSPackageStatement(com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement) PsiDirectory(com.intellij.psi.PsiDirectory) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 50 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass 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

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