Java 类com.intellij.lang.javascript.psi.JSParameter 实例源码

项目:consulo-unity3d    文件:UnityScriptEventFunctionLineMarkerProvider.java   
private static boolean isEqualParameters(Map<String, String> funcParameters, JSFunction function)
{
    JSParameter[] parameters = function.getParameterList().getParameters();
    if(parameters.length == 0)
    {
        return true;
    }
    if(parameters.length != funcParameters.size())
    {
        return false;
    }

    /*int i = 0;
    for(DotNetTypeRef expectedTypeRef : funcParameters.values())
    {
        JSParameter parameter = parameters[i++];

        if(!CSharpTypeUtil.isTypeEqual(parameter.toTypeRef(true), expectedTypeRef, parameter))
        {
            return false;
        }
    }   */
    return true;
}
项目:consulo-javascript    文件:JavaScriptLambdaExpressionImpl.java   
@Override
@RequiredReadAction
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place)
{
    if(lastParent != null && lastParent.getParent() == this)
    {
        final JSParameter[] params = getParameterList().getParameters();
        for(JSParameter param : params)
        {
            if(!processor.execute(param, state))
            {
                return false;
            }
        }

        boolean b = JSResolveUtil.processDeclarationsInScope(this, processor, state, lastParent, place);
        if(b)
        {
            processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
        }
        return b;
    }

    return processor.execute(this, state);
}
项目:consulo-javascript    文件:JSParameterInfoHandler.java   
@Override
public void updateUI(final JSFunction p, final ParameterInfoUIContext context)
{
    final JSParameterList parameterList = p.getParameterList();
    final JSParameter[] params = parameterList != null ? parameterList.getParameters() : new JSParameter[0];
    final int currentParameterIndex = context.getCurrentParameterIndex() >= 0 ? context.getCurrentParameterIndex() : params.length;
    final JSParameter parameter = currentParameterIndex < params.length ? params[currentParameterIndex] : null;

    final SignatureInfo signatureInfo = buildSignature(params, false, currentParameterIndex);
    final String name = signatureInfo.text;

    final String currentParameterSignature = parameter != null ? getSignatureForParameter(parameter, false) : null;
    int highlightStart = parameter != null ? signatureInfo.selectedParameterStart : 0;
    int highlightEnd = parameter != null ? highlightStart + currentParameterSignature.length() : 0;
    context.setupUIComponentPresentation(name, highlightStart, highlightEnd, false, false, false, context.getDefaultParameterColor());
}
项目:consulo-javascript    文件:JSUntypedDeclarationInspection.java   
private static void process(final JSNamedElement node, final ProblemsHolder holder)
{
    if(node.getContainingFile().getLanguage() != JavaScriptSupportLoader.ECMA_SCRIPT_L4)
    {
        return;
    }
    PsiElement nameIdentifier = node.getNameIdentifier();

    if(nameIdentifier != null &&
            JSPsiImplUtils.getTypeFromDeclaration(node) == null &&
            (!(node instanceof JSParameter) || !((JSParameter) node).isRest()))
    {
        holder.registerProblem(nameIdentifier, JavaScriptBundle.message(node instanceof JSFunction ? "js.untyped.function.problem" : "js.untyped" +
                ".variable.problem", nameIdentifier.getText()), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new AddTypeToDclFix());
    }
}
项目:consulo-javascript    文件:ParameterNamingConventionJSInspection.java   
@Override public void visitJSFunctionDeclaration(JSFunction function) {
    super.visitJSFunctionDeclaration(function);
    final JSParameterList parameterList = function.getParameterList();
    if (parameterList == null) {
        return;
    }
    final JSParameter[] parameters = parameterList.getParameters();
    for (JSVariable variable : parameters) {
        final String name = variable.getName();
        if (name == null) {
            continue;
        }
        if (isValid(name)) {
            continue;
        }
        registerVariableError(variable);
    }
}
项目:consulo-javascript    文件:UnusedCatchParameterJSInspection.java   
private void checkCatchSection(JSCatchBlock section) {
    final JSParameter param = section.getParameter();
    final JSStatement block = section.getStatement();
    if (param == null || block == null) {
        return;
    }
    @NonNls final String paramName = param.getName();
    if ("ignore".equals(paramName) || "ignored".equals(paramName)) {
        return;
    }
    if (m_ignoreCatchBlocksWithComments) {
        final PsiElement[] children = block.getChildren();
        for (final PsiElement child : children) {
            if (child instanceof PsiComment) {
                return;
            }
        }
    }
    final CatchParameterUsedVisitor visitor =
            new CatchParameterUsedVisitor(param);
    block.accept(visitor);
    if (!visitor.isUsed()) {
        registerVariableError(param);
    }
}
项目:needsmoredojo    文件:ImportReorderer.java   
public void doSwap(PsiElement source, Editor editor, AMDPsiUtil.Direction direction)
{
    PsiElement[] defines = getSourceAndDestination(source, direction);

    if(defines == null || defines.length == 0)
    {
        return;
    }

    // get the parameter element
    JSArgumentList list = (JSArgumentList) defines[0].getParent().getParent();
    DefineStatement items = new DefineResolver().getDefineStatementItemsFromArguments(list.getArguments(), null);

    int sourceIndex = PsiUtil.getIndexInParent(defines[0]);
    int destinationIndex = PsiUtil.getIndexInParent(defines[1]);
    JSParameter[] parameterList = items.getFunction().getParameters();

    if(sourceIndex >= parameterList.length || destinationIndex >= parameterList.length)
    {
        // we're moving into a plugin's position
        return;
    }

    PsiElement[] parameters = new PsiElement[] { parameterList[sourceIndex], parameterList[destinationIndex] };

    PsiElement[] elementsWithPositions = reorder(defines[0], defines[1]);
    reorder(parameters[0], parameters[1]);

    editor.getCaretModel().moveToOffset(elementsWithPositions[0].getTextOffset());
    editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
}
项目:needsmoredojo    文件:MockJSFunction.java   
public MockJSFunction(String[] parameters) {
    super(mock(ASTNode.class));

    this.parameters = new JSParameter[parameters.length];
    for(int i=0;i<parameters.length;i++)
    {
        this.parameters[i] = new MockJSParameter(parameters[i]);
    }
}
项目:needsmoredojo    文件:MockJSFunctionExpression.java   
public MockJSFunctionExpression(String[] parameters)
{
    super(mock(ASTNode.class));

    function = new MockJSFunction(parameters);

    this.parameters = new JSParameter[parameters.length];
    for(int i=0;i<parameters.length;i++)
    {
        this.parameters[i] = new MockJSParameter(parameters[i]);
    }
}
项目:consulo-javascript    文件:JSParameterElementType.java   
@RequiredReadAction
@Override
public JSParameterStub createStub(@NotNull JSParameter psi, StubElement parentStub)
{
    String name = psi.getName();
    int flags = JSParameterStubImpl.buildFlags(psi);
    String typeString = psi.getTypeString();
    String initializerText = psi.getInitializerText();
    String qualifiedName = psi.getQualifiedName();
    return new JSParameterStubImpl(name, flags, typeString, initializerText, qualifiedName, parentStub, this);
}
项目:consulo-javascript    文件:JSCatchBlockImpl.java   
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent,
        @NotNull PsiElement place)
{
    if(lastParent != null)
    {
        final JSParameter param = getParameter();
        if(param != null)
        {
            return processor.execute(param, state);
        }
    }

    return true;
}
项目:consulo-javascript    文件:JSParameterInfoHandler.java   
private static
@NotNull
SignatureInfo buildSignature(final JSParameter[] params, final boolean skipType, int selectedParameterIndex)
{
    SignatureInfo info = new SignatureInfo();
    if(params.length > 0)
    {
        StringBuilder result = new StringBuilder();
        for(int i = 0; i < params.length; ++i)
        {
            if(result.length() > 0)
            {
                result.append(", ");
            }
            if(selectedParameterIndex == i)
            {
                info.selectedParameterStart = result.length();
            }
            result.append(getSignatureForParameter(params[i], skipType));
        }

        info.text = result.toString();
    }
    else
    {
        info.text = CodeInsightBundle.message("parameter.info.no.parameters");
    }
    return info;
}
项目:consulo-javascript    文件:JSParameterInfoHandler.java   
public static String getSignatureForParameter(final JSParameter p, boolean skipType)
{
    final String s = skipType ? null : p.getTypeString();

    if(s != null && s.length() > 0)
    {
        final boolean ecmal4 = p.getContainingFile().getLanguage() == JavaScriptSupportLoader.ECMA_SCRIPT_L4;
        String result;

        if(ecmal4)
        {
            if(p.isRest())
            {
                result = "...";
            }
            else
            {
                result = p.getName() + ":" + s;
            }
        }
        else
        {
            result = "[" + s + "] " + p.getName();
        }
        final String initializerText = p.getInitializerText();
        if(initializerText != null)
        {
            result += " = " + initializerText;
        }
        return result;
    }
    return p.getName();
}
项目:consulo-javascript    文件:BaseCreateMethodsFix.java   
protected String buildParameterList(final JSParameterList parameterList, final T fun)
{
    if(parameterList != null)
    {
        for(JSParameter param : parameterList.getParameters())
        {
            final String s = param.getTypeString();
            if(s != null)
            {
                importType(s, fun);
            }
        }
    }
    return (parameterList != null ? parameterList.getText() : "()");
}
项目:consulo-javascript    文件:ParametersPerFunctionJSInspection.java   
@Override public void visitJSFunctionDeclaration(@NotNull JSFunction function) {
    final JSParameterList parameterList = function.getParameterList();
    if (parameterList == null) {
        return;
    }
    final JSParameter[] parameters = parameterList.getParameters();
    if (parameters == null) {
        return;
    }
    final int numParameters = parameters.length;
    if (numParameters <= getLimit()) {
        return;
    }
    registerFunctionError(function);
}
项目:needsmoredojo    文件:NearestAMDImportLocator.java   
protected @Nullable JSElement getParameter(PsiElement elementAtCaretPosition, DefineStatement defineStatement)
{
    iterations += 1;

    if(elementAtCaretPosition == null || iterations > 10)
    {
        return null;
    }

    if(elementAtCaretPosition.getPrevSibling() instanceof JSParameter)
    {
        return (JSElement) elementAtCaretPosition.getPrevSibling();
    }

    // I know I know ... but this accounts for the case where the cursor is right after the comma so it's a special case
    if(elementAtCaretPosition.getPrevSibling() != null && elementAtCaretPosition.getPrevSibling().getPrevSibling() instanceof JSParameter)
    {
        return (JSElement) elementAtCaretPosition.getPrevSibling().getPrevSibling();
    }

    if(elementAtCaretPosition.getParent() instanceof JSParameter)
    {
        return (JSElement) elementAtCaretPosition.getParent();
    }

    // assume the caret element is a define literal
    JSElement define = getDefineLiteral(elementAtCaretPosition, defineStatement);
    if(define == null)
    {
        return null;
    }

    int defineIndex = getIndexOfDefine(defineStatement, define);
    if(defineIndex >= defineStatement.getFunction().getParameters().length)
    {
        return null;
    }


    JSElement parameter = defineStatement.getFunction().getParameters()[defineIndex];

    return parameter;
}
项目:needsmoredojo    文件:MockJSFunction.java   
@Override
public JSParameter[] getParameters()
{
    return parameters;
}
项目:needsmoredojo    文件:MockJSFunctionExpression.java   
@NotNull
@Override
public JSParameter[] getParameters()
{
    return parameters;
}
项目:consulo-javascript    文件:JSParameterElementType.java   
@Override
public JSParameter createPsi(@NotNull JSParameterStub stub)
{
    return new JSParameterImpl(stub);
}
项目:consulo-javascript    文件:JSParameterStubImpl.java   
public static int buildFlags(final JSParameter clazz)
{
    final int i = JSVariableStubBaseImpl.buildFlags(clazz);
    return i | (clazz.isRest() ? REST_MASK : 0) | (clazz.isOptional() ? OPTIONAL_MASK : 0);
}
项目:consulo-javascript    文件:JSParameterListImpl.java   
@Override
public JSParameter[] getParameters()
{
    return getStubOrPsiChildren(JSElementTypes.FORMAL_PARAMETER, JSParameter.EMPTY_ARRAY);
}
项目:consulo-javascript    文件:JSCatchBlockImpl.java   
@Override
public JSParameter getParameter()
{
    final ASTNode node = getNode().findChildByType(JSElementTypes.FORMAL_PARAMETER);
    return node != null ? (JSParameter) node.getPsi() : null;
}
项目:consulo-javascript    文件:OverrideMethodsFix.java   
@Override
protected String buildFunctionBodyText(final String retType, final JSParameterList parameterList, final JSFunction func)
{
    @NonNls String functionText = "";
    functionText += "{\n";

    if(!"void".equals(retType))
    {
        functionText += "  return";
    }
    else
    {
        functionText += " ";
    }

    functionText += " super." + func.getName();

    if(func.isGetProperty())
    {

    }
    else if(func.isSetProperty())
    {
        functionText += " = " + parameterList.getParameters()[0].getName();
    }
    else
    {
        functionText += "(";
        boolean first = true;
        for(JSParameter param : parameterList.getParameters())
        {
            if(!first)
            {
                functionText += ",";
            }
            first = false;
            functionText += param.getName();
        }
        functionText += ")";
    }

    functionText += JSChangeUtil.getSemicolon(func.getProject()) + "\n}";
    return functionText;
}
项目:consulo-javascript    文件:JavaScriptFindUsagesProvider.java   
@Override
@NotNull
public String getType(@NotNull PsiElement element)
{
    if(element instanceof JSFunction)
    {
        return JavaScriptBundle.message("javascript.language.term.function");
    }
    if(element instanceof JSClass)
    {
        return JavaScriptBundle.message("javascript.language.term.class");
    }
    if(element instanceof JSNamespaceDeclaration)
    {
        return JavaScriptBundle.message("javascript.language.term.namespace");
    }
    if(element instanceof JSParameter)
    {
        return JavaScriptBundle.message("javascript.language.term.parameter");
    }
    if(element instanceof JSProperty)
    {
        return JavaScriptBundle.message("javascript.language.term.property");
    }
    if(element instanceof JSVariable)
    {
        return JavaScriptBundle.message("javascript.language.term.variable");
    }
    if(element instanceof JSLabeledStatement)
    {
        return JavaScriptBundle.message("javascript.language.term.label");
    }
    if(element instanceof JSDefinitionExpression)
    {
        return JavaScriptBundle.message("javascript.language.term.value");
    }
    if(element instanceof XmlTag)
    {
        return JavaScriptBundle.message("javascript.language.term.tag");
    }
    if(element instanceof XmlToken)
    {
        return JavaScriptBundle.message("javascript.language.term.attribute.value");
    }
    if(element instanceof JSPackageStatement)
    {
        return JavaScriptBundle.message("javascript.language.term.package");
    }
    return "";
}
项目:consulo-javascript    文件:CatchParameterUsedVisitor.java   
CatchParameterUsedVisitor(JSParameter variable) {
    super();
    parameter = variable;
}