Less buggy regex
This commit is contained in:
@@ -4,7 +4,7 @@ import org.lumijiez.util.Utils;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class CodeFile extends Document{
|
||||
public class CodeFile extends Document {
|
||||
public CodeFile(Path path) {
|
||||
super(path);
|
||||
}
|
||||
|
||||
@@ -87,6 +87,12 @@ public class Document extends File implements IDocument {
|
||||
|
||||
@Override
|
||||
public String getInfo() {
|
||||
return "Name: " + getName() + " Size: " + getFilesizeKB() + "Type: " + getFileType().getTypeName();
|
||||
StringBuilder info = new StringBuilder();
|
||||
info.append("Type: ").append(getFileType().getTypeName()).append("<br>");
|
||||
info.append("Extension: ").append(getExtension().toUpperCase()).append("<br>");
|
||||
info.append("File size: ").append(getFilesizeKB()).append(" KB").append("<br>");
|
||||
info.append("Created at: ").append(getCreatedTime()).append("<br>");
|
||||
info.append("Modified at: ").append(getModificationTime()).append("<br>");
|
||||
return info.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.lumijiez.enums;
|
||||
|
||||
public enum DiffType {
|
||||
CREATE(StateType.NEW), DELETE(StateType.DELETED), MODIFY(StateType.MODIFIED), NONE(StateType.NONE);
|
||||
|
||||
private final StateType type;
|
||||
|
||||
DiffType(StateType type) {
|
||||
|
||||
@@ -71,12 +71,10 @@ public class TrackerThread extends Thread {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void checkDirectory() {
|
||||
Map<DiffType, ArrayList<Document>> result = FileDiffer.diff(fileContents, FileDiffer.crawlDirectory(MainFrame.FOLDER_PATH));
|
||||
Map<DiffType, ArrayList<Document>> result = FileDiffer.diff(fileContents, FileDiffer.crawlDirectory(MainFrame.FOLDER_PATH.toFile()));
|
||||
|
||||
StringBuilder toShow = new StringBuilder();
|
||||
|
||||
boolean somethingNew = false;
|
||||
|
||||
for (DiffType type : result.keySet()) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.lumijiez.util;
|
||||
import org.lumijiez.base.Document;
|
||||
import org.lumijiez.enums.DiffType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -56,4 +57,23 @@ public class FileDiffer {
|
||||
}
|
||||
return newFileContents;
|
||||
}
|
||||
|
||||
public static Map<Document, byte[]> crawlDirectory(File file) {
|
||||
Map<Document, byte[]> newFileContents = new HashMap<>();
|
||||
try (Stream<Path> paths = Files.walk(file.toPath())) {
|
||||
paths.forEach(p -> {
|
||||
Document doc = new Document(p);
|
||||
if (Files.isRegularFile(doc.toPath())) {
|
||||
try {
|
||||
newFileContents.put(doc, Files.readAllBytes(doc.toPath()));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return newFileContents;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,45 +48,44 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static int countClasses(Document doc) {
|
||||
try {
|
||||
int classCount = 0;
|
||||
int classCount = 0;
|
||||
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(doc));
|
||||
String line;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.contains("class ")) {
|
||||
if (line.matches(".*class\\s+\\w+.*") || line.matches(".*def\\s+\\w+.*")) {
|
||||
classCount++;
|
||||
}
|
||||
}
|
||||
|
||||
reader.close();
|
||||
return classCount;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
|
||||
return classCount;
|
||||
}
|
||||
|
||||
public static int countMethods(Document doc) {
|
||||
try {
|
||||
int methodCount = 0;
|
||||
int methodCount = 0;
|
||||
|
||||
try {
|
||||
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 ")) {
|
||||
if (line.matches(".*def\\s+\\w+.*") || line.matches(".*\\b(public|private|protected)?\\s+(static\\s+)?\\w+\\s+\\w+\\(.*\\)\\s*\\{.*")) {
|
||||
methodCount++;
|
||||
}
|
||||
}
|
||||
|
||||
reader.close();
|
||||
return methodCount;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
|
||||
return methodCount;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user