Search in sources :

Example 1 with JSParameter

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

the class FlexImplicitUsageProvider method isImplicitUsage.

@Override
public boolean isImplicitUsage(PsiElement element) {
    if (element instanceof XmlAttribute && ((XmlAttribute) element).isNamespaceDeclaration() && JavaScriptSupportLoader.isLanguageNamespace(((XmlAttribute) element).getValue())) {
        return true;
    }
    if (element instanceof JSClass) {
        JSClass clazz = (JSClass) element;
        final Module module = ModuleUtilCore.findModuleForPsiElement(clazz);
        if (module == null || ModuleType.get(module) != FlexModuleType.getInstance())
            return false;
        if (FlashRunConfigurationProducer.isAcceptedMainClass(clazz, module))
            return true;
        if (ActionScriptClassResolver.isParentClass(clazz, FlashRunConfigurationForm.MODULE_BASE_CLASS_NAME))
            return true;
        FlexUnitSupport flexUnitSupport = FlexUnitSupport.getSupport(module);
        if (flexUnitSupport != null && flexUnitSupport.isTestClass(clazz, true))
            return true;
    } else if (element instanceof JSFunction) {
        if (isTestMethod((JSFunction) element))
            return true;
        if (isAnnotatedByUnknownAttribute((JSAttributeListOwner) element))
            return true;
    } else if (element instanceof JSVariable) {
        if (isAnnotatedByUnknownAttribute((JSAttributeListOwner) element))
            return true;
        if (JSResolveUtil.findParent(element) instanceof JSClass) {
            final JSAttributeList varAttrList = ((JSVariable) element).getAttributeList();
            if (varAttrList != null && varAttrList.findAttributeByName(FlexAnnotationNames.EMBED) != null) {
                return true;
            }
        }
    }
    if (element instanceof JSParameter) {
        JSFunction function = PsiTreeUtil.getParentOfType(element, JSFunction.class);
        if (function != null) {
            final JSParameter[] params = function.getParameterVariables();
            if (params.length == 1 && element == params[0]) {
                @NonNls String type = ((JSParameter) element).getTypeString();
                if (type != null)
                    type = JSImportHandlingUtil.resolveTypeName(type, element);
                if (type != null) {
                    if (FlexCommonTypeNames.FLASH_EVENT_FQN.equals(type) || FlexCommonTypeNames.STARLING_EVENT_FQN.equals(type)) {
                        return true;
                    }
                    boolean b = JSResolveUtil.processHierarchy(type, element.getContainingFile(), jsClass -> !FlexCommonTypeNames.FLASH_EVENT_FQN.equals(jsClass.getQualifiedName()) && !FlexCommonTypeNames.STARLING_EVENT_FQN.equals(jsClass.getQualifiedName()), false);
                    if (!b)
                        return true;
                }
            }
        }
    }
    return false;
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) NonNls(org.jetbrains.annotations.NonNls) XmlAttribute(com.intellij.psi.xml.XmlAttribute) JSVariable(com.intellij.lang.javascript.psi.JSVariable) JSFunction(com.intellij.lang.javascript.psi.JSFunction) FlexUnitSupport(com.intellij.lang.javascript.flex.flexunit.FlexUnitSupport) Module(com.intellij.openapi.module.Module) JSAttributeListOwner(com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner) JSParameter(com.intellij.lang.javascript.psi.JSParameter) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 2 with JSParameter

use of com.intellij.lang.javascript.psi.JSParameter 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 3 with JSParameter

use of com.intellij.lang.javascript.psi.JSParameter in project oxy-template-support-plugin by mutant-industries.

the class JsMacroParamSuggestionProvider method getMacroParamSuggestions.

