mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-14 18:05:27 +07:00
master-inspectopedia-collector
Cleaner checks for br element Merge branch 'master' into master-inspectopedia-collector Collecting CWE ids Merge-request: IJ-MR-126396 Merged-by: Egor Malyshev <egor.malyshev@jetbrains.com> GitOrigin-RevId: 6bec313f9bf5a255bd81e922ed2e0b34fc6e4304
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0b5363a00e
commit
63d7aa8192
@@ -8,8 +8,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||
import com.intellij.codeInspection.InspectionEP;
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ex.ScopeToolState;
|
||||
import com.intellij.codeInspection.ex.*;
|
||||
import com.intellij.codeInspection.options.*;
|
||||
import com.intellij.ide.plugins.PluginManager;
|
||||
import com.intellij.inspectopedia.extractor.data.Inspection;
|
||||
@@ -18,6 +17,7 @@ import com.intellij.inspectopedia.extractor.data.Plugin;
|
||||
import com.intellij.inspectopedia.extractor.data.Plugins;
|
||||
import com.intellij.inspectopedia.extractor.utils.HtmlUtils;
|
||||
import com.intellij.openapi.application.ApplicationInfo;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ApplicationStarter;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -97,6 +97,11 @@ final class InspectopediaExtractor implements ApplicationStarter {
|
||||
|
||||
availablePlugins.put(IDE_NAME, new Plugin(IDE_NAME, IDE_NAME, IDE_VERSION));
|
||||
|
||||
final InspectionMetaInformationService
|
||||
service = ApplicationManager.getApplication().getService(InspectionMetaInformationService.class);
|
||||
|
||||
final MetaInformationState inspectionsExtraState = service == null ? null : (MetaInformationState)service.getState(null);
|
||||
|
||||
for (final ScopeToolState scopeToolState : scopeToolStates) {
|
||||
|
||||
final InspectionToolWrapper<?, ?> wrapper = scopeToolState.getTool();
|
||||
@@ -118,13 +123,16 @@ final class InspectopediaExtractor implements ApplicationStarter {
|
||||
catch (Throwable t) {
|
||||
LOG.info("Cannot create options panel " + wrapper.getShortName(), t);
|
||||
}
|
||||
final MetaInformation metaInformation = inspectionsExtraState == null ? null : inspectionsExtraState.getInspections().get(wrapper.getID());
|
||||
final List<Integer> cweIds = metaInformation == null ? null : metaInformation.getCweIds();
|
||||
|
||||
final String language = wrapper.getLanguage();
|
||||
final String briefDescription = HtmlUtils.cleanupHtml(description[0], language);
|
||||
final String extendedDescription = description.length > 1 ? HtmlUtils.cleanupHtml(description[1], language) : null;
|
||||
final Inspection inspection = new Inspection(wrapper.getShortName(), wrapper.getDisplayName(), wrapper.getDefaultLevel().getName(),
|
||||
language, briefDescription,
|
||||
extendedDescription, Arrays.asList(wrapper.getGroupPath()), wrapper.applyToDialects(),
|
||||
wrapper.isCleanupTool(), wrapper.isEnabledByDefault(), panelInfo);
|
||||
wrapper.isCleanupTool(), wrapper.isEnabledByDefault(), panelInfo, cweIds);
|
||||
|
||||
availablePlugins.get(pluginId).addInspection(inspection);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ public class Inspection implements Comparable<Inspection> {
|
||||
public String extendedDescription = "";
|
||||
public boolean hasOptionsPanel = false;
|
||||
public List<OptionsPanelInfo> options = null;
|
||||
public List<Integer> cweIds = null;
|
||||
|
||||
public Inspection(String id,
|
||||
String name,
|
||||
@@ -38,7 +39,8 @@ public class Inspection implements Comparable<Inspection> {
|
||||
boolean appliesToDialects,
|
||||
boolean partOfCodeCleanup,
|
||||
boolean enabledByDefault,
|
||||
List<OptionsPanelInfo> options) {
|
||||
List<OptionsPanelInfo> options,
|
||||
List<Integer> cweIds) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.severity = severity;
|
||||
@@ -51,6 +53,7 @@ public class Inspection implements Comparable<Inspection> {
|
||||
this.isEnabledDefault = enabledByDefault;
|
||||
this.hasOptionsPanel = options != null;
|
||||
this.options = options;
|
||||
this.cweIds = cweIds;
|
||||
}
|
||||
|
||||
public Inspection() {
|
||||
|
||||
@@ -110,12 +110,13 @@ public final class HtmlUtils {
|
||||
REMOVE_MAP.forEach(map -> document.select(map).remove());
|
||||
|
||||
Elements paragraphsWithParagraphs;
|
||||
//What if there are hypothetically many nested P, and we're going to miss them with only one iteration?
|
||||
//What if there are hypothetically many nested P, and we're going to miss them with only one iteration?
|
||||
do {
|
||||
paragraphsWithParagraphs = document.select("p:has(p)");
|
||||
paragraphsWithParagraphs.unwrap();
|
||||
} while (!paragraphsWithParagraphs.isEmpty());
|
||||
//And then there were multi nested paragraphs which deep down contained nothing but whitespace? Now they're ready for removal as well :)
|
||||
}
|
||||
while (!paragraphsWithParagraphs.isEmpty());
|
||||
//And then there were multi nested paragraphs which deep down contained nothing but whitespace? Now they're ready for removal as well :)
|
||||
final Elements emptyParagraphs = document.select("p:matches(^\\s*$)");
|
||||
emptyParagraphs.remove();
|
||||
|
||||
@@ -129,18 +130,16 @@ public final class HtmlUtils {
|
||||
}
|
||||
|
||||
private static boolean isBlockElement(@NotNull Node node) {
|
||||
if (!(node instanceof Element element))
|
||||
if (!(node instanceof Element element)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return element.tagName().equals("list") ||
|
||||
(element.tagName().equals("code") && element.attr("style").equals("block")) ||
|
||||
return "list".equals(element.tagName()) ||
|
||||
("code".equals(element.tagName()) && "block".equals(element.attr("style"))) ||
|
||||
isBr(node);
|
||||
}
|
||||
|
||||
private static boolean isBr(@NotNull Node node) {
|
||||
if (!(node instanceof Element))
|
||||
return false;
|
||||
|
||||
return "br".equals(((Element) node).tagName());
|
||||
return node instanceof Element element && "br".equals(element.tagName());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user