1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-21 18:17:58 +01:00

Merge pull request #452 from Flowdalic/abstract-provider-element-type

[core] AbstractProvider should also consider TypeVariable
This commit is contained in:
Florian Schmaus 2021-01-10 20:45:12 +01:00 committed by GitHub
commit 938a4271f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2019-2020 Florian Schmaus
* Copyright 2019-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,6 +18,7 @@ package org.jivesoftware.smack.provider;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import org.jivesoftware.smack.packet.Element;
@ -42,9 +43,12 @@ public class AbstractProvider<E extends Element> {
} else if (elementType instanceof ParameterizedType) {
ParameterizedType parameteriezedElementType = (ParameterizedType) elementType;
elementClass = (Class<E>) parameteriezedElementType.getRawType();
} else if (elementType instanceof TypeVariable) {
TypeVariable<?> typeVariableElementType = (TypeVariable<?>) elementType;
elementClass = (Class<E>) typeVariableElementType.getClass();
} else {
throw new AssertionError(
"Element type '" + elementType + "' is neither of type Class or ParameterizedType");
throw new AssertionError("Element type '" + elementType + "' (" + elementType.getClass()
+ ") is neither of type Class, ParameterizedType or TypeVariable");
}
}