From 39a84b21d571d103c4fb47906f83a1d51da41706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20C=C3=A9bron?= Date: Fri, 15 Mar 2019 17:49:14 +0100 Subject: [PATCH] IDEA-209078 Devkit plugin.xml: allow multiple components with same interface-class across types --- .../RegistrationProblemsInspection.java | 20 +++++++++---------- .../ComponentMultipleWithSameInterface.xml | 11 ++++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/plugins/devkit/devkit-core/src/inspections/RegistrationProblemsInspection.java b/plugins/devkit/devkit-core/src/inspections/RegistrationProblemsInspection.java index 60f0429cda91..9ed76ccae668 100644 --- a/plugins/devkit/devkit-core/src/inspections/RegistrationProblemsInspection.java +++ b/plugins/devkit/devkit-core/src/inspections/RegistrationProblemsInspection.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.idea.devkit.inspections; import com.intellij.codeInsight.intention.QuickFixFactory; @@ -14,7 +14,7 @@ import com.intellij.psi.util.PsiUtil; import com.intellij.psi.xml.*; import com.intellij.util.ArrayUtil; import com.intellij.util.SmartList; -import gnu.trove.THashSet; +import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -193,7 +193,7 @@ public class RegistrationProblemsInspection extends DevKitInspectionBase { private final XmlFile myXmlFile; private final PsiManager myPsiManager; private final GlobalSearchScope myScope; - private final Set myInterfaceClasses = new THashSet<>(); + private final MultiMap myInterfaceClasses = MultiMap.createSet(); private final boolean myOnTheFly; private RegistrationChecker(InspectionManager manager, XmlFile xmlFile, boolean onTheFly) { @@ -250,17 +250,17 @@ public class RegistrationProblemsInspection extends DevKitInspectionBase { final String fqn = intfClass.getQualifiedName(); if (type == ComponentType.MODULE) { - if (!checkInterface(fqn, intf)) { + if (!checkInterface(type, fqn, intf)) { // module components can be restricted to modules of certain types final String[] keys = makeQualifiedModuleInterfaceNames(component, fqn); for (String key : keys) { - checkInterface(key, intf); - myInterfaceClasses.add(key); + checkInterface(type, key, intf); + myInterfaceClasses.putValue(type, key); } } } else { - checkInterface(fqn, intf); - myInterfaceClasses.add(fqn); + checkInterface(type, fqn, intf); + myInterfaceClasses.putValue(type, fqn); } if (intfClass != implClass && !implClass.isInheritor(intfClass, true)) { @@ -274,8 +274,8 @@ public class RegistrationProblemsInspection extends DevKitInspectionBase { return true; } - private boolean checkInterface(String fqn, XmlTagValue value) { - if (myInterfaceClasses.contains(fqn)) { + private boolean checkInterface(ComponentType type, String fqn, XmlTagValue value) { + if (myInterfaceClasses.get(type).contains(fqn)) { addProblem(value, DevKitBundle.message("inspections.registration.problems.component.duplicate.interface", fqn), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, myOnTheFly); diff --git a/plugins/devkit/devkit-java-tests/testData/inspections/registrationProblems/xml/ComponentMultipleWithSameInterface.xml b/plugins/devkit/devkit-java-tests/testData/inspections/registrationProblems/xml/ComponentMultipleWithSameInterface.xml index 5b3c328cb58d..1312d5ab71fd 100644 --- a/plugins/devkit/devkit-java-tests/testData/inspections/registrationProblems/xml/ComponentMultipleWithSameInterface.xml +++ b/plugins/devkit/devkit-java-tests/testData/inspections/registrationProblems/xml/ComponentMultipleWithSameInterface.xml @@ -8,8 +8,19 @@ ApplicationComponentInterface ApplicationComponent + + java.lang.Number + java.lang.Double + + + + java.lang.Number + java.lang.Double + + +