Remove non-idiomatic inheritance

Remove inheritance implemented with the bad "superclass calls
subclass through interface" pattern, and replace it with composition.

Test: builds
Change-Id: If323f89360455b3f98b40777edaaaa265bb3b5fc
diff --git a/java/app.go b/java/app.go
index ef576e2..3a7025c 100644
--- a/java/app.go
+++ b/java/app.go
@@ -57,7 +57,7 @@
 }
 
 type AndroidApp struct {
-	javaBase
+	Module
 
 	appProperties androidAppProperties
 
@@ -65,9 +65,10 @@
 	exportPackage    android.Path
 }
 
-func (a *AndroidApp) JavaDependencies(ctx AndroidJavaModuleContext) []string {
-	deps := a.javaBase.JavaDependencies(ctx)
+func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
+	a.Module.deps(ctx)
 
+	var deps []string
 	if !a.properties.No_standard_libraries {
 		switch a.properties.Sdk_version { // TODO: Res_sdk_version?
 		case "current", "system_current", "":
@@ -77,10 +78,10 @@
 		}
 	}
 
-	return deps
+	ctx.AddDependency(ctx.Module(), nil, deps...)
 }
 
-func (a *AndroidApp) GenerateJavaBuildActions(ctx android.ModuleContext) {
+func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
 	aaptFlags, aaptDeps, hasResources := a.aaptFlags(ctx)
 
 	if hasResources {
@@ -114,14 +115,14 @@
 		ctx.CheckbuildFile(aaptJavaFileList)
 	}
 
-	// apps manifests are handled by aapt, don't let javaBase see them
+	// apps manifests are handled by aapt, don't let Module see them
 	a.properties.Manifest = nil
 
 	//if !ctx.ContainsProperty("proguard.enabled") {
 	//	a.properties.Proguard.Enabled = true
 	//}
 
-	a.javaBase.GenerateJavaBuildActions(ctx)
+	a.Module.compile(ctx)
 
 	aaptPackageFlags := append([]string(nil), aaptFlags...)
 	var hasProduct bool
@@ -238,7 +239,7 @@
 			depFile = android.OptionalPathForPath(sdkDep.ClasspathFile())
 		} else if javaDep, ok := module.(JavaDependency); ok {
 			if ctx.OtherModuleName(module) == "framework-res" {
-				depFile = android.OptionalPathForPath(javaDep.(*javaBase).module.(*AndroidApp).exportPackage)
+				depFile = android.OptionalPathForPath(javaDep.(*AndroidApp).exportPackage)
 			}
 		}
 		if depFile.Valid() {
@@ -278,5 +279,6 @@
 
 	module.properties.Dex = true
 
-	return NewJavaBase(&module.javaBase, module, android.DeviceSupported, &module.appProperties)
+	return android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon,
+		&module.Module.properties, &module.appProperties)
 }
diff --git a/java/gen.go b/java/gen.go
index e3973bf..e473859 100644
--- a/java/gen.go
+++ b/java/gen.go
@@ -84,7 +84,7 @@
 	return javaFile
 }
 
