1 16 package org.apache.commons.attributes; 17 18 import java.util.ArrayList ; 19 import java.util.List ; 20 21 43 public class InvalidAttributeTargetError extends Error { 44 45 public InvalidAttributeTargetError (String attributeClass, String element, int targetFlags) { 46 super ("Attributes of type " + attributeClass + " can't be applied to " + element + ". " + 47 "They can only be applied to: " + flagsToString (targetFlags)); 48 } 49 50 private final static String flagsToString (int flags) { 51 List targetNames = new ArrayList (); 52 if ((flags & Target.CLASS) > 0) { 53 targetNames.add ("CLASS"); 54 } 55 if ((flags & Target.FIELD) > 0) { 56 targetNames.add ("FIELD"); 57 } 58 if ((flags & Target.METHOD) > 0) { 59 targetNames.add ("METHOD"); 60 } 61 if ((flags & Target.CONSTRUCTOR) > 0) { 62 targetNames.add ("CONSTRUCTOR"); 63 } 64 if ((flags & Target.METHOD_PARAMETER) > 0) { 65 targetNames.add ("METHOD_PARAMETER"); 66 } 67 if ((flags & Target.CONSTRUCTOR_PARAMETER) > 0) { 68 targetNames.add ("CONSTRUCTOR_PARAMETER"); 69 } 70 if ((flags & Target.RETURN) > 0) { 71 targetNames.add ("RETURN"); 72 } 73 74 StringBuffer sb = new StringBuffer (); 75 for (int i = 0; i < targetNames.size (); i++) { 76 sb.append (targetNames.get (i)); 77 if (i < targetNames.size () - 1) { 78 sb.append (" | "); 79 } 80 } 81 return sb.toString (); 82 } 83 84 } | Popular Tags |