Package cn.wensiqun.visitor.annotated

Source Code of cn.wensiqun.visitor.annotated.FieldDefVisitor

package cn.wensiqun.visitor.annotated;

import java.util.ArrayList;
import java.util.List;

import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.commons.EmptyVisitor;

import cn.wensiqun.GrepRobotInternal;
import cn.wensiqun.grep.annotated.FieldGrep;
import cn.wensiqun.info.AnnotationInfo;
import cn.wensiqun.info.FieldInfo;

public class FieldDefVisitor extends CommonDef implements FieldVisitor {

  private FieldInfo info;
 
  private FieldGrep fieldGrep;
 
  public FieldDefVisitor(GrepRobotInternal grepClient, FieldInfo info) {
    super(grepClient);
    this.info = info;
    this.fieldGrep = grepClient.getFieldGrep();
  }

  public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
    AnnotationInfo annotationInfo = new AnnotationInfo(desc);
    if(grepClient.getAnnotationCriterion().contains(annotationInfo.getName())){
          info.getAnnotations().add(annotationInfo);
          List<FieldInfo> infos = fieldGrep.getAnnotatedFieldMap().get(annotationInfo.getName());
          if (infos == null) {
              infos = new ArrayList<FieldInfo>();
              fieldGrep.getAnnotatedFieldMap().put(annotationInfo.getName(), infos);
          }
          infos.add(info);
          return new AnnotationDefVisitor(grepClient, annotationInfo);
    }else{
      return new EmptyVisitor();
    }
  }

  public void visitAttribute(Attribute attr) {

  }

  public void visitEnd() {

  }

}
TOP

Related Classes of cn.wensiqun.visitor.annotated.FieldDefVisitor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.