声纳中用于 Java 中导入语句的重复代码块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36111476/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 17:27:53  来源:igfitidea点击:

Duplicated block of Code in Sonar for import statements in Java

javasonarqubesonarqube-4.5sonarqube-web

提问by tuk

In Sonar 4.5.6 (with default settings) I am seeing Duplicated Blocksmessage as

在声纳 4.5.6(使用默认设置)中,我看到的Duplicated Blocks消息为

enter image description here

enter image description here

My java code for which I am getting the message is like below:-

我收到消息的 Java 代码如下所示:-

package com.jabong.orchestratorservice.adapter.order.endpoints;

import com.jabong.orchestratorservice.adapter.order.request.UpdateOrderStatusReadyShipRequest;

public class UpdateOrderReadyShipEndPoint extends BaseOrderEndPoint {
    private final static String API_NAME = "setStatusToReadyToShip";

    @Override
    public String getSourceEndPoint() {
    return new StringBuilder("direct:").append(API_NAME).toString();
    }

    @Override
    public String getDestinationEndPoint() {
    return new StringBuilder("bean:orderHelper?method=").append(API_NAME).toString();
    }

    @Override
    protected String getName() {
    return API_NAME;
    }

    @Override
    protected String getApiInputClassName() {
    return UpdateOrderStatusReadyShipRequest.class.getName();
    }
}

UpdateOrderStatusReadyShipRequestalso does not import UpdateOrderReadyShipEndPoint

UpdateOrderStatusReadyShipRequest也不导入 UpdateOrderReadyShipEndPoint

package com.jabong.orchestratorservice.adapter.order.request;

public class UpdateOrderStatusReadyShipRequest extends BaseOrderRequest {

Can some let me know what does this mean?

有人可以让我知道这是什么意思吗?

采纳答案by G. Ann - SonarSource Team

The Duplicate Blocks rule raises issues at the file level. So it's not trying to tell you that your import statement is duplicated, but that somewhere in the file is a duplicate block. If you'll scroll down, you should see a vertical yellow/orange bar in the left margin. It marks the duplicate block. Click on the bar to get details of where the block is duplicated.

Duplicate Blocks 规则会在文件级别引发问题。所以它不是试图告诉你你的 import 语句是重复的,而是文件中的某个地方是一个重复的块。如果向下滚动,您应该会在左边距中看到一个垂直的黄色/橙色条。它标记重复块。单击该栏以获取有关块复制位置的详细信息。

EDITIn more recent versions the duplication marker is brown or gray.

编辑在更新的版本中,重复标记为棕色或灰色。

回答by Carlos Cruz

You have to look (scroll down) your code. There will be a duplication marker in brown/gray like this:

您必须查看(向下滚动)您的代码。将有一个棕色/灰色的重复标记,如下所示:

enter image description here

enter image description here