public void testExprNewArrayPrimitive2Rvalue() throws Exception {
   doTestFieldType(
       "myField",
       "Expr",
       PsiType.BOOLEAN.createArrayType().createArrayType(),
       PsiType.INT.createArrayType().createArrayType());
 }
 private static boolean isValueOfCall(PsiMethodCallExpression methodCallExpression) {
   final PsiExpressionList argumentList = methodCallExpression.getArgumentList();
   final PsiExpression[] arguments = argumentList.getExpressions();
   if (arguments.length != 1) {
     return false;
   }
   final PsiExpression argument = arguments[0];
   final PsiType type = argument.getType();
   return (MethodCallUtils.isCallToMethod(
               methodCallExpression,
               CommonClassNames.JAVA_LANG_INTEGER,
               null,
               "valueOf",
               PsiType.INT)
           && PsiType.INT.equals(type))
       || (MethodCallUtils.isCallToMethod(
               methodCallExpression,
               CommonClassNames.JAVA_LANG_SHORT,
               null,
               "valueOf",
               PsiType.SHORT)
           && PsiType.SHORT.equals(type))
       || (MethodCallUtils.isCallToMethod(
               methodCallExpression,
               CommonClassNames.JAVA_LANG_BYTE,
               null,
               "valueOf",
               PsiType.BYTE)
           && PsiType.BYTE.equals(type))
       || (MethodCallUtils.isCallToMethod(
               methodCallExpression,
               CommonClassNames.JAVA_LANG_LONG,
               null,
               "valueOf",
               PsiType.LONG)
           && PsiType.LONG.equals(type))
       || (MethodCallUtils.isCallToMethod(
               methodCallExpression,
               CommonClassNames.JAVA_LANG_CHARACTER,
               null,
               "valueOf",
               PsiType.CHAR)
           && PsiType.CHAR.equals(type))
       || (MethodCallUtils.isCallToMethod(
               methodCallExpression,
               CommonClassNames.JAVA_LANG_DOUBLE,
               null,
               "valueOf",
               PsiType.DOUBLE)
           && PsiType.DOUBLE.equals(type))
       || (MethodCallUtils.isCallToMethod(
               methodCallExpression,
               CommonClassNames.JAVA_LANG_FLOAT,
               null,
               "valueOf",
               PsiType.FLOAT)
           && PsiType.FLOAT.equals(type));
 }
Exemple #3
0
 public static Value createValue(VirtualMachineProxyImpl vm, String expectedType, char value) {
   if (PsiType.CHAR.getPresentableText().equals(expectedType)) {
     return vm.mirrorOf(value);
   }
   if (PsiType.LONG.getPresentableText().equals(expectedType)) {
     return vm.mirrorOf((long) value);
   }
   if (PsiType.INT.getPresentableText().equals(expectedType)) {
     return vm.mirrorOf((int) value);
   }
   if (PsiType.SHORT.getPresentableText().equals(expectedType)) {
     return vm.mirrorOf((short) value);
   }
   if (PsiType.BYTE.getPresentableText().equals(expectedType)) {
     return vm.mirrorOf((byte) value);
   }
   return null;
 }
 private void checkExpression(@NotNull PsiExpression expression) {
   if (expression.getParent() instanceof PsiParenthesizedExpression) {
     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);
   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);
 }
Exemple #5
0
 @SuppressWarnings({"HardCodedStringLiteral"})
 public static String getPrimitiveSignature(String typeName) {
   if (PsiType.BOOLEAN.getCanonicalText().equals(typeName)) {
     return "Z";
   } else if (PsiType.BYTE.getCanonicalText().equals(typeName)) {
     return "B";
   } else if (PsiType.CHAR.getCanonicalText().equals(typeName)) {
     return "C";
   } else if (PsiType.SHORT.getCanonicalText().equals(typeName)) {
     return "S";
   } else if (PsiType.INT.getCanonicalText().equals(typeName)) {
     return "I";
   } else if (PsiType.LONG.getCanonicalText().equals(typeName)) {
     return "J";
   } else if (PsiType.FLOAT.getCanonicalText().equals(typeName)) {
     return "F";
   } else if (PsiType.DOUBLE.getCanonicalText().equals(typeName)) {
     return "D";
   } else if (PsiType.VOID.getCanonicalText().equals(typeName)) {
     return "V";
   }
   return null;
 }