/* * Created on Jan 5, 2005 */ package fr.lifl.stc.stan.tools; import fr.lifl.stc.stan.signature.Signature; import fr.lifl.stc.stan.signature.SignatureDictionary; import gnu.getopt.Getopt; import gnu.getopt.LongOpt; /** * @author yann * * Displays annotations for a method in a given dictionary, otr displays the entire dictionary if no method is specified. */ public class Displayer { private static String meth = null; private static SignatureDictionary dict = null; public static void display(Signature sign) { System.out.println(sign.toString()); /*Collection c = sign.getPartialSignatures(); Iterator it = c.iterator(); while (it.hasNext()) { PartialSignature element = (PartialSignature) it.next(); System.out.println(sign); //element.display(System.out); } */ } private static void printHelp() { System.out.println("Usage : if_displayDico "); System.out.println("where possible options include: "); System.out.println("-h/--help : print this help"); System.out.println("-d/--dictionary : use as dictionary"); System.out.println("-m/--method : display annotations for . If not set, display dictionary index."); } public static void main(String[] args) { int c; LongOpt[] longopts = new LongOpt[3]; longopts[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h'); longopts[1] = new LongOpt("dictionary", LongOpt.REQUIRED_ARGUMENT, null, 'd'); longopts[2] = new LongOpt("method", LongOpt.REQUIRED_ARGUMENT, null, 'm'); Getopt g = new Getopt("Displayer", args, "-:hd:m:W;", longopts); try { while ((c = g.getopt()) != -1) switch (c) { case 'h': printHelp(); System.exit(0); break; case 'd': dict = new SignatureDictionary(g.getOptarg()); break; case 'm': meth = g.getOptarg(); break; case 'W': System.out.println("You tried a -W with an incorrect long option name"); break; case ':': System.out.println("You need an argument for option " + (char) g.getOptopt()); break; case '?': System.out.println("The option '" + (char) g.getOptopt() + "' is not valid"); break; default: System.out.println("getopt(): unknown option " + c); //break; } if (dict == null) { System.err.println("You must provide a dictionary"); printHelp(); System.exit(1); } if (meth != null) { Signature sign = dict.findSignature(meth, true); if (sign == null) { System.err.println("Error: no such method \"" + meth + "\" in dictionary"); System.exit(1); } display(sign); } else { System.out.println("global"); String[] index = dict.getIndex(); for (int i = 0; i < index.length; i++) { System.out.println(index[i]); Signature sign = dict.findGlobalSignature(index[i]); if (sign == null) { System.err.println("Error: no such method \"" + meth + "\" in dictionary"); System.exit(1); } display(sign); } System.out.println("exact"); index = dict.getExactIndex(); for (int i = 0; i < index.length; i++) { System.out.println(index[i]); Signature sign = dict.findExactSignature(index[i]); if (sign == null) { System.err.println("Error: no such method \"" + meth + "\" in dictionary"); System.exit(1); } display(sign); } } } catch (ClassNotFoundException e) { System.err.println("Error: Dictionary contains unknown classes"); System.exit(1); } } }