@NotNull
@Override
protected MacroParamSuggestionSet getMacroParamSuggestions() {
    JSParameter[] params;
    if ((params = functionExpression.getParameterVariables()).length == 0) {
        return MacroParamSuggestionSet.empty();
    }
    final MacroParamSuggestionSet result = new MacroParamSuggestionSet();
    submergedCalls = new LinkedList<>();
    String paramsObjectName = params[0].getText();
    /**
     * !! cannot be done via {@link com.intellij.psi.search.searches.ReferencesSearch.search}, which would in some
     * special cases (foreach in foreach) end up in infinite loop - reference search calls type resolver, which makes use of this method
     */
    for (PsiElement elementLocal : getParamReferencesLocal(params[0])) {
        PsiElement element = elementLocal;
        if (!(elementLocal instanceof JSReferenceExpression)) {
            continue;
        }
        if ((elementLocal = elementLocal.getNextSibling()) != null) {
            if (elementLocal.getNode().getElementType() == TokenType.WHITE_SPACE) {
                elementLocal = elementLocal.getNextSibling();
            }
            if (elementLocal != null && elementLocal.getNode().getElementType() == JSTokenTypes.DOT) {
                if ((elementLocal = elementLocal.getNextSibling()) != null) {
                    if (elementLocal.getNode().getElementType() == TokenType.WHITE_SPACE) {
                        elementLocal = elementLocal.getNextSibling();
                    }
                    if (elementLocal != null && elementLocal.getNode().getElementType() == JSTokenTypes.IDENTIFIER) {
                        result.add(new JsMacroParamDescriptor(elementLocal.getText(), macro, getJsParamDoc(elementLocal.getText(), macro), true));
                    }
                }
                continue;
            }
        }
        JSCallExpression macroCall = getMacroCall(element);
        JSReferenceExpression callReference;
        if (macroCall == null || (callReference = PsiTreeUtil.getChildOfType(macroCall, JSReferenceExpression.class)) == null || (element = callReference.resolve()) == null) {
            continue;
        }
        submergedCalls.add(element);
    }
    if (macro.getFirstChild() instanceof JSDocComment) {
        String paramName;
        PsiReference reference;
        PsiElement resolve;
        for (JSDocTag docTag : ((JSDocComment) macro.getFirstChild()).getTags()) {
            if ((reference = docTag.getReference()) != null && (resolve = reference.resolve()) != null && !params[0].isEquivalentTo(resolve) || (paramName = getCommentParameterName(docTag)) == null) {
                continue;
            }
            paramName = paramName.replaceFirst("^" + paramsObjectName + "\\.", "");
            if (result.getByName(paramName) != null) {
                continue;
            }
            result.add(new JsMacroParamDescriptor(paramName, macro, docTag, false));
        }
    }
    return result;
}
Also used : JSDocComment(com.intellij.lang.javascript.psi.jsdoc.JSDocComment) MacroParamSuggestionSet(ool.intellij.plugin.psi.macro.param.MacroParamSuggestionSet) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) PsiReference(com.intellij.psi.PsiReference) JsMacroParamDescriptor(ool.intellij.plugin.psi.macro.param.descriptor.JsMacroParamDescriptor) JSDocTag(com.intellij.lang.javascript.psi.jsdoc.JSDocTag) JSParameter(com.intellij.lang.javascript.psi.JSParameter) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with JSParameter

use of com.intellij.lang.javascript.psi.JSParameter in project oxy-template-support-plugin by mutant-industries.

the class JsMacroParamSuggestionProvider method getJsParamDoc.

@Nullable
private static JSDocTag getJsParamDoc(@NotNull String paramName, @NotNull JSProperty macro) {
    JSFunctionExpression functionExpression = (JSFunctionExpression) macro.getLastChild();
    JSDocComment docComment;
    JSParameter[] referenceParams;
    if (!(macro.getFirstChild() instanceof JSDocComment) || (referenceParams = functionExpression.getParameterVariables()).length == 0) {
        return null;
    }
    String docParamExpectedName = referenceParams[0].getText() + '.' + paramName;
    docComment = (JSDocComment) macro.getFirstChild();
    String commentParameterName;
    for (JSDocTag docTag : docComment.getTags()) {
        if ((commentParameterName = getCommentParameterName(docTag)) == null) {
            continue;
        }
        if (paramName.equals(commentParameterName) || docParamExpectedName.equals(commentParameterName)) {
            return docTag;
        }
    }
    return null;
}
Also used : JSFunctionExpression(com.intellij.lang.javascript.psi.JSFunctionExpression) JSDocComment(com.intellij.lang.javascript.psi.jsdoc.JSDocComment) JSDocTag(com.intellij.lang.javascript.psi.jsdoc.JSDocTag) JSParameter(com.intellij.lang.javascript.psi.JSParameter) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JSParameter (com.intellij.lang.javascript.psi.JSParameter)4 JSFunction (com.intellij.lang.javascript.psi.JSFunction)2 JSDocComment (com.intellij.lang.javascript.psi.jsdoc.JSDocComment)2 JSDocTag (com.intellij.lang.javascript.psi.jsdoc.JSDocTag)2 FlexUnitSupport (com.intellij.lang.javascript.flex.flexunit.FlexUnitSupport)1 JSCallExpression (com.intellij.lang.javascript.psi.JSCallExpression)1 JSFunctionExpression (com.intellij.lang.javascript.psi.JSFunctionExpression)1 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)1 JSVariable (com.intellij.lang.javascript.psi.JSVariable)1 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)1 JSAttributeListOwner (com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner)1 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)1 Module (com.intellij.openapi.module.Module)1 PsiElement (com.intellij.psi.PsiElement)1 PsiReference (com.intellij.psi.PsiReference)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 MacroParamSuggestionSet (ool.intellij.plugin.psi.macro.param.MacroParamSuggestionSet)1 JsMacroParamDescriptor (ool.intellij.plugin.psi.macro.param.descriptor.JsMacroParamDescriptor)1 NonNls (org.jetbrains.annotations.NonNls)1 NotNull (org.jetbrains.annotations.NotNull)1