Initial commit from SVN.

This commit is contained in:
wcrisman
2014-05-30 10:31:51 -07:00
commit b45e56b890
1968 changed files with 370949 additions and 0 deletions

7
Line Count/.classpath Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/Application Foundation"/>
<classpathentry kind="output" path="bin"/>
</classpath>

17
Line Count/.project Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Line Count</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

154
Line Count/src/Main.java Normal file
View File

@@ -0,0 +1,154 @@
/*
* Copyright (c) 2008,2009 Declarative Engineering LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Declarative Engineering LLC
* verson 1 which accompanies this distribution, and is available at
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
*/
import java.io.File;
import java.io.FileInputStream;
import java.text.DateFormat;
import java.util.Date;
import com.common.debug.Debug;
import com.common.io.StreamSupport;
/**
* A simple utility that searches all java files in the current directory and all subdirectories to generate statistics.
*/
public class Main {
private int totalLineCharacterCount = 0;
private int totalLineCount = 0;
private int totalCommentCharacterCount = 0;
private int totalCommentCount = 0;
private int totalFileCount = 0;
private int totalClassCount = 0;
private int totalInterfaceCount = 0;
/**
* Starts the utility - no parameters are expected.
* @param args
*/
public static void main(String[] args) {
new Main().start();
// Date date = new Date(1246423640000L);
// DateFormat format = DateFormat.getDateTimeInstance();
//
// System.out.println(format.format(date));
}//main()//
/**
* Starts the processing of files and then outputs the results.
*/
private void start() {
File file = new File(".");
processFile(file);
Debug.log("Total File Count: " + totalFileCount);
Debug.log("Total Class Count: " + totalClassCount);
Debug.log("Total Interface Count: " + totalInterfaceCount);
Debug.log("Total Line Count: " + totalLineCount);
Debug.log("Total Line Character Count: " + totalLineCharacterCount);
Debug.log("Total Comment Count: " + totalCommentCount);
Debug.log("Total Comment Character Count: " + totalCommentCharacterCount);
}//start()//
/**
* Processes files recursively looking for java files.
* @param file The file to search.
*/
private void processFile(File file) {
if(file.isDirectory()) {
File[] files = file.listFiles();
for(int index = 0; index < files.length; index++) {
processFile(files[index]);
}//for//
}//if//
else {
String fileName = file.getName();
if((fileName.length() > 5) && (fileName.substring(fileName.length() - 5).equalsIgnoreCase(".java"))) {
processJavaFile(file);
}//if//
}//else//
}//processFile()//
/**
* Processes a java file to extract statistics.
* <p>TODO: Don't just count semi-colons - loop beginnings should count as one line (versus none or several) and loop endings should tie to the loop beginnings.
* @param file The java file.
*/
private void processJavaFile(File file) {
try {
FileInputStream fin = new FileInputStream(file);
String contents = StreamSupport.readString(fin, "UTF8", (int) file.length());
int contentsIndex = 0;
int lineCharacterCount = 0;
int lineCount = 0;
while(contentsIndex != -1 && contentsIndex < contents.length()) {
char next = contents.charAt(contentsIndex);
if((next == '/') && (contentsIndex + 1 < contents.length()) && (contents.charAt(contentsIndex + 1) == '*')) {
int endIndex = contents.indexOf("*/", contentsIndex + 2);
if(endIndex == -1) {
endIndex = contents.length();
}//if//
recordComment(contents.substring(contentsIndex + 2, endIndex));
contentsIndex = endIndex + 2;
}//if//
else if((next == '/') && (contentsIndex + 1 < contents.length()) && (contents.charAt(contentsIndex + 1) == '/')) {
int endIndex = contents.indexOf('\n', contentsIndex + 2);
if(endIndex == -1) {
endIndex = contents.length();
}//if//
recordComment(contents.substring(contentsIndex + 2, endIndex));
contentsIndex = endIndex + 1;
}//else if//
else {
if((next == 'c') && (contentsIndex + 6 < contents.length()) && (contents.charAt(contentsIndex + 1) == 'l') && (contents.charAt(contentsIndex + 2) == 'a') && (contents.charAt(contentsIndex + 3) == 's') && (contents.charAt(contentsIndex + 4) == 's') && (Character.isSpaceChar(contents.charAt(contentsIndex + 5)))) {
totalClassCount++;
}//if//
else if((next == 'i') && (contentsIndex + 9 < contents.length()) && (contents.charAt(contentsIndex + 1) == 'n') && (contents.charAt(contentsIndex + 2) == 't') && (contents.charAt(contentsIndex + 3) == 'e') && (contents.charAt(contentsIndex + 4) == 'r') && (contents.charAt(contentsIndex + 5) == 'f') && (contents.charAt(contentsIndex + 6) == 'a') && (contents.charAt(contentsIndex + 7) == 'c') && (contents.charAt(contentsIndex + 8) == 'e') && (Character.isSpaceChar(contents.charAt(contentsIndex + 9)))) {
totalInterfaceCount++;
}//else if//
if(!Character.isSpaceChar(next)) {
lineCharacterCount++;
if(next == ';') {
lineCount++;
}//if//
}//if//
}//else//
contentsIndex++;
}//while//
totalLineCharacterCount += lineCharacterCount;
totalLineCount += lineCount;
totalFileCount++;
}//try//
catch(Throwable e) {
Debug.log(e);
System.exit(1);
}//catch//
}//processJavaFile()//
/**
* Records statistics on each comment.
* @param comment The comment text.
*/
private void recordComment(String comment) {
int characterCount = 0;
for(int index = 0; index < comment.length(); index++) {
if(!Character.isSpaceChar(comment.charAt(index))) {
characterCount++;
}//if//
}//for//
totalCommentCharacterCount += characterCount;
totalCommentCount++;
}//recordComment()//
}//Main//