001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bstefanescu 018 */ 019package org.nuxeo.ecm.webengine.jaxrs.scan; 020 021import java.util.ArrayList; 022import java.util.List; 023import java.util.Set; 024 025import org.objectweb.asm.AnnotationVisitor; 026import org.objectweb.asm.ClassVisitor; 027import org.objectweb.asm.Opcodes; 028 029/** 030 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 031 */ 032public class AnnotationReader extends ClassVisitor { 033 034 protected Set<String> annotations; 035 036 protected List<String> results; 037 038 protected String cname; 039 040 public AnnotationReader(Set<String> annotations) { 041 super(Opcodes.ASM7); 042 results = new ArrayList<>(); 043 this.annotations = annotations; 044 } 045 046 public String getClassName() { 047 return cname.replace('/', '.'); 048 } 049 050 public String getFileName() { 051 return cname; 052 } 053 054 public List<String> getResults() { 055 return results; 056 } 057 058 public boolean hasResults() { 059 return !results.isEmpty(); 060 } 061 062 @Override 063 public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { 064 cname = name; 065 } 066 067 @Override 068 public AnnotationVisitor visitAnnotation(String arg0, boolean arg1) { 069 if (annotations.contains(arg0)) { 070 results.add(arg0); 071 } 072 return null; 073 } 074 075}