在学习spring的时候看到很多注解,看完就忘记了,自己平时又不注重做笔记,想系统的理解一下各个注解的大概含义,How can I do ?
闲来无事一不做二不休,用Python去找出源码中所有的注解吧,不过排除非spring注解的方式确实有点low
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os,re
filePath = "D:\****"
fileType = {".java"}
outputRoot = "D:\\result.txt"
#非spring注解集合
filter={"Setter","Getter","since","author","param","return","Override","ToString"}
def run(filePath):
result = set()
search(filePath,result)
#写入到txt文本中
writeFile(outputRoot,result)
def search(filePath,result):
lists= os.listdir(filePath)
for i in range(0,len(lists)):
rootPath = os.path.join(filePath,lists[i])
if os.path.isfile(rootPath):
ofile=os.path.splitext(lists[i])
filename,otype=ofile
if otype in fileType:
for line in open(rootPath):
pattern=re.compile("@([a-zA-Z]*)",re.IGNORECASE | re.M)
res=pattern.search(line)
if res:
value = res.group(1)
if value not in filter:
result.add(value)
#文件名称
#print(filename)
#文件类型
#print(otype)
if os.path.isdir(rootPath):
#递归遍历
search(rootPath,result)
#print rootPath
def writeFile(rootPath,data):
if os.path.exists(rootPath):
os.remove(rootPath)
#a+追加读写,文件不存在就创建
#可读可写,文件不存在就创建
f=file(rootPath,"a+")
print "file write start"
for item in data:
f.write(item+'\r\n')
print item
print "file write finish"
f.close()
if __name__ == '__main__' :
run(filePath);