Move java.sdkSpec to the android package

... in preparation for making the handling of sdk versions consistent
across java and cc modules.

Bug: 175678607
Test: m
Change-Id: I598f0454bce9b7320621022115412fbe97403945
diff --git a/java/base.go b/java/base.go
index bd394af..73e5352 100644
--- a/java/base.go
+++ b/java/base.go
@@ -373,11 +373,11 @@
 }
 
 func (j *Module) CheckStableSdkVersion() error {
-	sdkVersion := j.sdkVersion()
-	if sdkVersion.stable() {
+	sdkVersion := j.SdkVersion()
+	if sdkVersion.Stable() {
 		return nil
 	}
-	if sdkVersion.kind == sdkCorePlatform {
+	if sdkVersion.Kind == android.SdkCorePlatform {
 		if useLegacyCorePlatformApiByName(j.BaseModuleName()) {
 			return fmt.Errorf("non stable SDK %v - uses legacy core platform", sdkVersion)
 		} else {
@@ -392,8 +392,8 @@
 // checkSdkVersions enforces restrictions around SDK dependencies.
 func (j *Module) checkSdkVersions(ctx android.ModuleContext) {
 	if j.RequiresStableAPIs(ctx) {
-		if sc, ok := ctx.Module().(sdkContext); ok {
-			if !sc.sdkVersion().specified() {
+		if sc, ok := ctx.Module().(android.SdkContext); ok {
+			if !sc.SdkVersion().Specified() {
 				ctx.PropertyErrorf("sdk_version",
 					"sdk_version must have a value when the module is located at vendor or product(only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set).")
 			}
@@ -416,9 +416,9 @@
 }
 
 func (j *Module) checkPlatformAPI(ctx android.ModuleContext) {
-	if sc, ok := ctx.Module().(sdkContext); ok {
+	if sc, ok := ctx.Module().(android.SdkContext); ok {
 		usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis)
-		sdkVersionSpecified := sc.sdkVersion().specified()
+		sdkVersionSpecified := sc.SdkVersion().Specified()
 		if usePlatformAPI && sdkVersionSpecified {
 			ctx.PropertyErrorf("platform_apis", "platform_apis must be false when sdk_version is not empty.")
 		} else if !usePlatformAPI && !sdkVersionSpecified {
@@ -512,30 +512,30 @@
 	return false
 }
 
-func (j *Module) sdkVersion() sdkSpec {
-	return sdkSpecFrom(String(j.deviceProperties.Sdk_version))
+func (j *Module) SdkVersion() android.SdkSpec {
+	return android.SdkSpecFrom(String(j.deviceProperties.Sdk_version))
 }
 
-func (j *Module) systemModules() string {
+func (j *Module) SystemModules() string {
 	return proptools.String(j.deviceProperties.System_modules)
 }
 
-func (j *Module) minSdkVersion() sdkSpec {
+func (j *Module) MinSdkVersion() android.SdkSpec {
 	if j.deviceProperties.Min_sdk_version != nil {
-		return sdkSpecFrom(*j.deviceProperties.Min_sdk_version)
+		return android.SdkSpecFrom(*j.deviceProperties.Min_sdk_version)
 	}
-	return j.sdkVersion()
+	return j.SdkVersion()
 }
 
-func (j *Module) targetSdkVersion() sdkSpec {
+func (j *Module) TargetSdkVersion() android.SdkSpec {
 	if j.deviceProperties.Target_sdk_version != nil {
-		return sdkSpecFrom(*j.deviceProperties.Target_sdk_version)
+		return android.SdkSpecFrom(*j.deviceProperties.Target_sdk_version)
 	}
-	return j.sdkVersion()
+	return j.SdkVersion()
 }
 
-func (j *Module) MinSdkVersion() string {
-	return j.minSdkVersion().version.String()
+func (j *Module) MinSdkVersionString() string {
+	return j.MinSdkVersion().Version.String()
 }
 
 func (j *Module) AvailableFor(what string) bool {
@@ -552,7 +552,7 @@
 	if ctx.Device() {
 		j.linter.deps(ctx)
 
-		sdkDeps(ctx, sdkContext(j), j.dexer)
+		sdkDeps(ctx, android.SdkContext(j), j.dexer)
 
 		if j.deviceProperties.SyspropPublicStub != "" {
 			// This is a sysprop implementation library that has a corresponding sysprop public
@@ -702,7 +702,7 @@
 	var flags javaBuilderFlags
 
 	// javaVersion flag.
-	flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
+	flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), android.SdkContext(j))
 
 	if ctx.Config().RunErrorProne() {
 		if config.ErrorProneClasspath == nil && ctx.Config().TestProductVariables == nil {
@@ -731,7 +731,7 @@
 	flags.processors = android.FirstUniqueStrings(flags.processors)
 
 	if len(flags.bootClasspath) == 0 && ctx.Host() && !flags.javaVersion.usesJavaModules() &&
-		decodeSdkDep(ctx, sdkContext(j)).hasStandardLibs() {
+		decodeSdkDep(ctx, android.SdkContext(j)).hasStandardLibs() {
 		// Give host-side tools a version of OpenJDK's standard libraries
 		// close to what they're targeting. As of Dec 2017, AOSP is only
 		// bundling OpenJDK 8 and 9, so nothing < 8 is available.
@@ -1209,7 +1209,7 @@
 			}
 			// Dex compilation
 			var dexOutputFile android.OutputPath
-			dexOutputFile = j.dexer.compileDex(ctx, flags, j.minSdkVersion(), outputFile, jarName)
+			dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(), outputFile, jarName)
 			if ctx.Failed() {
 				return
 			}
@@ -1254,8 +1254,8 @@
 	}
 
 	if ctx.Device() {
-		lintSDKVersionString := func(sdkSpec sdkSpec) string {
-			if v := sdkSpec.version; v.isNumbered() {
+		lintSDKVersionString := func(sdkSpec android.SdkSpec) string {
+			if v := sdkSpec.Version; v.IsNumbered() {
 				return v.String()
 			} else {
 				return ctx.Config().DefaultAppTargetSdk(ctx).String()
@@ -1267,9 +1267,9 @@
 		j.linter.srcJars = srcJars
 		j.linter.classpath = append(append(android.Paths(nil), flags.bootClasspath...), flags.classpath...)
 		j.linter.classes = j.implementationJarFile
-		j.linter.minSdkVersion = lintSDKVersionString(j.minSdkVersion())
-		j.linter.targetSdkVersion = lintSDKVersionString(j.targetSdkVersion())
-		j.linter.compileSdkVersion = lintSDKVersionString(j.sdkVersion())
+		j.linter.minSdkVersion = lintSDKVersionString(j.MinSdkVersion())
+		j.linter.targetSdkVersion = lintSDKVersionString(j.TargetSdkVersion())
+		j.linter.compileSdkVersion = lintSDKVersionString(j.SdkVersion())
 		j.linter.javaLanguageLevel = flags.javaVersion.String()
 		j.linter.kotlinLanguageLevel = "1.3"
 		if !apexInfo.IsForPlatform() && ctx.Config().UnbundledBuildApps() {
@@ -1471,14 +1471,14 @@
 // Implements android.ApexModule
 func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
 	sdkVersion android.ApiLevel) error {
-	sdkSpec := j.minSdkVersion()
-	if !sdkSpec.specified() {
+	sdkSpec := j.MinSdkVersion()
+	if !sdkSpec.Specified() {
 		return fmt.Errorf("min_sdk_version is not specified")
 	}
-	if sdkSpec.kind == sdkCore {
+	if sdkSpec.Kind == android.SdkCore {
 		return nil
 	}
-	ver, err := sdkSpec.effectiveVersion(ctx)
+	ver, err := sdkSpec.EffectiveVersion(ctx)
 	if err != nil {
 		return err
 	}
@@ -1576,24 +1576,24 @@
 		return linkType, true
 	}
 
-	ver := m.sdkVersion()
-	switch ver.kind {
-	case sdkCore:
+	ver := m.SdkVersion()
+	switch ver.Kind {
+	case android.SdkCore:
 		return javaCore, false
-	case sdkSystem:
+	case android.SdkSystem:
 		return javaSystem, false
-	case sdkPublic:
+	case android.SdkPublic:
 		return javaSdk, false
-	case sdkModule:
+	case android.SdkModule:
 		return javaModule, false
-	case sdkSystemServer:
+	case android.SdkSystemServer:
 		return javaSystemServer, false
-	case sdkPrivate, sdkNone, sdkCorePlatform, sdkTest:
+	case android.SdkPrivate, android.SdkNone, android.SdkCorePlatform, android.SdkTest:
 		return javaPlatform, false
 	}
 
-	if !ver.valid() {
-		panic(fmt.Errorf("sdk_version is invalid. got %q", ver.raw))
+	if !ver.Valid() {
+		panic(fmt.Errorf("sdk_version is invalid. got %q", ver.Raw))
 	}
 	return javaSdk, false
 }
@@ -1625,7 +1625,7 @@
 	var deps deps
 
 	if ctx.Device() {
-		sdkDep := decodeSdkDep(ctx, sdkContext(j))
+		sdkDep := decodeSdkDep(ctx, android.SdkContext(j))
 		if sdkDep.invalidVersion {
 			ctx.AddMissingDependencies(sdkDep.bootclasspath)
 			ctx.AddMissingDependencies(sdkDep.java9Classpath)
@@ -1656,7 +1656,7 @@
 		if dep, ok := module.(SdkLibraryDependency); ok {
 			switch tag {
 			case libTag:
-				deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
+				deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion())...)
 			case staticLibTag:
 				ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
 			}