javax.lang.model.util.Types.isSubtype()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(181)

本文整理了Java中javax.lang.model.util.Types.isSubtype()方法的一些代码示例,展示了Types.isSubtype()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types.isSubtype()方法的具体详情如下:
包路径:javax.lang.model.util.Types
类名称:Types
方法名:isSubtype

Types.isSubtype介绍

[英]Tests whether one type is a subtype of another. Any type is considered to be a subtype of itself.
[中]测试一种类型是否是另一种类型的子类型。任何类型都被认为是其自身的一个子类型。

代码示例

代码示例来源:origin: immutables/immutables

boolean isCheckedException(TypeMirror throwable) {
  return types.isSubtype(throwable, exceptionType)
    && !types.isSubtype(throwable, runtimeExceptionType);
 }
}

代码示例来源:origin: androidannotations/androidannotations

/**
 * Tests whether one type is a subtype of another. Any type is considered to be
 * a subtype of itself.
 */
public boolean isSubtype(TypeMirror potentialSubtype, TypeMirror potentialSupertype) {
  return getTypeUtils().isSubtype(potentialSubtype, potentialSupertype);
}

代码示例来源:origin: meituan/WMRouter

public boolean isSubType(Element element, TypeMirror typeMirror) {
  return element != null && types.isSubtype(element.asType(), typeMirror);
}

代码示例来源:origin: airbnb/epoxy

static boolean isSubtype(TypeMirror e1, TypeMirror e2, Types types) {
 return types.isSubtype(e1, types.erasure(e2));
}

代码示例来源:origin: sockeqwe/fragmentargs

/**
 * Checks if the given element is in a valid Fragment class
 */
