コード例 #1
0
 private boolean checkConstantValueVariableUse(
     @Nullable PsiExpression expression,
     @NotNull PsiExpression constantExpression,
     @NotNull PsiElement body) {
   final PsiType constantType = constantExpression.getType();
   if (PsiType.DOUBLE.equals(constantType)) {
     final Object result = ExpressionUtils.computeConstantExpression(constantExpression, false);
     if (Double.valueOf(0.0).equals(result) || Double.valueOf(-0.0).equals(result)) {
       return false;
     }
   }
   if (!(expression instanceof PsiReferenceExpression)) {
     return false;
   }
   final PsiReferenceExpression referenceExpression = (PsiReferenceExpression) expression;
   final PsiElement target = referenceExpression.resolve();
   if (!(target instanceof PsiVariable)) {
     return false;
   }
   if (target instanceof PsiField) {
     return false;
   }
   final PsiVariable variable = (PsiVariable) target;
   final VariableReadVisitor visitor = new VariableReadVisitor(variable);
   body.accept(visitor);
   if (!visitor.isRead()) {
     return false;
   }
   registerError(visitor.getReference(), constantExpression);
   return true;
 }
コード例 #2
0
 public static boolean isAssociativeOperation(PsiPolyadicExpression expression) {
   final IElementType tokenType = expression.getOperationTokenType();
   final PsiType type = expression.getType();
   final PsiPrimitiveType primitiveType;
   if (type instanceof PsiClassType) {
     primitiveType = PsiPrimitiveType.getUnboxedType(type);
     if (primitiveType == null) {
       return false;
     }
   } else if (type instanceof PsiPrimitiveType) {
     primitiveType = (PsiPrimitiveType) type;
   } else {
     return false;
   }
   if (JavaTokenType.PLUS == tokenType || JavaTokenType.ASTERISK == tokenType) {
     return !PsiType.FLOAT.equals(primitiveType) && !PsiType.DOUBLE.equals(primitiveType);
   } else if (JavaTokenType.EQEQ == tokenType || JavaTokenType.NE == tokenType) {
     return PsiType.BOOLEAN.equals(primitiveType);
   } else if (JavaTokenType.AND == tokenType
       || JavaTokenType.OR == tokenType
       || JavaTokenType.XOR == tokenType) {
     return true;
   } else if (JavaTokenType.OROR == tokenType || JavaTokenType.ANDAND == tokenType) {
     return true;
   }
   return false;
 }
コード例 #3
0
 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));
 }
コード例 #4
0
ファイル: DebuggerUtilsEx.java プロジェクト: jared2501/test
 public static Value createValue(VirtualMachineProxyImpl vm, String expectedType, double value) {
   if (PsiType.DOUBLE.getPresentableText().equals(expectedType)) {
     return vm.mirrorOf(value);
   }
   if (PsiType.FLOAT.getPresentableText().equals(expectedType)) {
     return vm.mirrorOf((float) value);
   }
   return createValue(vm, expectedType, (long) value);
 }
コード例 #5
0
  /**
   * Sets the basic element information from the given type.
   *
   * @param element the element to set information from the type
   * @param factory
   * @param type the type
   * @param modifiers modifier list
   * @since 2.15
   */
  private static void setElementInfo(
      AbstractElement element, PsiElementFactory factory, PsiType type, PsiModifierList modifiers) {

    // type names
    element.setTypeName(PsiAdapter.getTypeClassName(type));
    element.setTypeQualifiedName(PsiAdapter.getTypeQualifiedClassName(type));
    element.setType(type.getCanonicalText());

    // arrays, collections and maps types
    if (PsiAdapter.isObjectArrayType(type)) {
      element.setObjectArray(true);
      element.setArray(true);

      // additional specify if the element is a string array
      if (PsiAdapter.isStringArrayType(type)) element.setStringArray(true);

    } else if (PsiAdapter.isPrimitiveArrayType(type)) {
      element.setPrimitiveArray(true);
      element.setArray(true);
    }
    if (PsiAdapter.isCollectionType(factory, type)) element.setCollection(true);
    if (PsiAdapter.isListType(factory, type)) element.setList(true);
    if (PsiAdapter.isSetType(factory, type)) element.setSet(true);
    if (PsiAdapter.isMapType(factory, type)) element.setMap(true);

    // other types
    if (PsiAdapter.isPrimitiveType(type)) element.setPrimitive(true);
    if (PsiAdapter.isObjectType(factory, type)) element.setObject(true);
    if (PsiAdapter.isStringType(factory, type)) element.setString(true);
    if (PsiAdapter.isNumericType(factory, type)) element.setNumeric(true);
    if (PsiAdapter.isDateType(factory, type)) element.setDate(true);
    if (PsiAdapter.isCalendarType(factory, type)) element.setCalendar(true);
    if (PsiAdapter.isBooleanType(factory, type)) element.setBoolean(true);
    if (PsiType.VOID.equals(type)) element.setVoid(true);
    if (PsiType.LONG.equals(type)) element.setLong(true);
    if (PsiType.FLOAT.equals(type)) element.setFloat(true);
    if (PsiType.DOUBLE.equals(type)) element.setDouble(true);
    if (PsiType.BYTE.equals(type)) element.setByte(true);
    if (PsiType.CHAR.equals(type)) element.setChar(true);
    if (PsiType.SHORT.equals(type)) element.setShort(true);
    element.setNestedArray(PsiAdapter.isNestedArray(type));
    // modifiers
    if (modifiers != null) {
      if (modifiers.hasModifierProperty(PsiModifier.STATIC)) element.setModifierStatic(true);
      if (modifiers.hasModifierProperty(PsiModifier.FINAL)) element.setModifierFinal(true);
      if (modifiers.hasModifierProperty(PsiModifier.PUBLIC)) {
        element.setModifierPublic(true);
      } else if (modifiers.hasModifierProperty(PsiModifier.PROTECTED)) {
        element.setModifierProtected(true);
      } else if (modifiers.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) {
        element.setModifierPackageLocal(true);
      } else if (modifiers.hasModifierProperty(PsiModifier.PRIVATE))
        element.setModifierPrivate(true);
    }
  }
コード例 #6
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;
 }
コード例 #7
0
ファイル: DebuggerUtilsEx.java プロジェクト: jared2501/test
 public static Value createValue(VirtualMachineProxyImpl vm, String expectedType, long value) {
   if (PsiType.LONG.getPresentableText().equals(expectedType)) {
     return vm.mirrorOf(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);
   }
   if (PsiType.CHAR.getPresentableText().equals(expectedType)) {
     return vm.mirrorOf((char) value);
   }
   if (PsiType.DOUBLE.getPresentableText().equals(expectedType)) {
     return vm.mirrorOf((double) value);
   }
   if (PsiType.FLOAT.getPresentableText().equals(expectedType)) {
     return vm.mirrorOf((float) value);
   }
   return null;
 }