Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

DefaultFilterableIssue.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2020 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.scanner.issue;
  21. import javax.annotation.concurrent.ThreadSafe;
  22. import org.apache.commons.lang.builder.ToStringBuilder;
  23. import org.apache.commons.lang.builder.ToStringStyle;
  24. import org.sonar.api.batch.fs.InputComponent;
  25. import org.sonar.api.batch.fs.TextRange;
  26. import org.sonar.api.batch.fs.internal.DefaultInputProject;
  27. import org.sonar.api.batch.fs.internal.DefaultTextPointer;
  28. import org.sonar.api.batch.fs.internal.DefaultTextRange;
  29. import org.sonar.api.rule.RuleKey;
  30. import org.sonar.api.scan.issue.filter.FilterableIssue;
  31. import org.sonar.scanner.protocol.output.ScannerReport.Issue;
  32. @ThreadSafe
  33. public class DefaultFilterableIssue implements FilterableIssue {
  34. private final Issue rawIssue;
  35. private final InputComponent component;
  36. private DefaultInputProject project;
  37. public DefaultFilterableIssue(DefaultInputProject project, Issue rawIssue, InputComponent component) {
  38. this.project = project;
  39. this.rawIssue = rawIssue;
  40. this.component = component;
  41. }
  42. @Override
  43. public String componentKey() {
  44. return component.key();
  45. }
  46. @Override
  47. public RuleKey ruleKey() {
  48. return RuleKey.of(rawIssue.getRuleRepository(), rawIssue.getRuleKey());
  49. }
  50. @Override
  51. public String severity() {
  52. return rawIssue.getSeverity().name();
  53. }
  54. @Override
  55. public String message() {
  56. return rawIssue.getMsg();
  57. }
  58. @Deprecated
  59. @Override
  60. public Integer line() {
  61. return rawIssue.hasTextRange() ? rawIssue.getTextRange().getStartLine() : null;
  62. }
  63. @Override
  64. public TextRange textRange() {
  65. if (!rawIssue.hasTextRange()) {
  66. return null;
  67. }
  68. return new DefaultTextRange(
  69. new DefaultTextPointer(rawIssue.getTextRange().getStartLine(), rawIssue.getTextRange().getStartOffset()),
  70. new DefaultTextPointer(rawIssue.getTextRange().getEndLine(), rawIssue.getTextRange().getEndOffset()));
  71. }
  72. @Override
  73. public Double gap() {
  74. return rawIssue.getGap() != 0 ? rawIssue.getGap() : null;
  75. }
  76. @Override
  77. public String projectKey() {
  78. return project.key();
  79. }
  80. public InputComponent getComponent() {
  81. return component;
  82. }
  83. @Override
  84. public String toString() {
  85. return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
  86. }
  87. }