@Override public void invoke(@NotNull final Project project, final Editor editor, @NotNull final PsiElement psiElement) throws IncorrectOperationException { if(psiElement == null) { return; } final PsiCallExpression call = findParent(PsiCallExpression.class, psiElement); if(call == null) { return; } final PsiMethod psiMethod = call.resolveMethod(); if(psiMethod == null) { return; } final PsiParameterList parameterList = psiMethod.getParameterList(); if(parameterList == null) { return; } final PsiParameter[] params = parameterList.getParameters(); if(params == null) { return; } String prefix = ""; int offset = editor.getCaretModel().getOffset(); final Document doc = editor.getDocument(); for(final PsiParameter p : params) { doc.insertString(offset, prefix+p.getName()); offset += p.getName().length() + prefix.length(); prefix = ", "; } editor.getCaretModel().moveToOffset(offset + 1); }
public InlineParameterDialog(PsiCallExpression methodCall, PsiMethod method, PsiParameter psiParameter, PsiExpression initializer, boolean createLocal) { super(method.getProject(), true); myMethodCall = methodCall; myMethod = method; myParameter = psiParameter; myInitializer = initializer; init(); myCreateLocalCheckbox.setSelected(createLocal); setTitle(InlineParameterHandler.REFACTORING_NAME); }
public void obtainTypeArguments(@NotNull PsiCallExpression callExpression) { final PsiType[] typeArguments = callExpression.getTypeArguments(); if(typeArguments.length > 0) { setTypeArguments(typeArguments); } }
@NotNull @Override public List<InlayInfo> getParameterHints(@NotNull PsiElement element) { if(element instanceof PsiCallExpression) { return ContainerUtil.newArrayList(JavaInlayHintsProvider.createHints((PsiCallExpression) element)); } return Collections.emptyList(); }
@Nullable @Override public MethodInfo getMethodInfo(@NotNull PsiElement element) { if(element instanceof PsiCallExpression) { PsiElement resolvedElement = ((PsiCallExpression) element).resolveMethodGenerics().getElement(); if(resolvedElement instanceof PsiMethod) { return getMethodInfo(resolvedElement); } } return null; }
@Nullable private static Integer getUnambiguousParameterCount(PsiCallExpression call) { int argCount = -1; for(CandidateInfo candidate : PsiResolveHelper.SERVICE.getInstance(call.getProject()).getReferencedMethodCandidates(call, false)) { PsiElement element = candidate.getElement(); if(!(element instanceof PsiMethod)) { return null; } if(((PsiMethod) element).isVarArgs()) { return null; } int count = ((PsiMethod) element).getParameterList().getParametersCount(); if(argCount == -1) { argCount = count; } else if(argCount != count) { return null; } } return argCount; }
@Nullable private static List<PsiMethod> selectMethod(final PsiMethod[] methods, final Trinity<PsiClass, PsiFile, String> previousLineResult) { if(previousLineResult == null || previousLineResult.getThird() == null) { return null; } final List<PsiMethod> result = new SmartList<PsiMethod>(); for(final PsiMethod method : methods) { method.accept(new JavaRecursiveElementVisitor() { @Override public void visitCallExpression(PsiCallExpression callExpression) { final PsiMethod resolved = callExpression.resolveMethod(); if(resolved != null) { if(resolved.getName().equals(previousLineResult.getThird())) { result.add(method); } } } }); } return result; }
@Override public PsiType getDefaultExpectedType(PsiCallExpression methodCall) { ExpectedTypeInfo[] expectedTypes = ExpectedTypesProvider.getExpectedTypes(methodCall, true); if(expectedTypes.length > 0) { return expectedTypes[0].getType(); } return PsiType.NULL; }
@Override public void visitCallExpression(PsiCallExpression callExpression) { mVisitor.report("PsiCallExpression", callExpression.getText(), callExpression); super.visitExpression(callExpression); }
@Override public boolean isAvailable(@NotNull final Project project, final Editor editor, @NotNull final PsiElement psiElement) { PsiCallExpression psiCallExpression = findParent(PsiCallExpression.class, psiElement); return psiCallExpression != null && psiCallExpression.resolveMethod() != null; }
public UnwrapCall(@NotNull PsiCallExpression call, @NotNull String unwrapMethod) { super(call); myCall = call; myUnwrapMethod = unwrapMethod; }
public UnwrapCall(@NotNull PsiCallExpression call, @NotNull String unwrapMethod) { super(call); this.call =call; this.unwrapMethod = unwrapMethod; }
public MethodResolverProcessor(@NotNull PsiCallExpression place, @NotNull PsiExpressionList argumentList, @NotNull PsiFile placeFile) { this(place, placeFile, new PsiConflictResolver[]{new JavaMethodsConflictResolver(argumentList, PsiUtil.getLanguageLevel(placeFile))}); setArgumentList(argumentList); obtainTypeArguments(place); }
@Nullable @Override public Pair<PsiType, ConstraintType> inferTypeConstraintFromCallContext(PsiExpression innerMethodCall, PsiExpressionList parent, PsiCallExpression contextCall, PsiTypeParameter typeParameter) { return null; }
@Override public PsiType getDefaultExpectedType(PsiCallExpression methodCall) { return PsiType.getJavaLangObject(methodCall.getManager(), methodCall.getResolveScope()); }
@Nullable public abstract Pair<PsiType, ConstraintType> inferTypeConstraintFromCallContext(PsiExpression innerMethodCall, PsiExpressionList parent, PsiCallExpression contextCall, PsiTypeParameter typeParameter);
@Override public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException { PsiExpressionList args = null; if(psiElement instanceof PsiMethodCallExpression/* && !(psiElement instanceof JspMethodCall)*/) { args = ((PsiMethodCallExpression) psiElement).getArgumentList(); } else if(psiElement instanceof PsiNewExpression) { args = ((PsiNewExpression) psiElement).getArgumentList(); } if(args != null && !hasRParenth(args)) { int caret = editor.getCaretModel().getOffset(); PsiCallExpression innermostCall = PsiTreeUtil.findElementOfClassAtOffset(psiElement.getContainingFile(), caret - 1, PsiCallExpression.class, false); if(innermostCall == null) { return; } args = innermostCall.getArgumentList(); if(args == null) { return; } int endOffset = -1; PsiElement child = args.getFirstChild(); while(child != null) { if(child instanceof PsiErrorElement) { final PsiErrorElement errorElement = (PsiErrorElement) child; if(errorElement.getErrorDescription().contains("')'")) { endOffset = errorElement.getTextRange().getStartOffset(); break; } } child = child.getNextSibling(); } if(endOffset == -1) { endOffset = args.getTextRange().getEndOffset(); } final PsiExpression[] params = args.getExpressions(); if(params.length > 0 && startLine(editor, args) != startLine(editor, params[0]) && caret < params[0].getTextRange().getStartOffset()) { endOffset = args.getTextRange().getStartOffset() + 1; } if(!DumbService.isDumb(args.getProject())) { Integer argCount = getUnambiguousParameterCount(innermostCall); if(argCount != null && argCount > 0 && argCount < params.length) { endOffset = Math.min(endOffset, params[argCount - 1].getTextRange().getEndOffset()); } } endOffset = CharArrayUtil.shiftBackward(editor.getDocument().getCharsSequence(), endOffset - 1, " \t\n") + 1; editor.getDocument().insertString(endOffset, ")"); } }
public abstract PsiType getDefaultExpectedType(PsiCallExpression methodCall);