001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2020 the original author or authors. 004// 005// This library is free software; you can redistribute it and/or 006// modify it under the terms of the GNU Lesser General Public 007// License as published by the Free Software Foundation; either 008// version 2.1 of the License, or (at your option) any later version. 009// 010// This library is distributed in the hope that it will be useful, 011// but WITHOUT ANY WARRANTY; without even the implied warranty of 012// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013// Lesser General Public License for more details. 014// 015// You should have received a copy of the GNU Lesser General Public 016// License along with this library; if not, write to the Free Software 017// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018//////////////////////////////////////////////////////////////////////////////// 019 020package com.puppycrawl.tools.checkstyle.meta; 021 022import java.util.ArrayList; 023import java.util.Collections; 024import java.util.HashMap; 025import java.util.List; 026import java.util.Map; 027 028/** Simple POJO class for module details. */ 029public final class ModuleDetails { 030 031 /** List of properties of the module. */ 032 private final List<ModulePropertyDetails> properties = new ArrayList<>(); 033 034 /** Properties of the module arranged in a map where key is property name. */ 035 private final Map<String, ModulePropertyDetails> modulePropertyKeyMap = new HashMap<>(); 036 037 /** List of violation message keys of the module. */ 038 private final List<String> violationMessageKeys = new ArrayList<>(); 039 040 /** Name of the module. */ 041 private String name; 042 043 /** Fully qualified name of the module. */ 044 private String fullQualifiedName; 045 046 /** Parent module. */ 047 private String parent; 048 049 /** Description of the module. */ 050 private String description; 051 052 /** Type of the module(check/filter/filefilter). */ 053 private ModuleType moduleType; 054 055 /** 056 * Get name of module. 057 * 058 * @return name of module 059 */ 060 public String getName() { 061 return name; 062 } 063 064 /** 065 * Set name of module. 066 * 067 * @param name module name 068 */ 069 public void setName(String name) { 070 this.name = name; 071 } 072 073 /** 074 * Get fully qualified name of module. 075 * 076 * @return fully qualified name of module 077 */ 078 public String getFullQualifiedName() { 079 return fullQualifiedName; 080 } 081 082 /** 083 * Set fully qualified name of module. 084 * 085 * @param fullQualifiedName fully qualified name of module 086 */ 087 public void setFullQualifiedName(String fullQualifiedName) { 088 this.fullQualifiedName = fullQualifiedName; 089 } 090 091 /** 092 * Get parent of module. 093 * 094 * @return parent of module 095 */ 096 public String getParent() { 097 return parent; 098 } 099 100 /** 101 * Set parent of module. 102 * 103 * @param parent parent of module 104 */ 105 public void setParent(String parent) { 106 this.parent = parent; 107 } 108 109 /** 110 * Get description of module. 111 * 112 * @return description of module 113 */ 114 public String getDescription() { 115 return description; 116 } 117 118 /** 119 * Set description of module. 120 * 121 * @param description description of module 122 */ 123 public void setDescription(String description) { 124 this.description = description; 125 } 126 127 /** 128 * Get property list of module. 129 * 130 * @return property list of module 131 */ 132 public List<ModulePropertyDetails> getProperties() { 133 return Collections.unmodifiableList(properties); 134 } 135 136 /** 137 * Add a single module property to the module's property list and map both. 138 * 139 * @param property module property 140 */ 141 public void addToProperties(ModulePropertyDetails property) { 142 properties.add(property); 143 modulePropertyKeyMap.put(property.getName(), property); 144 } 145 146 /** 147 * Add a list of properties to the module's property list and map both. 148 * 149 * @param modulePropertyDetailsList list of module property 150 */ 151 public void addToProperties(List<ModulePropertyDetails> modulePropertyDetailsList) { 152 properties.addAll(modulePropertyDetailsList); 153 modulePropertyDetailsList.forEach(modulePropertyDetails -> { 154 modulePropertyKeyMap.put(modulePropertyDetails.getName(), modulePropertyDetails); 155 }); 156 } 157 158 /** 159 * Get violation message keys of the module. 160 * 161 * @return violation message keys of module 162 */ 163 public List<String> getViolationMessageKeys() { 164 return Collections.unmodifiableList(violationMessageKeys); 165 } 166 167 /** 168 * Add a key to the violation message key list of the module. 169 * 170 * @param msg violation message key 171 */ 172 public void addToViolationMessages(String msg) { 173 violationMessageKeys.add(msg); 174 } 175 176 /** 177 * Add a list of keys to the violation message key list of the module. 178 * 179 * @param msgList a list of violation message keys 180 */ 181 public void addToViolationMessages(List<String> msgList) { 182 violationMessageKeys.addAll(msgList); 183 } 184 185 /** 186 * Get a module property object by supplying its name as key. 187 * 188 * @param key module property name 189 * @return module property object 190 */ 191 public ModulePropertyDetails getModulePropertyByKey(String key) { 192 return modulePropertyKeyMap.get(key); 193 } 194 195 /** 196 * Get module type. 197 * 198 * @return module type 199 */ 200 public ModuleType getModuleType() { 201 return moduleType; 202 } 203 204 /** 205 * Set type of module. 206 * 207 * @param moduleType type of module 208 */ 209 public void setModuleType(ModuleType moduleType) { 210 this.moduleType = moduleType; 211 } 212}