001package io.ebean.enhance.entity;
002
003import io.ebean.enhance.asm.AnnotationVisitor;
004import io.ebean.enhance.asm.Attribute;
005import io.ebean.enhance.asm.FieldVisitor;
006import io.ebean.enhance.asm.Opcodes;
007import io.ebean.enhance.common.EnhanceConstants;
008
009/**
010 * Used to collect information about a field (specifically from field annotations).
011 */
012public class LocalFieldVisitor extends FieldVisitor implements EnhanceConstants {
013
014  private final FieldMeta fieldMeta;
015
016  /**
017  * Constructor used for entity class enhancement.
018  *
019  * @param fv the fieldVisitor used to write
020  * @param fieldMeta the fieldMeta data
021  */
022  public LocalFieldVisitor(FieldVisitor fv, FieldMeta fieldMeta) {
023    super(Opcodes.ASM7, fv);
024    this.fieldMeta = fieldMeta;
025  }
026
027  /**
028  * Return the field name.
029  */
030  public String getName() {
031    return fieldMeta.getFieldName();
032  }
033
034  @Override
035  public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
036    fieldMeta.addAnnotationDesc(desc);
037    if (fv != null){
038      if (!visible && desc.equals(L_JETBRAINS_NOTNULL)) {
039        fv.visitAnnotation(L_EBEAN_NOTNULL, true);
040      }
041      return fv.visitAnnotation(desc, visible);
042    } else {
043      return null;
044    }
045  }
046
047  @Override
048  public void visitAttribute(Attribute attr) {
049    if (fv != null){
050      fv.visitAttribute(attr);
051    }
052  }
053
054  @Override
055  public void visitEnd() {
056    if (fv != null){
057      fv.visitEnd();
058    }
059  }
060
061}