-func (j *javaBase) genSources(ctx android.ModuleContext, srcFiles android.Paths,
+func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths,
 	flags javaBuilderFlags) android.Paths {
 
 	for i, srcFile := range srcFiles {
diff --git a/java/java.go b/java/java.go
index 6dc955d..8efff6e 100644
--- a/java/java.go
+++ b/java/java.go
@@ -15,7 +15,7 @@
 package java
 
 // This file contains the module types for compiling Java for Android, and converts the properties
-// into the flags and filenames necessary to pass to the compiler.  The final creation of the rules
+// into the flags and filenames necessary to pass to the Module.  The final creation of the rules
 // is handled in builder.go
 
 import (
@@ -54,7 +54,7 @@
 // DroidDoc
 // Findbugs
 
-type javaBaseProperties struct {
+type compilerProperties struct {
 	// list of source files used to compile the Java module.  May be .java, .logtags, .proto,
 	// or .aidl files.
 	Srcs []string `android:"arch_variant"`
@@ -106,13 +106,11 @@
 	Export_aidl_include_dirs []string
 }
 
-// javaBase contains the properties and members used by all java module types, and implements
-// the blueprint.Module interface.
-type javaBase struct {
+// Module contains the properties and members used by all java module types
+type Module struct {
 	android.ModuleBase
-	module JavaModuleType
 
-	properties javaBaseProperties
+	properties compilerProperties
 
 	// output file suitable for inserting into the classpath of another compile
 	classpathFile android.Path
@@ -138,13 +136,6 @@
 	installFile android.Path
 }
 
-type AndroidJavaModuleContext android.BaseContext
-
-type JavaModuleType interface {
-	GenerateJavaBuildActions(ctx android.ModuleContext)
-	JavaDependencies(ctx AndroidJavaModuleContext) []string
-}
-
 type JavaDependency interface {
 	ClasspathFile() android.Path
 	ClassJarSpecs() []jarSpec
@@ -152,17 +143,7 @@
 	AidlIncludeDirs() android.Paths
 }
 
-func NewJavaBase(base *javaBase, module JavaModuleType, hod android.HostOrDeviceSupported,
-	props ...interface{}) (blueprint.Module, []interface{}) {
-
-	base.module = module
-
-	props = append(props, &base.properties)
-
-	return android.InitAndroidArchModule(base, hod, android.MultilibCommon, props...)
-}
-
-func (j *javaBase) BootClasspath(ctx android.BaseContext) string {
+func (j *Module) BootClasspath(ctx android.BaseContext) string {
 	if ctx.Device() {
 		if j.properties.Sdk_version == "" {
 			return "core-libart"
@@ -186,13 +167,7 @@
 
 var defaultJavaLibraries = []string{"core-libart", "legacy-test", "ext", "framework"}
 
-func (j *javaBase) DepsMutator(ctx android.BottomUpMutatorContext) {
-	if j, ok := ctx.Module().(JavaModuleType); ok {
-		ctx.AddDependency(ctx.Module(), nil, j.JavaDependencies(ctx)...)
-	}
-}
-
-func (j *javaBase) JavaDependencies(ctx AndroidJavaModuleContext) []string {
+func (j *Module) deps(ctx android.BottomUpMutatorContext) {
 	var deps []string
 
 	if !j.properties.No_standard_libraries {
@@ -207,10 +182,10 @@
 	deps = append(deps, j.properties.Java_libs...)
 	deps = append(deps, j.properties.Java_static_libs...)
 
-	return deps
+	ctx.AddDependency(ctx.Module(), nil, deps...)
 }
 
-func (j *javaBase) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
+func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
 	aidlIncludeDirs android.Paths) []string {
 
 	localAidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl_includes)
@@ -230,7 +205,7 @@
 	return flags
 }
 
-func (j *javaBase) collectDeps(ctx android.ModuleContext) (classpath android.Paths,
+func (j *Module) collectDeps(ctx android.ModuleContext) (classpath android.Paths,
 	bootClasspath android.OptionalPath, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess android.OptionalPath,
 	aidlIncludeDirs android.Paths, srcFileLists android.Paths) {
 
@@ -251,7 +226,7 @@
 				if ctx.ModuleName() == "framework" {
 					// framework.jar has a one-off dependency on the R.java and Manifest.java files
 					// generated by framework-res.apk
-					srcFileLists = append(srcFileLists, module.(*javaBase).module.(*AndroidApp).aaptJavaFileList)
+					srcFileLists = append(srcFileLists, module.(*AndroidApp).aaptJavaFileList)
 				}
 			} else {
 				panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
@@ -274,11 +249,7 @@
 		aidlIncludeDirs, srcFileLists
 }
 
-func (j *javaBase) GenerateAndroidBuildActions(ctx android.ModuleContext) {
-	j.module.GenerateJavaBuildActions(ctx)
-}
-
-func (j *javaBase) GenerateJavaBuildActions(ctx android.ModuleContext) {
+func (j *Module) compile(ctx android.ModuleContext) {
 
 	j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Export_aidl_include_dirs)
 
@@ -404,25 +375,25 @@
 
 var _ JavaDependency = (*JavaLibrary)(nil)
 
-func (j *javaBase) ClasspathFile() android.Path {
+func (j *Module) ClasspathFile() android.Path {
 	return j.classpathFile
 }
 
-func (j *javaBase) ClassJarSpecs() []jarSpec {
+func (j *Module) ClassJarSpecs() []jarSpec {
 	return j.classJarSpecs
 }
 
-func (j *javaBase) ResourceJarSpecs() []jarSpec {
+func (j *Module) ResourceJarSpecs() []jarSpec {
 	return j.resourceJarSpecs
 }
 
-func (j *javaBase) AidlIncludeDirs() android.Paths {
+func (j *Module) AidlIncludeDirs() android.Paths {
 	return j.exportAidlIncludeDirs
 }
 
-var _ logtagsProducer = (*javaBase)(nil)
+var _ logtagsProducer = (*Module)(nil)
 
-func (j *javaBase) logtags() android.Paths {
+func (j *Module) logtags() android.Paths {
 	return j.logtagsSrcs
 }
 
@@ -431,27 +402,33 @@
 //
 
 type JavaLibrary struct {
-	javaBase
+	Module
 }
 
-func (j *JavaLibrary) GenerateJavaBuildActions(ctx android.ModuleContext) {
-	j.javaBase.GenerateJavaBuildActions(ctx)
+func (j *JavaLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+	j.compile(ctx)
 
 	j.installFile = ctx.InstallFileName(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".jar", j.outputFile)
 }
 
+func (j *JavaLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
+	j.deps(ctx)
+}
+
 func JavaLibraryFactory() (blueprint.Module, []interface{}) {
 	module := &JavaLibrary{}
 
 	module.properties.Dex = true
 
-	return NewJavaBase(&module.javaBase, module, android.HostAndDeviceSupported)
+	return android.InitAndroidArchModule(module, android.HostAndDeviceSupported,
+		android.MultilibCommon, &module.Module.properties)
 }
 
 func JavaLibraryHostFactory() (blueprint.Module, []interface{}) {
 	module := &JavaLibrary{}
 
-	return NewJavaBase(&module.javaBase, module, android.HostSupported)
+	return android.InitAndroidArchModule(module, android.HostSupported,
+		android.MultilibCommon, &module.Module.properties)
 }
 
 //
@@ -469,8 +446,8 @@
 	binaryProperties javaBinaryProperties
 }
 
-func (j *JavaBinary) GenerateJavaBuildActions(ctx android.ModuleContext) {
-	j.JavaLibrary.GenerateJavaBuildActions(ctx)
+func (j *JavaBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+	j.JavaLibrary.GenerateAndroidBuildActions(ctx)
 
 	// Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by
 	// another build rule before the jar has been installed.
@@ -478,18 +455,24 @@
 		j.installFile)
 }
 
+func (j *JavaBinary) DepsMutator(ctx android.BottomUpMutatorContext) {
+	j.deps(ctx)
+}
+
 func JavaBinaryFactory() (blueprint.Module, []interface{}) {
 	module := &JavaBinary{}
 
 	module.properties.Dex = true
 
-	return NewJavaBase(&module.javaBase, module, android.HostAndDeviceSupported, &module.binaryProperties)
+	return android.InitAndroidArchModule(module, android.HostAndDeviceSupported,
+		android.MultilibCommon, &module.Module.properties, &module.binaryProperties)
 }
 
 func JavaBinaryHostFactory() (blueprint.Module, []interface{}) {
 	module := &JavaBinary{}
 
-	return NewJavaBase(&module.javaBase, module, android.HostSupported, &module.binaryProperties)
+	return android.InitAndroidArchModule(module, android.HostSupported,
+		android.MultilibCommon, &module.Module.properties, &module.binaryProperties)
 }
 
 //