Search in sources :

Example 1 with ParamInfo

use of org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo in project intellij-community by JetBrains.

the class DynamicTest method testMethod.

public void testMethod() throws Throwable {
    final GrReferenceExpression referenceExpression = doDynamicFix();
    final PsiType[] psiTypes = PsiUtil.getArgumentTypes(referenceExpression, false);
    final String[] methodArgumentsNames = GroovyNamesUtil.getMethodArgumentsNames(getProject(), psiTypes);
    final List<ParamInfo> pairs = QuickfixUtil.swapArgumentsAndTypes(methodArgumentsNames, psiTypes);
    assertNotNull(getDClassElement().getMethod(referenceExpression.getReferenceName(), QuickfixUtil.getArgumentsTypes(pairs)));
}
Also used : GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) PsiType(com.intellij.psi.PsiType) ParamInfo(org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo)

Example 2 with ParamInfo

use of org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo in project intellij-community by JetBrains.

the class QuickfixUtil method getArgumentsTypes.

public static String[] getArgumentsTypes(List<ParamInfo> listOfPairs) {
    final List<String> result = new ArrayList<>();
    if (listOfPairs == null)
        return ArrayUtil.EMPTY_STRING_ARRAY;
    for (ParamInfo listOfPair : listOfPairs) {
        String type = PsiTypesUtil.unboxIfPossible(listOfPair.type);
        result.add(type);
    }
    return ArrayUtil.toStringArray(result);
}
Also used : ArrayList(java.util.ArrayList) ParamInfo(org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo)

Example 3 with ParamInfo

use of org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo in project intellij-community by JetBrains.

the class QuickfixUtil method swapArgumentsAndTypes.

public static List<ParamInfo> swapArgumentsAndTypes(String[] names, PsiType[] types) {
    List<ParamInfo> result = new ArrayList<>();
    if (names.length != types.length)
        return Collections.emptyList();
    for (int i = 0; i < names.length; i++) {
        String name = names[i];
        final PsiType type = types[i];
        result.add(new ParamInfo(name, type.getCanonicalText()));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ParamInfo(org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo)

Example 4 with ParamInfo

use of org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo in project intellij-community by JetBrains.

the class QuickfixUtil method getArgumentsNames.

public static String[] getArgumentsNames(List<ParamInfo> listOfPairs) {
    final ArrayList<String> result = new ArrayList<>();
    for (ParamInfo listOfPair : listOfPairs) {
        String name = listOfPair.name;
        result.add(name);
    }
    return ArrayUtil.toStringArray(result);
}
Also used : ArrayList(java.util.ArrayList) ParamInfo(org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo)

Example 5 with ParamInfo

use of org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo in project intellij-community by JetBrains.

the class QuickfixUtil method createSettings.

public static DynamicElementSettings createSettings(GrReferenceExpression referenceExpression) {
    DynamicElementSettings settings = new DynamicElementSettings();
    final PsiClass containingClass = findTargetClass(referenceExpression, false);
    assert containingClass != null;
    String className = containingClass.getQualifiedName();
    className = className == null ? containingClass.getContainingFile().getName() : className;
    if (isStaticCall(referenceExpression)) {
        settings.setStatic(true);
    }
    settings.setContainingClassName(className);
    settings.setName(referenceExpression.getReferenceName());
    if (PsiUtil.isCall(referenceExpression)) {
        List<PsiType> unboxedTypes = new ArrayList<>();
        for (PsiType type : PsiUtil.getArgumentTypes(referenceExpression, false)) {
            unboxedTypes.add(TypesUtil.unboxPrimitiveTypeWrapperAndEraseGenerics(type));
        }
        final PsiType[] types = unboxedTypes.toArray(PsiType.createArray(unboxedTypes.size()));
        final String[] names = GroovyNamesUtil.getMethodArgumentsNames(referenceExpression.getProject(), types);
        final List<ParamInfo> infos = swapArgumentsAndTypes(names, types);
        settings.setMethod(true);
        settings.setParams(infos);
    } else {
        settings.setMethod(false);
    }
    return settings;
}
Also used : ArrayList(java.util.ArrayList) DynamicElementSettings(org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ui.DynamicElementSettings) ParamInfo(org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo)

Aggregations

ParamInfo (org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo)7 ArrayList (java.util.ArrayList)4 PsiType (com.intellij.psi.PsiType)1 ListTableModel (com.intellij.util.ui.ListTableModel)1 CellEditorListener (javax.swing.event.CellEditorListener)1 ChangeEvent (javax.swing.event.ChangeEvent)1 TableColumn (javax.swing.table.TableColumn)1 DynamicElementSettings (org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ui.DynamicElementSettings)1 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)1