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

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

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

Types.getDeclaredType介绍

[英]Returns the type corresponding to a type element and actual type arguments. Given the type element for Set and the type mirror for String, for example, this method may be used to get the parameterized type Set.

The number of type arguments must either equal the number of the type element's formal type parameters, or must be zero. If zero, and if the type element is generic, then the type element's raw type is returned.

If a parameterized type is being returned, its type element must not be contained within a generic outer class. The parameterized type Outer.Inner, for example, may be constructed by first using this method to get the type Outer, and then invoking #getDeclaredType(DeclaredType,TypeElement,TypeMirror...).
[中]返回与类型元素和实际类型参数对应的类型。例如,给定Set的type元素和String的type mirror,可以使用此方法获取参数化类型集。
类型参数的数量必须等于类型元素的形式类型参数的数量,或者必须为零。如果为零,并且type元素是泛型的,则返回type元素的原始类型。
如果返回参数化类型,则其类型元素不得包含在泛型外部类中。参数化类型为外部。例如,可以通过首先使用此方法获取外部类型,然后调用#getDeclaredType(DeclaredType、TypeElement、TypeMirror…)来构造内部。

代码示例

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

public TypeMirror wrapIterable(TypeMirror typeMirror) {
 return types.getDeclaredType(iterableElement, typeMirror);
}

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

DeclaredType makeIterableTypeOf(TypeMirror resolved) {
 return knife.types.getDeclaredType(knife.accessors.iterableElement, resolved);
}

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

private static DeclaredType getTypeMirror(Types types, Elements elements, Class<?> reflected) {
 TypeElement typeElement = elements.getTypeElement(reflected.getName());
 checkState(typeElement != null, "type must be present: %s", reflected.getName());
 return types.getDeclaredType(typeElement);
}

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

private TypeMirror getArrayListType(String elementType) {
  TypeElement arrayList = processingEnv.getElementUtils().getTypeElement("java.util.ArrayList");
  TypeMirror elType = processingEnv.getElementUtils().getTypeElement(elementType).asType();
  return processingEnv.getTypeUtils().getDeclaredType(arrayList, elType);
}

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

private TypeMirror getWildcardType(String type, String elementType) {
  TypeElement arrayList = processingEnv.getElementUtils().getTypeElement(type);
  TypeMirror elType = processingEnv.getElementUtils().getTypeElement(elementType).asType();
  return processingEnv.getTypeUtils()
      .getDeclaredType(arrayList, processingEnv.getTypeUtils().getWildcardType(elType, null));
}

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

private void createDaoParametrizedTypes() {
    daoTypeElement = helper.typeElementFromQualifiedName(OrmLiteClasses.DAO);
    runtimeExceptionDaoTypeElement = helper.typeElementFromQualifiedName(OrmLiteClasses.RUNTIME_EXCEPTION_DAO);

    Types typeUtils = helper.getTypeUtils();
    TypeMirror wildcardType = typeUtils.getWildcardType(null, null);
    daoParametrizedType = helper.getTypeUtils().getDeclaredType(daoTypeElement, wildcardType, wildcardType);
    runtimeExceptionDaoParametrizedType = helper.getTypeUtils().getDeclaredType(runtimeExceptionDaoTypeElement, wildcardType, wildcardType);
  }
}

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

public DeclaredType getTypedRuntimeExceptionDao(Element element) {
  if (runtimeExceptionDaoTypeElement == null) {
    createDaoParametrizedTypes();
  }
  return helper.getTypeUtils().getDeclaredType(runtimeExceptionDaoTypeElement, getEntityType(element), getEntityIdType(element));
}

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

public DeclaredType getTypedDao(Element element) {
  if (daoTypeElement == null) {
    createDaoParametrizedTypes();
  }
  return helper.getTypeUtils().getDeclaredType(daoTypeElement, getEntityType(element), getEntityIdType(element));
}

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

private IJExpression instantiateArrayList(TypeMirror viewType, EComponentWithViewSupportHolder holder, String name) {
  TypeElement arrayListTypeElement = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.ARRAYLIST);
  DeclaredType arrayListType = getProcessingEnvironment().getTypeUtils().getDeclaredType(arrayListTypeElement, viewType);
  AbstractJClass arrayListClass = codeModelHelper.typeMirrorToJClass(arrayListType);
  return holder.getOnViewChangedBodyBeforeInjectionBlock().decl(arrayListClass, name, _new(arrayListClass));
}

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

