当前位置: 首页>>代码示例>>Java>>正文


Java TypeConversionUtil.isPrimitiveAndNotNull方法代码示例

本文整理汇总了Java中com.intellij.psi.util.TypeConversionUtil.isPrimitiveAndNotNull方法的典型用法代码示例。如果您正苦于以下问题:Java TypeConversionUtil.isPrimitiveAndNotNull方法的具体用法?Java TypeConversionUtil.isPrimitiveAndNotNull怎么用?Java TypeConversionUtil.isPrimitiveAndNotNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.util.TypeConversionUtil的用法示例。


在下文中一共展示了TypeConversionUtil.isPrimitiveAndNotNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isAvailable

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
  PsiInstanceOfExpression instanceOfExpression = getInstanceOfExpressionAtCaret(editor, file);
  if (instanceOfExpression == null) return false;
  PsiTypeElement checkType = instanceOfExpression.getCheckType();
  if (checkType == null) return false;
  PsiExpression operand = instanceOfExpression.getOperand();
  PsiType operandType = operand.getType();
  if (TypeConversionUtil.isPrimitiveAndNotNull(operandType)) return false;
  PsiType type = checkType.getType();
  String castTo = type.getPresentableText();
  setText(QuickFixBundle.message("create.local.from.instanceof.usage.text", castTo, operand.getText()));

  PsiStatement statement = PsiTreeUtil.getParentOfType(instanceOfExpression, PsiStatement.class);
  boolean insideIf = statement instanceof PsiIfStatement
                     && PsiTreeUtil.isAncestor(((PsiIfStatement)statement).getCondition(), instanceOfExpression, false);
  boolean insideWhile = statement instanceof PsiWhileStatement
                        && PsiTreeUtil.isAncestor(((PsiWhileStatement)statement).getCondition(), instanceOfExpression, false);
  return (insideIf || insideWhile) && !isAlreadyCastedTo(type, instanceOfExpression, statement);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:CreateLocalVarFromInstanceofAction.java

