/
ajc-java-complete.el
1376 lines (1270 loc) · 68.9 KB
/
ajc-java-complete.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; ajc-java-complete.el --- Auto Java Completion for GNU Emacs
;; This file is NOT part of GNU Emacs
;; plesase send Bug reports and suggestions to 'Joseph at <jixiuf@gmail.com>
;; License
;; Copyright (C) 2011 Joseph <jixiuf@gmail.com> Limited
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary
;;;this is "Auto Java Complete".
;;; Commands:
;;
;; Below are complete command list:
;;
;; `ajc-reload'
;; restart Auto Java Complete ,when your tag file changed,
;; `ajc-import-all-unimported-class'
;; import all unimported class .
;; `ajc-import-class-under-point'
;; import class under point.
;;
;;; Customizable Options:
;;
;; Below are customizable option list:
;;
;; `ajc-tag-file'
;; the tag file is used for java complete ,it is generate by a Tags.java ,
;; default = "~/.java_base.tag"
;; `ajc-default-length-of-class'
;; the length of class name at dropdown-menu ,if the class
;; default = 36
;; `ajc-return-type-char'
;; the char before return type when
;; default = ":"
;; `ajc-throws-char'
;; the char before Exceptions when completing
;; default = " #"
;;1. it depends on auto complete ,so it would complete
;; everything by dropdowning a menu.
;;2. it is tag based . so before you used it on emacs ,you
;; should generate a tag file by using Tags.java .
;; about how to use it ,see the Install section.
;;3. it depends on yasnippet . when completing method and
;; constructor it would generate a templete dynamically
;; so that you can jump from a paramter to another one .
;;; Features
;; 1. support importing.
;; when you type in import javax.s-|-
;; it would drop down a menu like this
;; import javax.s
;;
;; javax.sql
;; javax.swing
;; javax.sound
;; 2. support import class with keybindings (even in jsp file)
;; auto import all Class in source file
;; (local-set-key (kbd "C-c i") (quote ajc-import-all-unimported-class))
;; import Class where under point
;; (local-set-key (kbd "C-c m") (quote ajc-import-class-under-point))
;; included in ajc-complete-config.el
;; 3. support completing class name ,you just need typing
;; in a Word beginning with [A-Z] ,then it would auto find
;; matched class and list it with dropdown menu.
;; 4. support complete method.
;; for example
;; List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
;; list.
;; it would list all method like this
;; list.
;; equals(Object)
;; add(Object)
;; clear()
;; it can do more
;; list.listIterator().next().
;; toString()
;; getClass()
;; notify()
;; 5. support complete constructor
;; after keyword 'new' it would try to complete constructor
;; 6. support completing in jsp files.
;; If your want to enable ajc-java-complete-mode when openning
;; a jsp file. you can
;; (add-hook 'jsp-mode 'ajc-java-complete-mode)
;; if you has a jsp-mode;
;; if not ,you can do it like this
;; (add-hook 'find-file-hook 'ajc-4-jsp-find-file-hook)
;; now it can complete class name,method ,constructor.
;; it also support complete importing ,but it isn't auto completed,
;; you must trigger it by a key binding
;; for example (define-key ac-mode-map (kbd "M-1") 'auto-complete)
;; <%@ page language="java" import="java.io.File,java.util.Map,javax.sw-|-"%>
;; now you can press M-1 to show the menu.
;;
;;; Install
;; see Install file in this directory
;;; Code.
(defgroup auto-java-complete nil
"Auto Java Completion."
:group 'convenience
:prefix "auto-java-complete")
(defcustom ajc-tag-file "~/.java_base.tag"
"the tag file is used for java complete ,it is generate by a Tags.java ,
so before you use this tool ,try to compile Tags.java
javac Tags.java
and use this class like this
java Tags
it will tag all jars in classpath to tag file , or
java Tags com.whatever.*
just tag class under com.whatever packages "
:type 'string
:group 'auto-java-complete)
(defcustom ajc-default-length-of-class 36
"the length of class name at dropdown-menu ,if the class
name is shorter than this value ,then empty string are append
.and return type are at position 37 "
:type 'integer
:group 'auto-java-complete)
(defcustom ajc-return-type-char ":"
"the char before return type when
completing methods."
:type 'string
:group 'auto-java-complete
)
(defcustom ajc-throws-char " #"
"the char before Exceptions when completing
method"
:type 'string
:group 'auto-java-complete
)
;;private variables
(defvar ajc-is-running nil "after (ajc-init) it will become true")
(defvar ajc-all-sorted-class-items nil "this is a list,
all the element are sorted class-item
this variable should work with ajc-two-char-list,
then search class is faster ")
(defvar ajc-two-char-list nil
"in this list ,it looks like '((Ab 1 3 ) (Ac 4 15))that means
all class those name starts with Ab are in the position of
0~2 (because index from 0 not 1) in ajc-all-sorted-class-items " )
(defvar ajc-tmp-sorted-class-buffer-name " *ajc-tmp-sorted-class*")
(defvar ajc-tag-buffer nil "this is the buffer of .java_base.tag" )
(defvar ajc-package-first-ln 0
"the first line number of the package section in tag file")
(defvar ajc-class-first-ln 0
"the first line number of the class section in tag file,
it is the end of package section line number too. " )
(defvar ajc-member-first-ln 0
"the first line number of the member section in tag file ,
actually it is the end of package section line number too" )
(defvar ajc-member-end-ln 0
"the end line number of the member section in tag file ,
it is the last line number in tag file" )
(defvar ajc-position-of-package-first-line 1)
(defvar ajc-position-of-class-first-line 1)
(defvar ajc-position-of-member-first-line 1)
(defvar ajc-position-of-member-end-line 1)
(defvar ajc-matched-class-items-cache nil
"when search class-prefix without package-name ,
it will search thoudsands of lines in tags files ,
so this will cache for next match maybe ")
(defvar ajc-previous-class-prefix nil "cache last class-prefix ")
(defvar ajc-matched-import-cache-list nil
"when complete a import ,sometimes we can use
the last completed items for next complete ")
(defvar ajc-previous-matched-import-prefix nil
"previous matched prefix for import Class at head of source")
(defvar ajc-current-class-prefix-4-complete-class nil
"when (ajc-is-available-4-complete-class-p ) return true,
it will save current class-prefix in this variable ,so
(ajc-complete-class-candidates) can reuse it . ")
(defun ajc-goto-line ( line-num &optional buffer)
(with-current-buffer (or buffer (current-buffer))
(when (numberp line-num)
(goto-char (point-min))
(forward-line (1- line-num )))))
(defun ajc-read-line(line-number &optional buffer)
"read a line and return the string"
(with-current-buffer (or buffer (current-buffer))
(ajc-goto-line line-number)
(buffer-substring-no-properties
(line-beginning-position) (line-end-position))))
(defun ajc-split-string-with-separator(str regexp &optional replacement omit-nulls)
"this function is a tool like split-string,
but it treat separator as an element of returned list
for example (ajc-split-string-with-separator abc.def.g \"\\.\" \".\")
will return '(\"abc\" \".\" \"def\" \".\" \"g\" )"
(when str
(let (split-list substr match-end)
(if (string-match regexp str)
(progn
(while (string-match regexp str)
(setq match-end (match-end 0))
(setq substr (substring-no-properties str 0 (- match-end 1)))
(when (or (not omit-nulls) (> (length substr ) 0))
(setq split-list (append split-list (list substr))) )
(setq split-list (append split-list (list (or replacement regexp))))
(setq str (substring-no-properties str match-end)))
(when (or (not omit-nulls) (> (length str ) 0))
(setq split-list (append split-list (list str)))))
(setq split-list (list str)))
split-list)))
(defun ajc-split-pkg-item ( pkg-line-string )
"the format pkg-line-string is str`num`num
this function translate it to a list ,the num will be string2number
give me `java.lang`222`333 ,return '(\"java.lang\" 222 333 ) "
(let (( pkg-item (split-string pkg-line-string "`" t)))
(setcar (nthcdr 1 pkg-item ) (string-to-number (nth 1 pkg-item )))
(setcar (nthcdr 2 pkg-item ) (string-to-number (nth 2 pkg-item )))
pkg-item))
(defun ajc-split-pkg-item-by-pkg-ln ( pkg-line-number &optional buffer )
"the format pkg-line-string is str`num`num
this function translate it to a list ,the num will be
string2number return a list of pkg info of line-number "
(ajc-split-pkg-item
(ajc-read-line pkg-line-number
(or buffer (ajc-reload-tag-buffer-maybe)))))
(defun ajc-split-class-item ( class-line-string )
"the format of class-line-string is
classname`packageLineNum`memberStartLineNum`memberEndLineNum
this function translate it to a list ,the num will be convert to number "
(let (( class-item (split-string class-line-string "`" t)))
(setcar (nthcdr 1 class-item ) (string-to-number (nth 1 class-item )))
(setcar (nthcdr 2 class-item) (string-to-number (nth 2 class-item )))
(setcar (nthcdr 3 class-item) (string-to-number (nth 3 class-item )))
class-item))
(defun ajc-split-class-item-by-class-ln
( class-line-number &optional buffer )
(ajc-split-class-item
(ajc-read-line class-line-number
(or buffer (ajc-reload-tag-buffer-maybe)))))
(defun ajc-split-constructor-by-line-num ( constructor-line-num )
(ajc-split-constructor
(ajc-read-line constructor-line-num
(ajc-reload-tag-buffer-maybe))))
(defun ajc-split-field (field-line-string)
(when field-line-string
(let* ((field-item)
(field-line-string (substring-no-properties field-line-string 1))
(split-list (split-string field-line-string "`"))
(return-type (nth 1 split-list)))
;;handle field name
(add-to-list 'field-item (car split-list) t)
(if (string-match "^~" return-type )
(add-to-list 'field-item (substring-no-properties return-type 1) t)
(add-to-list 'field-item (ajc-split-class-item-by-class-ln
(string-to-number return-type)) t))
field-item )))
(defun append-space-to-item(str)
(let ((len (length str)));; insert whitespace between classname and return type
(if (< len (- ajc-default-length-of-class 3))
(setq str
(concat str
(make-string (- (- ajc-default-length-of-class 3) len ) 32 )));;32 mean whitespace
(setq str (concat str " "))))
)
;; (ajc-field-to-string (ajc-split-field " out`654 " ) )
;; (ajc-field-to-string (ajc-split-field " out`654 " ) t)
(defun ajc-field-to-string (field-item &optional with-return-type)
(when field-item
(if with-return-type
(let ((field-string (car field-item)) (return-type (nth 1 field-item)))
(setq field-string (append-space-to-item field-string))
(setq field-string (concat field-string ajc-return-type-char))
(when (stringp return-type)
(setq field-string (concat field-string return-type ) ))
(when (listp return-type)
(setq field-string (concat field-string (car return-type))))
field-string)
(car field-item))))
;; (ajc-method-to-string (ajc-split-method "skippedEntity`~void`784`4012"))
;; (ajc-method-to-string (ajc-split-method "skippedEntity`~void`784`4012") t)
(defun ajc-method-to-string (method-item &optional with-return-type-and-throws )
"this is a toString() like function .
when param with-detail is not null, it will include
return type and exceptions, default it only include method name
and params"
(when method-item
(let ((method-string (car method-item))
(return-type (nth 1 method-item) )
(params (nth 2 method-item) )
(exceptions (nth 3 method-item)))
(if (stringp params )
(setq method-string (concat method-string "()"))
(setq method-string (concat method-string "("))
(dolist (param params )
(when (stringp param )
(setq method-string (concat method-string param " , " )))
(when (listp param)
(setq method-string (concat method-string (car param) " , " ))
))
(setq method-string
(replace-regexp-in-string " , $" ")" method-string )))
(when with-return-type-and-throws
(setq method-string (append-space-to-item method-string))
(cond ((stringp return-type)
(setq method-string (concat method-string ajc-return-type-char return-type)))
((listp return-type)
(setq method-string (concat method-string ajc-return-type-char (car return-type))))
)
(when (listp exceptions )
(setq method-string (concat method-string ajc-throws-char))
(dolist (exception exceptions )
(when (stringp exception ) (setq method-string (concat method-string exception " , " )))
(when (listp exception)
(setq method-string (concat method-string (car exception) " , " ))))
(setq method-string (replace-regexp-in-string ", $" "" method-string )))
)
method-string )))
;; (ajc-class-to-string (ajc-split-class-item "RasterOp`18`15551`15556"))
;; (ajc-class-to-string (ajc-split-class-item "RasterOp`18`15551`15556") t)
(defun ajc-class-to-string(class-item &optional with-package-name-append)
(when class-item
(let* ((class-string (car class-item)))
(when with-package-name-append
(setq class-string
(concat (append-space-to-item class-string) ajc-return-type-char
(car (ajc-split-pkg-item-by-pkg-ln (nth 1 class-item))))))
class-string
)))
;; (yas/expand-snippet(ajc-method-to-yasnippet-templete (car
;; (ajc-find-members (car (ajc-find-out-matched-class-item-without-package-prefix "FileWriter" t )) "write" ))))
;; (ajc-method-to-string (car
;; (ajc-find-members (car (ajc-find-out-matched-class-item-without-package-prefix "String" t )) "split" )))
;; "split(String , int)"
;(yas/expand-snippet "split(${1:String} , ${2:int})"
(defun ajc-method-to-yasnippet-templete (method-item)
(when method-item
(let ((method-string (car method-item))
(params (nth 2 method-item) )
(exceptions (nth 3 method-item))
(index 0))
(if (stringp params ) (setq method-string (concat method-string "()"))
(setq method-string (concat method-string "("))
(dolist(param params)
(when (stringp param)
(setq method-string
(concat method-string "${" (number-to-string (+ index 1)) ":"
param "} , " )))
(when (listp param)
(setq method-string
(concat method-string "${" (number-to-string (+ 1 index )) ":"
(car param) "} , " )))
(setq index (1+ index)))
(setq method-string (replace-regexp-in-string " , $" ")$0" method-string )))
method-string)))
(defun ajc-method-item-to-candidate(field-or-method-item)
"translate `field-or-method-item' to candidate ,`field-or-method-item'
can be a method item ,or a field item"
(let ((candidate))
(if (= 2 (length field-or-method-item ));; lenth of field is 2 (only field and returntype )
(let ((field-full-string (ajc-field-to-string field-or-method-item t))
(field-short-string (ajc-field-to-string field-or-method-item nil)))
(setq candidate (cons field-full-string field-short-string))
)
(let((method-full-string (ajc-method-to-string field-or-method-item t))
(method-short-string (ajc-method-to-string field-or-method-item nil)))
(setq candidate
(cons (propertize method-full-string
'templete field-or-method-item
'templete-type 'method)
method-short-string))))
candidate))
(defun ajc-split-method ( method-line-string )
(when method-line-string
(let ((method-item) (split-list)(return-type))
(setq split-list (split-string method-line-string "`"))
;;handle method name
(add-to-list 'method-item (car split-list) t)
(setq return-type (nth 1 split-list))
(if (string-match "^~" return-type )
(add-to-list 'method-item (substring-no-properties return-type 1) t)
(add-to-list 'method-item (ajc-split-class-item-by-class-ln
(string-to-number return-type)) t))
;;handle params if exists
(if (not (string-equal "" (nth 2 split-list)))
(let ((params)(param-split-list))
(setq param-split-list (split-string (nth 2 split-list) "," t))
(dolist (param param-split-list)
(if (string-match "^~" param )
(setq params (append params (list (substring-no-properties param 1 ))))
(setq params (append params (list (ajc-split-class-item-by-class-ln
(string-to-number param)))))))
(setq method-item (append method-item (list params))))
(setq method-item (append method-item (list ""))))
(if (not (string-equal "" (nth 3 split-list)))
(let ((exceptions)(exception-split-list))
(setq exception-split-list (split-string (nth 3 split-list) "," t))
(dolist (exception exception-split-list)
(if (string-match "^~" exception )
(setq exceptions (append exceptions (list (substring-no-properties exception 1 ))))
(setq exceptions (append exceptions (list (ajc-split-class-item-by-class-ln
(string-to-number exception)))))))
(setq method-item (append method-item (list exceptions))))
(setq method-item (append method-item (list ""))))
method-item)))
(defun ajc-split-constructor(constructor-line-string)
(when constructor-line-string
(let ((constructor-item) (split-list))
(setq constructor-line-string (substring-no-properties constructor-line-string 2))
(setq split-list (split-string constructor-line-string "`"))
;;handle constructor name
(add-to-list 'constructor-item (car split-list) t)
;;handle params if exists
(if (not (string-equal "" (nth 1 split-list)))
(let ((params)(param-split-list))
(setq param-split-list (split-string (nth 1 split-list) "," t))
(dolist (param param-split-list)
(if (string-match "^~" param )
(setq params (append params (list (substring-no-properties param 1 ))))
(setq params (append params (list (ajc-split-class-item-by-class-ln
(string-to-number param)))))))
(setq constructor-item (append constructor-item (list params))))
(setq constructor-item (append constructor-item (list ""))))
(if (not (string-equal "" (nth 2 split-list)))
(let ((exceptions)(exception-split-list))
(setq exception-split-list (split-string (nth 2 split-list) "," t))
(dolist (exception exception-split-list)
(if (string-match "^~" exception )
(setq exceptions (append exceptions (list (substring-no-properties exception 1 ))))
(progn
(setq exceptions (append exceptions (list (ajc-split-class-item-by-class-ln
(string-to-number exception))))))))
(setq constructor-item (append constructor-item (list exceptions))))
(setq constructor-item (append constructor-item (list ""))))
constructor-item)))
(defun ajc-constructor-to-string (constructor-item &optional is-with-exceptions)
(when constructor-item
(let((constructor-string (car constructor-item))
(params (nth 1 constructor-item) )
(exceptions (nth 2 constructor-item)))
(if (stringp params ) (setq constructor-string (concat constructor-string "()"))
(progn
(setq constructor-string (concat constructor-string "("))
(dolist (param params )
(when (stringp param ) (setq constructor-string (concat constructor-string param " , " )))
(when (listp param)
(setq constructor-string (concat constructor-string (car param) " , " ))))
(setq constructor-string (replace-regexp-in-string " , $" ")" constructor-string ))))
(when is-with-exceptions
(when (listp exceptions )
(setq constructor-string (concat constructor-string ajc-throws-char))
(dolist (exception exceptions )
(when (stringp exception ) (setq constructor-string (concat constructor-string exception " , " )))
(when (listp exception)
(setq constructor-string (concat constructor-string (car exception) " , " ))))
(setq constructor-string (replace-regexp-in-string ", $" "" constructor-string ))))
constructor-string)))
(defun ajc-constructor-to-yasnippet-templete (constructor-item)
(when constructor-item
(let((constructor-string (car constructor-item))
(params (nth 1 constructor-item) )
(exceptions (nth 2 constructor-item))
(index 0))
(if (stringp params ) (setq constructor-string (concat constructor-string "()"))
(setq constructor-string (concat constructor-string "("))
(dolist (param params)
(when (stringp param ) (setq constructor-string
(concat constructor-string "${" (number-to-string (+ index 1)) ":"
param "} , " )))
(when (listp param)
(setq constructor-string (concat constructor-string "${" (number-to-string (+ 1 index )) ":"
(car param) "} , " )))
(setq index (+ 1 index ))
)
(setq constructor-string (replace-regexp-in-string " , $" ")$0" constructor-string )))
(setq constructor-string constructor-string))))
;; find tag file
(defun ajc-init()
"find java tag file and do some initial works, like populate some variables "
(unless ajc-is-running
(setq ajc-tag-file (file-truename (expand-file-name ajc-tag-file )))
(if (file-exists-p ajc-tag-file)
(with-current-buffer (find-file-noselect ajc-tag-file )
;; a buffer name starts with empth string,means hidden this buffer
(rename-buffer " *java-base.tag*")
(setq ajc-tag-buffer " *java-base.tag*")
(buffer-disable-undo)
(setq buffer-read-only t)
(fundamental-mode)
(setq case-fold-search nil)
(setq ajc-package-first-ln (string-to-number (ajc-read-line 3)))
(setq ajc-position-of-package-first-line (progn (ajc-goto-line ajc-package-first-ln) (point)) )
(setq ajc-class-first-ln (string-to-number (ajc-read-line 4)))
(setq ajc-position-of-class-first-line (progn (ajc-goto-line ajc-class-first-ln) (point)) )
(setq ajc-member-first-ln (string-to-number (ajc-read-line 5)))
(setq ajc-position-of-member-first-line (progn (ajc-goto-line ajc-member-first-ln) (point)) )
(setq ajc-member-end-ln (string-to-number (ajc-read-line 6)))
(setq ajc-position-of-member-end-line (progn (ajc-goto-line ajc-member-end-ln) (point)) )
;; (ajc-load-all-sorted-class-items-to-memory)
(ajc-sort-class)
)
(message ( concat ajc-tag-file " doesn't exists !!!")))
(setq ajc-is-running t)
))
;;;###autoload
(defun ajc-reload()
"restart Auto Java Complete ,when your tag file changed,
you can use this function restart AutoJavaComplete "
(interactive)
(setq ajc-is-running nil)
(ajc-init)
)
;;;###autoload
(defalias 'auto-java-complete-reload 'ajc-reload)
(defun ajc-reload-tag-buffer-maybe( )
"check if the ajc-tag-buffer is still live ,if not reload it "
(unless ajc-tag-buffer
(ajc-init))
ajc-tag-buffer)
;; (ajc-find-out-matched-pkg-item "java.awt")
;; (ajc-find-out-matched-pkg-item "java.awt" t)
(defun ajc-find-out-matched-pkg-item
(pkg-prefix &optional exactly_match buffer)
"this function is used to find out all matched packages whose prefix is `pkg-prefix'
for example: suppose pkg-prefix=javax.xm then it will return
'( (\"javax.xml.bind\" 2741 2767 ) (\"javax.xml.bind.attachment\" 2776 2778 ))
if exactly_match is not nil then pkg-prefix will be seen as full package name , and
we will suppose you are searching package name = pkg-prefix , if exactly_match is given
then only 1 or 0 item will returned so we will try to
convert '((packageName 12 33 )) to '(packageName 12 33 ) "
(with-current-buffer (or buffer (ajc-reload-tag-buffer-maybe))
(let ((regexp-pkg-prefix (concat "^" (regexp-quote pkg-prefix)))
matched-package)
(when exactly_match ;;I use ` char as the separator in tag file
(setq regexp-pkg-prefix (concat "^" (regexp-quote pkg-prefix ) "`" )))
(goto-char ajc-position-of-package-first-line)
(while (re-search-forward regexp-pkg-prefix ajc-position-of-class-first-line t)
(add-to-list 'matched-package
(ajc-split-pkg-item
(buffer-substring-no-properties (line-beginning-position)(line-end-position)))))
(when exactly_match (setq matched-package (car matched-package)))
matched-package )))
;; (ajc-shrunk-matched-pkgs "java.aw") == java.awt
(defun ajc-shrunk-matched-pkgs (pkg-prefix)
"this function is used for list matched package.
when you import a package in head of your java file,
when you typed in 'jav-|-', then it will list 'java javax'
instead of 'java.lang java.lang.rel javax.xml javax.xml.ws'"
(let ((matched-pkg-items (ajc-find-out-matched-pkg-item pkg-prefix))
(index-of-first-dot 0) (return-list)
(length-of-pkg-prefix (length pkg-prefix)))
(dolist (current-item matched-pkg-items)
(if (setq index-of-first-dot
(string-match "\\." (car current-item) length-of-pkg-prefix))
(add-to-list 'return-list (substring-no-properties
(car current-item) 0 index-of-first-dot))
(add-to-list 'return-list (car current-item))))
return-list))
(defun ajc-find-class-first-check-imported(class-name)
"this function will find class from imported classes,
if doesn't exists,find from the tag file,
if more than one class item matched class-name in tag file,
then imported one of them first"
(let* ((imported-class (ajc-caculate-all-imported-class-items))
(matched-class-item
(catch 'found
(dolist (item imported-class)
(when (string-equal class-name (car item))
(throw 'found item))))))
(unless matched-class-item;;if not found from imported section
(let ((matched-class-items
(ajc-find-out-matched-class-item-without-package-prefix class-name t)))
(if (= (length matched-class-items) 1)
(setq matched-class-item (car matched-class-items))
(setq matched-class-item
(car (ajc-insert-import-at-head-of-source-file matched-class-items))))))
matched-class-item))
;; (ajc-find-out-matched-class-item "java.io" "Fil")
;; (ajc-find-out-matched-class-item "java.io" "")
;; (ajc-find-out-matched-class-item "java.io" nil)
;; (ajc-find-out-matched-class-item "java.io" "File" t)
;; (ajc-find-out-matched-class-item nil "File" )
;; (print (length (ajc-find-out-matched-class-item nil nil )))
(defun ajc-find-out-matched-class-item
(package-name class-prefix &optional exactly_match buffer)
"this function is use to find out all Class whose package name is
`package-name' and ClassName starts with `class-prefix' if package-name
is nil, then try to find out all Class whose ClassName starts with
`class-prefix' if `class-prefix' is nil or empty string ,it will try to
find out all Class in package `package-name' if both `package-name'
and class-prefix are nil, then it will return all Class in all package
the param `exactly_match' ,means only class name exactly equals
to `class-prefix' will be return"
(let* ((class-prefix (or class-prefix ""))
(regexp-class-prefix
(if exactly_match (concat "^" (regexp-quote class-prefix) "`" )
(concat "^" (regexp-quote class-prefix))))
(matched-pkg-item (when package-name (ajc-find-out-matched-pkg-item package-name t)))
(line-num ajc-class-first-ln)
(end-position ajc-member-first-ln)
return-list current-line-string)
(with-current-buffer (or buffer (ajc-reload-tag-buffer-maybe))
(when matched-pkg-item
(setq line-num (nth 1 matched-pkg-item)
end-position (nth 2 matched-pkg-item)))
(while (< line-num end-position)
(setq current-line-string (ajc-read-line line-num))
(when (string-match regexp-class-prefix current-line-string)
(add-to-list 'return-list (ajc-split-class-item current-line-string)))
(setq line-num (1+ line-num)))
return-list)))
;;(ajc-sort-class)
;;(ajc-get-two-char-item "Sy")
(defun ajc-get-two-char-item(two-char-string)
(catch 'found
(dolist (item ajc-two-char-list)
(when (string= (car item) two-char-string)
(throw 'found item)))))
;;(ajc-find-out-matched-class-item-without-package-prefix "System" t)
;; (ajc-find-out-matched-class-item-without-package-prefix "_ServantLocatorStub")
(defun ajc-find-out-matched-class-item-without-package-prefix
(class-prefix &optional exactly_match)
"actully you can use ajc-find-out-matched-class-item to do
the same thing ,just let package-prefix nil but it is very slowly ,
it need to search all the line in tag file just to find out one class item .
so this function use ajc-load-all-sorted-clas-items-to-memory
to sort the class section and load it in memory and build a index for it,
limit : length of class-prefix must larger than 2"
(with-current-buffer (get-buffer ajc-tmp-sorted-class-buffer-name)
(let ((matched-class-items) (case-fold-search nil)
(regexp-class-prefix (if exactly_match
(concat "^" class-prefix "`")
(concat "^" class-prefix ) ))
(two-char-item (or (and (> (length class-prefix) 1)
(ajc-get-two-char-item (substring-no-properties class-prefix 0 2)))
(list nil (point-min) (point-max)) )))
(goto-char (nth 1 two-char-item))
(while (re-search-forward regexp-class-prefix (nth 2 two-char-item) t )
(add-to-list 'matched-class-items
(ajc-split-class-item
(buffer-substring-no-properties
(line-beginning-position) (line-end-position))) t))
matched-class-items
)))
(defun ajc-sort-class ()
"sort class for search ,we build a table for example ((Ab 1 3) (Ac 4 6))
then we search AbstractC ,we just need to search line number from 1 3 "
(let ((case-fold-search nil))
(with-current-buffer (get-buffer-create ajc-tmp-sorted-class-buffer-name)
(erase-buffer)
(insert-buffer-substring (ajc-reload-tag-buffer-maybe)
ajc-position-of-class-first-line ajc-position-of-member-first-line)
(sort-lines nil 1 (point-max))
(let ((end ?Z) (index ?A) (index2 ?A) (two-char)
(two-char-item)(next-start-search-postion))
(setq ajc-two-char-list nil)
(while (<= index end) (setq index2 ?A)
(while ( <= index2 ?z)
(setq two-char (concat (char-to-string index) (char-to-string index2)))
(setq two-char-item
(ajc-build-map-4-search-class
two-char ajc-tmp-sorted-class-buffer-name (or next-start-search-postion 1)))
(if two-char-item
(add-to-list 'ajc-two-char-list two-char-item t)
(setq next-start-search-postion (nth 2 two-char-item)))
(if (= index2 ?Z) (setq index2 ?a) (setq index2 (+ index2 1))))
(setq index (+ index 1)))))))
(defun ajc-build-map-4-search-class (two-char-prefix ajc-tmp-sorted-class-buffer-name start-search-postion)
"suppose two-char-prefix is 'Ab' and ajc-tmp-sorted-class-buffer-name is the buffer
,all lines in it is the classname has been sorted by classname
it is cut from tag file between ajc-class-first-ln and ajc-member-first-ln ,and sorted by (sort-lines)
then this function is try to find out className begin with two-char-prefix ,and got the start position
and end position ,record in a list ,when search class name begin with two-char-prefix ,we just need to
find it from the start position to the end position ,it is faster than directly searching the unsorted
tag buffer file "
(with-current-buffer ajc-tmp-sorted-class-buffer-name
(goto-char start-search-postion)
(let ((char1 (string-to-char (substring-no-properties two-char-prefix 0 1)))
(char2 (string-to-char (substring-no-properties two-char-prefix 1 2)))
start end has-found-first return-item end-position end-prefix-regexp case-fold-search)
(if (or (= char1 ?Z) (= char2 ?z) (= char2 ?Z))
(setq end-position (line-number-at-pos (point-max)))
(progn
(if (< char2 ?a)
(setq end-prefix-regexp (concat "^" (char-to-string char1)
"[a-z" (char-to-string (+ 1 char2)) "-Z]\\|^" (char-to-string (+ char1 1)) "[a-zA-Z]" ))
(setq end-prefix-regexp (concat "^" (char-to-string char1)
"[" (char-to-string (+ 1 char2)) "-z]\\|^" (char-to-string (+ char1 1)) "[a-zA-Z]" )))
(goto-char start-search-postion)
(if (re-search-forward end-prefix-regexp (point-max) t)
(setq end-position (point))
(setq end-position (point-max)))))
(goto-char start-search-postion)
(while (re-search-forward (concat "^" two-char-prefix ) end-position t )
(when (not has-found-first)
(setq has-found-first t)
(setq start (line-beginning-position)))
(setq end (line-end-position)))
(when (numberp start) (setq return-item (list two-char-prefix start end)))
return-item)))
;; (defun ajc-load-all-sorted-class-items-to-memory()
;; (ajc-sort-class);;first sort the class ,and populate ajc-two-char-list variable
;; (with-current-buffer ajc-tmp-sorted-class-buffer-name
;; (goto-char (point-min))
;; (let ((max-line-num (line-number-at-pos (point-max)))(line-num 1))
;; (while (< line-num max-line-num)
;; (add-to-list 'ajc-all-sorted-class-items
;; (ajc-split-class-item (ajc-read-line line-num)) t)
;; (setq line-num (+ line-num 1)))))
;; (kill-buffer (get-buffer ajc-tmp-sorted-class-buffer-name)))
(defun ajc-import-package-candidates()
"this function is the candidates , so you can bind it with a key sequence
it will return a list, for example `( java.lang ,java.ref)"
(save-excursion
(let ((prefix-string) (matched-pkg-strings))
(setq case-fold-search nil)
(when
(re-search-backward ;;search import string in java file or jsp file ,now support jsp
"\\(?:\\(?:import=\"\\(?:.*[ \t\n]*,[ \t\n]*\\)*\\)\\|\\(?:import[ \t]+\\)\\)\\([a-zA-Z0-9_\\.]*\\)"
nil t)
(setq prefix-string (match-string-no-properties 1 ))
(when (and ajc-matched-import-cache-list ;;first try completion from cache
(string-match (concat "^" ajc-previous-matched-import-prefix ) prefix-string ))
(setq matched-pkg-strings (all-completions prefix-string ajc-matched-import-cache-list)))
(when (= (length matched-pkg-strings ) 0 ) ;;if there are 0 matched in cache then find it out from tag files
(setq matched-pkg-strings ;;add pkgs
(append matched-pkg-strings
(ajc-shrunk-matched-pkgs prefix-string)))
(let ((index_of_last_dot (string-match "\\.[a-zA-Z_0-9]*$" prefix-string));;add classes
(package-prefix)(class-prefix))
(when index_of_last_dot
(setq package-prefix (substring-no-properties prefix-string 0 index_of_last_dot))
(setq class-prefix (substring-no-properties prefix-string (+ 1 index_of_last_dot)))
(dolist (element (ajc-find-out-matched-class-item package-prefix class-prefix))
(add-to-list 'matched-pkg-strings (concat package-prefix "." (car element)))))))
;; (setq ajc-is-importing-packages-p t)
(setq ajc-previous-matched-import-prefix prefix-string) ;;
(setq ajc-matched-import-cache-list matched-pkg-strings)))))
(defun ajc-find-out-class-by-parse-source ()
"find out class in current java source file, then will import them if they haven't been imported "
(save-excursion
(save-match-data
(let ((matched-class-strings)
(return-type-regexp "\\(\\([a-zA-Z0-9_]\\| *\t*< *\t*\\| *\t*>\\| *\t*, *\t*\\| *\t*\\[ *\t*]\\)+\\)" )
(split-char-regexp "\\(,\\|<\\|>\\|]\\|\\[\\| \\|\t\\|\n\\)"));;a list of split char like ", \t<>[]"
(goto-char (point-min)) (setq case-fold-search nil)
(while (search-forward-regexp (concat "\\bnew[ \t]+" return-type-regexp)(point-max) 't)
(setq matched-class-strings (append matched-class-strings (split-string (match-string-no-properties 1 ) split-char-regexp t))))
(goto-char (point-min))
(while (search-forward-regexp "\\b\\([A-Z][a-zA-Z0-9_]*\\)\\.[a-zA-Z0-9_]+[ \t]*(" (point-max) 't)
(setq matched-class-strings (append matched-class-strings (list (match-string-no-properties 1)))))
(goto-char (point-min))
(while (search-forward-regexp "\\([a-zA-Z0-9_]+\\)\\.getInstance[ \t]*(" (point-max) 't)
(add-to-list 'matched-class-strings (match-string-no-properties 1)))
(goto-char (point-min))
;;find out all statement of variable ,for example
;; String name; Map<String,<String,Ojbect>>[] map=
(while (search-forward-regexp "^[ \t]*\\(public\\|private\\|static\\|final\\|native\\|synchronized\\|transient\\|volatile\\|strictfp\\| \\|\t\\)*\\([A-Z]\\([a-zA-Z0-9_]\\| *\t*< *\t*\\| *\t*>\\| *\t*, *\t*\\| *\t*\\[ *\t*]\\)+\\)[ \t]+[a-zA-Z0-9_]+[ \t]*[;=]" (point-max) 't)
(setq matched-class-strings
(append matched-class-strings (split-string (match-string-no-properties 2 ) split-char-regexp t))))
(goto-char (point-min));; find ClassName after "catch" keywords for example :catch(IOException e )
(while (search-forward-regexp "catch[ \t]*(\\([a-zA-Z0-9_]+\\)[ \t]+" (point-max) 't)
(add-to-list 'matched-class-strings (match-string-no-properties 1)))
(goto-char (point-min)) ;;find method statement
(while (search-forward-regexp "^[ \t]*\\(public\\|private\\|static\\|final\\|native\\|synchronized\\|transient\\|volatile\\|strictfp\\| \\|\t\\)*[ \t]+\\(\\([a-zA-Z0-9_]\\|\\( *\t*< *\t*\\)\\|\\( *\t*> *\t*\\)\\|\\( *\t*, *\t*\\)\\|\\( *\t*\\[ *\t*\\)\\|\\(]\\)\\)+\\)[ \t]+[a-zA-Z0-9_]+[ \t]*(\\(.*\\))[ \t]*\\(throws[ \t]+\\([a-zA-Z0-9_, \t\n]*\\)\\)?[ \t\n]*{" (point-max) 't)
(let ((exception (match-string-no-properties 11))
(returns (match-string-no-properties 2))
(params (match-string-no-properties 9)))
;;handle return type
(setq matched-class-strings (append matched-class-strings (split-string returns "\\(,\\|<\\|>\\|]\\|\\[\\| \\|\t\\)" t)))
;;;;handle methods parameters ;;find out 'Map String Ojbect User' from "Map<String,Object> map,User user"
(while (and params (> (length params) 0))
(if (string-match "\\([a-zA-Z0-9_]\\|\\( *\t*< *\t*\\)\\|\\( *\t*>\\)\\|\\( *\t*, *\t*\\)\\|\\( *\t*\\[ *\t*\\)\\|\\(]\\)\\)+" params)
(progn (setq matched-class-strings
(append matched-class-strings (split-string (match-string-no-properties 0 params ) split-char-regexp t)))
(string-match "[ \t]*[a-zA-Z0-9_]+[ \t,]?" params (match-end 0 ))
(setq params (substring-no-properties params (match-end 0 ))))
(setq params nil)))
;;handle throws Exception1,Exception2, we will exatract Exception1 Exception2 from throws sentence
(when exception
(setq matched-class-strings (append matched-class-strings (split-string exception split-char-regexp t))))))
;;remove primitive type and remove duplicate item
(delete-dups matched-class-strings) (delete "" matched-class-strings)
(dolist (ele matched-class-strings)
(if (string-match "\\(int\\|float\\|double\\|long\\|short\\|char\\|byte\\|void\\|boolean\\|return\\|public\\|static\\|private\\|protected\\|abstract\\|final\\|native\\|package\\|new\\)" ele)
(delete ele matched-class-strings)))
matched-class-strings
))))
(defun ajc-caculate-all-unimported-class-items()
"this function will find out all unimported Class itmes , it just do a subtration
(ajc-find-out-class-by-parse-source) -(ajc-caculate-all-imported-class-items)
what you need to do next, is just import the unimported class "
(let ((imported-class-names (mapcar 'car (ajc-caculate-all-imported-class-items)))
(class-names-in-source (ajc-find-out-class-by-parse-source))
(unimported-class-items))
(print class-names-in-source)
(dolist (ele class-names-in-source)
(unless (member ele imported-class-names)
(setq unimported-class-items
(append unimported-class-items
(ajc-find-out-matched-class-item-without-package-prefix ele t)))))
unimported-class-items))
(defun ajc-import-all-unimported-class()
"import all unimported class ."
(interactive)
(ajc-insert-import-at-head-of-source-file
(ajc-caculate-all-unimported-class-items)))
(defun ajc-import-class-under-point ()
"import class under point."
(interactive)
(let ((cur-word (current-word)))
(when (and cur-word (> (length cur-word) 0))
(when (string-match "[^a-zA-Z0-9_]\\([a-zA-Z0-9_]+\\)$" cur-word)
(setq cur-word (match-string-no-properties 1 cur-word )))
(when (string-match "^\\([a-zA-Z0-9_]+\\)[^a-zA-Z0-9_]" cur-word)
(setq cur-word (match-string-no-properties 1 cur-word)))
(ajc-insert-import-at-head-of-source-file
(ajc-find-out-matched-class-item-without-package-prefix cur-word t)))))
(defun ajc-insert-import-at-head-of-source-file (import-class-items-list)
"insert 'import sentence' at head of java source file,
before that it will use y-or-n-p ask user to confirm "
(let ((import-class-buffer "*ajc-import-java-class*")
(import-class-window) (user-confirmed-class-items-list)
(java-buffer (current-buffer))(java-window))
(setq case-fold-search nil)
(if (and import-class-items-list (> (length import-class-items-list) 0))
(progn
(setq import-class-buffer (switch-to-buffer-other-window import-class-buffer t))
(setq java-window (get-buffer-window java-buffer))
(setq import-class-window (get-buffer-window import-class-buffer))
(with-current-buffer import-class-buffer ;;show maybe imported Class in a new buffer
(delete-region (point-min)(point-max))
(dolist (ele import-class-items-list)
(insert (concat "[ ] " (car (ajc-split-pkg-item-by-pkg-ln (nth 1 ele ))) "." (car ele) "\n")))
(insert " ");;insert empty line at end of buffer
(goto-char (1+(point-min)))
(dolist (ele import-class-items-list ) ;;ask user whether to import the Class
(beginning-of-line)(forward-char 1)
(when (y-or-n-p (concat "import " (car ele) "? "))
(add-to-list 'user-confirmed-class-items-list ele)
(delete-char 1) (insert "*"))
(forward-line 1)(forward-char 1)))
;;delete *import-java-class* buffer and window
(delete-window import-class-window)(kill-buffer import-class-buffer)
(with-current-buffer java-buffer
(ajc-insert-import-at-head-of-source-file-without-confirm user-confirmed-class-items-list))
(message "Finished importing.")
user-confirmed-class-items-list)
(message "No class need import."))))
(defun ajc-insert-import-at-head-of-source-file-without-confirm (class-items)
(save-match-data ;;insert at head of java source
(setq case-fold-search nil)
(save-excursion (goto-char (point-min))
(let* ((class-start (save-excursion
(re-search-forward
"\\(\\b\\(class\\|interface\\)[ \t]+[a-zA-Z0-9_]+[\n \t]*\\({\\|extends\\|implements\\|<\\)\\)" nil 't))))
(if (not class-start);; then this is a jsp file
(let ((all-class-strings ""))
(dolist (class-item class-items)
(setq all-class-strings
(concat all-class-strings
(car (ajc-split-pkg-item-by-pkg-ln (nth 1 class-item ))) "." (car class-item)
",")))
(unless (string-equal "" all-class-strings);;delete last char ","
(setq all-class-strings (substring all-class-strings 0 (1- (string-width all-class-strings)))))
(goto-char (point-min))
(insert (concat "<%@ page import=\"" all-class-strings "\" %>\n" )))
(if(re-search-forward "^[ \t]*import[ \t]+[a-zA-Z0-9_\\.\\*]+[ \t]*;" class-start 't)
;;if find 'import' insert before it
(progn (beginning-of-line )(insert "\n")(forward-line -1)
(dolist (ele class-items)(insert
(concat "import "
(car (ajc-split-pkg-item-by-pkg-ln (nth 1 ele )))
"." (car ele) ";\n"))))
;; if hasn't found 'import; then insert after 'package ' statement
(progn (goto-char (point-min))
(if (re-search-forward "^[ \t]*package[ \t]+[a-z0-9_\\.]+[ \t]*;" class-start 't)
(progn (forward-line 1) (beginning-of-line)(newline)
(dolist (ele class-items)
(insert (concat "import "
(car (ajc-split-pkg-item-by-pkg-ln (nth 1 ele )))
"." (car ele) ";\n"))))
(progn ;;if hasn't found 'import' and 'package' then insert at head of buffer
(goto-char (point-min))
(dolist (ele class-items)
(insert (concat "import "
(car (ajc-split-pkg-item-by-pkg-ln (nth 1 ele )))
"." (car ele) ";\n")))))))
)))))
(defun ajc-find-out-import-line ()
"make a regex to match the packages in the import statements ,
return a list of each line string (exclude keyword 'import') "
(let ((imported-lines))
(save-match-data (save-excursion
(goto-char (point-min))
(setq case-fold-search nil)
(let ((class-start (save-excursion
(re-search-forward
"\\(\\b\\(class\\|interface\\)[ \t]+[a-zA-Z0-9_]+[\n \t]*\\({\\|extends\\|implements\\|<\\)\\)" nil 't))))
(if class-start ;;if found class or interface key words ,then this is a java file ,if not it is a jsp file
(while (re-search-forward "^[ \t]*import[ \t]+\\([a-zA-Z0-9_\\.\\*]+\\)[ \t]*;" class-start 't)
(add-to-list 'imported-lines (match-string-no-properties 1))
(end-of-line))
;;may be this is a jsp file
(while (re-search-forward "\\bimport=\"\\(.*?\\)[ \t]*\"[ \t]+" (point-max) 't)
(setq imported-lines (append imported-lines (split-string (match-string-no-properties 1) "[ \t,]" t)))
(end-of-line))))))
imported-lines ))
(defun ajc-caculate-all-imported-class-items (&optional exclude_java_lang)
"find out all imported class ,default include class in java.lang.*"
(let ((imported-line (ajc-find-out-import-line))(element)(index) (return-class-items))
(setq case-fold-search nil)
(dolist ( element imported-line )
(setq index (string-match "\\.\\*$" element))
(if index ;;import a package
(setq return-class-items (append return-class-items
(ajc-find-out-matched-class-item (substring-no-properties element 0 index) nil)))
(progn ;;import a class