本文整理了Java中javax.lang.model.util.Types.getPrimitiveType()
方法的一些代码示例,展示了Types.getPrimitiveType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types.getPrimitiveType()
方法的具体详情如下:
包路径:javax.lang.model.util.Types
类名称:Types
方法名:getPrimitiveType
[英]Returns a primitive type.
[中]返回一个基元类型。
代码示例来源:origin: neo4j/neo4j
public PrimitiveType primitive( TypeKind kind )
{
return typeUtils.getPrimitiveType( kind );
}
代码示例来源: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: org.netbeans.api/org-openide-util-lookup
} else {
if (!processingEnv.getTypeUtils().isSameType(
processingEnv.getTypeUtils().getPrimitiveType(TypeKind.INT),
attr.getReturnType()
)) {
代码示例来源:origin: hibernate/hibernate-validator
public AnnotationApiHelper(Elements elementUtils, Types typeUtils) {
this.elementUtils = elementUtils;
this.typeUtils = typeUtils;
Map<Class<?>, TypeMirror> tempPrimitiveMirrors = CollectionHelper.newHashMap();
tempPrimitiveMirrors.put( Boolean.TYPE, typeUtils.getPrimitiveType( TypeKind.BOOLEAN ) );
tempPrimitiveMirrors.put( Character.TYPE, typeUtils.getPrimitiveType( TypeKind.CHAR ) );
tempPrimitiveMirrors.put( Byte.TYPE, typeUtils.getPrimitiveType( TypeKind.BYTE ) );
tempPrimitiveMirrors.put( Short.TYPE, typeUtils.getPrimitiveType( TypeKind.SHORT ) );
tempPrimitiveMirrors.put( Integer.TYPE, typeUtils.getPrimitiveType( TypeKind.INT ) );
tempPrimitiveMirrors.put( Long.TYPE, typeUtils.getPrimitiveType( TypeKind.LONG ) );
tempPrimitiveMirrors.put( Float.TYPE, typeUtils.getPrimitiveType( TypeKind.FLOAT ) );
tempPrimitiveMirrors.put( Double.TYPE, typeUtils.getPrimitiveType( TypeKind.DOUBLE ) );
primitiveMirrors = Collections.unmodifiableMap( tempPrimitiveMirrors );
}
代码示例来源: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: 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
/** Returns a {@link TypeMirror} for the given class (raw T, not T<?>, if T is generic). */
public static TypeMirror typeMirror(
Types typeUtils,
Elements elementUtils,
Class<?> cls) {
if (cls.equals(void.class)) {
return typeUtils.getNoType(TypeKind.VOID);
} else if (cls.isPrimitive()) {
return typeUtils.getPrimitiveType(TypeKind.valueOf(cls.getSimpleName().toUpperCase()));
} else if (cls.isArray()) {
return typeUtils.getArrayType(typeMirror(typeUtils, elementUtils, cls.getComponentType()));
} else {
return rawType(typeUtils, elementUtils, cls.getCanonicalName());
}
}
代码示例来源: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: inferred/FreeBuilder
@Test
public void typeUtils() {
PrimitiveType booleanType = model.typeUtils().getPrimitiveType(TypeKind.BOOLEAN);
assertEquals("boolean", booleanType.toString());
}
代码示例来源:origin: inferred/FreeBuilder
PrimitiveType primitiveType = config.getTypes().getPrimitiveType(optionalType.primitiveKind);
FunctionalType primitiveOperator = primitiveUnaryOperator(primitiveType);
FunctionalType optionalOperator = unaryOperator(type);
代码示例来源:origin: inferred/FreeBuilder
private static boolean hasSetCountMethodOverride(
Config config, TypeMirror type) {
return overrides(
config.getBuilder(),
config.getTypes(),
setCountMethod(config.getProperty()),
type,
config.getTypes().getPrimitiveType(TypeKind.INT));
}
代码示例来源:origin: inferred/FreeBuilder
private static void checkForInfiniteLoop(Config config, OptionalType optional) {
ExecutableElement override = override(
config.getBuilder(),
config.getTypes(),
setter(config.getProperty()),
config.getTypes().getPrimitiveType(optional.primitiveKind)).orElse(null);
if (override == null) {
return;
}
MethodIntrospector.instance(config.getEnvironment())
.visitAllOwnMethodInvocations(override, (methodName, logger) -> {
if (setter(config.getProperty()).contentEquals(methodName)) {
logger.logMessage(Kind.ERROR, "Infinite recursive loop detected");
}
});
}
}
代码示例来源:origin: org.mapstruct/mapstruct-processor
private TypeMirror getPrimitiveType(Class<?> primitiveType) {
return primitiveType == byte.class ? typeUtils.getPrimitiveType( TypeKind.BYTE ) :
primitiveType == short.class ? typeUtils.getPrimitiveType( TypeKind.SHORT ) :
primitiveType == int.class ? typeUtils.getPrimitiveType( TypeKind.INT ) :
primitiveType == long.class ? typeUtils.getPrimitiveType( TypeKind.LONG ) :
primitiveType == float.class ? typeUtils.getPrimitiveType( TypeKind.FLOAT ) :
primitiveType == double.class ? typeUtils.getPrimitiveType( TypeKind.DOUBLE ) :
primitiveType == boolean.class ? typeUtils.getPrimitiveType( TypeKind.BOOLEAN ) :
primitiveType == char.class ? typeUtils.getPrimitiveType( TypeKind.CHAR ) :
typeUtils.getPrimitiveType( TypeKind.VOID );
}
代码示例来源:origin: vimeo/stag-java
private static boolean isPrimitive(@NotNull TypeMirror type, @NotNull Types utils) {
try {
utils.getPrimitiveType(type.getKind());
return true;
} catch (IllegalArgumentException ignored) {
return false;
}
}
代码示例来源:origin: br.com.objectos.code/apt
@Override
public TypeMirror get(Elements elements, Types types) {
String name = type.getName();
TypeKind kind = TypeKind.valueOf(name.toUpperCase());
return types.getPrimitiveType(kind);
}
代码示例来源:origin: org.glassfish.metro/webservices-tools
public TypeMirror getPrimitive(Class primitiveType) {
assert primitiveType.isPrimitive();
if(primitiveType==void.class)
return getVoidType();
return env.getTypeUtils().getPrimitiveType(primitives.get(primitiveType));
}
代码示例来源: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;
}
代码示例来源:origin: yongjhih/RetroFacebook
public void testImportsForImplicitlyImportedTypes() {
Set<TypeMirror> types = typeMirrorSet(
typeMirrorOf("java.lang.String"),
typeMirrorOf("javax.management.MBeanServer"), // Same package, so no import.
typeUtil.getPrimitiveType(TypeKind.INT),
typeUtil.getPrimitiveType(TypeKind.BOOLEAN)
);
TypeSimplifier typeSimplifier =
new TypeSimplifier(typeUtil, "javax.management", types, baseWithoutContainedTypes());
assertEquals(ImmutableSet.of(), typeSimplifier.typesToImport());
}
代码示例来源:origin: yongjhih/RetroFacebook
public void testImportsForImplicitlyImportedTypes() {
Set<TypeMirror> types = typeMirrorSet(
typeMirrorOf("java.lang.String"),
typeMirrorOf("javax.management.MBeanServer"), // Same package, so no import.
typeUtil.getPrimitiveType(TypeKind.INT),
typeUtil.getPrimitiveType(TypeKind.BOOLEAN)
);
TypeSimplifier typeSimplifier =
new TypeSimplifier(typeUtil, "javax.management", types, baseWithoutContainedTypes());
assertEquals(ImmutableSet.of(), typeSimplifier.typesToImport());
}
代码示例来源:origin: org.inferred/freebuilder
private static boolean hasSetCountMethodOverride(
Config config, TypeMirror type) {
return overrides(
config.getBuilder(),
config.getTypes(),
setCountMethod(config.getProperty()),
type,
config.getTypes().getPrimitiveType(TypeKind.INT));
}
内容来源于网络,如有侵权,请联系作者删除!