Search in sources :

Example 1 with GrMethodDescriptor

use of org.jetbrains.plugins.groovy.refactoring.changeSignature.GrMethodDescriptor in project intellij-community by JetBrains.

the class CreateParameterFromUsageFix method showDialog.

private static void showDialog(final PsiMethod method, final GrReferenceExpression ref, final Project project) {
    final String name = ref.getReferenceName();
    final List<PsiType> types = GroovyExpectedTypesProvider.getDefaultExpectedTypes(ref);
    PsiType unboxed = types.isEmpty() ? null : TypesUtil.unboxPrimitiveTypeWrapper(types.get(0));
    @NotNull final PsiType type = unboxed != null ? unboxed : PsiType.getJavaLangObject(ref.getManager(), ref.getResolveScope());
    if (method instanceof GrMethod) {
        GrMethodDescriptor descriptor = new GrMethodDescriptor((GrMethod) method);
        GrChangeSignatureDialog dialog = new GrChangeSignatureDialog(project, descriptor, true, ref);
        List<GrParameterInfo> parameters = dialog.getParameters();
        parameters.add(createParameterInfo(name, type));
        dialog.setParameterInfos(parameters);
        dialog.show();
    } else if (method != null) {
        JavaChangeSignatureDialog dialog = new JavaChangeSignatureDialog(project, method, false, ref);
        final List<ParameterInfoImpl> parameterInfos = new ArrayList<>(Arrays.asList(ParameterInfoImpl.fromMethod(method)));
        ParameterInfoImpl parameterInfo = new ParameterInfoImpl(-1, name, type, PsiTypesUtil.getDefaultValueOfType(type), false);
        if (!method.isVarArgs()) {
            parameterInfos.add(parameterInfo);
        } else {
            parameterInfos.add(parameterInfos.size() - 1, parameterInfo);
        }
        dialog.setParameterInfos(parameterInfos);
        dialog.show();
    }
}
Also used : GrMethodDescriptor(org.jetbrains.plugins.groovy.refactoring.changeSignature.GrMethodDescriptor) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) ParameterInfoImpl(com.intellij.refactoring.changeSignature.ParameterInfoImpl) NotNull(org.jetbrains.annotations.NotNull) GrChangeSignatureDialog(org.jetbrains.plugins.groovy.refactoring.changeSignature.GrChangeSignatureDialog) GrParameterInfo(org.jetbrains.plugins.groovy.refactoring.changeSignature.GrParameterInfo) JavaChangeSignatureDialog(com.intellij.refactoring.changeSignature.JavaChangeSignatureDialog) ArrayList(java.util.ArrayList) List(java.util.List) PsiType(com.intellij.psi.PsiType)

Aggregations

PsiType (com.intellij.psi.PsiType)1 JavaChangeSignatureDialog (com.intellij.refactoring.changeSignature.JavaChangeSignatureDialog)1 ParameterInfoImpl (com.intellij.refactoring.changeSignature.ParameterInfoImpl)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 NotNull (org.jetbrains.annotations.NotNull)1 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)1 GrChangeSignatureDialog (org.jetbrains.plugins.groovy.refactoring.changeSignature.GrChangeSignatureDialog)1 GrMethodDescriptor (org.jetbrains.plugins.groovy.refactoring.changeSignature.GrMethodDescriptor)1 GrParameterInfo (org.jetbrains.plugins.groovy.refactoring.changeSignature.GrParameterInfo)1