/* * Created on Jan 4, 2005 */ package fr.lifl.stc.stan.tools; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Collection; import java.util.Iterator; import fr.lifl.stc.stan.signature.PartialSignature; import fr.lifl.stc.stan.signature.Signature; import fr.lifl.stc.stan.signature.SignatureDictionary; import gnu.getopt.Getopt; import gnu.getopt.LongOpt; /** * @author yann */ public class HandAnnoter { private static String meth = null; private static SignatureDictionary dict = null; private static String annot = null; private static String value = null; public static void edit(Signature sign) { Collection s = sign.getPartialSignatures(); Iterator it = s.iterator(); while (it.hasNext()) { PartialSignature ps = it.next(); if(ps.getClassId().indexOf(annot) != -1) { ps.getComponent().setData(value); break; } } } private static void printHelp() { System.out.println("-h/--help : print this help"); System.out.println("-d/--dictionary : use as dictionary"); System.out.println("-m/--method : set annotation for this method"); } public static void main(String[] args) { int c; LongOpt[] longopts = new LongOpt[5]; 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'); longopts[3] = new LongOpt("annotation", LongOpt.REQUIRED_ARGUMENT, null, 'a'); longopts[4] = new LongOpt("value", LongOpt.REQUIRED_ARGUMENT, null, 'v'); Getopt g = new Getopt("Displayer", args, "-:hd:m:a:v: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 'a': annot = g.getOptarg(); break; case 'v': value = 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"); System.exit(1); } if (meth == null) { System.err.println("You must provide a method"); System.exit(1); } if (annot == null) { System.err.println("You must provide an annotation"); System.exit(1); } if (value == null) { System.err.println("You must provide a value"); System.exit(1); } Signature sign = dict.findSignature(meth,true); if (sign == null) { System.err.println("Error: no such method \"" + meth + "\"in dictionary"); System.exit(1); } edit(sign); dict.putSignatureForcively(meth,sign, true); dict.dump(); } catch (ClassNotFoundException e) { System.err.println("Error: Dictionary contains unknown classes"); System.exit(1); } catch (FileNotFoundException e) { System.err.println("Error: Dictionary file not found"); System.exit(1); } catch (IOException e) { System.err.println("Error: IO error"); System.exit(1); } } }