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);
}
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);
}
Aggregations