public boolean isDefineFirstCollection(PsiElement element) { PsiElement jsArrayLiteral = element.getParent(); if (null != jsArrayLiteral && jsArrayLiteral instanceof JSArrayLiteralExpression) { PsiElement jsArgumentList = jsArrayLiteral.getParent(); if (null != jsArgumentList && jsArgumentList instanceof JSArgumentList) { PsiElement jsReferenceExpression = jsArgumentList.getPrevSibling(); if (null != jsReferenceExpression && jsReferenceExpression instanceof JSReferenceExpression) { if (jsReferenceExpression.getText().equals(Settings.REQUIREJS_DEFINE_FUNCTION_NAME)) { return true; } } } } return false; }
public static boolean containsTestsInFiles(JSFile file) { JSSourceElement[] statements = file.getStatements(); for(JSSourceElement statement : statements) { if(statement instanceof JSExpressionStatement) { JSExpression expression = ((JSExpressionStatement) statement).getExpression(); if(expression instanceof JSCallExpression) { JSExpression methodExpression = ((JSCallExpression) expression).getMethodExpression(); if(methodExpression instanceof JSReferenceExpression) { JSExpression qualifier = ((JSReferenceExpression) methodExpression).getQualifier(); if(qualifier != null) { continue; } String referencedName = ((JSReferenceExpression) methodExpression).getReferencedName(); if("describe".equals(referencedName)) { JSArgumentList argumentList = ((JSCallExpression) expression).getArgumentList(); if(argumentList != null && argumentList.getArguments().length == 2) { return true; } } } } } } return false; }
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); }
@Override protected void addParameters(Template template, JSReferenceExpression referenceExpression, PsiFile file, Set<JavaScriptFeature> features) { JSCallExpression methodInvokation = (JSCallExpression) referenceExpression.getParent(); final JSArgumentList list = methodInvokation.getArgumentList(); final JSExpression[] expressions = list.getArguments(); int paramCount = expressions.length; for(int i = 0; i < paramCount; ++i) { if(i != 0) { template.addTextSegment(", "); } String var = null; final JSExpression passedParameterValue = expressions[i]; if(passedParameterValue instanceof JSReferenceExpression) { var = ((JSReferenceExpression) passedParameterValue).getReferencedName(); } if(var == null || var.length() == 0) { var = "param" + (i != 0 ? Integer.toString(i + 1) : ""); } final String var1 = var; Expression expression = new MyExpression(var1); template.addVariable(var, expression, expression, true); if(features.contains(JavaScriptFeature.CLASS)) { template.addTextSegment(":"); BaseCreateFix.guessExprTypeAndAddSuchVariable(passedParameterValue, template, var1, file, features); } } }
@Override public JSArgumentList findElementForParameterInfo(final CreateParameterInfoContext context) { JSArgumentList argList = findArgumentList(context.getFile(), context.getOffset()); if(argList != null) { return fillSignaturesForArgumentList(context, argList); } return argList; }
@Nullable public static JSArgumentList findArgumentList(final PsiFile file, final int offset) { JSArgumentList argList = ParameterInfoUtils.findParentOfType(file, offset, JSArgumentList.class); if(argList == null) { final JSCallExpression callExpression = ParameterInfoUtils.findParentOfType(file, offset, JSCallExpression.class); if(callExpression != null) { argList = callExpression.getArgumentList(); } } return argList; }
@Override public void updateParameterInfo(@NotNull final JSArgumentList o, final UpdateParameterInfoContext context) { if(context.getParameterOwner() != o) { context.removeHint(); return; } final int currentParameterIndex = ParameterInfoUtils.getCurrentParameterIndex(o.getNode(), context.getOffset(), JSTokenTypes.COMMA); context.setCurrentParameter(currentParameterIndex); }
private static boolean newExpressionDefinitelyRecurses(JSNewExpression exp, JSFunction method) { final JSArgumentList argumentList = exp.getArgumentList(); if (argumentList != null) { final JSExpression[] args = argumentList.getArguments(); for (final JSExpression arg : args) { if (RecursionUtil.expressionDefinitelyRecurses(arg, method)) { return true; } } } return false; }
@Override public JSArgumentList getArgumentList() { ASTNode node = getNode().findChildByType(JSElementTypes.ARGUMENT_LIST); return node != null ? (JSArgumentList) node.getPsi() : null; }
@Override public JSArgumentList getArgumentList() { final ASTNode node = getNode().findChildByType(JSElementTypes.ARGUMENT_LIST); return node != null ? (JSArgumentList) node.getPsi() : null; }
@Nullable private static JSArgumentList fillSignaturesForArgumentList(final CreateParameterInfoContext context, final @NotNull JSArgumentList argList) { final PsiElement psiElement = argList.getParent(); if(!(psiElement instanceof JSCallExpression)) { return null; } final JSCallExpression parent = (JSCallExpression) psiElement; final JSExpression methodExpression = parent.getMethodExpression(); if(methodExpression instanceof JSReferenceExpression) { final ResolveResult[] resolveResults = ((JSReferenceExpression) methodExpression).multiResolve(true); if(resolveResults.length > 0) { List<JSFunction> items = new ArrayList<JSFunction>(resolveResults.length); Set<String> availableSignatures = new HashSet<String>(); for(ResolveResult r : resolveResults) { PsiElement element = r.getElement(); if(element instanceof JSProperty) { element = ((JSProperty) element).getValue(); } doAddSignature(items, availableSignatures, element); } context.setItemsToShow(ArrayUtil.toObjectArray(items)); return argList; } } else if(methodExpression instanceof JSSuperExpression) { final PsiElement clazz = methodExpression.getReference().resolve(); if(clazz instanceof JSFunction) { context.setItemsToShow(new Object[]{clazz}); return argList; } } return null; }
@Override public void showParameterInfo(@NotNull final JSArgumentList element, final CreateParameterInfoContext context) { context.showHint(element, element.getTextOffset(), this); }
@Override public JSArgumentList findElementForUpdatingParameterInfo(final UpdateParameterInfoContext context) { return findArgumentList(context.getFile(), context.getOffset()); }
@Override @NotNull public JSExpression[] getActualParameters(@NotNull final JSArgumentList jsArgumentList) { return jsArgumentList.getArguments(); }
@Override @NotNull public Class<JSArgumentList> getArgumentListClass() { return JSArgumentList.class; }