001package ball.annotation.processing; 002/*- 003 * ########################################################################## 004 * Utilities 005 * %% 006 * Copyright (C) 2008 - 2022 Allen D. Ball 007 * %% 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 * ########################################################################## 020 */ 021import java.io.IOException; 022import java.util.LinkedList; 023import java.util.List; 024import java.util.Set; 025import javax.annotation.processing.Processor; 026import javax.tools.JavaFileManager; 027import javax.tools.JavaFileObject; 028 029import static java.util.Collections.singleton; 030import static javax.tools.StandardLocation.CLASS_OUTPUT; 031import static org.apache.commons.lang3.StringUtils.EMPTY; 032 033/** 034 * Interface to provide an alternate entry point for annotation processing 035 * on compiled class files. Implementors must extend 036 * {@link AnnotatedProcessor}. 037 * 038 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball} 039 */ 040public interface ClassFileProcessor extends Processor { 041 042 /** 043 * {@link Processor} alternate entry point. 044 * 045 * @param set The {@link Set} of {@link Class}es to 046 * analyze. 047 * @param fm The configured {@link JavaFileManager} (for 048 * writing output files). 049 * 050 * @throws Exception If the implementation throws a 051 * {@link Exception}. 052 */ 053 public void process(Set<Class<?>> set, JavaFileManager fm) throws Exception; 054 055 /** 056 * Static method to get the list of {@link Class} file names that have 057 * been generated by the {@link JavaFileManager}. 058 * 059 * @param fm The configured {@link JavaFileManager}. 060 * 061 * @return The {@link List} of class file names ({@link String}s). 062 * 063 * @throws IOException If the {@link JavaFileManager} throws an 064 * {@link IOException}. 065 */ 066 public static List<String> list(JavaFileManager fm) throws IOException { 067 List<String> list = new LinkedList<>(); 068 069 for (JavaFileObject file : fm.list(CLASS_OUTPUT, EMPTY, singleton(JavaFileObject.Kind.CLASS), true)) { 070 list.add(fm.inferBinaryName(CLASS_OUTPUT, file)); 071 } 072 073 return list; 074 } 075}