| 735 | | if (ret instanceof PyObject) { |
|---|
| | 741 | if (ret instanceof PyJavaClass) { |
|---|
| | 742 | Class c = (Class) ((PyJavaClass) ret).__tojava__(Class.class); |
|---|
| | 743 | |
|---|
| | 744 | String doc = new ClassDocumentation().getClassDocumentation(right, null, c); |
|---|
| | 745 | if (doc != null) { |
|---|
| | 746 | Completion cc = new Completion() { |
|---|
| | 747 | |
|---|
| | 748 | @Override |
|---|
| | 749 | public void update() { |
|---|
| | 750 | } |
|---|
| | 751 | }; |
|---|
| | 752 | cc.text = doc; |
|---|
| | 753 | cc.isDocumentation = true; |
|---|
| | 754 | comp.add(cc); |
|---|
| | 755 | } |
|---|
| | 756 | |
|---|
| | 757 | List<Comp> customcomp = new ClassDocumentation().getClassCustomCompletion(right, null, c); |
|---|
| | 758 | if (customcomp != null) { |
|---|
| | 759 | for (Comp cc : customcomp) { |
|---|
| | 760 | makeCompletion(right, comp, cc); |
|---|
| | 761 | } |
|---|
| | 762 | } |
|---|
| | 763 | |
|---|
| | 764 | completionsFromReflectingUponClass(right, comp, c, publicOnly); |
|---|
| | 765 | |
|---|
| | 766 | } else if (ret instanceof PyObject) { |
|---|
| 815 | | private void completionsFromReflectingUponClass(Object ret, final String right, ArrayList<Completion> comp, Class<? extends Object> class1, boolean publicOnly) { |
|---|
| | 847 | protected void completionsFromReflectingUponClass(String right, ArrayList<Completion> comp, Class class1, boolean publicOnly) { |
|---|
| | 848 | Object ret = null; |
|---|
| | 849 | |
|---|
| | 850 | boolean added = false; |
|---|
| | 851 | Field[] fields = class1.getDeclaredFields(); |
|---|
| | 852 | for (Field f : fields) { |
|---|
| | 853 | if (Modifier.isStatic(f.getModifiers())) |
|---|
| | 854 | if (f.getName().startsWith(right) && (!publicOnly || Modifier.isPublic(f.getModifiers()))) { |
|---|
| | 855 | if (!added) { |
|---|
| | 856 | comp.add(getSeparatorFor(ret, class1, right)); |
|---|
| | 857 | added = true; |
|---|
| | 858 | } |
|---|
| | 859 | comp.add(getCompletionFor(ret, class1, f, right)); |
|---|
| | 860 | } |
|---|
| | 861 | } |
|---|
| | 862 | // methods |
|---|
| | 863 | Method[] methods = class1.getDeclaredMethods(); |
|---|
| | 864 | for (Method m : methods) { |
|---|
| | 865 | if (Modifier.isStatic(m.getModifiers())) |
|---|
| | 866 | if (m.getName().startsWith(right) && (!publicOnly || Modifier.isPublic(m.getModifiers()))) { |
|---|
| | 867 | if (!added) { |
|---|
| | 868 | comp.add(getSeparatorFor(ret, class1, right)); |
|---|
| | 869 | added = true; |
|---|
| | 870 | } |
|---|
| | 871 | comp.add(getCompletionFor(ret, class1, m, right)); |
|---|
| | 872 | } |
|---|
| | 873 | } |
|---|
| | 874 | Class c = class1.getSuperclass(); |
|---|
| | 875 | if (c != null) |
|---|
| | 876 | completionsFromReflectingUponClass(right, comp, c, publicOnly); |
|---|
| | 877 | } |
|---|
| | 878 | |
|---|
| | 879 | protected void completionsFromReflectingUponConstructors(String right, ArrayList<Completion> comp, Class class1, boolean publicOnly) { |
|---|
| | 880 | Object ret = null; |
|---|
| | 881 | |
|---|
| | 882 | boolean added = false; |
|---|
| | 883 | |
|---|
| | 884 | Constructor[] methods = class1.getDeclaredConstructors(); |
|---|
| | 885 | for (Constructor m : methods) { |
|---|
| | 886 | { |
|---|
| | 887 | if (!added) { |
|---|
| | 888 | Completion setp = getSeparatorFor(ret, class1, right); |
|---|
| | 889 | setp.text += " (constructors)"; |
|---|
| | 890 | comp.add(setp); |
|---|
| | 891 | added = true; |
|---|
| | 892 | } |
|---|
| | 893 | comp.add(getCompletionFor(class1, m, right)); |
|---|
| | 894 | } |
|---|
| | 895 | } |
|---|
| | 896 | } |
|---|
| | 897 | |
|---|
| | 898 | private void completionsFromReflectingUponInstance(Object ret, final String right, ArrayList<Completion> comp, Class<? extends Object> class1, boolean publicOnly) { |
|---|
| 1077 | | // System.out.println(" didn't find it "); |
|---|
| 1078 | | // |
|---|
| 1079 | | // for (JavaMethod jm : jc.getMethods()) { |
|---|
| 1080 | | // JavaParameter[] p = jm.getParameters(); |
|---|
| 1081 | | // System.out.println("name: <" + jm.getName() + ">: signature"); |
|---|
| 1082 | | // for (JavaParameter pp : p) { |
|---|
| 1083 | | // System.out.println(pp.getName() + " " + pp.getType()); |
|---|
| 1084 | | // } |
|---|
| 1085 | | // } |
|---|
| | 1179 | // System.out.println(" |
|---|
| | 1180 | // didn't find |
|---|
| | 1181 | // it "); |
|---|
| | 1182 | // |
|---|
| | 1183 | // for |
|---|
| | 1184 | // (JavaMethod |
|---|
| | 1185 | // jm : |
|---|
| | 1186 | // jc.getMethods()) |
|---|
| | 1187 | // { |
|---|
| | 1188 | // JavaParameter[] |
|---|
| | 1189 | // p = |
|---|
| | 1190 | // jm.getParameters(); |
|---|
| | 1191 | // System.out.println("name: |
|---|
| | 1192 | // <" + |
|---|
| | 1193 | // jm.getName() |
|---|
| | 1194 | // + ">: |
|---|
| | 1195 | // signature"); |
|---|
| | 1196 | // for |
|---|
| | 1197 | // (JavaParameter |
|---|
| | 1198 | // pp : p) { |
|---|
| | 1199 | // System.out.println(pp.getName() |
|---|
| | 1200 | // + " " + |
|---|
| | 1201 | // pp.getType()); |
|---|
| | 1202 | // } |
|---|
| | 1203 | // } |
|---|
| | 1204 | |
|---|
| | 1205 | } |
|---|
| | 1206 | } catch (Exception e) { |
|---|
| | 1207 | // e.printStackTrace(); |
|---|
| | 1208 | } |
|---|
| | 1209 | } |
|---|
| | 1210 | } |
|---|
| | 1211 | } |
|---|
| | 1212 | } |
|---|
| | 1213 | |
|---|
| | 1214 | c.enabled = true; |
|---|
| | 1215 | return c; |
|---|
| | 1216 | } |
|---|
| | 1217 | |
|---|
| | 1218 | private Completion getCompletionFor(Class<? extends Object> class1, final Constructor m, final String right) { |
|---|
| | 1219 | Completion c = new Completion() { |
|---|
| | 1220 | @Override |
|---|
| | 1221 | public void update() { |
|---|
| | 1222 | try { |
|---|
| | 1223 | ed.getDocument().remove(ed.getCaretPosition() - right.length(), right.length()); |
|---|
| | 1224 | ed.getDocument().insertString(ed.getCaretPosition(), m.getName(), SimpleAttributeSet.EMPTY); |
|---|
| | 1225 | hint = this.text; |
|---|
| | 1226 | hintAlpha = 0.75f; |
|---|
| | 1227 | } catch (BadLocationException e) { |
|---|
| | 1228 | e.printStackTrace(); |
|---|
| | 1229 | } |
|---|
| | 1230 | } |
|---|
| | 1231 | }; |
|---|
| | 1232 | |
|---|
| | 1233 | c.text = "\u1d39 <font face='" + field.core.Constants.defaultFont + "' color='#000000'>" + strip(m.getName()) + "(" + (m.getParameterTypes().length == 0 ? "" : Arrays.asList(m.getParameterTypes())) + ")"; |
|---|
| | 1234 | |
|---|
| | 1235 | String name = m.getDeclaringClass().getCanonicalName(); |
|---|
| | 1236 | System.out.println(" constructor dc name is <"+name+">"); |
|---|
| | 1237 | if (name != null) { |
|---|
| | 1238 | String[] sd = getSourceDirs(); |
|---|
| | 1239 | for (int n = 0; n < sd.length; n++) { |
|---|
| | 1240 | if (sd[n].endsWith(".jar/")) |
|---|
| | 1241 | sd[n] = sd[n].substring(0, sd[n].length() - 1); |
|---|
| | 1242 | |
|---|
| | 1243 | if (sd[n].endsWith(".jar")) { |
|---|
| | 1244 | try { |
|---|
| | 1245 | |
|---|
| | 1246 | JarFile jar = new JarFile(sd[n]); |
|---|
| | 1247 | try { |
|---|
| | 1248 | ZipEntry entry = jar.getEntry("src/" + name.replace(".", "/") + ".java"); |
|---|
| | 1249 | if (entry != null) { |
|---|
| | 1250 | InputStream is = jar.getInputStream(entry); |
|---|
| | 1251 | try { |
|---|
| | 1252 | db.addSource(new InputStreamReader(is)); |
|---|
| | 1253 | |
|---|
| | 1254 | com.thoughtworks.qdox.model.JavaClass jc = db.getClassByName(name); |
|---|
| | 1255 | |
|---|
| | 1256 | Type[] types = new Type[m.getParameterTypes().length]; |
|---|
| | 1257 | for (int i = 0; i < m.getParameterTypes().length; i++) { |
|---|
| | 1258 | types[i] = new Type(m.getParameterTypes()[i].getCanonicalName().replace("[", "").replace("]", ""), m.getParameterTypes()[i].isArray() ? 1 : 0); |
|---|
| | 1259 | } |
|---|
| | 1260 | |
|---|
| | 1261 | JavaMethod method = jc.getMethodBySignature(m.getDeclaringClass().getSimpleName(), types); |
|---|
| | 1262 | |
|---|
| | 1263 | System.out.println(" looking for a method called <"+m.getDeclaringClass().getSimpleName()+"> inside <"+jc+"> found <"+method+">"); |
|---|
| | 1264 | |
|---|
| | 1265 | if (method != null) { |
|---|
| | 1266 | if (method.getParameters() != null) { |
|---|
| | 1267 | |
|---|
| | 1268 | String ctext = "<b>" + m.getDeclaringClass().getSimpleName() + "</b>" + " ( "; |
|---|
| | 1269 | for (int i = 0; i < method.getParameters().length; i++) { |
|---|
| | 1270 | ctext += strip(m.getParameterTypes()[i].getCanonicalName()) + " <b><i>" + method.getParameters()[i].getName() + "</i></b>" + (i != method.getParameters().length - 1 ? ", " : ""); |
|---|
| | 1271 | } |
|---|
| | 1272 | ctext += " )"; |
|---|
| | 1273 | |
|---|
| | 1274 | String comment = method.getComment(); |
|---|
| | 1275 | if (comment == null) |
|---|
| | 1276 | comment = ""; |
|---|
| | 1277 | |
|---|
| | 1278 | c.text = (Modifier.isPublic(m.getModifiers()) ? "\u24d2 <font face='" + field.core.Constants.defaultFont + "' color='#000000'> " : "\u24d2 <font face='" + field.core.Constants.defaultFont + "' color='#444444'>") + ctext + (comment.length() > 0 ? " Ñ " + smaller(limitDocumentation(comment)) : ""); |
|---|
| | 1279 | } else { |
|---|
| | 1280 | System.out.println(" does this ever happen ? "); |
|---|
| | 1281 | } |
|---|
| | 1282 | } else { |
|---|
| | 1283 | |
|---|
| | 1284 | } |
|---|
| | 1285 | } catch (Exception e) { |
|---|
| | 1286 | // e.printStackTrace(); |
|---|
| | 1287 | } |
|---|
| | 1288 | } |
|---|
| | 1289 | } finally { |
|---|
| | 1290 | jar.close(); |
|---|
| | 1291 | } |
|---|
| | 1292 | // Enumeration<JarEntry> |
|---|
| | 1293 | // entries |
|---|
| | 1294 | // = |
|---|
| | 1295 | // jar.entries(); |
|---|
| | 1296 | // for(JarEntry |
|---|
| | 1297 | // j : |
|---|
| | 1298 | // entries) |
|---|
| | 1299 | // { |
|---|
| | 1300 | // } |
|---|
| | 1301 | } catch (IOException e) { |
|---|
| | 1302 | e.printStackTrace(); |
|---|
| | 1303 | } |
|---|
| | 1304 | } else { |
|---|
| | 1305 | String filename = sd[n] + "/" + name.replace(".", "/") + ".java"; |
|---|
| | 1306 | if (new File(filename).exists()) { |
|---|
| | 1307 | try { |
|---|
| | 1308 | db.addSource(new FileReader(filename)); |
|---|
| | 1309 | |
|---|
| | 1310 | com.thoughtworks.qdox.model.JavaClass jc = db.getClassByName(name); |
|---|
| | 1311 | |
|---|
| | 1312 | Type[] types = new Type[m.getParameterTypes().length]; |
|---|
| | 1313 | for (int i = 0; i < m.getParameterTypes().length; i++) { |
|---|
| | 1314 | types[i] = new Type(m.getParameterTypes()[i].getCanonicalName().replace("[", "").replace("]", ""), m.getParameterTypes()[i].isArray() ? 1 : 0); |
|---|
| | 1315 | } |
|---|
| | 1316 | JavaMethod method = jc.getMethodBySignature(m.getDeclaringClass().getSimpleName(), types); |
|---|
| | 1317 | |
|---|
| | 1318 | System.out.println(" looking for a method called <"+m.getDeclaringClass().getSimpleName()+"> inside <"+jc+"> found <"+method+">"); |
|---|
| | 1319 | |
|---|
| | 1320 | // System.out.println(" |
|---|
| | 1321 | // looking for method <" |
|---|
| | 1322 | // + method + "> <" + |
|---|
| | 1323 | // m.getName() + "><" + |
|---|
| | 1324 | // Arrays.asList(types) |
|---|
| | 1325 | // + ">"); |
|---|
| | 1326 | if (method != null) { |
|---|
| | 1327 | if (method.getParameters() != null) { |
|---|
| | 1328 | |
|---|
| | 1329 | String ctext = "<b>" + m.getDeclaringClass().getSimpleName() + "</b>" + " ( "; |
|---|
| | 1330 | for (int i = 0; i < method.getParameters().length; i++) { |
|---|
| | 1331 | ctext += strip(m.getParameterTypes()[i].getCanonicalName()) + " <b><i>" + method.getParameters()[i].getName() + "</i></b>" + (i != method.getParameters().length - 1 ? ", " : ""); |
|---|
| | 1332 | } |
|---|
| | 1333 | ctext += " )"; |
|---|
| | 1334 | |
|---|
| | 1335 | String comment = method.getComment(); |
|---|
| | 1336 | if (comment == null) |
|---|
| | 1337 | comment = ""; |
|---|
| | 1338 | |
|---|
| | 1339 | c.text = (Modifier.isPublic(m.getModifiers()) ? "\u24d2 <font face='" + field.core.Constants.defaultFont + "' color='#000000'> " : "\u24d2 <font face='" + field.core.Constants.defaultFont + "' color='#444444'>") + ctext + (comment.length() > 0 ? " Ñ " + smaller(comment) : ""); |
|---|
| | 1340 | } else { |
|---|
| | 1341 | System.out.println(" does this ever happen ? "); |
|---|
| | 1342 | } |
|---|
| | 1343 | } else { |
|---|
| | 1344 | // System.out.println(" |
|---|
| | 1345 | // didn't find |
|---|
| | 1346 | // it "); |
|---|
| | 1347 | // |
|---|
| | 1348 | // for |
|---|
| | 1349 | // (JavaMethod |
|---|
| | 1350 | // jm : |
|---|
| | 1351 | // jc.getMethods()) |
|---|
| | 1352 | // { |
|---|
| | 1353 | // JavaParameter[] |
|---|
| | 1354 | // p = |
|---|
| | 1355 | // jm.getParameters(); |
|---|
| | 1356 | // System.out.println("name: |
|---|
| | 1357 | // <" + |
|---|
| | 1358 | // jm.getName() |
|---|
| | 1359 | // + ">: |
|---|
| | 1360 | // signature"); |
|---|
| | 1361 | // for |
|---|
| | 1362 | // (JavaParameter |
|---|
| | 1363 | // pp : p) { |
|---|
| | 1364 | // System.out.println(pp.getName() |
|---|
| | 1365 | // + " " + |
|---|
| | 1366 | // pp.getType()); |
|---|
| | 1367 | // } |
|---|
| | 1368 | // } |
|---|