本文整理了Java中javax.lang.model.util.Types.directSupertypes()
方法的一些代码示例,展示了Types.directSupertypes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types.directSupertypes()
方法的具体详情如下:
包路径:javax.lang.model.util.Types
类名称:Types
方法名:directSupertypes
[英]Returns the direct supertypes of a type. The interface types, if any, will appear last in the list.
[中]返回类型的直接超类型。接口类型(如果有)将在列表中最后出现。
代码示例来源:origin: spring-projects/spring-framework
/**
* Return the super class of the specified {@link Element} or null if this
* {@code element} represents {@link Object}.
*/
public Element getSuperClass(Element element) {
List<? extends TypeMirror> superTypes = this.types.directSupertypes(element.asType());
if (superTypes.isEmpty()) {
return null; // reached java.lang.Object
}
return this.types.asElement(superTypes.get(0));
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Return the interfaces that are <strong>directly</strong> implemented by the
* specified {@link Element} or an empty list if this {@code element} does not
* implement any interface.
*/
public List<Element> getDirectInterfaces(Element element) {
List<? extends TypeMirror> superTypes = this.types.directSupertypes(element.asType());
List<Element> directInterfaces = new ArrayList<>();
if (superTypes.size() > 1) { // index 0 is the super class
for (int i = 1; i < superTypes.size(); i++) {
Element e = this.types.asElement(superTypes.get(i));
if (e != null) {
directInterfaces.add(e);
}
}
}
return directInterfaces;
}
代码示例来源:origin: androidannotations/androidannotations
public List<? extends TypeMirror> directSupertypes(TypeMirror typeMirror) {
return getTypeUtils().directSupertypes(typeMirror);
}
代码示例来源:origin: facebook/litho
private static TagModel newTagModel(Element typeElement, Types types) {
return new TagModel(
ClassName.bestGuess(typeElement.toString()),
types.directSupertypes(typeElement.asType()).size()
> 1, // java.lang.Object is always a supertype
!typeElement.getEnclosedElements().isEmpty(),
typeElement);
}
}
代码示例来源:origin: querydsl/querydsl
private boolean isSubType(TypeMirror type1, TypeMirror clazz) {
return env.getTypeUtils().isSubtype(type1, clazz)
// XXX Eclipse 3.6 support
|| env.getTypeUtils().directSupertypes(type1).contains(clazz);
}
代码示例来源:origin: androidannotations/androidannotations
private Map<String, TypeMirror> getActualTypes(Types typeUtils, DeclaredType baseClass, TypeMirror annotatedClass) {
List<TypeMirror> superTypes = new ArrayList<>();
superTypes.add(annotatedClass);
while (!superTypes.isEmpty()) {
TypeMirror x = superTypes.remove(0);
if (typeUtils.isSameType(typeUtils.erasure(x), typeUtils.erasure(baseClass))) {
DeclaredType type = (DeclaredType) x;
Map<String, TypeMirror> actualTypes = new HashMap<>();
for (int i = 0; i < type.getTypeArguments().size(); i++) {
TypeMirror actualArg = type.getTypeArguments().get(i);
TypeMirror formalArg = baseClass.getTypeArguments().get(i);
if (!typeUtils.isSameType(actualArg, formalArg)) {
actualTypes.put(formalArg.toString(), actualArg);
}
}
return actualTypes;
}
superTypes.addAll(typeUtils.directSupertypes(x));
}
return Collections.emptyMap();
}
代码示例来源:origin: querydsl/querydsl
List<? extends TypeMirror> superTypes = env.getTypeUtils().directSupertypes(declaredType);
for (TypeMirror superType : superTypes) {
if (env.getTypeUtils().isSubtype(superType, type)) {
代码示例来源:origin: evernote/android-state
private TypeMirror getSuperType(TypeMirror classElement, Set<Element> allClassElements) {
List<? extends TypeMirror> typeMirrors = mTypeUtils.directSupertypes(classElement);
while (typeMirrors != null && !typeMirrors.isEmpty()) {
TypeMirror superClass = typeMirrors.get(0); // interfaces are at the end
if (OBJECT_CLASS_NAME.equals(superClass.toString())) {
break;
}
if (allClassElements.contains(mTypeUtils.asElement(superClass))) {
return superClass;
}
typeMirrors = mTypeUtils.directSupertypes(superClass);
}
return null;
}
代码示例来源:origin: apache/tinkerpop
private Element findClassAsElement(final Element element, final Class<?> clazz) {
if (element.getSimpleName().contentEquals(clazz.getSimpleName())) {
return element;
}
final List<? extends TypeMirror> supertypes = typeUtils.directSupertypes(element.asType());
return findClassAsElement(typeUtils.asElement(supertypes.get(0)), clazz);
}
代码示例来源:origin: cincheo/jsweet
public static boolean isDeclarationOrSubClassDeclaration(javax.lang.model.util.Types types, ClassType classType,
String searchedClassName) {
while (classType != null) {
if (classType.tsym.getQualifiedName().toString().equals(searchedClassName)) {
return true;
}
List<? extends TypeMirror> superTypes = types.directSupertypes(classType);
classType = superTypes == null || superTypes.isEmpty() ? null : (ClassType) superTypes.get(0);
}
return false;
}
代码示例来源:origin: cincheo/jsweet
public static boolean isDeclarationOrSubClassDeclarationBySimpleName(javax.lang.model.util.Types types,
ClassType classType, String searchedClassSimpleName) {
while (classType != null) {
if (classType.tsym.getSimpleName().toString().equals(searchedClassSimpleName)) {
return true;
}
List<? extends TypeMirror> superTypes = types.directSupertypes(classType);
classType = superTypes == null || superTypes.isEmpty() ? null : (ClassType) superTypes.get(0);
}
return false;
}
}
代码示例来源:origin: javaee/glassfish
private TypeMirror onDeclaredType(DeclaredType t, TypeElement sup) {
// t = sup<...>
if (t.asElement().equals(sup))
return t;
for (TypeMirror i : env.getTypeUtils().directSupertypes(t)) {
TypeMirror r = visitDeclared((DeclaredType) i, sup);
if (r != null) return r;
}
return null;
}
代码示例来源:origin: soundcloud/lightcycle
private LightCycleBinder findBinder(TypeElement element) {
if (element == null) {
return LightCycleBinder.DISPATCHER_NOT_FOUND;
}
final TypeMirror elementType = element.asType();
if (elementType.getKind() != TypeKind.DECLARED) {
return LightCycleBinder.DISPATCHER_NOT_FOUND;
}
for (TypeMirror typeMirror : typeUtils.directSupertypes(elementType)) {
for (LightCycleDispatcherKind dispatcherKind : LightCycleDispatcherKind.values()) {
if (dispatcherKind.matches(typeUtils.asElement(typeMirror).getSimpleName())) {
return LightCycleBinder.forFields(dispatcherKind, ((DeclaredType) typeMirror));
}
}
}
return findBinder((TypeElement) typeUtils.asElement(element.getSuperclass()));
}
代码示例来源:origin: hibernate/hibernate-validator
private TypeMirror getConstraintValidatorSuperType(AnnotationValue oneValidatorClassReference) {
TypeMirror type = oneValidatorClassReference.accept(
new SimpleAnnotationValueVisitor8<TypeMirror, Void>() {
@Override
public TypeMirror visitType(TypeMirror t, Void p) {
return t;
}
}, null
);
List<? extends TypeMirror> superTypes = typeUtils.directSupertypes( type );
List<TypeMirror> nextSuperTypes = CollectionHelper.newArrayList();
//follow the type hierarchy upwards, until we have found the ConstraintValidator IF
while ( !superTypes.isEmpty() ) {
for ( TypeMirror oneSuperType : superTypes ) {
if ( getName( typeUtils.asElement( oneSuperType ) ).contentEquals( BeanValidationTypes.CONSTRAINT_VALIDATOR ) ) {
return oneSuperType;
}
nextSuperTypes.addAll( typeUtils.directSupertypes( oneSuperType ) );
}
superTypes = nextSuperTypes;
nextSuperTypes = CollectionHelper.newArrayList();
}
//HV-293: Actually this should never happen, as we can have only ConstraintValidator implementations
//here. The Eclipse JSR 269 implementation unfortunately doesn't always create the type hierarchy
//properly though.
//TODO GM: create and report an isolated test case
throw new IllegalStateException( "Expected type " + type + " to implement javax.validation.ConstraintValidator, but it doesn't." );
}
代码示例来源:origin: hibernate/hibernate-validator
@Override
public TypeMirror visitDeclared(DeclaredType declaredType, Void aVoid) {
TypeMirror eraseType = typeUtils.erasure( declaredType );
if ( typeUtils.isSameType( eraseType, defaultGroupSequenceProviderType ) ) {
List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
if ( !typeArguments.isEmpty() ) {
return typeArguments.get( 0 );
}
return null;
}
List<? extends TypeMirror> superTypes = typeUtils.directSupertypes( declaredType );
for ( TypeMirror superType : superTypes ) {
TypeMirror genericProviderType = superType.accept( this, aVoid );
if ( genericProviderType != null ) {
return genericProviderType;
}
}
return null;
}
代码示例来源:origin: com.google.gwt/gwt-servlet
return searchFrom;
for (TypeMirror s : state.types.directSupertypes(searchFrom)) {
TypeMirror maybe = viewAs(desiredType, s, state);
if (maybe != null) {
代码示例来源:origin: evernote/android-state
List<? extends TypeMirror> superTypes = classElement == null ? null : mTypeUtils.directSupertypes(classElement.asType());
代码示例来源:origin: org.springframework/spring-context-indexer
/**
* Return the super class of the specified {@link Element} or null if this
* {@code element} represents {@link Object}.
*/
public Element getSuperClass(Element element) {
List<? extends TypeMirror> superTypes = this.types.directSupertypes(element.asType());
if (superTypes.isEmpty()) {
return null; // reached java.lang.Object
}
return this.types.asElement(superTypes.get(0));
}
代码示例来源:origin: ngs-doo/dsl-json
private void getAllTypes(TypeElement element, List<TypeElement> result, Set<TypeElement> processed) {
if (!processed.add(element) || element.getQualifiedName().contentEquals("java.lang.Object")) return;
result.add(element);
for (TypeMirror type : types.directSupertypes(element.asType())) {
Element current = types.asElement(type);
if (current instanceof TypeElement) {
getAllTypes((TypeElement) current, result, processed);
}
}
}
代码示例来源:origin: stoicflame/enunciate
public List<? extends TypeMirror> directSupertypes(TypeMirror t) {
while (t instanceof DecoratedTypeMirror) {
t = ((DecoratedTypeMirror) t).getDelegate();
}
return TypeMirrorDecorator.decorate(delegate.directSupertypes(t), this.env);
}
内容来源于网络,如有侵权,请联系作者删除!