示例2: getTypeClass

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
@Nullable
public ResolvedClass getTypeClass() {
  if (!TypeConversionUtil.isPrimitiveAndNotNull(myType)) {
    GlobalSearchScope resolveScope = myType.getResolveScope();
    if (resolveScope != null && resolveScope.getProject() != null) {
      ApplicationManager.getApplication().assertReadAccessAllowed();
      PsiClass aClass = JavaPsiFacade.getInstance(resolveScope.getProject()).findClass(getSignature(), resolveScope);
      if (aClass != null) {
        return new ResolvedPsiClass(aClass);
      }
    }
  }

  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:LombokPsiParser.java

示例3: checkExpression

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private void checkExpression(PsiExpression expression) {
  if (expression.getParent() instanceof PsiParenthesizedExpression) {
    return;
  }
  final PsiType expressionType = expression.getType();
  if (!TypeConversionUtil.isAssignableFromPrimitiveWrapper(expressionType)) {
    return;
  }
  final PsiType expectedType = ExpectedTypeUtils.findExpectedType(expression, false, true);
  if (!TypeConversionUtil.isPrimitiveAndNotNull(expectedType)) {
    return;
  }
  if (!(expression.getParent() instanceof PsiTypeCastExpression)) {
    final PsiPrimitiveType unboxedType = PsiPrimitiveType.getUnboxedType(expressionType);
    if (unboxedType == null || !expectedType.isAssignableFrom(unboxedType)) {
      return;
    }
  }
  registerError(expression, expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:AutoUnboxingInspection.java

示例4: isFieldMissingNullAnnotation

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private boolean isFieldMissingNullAnnotation(PsiField field, PsiType type) {
    return reportFields
            && field.isPhysical()
            && !(field instanceof PsiEnumConstant)
            && !TypeConversionUtil.isPrimitiveAndNotNull(type)
            && shouldCheckField(field)
            && !hasAnnotation(field);
}
 
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:9,代码来源:NullabilityAnnotationsInspection.java

示例5: findNullabilityAnnotationWithDefault

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Nullable 
private PsiAnnotation findNullabilityAnnotationWithDefault(@NotNull PsiModifierListOwner owner, boolean checkBases, boolean nullable) {
  PsiAnnotation annotation = findPlainNullabilityAnnotation(owner, checkBases);
  if (annotation != null) {
    String qName = annotation.getQualifiedName();
    if (qName == null) return null;

    List<String> contradictory = nullable ? getNotNulls() : getNullables();
    if (contradictory.contains(qName)) return null;

    return annotation;
  }

  PsiType type = getOwnerType(owner);
  if (type == null || TypeConversionUtil.isPrimitiveAndNotNull(type)) return null;

  // even if javax.annotation.Nullable is not configured, it should still take precedence over ByDefault annotations
  if (AnnotationUtil.isAnnotated(owner, nullable ? Arrays.asList(DEFAULT_NOT_NULLS) : Arrays.asList(DEFAULT_NULLABLES), checkBases, false)) {
    return null;
  }

  if (!nullable && hasHardcodedContracts(owner)) {
    return null;
  }
  
  return findNullabilityDefaultInHierarchy(owner, nullable);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:NullableNotNullManager.java

示例6: applyBoxedRelation

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private boolean applyBoxedRelation(DfaVariableValue dfaLeft, DfaValue dfaRight, boolean negated) {
  if (!TypeConversionUtil.isPrimitiveAndNotNull(dfaLeft.getVariableType())) return true;

  DfaBoxedValue.Factory boxedFactory = myFactory.getBoxedFactory();
  DfaValue boxedLeft = boxedFactory.createBoxed(dfaLeft);
  DfaValue boxedRight = boxedFactory.createBoxed(dfaRight);
  return boxedLeft == null || boxedRight == null || applyRelation(boxedLeft, boxedRight, negated);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:DfaMemoryStateImpl.java

示例7: isAvailable

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
  return myType.isValid()
         && myExpression.isValid()
         && myExpression.getManager().isInProject(myExpression)
         && !TypeConversionUtil.isPrimitiveAndNotNull(myType)
         && (myType instanceof PsiArrayType || myExpression.getArgumentList() != null)
    ;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:ChangeNewOperatorTypeFix.java

示例8: visitReferenceExpression

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
public void visitReferenceExpression(PsiReferenceExpression expression) {
  super.visitReferenceExpression(expression);
  if (expression instanceof PsiMethodReferenceExpression) {
    final PsiMethodReferenceExpression methodReferenceExpression = (PsiMethodReferenceExpression)expression;
    if (methodReferenceExpression.isConstructor()) {
      return;
    }
    final PsiElement referenceNameElement = methodReferenceExpression.getReferenceNameElement();
    if (referenceNameElement == null) {
      return;
    }
    final PsiElement target = methodReferenceExpression.resolve();
    if (!(target instanceof PsiMethod)) {
      return;
    }
    final PsiMethod method = (PsiMethod)target;
    final PsiType returnType = method.getReturnType();
    if (returnType == null || returnType.equals(PsiType.VOID) || !TypeConversionUtil.isPrimitiveAndNotNull(returnType)) {
      return;
    }
    final PsiPrimitiveType primitiveType = (PsiPrimitiveType)returnType;
    final PsiClassType boxedType = primitiveType.getBoxedType(expression);
    if (boxedType == null) {
      return;
    }
    final PsiType functionalInterfaceReturnType = LambdaUtil.getFunctionalInterfaceReturnType(methodReferenceExpression);
    if (functionalInterfaceReturnType == null || ClassUtils.isPrimitive(functionalInterfaceReturnType) ||
        !functionalInterfaceReturnType.isAssignableFrom(boxedType)) {
      return;
    }
    registerError(referenceNameElement);
  }
  else {
    checkExpression(expression);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:38,代码来源:AutoBoxingInspection.java

示例9: isPrimitiveArrayType

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static boolean isPrimitiveArrayType(PsiType type) {
  if (!(type instanceof PsiArrayType)) {
    return false;
  }
  final PsiType componentType = ((PsiArrayType)type).getComponentType();
  return TypeConversionUtil.isPrimitiveAndNotNull(componentType);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:PrimitiveArrayArgumentToVariableArgMethodInspection.java

示例10: isDeepPrimitiveArrayType

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static boolean isDeepPrimitiveArrayType(PsiType type, PsiSubstitutor substitutor) {
  if (!(type instanceof PsiEllipsisType)) {
    return false;
  }
  final PsiType componentType = type.getDeepComponentType();
  final PsiType substitute = substitutor.substitute(componentType);
  return TypeConversionUtil.isPrimitiveAndNotNull(substitute.getDeepComponentType());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:PrimitiveArrayArgumentToVariableArgMethodInspection.java

示例11: isImmutable

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
public static boolean isImmutable(PsiType type) {
  if (TypeConversionUtil.isPrimitiveAndNotNull(type)) {
    return true;
  }
  if (!(type instanceof PsiClassType)) {
    return false;
  }
  final PsiClassType classType = (PsiClassType)type;
  final String className = classType.getCanonicalText();
  return immutableTypes.contains(className);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:ClassUtils.java

示例12: getType

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
/**
 * JLS 15.25
 */
@Override
public PsiType getType() {
  PsiExpression expr1 = getThenExpression();
  PsiExpression expr2 = getElseExpression();
  PsiType type1 = expr1 == null ? null : expr1.getType();
  PsiType type2 = expr2 == null ? null : expr2.getType();
  if (type1 == null) return type2;
  if (type2 == null) return type1;

  if (type1.equals(type2)) return type1;
  final int typeRank1 = TypeConversionUtil.getTypeRank(type1);
  final int typeRank2 = TypeConversionUtil.getTypeRank(type2);

  // bug in JLS3, see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6888770
  if (type1 instanceof PsiClassType && type2.equals(PsiPrimitiveType.getUnboxedType(type1))) return type2;
  if (type2 instanceof PsiClassType && type1.equals(PsiPrimitiveType.getUnboxedType(type2))) return type1;

  if (TypeConversionUtil.isNumericType(typeRank1) && TypeConversionUtil.isNumericType(typeRank2)){
    if (typeRank1 == TypeConversionUtil.BYTE_RANK && typeRank2 == TypeConversionUtil.SHORT_RANK) {
      return type2 instanceof PsiPrimitiveType ? type2 : PsiPrimitiveType.getUnboxedType(type2);
    }
    if (typeRank1 == TypeConversionUtil.SHORT_RANK && typeRank2 == TypeConversionUtil.BYTE_RANK) {
      return type1 instanceof PsiPrimitiveType ? type1 : PsiPrimitiveType.getUnboxedType(type1);
    }
    if (typeRank2 == TypeConversionUtil.INT_RANK && (typeRank1 == TypeConversionUtil.BYTE_RANK || typeRank1 == TypeConversionUtil.SHORT_RANK || typeRank1 == TypeConversionUtil.CHAR_RANK)){
      if (TypeConversionUtil.areTypesAssignmentCompatible(type1, expr2)) return type1;
    }
    if (typeRank1 == TypeConversionUtil.INT_RANK && (typeRank2 == TypeConversionUtil.BYTE_RANK || typeRank2 == TypeConversionUtil.SHORT_RANK || typeRank2 == TypeConversionUtil.CHAR_RANK)){
      if (TypeConversionUtil.areTypesAssignmentCompatible(type2, expr1)) return type2;
    }
    return TypeConversionUtil.binaryNumericPromotion(type1, type2);
  }
  if (TypeConversionUtil.isNullType(type1) && !(type2 instanceof PsiPrimitiveType)) return type2;
  if (TypeConversionUtil.isNullType(type2) && !(type1 instanceof PsiPrimitiveType)) return type1;

  if (PsiUtil.isLanguageLevel8OrHigher(this) && 
      PsiPolyExpressionUtil.isPolyExpression(this) && 
      !MethodCandidateInfo.ourOverloadGuard.currentStack().contains(PsiUtil.skipParenthesizedExprUp(this.getParent()))) {
    //15.25.3 Reference Conditional Expressions 
    // The type of a poly reference conditional expression is the same as its target type.
    return InferenceSession.getTargetType(this);
  }

  if (TypeConversionUtil.isAssignable(type1, type2, false)) return type1;
  if (TypeConversionUtil.isAssignable(type2, type1, false)) return type2;
  if (!PsiUtil.isLanguageLevel5OrHigher(this)) {
    return null;
  }
  if (TypeConversionUtil.isPrimitiveAndNotNull(type1)) {
    type1 = ((PsiPrimitiveType)type1).getBoxedType(this);
    if (type1 == null) return null;
  }
  if (TypeConversionUtil.isPrimitiveAndNotNull(type2)) {
    type2 = ((PsiPrimitiveType)type2).getBoxedType(this);
    if (type2 == null) return null;
  }

  if (type1 instanceof PsiLambdaParameterType || type2 instanceof PsiLambdaParameterType) return null;
  final PsiType leastUpperBound = GenericsUtil.getLeastUpperBound(type1, type2, getManager());
  return leastUpperBound != null ? PsiUtil.captureToplevelWildcards(leastUpperBound, this) : null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:65,代码来源:PsiConditionalExpressionImpl.java

示例13: buildVisitor

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
  return new JavaElementVisitor() {
    @Override
    public void visitField(PsiField field) {
      analyzeCodeBlock(field, holder, isOnTheFly);
    }

    @Override
    public void visitMethod(PsiMethod method) {
      analyzeCodeBlock(method.getBody(), holder, isOnTheFly);
    }

    @Override
    public void visitClassInitializer(PsiClassInitializer initializer) {
      analyzeCodeBlock(initializer.getBody(), holder, isOnTheFly);
    }

    @Override
    public void visitMethodReferenceExpression(PsiMethodReferenceExpression expression) {
      super.visitMethodReferenceExpression(expression);
      final PsiElement resolve = expression.resolve();
      if (resolve instanceof PsiMethod) {
        final PsiType methodReturnType = ((PsiMethod)resolve).getReturnType();
        if (TypeConversionUtil.isPrimitiveWrapper(methodReturnType) && NullableNotNullManager.isNullable((PsiMethod)resolve)) {
          final PsiType returnType = LambdaUtil.getFunctionalInterfaceReturnType(expression);
          if (TypeConversionUtil.isPrimitiveAndNotNull(returnType)) {
            holder.registerProblem(expression, InspectionsBundle.message("dataflow.message.unboxing.method.reference"));
          }
        }
      }
    }

    @Override
    public void visitIfStatement(PsiIfStatement statement) {
      PsiExpression condition = statement.getCondition();
      if (BranchingInstruction.isBoolConst(condition)) {
        LocalQuickFix fix = createSimplifyBooleanExpressionFix(condition, condition.textMatches(PsiKeyword.TRUE));
        holder.registerProblem(condition, "Condition is always " + condition.getText(), fix);
      }
    }

  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:46,代码来源:DataFlowInspectionBase.java

示例14: checkExpression

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private void checkExpression(@NotNull PsiExpression expression) {
  final PsiElement parent = expression.getParent();
  if (parent instanceof PsiParenthesizedExpression) {
    return;
  }
  if (parent instanceof PsiExpressionList) {
    final PsiElement grandParent = parent.getParent();
    if (grandParent instanceof PsiMethodCallExpression) {
      final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)grandParent;
      final PsiMethod method = methodCallExpression.resolveMethod();
      if (method != null &&
          AnnotationUtil.isAnnotated(method, Collections.singletonList("java.lang.invoke.MethodHandle.PolymorphicSignature"))) {
        return;
      }
    }
  }
  final PsiType expressionType = expression.getType();
  if (expressionType == null || expressionType.equals(PsiType.VOID) || !TypeConversionUtil.isPrimitiveAndNotNull(expressionType)) {
    return;
  }
  final PsiPrimitiveType primitiveType = (PsiPrimitiveType)expressionType;
  final PsiClassType boxedType = primitiveType.getBoxedType(expression);
  if (boxedType == null) {
    return;
  }
  final PsiType expectedType = ExpectedTypeUtils.findExpectedType(expression, false, true);
  if (expectedType == null || ClassUtils.isPrimitive(expectedType)) {
    return;
  }
  if (!expectedType.isAssignableFrom(boxedType)) {
    // JLS 5.2 Assignment Conversion
    // check if a narrowing primitive conversion is applicable
    if (!(expectedType instanceof PsiClassType) || !PsiUtil.isConstantExpression(expression)) {
      return;
    }
    final PsiClassType classType = (PsiClassType)expectedType;
    final String className = classType.getCanonicalText();
    if (!convertableBoxedClassNames.contains(className)) {
      return;
    }
    if (!PsiType.BYTE.equals(expressionType) && !PsiType.CHAR.equals(expressionType) &&
        !PsiType.SHORT.equals(expressionType) && !PsiType.INT.equals(expressionType)) {
      return;
    }
  }
  if (ignoreAddedToCollection && isAddedToCollection(expression)) {
    return;
  }
  registerError(expression, expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:51,代码来源:AutoBoxingInspection.java

示例15: 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;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:60,代码来源:ExpectedTypeUtils.java


注:本文中的com.intellij.psi.util.TypeConversionUtil.isPrimitiveAndNotNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。