mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
DOM: get rid of Raw type usage inspection in DomUtil
GitOrigin-RevId: 6c171a9458d9d3f9eca0a5d7efde54768b5a5d6f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
994c5d9a60
commit
acd72e6cdd
@@ -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<Class<GenericValue>> GENERIC_VALUE_TYPE_VARIABLE = GenericValue.class.getTypeParameters()[0];
|
||||
private static final Class<Void> DUMMY = void.class;
|
||||
private static final Key<DomFileElement> FILE_ELEMENT_KEY = Key.create("dom file element");
|
||||
private static final Key<DomFileElement<?>> FILE_ELEMENT_KEY = Key.create("dom file element");
|
||||
|
||||
private static final ConcurrentMap<Type, Class> ourTypeParameters = ConcurrentFactoryMap.createMap(key-> {
|
||||
private static final ConcurrentMap<Type, Class<?>> ourTypeParameters = ConcurrentFactoryMap.createMap(key-> {
|
||||
final Class<?> result = substituteGenericType(GENERIC_VALUE_TYPE_VARIABLE, key);
|
||||
return result == null ? DUMMY : result;
|
||||
}
|
||||
);
|
||||
private static final ConcurrentMap<Couple<Type>, Class> ourVariableSubstitutions =
|
||||
private static final ConcurrentMap<Couple<Type>, 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<? extends DomElement> 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<T> 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 <T extends DomElement> DomFileElement<T> getFileElement(@NotNull DomElement element) {
|
||||
|
||||
if (element instanceof DomFileElement) {
|
||||
return (DomFileElement)element;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user