use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class ControlFlowBuilder method buildFlowForClosure.
private void buildFlowForClosure(final GrClosableBlock closure) {
for (GrParameter parameter : closure.getAllParameters()) {
if (myPolicy.isVariableInitialized(parameter)) {
addNode(new ReadWriteVariableInstruction(parameter.getName(), parameter, ReadWriteVariableInstruction.WRITE));
}
}
addNode(new ReadWriteVariableInstruction("owner", closure.getLBrace(), ReadWriteVariableInstruction.WRITE));
PsiElement child = closure.getFirstChild();
while (child != null) {
if (child instanceof GroovyPsiElement) {
((GroovyPsiElement) child).accept(this);
}
child = child.getNextSibling();
}
final GrStatement[] statements = closure.getStatements();
if (statements.length > 0) {
handlePossibleReturn(statements[statements.length - 1]);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class ControlFlowBuilder method findCatch.
@Nullable
private ExceptionInfo findCatch(PsiType thrownType) {
final Iterator<ExceptionInfo> iterator = myCaughtExceptionInfos.descendingIterator();
while (iterator.hasNext()) {
final ExceptionInfo info = iterator.next();
final GrCatchClause clause = info.myClause;
final GrParameter parameter = clause.getParameter();
if (parameter != null) {
final PsiType type = parameter.getType();
if (type.isAssignableFrom(thrownType))
return info;
}
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class GrInnerClassConstructorUtil method addEnclosingInstanceParam.
@NotNull
public static GrParameter[] addEnclosingInstanceParam(@NotNull GrMethod method, @NotNull PsiClass enclosingClass, @NotNull GrParameter[] originalParams, boolean isOptional) {
final GrParameter[] parameters = new GrParameter[originalParams.length + 1];
final PsiClassType enclosingClassType = JavaPsiFacade.getElementFactory(method.getProject()).createType(enclosingClass, PsiSubstitutor.EMPTY);
final GrLightParameter enclosing = new GrLightParameter("enclosing", enclosingClassType, method);
if (isOptional) {
enclosing.setOptional(true);
enclosing.setInitializerGroovy(GroovyPsiElementFactory.getInstance(method.getProject()).createExpressionFromText("null"));
}
parameters[0] = enclosing;
System.arraycopy(originalParams, 0, parameters, 1, originalParams.length);
return parameters;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class AbstractClosureParameterEnhancer method getVariableType.
@Override
public final PsiType getVariableType(GrVariable variable) {
if (!(variable instanceof GrParameter)) {
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);
}
PsiType res = getClosureParameterType(closure, paramIndex);
if (res instanceof PsiPrimitiveType) {
return ((PsiPrimitiveType) res).getBoxedType(closure);
}
return res;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class ClosureParamsEnhancer method findFittingSignatures.
@NotNull
public static List<PsiType[]> findFittingSignatures(GrClosableBlock closure) {
GrCall call = findCall(closure);
if (call == null)
return Collections.emptyList();
List<PsiType[]> expectedSignatures = ContainerUtil.newArrayList();
GroovyResolveResult[] variants = call.getCallVariants(closure);
for (GroovyResolveResult variant : variants) {
expectedSignatures.addAll(inferExpectedSignatures(variant, call, closure));
}
final GrParameter[] parameters = closure.getAllParameters();
return ContainerUtil.findAll(expectedSignatures, types -> types.length == parameters.length);
}
Aggregations