001package com.hfg.util; 002 003import java.lang.reflect.Field; 004 005 006//------------------------------------------------------------------------------ 007/** 008 General utility functions for working with Java annotations. 009 <div> 010 @author J. Alex Taylor, hairyfatguy.com 011 </div> 012 */ 013//------------------------------------------------------------------------------ 014// com.hfg XML/HTML Coding Library 015// 016// This library is free software; you can redistribute it and/or 017// modify it under the terms of the GNU Lesser General Public 018// License as published by the Free Software Foundation; either 019// version 2.1 of the License, or (at your option) any later version. 020// 021// This library is distributed in the hope that it will be useful, 022// but WITHOUT ANY WARRANTY; without even the implied warranty of 023// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 024// Lesser General Public License for more details. 025// 026// You should have received a copy of the GNU Lesser General Public 027// License along with this library; if not, write to the Free Software 028// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 029// 030// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 031// jataylor@hairyfatguy.com 032//------------------------------------------------------------------------------ 033 034public class AnnotationUtil 035{ 036 037 //--------------------------------------------------------------------------- 038 /** 039 Tests whether or not the specified declared field is annotated as Deprecated. 040 * @param inObj the declared field to test 041 * @return whether or not the specified declared field is annotated as Deprecated 042 */ 043 public static boolean isDeclaredFieldDeprecated(Object inObj) 044 { 045 boolean result = false; 046 047 Class clazz = inObj.getClass(); 048 for (Field field : clazz.getDeclaredFields()) 049 { 050 try 051 { 052 if (field.get(null).equals(inObj)) 053 { 054 result = field.isAnnotationPresent(Deprecated.class); 055 break; 056 } 057 } 058 catch (IllegalAccessException | NullPointerException e) 059 { 060 // Ignore 061 } 062 } 063 064 return result; 065 } 066 067}