Search in sources :

Example 91 with GrParameter

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]);
    }
}
Also used : GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 92 with GrParameter

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;
}
Also used : GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) Nullable(org.jetbrains.annotations.Nullable)

Example 93 with GrParameter

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;
}
Also used : GrLightParameter(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightParameter) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) NotNull(org.jetbrains.annotations.NotNull)

Example 94 with GrParameter

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;
}
Also used : GrParameterList(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList) PsiPrimitiveType(com.intellij.psi.PsiPrimitiveType) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) ClosureSyntheticParameter(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.ClosureSyntheticParameter) PsiElement(com.intellij.psi.PsiElement) PsiType(com.intellij.psi.PsiType)

Example 95 with GrParameter

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);
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)99 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)22 NotNull (org.jetbrains.annotations.NotNull)20 PsiElement (com.intellij.psi.PsiElement)19 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)19 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)18 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)16 GrParameterList (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList)14 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)13 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)12 ArrayList (java.util.ArrayList)11 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)10 TextRange (com.intellij.openapi.util.TextRange)9 GrOpenBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock)9 Nullable (org.jetbrains.annotations.Nullable)8 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)7 Project (com.intellij.openapi.project.Project)6 IncorrectOperationException (com.intellij.util.IncorrectOperationException)6 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)6 GrField (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)6