-
Notifications
You must be signed in to change notification settings - Fork 2
/
android-classes.el
106 lines (90 loc) · 5.2 KB
/
android-classes.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
(require 'pjb-html)
;; (require 'jde nil t)
;; (require 'jde-import nil t)
(defun make-android-package-info (name documentation-url) (list name documentation-url))
(defun android-class-info-name (info) (first info))
(defun android-class-info-documentation-url (info) (second info))
(defun make-android-class-info (name package documentation-url) (list name package documentation-url))
(defun android-class-info-name (info) (first info))
(defun android-class-info-package (info) (second info))
(defun android-class-info-documentation-url (info) (third info))
(defun android-packages-and-classes (android-classes-xhtml)
(let* ((root "http://developer.android.com/reference/")
(android-xml (with-file android-classes-xhtml
(pjb-parse-html (buffer-substring (point-min) (point-max)))))
(body (get-first-child-tagged (car android-xml) 'body))
(ul (get-first-child-tagged body 'ul))
(lis (get-children-tagged ul 'li))
(packages (mapcar (lambda (li)
(let* ((a (get-first-child-tagged li 'a))
(href (attribute-value (get-attribute-named a 'href )))
(name (cl:string-trim " \n\t" (first (element-children a)))))
(make-android-package-info name href)))
lis))
(table (get-first-child-tagged body 'table))
(trs (get-children-tagged table 'tr))
(classes (mapcar (lambda (tr)
(let* ((linkcol (get-first-child-valued tr 'class "jd-linkcol"))
(a (get-first-child-tagged linkcol 'a))
(url (attribute-value (get-attribute-named a 'href)))
(name (cl:string-trim " \n\t" (first (element-children a))))
(package (if (and (prefixp root url)
(suffixp ".html" url))
(substitute (character ".") (character "/")
(substring url (length root) (- (length url) (length ".html"))))
name)))
(make-android-class-info name package url)))
trs)))
(list packages classes)))
(defvar *android-packages* '())
(defvar *android-classes* '())
(let ((pc (android-packages-and-classes "~/src/public/emacs/android-classes.xhtml")))
(setf *android-packages* (first pc)
*android-classes* (second pc))
nil)
(defun java-all-program-classes ()
"Return a list of fully qualified names of all the java classes found in the current project."
(let ((path (or (buffer-file-name) default-directory)))
(and path
(let* ((path (file-name-directory path))
(root-component "/src/")
(root-position (search root-component path :from-end t)))
(and root-position
(let ((root-directory (subseq path 0 (+ root-position (length root-component)))))
(mapcar (lambda (class-path)
(let ((components (split-string (subseq class-path (length root-directory)
(- (length class-path)
(length ".java")))
"/")))
(make-android-class-info (car (last components))
(mapconcat (function identity)
components
".")
nil)))
(let ((result (quote())))
(mapfiles (lambda (path)
(when (suffixp ".java" path)
(push path result)))
root-directory :recursive)
result))))))))
(defun android-all-classes ()
"Return a list of fully qualified names of all the android classes found in the buffer."
(let ((packages '())
(class-package-alist (append (java-all-program-classes) *android-classes*)))
(dolist (class-name (jde-import-all-find-classes-to-import) packages)
(let ((class (assoc class-name class-package-alist)))
(when class
(pushnew (android-class-info-package class) packages :test (function string=)))))))
(defun android-browse-documentation-of-class (class-name)
(let ((class-info (assoc class-name *android-classes*)))
(if class-info
(browse-url (android-class-info-documentation-url class-info))
(error "Not a known android class: %s" class-name))))
(defun android-browse-documentation-of-class-at-point ()
(interactive)
(android-browse-documentation-of-class (thing-at-point 'symbol)))
(defun android-import-all ()
(interactive)
(dolist (class (android-all-classes))
(jde-import-one-class class)))
(provide 'android-classes)