001/* 002 * SonarQube 003 * Copyright (C) 2009-2016 SonarSource SA 004 * mailto:contact AT sonarsource DOT com 005 * 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.api.batch.rule.internal; 021 022import com.google.common.collect.ImmutableMap; 023import org.sonar.api.batch.debt.DebtRemediationFunction; 024import org.sonar.api.batch.rule.Rule; 025import org.sonar.api.batch.rule.RuleParam; 026import org.sonar.api.rule.RuleKey; 027import org.sonar.api.rule.RuleStatus; 028 029import javax.annotation.CheckForNull; 030import javax.annotation.concurrent.Immutable; 031 032import java.util.Collection; 033import java.util.Map; 034 035@Immutable 036public class DefaultRule implements Rule { 037 038 private final RuleKey key; 039 private final Integer id; 040 private final String name; 041 private final String severity; 042 private final String description; 043 private final String internalKey; 044 private final RuleStatus status; 045 private final Map<String, RuleParam> params; 046 047 DefaultRule(NewRule newRule) { 048 this.key = newRule.key; 049 this.id = newRule.id; 050 this.name = newRule.name; 051 this.severity = newRule.severity; 052 this.description = newRule.description; 053 this.internalKey = newRule.internalKey; 054 this.status = newRule.status; 055 056 ImmutableMap.Builder<String, RuleParam> builder = ImmutableMap.builder(); 057 for (NewRuleParam newRuleParam : newRule.params.values()) { 058 builder.put(newRuleParam.key, new DefaultRuleParam(newRuleParam)); 059 } 060 params = builder.build(); 061 } 062 063 @Override 064 public RuleKey key() { 065 return key; 066 } 067 068 @CheckForNull 069 public Integer id() { 070 return id; 071 } 072 073 @Override 074 public String name() { 075 return name; 076 } 077 078 @Override 079 public String severity() { 080 return severity; 081 } 082 083 @Override 084 public String description() { 085 return description; 086 } 087 088 @Override 089 public String internalKey() { 090 return internalKey; 091 } 092 093 @Override 094 public RuleStatus status() { 095 return status; 096 } 097 098 @Override 099 public String debtSubCharacteristic() { 100 throw new UnsupportedOperationException("Debt characteristic is not available by analyzer since version 5.2 (data computation moved to server)"); 101 } 102 103 @Override 104 public DebtRemediationFunction debtRemediationFunction() { 105 throw new UnsupportedOperationException("Debt remediation function is not available by analyzer since version 5.2 (data computation moved to server)"); 106 } 107 108 @Override 109 public RuleParam param(String paramKey) { 110 return params.get(paramKey); 111 } 112 113 @Override 114 public Collection<RuleParam> params() { 115 return params.values(); 116 } 117}