package org.realityforge.gwt.propertysource.example.client;

import com.github.legioth.propertysource.client.PropertySource;
import com.github.legioth.propertysource.client.annotations.BooleanConversion;
import com.github.legioth.propertysource.client.annotations.Property;
import com.google.gwt.core.shared.GWT;

public class UserAgentPermutation
{
  @Property("user.agent")
  interface Properties
    extends PropertySource
  {
    @BooleanConversion(truePattern = "gecko.*")
    boolean isGecko();

    @BooleanConversion(trueValues = "safari")
    boolean isSafari();

    @BooleanConversion(trueValues = "opera")
    boolean isOpera();

    @BooleanConversion(truePattern = "ie\\d+")
    boolean isIe();

    @BooleanConversion(trueValues = "ie6")
    boolean isIe6();

    @BooleanConversion(trueValues = "ie8")
    boolean isIe8();

    @BooleanConversion(trueValues = "ie9")
    boolean isIe9();

    String name();
  }

  private static Properties devModeCache;

  private static Properties get()
  {
    if ( GWT.isProdMode() )
    {
      // GWT compiler inlines these, but it could inline if the null check
      // was here
      return GWT.create( Properties.class );
    }
    else
    {
      // Use same instance every time in devmode to avoid creating new
      // object every time
      if ( devModeCache == null )
      {
        devModeCache = GWT.create( Properties.class );
      }
      return devModeCache;
    }
  }

  public static boolean isGecko()
  {
    return get().isGecko();
  }

  public static boolean isSafari()
  {
    return get().isSafari();
  }

  public static boolean isOpera()
  {
    return get().isOpera();
  }

  public static boolean isIe()
  {
    return get().isIe();
  }

  public static boolean isIe6()
  {
    return get().isIe6();
  }

  public static boolean isIe8()
  {
    return get().isIe8();
  }

  public static boolean isIe9()
  {
    return get().isIe9();
  }

  public static String getName()
  {
    return get().name();
  }
}

@@ -355,16 +355,17 @@
 roperty(
+ 
 %22user.ag
@@ -368,16 +368,17 @@
 r.agent%22
+ 
 )%0A  inte
@@ -440,32 +440,33 @@
 oleanConversion(
+ 
 truePattern = %22g
@@ -472,16 +472,17 @@
 gecko.*%22
+ 
 )%0A    bo
@@ -514,32 +514,33 @@
 oleanConversion(
+ 
 trueValues = %22sa
@@ -544,16 +544,17 @@
 %22safari%22
+ 
 )%0A    bo
@@ -587,32 +587,33 @@
 oleanConversion(
+ 
 trueValues = %22op
@@ -616,16 +616,17 @@
  %22opera%22
+ 
 )%0A    bo
@@ -662,24 +662,25 @@
 nConversion(
+ 
 truePattern 
@@ -689,16 +689,17 @@
 %22ie%5C%5Cd+%22
+ 
 )%0A    bo
@@ -728,32 +728,33 @@
 oleanConversion(
+ 
 trueValues = %22ie
@@ -755,16 +755,17 @@
  = %22ie6%22
+ 
 )%0A    bo
@@ -795,32 +795,33 @@
 oleanConversion(
+ 
 trueValues = %22ie
@@ -822,16 +822,17 @@
  = %22ie8%22
+ 
 )%0A    bo
@@ -870,16 +870,17 @@
 version(
+ 
 trueValu
@@ -889,16 +889,17 @@
  = %22ie9%22
+ 
 )%0A    bo
@@ -970,489 +970,60 @@
 ies 
-devModeCache;%0A%0A  private static Properties get()%0A  %7B%0A    if ( GWT.isProdMode() )%0A    %7B%0A      // GWT compiler inlines these, but it could inline if the null check%0A      // was here%0A      return GWT.create( Properties.class );%0A    %7D%0A    else%0A    %7B%0A      // Use same instance every time in devmode to avoid creating new%0A      // object every time%0A      if ( devModeCache == null )%0A      %7B%0A        devModeCache = GWT.create( Properties.class );%0A      %7D%0A      return devModeCache;%0A    %7D
+get()%0A  %7B%0A    return GWT.create( Properties.class );
 %0A  %7D

Remove devmode cache