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)));
}
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);
}
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;
}
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);
}
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;
}
Aggregations