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

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

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

Types.boxedClass介绍

[英]Returns the class of a boxed value of a given primitive type. That is, boxing conversion is applied.
[中]

代码示例

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

private TypeMirror boxed( PrimitiveType bool )
  {
    return typeUtils.boxedClass( bool ).asType();
  }
}

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

private void collectBuiltins(Map<String, TypeMirror> collected) {
 for (TypeKind kind : TypeKind.values()) {
  if (kind.isPrimitive()) {
   TypeElement boxedClass = types.boxedClass(types.getPrimitiveType(kind));
   collected.put(boxedClass.getSimpleName().toString(), boxedClass.asType());
  }
 }
 TypeElement typeElement = elements.getTypeElement(String.class.getCanonicalName());
 collected.put(typeElement.getSimpleName().toString(), typeElement.asType());
 typeElement = elements.getTypeElement(Templates.Invokable.class.getCanonicalName());
 collected.put(typeElement.getSimpleName().toString(), typeElement.asType());
}

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

TypeName boxedTypeName(TypeMirror typeMirror) {
  if (typeMirror.getKind().isPrimitive()) {
    return TypeName.get(types.boxedClass((PrimitiveType) typeMirror).asType());
  }
  return TypeName.get(typeMirror);
}

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

TypeElement element = null;
if (mirror.getKind().isPrimitive()) {
  element = types.boxedClass((PrimitiveType) mirror);
} else if (mirror.getKind() == TypeKind.DECLARED) {
  element = (TypeElement) types.asElement(mirror);

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

@Override
public TypeMirror visitPrimitive(PrimitiveType x, State state) {
 if (boxPrimitives) {
  return state.types.boxedClass(x).asType();
 }
 return x;
}

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

if (keyType.getKind().isPrimitive()) {
  Types types = processingEnvironment.getTypeUtils();
  keyType = types.boxedClass((PrimitiveType)keyType).asType();

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

/**
 * No parameters, name stars with "get" or is a boolean / Boolean isFoo hasFoo
 * method.
 */
protected boolean isGetter(ExecutableElement x, State state) {
 String name = x.getSimpleName().toString();
 TypeMirror returnType = x.getReturnType();
 if (!x.getParameters().isEmpty()) {
  return false;
 }
 if (name.startsWith("get")) {
  return true;
 }
 if (name.startsWith("is") || name.startsWith("has")) {
  TypeMirror javaLangBoolean =
    state.types.boxedClass(state.types.getPrimitiveType(TypeKind.BOOLEAN)).asType();
  if (returnType.getKind().equals(TypeKind.BOOLEAN)
    || state.types.isSameType(returnType, javaLangBoolean)) {
   return true;
  }
 }
 return false;
}

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

/**
 * Returns a unary operator that will accept {@code type}, without autoboxing if possible.
 */
public static FunctionalType unboxedUnaryOperator(TypeMirror type, Types types) {
 switch (type.getKind()) {
  case INT:
  case LONG:
  case DOUBLE:
   return primitiveUnaryOperator((PrimitiveType) type);
  case BOOLEAN:
  case BYTE:
  case CHAR:
  case SHORT:
  case FLOAT:
   return unaryOperator(types.boxedClass((PrimitiveType) type).asType());
  default:
   return unaryOperator(type);
 }
}

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

/**
  * This method should be kept in sync with
  * {@code ValueCodex.getAllValueTypes()}. It doesn't use
  * {@code getAllValueTypes()} because a dependency on {@code ValueCodex} would
  * pull in a large number of dependencies into the minimal
  * {@code requestfactory-apt.jar}.
  */
 protected List<DeclaredType> getValueTypes(State state) {
  List<DeclaredType> types = new ArrayList<DeclaredType>();
  for (TypeKind kind : TypeKind.values()) {
   if (kind.isPrimitive()) {
    PrimitiveType primitiveType = state.types.getPrimitiveType(kind);
    TypeElement boxedClass = state.types.boxedClass(primitiveType);
    types.add((DeclaredType) boxedClass.asType());
   }
  }
  types.add(state.findType(BigDecimal.class));
  types.add(state.findType(BigInteger.class));
  types.add(state.findType(Date.class));
  types.add(state.findType(String.class));
  types.add(state.findType(Void.class));
  // Avoids compile-dependency bloat
  types.add(state.types.getDeclaredType(state.elements
    .getTypeElement("com.google.web.bindery.autobean.shared.Splittable")));
  return Collections.unmodifiableList(types);
 }
}

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

/**
 * Introspects {@code method}, as found on {@code valueType}.
 */
private void addPropertyData(
  Property.Builder propertyBuilder,
  TypeElement valueType,
  ExecutableElement method,
  Optional<JacksonSupport> jacksonSupport) {
 TypeMirror propertyType = getReturnType(valueType, method, types);
 propertyBuilder
   .setAllCapsName(camelCaseToAllCaps(propertyBuilder.getName()))
   .setType(propertyType)
   .setFullyCheckedCast(CAST_IS_FULLY_CHECKED.visit(propertyType));
 if (jacksonSupport.isPresent()) {
  jacksonSupport.get().addJacksonAnnotations(propertyBuilder, method);
 }
 if (propertyType.getKind().isPrimitive()) {
  PrimitiveType unboxedType = types.getPrimitiveType(propertyType.getKind());
  TypeMirror boxedType = types.erasure(types.boxedClass(unboxedType).asType());
  propertyBuilder.setBoxedType(boxedType);
 }
}

代码示例来源:origin: net.wetheinter/gwt-user

@Override
public TypeMirror visitPrimitive(PrimitiveType x, State state) {
 if (boxPrimitives) {
  return state.types.boxedClass(x).asType();
 }
 return x;
}

代码示例来源:origin: com.google.web.bindery/requestfactory-apt

@Override
public TypeMirror visitPrimitive(PrimitiveType x, State state) {
 if (boxPrimitives) {
  return state.types.boxedClass(x).asType();
 }
 return x;
}

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

@Override
public TypeMirror visitPrimitive(PrimitiveType t, Types types) {
 return types.boxedClass(t).asType();
}

代码示例来源:origin: domaframework/doma

public Void visitPrimitive(PrimitiveType t, StringBuilder p) {
 if (p.length() == 0) {
  p.append(t);
 } else {
  TypeElement e = typeUtils.boxedClass(t);
  p.append(e.getSimpleName());
 }
 return null;
}

代码示例来源:origin: org.eiichiro.acidhouse/acidhouse-modelgen

private TypeMirror box(TypeMirror type) {
  if (type.getKind().isPrimitive()) {
    return environment.getTypeUtils().boxedClass((PrimitiveType) type).asType();
  }
  return type;
}

代码示例来源:origin: org.immutables/generator-processor

private void collectBuiltins(Map<String, TypeMirror> collected) {
 for (TypeKind kind : TypeKind.values()) {
  if (kind.isPrimitive()) {
   TypeElement boxedClass = types.boxedClass(types.getPrimitiveType(kind));
   collected.put(boxedClass.getSimpleName().toString(), boxedClass.asType());
  }
 }
 TypeElement typeElement = elements.getTypeElement(String.class.getCanonicalName());
 collected.put(typeElement.getSimpleName().toString(), typeElement.asType());
 typeElement = elements.getTypeElement(Templates.Invokable.class.getCanonicalName());
 collected.put(typeElement.getSimpleName().toString(), typeElement.asType());
}

代码示例来源:origin: vbauer/jackdaw

public static TypeElement getWrappedType(final TypeMirror mirror) {
  final ProcessingEnvironment env = ProcessorContextHolder.getProcessingEnvironment();
  final Types typeUtils = env.getTypeUtils();
  final TypeKind kind = mirror.getKind();
  final boolean primitive = kind.isPrimitive();
  if (primitive) {
    return typeUtils.boxedClass((PrimitiveType) mirror);
  }
  return (TypeElement) typeUtils.asElement(mirror);
}

代码示例来源:origin: stoicflame/enunciate

public TypeElement boxedClass(PrimitiveType p) {
 while (p instanceof DecoratedPrimitiveType) {
  p = ((DecoratedPrimitiveType) p).getDelegate();
 }
 return ElementDecorator.decorate(delegate.boxedClass(p), this.env);
}

代码示例来源:origin: net.digitalid.utility/utility-processing

/**
 * Returns the boxed type of the given type mirror or its component type in case of arrays.
 */
@Pure
public static @Nonnull TypeMirror getBoxedType(@Nonnull TypeMirror typeMirror) {
  if (isPrimitive(typeMirror)) {
    return getType(StaticProcessingEnvironment.getTypeUtils().boxedClass((PrimitiveType) typeMirror));
  } else {
    return typeMirror;
  }
}

代码示例来源:origin: com.oracle.truffle/truffle-dsl-processor

private boolean isPrimitiveWrapper(TypeMirror type) {
  Types types = context.getEnvironment().getTypeUtils();
  for (TypeKind kind : TypeKind.values()) {
    if (!kind.isPrimitive()) {
      continue;
    }
    if (ElementUtils.typeEquals(type, types.boxedClass(types.getPrimitiveType(kind)).asType())) {
      return true;
    }
  }
  return false;
}

相关文章