mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Bug fix: IDEA can not determinate type for synthetic parameter 'it' in validation closure.
This commit is contained in:
+25
-27
@@ -1,54 +1,52 @@
|
||||
package org.jetbrains.plugins.groovy.lang.psi;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiPrimitiveType;
|
||||
import com.intellij.psi.PsiType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.ClosureSyntheticParameter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public abstract class AbstractClosureParameterEnhancer extends GrVariableEnhancer {
|
||||
@Override
|
||||
public PsiType getVariableType(GrVariable variable) {
|
||||
public final PsiType getVariableType(GrVariable variable) {
|
||||
if (!(variable instanceof GrParameter)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
assert variable.isValid();
|
||||
GrClosableBlock closure = variable instanceof ClosureSyntheticParameter
|
||||
? ((ClosureSyntheticParameter)variable).getClosure() : findClosureWithArgument(variable.getParent());
|
||||
if (closure == null) {
|
||||
return null;
|
||||
GrClosableBlock closure;
|
||||
int paramIndex;
|
||||
|
||||
if (variable instanceof ClosureSyntheticParameter) {
|
||||
closure = ((ClosureSyntheticParameter)variable).getClosure();
|
||||
paramIndex = 0;
|
||||
}
|
||||
else {
|
||||
PsiElement eParameterList = variable.getParent();
|
||||
if (!(eParameterList instanceof GrParameterList)) return null;
|
||||
|
||||
PsiElement eClosure = eParameterList.getParent();
|
||||
if (!(eClosure instanceof GrClosableBlock)) return null;
|
||||
|
||||
closure = (GrClosableBlock)eClosure;
|
||||
|
||||
GrParameterList parameterList = (GrParameterList)eParameterList;
|
||||
paramIndex = parameterList.getParameterNumber((GrParameter)variable);
|
||||
}
|
||||
|
||||
assert closure.isValid();
|
||||
PsiType res = getClosureParameterType(closure, paramIndex);
|
||||
|
||||
List<GrParameter> parameters = Arrays.asList(closure.getAllParameters());
|
||||
@SuppressWarnings({"SuspiciousMethodCalls"})
|
||||
int index = parameters.indexOf(variable);
|
||||
assert index >= 0 : parameters + "; " + variable;
|
||||
return TypesUtil.boxPrimitiveType(getClosureParameterType(closure, index), closure.getManager(), closure.getResolveScope());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static GrClosableBlock findClosureWithArgument(@NotNull PsiElement parent) {
|
||||
if (parent instanceof GrParameterList) {
|
||||
GrParameterList list = (GrParameterList)parent;
|
||||
if (list.getParent() instanceof GrClosableBlock) {
|
||||
return (GrClosableBlock)list.getParent();
|
||||
}
|
||||
if (res instanceof PsiPrimitiveType) {
|
||||
return ((PsiPrimitiveType)res).getBoxedType(closure);
|
||||
}
|
||||
return null;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user