Class/method counter, kind of buggy, unpleased
This commit is contained in:
@@ -16,6 +16,8 @@ public class CodeFile extends Document{
|
||||
info.append("Extension: ").append(getExtension().toUpperCase()).append("<br>");
|
||||
info.append("File size: ").append(getFilesizeKB()).append(" KB").append("<br>");
|
||||
info.append("Lines: ").append(Utils.countLines(this)).append("<br>");
|
||||
info.append("Classes: ").append(Utils.countClasses(this)).append("<br>");
|
||||
info.append("Methods: ").append(Utils.countMethods(this)).append("<br>");
|
||||
info.append("Created at: ").append(getCreatedTime()).append("<br>");
|
||||
info.append("Modified at: ").append(getModificationTime()).append("<br>");
|
||||
return info.toString();
|
||||
|
||||
@@ -45,7 +45,48 @@ public class Utils {
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static int countClasses(Document doc) {
|
||||
try {
|
||||
int classCount = 0;
|
||||
|
||||
BufferedReader reader = new BufferedReader(new FileReader(doc));
|
||||
String line;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.contains("class ")) {
|
||||
classCount++;
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
return classCount;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int countMethods(Document doc) {
|
||||
try {
|
||||
int methodCount = 0;
|
||||
|
||||
BufferedReader reader = new BufferedReader(new FileReader(doc));
|
||||
String line;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.matches(".*\\b\\w+\\s+\\w+\\(.*\\)\\s*\\{.*")) {
|
||||
methodCount++;
|
||||
} else if (line.contains("def ")) {
|
||||
methodCount++;
|
||||
}
|
||||
}
|
||||
|
||||
reader.close();
|
||||
return methodCount;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user