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; }
@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); }
@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()); }
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()); } }
@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); } }
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); } }
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); }
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]); } }
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]); } }
@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); }
@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; }
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; }
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(); }
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() : "()"); }
@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); }
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; }
@Override public JSParameter[] getParameters() { return parameters; }
@NotNull @Override public JSParameter[] getParameters() { return parameters; }
@Override public JSParameter createPsi(@NotNull JSParameterStub stub) { return new JSParameterImpl(stub); }
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); }
@Override public JSParameter[] getParameters() { return getStubOrPsiChildren(JSElementTypes.FORMAL_PARAMETER, JSParameter.EMPTY_ARRAY); }
@Override public JSParameter getParameter() { final ASTNode node = getNode().findChildByType(JSElementTypes.FORMAL_PARAMETER); return node != null ? (JSParameter) node.getPsi() : null; }
@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; }
@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 ""; }
CatchParameterUsedVisitor(JSParameter variable) { super(); parameter = variable; }