GField { public GField autoImportInitialValue() { this.initialValue = this.gclass.stripAndImportPackageIfPossible(this.initialValue); return this; } GField(GClass gclass, String name); String toCode(); String getName(); String getTypeClassName(); GField type(Class<?> type); GField type(String fullClassName, Object... args); GField initialValue(String initialValue, Object... args); GField autoImportInitialValue(); GClass initialAnonymousClass(); GField setStatic(); GField setFinal(); GField setPublic(); GField setProtected(); GField setAccess(Access access); String toString(); GMethod makeGetter(); GField addAnnotation(String annotation, Object... args);  }
@Test public void testAutoImportInitialValue() { GClass gc = new GClass("foo.Foo"); gc.getField("bar").type("bar.IBar<zaz.Zaz>").initialValue("new bar.BarImpl<zaz.Zaz>()").autoImportInitialValue(); Assert.assertEquals(Join.lines("package foo;", "", "import bar.BarImpl;", "import bar.IBar;", "import zaz.Zaz;", "", "public class Foo {", "", " private IBar<Zaz> bar = new BarImpl<Zaz>();", "", "}", ""), gc.toCode()); }