0
這是我的代碼的一部分來計算java文件中不同行的數量。在大多數情況下,這個代碼可以得到正確的number.But如果註釋行是這樣的:如何計算java文件中的註釋行數?
/* .......
* .......
*/
它將把該塊,作爲僅有的兩條線路
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
看看[plyj](https://github.com/musiKk/plyj) – Selcuk