get Super Class from TypeElement - Java Reflection

Java examples for Reflection:Class

Description

get Super Class from TypeElement

Demo Code


//package com.java2s;
import javax.lang.model.element.Element;

import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;

import javax.lang.model.type.TypeMirror;

public class Main {
    public static TypeElement getSuperClass(TypeElement element) {
        TypeMirror parent = element.getSuperclass();
        if (parent instanceof DeclaredType) {
            Element elt = ((DeclaredType) parent).asElement();
            if (elt instanceof TypeElement) {
                return (TypeElement) elt;
            }/*from   ww w. ja v a2s.c  o  m*/
        }
        return null;
    }
}

Related Tutorials