@Nullable private static PsiType getCastedExpressionType(PsiElement parenthesisOwner) { if (parenthesisOwner instanceof PsiTypeCastExpression) { final PsiExpression operand = ((PsiTypeCastExpression)parenthesisOwner).getOperand(); return operand == null ? null : operand.getType(); } if (parenthesisOwner instanceof PsiParenthesizedExpression) { PsiElement next = parenthesisOwner.getNextSibling(); while (next != null && (next instanceof PsiEmptyExpressionImpl || next instanceof PsiErrorElement || next instanceof PsiWhiteSpace)) { next = next.getNextSibling(); } if (next instanceof PsiExpression) { return ((PsiExpression)next).getType(); } } return null; }
@Nullable private static PsiType getCastedExpressionType(PsiElement originalPosition) { if (INSIDE_TYPECAST_TYPE.accepts(originalPosition)) { final PsiTypeCastExpression cast = PsiTreeUtil.getParentOfType(originalPosition, PsiTypeCastExpression.class); if (cast != null) { final PsiExpression operand = cast.getOperand(); return operand == null ? null : operand.getType(); } } final PsiParenthesizedExpression parens = PsiTreeUtil.getParentOfType(originalPosition, PsiParenthesizedExpression.class, true, PsiStatement.class); if (parens != null) { final PsiExpression rightSide = parens.getExpression(); if (rightSide != null) { return rightSide.getType(); } PsiElement next = parens.getNextSibling(); while (next != null && (next instanceof PsiEmptyExpressionImpl || next instanceof PsiErrorElement || next instanceof PsiWhiteSpace)) { next = next.getNextSibling(); } if (next instanceof PsiExpression) { return ((PsiExpression)next).getType(); } return null; } return null; }
private static PsiExpression getCastedExpression(PsiElement parenthesisOwner) { if(parenthesisOwner instanceof PsiTypeCastExpression) { return ((PsiTypeCastExpression) parenthesisOwner).getOperand(); } if(parenthesisOwner instanceof PsiParenthesizedExpression) { PsiElement next = parenthesisOwner.getNextSibling(); while(next != null && (next instanceof PsiEmptyExpressionImpl || next instanceof PsiErrorElement || next instanceof PsiWhiteSpace)) { next = next.getNextSibling(); } if(next instanceof PsiExpression) { return (PsiExpression) next; } } return null; }