irenkaã®Hackãæ¸ãã¦ããã¨Hackã®é©ç¨ãç¹å®ã®ã¯ã©ã¹ã ãé¿ãããå ´åãããã¾ãã
ãã¨ãã°ãtoStringã¡ã½ããããªã¼ãã¼ã©ã¤ãããHackããã¹ãã¼ãã¬ã¹ãªã¯ã©ã¹ã«å¯¾ãã¦ã¯ãã¾ãæå³ãæã¡ã¾ããããã®å ´åã«Hackãé©ç¨ããªãããã«ãããã®ã§ãã
èããããçã¨ãã¦ã¯ãJavaã®ã¯ã©ã¹ã«å¯¾ãã¦Hackãå¶å¾¡ããããã®Tigerã¢ããã¼ã·ã§ã³ãå²ãå½ã¦ã¦Hackã®è¨å®ãæ¸ãã¨ããæ¹æ³ããã®æ¹æ³ã ã¨Hackå¶å¾¡ç¨ã¢ããã¼ã·ã§ã³ããã«ããã¹ã«å«ããå¿ è¦ãã§ã¦ãã¦ãMaven2ãªã©ã®Eclipse以å¤ã®ãã«ããã¼ã«ã®é½åãèããã¨ã§åä»ã§ãã
ããã§ã¿ã¤ãã»ã¼ããããªãããªãã¡ã¯ã¿ãªã³ã°ãå©ããªããã§ãããããã¨ããããJavadocã«@suppresshackã¨æ¸ãã°ãããããççºæ³ã§èãã¦ã¿ã¾ããã
irenkaã¯Javaã®ã³ã¼ãã ãã§ãªããJavadocãirenka ã®DOM APIã使ã£ã¦èªã¿æ¸ãã§ããã®ã§ãã®æ©è½ã使ã£ã¦å®è£
ãã¦ã¿ã¾ããã以ä¸ãå¤å®ç¨ã®ãã¸ãã¯ã§ããisSuppressMyValidatorãHackã®å
é ã§å¼ã³åºãã¯Hackãé©ç¨ãã¦ããããã©ããã®å¤å®ãã§ãã¾ãã
protected boolean isSuppressMyValidator(Class<?> clazz, final CtReference ref) { List<String> validatorClasses = getSuppressHackingValue(ref); return validatorClasses.contains(clazz.getCanonicalName()); } protected List<String> getSuppressHackingValue(CtReference ref) { List<String> result = new ArrayList<String>(); CtJavadoc javadoc = ref.getJavadoc(); if (javadoc != null && javadoc.getBlocks() != null) { for (int i = 0; i < javadoc.getBlocks().size(); i++) { CtDocBlock docBlock = javadoc.getBlocks().get(i); if ("@suppresshack".equals(docBlock.getTag())) { for (int f = 0; f < docBlock.getFragments().size(); f++) { CtDocFragment docFragment = docBlock.getFragments().get(f); if (docFragment instanceof CtDocText) { CtDocText text = (CtDocText) docFragment; String paramText = text.getContent(); if (!StringUtils.isEmpty(paramText)) { String[] params = paramText.split(","); for (String param : params) { result.add(param.trim()); } } } } } } } return result; }
å®éã®ä½¿ãæ¹ã¯ä»¥ä¸ã
/** toStringã¡ã½ããããªã¼ãã¼ã©ã¤ãããHack */ public class ToStringRewriter{ /** * ã½ã¼ã¹ã³ã¼ãããªã©ã¤ããã¾ãã * * @when * @param clazz */ public void rewrite(CtClass<?> clazz) { // Hackã®å¦çãå§ããåã« if ( isSuppressMyValidator(ToStringRewriter.class, clazz) ){ return; } // 以ä¸ãçç¥ } }
/** * @suppresshack com.google.code.hack.ej2.ToStringRewriter */ public class Hoge{ // suppresshackã¢ããã¼ã·ã§ã³ã«ãã£ã¦Hackãé©ç¨ãããªãã®ã§toStringã¡ã½ãããèªåçæãããªã }