mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
support for Groovy 2.2's DelegatesTo#genericIndexType
This commit is contained in:
@@ -34,4 +34,14 @@ public class GrAnnotationUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Integer inferIntegerAttribute(@NotNull PsiAnnotation annotation, @NotNull String attributeName) {
|
||||
final PsiAnnotationMemberValue targetValue = annotation.findAttributeValue(attributeName);
|
||||
if (targetValue instanceof PsiLiteral) {
|
||||
final Object value = ((PsiLiteral)targetValue).getValue();
|
||||
if (value instanceof Integer) return (Integer)value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+13
-2
@@ -56,7 +56,7 @@ public class GrDelegatesToUtil {
|
||||
if (signature == null) return null;
|
||||
|
||||
final GrClosureSignatureUtil.ArgInfo<PsiElement>[] map = GrClosureSignatureUtil.mapParametersToArguments(
|
||||
signature, call.getNamedArguments(), call.getExpressionArguments(), call.getClosureArguments(), place, false, true
|
||||
signature, call.getNamedArguments(), call.getExpressionArguments(), call.getClosureArguments(), place, false, false
|
||||
);
|
||||
|
||||
if (map == null) {
|
||||
@@ -112,7 +112,18 @@ public class GrDelegatesToUtil {
|
||||
|
||||
final int parameter = findTargetParameter(delegatesTo, target);
|
||||
if (parameter >= 0) {
|
||||
return map[parameter].type;
|
||||
final PsiType type = map[parameter].type;
|
||||
final Integer index = GrAnnotationUtil.inferIntegerAttribute(delegatesTo, "genericTypeIndex");
|
||||
if (index == null) {
|
||||
return type;
|
||||
}
|
||||
if (type instanceof PsiClassType) {
|
||||
final PsiType[] parameters = ((PsiClassType)type).getParameters();
|
||||
if (parameters.length > index) {
|
||||
return parameters[index];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (value instanceof PsiExpression) {
|
||||
|
||||
+9
@@ -631,6 +631,15 @@ foo(4) {
|
||||
''', 'Integer')
|
||||
}
|
||||
|
||||
void testGenericTypeIndex() {
|
||||
assertScript('''\
|
||||
def foo(@DelegatesTo.Target def map, @DelegatesTo(genericTypeIndex = 1) Closure c) {}
|
||||
|
||||
foo([1:'ab', 2:'cde']) {
|
||||
sub<caret>string(1)
|
||||
}
|
||||
''', 'String')
|
||||
}
|
||||
|
||||
void assertScript(String text, String resolvedClass) {
|
||||
myFixture.configureByText('_a.groovy', text)
|
||||
|
||||
Reference in New Issue
Block a user