`
ezzze
  • 浏览: 41469 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

FileTest

阅读更多
/**
 * @author ezzze
 * @version 0.009 2009-7-16
 */
public class FileTest{
	
	
	def isAuthLine(String str){
		return (!str.isEmpty()&&
				!str.startsWith('private')&&
				!str.startsWith('import')&&
				!str.startsWith('package')&&
				!str.startsWith('/*')&&
				!str.startsWith('*') &&
				!str.startsWith('this')
                        )
		
	}
	def cleanThem = { 
		fileName->
		new File('src/').eachFileMatch( ~"$fileName.*txt" ) { f ->
			f.delete()
		}
	}
	
	def createFile(String path,String fileName){
		def tmp = File.createTempFile('Tem', '.txt',new File('D:\\workSpace\\groovy\\src\\'))
		boolean flag = false
		new File(path,fileName).eachLine(){ line->
			line = line.trim();
			if(isAuthLine(line) &&
			line.indexOf("{")<0
			){
				if(line.startsWith("public") 
				&& line.indexOf('extends')>0){
					flag = true
					return
					
				}
				
				String[] dd = line.split('\\(')
				if(dd.length > 1){
					if(dd[1].indexOf(';') > 0){
						flag = false
					}
					
					tmp.append('/** ' +dd[0] + ' ' + dd[1].substring(1,dd[1].length() -3) + ' */\n')
					tmp.append(line)
					tmp.append('\n')
				}else{
					tmp.append(line)
					tmp.append('\n')
					
				}
				
			}
			else{
				if(flag){
					
					
					tmp.append('\n')
				}else{
					
					
					tmp.append(line)
					tmp.append('\n')
				}
			}
			
			
		}
		
		
	}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics