From acd72e6cdd08072c6498fa7640d4f1524dfa892b Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Mon, 23 Nov 2020 19:38:32 +0300 Subject: [PATCH] DOM: get rid of Raw type usage inspection in DomUtil GitOrigin-RevId: 6c171a9458d9d3f9eca0a5d7efde54768b5a5d6f --- .../src/com/intellij/util/xml/DomUtil.java | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/xml/dom-openapi/src/com/intellij/util/xml/DomUtil.java b/xml/dom-openapi/src/com/intellij/util/xml/DomUtil.java index fcdf73ba0e89..c99431c5510f 100644 --- a/xml/dom-openapi/src/com/intellij/util/xml/DomUtil.java +++ b/xml/dom-openapi/src/com/intellij/util/xml/DomUtil.java @@ -34,20 +34,19 @@ import java.util.concurrent.ConcurrentMap; * @author peter */ public class DomUtil { - private static final Logger LOG = Logger.getInstance(DomUtil.class); public static final TypeVariable> GENERIC_VALUE_TYPE_VARIABLE = GenericValue.class.getTypeParameters()[0]; private static final Class DUMMY = void.class; - private static final Key FILE_ELEMENT_KEY = Key.create("dom file element"); + private static final Key> FILE_ELEMENT_KEY = Key.create("dom file element"); - private static final ConcurrentMap ourTypeParameters = ConcurrentFactoryMap.createMap(key-> { + private static final ConcurrentMap> ourTypeParameters = ConcurrentFactoryMap.createMap(key-> { final Class result = substituteGenericType(GENERIC_VALUE_TYPE_VARIABLE, key); return result == null ? DUMMY : result; } ); - private static final ConcurrentMap, Class> ourVariableSubstitutions = + private static final ConcurrentMap, Class> ourVariableSubstitutions = ConcurrentFactoryMap.createMap(key -> ReflectionUtil.substituteGenericType(key.first, key.second)); - public static Class extractParameterClassFromGenericType(Type type) { + public static Class extractParameterClassFromGenericType(Type type) { return getGenericValueParameter(type); } @@ -129,7 +128,7 @@ public class DomUtil { final DomGenericInfo genericInfo = parent.getGenericInfo(); if (element instanceof GenericAttributeValue) { - final DomAttributeChildDescription description = genericInfo.getAttributeChildDescription(xmlElementName, namespace); + DomAttributeChildDescription description = genericInfo.getAttributeChildDescription(xmlElementName, namespace); assert description != null; return description.getGetterMethod(); } @@ -143,16 +142,16 @@ public class DomUtil { } @Nullable - public static Class getGenericValueParameter(Type type) { - final Class aClass = ourTypeParameters.get(type); + public static Class getGenericValueParameter(Type type) { + final Class aClass = ourTypeParameters.get(type); return aClass == DUMMY ? null : aClass; } @Nullable - public static XmlElement getValueElement(GenericDomValue domValue) { + public static XmlElement getValueElement(GenericDomValue domValue) { if (domValue instanceof GenericAttributeValue) { - final GenericAttributeValue value = (GenericAttributeValue)domValue; - final XmlAttributeValue attributeValue = value.getXmlAttributeValue(); + GenericAttributeValue value = (GenericAttributeValue)domValue; + XmlAttributeValue attributeValue = value.getXmlAttributeValue(); return attributeValue == null ? value.getXmlAttribute() : attributeValue; } else { return domValue.getXmlTag(); @@ -160,7 +159,7 @@ public class DomUtil { } public static List getIdentitySiblings(DomElement element) { - final GenericDomValue nameDomElement = element.getGenericInfo().getNameDomElement(element); + GenericDomValue nameDomElement = element.getGenericInfo().getNameDomElement(element); if (nameDomElement == null) return Collections.emptyList(); final NameValue nameValue = nameDomElement.getAnnotation(NameValue.class); @@ -188,9 +187,9 @@ public class DomUtil { final List result = new SmartList<>(); parent.acceptChildren(new DomElementVisitor() { @Override - public void visitDomElement(final DomElement element) { + public void visitDomElement(DomElement element) { if (type.isInstance(element)) { - result.add((T)element); + result.add(type.cast(element)); } } }); @@ -216,7 +215,7 @@ public class DomUtil { if (parent instanceof GenericAttributeValue) return Collections.emptyList(); if (parent instanceof DomFileElement) { - final DomFileElement element = (DomFileElement)parent; + DomFileElement element = (DomFileElement)parent; return tags ? Collections.singletonList(element.getRootElement()) : Collections.emptyList(); } @@ -228,10 +227,10 @@ public class DomUtil { if (attributes) { for (final XmlAttribute attribute : tag.getAttributes()) { if (!attribute.isValid()) { - LOG.error("Invalid attr: parent.valid=" + tag.isValid()); + Logger.getInstance(DomUtil.class).error("Invalid attr: parent.valid=" + tag.isValid()); continue; } - GenericAttributeValue element = domManager.getDomElement(attribute); + GenericAttributeValue element = domManager.getDomElement(attribute); if (checkHasXml(attribute, element)) { ContainerUtil.addIfNotNull(result, element); } @@ -240,7 +239,7 @@ public class DomUtil { if (tags) { for (final XmlTag subTag : tag.getSubTags()) { if (!subTag.isValid()) { - LOG.error("Invalid subtag: parent.valid=" + tag.isValid()); + Logger.getInstance(DomUtil.class).error("Invalid subtag: parent.valid=" + tag.isValid()); continue; } DomElement element = domManager.getDomElement(subTag); @@ -256,7 +255,7 @@ public class DomUtil { private static boolean checkHasXml(XmlElement psi, DomElement dom) { if (dom != null && !hasXml(dom)) { - LOG.error("No xml for dom " + dom + "; attr=" + psi + ", physical=" + psi.isPhysical()); + Logger.getInstance(DomUtil.class).error("No xml for dom " + dom + "; attr=" + psi + ", physical=" + psi.isPhysical()); return false; } return true; @@ -311,7 +310,7 @@ public class DomUtil { curElement != null; curElement = curElement.getParent()) { if (requiredClass.isInstance(curElement)) { - return (T)curElement; + return requiredClass.cast(curElement); } } return null; @@ -351,7 +350,7 @@ public class DomUtil { final DomManager domManager = DomManager.getDomManager(project); final XmlAttribute attr = PsiTreeUtil.getParentOfType(element, XmlAttribute.class, false); if (attr != null) { - final GenericAttributeValue value = domManager.getDomElement(attr); + GenericAttributeValue value = domManager.getDomElement(attr); if (value != null) return value; } @@ -421,7 +420,6 @@ public class DomUtil { } public static DomFileElement getFileElement(@NotNull DomElement element) { - if (element instanceof DomFileElement) { return (DomFileElement)element; }