private TypeMirror getRealElementType(Element element) {
  AnnotationMirror mirror = TypeUtils.getAnnotationMirrorOfType(element, ManyToOne.class);
  if (mirror == null) {
    mirror = TypeUtils.getAnnotationMirrorOfType(element, OneToOne.class);
  }
  if (mirror != null) {
    return TypeUtils.getAnnotationValueAsTypeMirror(mirror, "targetEntity");
  }
  mirror = TypeUtils.getAnnotationMirrorOfType(element, OneToMany.class);
  if (mirror == null) {
    mirror = TypeUtils.getAnnotationMirrorOfType(element, ManyToMany.class);
  }
  if (mirror != null) {
    TypeMirror typeArg = TypeUtils.getAnnotationValueAsTypeMirror(mirror, "targetEntity");
    TypeMirror erasure = types.erasure(element.asType());
    TypeElement typeElement = (TypeElement) types.asElement(erasure);
    if (typeElement != null && typeArg != null) {
      if (typeElement.getTypeParameters().size() == 1) {
        return types.getDeclaredType(typeElement, typeArg);
      } else if (typeElement.getTypeParameters().size() == 2) {
        if (element.asType() instanceof DeclaredType) {
          TypeMirror first = ((DeclaredType) element.asType()).getTypeArguments().get(0);
          return types.getDeclaredType(typeElement, first, typeArg);
        }
      }
    }
  }
  return null;
}

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

processingEnv.getTypeUtils().getDeclaredType(
  processingEnv.getElementUtils().getTypeElement(type.getName().replace('$', '.'))) :
null;

代码示例来源:origin: hibernate/hibernate-validator

/**
 * Returns the {@link DeclaredType} for the given class name.
 *
 * @param className A fully qualified class name, e.g. "java.lang.String".
 *
 * @return A {@link DeclaredType} representing the type with the given name,
 *         or null, if no such type exists.
 */
public DeclaredType getDeclaredTypeByName(String className) {
  TypeElement typeElement = elementUtils.getTypeElement( className );
  return typeElement != null ? typeUtils.getDeclaredType( typeElement ) : null;
}

代码示例来源:origin: inferred/FreeBuilder

private static TypeMirror multiset(
   TypeMirror elementType,
   Elements elements,
   Types types) {
  TypeElement multisetType = elements.getTypeElement(Multiset.class.getName());
  return types.getDeclaredType(multisetType, elementType);
 }
}

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * Utility method to look up raw types from class literals.
 */
public DeclaredType findType(Class<?> clazz) {
 return types.getDeclaredType(elements.getTypeElement(clazz.getCanonicalName()));
}

代码示例来源:origin: inferred/FreeBuilder

private static TypeMirror listMultimap(
   TypeMirror keyType,
   TypeMirror valueType,
   Elements elements,
   Types types) {
  TypeElement listMultimapType = elements.getTypeElement(ListMultimap.class.getName());
  return types.getDeclaredType(listMultimapType, keyType, valueType);
 }
}

代码示例来源:origin: inferred/FreeBuilder

private static TypeMirror setMultimap(
   TypeMirror keyType,
   TypeMirror valueType,
   Elements elements,
   Types types) {
  TypeElement setMultimapType = elements.getTypeElement(SetMultimap.class.getName());
  return types.getDeclaredType(setMultimapType, keyType, valueType);
 }
}

代码示例来源:origin: inferred/FreeBuilder

private static TypeMirror wildcardSuperSet(
   TypeMirror elementType,
   Elements elements,
   Types types) {
  TypeElement setType = elements.getTypeElement(Set.class.getName());
  return types.getWildcardType(null, types.getDeclaredType(setType, elementType));
 }
}

代码示例来源:origin: inferred/FreeBuilder

/**
  * Returns {@code ? super List<elementType>}.
  */
 private static TypeMirror wildcardSuperList(
   TypeMirror elementType,
   Elements elements,
   Types types) {
  TypeElement listType = elements.getTypeElement(List.class.getName());
  return types.getWildcardType(null, types.getDeclaredType(listType, elementType));
 }
}

代码示例来源:origin: inferred/FreeBuilder

private static TypeMirror wildcardSuperMap(
   TypeMirror keyType,
   TypeMirror valueType,
   Elements elements,
   Types types) {
  TypeElement mapType = elements.getTypeElement(Map.class.getName());
  return types.getWildcardType(null, types.getDeclaredType(mapType, keyType, valueType));
 }
}

代码示例来源:origin: inferred/FreeBuilder

private static TypeMirror wildcardSuperSortedSet(
   TypeMirror elementType,
   Elements elements,
   Types types) {
  TypeElement setType = elements.getTypeElement(SortedSet.class.getName());
  return types.getWildcardType(null, types.getDeclaredType(setType, elementType));
 }
}

相关文章