Search in sources :

Example 1 with Type

use of org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue.Type in project sonarlint-core by SonarSource.

the class ProxyIssueListener method handle.

@Override
public void handle(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue issue) {
    Severity severity;
    ClientInputFile inputFile = issue.getInputFile();
    switch(issue.getSeverity()) {
        case "MINOR":
            severity = Severity.MINOR;
            break;
        case "BLOCKER":
            severity = Severity.BLOCKER;
            break;
        case "INFO":
            severity = Severity.INFO;
            break;
        case "CRITICAL":
            severity = Severity.CRITICAL;
            break;
        case "MAJOR":
        default:
            severity = Severity.MAJOR;
            break;
    }
    Type type = Type.CODE_SMELL;
    if (issue.getType() != null) {
        switch(StringUtils.lowerCase(issue.getType())) {
            case "bug":
                type = Type.BUG;
                break;
            case "vulnerability":
                type = Type.VULNERABILITY;
                break;
            case "code_smell":
            default:
                type = Type.CODE_SMELL;
                break;
        }
    }
    Issue.Builder builder = Issue.newBuilder();
    builder.setRuleKey(issue.getRuleKey()).setRuleName(issue.getRuleName()).setMessage(issue.getMessage()).setSeverity(severity).setType(type).setStartLine(issue.getStartLine() != null ? issue.getStartLine() : 0).setStartLineOffset(issue.getStartLineOffset() != null ? issue.getStartLineOffset() : 0).setEndLine(issue.getEndLine() != null ? issue.getEndLine() : 0).setEndLineOffset(issue.getEndLineOffset() != null ? issue.getEndLineOffset() : 0);
    if (inputFile != null) {
        builder.setFilePath(inputFile.getPath());
        if (inputFile.getClientObject() != null) {
            builder.setUserObject((String) inputFile.getClientObject());
        }
    }
    observer.onNext(builder.build());
}
Also used : Type(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue.Type) Issue(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue) Severity(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue.Severity) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)

Aggregations

ClientInputFile (org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)1 Issue (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue)1 Severity (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue.Severity)1 Type (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue.Type)1