001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.dependencyfinder.cli;
034:
035: import java.io.*;
036: import java.util.*;
037:
038: import com.jeantessier.classreader.*;
039: import com.jeantessier.commandline.*;
040:
041: public class ListSymbols extends Command {
042: public ListSymbols() throws CommandLineException {
043: super ("ListSymbols");
044: }
045:
046: protected void showSpecificUsage(PrintStream out) {
047: out.println();
048: out
049: .println("If no files are specified, it processes the current directory.");
050: out.println();
051: }
052:
053: protected void populateCommandLineSwitches() {
054: super .populateCommandLineSwitches();
055:
056: getCommandLine().addToggleSwitch("class-names");
057: getCommandLine().addToggleSwitch("field-names");
058: getCommandLine().addToggleSwitch("method-names");
059: getCommandLine().addToggleSwitch("local-names");
060: }
061:
062: protected Collection<CommandLineException> parseCommandLine(
063: String[] args) {
064: Collection<CommandLineException> exceptions = super
065: .parseCommandLine(args);
066:
067: if (!getCommandLine().isPresent("class-names")
068: && !getCommandLine().isPresent("field-names")
069: && !getCommandLine().isPresent("method-names")
070: && !getCommandLine().isPresent("local-names")) {
071: getCommandLine().getSwitch("class-names").setValue(true);
072: getCommandLine().getSwitch("field-names").setValue(true);
073: getCommandLine().getSwitch("method-names").setValue(true);
074: getCommandLine().getSwitch("local-names").setValue(true);
075: }
076:
077: return exceptions;
078: }
079:
080: protected void doProcessing() throws Exception {
081: List<String> parameters = getCommandLine().getParameters();
082: if (parameters.size() == 0) {
083: parameters.add(".");
084: }
085:
086: SymbolGatherer collector = new SymbolGatherer();
087: collector.setCollectingClassNames(getCommandLine()
088: .getToggleSwitch("class-names"));
089: collector.setCollectingFieldNames(getCommandLine()
090: .getToggleSwitch("field-names"));
091: collector.setCollectingMethodNames(getCommandLine()
092: .getToggleSwitch("method-names"));
093: collector.setCollectingLocalNames(getCommandLine()
094: .getToggleSwitch("local-names"));
095:
096: ClassfileLoader loader = new TransientClassfileLoader();
097: loader
098: .addLoadListener(new LoadListenerVisitorAdapter(
099: collector));
100: loader.addLoadListener(getVerboseListener());
101: loader.load(parameters);
102:
103: for (String symbol : collector.getCollection()) {
104: out.println(symbol);
105: }
106: }
107:
108: public static void main(String[] args) throws Exception {
109: new ListSymbols().run(args);
110: }
111: }
|