本文整理汇总了Java中com.intellij.psi.util.TypeConversionUtil.isBooleanType方法的典型用法代码示例。如果您正苦于以下问题:Java TypeConversionUtil.isBooleanType方法的具体用法?Java TypeConversionUtil.isBooleanType怎么用?Java TypeConversionUtil.isBooleanType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.util.TypeConversionUtil
的用法示例。
在下文中一共展示了TypeConversionUtil.isBooleanType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isBooleanOrNumeric
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static ConditionalKind isBooleanOrNumeric(PsiExpression expr) {
if (expr instanceof PsiParenthesizedExpression) {
return isBooleanOrNumeric(((PsiParenthesizedExpression)expr).getExpression());
}
if (expr == null) return null;
PsiType type = null;
if (expr instanceof PsiNewExpression || hasStandaloneForm(expr)) {
type = expr.getType();
} else if (expr instanceof PsiMethodCallExpression) {
final PsiMethod method = ((PsiMethodCallExpression)expr).resolveMethod();
if (method != null) {
type = method.getReturnType();
}
}
if (TypeConversionUtil.isNumericType(type)) return ConditionalKind.NUMERIC;
if (TypeConversionUtil.isBooleanType(type)) return ConditionalKind.BOOLEAN;
if (expr instanceof PsiConditionalExpression) {
final PsiExpression thenExpression = ((PsiConditionalExpression)expr).getThenExpression();
final PsiExpression elseExpression = ((PsiConditionalExpression)expr).getElseExpression();
final ConditionalKind thenKind = isBooleanOrNumeric(thenExpression);
final ConditionalKind elseKind = isBooleanOrNumeric(elseExpression);
if (thenKind == elseKind || elseKind == null) return thenKind;
if (thenKind == null) return elseKind;
}
return null;
}
示例2: isAvailable
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (!myPrefixExpression.isValid() || myPrefixExpression.getOperand() == null) return false;
PsiElement parent = myPrefixExpression.getParent();
if (parent instanceof PsiInstanceOfExpression && ((PsiInstanceOfExpression)parent).getOperand() == myPrefixExpression) {
return true;
}
if (!(parent instanceof PsiBinaryExpression)) return false;
PsiBinaryExpression binaryExpression = (PsiBinaryExpression)parent;
return binaryExpression.getLOperand() == myPrefixExpression && TypeConversionUtil.isBooleanType(binaryExpression.getType());
}
示例3: expectedPrimitiveType
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private PsiType expectedPrimitiveType(PsiPrimitiveType type1, PsiType type2) {
if (TypeConversionUtil.isNumericType(type1)) {
// JLS 15.21.1. Numerical Equality Operators == and !=
return TypeConversionUtil.isNumericType(type2) ? TypeConversionUtil.binaryNumericPromotion(type1, type2) : null;
}
else if (PsiType.BOOLEAN.equals(type1)) {
// JLS 15.21.2. Boolean Equality Operators == and !=
return TypeConversionUtil.isBooleanType(type2) ? PsiType.BOOLEAN : null;
}
else if (PsiType.NULL.equals(type1)) {
return TypeUtils.getObjectType(wrappedExpression);
}
// void
return null;
}
示例4: visitPolyadicExpression
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
public void visitPolyadicExpression(@NotNull PsiPolyadicExpression polyadicExpression) {
final PsiExpression[] operands = polyadicExpression.getOperands();
if (operands.length < 2) {
expectedType = null;
return;
}
for (PsiExpression operand : operands) {
if (operand == null || operand.getType() == null) {
expectedType = null;
return;
}
}
final IElementType tokenType = polyadicExpression.getOperationTokenType();
final PsiType type = polyadicExpression.getType();
final PsiType wrappedExpressionType = wrappedExpression.getType();
if (TypeUtils.isJavaLangString(type) || isArithmeticOperation(tokenType) || isBooleanOperation(tokenType)) {
expectedType = type;
}
else if (isShiftOperation(tokenType)) {
expectedType = TypeUtils.unaryNumericPromotion(wrappedExpressionType);
}
else if (ComparisonUtils.isEqualityComparison(polyadicExpression)) {
final PsiExpression operand1 = operands[0];
final PsiExpression operand2 = operands[1];
if (operand1 == wrappedExpression || operand2 == wrappedExpression) {
final PsiType type1 = operand1.getType();
final PsiType type2 = operand2.getType();
if (type1 instanceof PsiPrimitiveType) {
expectedType = expectedPrimitiveType((PsiPrimitiveType)type1, type2);
}
else if (type2 instanceof PsiPrimitiveType) {
expectedType = expectedPrimitiveType((PsiPrimitiveType)type2, type1);
}
else {
expectedType = TypeUtils.getObjectType(wrappedExpression);
}
}
else {
// third or more operand must always be boolean or does not compile
expectedType = TypeConversionUtil.isBooleanType(wrappedExpressionType) ? PsiType.BOOLEAN : null;
}
}
else if (ComparisonUtils.isComparisonOperation(tokenType)) {
if (operands.length != 2) {
expectedType = null;
return;
}
else if (!TypeConversionUtil.isPrimitiveAndNotNull(wrappedExpressionType)) {
if (PsiPrimitiveType.getUnboxedType(wrappedExpressionType) == null) {
return;
}
}
expectedType = TypeConversionUtil.binaryNumericPromotion(operands[0].getType(), operands[1].getType());
}
else {
expectedType = null;
}
}