1 package org.ashkelon.util; 2 6 7 import java.io.BufferedReader ; 8 import java.io.FileReader ; 9 import java.io.IOException ; 10 import java.util.ArrayList ; 11 import java.util.HashMap ; 12 import java.util.List ; 13 import java.util.Map ; 14 15 import org.ashkelon.DocInfo; 16 import org.ashkelon.pages.ConfigInfo; 17 18 import com.sun.javadoc.ParamTag; 19 import com.sun.javadoc.ProgramElementDoc; 20 import com.sun.javadoc.Tag; 21 import com.sun.javadoc.Type; 22 23 29 public class JDocUtil 30 { 31 public static final int UNKNOWN_TYPE = -123; 32 33 34 public static final int PUBLIC = 1; 35 public static final int PROTECTED = 2; 36 public static final int PRIVATE = 3; 37 public static final int PACKAGEPRIVATE = 4; 38 39 public static final String [] ACCESSIBILITIES = {"public", "protected", "private", "packageprivate"}; 40 41 45 public static String getDimension(int dim) 46 { 47 return StringUtils.join("[]", "", dim); 48 } 49 50 54 public static int getDimension(Type type) 55 { 56 if (type.dimension() == null) return 0; 57 return (type.dimension().length()/2); 58 } 59 60 64 public static String unqualify(String qualifiedName) 65 { 66 return unqualify(qualifiedName, false); 67 } 68 69 public static String unqualify(String qualifiedName, boolean isNestedClass) 70 { 71 if (qualifiedName == null) { return ""; } 72 73 int idx = qualifiedName.indexOf("("); 74 boolean isexecmember = (idx > -1); 75 if (isexecmember) 76 { 77 String end = qualifiedName.substring(idx); 78 String start = qualifiedName.substring(0,idx); 79 int index = start.lastIndexOf("."); 80 if (index < 0) { return qualifiedName; } 81 return start.substring(index+1) + end; 82 } 83 else 84 { 85 int index = qualifiedName.lastIndexOf("."); 86 if (index < 0) { return qualifiedName; } 87 88 if (isNestedClass) 89 { 90 String firstPart = qualifiedName.substring(0, index); 91 index = firstPart.lastIndexOf("."); 92 if (index < 0) { return qualifiedName; } 93 } 94 95 return qualifiedName.substring(index+1); 96 } 97 } 98 99 105 public static String conditionalQualify(String name, String pkgName) 106 { 107 if (name.startsWith(pkgName+".")) 108 { 109 return name.substring(pkgName.length()+1); 110 } 111 else if (name.startsWith("java.lang.")) 112 { 113 return name.substring("java.lang.".length()); 114 } 115 else 116 { 117 return name; 118 } 119 } 120 121 public static boolean isQualified(String name) 122 { 123 return (name.indexOf(".")>=0); 124 } 125 126 130 public static String getTagText(Tag tags[]) 131 { 132 String text = ""; 133 for (int i=0; i<tags.length; i++) 134 { 135 text += tags[i].text() + " "; 136 } 137 return text.trim(); 138 } 139 140 145 public static String resolveDescription(DocInfo sourcedoc, Tag tags[]) 146 { 147 return ConfigInfo.getResolver().resolveDescription(sourcedoc, tags); 148 } 149 150 156 public static String [] getTagList(Tag tags[]) 157 { 158 List list = new ArrayList (); 159 for (int i=0; i<tags.length; i++) 160 { 161 String [] vals = StringUtils.split(tags[i].text(), ","); 162 for (int j=0; j<vals.length; j++) 163 { 164 list.add(vals[j]); 165 } 166 } 167 String [] stringlist = new String [list.size()]; 168 list.toArray(stringlist); 169 return stringlist; 170 } 171 172 175 public static boolean isPrimitive(Type type) 176 { 177 return (type.asClassDoc() == null); 178 } 179 180 183 public static int getAccessibility(ProgramElementDoc programElement) 184 { 185 if (programElement.isPublic()) 186 { 187 return PUBLIC; 188 } 189 else if (programElement.isProtected()) 190 { 191 return PROTECTED; 192 } 193 else if (programElement.isPrivate()) 194 { 195 return PRIVATE; 196 } 197 else 198 { 199 return PACKAGEPRIVATE; 200 } 201 } 202 203 206 public static Map makeParamMap(DocInfo sourcedoc, ParamTag[] paramTags) 207 { 208 Map paramInfo = new HashMap (); 209 String paramdescription = ""; 210 for (int i=0; i<paramTags.length; i++) 211 { 212 paramdescription = resolveDescription(sourcedoc, paramTags[i].inlineTags()); 214 paramInfo.put(paramTags[i].parameterName(), paramdescription); 215 } 216 return paramInfo; 217 } 218 219 224 public static List getPackageListFromFileName(String filename) 225 { 226 List pkgs = new ArrayList (12); 227 if (filename==null) return pkgs; 228 if (filename.startsWith("@")) 229 filename = filename.substring(1); 230 try 231 { 232 BufferedReader br = new BufferedReader (new FileReader (filename)); 233 String pkg = null; 234 while ((pkg=br.readLine()) != null) 235 { 236 pkgs.add(pkg); 237 } 238 } 239 catch (IOException ex) 240 { 241 } 242 return pkgs; 243 } 244 245 } 246 | Popular Tags |