2014-03-27 3 views
0

이것은 자바 파일의 다른 줄 수를 계산하는 코드의 일부입니다. 대부분의 경우,이 코드는 권리를 얻을 수 number.But 주석 라인 같은 경우 :자바 파일에서 주석 행을 계산하는 방법은 무엇입니까?

/* .......

* .......

*/

단지 두 줄

 for eachLine in allLines: 
      if eachLine != " " : 
       eachLine = eachLine.replace(" ",""); #remove space 
       eachLine = self.trim(eachLine);  #remove tabIndent 
       if (iscomment==False): 
        if(eachLine.strip().startswith("//")): #LINECOMMENT 
         commentCount += 1; 
        if eachLine == "": 
         blankCount += 1; 
        if(eachLine.strip().startswith("/*")): 
         commentCount += 1; 
         if(not eachLine.strip().endswith("*/")): 
          iscomment=True 
       else : 
        commentCount += 1; 
        if(eachLine.find("*/")): 
         iscomment=False 
      lineCount = lineCount + 1; 
     codeCount=lineCount-commentCount-blankCount 
+0

[plyj] (https://github.com/musiKk/plyj) – Selcuk

답변

0
if(eachLine.find("*/")): 

-1을 리턴 실패 거짓하지이 블록을 생각한다. 내 아주 간단한 프로젝트를 시도,

import re 

comments = re.findall('#.*?\n', allLines) 
for item in re.findall('/\*.?*\*/', allLines): 
    for row in item.split('\n'): 
     comments.append(row) 
print(len(comments)) 

혼자 뭔가 이것의 라인과 라인의 적절한 액수를 가져 나타납니다

http://docs.python.org/2/library/string.html

관련 문제