use of javax.lang.model.type.TypeKind in project buck by facebook.
the class TreeBackedTypesTest method testIsSameTypePrimitiveType.
@Test
public void testIsSameTypePrimitiveType() throws IOException {
initCompiler();
for (TypeKind typeKind : TypeKind.values()) {
if (typeKind.isPrimitive()) {
PrimitiveType primitiveType = types.getPrimitiveType(typeKind);
PrimitiveType primitiveType2 = types.getPrimitiveType(typeKind);
assertSameType(primitiveType, primitiveType2);
}
}
}
use of javax.lang.model.type.TypeKind in project immutables by immutables.
the class TypeStringProvider method process.
void process() {
if (startType.getKind().isPrimitive()) {
// taking a shortcut for primitives
String typeName = Ascii.toLowerCase(startType.getKind().name());
this.rawTypeName = typeName;
this.returnTypeName = typeName;
List<? extends AnnotationMirror> annotations = AnnotationMirrors.from(startType);
if (!annotations.isEmpty()) {
returnTypeName = typeAnnotationsToBuffer(annotations).append(typeName).toString();
}
} else {
this.buffer = new StringBuilder(100);
caseType(startType);
if (workaroundTypeString != null) {
// to not mix the mess, we just replace buffer with workaround produced type string
this.buffer = new StringBuilder(workaroundTypeString);
}
// It seems that array type annotations are not exposed in javac
// Nested type argument's type annotations are not exposed as well (in javac)
// So currently we instert only for top level, declared type (here),
// and primitives (see above)
TypeKind k = startType.getKind();
if (k == TypeKind.DECLARED || k == TypeKind.ERROR) {
insertTypeAnnotationsIfPresent(startType, 0, rawTypeName.length());
}
this.returnTypeName = buffer.toString();
}
}
use of javax.lang.model.type.TypeKind in project bazel by bazelbuild.
the class TypesUtils method widenedNumericType.
/**
* Returns the widened numeric type for an arithmetic operation
* performed on a value of the left type and the right type.
* Defined in JLS 5.6.2. We return a {@link TypeKind} because
* creating a {@link TypeMirror} requires a {@link Types} object
* from the {@link javax.annotation.processing.ProcessingEnvironment}.
*
* @return the result of widening numeric conversion, or NONE when
* the conversion cannot be performed
*/
public static TypeKind widenedNumericType(TypeMirror left, TypeMirror right) {
if (!isNumeric(left) || !isNumeric(right)) {
return TypeKind.NONE;
}
TypeKind leftKind = left.getKind();
TypeKind rightKind = right.getKind();
if (leftKind == TypeKind.DOUBLE || rightKind == TypeKind.DOUBLE) {
return TypeKind.DOUBLE;
}
if (leftKind == TypeKind.FLOAT || rightKind == TypeKind.FLOAT) {
return TypeKind.FLOAT;
}
if (leftKind == TypeKind.LONG || rightKind == TypeKind.LONG) {
return TypeKind.LONG;
}
return TypeKind.INT;
}
use of javax.lang.model.type.TypeKind in project LoganSquare by bluelinelabs.
the class JsonFieldHolder method getGetter.
public static String getGetter(Element element, Elements elements) {
TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
TypeKind elementTypeKind = element.asType().getKind();
String elementName = element.getSimpleName().toString();
String elementNameLowerCase = elementName.toLowerCase();
List<String> possibleMethodNames = new ArrayList<>();
possibleMethodNames.add("get" + elementNameLowerCase);
if (elementTypeKind == TypeKind.BOOLEAN) {
possibleMethodNames.add("is" + elementNameLowerCase);
possibleMethodNames.add("has" + elementNameLowerCase);
possibleMethodNames.add(elementNameLowerCase);
}
// Handle the case where variables are named in the form mVariableName instead of just variableName
if (elementName.length() > 1 && elementName.charAt(0) == 'm' && (elementName.charAt(1) >= 'A' && elementName.charAt(1) <= 'Z')) {
possibleMethodNames.add("get" + elementNameLowerCase.substring(1));
if (elementTypeKind == TypeKind.BOOLEAN) {
possibleMethodNames.add("is" + elementNameLowerCase.substring(1));
possibleMethodNames.add("has" + elementNameLowerCase.substring(1));
possibleMethodNames.add(elementNameLowerCase.substring(1));
}
}
List<? extends Element> elementMembers = elements.getAllMembers(enclosingElement);
List<ExecutableElement> elementMethods = ElementFilter.methodsIn(elementMembers);
for (ExecutableElement methodElement : elementMethods) {
if (methodElement.getParameters().size() == 0) {
String methodNameString = methodElement.getSimpleName().toString();
String methodNameLowerCase = methodNameString.toLowerCase();
if (possibleMethodNames.contains(methodNameLowerCase)) {
if (methodElement.getParameters().size() == 0) {
if (methodElement.getReturnType().toString().equals(element.asType().toString())) {
return methodNameString;
}
}
}
}
}
return null;
}
use of javax.lang.model.type.TypeKind in project j2objc by google.
the class OperatorRewriter method getPromotionSuffix.
/**
* Some operator functions are given a suffix indicating the promotion type of
* the operands according to JLS 5.6.2.
*/
private static String getPromotionSuffix(Assignment node) {
if (!needsPromotionSuffix(node.getOperator())) {
return "";
}
TypeKind lhsKind = node.getLeftHandSide().getTypeMirror().getKind();
TypeKind rhsKind = node.getRightHandSide().getTypeMirror().getKind();
if (lhsKind == TypeKind.DOUBLE || rhsKind == TypeKind.DOUBLE) {
return "D";
}
if (lhsKind == TypeKind.FLOAT || rhsKind == TypeKind.FLOAT) {
return "F";
}
if (lhsKind == TypeKind.LONG || rhsKind == TypeKind.LONG) {
return "J";
}
return "I";
}
Aggregations