2 * JavaInspect - Utility to visualize java software
3 * Copyright (C) 2013-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 3 of the GNU Lesser General Public License
7 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.inspector.java.methods;
13 import java.io.IOException;
14 import java.util.ArrayList;
15 import java.util.HashMap;
16 import java.util.List;
19 import eu.svjatoslav.commons.file.FilePathParser;
20 import eu.svjatoslav.commons.string.tokenizer.InvalidSyntaxException;
22 public class ProjectScanner {
24 private final File scanPath;
26 Map<File, Project> projects = new HashMap<File, Project>();
27 public List<JavaFile> javaFiles = new ArrayList<JavaFile>();
29 public ProjectScanner(final File projectPath) {
30 scanPath = projectPath;
34 public List<Clazz> getAllClasses() {
35 final List<Clazz> result = new ArrayList<Clazz>();
37 for (final JavaFile file : javaFiles)
38 for (final Clazz clazz : file.classes)
46 if (!scanPath.exists())
47 System.out.println("Path not found: " + scanPath);
49 if (!scanPath.canRead())
50 System.out.println("Cannot read path: " + scanPath);
52 if (scanPath.isDirectory())
53 parseDirectory(scanPath);
55 if (scanPath.isFile())
59 public void parseDirectory(final File file) {
61 for (final File subFile : file.listFiles()) {
66 if (subFile.isDirectory())
67 parseDirectory(subFile);
71 public void parseFile(final File file) {
72 final String fileExtension = FilePathParser.getFileExtension(file);
73 if ("java".equalsIgnoreCase(fileExtension))
75 final JavaFile javaFile = new JavaFile(file);
76 javaFiles.add(javaFile);
77 } catch (final IOException e) {
78 System.out.println("Error parsing file: " + file.toString()
79 + ": " + e.toString());
80 } catch (final InvalidSyntaxException e) {
81 System.out.println("Syntax error occured while parsing file: "
82 + file.toString() + ": " + e.toString());