// try to get desc from already fetched rules
final Optional<SonarRules> sonarRules = SonarRules.getInstance(project);
if (sonarRules.isPresent()) {
final SonarRules sonarRulesState = sonarRules.get().getState();
if (sonarRulesState != null) {
final Rule rule = sonarRulesState.getSonarRulesByRuleKey().get(issue.get().getRuleKey());
if (rule != null && !rule.isEmpty()) return rule.getDesc();
}
}
// fetch and persist rule
Settings settings;
final Module moduleForFile = ModuleUtil.findModuleForFile(psiFile.getVirtualFile(), project);
if (moduleForFile != null) {
settings = ModuleSettings.getInstance(moduleForFile).getState();
settings = SettingsUtil.process(project, settings);
} else {
settings = ProjectSettings.getInstance(project).getState();
}
if (settings == null) return null;
final String serverName = settings.getServerName();
final Optional<SonarServerConfig> serverConfig = SonarServers.get(serverName);
if (!serverConfig.isPresent()) return null;
final SonarServer sonarServer = SonarServer.create(serverConfig.get());
final Rule rule = sonarServer.getRule(issue.get().getRuleKey());
// persist rule
if (sonarRules.isPresent()) {
final SonarRules sonarRulesState = sonarRules.get().getState();
if (sonarRulesState!= null && !rule.isEmpty()) {
sonarRulesState.getSonarRulesByRuleKey().put(issue.get().getRuleKey(), rule);
}
}
return rule.getDesc();
}