/*
 * FindBugs - Find Bugs in Java programs
 * Copyright (C) 2003-2008 University of Maryland
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package edu.umd.cs.findbugs;

import java.lang.reflect.Method;

import javax.annotation.Nonnull;

/**
 * @author pugh
 */
public class FindBugsMain implements Comparable<FindBugsMain> {
    
    public FindBugsMain(Class<?> mainClass, String cmd, String description, String kind, boolean analysis) 
            throws SecurityException, NoSuchMethodException {
        this.mainClass = mainClass;
        mainMethod = mainClass.getMethod("main", String[].class);
        this.cmd = cmd;
        this.description = description;
        this.kind = kind;
        this.analysis = analysis;
    }
    final Class<?> mainClass;
    final Method mainMethod;
    public final @Nonnull String cmd;
    public final String description;
    public final @Nonnull String kind;
    final boolean analysis;
    
    public void invoke(String [] args) throws Exception {
        if (!analysis)
            FindBugs.setNoAnalysis();
        mainMethod.invoke(null, (Object) args);
    }
    public int compareTo(FindBugsMain that) {
        int result = kind.compareTo(that.kind);
        if (result != 0)
            return result;
        return cmd.compareTo(that.cmd);
                
    }
    
    @Override
    public boolean equals(Object o) {
        if (!(o instanceof FindBugsMain))
            return false;
        FindBugsMain that = (FindBugsMain) o;
        return kind.equals(that.kind)&&  cmd.equals(that.cmd);
    }
    
    @Override
    public int hashCode() {
        return kind.hashCode() + cmd.hashCode();
    }


}

@@ -935,32 +935,118 @@
 ll;%0A
-%0A/**%0A * @author pugh%0A */
+import javax.annotation.ParametersAreNonnullByDefault;%0A%0A/**%0A * @author pugh%0A */%0A@ParametersAreNonnullByDefault
 %0Apub
@@ -1106,20 +1106,16 @@
 Main%3E %7B%0A
-    
 %0A    pub
@@ -1213,17 +1213,16 @@
 nalysis)
- 
 %0A       
@@ -1504,24 +1504,25 @@
 ysis;%0A    %7D%0A
+%0A
     final Cl
@@ -1519,16 +1519,29 @@
   final 
+@Nonnull%0A    
 Class%3C?%3E
@@ -1548,24 +1548,25 @@
  mainClass;%0A
+%0A
     final Me
@@ -1582,16 +1582,17 @@
 Method;%0A
+%0A
     publ
@@ -1600,32 +1600,36 @@
 c final @Nonnull
+%0A   
  String cmd;%0A   
@@ -1621,24 +1621,25 @@
 String cmd;%0A
+%0A
     public f
@@ -1659,24 +1659,25 @@
 escription;%0A
+%0A
     public f
@@ -1689,16 +1689,20 @@
 @Nonnull
+%0A   
  String 
@@ -1703,24 +1703,25 @@
 tring kind;%0A
+%0A
     final bo
@@ -1736,20 +1736,16 @@
 alysis;%0A
-    
 %0A    pub
@@ -1766,17 +1766,16 @@
 e(String
- 
 %5B%5D args)
@@ -1905,24 +1905,25 @@
 rgs);%0A    %7D%0A
+%0A
     public i
@@ -2100,35 +2100,15 @@
 d);%0A
-                
 %0A    %7D%0A
-    
 %0A   
@@ -2311,11 +2311,11 @@
 ind)
+ 
 &&
- 
  cmd
@@ -2339,20 +2339,16 @@
 ;%0A    %7D%0A
-    
 %0A    @Ov
@@ -2438,11 +2438,10 @@
 %0A    %7D%0A%0A
-%0A
 %7D%0A

clean up annotations