use of io.micronaut.inject.writer.StringSwitchWriter in project micronaut-core by micronaut-projects.
the class BeanIntrospectionWriter method buildFindIndexedProperty.
private void buildFindIndexedProperty(ClassWriter classWriter) {
if (indexByAnnotationAndValue.isEmpty()) {
return;
}
GeneratorAdapter writer = new GeneratorAdapter(classWriter.visitMethod(Opcodes.ACC_PROTECTED | Opcodes.ACC_FINAL, FIND_INDEXED_PROPERTY_METHOD.getName(), FIND_INDEXED_PROPERTY_METHOD.getDescriptor(), null, null), ACC_PROTECTED | Opcodes.ACC_FINAL, FIND_INDEXED_PROPERTY_METHOD.getName(), FIND_INDEXED_PROPERTY_METHOD.getDescriptor());
writer.loadThis();
writer.loadArg(0);
writer.invokeVirtual(Type.getType(Class.class), new Method("getName", Type.getType(String.class), new Type[] {}));
int classNameLocal = writer.newLocal(Type.getType(String.class));
writer.storeLocal(classNameLocal);
writer.loadLocal(classNameLocal);
new StringSwitchWriter() {
@Override
protected Set<String> getKeys() {
return indexByAnnotationAndValue.keySet().stream().map(s -> s.annotationName).collect(Collectors.toSet());
}
@Override
protected void pushStringValue() {
writer.loadLocal(classNameLocal);
}
@Override
protected void onMatch(String annotationName, Label end) {
if (indexByAnnotationAndValue.keySet().stream().anyMatch(s -> s.annotationName.equals(annotationName) && s.value == null)) {
Label falseLabel = new Label();
writer.loadArg(1);
writer.ifNonNull(falseLabel);
String propertyName = indexByAnnotationAndValue.get(new AnnotationWithValue(annotationName, null));
int propertyIndex = getPropertyIndex(propertyName);
writer.loadThis();
writer.push(propertyIndex);
writer.invokeVirtual(introspectionType, FIND_PROPERTY_BY_INDEX_METHOD);
writer.returnValue();
writer.visitLabel(falseLabel);
} else {
Label falseLabel = new Label();
writer.loadArg(1);
writer.ifNonNull(falseLabel);
writer.goTo(end);
writer.visitLabel(falseLabel);
}
Set<String> valueMatches = indexByAnnotationAndValue.keySet().stream().filter(s -> s.annotationName.equals(annotationName) && s.value != null).map(s -> s.value).collect(Collectors.toSet());
if (!valueMatches.isEmpty()) {
new StringSwitchWriter() {
@Override
protected Set<String> getKeys() {
return valueMatches;
}
@Override
protected void pushStringValue() {
writer.loadArg(1);
}
@Override
protected void onMatch(String value, Label end) {
String propertyName = indexByAnnotationAndValue.get(new AnnotationWithValue(annotationName, value));
int propertyIndex = getPropertyIndex(propertyName);
writer.loadThis();
writer.push(propertyIndex);
writer.invokeVirtual(introspectionType, FIND_PROPERTY_BY_INDEX_METHOD);
writer.returnValue();
}
}.write(writer);
}
writer.goTo(end);
}
}.write(writer);
writer.push((String) null);
writer.returnValue();
writer.visitMaxs(DEFAULT_MAX_STACK, 1);
writer.visitEnd();
}
use of io.micronaut.inject.writer.StringSwitchWriter in project micronaut-core by micronaut-projects.
the class BeanIntrospectionWriter method buildGetIndexedProperties.
private void buildGetIndexedProperties(ClassWriter classWriter) {
if (indexByAnnotations.isEmpty()) {
return;
}
GeneratorAdapter writer = new GeneratorAdapter(classWriter.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, GET_INDEXED_PROPERTIES.getName(), GET_INDEXED_PROPERTIES.getDescriptor(), null, null), ACC_PUBLIC | Opcodes.ACC_FINAL, GET_INDEXED_PROPERTIES.getName(), GET_INDEXED_PROPERTIES.getDescriptor());
writer.loadThis();
writer.loadArg(0);
writer.invokeVirtual(Type.getType(Class.class), new Method("getName", Type.getType(String.class), new Type[] {}));
int classNameLocal = writer.newLocal(Type.getType(String.class));
writer.storeLocal(classNameLocal);
writer.loadLocal(classNameLocal);
new StringSwitchWriter() {
@Override
protected Set<String> getKeys() {
return indexByAnnotations.keySet();
}
@Override
protected void pushStringValue() {
writer.loadLocal(classNameLocal);
}
@Override
protected void onMatch(String annotationName, Label end) {
writer.loadThis();
writer.getStatic(introspectionType, annotationIndexFields.get(annotationName), Type.getType(int[].class));
writer.invokeVirtual(introspectionType, GET_BP_INDEXED_SUBSET_METHOD);
writer.returnValue();
}
}.write(writer);
writer.invokeStatic(Type.getType(Collections.class), COLLECTIONS_EMPTY_LIST);
writer.returnValue();
writer.visitMaxs(DEFAULT_MAX_STACK, 1);
writer.visitEnd();
}
use of io.micronaut.inject.writer.StringSwitchWriter in project micronaut-core by micronaut-projects.
the class BeanIntrospectionWriter method buildPropertyIndexOfMethod.
private void buildPropertyIndexOfMethod(ClassWriter classWriter) {
GeneratorAdapter findMethod = new GeneratorAdapter(classWriter.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, PROPERTY_INDEX_OF.getName(), PROPERTY_INDEX_OF.getDescriptor(), null, null), ACC_PUBLIC | Opcodes.ACC_FINAL, PROPERTY_INDEX_OF.getName(), PROPERTY_INDEX_OF.getDescriptor());
new StringSwitchWriter() {
@Override
protected Set<String> getKeys() {
Set<String> keys = new HashSet<>();
for (BeanPropertyData prop : beanProperties) {
keys.add(prop.name);
}
for (BeanFieldData field : beanFields) {
keys.add(field.beanField.getName());
}
return keys;
}
@Override
protected void pushStringValue() {
findMethod.loadArg(0);
}
@Override
protected void onMatch(String value, Label end) {
findMethod.loadThis();
findMethod.push(getPropertyIndex(value));
findMethod.returnValue();
}
}.write(findMethod);
findMethod.push(-1);
findMethod.returnValue();
findMethod.visitMaxs(DEFAULT_MAX_STACK, 1);
findMethod.visitEnd();
}
Aggregations