title: java ProGuard remove (shrink) unused classes
body: <p>Let's say I have this Java app:</p>
  
  <pre><code>package com.site;
  
  public class MyAppBase {}
  </code></pre>
  
  <hr>
  
  <pre><code>package com.site.free;
  
  import com.site.MyAppBase;
  
  public class MyApp extends MyAppBase {}
  </code></pre>
  
  <hr>
  
  <pre><code>package com.site.pro;
  
  import com.site.MyAppBase;
  
  public class MyApp extends MyAppBase {}
  </code></pre>
  
  <hr>
  
  <pre><code>package com.site;
  
  public class Edition
  {
  
      public static final int     FREE    = 1;
      public static final int     PRO     = 2;
  
      private static final int    EDITION = PRO;
  
      public static boolean is(final int edition)
      {
          return (EDITION == edition);
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>package com.site;
  
  public class EditionFactory
  {
  
      public static MyAppBase get_app()
      {
          MyAppBase ret = null;
  
          if (Edition.is(Edition.FREE))
              ret = new com.site.free.MyApp();
          else if (Edition.is(Edition.PRO))
              ret = new com.site.pro.MyApp();
  
          return ret;
      }
  }
  </code></pre>
  
  <hr>
  
  <p>Now, any combination of ProGuard configuration I'm trying to get rid of the non-selected edition (in this case it's FREE) doesn't work.</p>
  
  <p>By "getting rid of" I mean make the actual class disappear (as well from the calling code).</p>
  
  <p>In other words, a call like this:</p>
  
  <pre><code>final MyAppBase app = EditionFactory.get_app();
  </code></pre>
  
  <p>.. is currently being translated to, after ProGuarding it, this:</p>
  
  <pre><code>if (a.a(1))
      localObject5 = new c(); // &lt;&lt;&lt; FREE
  else if (a.a(2))
      localObject5 = new d(); // &lt;&lt;&lt; PRO
  </code></pre>
  
  <p>.. while I'd wish it to be translated to this:</p>
  
  <pre><code>localObject5 = new d(); // &lt;&lt;&lt; PRO only in the code (as set at Edition.EDITION)
  </code></pre>
  
  <p><strong>Bottom line is</strong> (<strong><em>besides the fact that ProGuard is GREAT!!</em></strong>), I can't seem to make it "see through" and understand that Edition.is() is a boolean function returning a constant which makes it ok to remove some classes.</p>
  
  <p>I've tried configurations like:</p>
  
  <pre><code>-keep,allowshrinking,allowoptimization public class * extends com.site.MyAppBase
  -optimizationpasses 10
  </code></pre>
  
  <p>.. nothing works.</p>
  
  <p><strong>On the other hand</strong>, if I refer to Edition.EDITION and comparing it inlined (i.e without any "proxy" functions), the Java compiler (v1.6) detects it and remove the whole reference to the non-selected edition/class.<br>
  This results in that ProGuard removes/shrinks the unused class which is great.</p>
  
  <p>The only issue here is about maintaining - I'd be happy to keep being able to use the EditionFactory style.</p>