zoukankan      html  css  js  c++  java
  • idea inspections的解释说明1

    IntelliJ IDEA 检查严重性表示检查检测到的代码问题对项目的影响程度如何,并确定在编辑器中如何突出显示检测到的问题。默认情况下,每个检查都具有以下严重性级别之一:

    • 服务器问题 
    • 错字   
    • 信息   
    • 弱警告  
    • 警告  
    • 错误  

    您可以增加或减少每次 IntelliJ IDEA 检查的严重性级别。也就是说,您可以强制 IntelliJ IDEA 将一些警告显示为错误或弱警告。以类似的方式,最初被认为是一个弱警告的也可以显示为警告或错误,或者只是作为信息。

    您还可以配置用于突出显示每个严重性级别的颜色和字体样式。此外,您可以创建自定义的严重性级别并将其设置为特定检查。

    如有必要,您可以在不同范围内为同一检查设置不同的严重性级别。

    所有对上述检查的修改都保存在当前在检查设置中选定的检查配置文件中,并在使用此配置文件时应用。

    IntelliJ IDEA 更改检查严重性

    IntelliJ IDEA 自定义检查严重性级别

     

     新加级别和颜色,比如这个

    1. 使用向上 和向下 按钮更改新的严重性的优先级。

     

    Abstraction issues

    Title

    默认

    建议

    描述

    'instance of' a concrete class

     

    warning

    instance of一般判断是否是一个接口或者抽象类的实例

    'instance of' check for this

     

    warning 

    使用this肯定知道是哪个Class

    Magic number

     

    warning

    不允许任何魔法值(即未经定义的常量)直接出现在代码中 ,参考阿里规范

    Overly strong type cast

     

    warning

    高强强制类型转换,有时候我们强转List即可却强转成ArrayList

    Assignment issues 

    Title

    默认

    建议

    描述

    Assignment to for 'loop' parameter

     

    warning

    在for循环中改变了循环的参数

    Constructor assigns value to field defined in superclass

     

    warning

    在构造方法中对父类成员变量赋值,这样做不合理,应该调用父类构造方法

    Class Metrics

    Title

    默认

    建议

    描述

    Class with too many constructors

     

    warning

    类的构造方法过多(默认限制5个)

    Class structure

    Title

    默认

    建议

    描述

    Class name differs from file name

     

    warning

    类名和文件名不同

    No-op method in abstract class

     

    warning

    抽象类中的空方法没有被声明成abstract,比较少见

    'protected' member in final class

     

    warning

    定义成final的类无法被继承,protected的使用不正确

    Code maturity

    Title

    默认

    建议

    描述

    Call to printStackTrace()

     

    warning

    成熟的代码应该使用log

    Call to Thread.dumpStack

     

    warning

    静态dumpstack()方法提供一个new exception ("stack trace").printstacktrace ()的封装,打印一个追踪当前线程的堆栈,调试用。

    Use of absolute collection type

     

    warning

    使用了java.util.Vector or java.util.Hashtable这些不推荐使用的类

    Use of System.out or System.err

     

    warning

    使用了System.out or System.err,用log替代

    Code style issues

    Title

    默认

    建议

    描述

    Blocker marker comment

     

    warning

    注释位置不合理

    while (i < 10) {
    i++;
    } // end while参考阿里规范,写在while上方

    C-style array declaration

    No high lighting,only fix 

    warning

    C语言风格的数组声明

    public String process(String value[])[] {
    return value;
    }

    Control flow statement without braces

    No high lighting,only fix 

    warning

    条件或者循环语句括号没打好

    (expression).equals("literal")rather than("literal").equals(expression)

     

    warning

    减少空指针的好习惯

    indexOf expression is replacable with contains

     

    warning

    Reports any List.indexOf() expressions which can be replaced with the method List.contains(). 

    Missorted modifiers

     

    warning

    修饰词顺序不符合规范 

    Multiple variables in one declaration

     

    warning

    一行代码声明了多个变量

    Redundant no-arg constructor

     

    warning

    多余的无参构造方法

    size==0 replacable with isEmpty

     

    warning

    很实用,判断list非空isEmpty一目了然

    Unnessarily null check before equals call

     

    warning

    多余的空指针校验

    Variables of different types in one declaration

     

    warning

    一行声明多个不同类型的变量,String s = "", array[];

    Compiller issues

    Title

    默认

    建议

    描述

    Unchecked warning

    warning

    很多check多余,可关闭此warning

    Control flow issues

    Title

    默认

    建议

    描述

    Boolean expression could be replaced with conditional expression

     

    warning

    Boolean类型表达式优化

    Reports any boolean expressions which can be expressed more compactly, and arguably more clearly, as a conditional expression. Take for example the following expression:

    a && b || !a && c;

    which may be expressed as:

    a ? b : c;

    Conditional can be pushed inside branch expression

    No high lighting,only fix    

    warning

    条件表达式优化

    Reports conditional expressions with then and else branches so similar that the conditional expression can be pushed inside, thereby shortening the code.

    For example the following conditional expression:

    condition ? message("value: " + 1) : message("value: " + 2)

    Can be pushed inside and transformed into:

    message("value: " + (condition ? 1 : 2))

    default not last case in switch statement

     

    warning

    在switch中,default不在最后

    duplicate condition in if statement

     

    warning

    if中出现了重复的条件

    duplicate condition on && or ||

     

    warning

    条件重复

    fallthrough in switch statement

     

    warning

    swich中未使用break

    if statement could be replaced with conditional expression

     

    warning

    三元运算符简写if

    if statement with negated condition

     

    warning

    if的条件是否定,可以调换if else顺序

    negated equality expression

     

    warning

    !(i == 1)

    pointless indexOf comparison

     

    warning

    indexOf>-1则无意义

    redundant if statement

    warning

    多余的if

    For example:

    if (foo()) {

    return true;

    } else {

    return false;

    }

    can be simplified to

    return foo();

    有时候为了逻辑清晰,会有这样写的必要

    switch statement without default branch

     

    warning

    switch缺少default

    Declaration redundancy

    Title

    默认

    建议

    描述

    Declaration access can be weaker

    warning

    可以定义更低的访问权限public->protected->default->private,

    但长远考虑有时候会有这方面需要

    Declaration can have final modifier

    warning

    声明可以加上final

    Empty method

    warning

    空方法

    Method can be void

    warning

    方法可以声明成void的,

    虽然返回值没用起来,但是未来很可能会被使用

    Method returns the same value

    warning

    方法返回值总是相同,很常见

    remove redundant lambda parameter types

    No high lighting,only fix    

    warning

    优化lambda参数自动推测

    Example:

    Map<String, Integer> map = ...

    map.forEach((String s, Integer i) -> log.info(s + "=" + i));

    Error handling

    Title

    默认

    建议

    描述

    instanceof on catch parameter

     

    warning

    使用instanceof来区分异常不如使用多个catch块

    Nested try statement

     

    warning

    嵌套try

    Java language level migration aids

    Title

    默认

    建议

    描述

    try finally replacable with try with resources

    warning

    Before Java 7, the usual pattern was something like this:

    Connection con = null; PreparedStatement prep = null; try{ con = getConnection(); prep = prep.prepareStatement("Update ..."); ... con.commit(); } catch (SQLException e){ con.rollback(); throw e; } finally{ if (prep != null) prep.close(); if (con != null) con.close(); }

    With Java 7 you can go for:

    try(Connection con = getConnection(); PreparedStatement prep = con.prepareConnection("Update ..."){ ... con.commit(); }

    lambda can be replaced with method reference

    warning

    不同风格的lambda写法

    Numberic issues

    Title

    默认

    建议

    描述

    divdide by zero

    warning

    error

    除零

    equals called on java.math.BigDecimal

     

    warning

    使用compareTo

    Performance

    Title

    默认

    建议

    描述

    Single charactor string argument in String.indexOf call

     

    warning

    单字符串String无需indexOf直接equals即可

    String.equals("")

     

    warning

    直接.length==0,可能null则使用StringUtils.isEmpty

    Probable bugs

    Title

    默认

    建议

    描述

    Array comparison using == instead of Array.equals

     

    warning

    正确比较数组每个元素相等的方法Arrays.equals()

    Call to default toString

     

    warning

    未覆写ToString时使用只会打印地址

    Collection added to itself

    warning

    Reports cases where the argument of a method call on a java.util.Collection or java.util.Map is the collection or map itself. This includes adding a collection to itself, which can lead to a java.lang.StackOverflowError when, for example, calling hashCode() on the self-containing collection.

    equals and hashCode are not pared

     

    warning

    两个对象如果不相等,hashCode不强制要求不一样,但是如果能保证不一样,对哈希的效率会比较有帮助最重要的是第二点,相等的对象必须有相同的hashCode,由于默认的hashCode方法针对每一个对象返回一个固定的随机值(有的实现是根据对象地址返回值,相当于每一个对象对应一个固定的随机值),所以当我们使用equals方法的同时,必须override(重写)hashCode方法,以满足这一点。

    Object comparison using == instead of equals

    No high lighting,only fix    

    warning

    比较对象相等一般不是要比较地址

    Verbose or redundant code constructs

    Title

    默认

    建议

    描述

    unnecessary default for enum switch statement

     

    warning

    enum case就这么多无需default

    本文来自博客园,作者:三号小玩家,转载请注明原文链接:https://www.cnblogs.com/q1359720840/p/15776873.html

  • 相关阅读:
    Python MongoDB使用介绍
    算法网站
    无限级树状图css实现
    无限级别分类嵌套格式抓取
    无限级别分类
    计算多维数组到底是几维的
    获取无限级别分类
    mysql 重启
    radio 控制器function用法
    php-fpm 重启 nginx单独配置 重启
  • 原文地址:https://www.cnblogs.com/q1359720840/p/15776873.html
Copyright © 2011-2022 走看看