-
Notifications
You must be signed in to change notification settings - Fork 56
Class FindClassFile
Ori Roth edited this page Apr 2, 2017
·
3 revisions
public class FindClassFile {
/*
* Forge (1)
*/
FindClassFile();
/*
* Utilities (1)
*/
static void main(String[] args);
/*
* Nested types (1)
*/
static class Searcher implements Action { ... }
}
public static class FindClassFile.Searcher implements Action {
/*
* Forge (1)
*/
Searcher(String sought);
/*
* Type (5)
*/
void visitDirectory(File f);
void visitFile(File f) throws StopTraversal;
void visitZip(File f);
void visitZipEntry(String zipName, String entryName, InputStream stream) throws StopTraversal;
void visitZipDirectory(String zipName, String entryName, InputStream stream);
}
Input types: File, InputStream.
Exception types: StopTraversal.
// SSDLPedia
package il.ac.technion.cs.ssdl.files.visitors;
import static il.ac.technion.cs.ssdl.utils.DBC.unused;
import il.ac.technion.cs.ssdl.files.visitors.FileSystemVisitor.Action;
import il.ac.technion.cs.ssdl.files.visitors.FileSystemVisitor.Action.StopTraversal;
import il.ac.technion.cs.ssdl.stereotypes.Application;
import il.ac.technion.cs.ssdl.utils.Parenthesize;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
/**
* A program to search for a ".class" file in the file system.
*
* Author: Yossi Gil Mar 29, 2007
*/
@Application public class FindClassFile {
static final String name = "where";
public static void main(final String[] args) {
if (args.length == 0) {
System.err.printf("Usage: %s [ -n ] [ -f ] className [className ...]\n", name);
System.exit(1);
}
for (final String arg : args) {
if (processOption(arg))
continue;
try {
System.out.println("Searching for class: " + arg + " in " + Parenthesize.square(File.listRoots()));
new FileSystemVisitor(File.listRoots(), new Searcher("." + arg + ".class"), ".class").go();
} catch (final IOException e) {
System.err.println(e.getMessage());
continue;
} catch (final StopTraversal e) {
continue;
}
}
}
static boolean reportCounts;
static boolean findFirstOnly;
private static boolean processOption(final String option) {
if (option.equals("-n")) {
reportCounts = true;
return true;
}
if (option.equals("-f")) {
findFirstOnly = true;
return true;
}
return false;
}
/**
* An {@Action} searching for files with a given suffix, which
* counts the various kinds of file system entities it encounters during the
* search.
*
* Author: Yossi Gil @since 21/05/2007
*/
public static class Searcher implements Action {
private final String sought;
public Searcher(final String sought) {
this.sought = sought;
}
public void visitDirectory(final File f) {
directories++;
report("Directory: " + f.getAbsolutePath());
}
public void visitFile(final File f) throws StopTraversal {
files++;
report("File: " + f.getAbsolutePath());
check(f.getName(), f.getAbsolutePath());
}
public void visitZip(final File f) {
zips++;
report("Archive: " + f.getAbsolutePath());
}
public void visitZipEntry(final String zipName, final String entryName, final InputStream stream) throws StopTraversal {
unused(stream);
entries++;
report("Archive entry: " + entryName);
check(entryName, zipName);
}
private void check(final String file, final String directory) throws StopTraversal {
if (!file.endsWith(sought))
return;
System.out.printf("%s: %s\n", file, directory);
if (FindClassFile.findFirstOnly)
throw new StopTraversal();
}
public void visitZipDirectory(final String zipName, final String entryName, final InputStream stream) {
unused(stream);
report("Archive directory: " + entryName + " in zip " + zipName);
}
private void report(final String s) {
if (FindClassFile.reportCounts)
System.out.println(s + ". " + directories + " directories, " + files + " class files, " + zips + " ZIP archives, "
+ entries + " entries.");
}
private int directories = 0;
private int files = 0;
private int zips = 0;
private int entries = 0;
}
}
Metric | Value | Acronym | Explanation |
---|---|---|---|
LOC | 119 | Lines Of Code | Total number of lines in the code |
SCC | 48 | SemiColons Count | Total number of semicolon tokens found in the code. |
NOT | 654 | Number Of Tokens | Comments, whitespace and text which cannot be made into a token not included. |
VCC | 2758 | Visible Characters Count | The total number of non-white (i.e., not space, tab, newline, carriage return, form feed) characters. |
CCC | 2444 | Code Characters Count | Total number of non-white characters in tokens. White space characters in string and character literals are not counted. |
UIC | 66 | Unique Identifiers Count | The number of different identifiers found in the code |
WHC | 6 | Weighted Horizontal Complexity | A heuritistic on horizontal complexity |
Statitic | Value |
---|---|
Average token length | 3.7 |
Tokens/line | 5.5 |
Visible characters/line | 23 |
Code characters/line | 21 |
Semicolons/tokens | 7% |
Comment text percentage | 11% |
Token Kind | Occurrences |
---|---|
KEYWORD | 102 |
OPERATOR | 35 |
LITERAL | 27 |
ID | 209 |
PUNCTUATION | 281 |
COMMENT | 3 |
OTHER | 301 |