本文整理了Java中javax.lang.model.element.TypeElement.getSuperclass()
方法的一些代码示例,展示了TypeElement.getSuperclass()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TypeElement.getSuperclass()
方法的具体详情如下:
包路径:javax.lang.model.element.TypeElement
类名称:TypeElement
方法名:getSuperclass
[英]Returns the direct superclass of this type element. If this type element represents an interface or the class java.lang.Object, then a NoTypewith kind TypeKind#NONE is returned.
[中]返回此类型元素的直接超类。如果这个类型元素代表一个接口或java类。lang.Object,则返回一个NoTypewith-TypeKind#NONE。
代码示例来源:origin: JakeWharton/butterknife
/** Finds the parent binder type in the supplied set, if any. */
private @Nullable TypeElement findParentType(TypeElement typeElement, Set<TypeElement> parents) {
TypeMirror type;
while (true) {
type = typeElement.getSuperclass();
if (type.getKind() == TypeKind.NONE) {
return null;
}
typeElement = (TypeElement) ((DeclaredType) type).asElement();
if (parents.contains(typeElement)) {
return typeElement;
}
}
}
代码示例来源:origin: greenrobot/EventBus
private TypeElement getSuperclass(TypeElement type) {
if (type.getSuperclass().getKind() == TypeKind.DECLARED) {
TypeElement superclass = (TypeElement) processingEnv.getTypeUtils().asElement(type.getSuperclass());
String name = superclass.getQualifiedName().toString();
if (name.startsWith("java.") || name.startsWith("javax.") || name.startsWith("android.")) {
// Skip system classes, this just degrades performance
return null;
} else {
return superclass;
}
} else {
return null;
}
}
代码示例来源:origin: androidannotations/androidannotations
/**
* Finds superclasses until reaching the Object class
*/
private void addAncestorsElements(Set<TypeElement> elements, TypeElement typeElement) {
TypeMirror ancestorTypeMirror = typeElement.getSuperclass();
if (!isRootObjectClass(ancestorTypeMirror) && !isAndroidClass(ancestorTypeMirror) && ancestorTypeMirror instanceof DeclaredType) {
DeclaredType ancestorDeclaredType = (DeclaredType) ancestorTypeMirror;
Element ancestorElement = ancestorDeclaredType.asElement();
if (ancestorElement instanceof TypeElement) {
addAncestorsElements(elements, (TypeElement) ancestorElement);
elements.add((TypeElement) ancestorElement);
}
}
}
代码示例来源:origin: hibernate/hibernate-orm
public static TypeElement getSuperclassTypeElement(TypeElement element) {
final TypeMirror superClass = element.getSuperclass();
//superclass of Object is of NoType which returns some other kind
if ( superClass.getKind() == TypeKind.DECLARED ) {
//F..king Ch...t Have those people used their horrible APIs even once?
final Element superClassElement = ( (DeclaredType) superClass ).asElement();
return (TypeElement) superClassElement;
}
else {
return null;
}
}
代码示例来源:origin: requery/requery
private static boolean extendsClass(Types types, TypeElement element, String className) {
if (namesEqual(element, className)) {
return true;
}
// check super types
TypeMirror superType = element.getSuperclass();
while (superType != null && superType.getKind() != TypeKind.NONE) {
TypeElement superTypeElement = (TypeElement) types.asElement(superType);
if (namesEqual(superTypeElement, className)) {
return true;
}
superType = superTypeElement.getSuperclass();
}
return false;
}
代码示例来源:origin: f2prateek/dart
final TypeMirror superType = element.getSuperclass();
final TypeElement superTypeElement = (TypeElement) ((DeclaredType) superType).asElement();
代码示例来源:origin: remkop/picocli
/**
* Obtains the super type element for a given type element.
*
* @param element The type element
* @return The super type element or null if none exists
*/
static TypeElement superClassFor(TypeElement element) {
TypeMirror superclass = element.getSuperclass();
if (superclass.getKind() == TypeKind.NONE) {
return null;
}
logger.finest(format("Superclass of %s is %s (of kind %s)", element, superclass, superclass.getKind()));
DeclaredType kind = (DeclaredType) superclass;
return (TypeElement) kind.asElement();
}
代码示例来源:origin: requery/requery
static boolean overridesMethod(Types types, TypeElement element, String methodName) {
while (element != null) {
if (ElementFilter.methodsIn(element.getEnclosedElements()).stream()
.anyMatch(method -> method.getSimpleName().contentEquals(methodName))) {
return true;
}
TypeMirror superType = element.getSuperclass();
if (superType.getKind() == TypeKind.NONE) {
break;
} else {
element = (TypeElement) types.asElement(superType);
}
if (namesEqual(element, Object.class.getCanonicalName())) {
break;
}
}
return false;
}
代码示例来源:origin: querydsl/querydsl
TypeMirror superType = typeElement.getSuperclass();
TypeElement superTypeElement = null;
if (superType instanceof DeclaredType) {
superTypeElement = (TypeElement) ((DeclaredType) superType).asElement();
代码示例来源:origin: remkop/picocli
private TypeMirror createStringTypeMirror() {
TypeElement element = typeElement;
while (element.getSuperclass().getKind() != TypeKind.NONE) {
logger.finest("finding toString in " + element);
element = (TypeElement) ((DeclaredType) element.getSuperclass()).asElement();
}
for (Element enclosed : typeElement.getEnclosedElements()) {
if (enclosed.getKind() == ElementKind.METHOD) {
ExecutableElement method = (ExecutableElement) enclosed;
if (method.getSimpleName().contentEquals("toString")) {
return method.getReturnType();
}
}
}
throw new IllegalStateException("Cannot find toString method in Object");
}
private static boolean find(String interfaceName, TypeElement typeElement) {
代码示例来源:origin: airbnb/epoxy
if (clazz.getSuperclass().getKind() != TypeKind.DECLARED) {
return null;
DeclaredType superclass = (DeclaredType) clazz.getSuperclass();
TypeMirror recursiveResult =
getEpoxyObjectType((TypeElement) typeUtils.asElement(superclass), typeUtils);
if (recursiveResult != null && recursiveResult.getKind() != TypeKind.TYPEVAR) {
代码示例来源:origin: mulesoft/mule
private TypeElement getSuperclassElement(Element element) {
if (element instanceof TypeElement) {
TypeMirror superclass = ((TypeElement) element).getSuperclass();
if (superclass instanceof DeclaredType) {
return ((TypeElement) ((DeclaredType) superclass).asElement());
}
}
return null;
}
代码示例来源:origin: JakeWharton/butterknife
return true;
if (typeMirror.getKind() != TypeKind.DECLARED) {
return false;
List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
if (typeArguments.size() > 0) {
StringBuilder typeString = new StringBuilder(declaredType.asElement().toString());
typeString.append('<');
for (int i = 0; i < typeArguments.size(); i++) {
Element element = declaredType.asElement();
if (!(element instanceof TypeElement)) {
return false;
TypeMirror superType = typeElement.getSuperclass();
if (isSubtypeOfType(superType, otherType)) {
return true;
代码示例来源:origin: airbnb/epoxy
/**
* Get information about methods returning class type of the original class so we can duplicate
* them in the generated class for chaining purposes
*/
protected void collectMethodsReturningClassType(TypeElement modelClass, Types typeUtils) {
TypeElement clazz = modelClass;
while (clazz.getSuperclass().getKind() != TypeKind.NONE) {
for (Element subElement : clazz.getEnclosedElements()) {
Set<Modifier> modifiers = subElement.getModifiers();
if (subElement.getKind() == ElementKind.METHOD
&& !modifiers.contains(Modifier.PRIVATE)
&& !modifiers.contains(Modifier.FINAL)
&& !modifiers.contains(Modifier.STATIC)) {
TypeMirror methodReturnType = ((ExecutableType) subElement.asType()).getReturnType();
if (methodReturnType.equals(clazz.asType())
|| typeUtils.isSubtype(clazz.asType(), methodReturnType)) {
ExecutableElement castedSubElement = ((ExecutableElement) subElement);
List<? extends VariableElement> params = castedSubElement.getParameters();
String methodName = subElement.getSimpleName().toString();
if (methodName.equals(RESET_METHOD) && params.isEmpty()) {
continue;
}
methodsReturningClassType.add(new MethodInfo(methodName, modifiers,
buildParamSpecs(params), castedSubElement.isVarArgs()));
}
}
}
clazz = (TypeElement) typeUtils.asElement(clazz.getSuperclass());
}
}
代码示例来源:origin: wso2/siddhi
private String getMatchingSuperClass(Element elementToValidate, String[] superClassNames) {
TypeMirror superType = ((TypeElement) elementToValidate).getSuperclass();
String superClass = null;
// Looping the inheritance hierarchy to check if the element inherits at least one of the super
// classes specified.
while (!"none".equals(superType.toString())) {
Element superTypeElement = ((DeclaredType) superType).asElement();
if (Arrays.asList(superClassNames).contains(superTypeElement.toString())) {
superClass = superTypeElement.toString();
break;
}
superType = ((TypeElement) superTypeElement).getSuperclass();
}
return superClass;
}
代码示例来源:origin: hibernate/hibernate-orm
private static String findMappedSuperClass(MetaEntity entity, Context context) {
TypeMirror superClass = entity.getTypeElement().getSuperclass();
//superclass of Object is of NoType which returns some other kind
while ( superClass.getKind() == TypeKind.DECLARED ) {
//F..king Ch...t Have those people used their horrible APIs even once?
final Element superClassElement = ( (DeclaredType) superClass ).asElement();
String superClassName = ( (TypeElement) superClassElement ).getQualifiedName().toString();
if ( extendsSuperMetaModel( superClassElement, entity.isMetaComplete(), context ) ) {
return superClassName;
}
superClass = ( (TypeElement) superClassElement ).getSuperclass();
}
return null;
}
代码示例来源:origin: requery/requery
private static boolean implementsInterface(Types types, TypeElement element, String interfaceName) {
// check name or interfaces
if (namesEqual(element, interfaceName)) {
return true;
}
TypeMirror type = element.asType();
while (type != null && type.getKind() != TypeKind.NONE) {
TypeElement currentElement = (TypeElement) types.asElement(type);
if (currentElement == null) {
break;
}
List<? extends TypeMirror> interfaces = element.getInterfaces();
for (TypeMirror interfaceType : interfaces) {
interfaceType = types.erasure(interfaceType);
TypeElement typeElement = (TypeElement) types.asElement(interfaceType);
if (typeElement != null && implementsInterface(types, typeElement, interfaceName)) {
return true;
}
}
type = currentElement.getSuperclass();
}
return false;
}
代码示例来源:origin: mulesoft/mule
public static List<TypeMirror> getSuperClassGenerics(TypeElement type, Class superClass,
ProcessingEnvironment processingEnvironment) {
TypeElement superClassTypeElement = processingEnvironment.getElementUtils().getTypeElement(superClass.getName());
TypeElement objectType = processingEnvironment.getElementUtils().getTypeElement(Object.class.getName());
TypeMirror superClassTypeMirror = processingEnvironment.getTypeUtils().erasure(superClassTypeElement.asType());
if (!processingEnvironment.getTypeUtils().isAssignable(type.asType(), superClassTypeMirror)) {
throw new IllegalArgumentException(
format("Class '%s' does not extend the '%s' class", type.getQualifiedName(),
superClass.getSimpleName()));
}
DeclaredType searchClass = (DeclaredType) type.asType();
while (!processingEnvironment.getTypeUtils().isAssignable(objectType.asType(), searchClass)) {
if (processingEnvironment.getTypeUtils().isSameType(superClassTypeMirror,
processingEnvironment.getTypeUtils().erasure(searchClass))) {
List<TypeMirror> typeArguments = (List<TypeMirror>) searchClass.getTypeArguments();
return typeArguments;
}
TypeMirror superclass = ((TypeElement) searchClass.asElement()).getSuperclass();
if (superclass instanceof DeclaredType) {
searchClass = (DeclaredType) superclass;
} else {
searchClass = (DeclaredType) objectType.asType();
}
}
return emptyList();
}
代码示例来源:origin: f2prateek/dart
private TypeElement findClosestAncestorWithNavigationModelBinder(TypeElement element) {
while (true) {
final TypeMirror superType = element.getSuperclass();
if (superType.getKind() == TypeKind.NONE) {
// Got to the oldest ancestor and none contains NavigationModelModelBinder
return null;
}
element = (TypeElement) ((DeclaredType) superType).asElement();
// ancestor contains a NavigationModel field
if (getNavigationModelBinder(element) != null) {
return element;
}
}
}
代码示例来源:origin: sockeqwe/fragmentargs
TypeMirror currentClassSuperclass = currentClass.getSuperclass();
if (currentClassSuperclass == null || currentClassSuperclass.getKind() == TypeKind.NONE) {
TypeMirror superClass = problemClass.getSuperclass();
TypeElement superClassElement = null;
&& superClass.getKind() != TypeKind.NONE
&& (superClassElement = (TypeElement) typeUtils.asElement(superClass)) != null) {
break;
superClass = superClassElement.getSuperclass();
内容来源于网络,如有侵权,请联系作者删除!