use of javax.lang.model.util.Types in project RoboBinding by RoboBinding.
the class TypeMirrorWrapperTest method unsupportedTypeMirrors.
@DataPoints("unsupportedTypeMirrors")
public static TypeMirror[] unsupportedTypeMirrors() {
Types types = compilation.getTypes();
NullType nullType = types.getNullType();
NoType noneType = types.getNoType(TypeKind.NONE);
return new TypeMirror[] { nullType, noneType };
}
use of javax.lang.model.util.Types in project realm-java by realm.
the class RealmProxyClassGenerator method emitPrimitiveType.
/**
* Primitives and boxed types
*/
private void emitPrimitiveType(JavaWriter writer, final VariableElement field, final String fieldName, String fieldTypeCanonicalName) throws IOException {
final String realmType = Constants.JAVA_TO_REALM_TYPES.get(fieldTypeCanonicalName);
// Getter
writer.emitAnnotation("SuppressWarnings", "\"cast\"").beginMethod(fieldTypeCanonicalName, metadata.getInternalGetter(fieldName), EnumSet.of(Modifier.PUBLIC)).emitStatement("proxyState.getRealm$realm().checkIfValid()");
// For String and bytes[], null value will be returned by JNI code. Try to save one JNI call here.
if (metadata.isNullable(field) && !Utils.isString(field) && !Utils.isByteArray(field)) {
writer.beginControlFlow("if (proxyState.getRow$realm().isNull(%s))", fieldIndexVariableReference(field)).emitStatement("return null").endControlFlow();
}
// For Boxed types, this should be the corresponding primitive types. Others remain the same.
String castingBackType;
if (Utils.isBoxedType(fieldTypeCanonicalName)) {
Types typeUtils = processingEnvironment.getTypeUtils();
castingBackType = typeUtils.unboxedType(field.asType()).toString();
} else {
castingBackType = fieldTypeCanonicalName;
}
writer.emitStatement("return (%s) proxyState.getRow$realm().get%s(%s)", castingBackType, realmType, fieldIndexVariableReference(field));
writer.endMethod().emitEmptyLine();
// Setter
writer.beginMethod("void", metadata.getInternalSetter(fieldName), EnumSet.of(Modifier.PUBLIC), fieldTypeCanonicalName, "value");
emitCodeForUnderConstruction(writer, metadata.isPrimaryKey(field), new CodeEmitter() {
@Override
public void emit(JavaWriter writer) throws IOException {
// set value as default value
writer.emitStatement("final Row row = proxyState.getRow$realm()");
if (metadata.isNullable(field)) {
writer.beginControlFlow("if (value == null)").emitStatement("row.getTable().setNull(%s, row.getIndex(), true)", fieldIndexVariableReference(field)).emitStatement("return").endControlFlow();
} else if (!metadata.isNullable(field) && !Utils.isPrimitiveType(field)) {
writer.beginControlFlow("if (value == null)").emitStatement(Constants.STATEMENT_EXCEPTION_ILLEGAL_NULL_VALUE, fieldName).endControlFlow();
}
writer.emitStatement("row.getTable().set%s(%s, row.getIndex(), value, true)", realmType, fieldIndexVariableReference(field));
writer.emitStatement("return");
}
});
writer.emitStatement("proxyState.getRealm$realm().checkIfValid()");
// Compared with getter, null value won't trigger more native calls in setter which is relatively cheaper.
if (metadata.isPrimaryKey(field)) {
// Primary key is not allowed to be changed after object created.
writer.emitStatement(Constants.STATEMENT_EXCEPTION_PRIMARY_KEY_CANNOT_BE_CHANGED, fieldName);
} else {
if (metadata.isNullable(field)) {
writer.beginControlFlow("if (value == null)").emitStatement("proxyState.getRow$realm().setNull(%s)", fieldIndexVariableReference(field)).emitStatement("return").endControlFlow();
} else if (!metadata.isNullable(field) && !Utils.isPrimitiveType(field)) {
// Same reason, throw IAE earlier.
writer.beginControlFlow("if (value == null)").emitStatement(Constants.STATEMENT_EXCEPTION_ILLEGAL_NULL_VALUE, fieldName).endControlFlow();
}
writer.emitStatement("proxyState.getRow$realm().set%s(%s, value)", realmType, fieldIndexVariableReference(field));
}
writer.endMethod();
}
use of javax.lang.model.util.Types in project react4j by react4j.
the class ReactProcessor method determineRenderMethod.
private void determineRenderMethod(@Nonnull final TypeElement typeElement, @Nonnull final ComponentDescriptor descriptor) {
/*
* Get the render method that has been overridden by the typeElement, a parent class, or by a default
* method method implemented by the typeElement or a parent class.
*/
final ExecutableElement renderMethod = getComponentRenderMethod();
final Elements elementUtils = processingEnv.getElementUtils();
final Types typeUtils = processingEnv.getTypeUtils();
final TypeElement componentType = elementUtils.getTypeElement(Constants.COMPONENT_CLASSNAME);
final MethodDescriptor overriddenRenderMethod = // Get all methods on type parent classes, and default methods from interfaces
ProcessorUtil.getMethods(typeElement, processingEnv.getTypeUtils()).stream().filter(m -> elementUtils.overrides(m, renderMethod, typeElement)).filter(m -> m.getEnclosingElement() != componentType).map(m -> new MethodDescriptor(m, (ExecutableType) typeUtils.asMemberOf(descriptor.getDeclaredType(), m))).findAny().orElse(null);
if (null == overriddenRenderMethod) {
throw new ReactProcessorException("The react component does not override any render methods.", typeElement);
}
}
use of javax.lang.model.util.Types in project checker-framework by typetools.
the class StructuralEqualityComparer method subtypeAndCompare.
/**
* A temporary solution until we handle CaptureConversion, subtypeAndCompare handles cases in
* which we encounter a captured type being compared against a non-captured type. The captured
* type may have type arguments that are subtypes of the other type it is being compared to. In
* these cases, we will convert the bounds via this method to the other type and then continue
* on with the equality comparison. If neither of the type args can be converted to the other
* than we just compare the effective annotations on the two types for equality.
*/
boolean subtypeAndCompare(final AnnotatedTypeMirror type1, final AnnotatedTypeMirror type2, final VisitHistory visited) {
final Types types = type1.atypeFactory.types;
final AnnotatedTypeMirror t1;
final AnnotatedTypeMirror t2;
if (type1.getKind() == TypeKind.NULL && type2.getKind() == TypeKind.NULL) {
return areEqual(type1, type2);
}
if (type1.getKind() == TypeKind.NULL || type2.getKind() == TypeKind.NULL) {
t1 = type1;
t2 = type2;
} else if (types.isSubtype(type2.getUnderlyingType(), type1.getUnderlyingType())) {
t1 = type1;
t2 = AnnotatedTypes.asSuper(type1.atypeFactory, type2, type1);
} else if (types.isSubtype(type1.getUnderlyingType(), type2.getUnderlyingType())) {
t1 = AnnotatedTypes.asSuper(type1.atypeFactory, type1, type2);
t2 = type2;
} else {
t1 = null;
t2 = null;
}
if (t1 == null || t2 == null) {
final QualifierHierarchy qualifierHierarchy = type1.atypeFactory.getQualifierHierarchy();
if (currentTop == null) {
return AnnotationUtils.areSame(AnnotatedTypes.findEffectiveAnnotations(qualifierHierarchy, type1), AnnotatedTypes.findEffectiveAnnotations(qualifierHierarchy, type2));
} else {
return AnnotationUtils.areSame(AnnotatedTypes.findEffectiveAnnotationInHierarchy(qualifierHierarchy, type1, currentTop), AnnotatedTypes.findEffectiveAnnotationInHierarchy(qualifierHierarchy, type2, currentTop));
}
}
return areEqual(t1, t2, visited);
}
use of javax.lang.model.util.Types in project checker-framework by typetools.
the class FlowExpressionParseUtil method parseHelper.
private static FlowExpressions.Receiver parseHelper(String expression, FlowExpressionContext context, TreePath path) throws FlowExpressionParseException {
expression = expression.trim();
ProcessingEnvironment env = context.checkerContext.getProcessingEnvironment();
Types types = env.getTypeUtils();
if (isNullLiteral(expression, context)) {
return parseNullLiteral(expression, types);
} else if (isIntLiteral(expression, context)) {
return parseIntLiteral(expression, types);
} else if (isLongLiteral(expression, context)) {
return parseLongLiteral(expression, types);
} else if (isStringLiteral(expression, context)) {
return parseStringLiteral(expression, types, env.getElementUtils());
} else if (isThisLiteral(expression, context)) {
return parseThis(expression, context);
} else if (isSuperLiteral(expression, context)) {
return parseSuper(expression, types, context);
} else if (isIdentifier(expression, context)) {
return parseIdentifier(expression, env, path, context);
} else if (isParameter(expression, context)) {
return parseParameter(expression, context);
} else if (isArray(expression, context)) {
return parseArray(expression, context, path);
} else if (isMethod(expression, context)) {
return parseMethod(expression, context, path, env);
} else if (isMemberSelect(expression, context)) {
return parseMemberSelect(expression, env, context, path);
} else if (isParentheses(expression, context)) {
return parseParentheses(expression, context, path);
} else {
throw constructParserException(expression);
}
}
Aggregations