Search in sources :

Example 1 with GrCatchClause

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrCatchClause in project intellij-community by JetBrains.

the class TrySurrounder method getSurroundSelectionRange.

@Override
protected TextRange getSurroundSelectionRange(GroovyPsiElement element) {
    assert element instanceof GrTryCatchStatement;
    int endOffset = element.getTextRange().getEndOffset();
    GrTryCatchStatement tryCatchStatement = (GrTryCatchStatement) element;
    GrCatchClause[] catchClauses = tryCatchStatement.getCatchClauses();
    if (catchClauses != null && catchClauses.length > 0) {
        GrParameter parameter = catchClauses[0].getParameter();
        if (parameter == null) {
            GrOpenBlock block = catchClauses[0].getBody();
            assert block != null;
            endOffset = block.getTextRange().getEndOffset();
        } else {
            endOffset = parameter.getTextRange().getStartOffset();
            parameter.getParent().getNode().removeChild(parameter.getNode());
        }
    } else {
        GrOpenBlock block = tryCatchStatement.getTryBlock();
        if (block != null) {
            GrStatement[] statements = block.getStatements();
            if (statements.length > 0) {
                endOffset = statements[0].getTextRange().getStartOffset();
            }
        }
    }
    return new TextRange(endOffset, endOffset);
}
Also used : TextRange(com.intellij.openapi.util.TextRange) GrTryCatchStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrTryCatchStatement) GrCatchClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrCatchClause) GrOpenBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)

Example 2 with GrCatchClause

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrCatchClause in project intellij-community by JetBrains.

the class GrParameterImpl method getTypeGroovy.

@Override
@Nullable
public PsiType getTypeGroovy() {
    final PsiType declaredType = getDeclaredType();
    if (declaredType != null)
        return declaredType;
    if (isVarArgs()) {
        PsiClassType type = TypesUtil.getJavaLangObject(this);
        return new PsiEllipsisType(type);
    }
    PsiElement parent = getParent();
    if (parent instanceof GrForInClause) {
        GrExpression iteratedExpression = ((GrForInClause) parent).getIteratedExpression();
        if (iteratedExpression == null)
            return null;
        PsiType result = ClosureParameterEnhancer.findTypeForIteration(iteratedExpression, this);
        if (result != null) {
            return result;
        }
    } else if (parent instanceof GrTraditionalForClause) {
        return super.getTypeGroovy();
    } else if (parent instanceof GrCatchClause) {
        return TypesUtil.createTypeByFQClassName(CommonClassNames.JAVA_LANG_EXCEPTION, this);
    }
    return GrVariableEnhancer.getEnhancedType(this);
}
Also used : GrForInClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForInClause) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrCatchClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrCatchClause) GrTraditionalForClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrTraditionalForClause) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GrCatchClause (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrCatchClause)2 TextRange (com.intellij.openapi.util.TextRange)1 Nullable (org.jetbrains.annotations.Nullable)1 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)1 GrTryCatchStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrTryCatchStatement)1 GrOpenBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock)1 GrForInClause (org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForInClause)1 GrTraditionalForClause (org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrTraditionalForClause)1 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)1 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)1