クロスリファレンス情報を取得してみる
戻る
ChildrenViewer.java (creates/uses)
├CookieContainer
├DGUtils
└DataGatherer
is created or used by:
TreeContainer.java
/***/ actual line count of source code = 110
ConnectionPropertySetter.java (creates/uses)
/* NOTHING */
is created or used by:
DataGatherer.java
/***/ actual line count of source code = 15
ContentStringWriter.java (creates/uses)
└DGUtils
is created or used by:
LocalFileWriterFactory.java
/***/ actual line count of source code = 45
CookieContainer.java (creates/uses)
/* NOTHING */
is created or used by:
ChildrenViewer.java
DataGatherer.java
RecursiveCrawler.java
ResponseBodyTransmitter.java
RobotsTxtParser.java
TreeContainer.java
/***/ actual line count of source code = 73
DGUtils.java (creates/uses)
/* NOTHING */
is created or used by:
ChildrenViewer.java
ContentStringWriter.java
DataGatherer.java
HashedFileNamingContentWriter.java
HyperLinkURLExtractor.java
RecursiveCrawler.java
ResponseBodyTransmitter.java
SamariumizedFileNamingContentWriter.java
StatisticsDumper.java
TreeContainer.java
/***/ actual line count of source code = 257
DataGatherer.java (creates/uses)
├ConnectionPropertySetter
├CookieContainer
├DGUtils
├DataGathererExecuteException
├HyperLinkURLExtractor
├LinkExtractor
├PropertiesHashMap
├PropertiesHashMapNullPointerException
├PropertiesManager
├ResponseHeader
├SystemPropertySetter
└TagEraser
is created or used by:
ChildrenViewer.java
RecursiveCrawler.java
ResponseBodyTransmitter.java
RobotsTxtParser.java
/***/ actual line count of source code = 349
DataGathererExecuteException.java (creates/uses)
/* NOTHING */
is created or used by:
DataGatherer.java
/***/ actual line count of source code = 13
Gatherer.java (creates/uses)
/* NOTHING */
/***/ actual line count of source code = 15
HashedFileNamingContentWriter.java (creates/uses)
└DGUtils
is created or used by:
LocalFileWriterFactory.java
/***/ actual line count of source code = 67
HyperLinkURLExtractor.java (creates/uses)
└DGUtils
is created or used by:
DataGatherer.java
/***/ actual line count of source code = 29
Junk.java (creates/uses)
/* NOTHING */
/***/ actual line count of source code = 43
Label.java (creates/uses)
/* NOTHING */
is created or used by:
LabelList.java
/***/ actual line count of source code = 22
LabelList.java (creates/uses)
├Label
├ReverseParentage
└XMLEscaper
is created or used by:
RecursiveCrawler.java
/***/ actual line count of source code = 105
LinkExtractor.java (creates/uses)
/* NOTHING */
is created or used by:
DataGatherer.java
/***/ actual line count of source code = 62
LocalFileWriter.java (creates/uses)
/* NOTHING */
/***/ actual line count of source code = 7
LocalFileWriterFactory.java (creates/uses)
├ContentStringWriter
├HashedFileNamingContentWriter
└SamariumizedFileNamingContentWriter
is created or used by:
RecursiveCrawler.java
/***/ actual line count of source code = 20
PatternMatcher.java (creates/uses)
/* NOTHING */
is created or used by:
RecursiveCrawler.java
/***/ actual line count of source code = 28
PropertiesHashMap.java (creates/uses)
└PropertiesManager
is created or used by:
DataGatherer.java
/***/ actual line count of source code = 43
PropertiesHashMapNullPointerException.java (creates/uses)
/* NOTHING */
is created or used by:
DataGatherer.java
/***/ actual line count of source code = 6
PropertiesManager.java (creates/uses)
└PropertiesManagerLoadException
is created or used by:
DataGatherer.java
PropertiesHashMap.java
/***/ actual line count of source code = 59
PropertiesManagerLoadException.java (creates/uses)
/* NOTHING */
is created or used by:
PropertiesManager.java
/***/ actual line count of source code = 6
RecursiveCrawler.java (creates/uses)
├CookieContainer
├DGUtils
├DataGatherer
├LabelList
├LocalFileWriterFactory
├PatternMatcher
├RecursiveCrawlerPropertiesLoadException
├RecursiveCrawlerPropertiesNullException
├RobotsTxtChecker
├StatisticsDumper
└SummaryInfo
/***/ actual line count of source code = 296
RecursiveCrawlerPropertiesLoadException.java (creates/uses)
/* NOTHING */
is created or used by:
RecursiveCrawler.java
/***/ actual line count of source code = 6
RecursiveCrawlerPropertiesNullException.java (creates/uses)
/* NOTHING */
is created or used by:
RecursiveCrawler.java
/***/ actual line count of source code = 6
ResponseBodyTransmitter.java (creates/uses)
├CookieContainer
├DGUtils
└DataGatherer
/***/ actual line count of source code = 104
ResponseHeader.java (creates/uses)
/* NOTHING */
is created or used by:
DataGatherer.java
/***/ actual line count of source code = 18
ReverseParentage.java (creates/uses)
/* NOTHING */
is created or used by:
LabelList.java
/***/ actual line count of source code = 7
RobotsTxtChecker.java (creates/uses)
└RobotsTxtParser
is created or used by:
RecursiveCrawler.java
/***/ actual line count of source code = 53
RobotsTxtParser.java (creates/uses)
├CookieContainer
└DataGatherer
is created or used by:
RobotsTxtChecker.java
/***/ actual line count of source code = 97
Samarium.java (creates/uses)
└SamariumUnsupportedCharacterException
is created or used by:
SamariumizedFileNamingContentWriter.java
/***/ actual line count of source code = 79
SamariumUnsupportedCharacterException.java (creates/uses)
/* NOTHING */
is created or used by:
Samarium.java
/***/ actual line count of source code = 6
SamariumizedFileNamingContentWriter.java (creates/uses)
├DGUtils
└Samarium
is created or used by:
LocalFileWriterFactory.java
/***/ actual line count of source code = 69
StatisticsDumper.java (creates/uses)
└DGUtils
is created or used by:
RecursiveCrawler.java
/***/ actual line count of source code = 69
SummaryInfo.java (creates/uses)
/* NOTHING */
is created or used by:
RecursiveCrawler.java
/***/ actual line count of source code = 31
SystemPropertySetter.java (creates/uses)
/* NOTHING */
is created or used by:
DataGatherer.java
/***/ actual line count of source code = 9
TagEraser.java (creates/uses)
/* NOTHING */
is created or used by:
DataGatherer.java
/***/ actual line count of source code = 33
TreeContainer.java (creates/uses)
├ChildrenViewer
├CookieContainer
├DGUtils
└TreeNode
is created or used by:
TreeViewer.java
/***/ actual line count of source code = 179
TreeNode.java (creates/uses)
├TreeNodeNoChildrenException
└TreeNodeNullPointerException
is created or used by:
TreeContainer.java
/***/ actual line count of source code = 98
TreeNodeNoChildrenException.java (creates/uses)
/* NOTHING */
is created or used by:
TreeNode.java
/***/ actual line count of source code = 6
TreeNodeNullPointerException.java (creates/uses)
/* NOTHING */
is created or used by:
TreeNode.java
/***/ actual line count of source code = 12
TreeViewer.java (creates/uses)
└TreeContainer
/***/ actual line count of source code = 98
XMLEscaper.java (creates/uses)
/* NOTHING */
is created or used by:
LabelList.java
/***/ actual line count of source code = 28
XMLExtractionHelper.java (creates/uses)
/* NOTHING */
/***/ actual line count of source code = 134
import java.io.*;
import java.util.*;
import java.util.regex.*;
//--------------------------------------------------------------------------
// $Id: XrefChecker.html,v 1.1 2009/06/22 16:12:03 kishi Exp kishi $
// Description: Javaソースプログラムのコメントを削除する
//--------------------------------------------------------------------------
public class CommentEliminator {
static public String eliminateCommentOfCPP( String source ) throws Exception {
StringBuffer result = new StringBuffer();
try {
StringReader sr = new StringReader( source );
BufferedReader br = new BufferedReader( sr );
String line;
while ( ( line = br.readLine() ) != null ) {
String[] arr = line.split( "//" );
if ( arr.length > 1 ) {
result.append( arr[ 0 ] + "\n" );
} else {
result.append( line + "\n" );
}
}
sr.close();
br.close();
} catch ( Exception e ) {
throw( e );
}
return result.toString();
}
static public String eliminateCommentOfC( String source ) throws Exception {
StringBuffer result = new StringBuffer();
try {
StringReader sr = new StringReader( source );
int c;
long offset = 0;
long from = 0;
long to = 0;
ArrayList regionArray = new ArrayList();
// コメントの開始位置・終了位置を求める
// 本当は正規表現で切り出したほうがベターか?
char[] buffer = new char[ 2 ];
while ( ( c = sr.read() ) != -1 ) {
push( buffer, ( char ) c );
if ( buffer[ 0 ] == '/' && buffer[ 1 ] == '*' ) {
// System.err.println( "BEGIN ***" );
from = offset - 1;
}
if ( buffer[ 0 ] == '*' && buffer[ 1 ] == '/' ) {
// System.err.println( "*** END" );
to = offset;
// System.err.println( from + ":" + to );
Region region = new Region();
region.setFromTo( from, to );
regionArray.add( region );
}
offset++;
}
if ( regionArray.size() > 0 ) {
//先頭からもう一度読む
sr.reset();
int index = 0;
Region region = ( Region ) regionArray.get( index );
from = region.getFrom();
to = region.getTo();
boolean processingFlag = true;
offset = 0;
while ( ( c = sr.read() ) != -1 ) {
if ( offset == from ) {
processingFlag = false;
// System.err.println( "FALSE" );
}
if ( offset == to + 1 ) {
processingFlag = true;
// System.err.println( "TRUE" );
index++;
if ( index < regionArray.size() ) {
region = ( Region ) regionArray.get( index );
from = region.getFrom();
to = region.getTo();
}
}
if ( processingFlag ) {
result.append( ( char ) c );
}
offset++;
}
} else {
// コメントがない場合は処理せずに返す
result = new StringBuffer( source );
}
sr.close();
} catch ( Exception e ) {
throw( e );
}
return result.toString();
}
static public String eliminate( String in ) throws Exception {
String out = null;
try {
// Cのコメントのほうが優先される
out = CommentEliminator.eliminateCommentOfC( in );
out = CommentEliminator.eliminateCommentOfCPP( out );
} catch ( Exception e ) {
throw( e );
}
return out;
}
static public int[] getStatistics( String result ) throws Exception {
int[] arr = new int[ 2 ];
arr[ 0 ] = 0;
arr[ 1 ] = 0;
try {
StringReader sr = new StringReader( result );
BufferedReader br = new BufferedReader( sr );
String line;
int i = 0;
while ( ( line = br.readLine() ) != null ) {
// System.out.println( ( ++i ) + ": " + line );
if ( line.matches( "^\\s*$" ) ) {
// System.err.println("*** MATCHED ***");
} else {
arr[ 0 ] ++;
}
}
sr.close();
br.close();
} catch ( Exception e ) {
throw( e );
}
return arr;
}
static private void push( char[] buffer, char c ) {
buffer[ 0 ] = buffer[ 1 ];
buffer[ 1 ] = c;
}
// 単体テスト
static public void main( String[] args ) throws Exception {
if ( args.length != 1 ) {
System.err.println( "Usage: java -cp . CommentEliminator [FileName]" );
System.exit( 1 );
}
StringBuffer sb = new StringBuffer();
FileReader fr = new FileReader( args[ 0 ] );
BufferedReader br = new BufferedReader( fr );
String line;
while ( ( line = br.readLine() ) != null ) {
sb.append( line + "\n" );
}
fr.close();
br.close();
String result = null;
try {
result = CommentEliminator.eliminate( sb.toString() );
} catch ( Exception e ) {
e.printStackTrace();
}
/***************************************
System.out.println( result );
****************************************/
int[] arr = CommentEliminator.getStatistics( result );
System.out.println( "actual line count = " + arr[ 0 ] );
}
}
import java.io.*;
/**
$Id: XrefChecker.html,v 1.1 2009/06/22 16:12:03 kishi Exp kishi $
@author KISHI Yasuhiro
*/
public class ContentReader {
/** ファイルの内容を読み取り、文字列に格納する
@param target ファイル
@return 文字列
*/
static public String getContent( File target ) throws Exception {
StringBuffer sb = new StringBuffer();
// System.err.println( "in getContent(): " + target.toString() );
try {
FileReader fr = new FileReader( target );
BufferedReader br = new BufferedReader( fr );
String line;
while ( ( line = br.readLine() ) != null ) {
sb.append( line + "\n" );
}
fr.close();
br.close();
} catch ( Exception e ) {
e.printStackTrace();
} finally {
return sb.toString();
}
}
}
import java.util.*;
/**
$Id: XrefChecker.html,v 1.1 2009/06/22 16:12:03 kishi Exp kishi $
@author KISHI Yasuhiro
*/
public class FileXref {
/** 自分が使用しているプログラムのリスト **/
private ArrayList classNameList = null;
/** 自分が使用されているプログラムのSet **/
private TreeSet parentageSet = null;
private int[] statistics = null;
public ArrayList getClassNameList() {
return classNameList;
}
public TreeSet getParentageSet() {
return parentageSet;
}
public int[] getStatistics() {
return statistics;
}
public void setClassNameList( ArrayList al ) {
classNameList = al;
}
public void addParentageSet( String parentFileName ) {
if ( parentageSet == null ) {
parentageSet = new TreeSet();
}
parentageSet.add( parentFileName );
}
public void setStatistics( int[] stats ) {
statistics = stats;
}
}
// $Id: XrefChecker.html,v 1.1 2009/06/22 16:12:03 kishi Exp kishi $
public class Region {
private long from;
private long to;
public void setFromTo( long from, long to ) {
this.from = from;
this.to = to;
}
public long getFrom() {
return from;
}
public long getTo() {
return to;
}
}
import java.io.*;
import java.util.*;
import java.util.regex.*;
/**
$Id: XrefChecker.html,v 1.1 2009/06/22 16:12:03 kishi Exp kishi $
@author KISHI Yasuhiro
*/
public class XrefChecker {
/** とりあえず限定版 -- あとで引数として渡せるように変更する */
private String suffix = "java";
/** ファイルリスト */
private List fileList = null;
/** 処理対象ディレクトリ */
private String directory = null;
/** FileXrefをファイル名をキーにして格納するTreeMap */
private TreeMap tmFileXref = new TreeMap();
/** ディレクトリを設定する */
public void setDirectory( String directory ) {
this.directory = directory;
}
/** 処理対象ファイルのリストを取得する
@return リスト
*/
private List getFileList() {
if ( fileList == null ) {
fileList = new ArrayList();
}
File dir = new File( directory );
String[] files = dir.list();
Arrays.sort( files );
for ( int i = 0;i < files.length;i++ ) {
File target = new File( directory, files[ i ] );
if ( target.isDirectory() ) {
continue;
}
if ( !files[ i ].endsWith( suffix ) ) {
continue;
}
fileList.add( target );
}
return fileList;
}
/** 処理実行 */
public void doExecute() throws Exception {
fileList = getFileList();
for ( int i = 0;i < fileList.size();i++ ) {
File target = ( File ) fileList.get( i );
// このファイルがcreateあるいはuseしているファイルのリスト
ArrayList classNameList = new ArrayList();
//------------------------------------------------------------
// ソースファイルの内容をバッファにセット
//------------------------------------------------------------
String content = ContentReader.getContent( target );
try {
// コメントを削除
content = CommentEliminator.eliminate( content );
} catch ( Exception e ) {
throw( e );
}
for ( int j = 0;j < fileList.size();j++ ) {
//----------------------------------------------------------------
// ソースファイルをチェックして自身以外のクラスの名称を抽出
//----------------------------------------------------------------
if ( !target.equals( fileList.get( j ) ) ) {
File file = ( File ) fileList.get( j );
String fileName = file.getName();
String className = fileName.replaceAll( "\\." + suffix, "" );
if ( content.contains( " " + className + "(" ) || content.contains( " " + className + "." ) ) {
// System.out.println(" className=" + className + " が見つかりました!");
classNameList.add( className );
}
}
}
// 統計情報を取り出す
int[] arr = CommentEliminator.getStatistics( content );
//-------------------------
// TreeMapに格納
//-------------------------
FileXref fileXref = new FileXref();
fileXref.setClassNameList( classNameList );
fileXref.setStatistics( arr );
String targetFileName = target.getName();
tmFileXref.put( targetFileName, fileXref );
}
clarifyParentage();
}
/** 逆親子関係を求める */
private void clarifyParentage() {
Iterator iterator = tmFileXref.keySet().iterator();
while ( iterator.hasNext() ) {
String fileName = ( String ) iterator.next();
FileXref fileXref = ( FileXref ) tmFileXref.get( fileName );
ArrayList classNameList = fileXref.getClassNameList();
for ( int i = 0;i < classNameList.size(); i++ ) {
String keyFileName = ( String ) classNameList.get( i ) + "." + suffix;
// System.out.println( keyFileName + "\tis used by " + fileName );
FileXref obj = ( FileXref ) tmFileXref.get( keyFileName );
obj.addParentageSet( fileName );
}
}
}
/** ダンプする */
public void dumpAll() {
Iterator iterator = tmFileXref.keySet().iterator();
while ( iterator.hasNext() ) {
String fileName = ( String ) iterator.next();
FileXref fileXref = ( FileXref ) tmFileXref.get( fileName );
System.out.println( fileName + " (creates/uses)" );
ArrayList classNameList = fileXref.getClassNameList();
if ( classNameList.size() == 0 ) {
System.out.println( "\t/* NOTHING */" );
}
// 抽出したクラス名を表示
for ( int k = 0;k < classNameList.size(); k++ ) {
String branch;
if ( k != classNameList.size() - 1 ) {
branch = "├";
} else {
branch = "└";
}
System.out.println( "\t" + branch + classNameList.get( k ) );
}
// このクラスを利用しているファイルを一覧表示
TreeSet ts = fileXref.getParentageSet();
if ( ts != null ) {
System.out.println();
System.out.println( "\tis created or used by:" );
Iterator itrt = ts.iterator();
while ( itrt.hasNext() ) {
System.out.println( "\t\t" + itrt.next() );
}
}
// 統計情報を表示
int[] arr = fileXref.getStatistics();
System.out.println( "\n\t" + "/***/ actual line count of source code = " + arr[ 0 ] );
System.out.println();
}
}
/** MAIN METHOD */
static public void main( String[] args ) throws Exception {
if ( args.length != 1 ) {
System.err.println( "Usage: java -cp . XrefChecker [Directory]" );
System.exit( -1 );
}
XrefChecker xc = new XrefChecker();
xc.setDirectory( args[ 0 ] );
try {
xc.doExecute();
xc.dumpAll();
} catch ( Exception e ) {
throw( e );
}
}
}
戻る