private boolean isFragmentClass(Element classElement) {
  List<TypeElement> fragmentTypeElements = Arrays.asList(TYPE_FRAGMENT, TYPE_SUPPORT_FRAGMENT, TYPE_ANDROIDX_FRAGMENT);
  for (TypeElement fragmentTypeElement : fragmentTypeElements) {
    if(fragmentTypeElement != null && typeUtils.isSubtype(classElement.asType(),
        fragmentTypeElement.asType())) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: chenenyu/Router

private boolean isSubtype(Element typeElement, String type) {
  return processingEnv.getTypeUtils().isSubtype(typeElement.asType(),
      processingEnv.getElementUtils().getTypeElement(type).asType());
}

代码示例来源:origin: chenenyu/Router

private boolean isSubtype(TypeMirror typeMirror, String type) {
  return processingEnv.getTypeUtils().isSubtype(typeMirror,
      processingEnv.getElementUtils().getTypeElement(type).asType());
}

代码示例来源:origin: chenenyu/Router

private boolean isSubtype(Element typeElement, String type) {
  return processingEnv.getTypeUtils().isSubtype(typeElement.asType(),
      processingEnv.getElementUtils().getTypeElement(type).asType());
}

代码示例来源: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: immutables/immutables

private boolean isIterableType(TypeMirror type) {
 return types.isSubtype(types.erasure(type), iterableTypeErasure);
}

代码示例来源:origin: meituan/WMRouter

public boolean isSubType(TypeMirror type, String className) {
  return type != null && types.isSubtype(type, typeMirror(className));
}

代码示例来源:origin: orbit/orbit

void processElement(Element e)
{
  if (e instanceof TypeElement)
  {
    final TypeMirror t1 = e.asType();
    TypeElement typeElement = (TypeElement) e;
    int idFromStrategy = getIdFromStrategy(typeElement);
    if (idFromStrategy != 0 || typeUtils.isSubtype(t1, actorTypeMirror) || typeUtils.isSubtype(t1, actorObserverTypeMirror))
    {
      writeClassInfo(typeElement, idFromStrategy);
    }
  }
  e.getEnclosedElements().forEach(this::processElement);
}

代码示例来源:origin: androidannotations/androidannotations

public PreferencesDelegate(EComponentWithViewSupportHolder holder) {
  super(holder);
  Elements elementUtils = holder.getEnvironment().getProcessingEnvironment().getElementUtils();
  Types typeUtils = holder.getEnvironment().getProcessingEnvironment().getTypeUtils();
  TypeElement supportV7PreferenceFragmentCompat = elementUtils.getTypeElement(CanonicalNameConstants.SUPPORT_V7_PREFERENCE_FRAGMENTCOMPAT);
  TypeElement andoridxPreferenceFragmentCompat = elementUtils.getTypeElement(CanonicalNameConstants.ANDROIDX_PREFERENCE_FRAGMENTCOMPAT);
  TypeElement supportV14PreferenceFragment = elementUtils.getTypeElement(CanonicalNameConstants.SUPPORT_V14_PREFERENCE_FRAGMENT);
  TypeElement andoridxPreferenceFragment = elementUtils.getTypeElement(CanonicalNameConstants.ANDROIDX_PREFERENCE_FRAGMENT);
  TypeMirror annotatedType = holder.getAnnotatedElement().asType();
  if (andoridxPreferenceFragmentCompat != null && typeUtils.isSubtype(annotatedType, andoridxPreferenceFragmentCompat.asType())
      || andoridxPreferenceFragment != null && typeUtils.isSubtype(annotatedType, andoridxPreferenceFragment.asType())) {
    usingAndroidxPreference = true;
    basePreferenceClass = getClasses().ANDROIDX_PREFERENCE;
  } else if (supportV7PreferenceFragmentCompat != null && typeUtils.isSubtype(annotatedType, supportV7PreferenceFragmentCompat.asType())
      || supportV14PreferenceFragment != null && typeUtils.isSubtype(annotatedType, supportV14PreferenceFragment.asType())) {
    usingSupportV7Preference = true;
    basePreferenceClass = getClasses().SUPPORT_V7_PREFERENCE;
  } else {
    basePreferenceClass = getClasses().PREFERENCE;
  }
}

代码示例来源:origin: neo4j/neo4j

private Stream<CompilationMessage> validateReturnType( ExecutableElement method )
{
  String streamClassName = Stream.class.getCanonicalName();
  TypeMirror streamType = typeUtils.erasure( elementUtils.getTypeElement( streamClassName ).asType() );
  TypeMirror returnType = method.getReturnType();
  TypeMirror erasedReturnType = typeUtils.erasure( returnType );
  TypeMirror voidType = typeUtils.getNoType( TypeKind.VOID );
  if ( typeUtils.isSameType( returnType, voidType ) )
  {
    return Stream.empty();
  }
  if ( !typeUtils.isSubtype( erasedReturnType, streamType ) )
  {
    return Stream.of( new ReturnTypeError( method, "Return type of %s#%s must be %s",
        method.getEnclosingElement().getSimpleName(), method.getSimpleName(), streamClassName ) );
  }
  return recordVisitor.visit( returnType );
}

代码示例来源: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: androidannotations/androidannotations

public JInvocation getSuperPutExtraInvocation(TypeMirror elementType, JVar extraParam, JFieldVar extraKeyField) {
  IJExpression extraParameterArg = extraParam;
  // Cast to Parcelable, wrap with Parcels.wrap or cast Serializable if needed
  if (elementType.getKind() == TypeKind.DECLARED) {
    Elements elementUtils = environment.getProcessingEnvironment().getElementUtils();
    TypeMirror parcelableType = elementUtils.getTypeElement(PARCELABLE).asType();
    if (typeUtils.isSubtype(elementType, parcelableType)) {
      TypeMirror serializableType = elementUtils.getTypeElement(SERIALIZABLE).asType();
      if (typeUtils.isSubtype(elementType, serializableType)) {
        extraParameterArg = cast(environment.getClasses().PARCELABLE, extraParameterArg);
      }
    } else if (!BundleHelper.METHOD_SUFFIX_BY_TYPE_NAME.containsKey(elementType.toString()) && parcelerHelper.isParcelType(elementType)) {
      extraParameterArg = environment.getJClass(CanonicalNameConstants.PARCELS_UTILITY_CLASS).staticInvoke("wrap").arg(extraParameterArg);
    } else {
      TypeMirror stringType = elementUtils.getTypeElement(STRING).asType();
      if (!typeUtils.isSubtype(elementType, stringType)) {
        extraParameterArg = cast(environment.getClasses().SERIALIZABLE, extraParameterArg);
      }
    }
  }
  return _super().invoke("extra").arg(extraKeyField).arg(extraParameterArg);
}

代码示例来源:origin: org.jboss.logging/jboss-logging-processor

@Override
public final boolean isSubtypeOf(final Class<?> type) {
  return types.isSubtype(types.erasure(this.typeMirror), toType(type));
}

代码示例来源:origin: org.jboss.logging/jboss-logging-processor

AptReturnType(final ProcessingEnvironment processingEnv, final TypeMirror returnType, final MessageMethod method) {
  super(processingEnv, returnType);
  this.returnType = returnType;
  this.method = method;
  delegate = types.asElement(returnType);
  throwableType = null;
  if (types.isSubtype(types.erasure(returnType), types.erasure(ElementHelper.toType(elements, Supplier.class)))) {
    final List<? extends TypeMirror> typeArgs = ElementHelper.getTypeArguments(returnType);
    if (typeArgs.isEmpty()) {
      resolvedType = elements.getTypeElement(Object.class.getCanonicalName()).asType();
    } else {
      resolvedType = typeArgs.get(0);
    }
  } else {
    resolvedType = returnType;
  }
  isThrowable = types.isSubtype(types.erasure(resolvedType), ElementHelper.toType(elements, Throwable.class));
}

代码示例来源:origin: neo4j/neo4j

private boolean isValidErasedType( TypeMirror actualType )
{
  return whitelistedTypes.stream().anyMatch( type ->
  {
    TypeMirror erasedAllowedType = typeUtils.erasure( type );
    TypeMirror map = typeUtils.erasure( typeMirrors.typeMirror( Map.class ) );
    TypeMirror list = typeUtils.erasure( typeMirrors.typeMirror( List.class ) );
    if ( typeUtils.isSameType( erasedAllowedType, map ) || typeUtils.isSameType( erasedAllowedType, list ) )
    {
      return typeUtils.isSubtype( actualType, erasedAllowedType );
    }
    return typeUtils.isSameType( actualType, erasedAllowedType );
  } );
}

代码示例来源:origin: btraceio/btrace

@Override
public Boolean visitMemberSelect(MemberSelectTree node, Void v) {
  if (node.getIdentifier().contentEquals("class")) {
    TypeMirror tm = getType(node.getExpression());
    if (!verifier.getTypeUtils().isSubtype(tm, btraceServiceTm)) {
      reportError("no.class.literals", node);
    }
  }
  return super.visitMemberSelect(node, v);
}

相关文章