Code cleanup: data deprecations and some effective visibility stuff

This commit is contained in:
Mikhail Glukhikh
2015-10-16 17:15:45 +03:00
parent a501878d60
commit cae0388a57
7 changed files with 59 additions and 30 deletions
@@ -34,7 +34,7 @@ interface Conditional {
})
}
data class JsVersion(): PlatformVersion {
data class JsVersion(val version: Int = 5): PlatformVersion {
companion object : Parser("JsVersion", parse = { JsVersion() })
}
@@ -18,22 +18,22 @@ package org.jetbrains.kotlin.preprocessor
interface Evaluator : (List<Conditional>) -> Boolean
abstract class PlatformEvaluator : Evaluator {
final override fun invoke(conditions: List<Conditional>): Boolean = evaluate(conditions.filterIsInstance())
interface PlatformEvaluator : Evaluator {
override fun invoke(conditions: List<Conditional>): Boolean = evaluate(conditions.filterIsInstance())
open fun evaluate(conditions: List<Conditional.PlatformVersion>): Boolean
= conditions.isEmpty() || conditions.any { match(it) }
abstract fun match(platformCondition: Conditional.PlatformVersion): Boolean
fun match(platformCondition: Conditional.PlatformVersion): Boolean
}
data class JvmPlatformEvaluator(val version: Int): PlatformEvaluator() {
data class JvmPlatformEvaluator(val version: Int): PlatformEvaluator {
override fun match(platformCondition: Conditional.PlatformVersion)
= platformCondition is Conditional.JvmVersion && version in platformCondition.versionRange
override fun toString() = "platform: JVM$version"
}
data class JsPlatformEvaluator(val ecmaScriptVersion: Int = 5): PlatformEvaluator() {
data class JsPlatformEvaluator(val ecmaScriptVersion: Int = 5): PlatformEvaluator {
override fun match(platformCondition: Conditional.PlatformVersion)
= platformCondition is Conditional.JsVersion
override fun toString() = "platform: JS"
@@ -26,8 +26,16 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
public sealed class AccessTarget {
public data class Declaration(val descriptor: VariableDescriptor): AccessTarget()
public data class Call(val resolvedCall: ResolvedCall<*>): AccessTarget()
public class Declaration(val descriptor: VariableDescriptor): AccessTarget() {
override fun equals(other: Any?) = other is Declaration && descriptor == other.descriptor
override fun hashCode() = descriptor.hashCode()
}
public class Call(val resolvedCall: ResolvedCall<*>): AccessTarget() {
override fun equals(other: Any?) = other is Call && resolvedCall == other.resolvedCall
override fun hashCode() = resolvedCall.hashCode()
}
public object BlackBox: AccessTarget()
}
@@ -62,8 +62,10 @@ public class ClassDeserializer(private val components: DeserializationComponents
return DeserializedClassDescriptor(outerContext, classProto, nameResolver, sourceElement)
}
private data class ClassKey(val classId: ClassId, classDataWithSource: ClassDataWithSource?) {
// This property is not declared in the constructor because it shouldn't participate in equals/hashCode
val classDataWithSource: ClassDataWithSource? = classDataWithSource
private class ClassKey(val classId: ClassId, val classDataWithSource: ClassDataWithSource?) {
// classDataWithSource *intentionally* not used in equals() / hashCode()
override fun equals(other: Any?) = other is ClassKey && classId == other.classId
override fun hashCode() = classId.hashCode()
}
}
@@ -33,8 +33,8 @@ import java.util.*
public val LIBRARY_NAME_PREFIX: String = "library "
public abstract class IdeaModuleInfo : ModuleInfo {
abstract fun contentScope(): GlobalSearchScope
public interface IdeaModuleInfo : ModuleInfo {
fun contentScope(): GlobalSearchScope
}
private fun orderEntryToModuleInfo(project: Project, orderEntry: OrderEntry, productionOnly: Boolean): List<IdeaModuleInfo> {
@@ -80,14 +80,14 @@ fun ideaModelDependencies(module: Module, productionOnly: Boolean): List<IdeaMod
return result.toList()
}
public abstract class ModuleSourceInfo : IdeaModuleInfo() {
abstract val module: Module
public interface ModuleSourceInfo : IdeaModuleInfo {
val module: Module
}
public data class ModuleProductionSourceInfo(override val module: Module) : ModuleSourceInfo() {
public data class ModuleProductionSourceInfo(override val module: Module) : ModuleSourceInfo {
override val name = Name.special("<production sources for module ${module.getName()}>")
override fun contentScope() = ModuleProductionSourceScope(module)
override fun contentScope(): GlobalSearchScope = ModuleProductionSourceScope(module)
override fun dependencies() = module.cached(CachedValueProvider {
CachedValueProvider.Result(
@@ -99,10 +99,10 @@ public data class ModuleProductionSourceInfo(override val module: Module) : Modu
}
//TODO: (module refactoring) do not create ModuleTestSourceInfo when there are no test roots for module
public data class ModuleTestSourceInfo(override val module: Module) : ModuleSourceInfo() {
public data class ModuleTestSourceInfo(override val module: Module) : ModuleSourceInfo {
override val name = Name.special("<test sources for module ${module.getName()}>")
override fun contentScope() = ModuleTestSourceScope(module)
override fun contentScope(): GlobalSearchScope = ModuleTestSourceScope(module)
override fun dependencies() = module.cached(CachedValueProvider {
CachedValueProvider.Result(
@@ -148,10 +148,10 @@ private class ModuleTestSourceScope(module: Module) : ModuleSourceScope(module)
override fun contains(file: VirtualFile) = moduleFileIndex.isInTestSourceContent(file)
}
public data class LibraryInfo(val project: Project, val library: Library) : IdeaModuleInfo() {
public data class LibraryInfo(val project: Project, val library: Library) : IdeaModuleInfo {
override val name: Name = Name.special("<$LIBRARY_NAME_PREFIX${library.getName()}>")
override fun contentScope() = LibraryWithoutSourceScope(project, library)
override fun contentScope(): GlobalSearchScope = LibraryWithoutSourceScope(project, library)
override val isLibrary: Boolean
get() = true
@@ -171,7 +171,7 @@ public data class LibraryInfo(val project: Project, val library: Library) : Idea
override fun toString() = "LibraryInfo(libraryName=${library.getName()})"
}
internal data class LibrarySourceInfo(val project: Project, val library: Library) : IdeaModuleInfo() {
internal data class LibrarySourceInfo(val project: Project, val library: Library) : IdeaModuleInfo {
override val name: Name = Name.special("<sources for library ${library.getName()}>")
override fun contentScope() = GlobalSearchScope.EMPTY_SCOPE
@@ -187,15 +187,15 @@ internal data class LibrarySourceInfo(val project: Project, val library: Library
}
//TODO: (module refactoring) there should be separate SdkSourceInfo but there are no kotlin source in existing sdks for now :)
public data class SdkInfo(val project: Project, val sdk: Sdk) : IdeaModuleInfo() {
public data class SdkInfo(val project: Project, val sdk: Sdk) : IdeaModuleInfo {
override val name: Name = Name.special("<$LIBRARY_NAME_PREFIX${sdk.getName()}>")
override fun contentScope() = SdkScope(project, sdk)
override fun contentScope(): GlobalSearchScope = SdkScope(project, sdk)
override fun dependencies(): List<IdeaModuleInfo> = listOf(this)
}
internal object NotUnderContentRootModuleInfo : IdeaModuleInfo() {
internal object NotUnderContentRootModuleInfo : IdeaModuleInfo {
override val name: Name = Name.special("<special module for files not under source root>")
override fun contentScope() = GlobalSearchScope.EMPTY_SCOPE
@@ -204,12 +204,21 @@ internal object NotUnderContentRootModuleInfo : IdeaModuleInfo() {
override fun dependencies(): List<IdeaModuleInfo> = listOf(this)
}
private data class LibraryWithoutSourceScope(project: Project, private val library: Library) :
private class LibraryWithoutSourceScope(project: Project, private val library: Library) :
LibraryScopeBase(project, library.getFiles(OrderRootType.CLASSES), arrayOf<VirtualFile>()) {
override fun equals(other: Any?) = other is LibraryWithoutSourceScope && library == other.library
override fun hashCode() = library.hashCode()
}
//TODO: (module refactoring) android sdk has modified scope
private data class SdkScope(project: Project, private val sdk: Sdk) :
LibraryScopeBase(project, sdk.getRootProvider().getFiles(OrderRootType.CLASSES), arrayOf<VirtualFile>())
private class SdkScope(project: Project, private val sdk: Sdk) :
LibraryScopeBase(project, sdk.getRootProvider().getFiles(OrderRootType.CLASSES), arrayOf<VirtualFile>()) {
override fun equals(other: Any?) = other is SdkScope && sdk == other.sdk
override fun hashCode() = sdk.hashCode()
}
internal fun IdeaModuleInfo.isLibraryClasses() = this is SdkInfo || this is LibraryInfo
@@ -675,9 +675,14 @@ data class ChangesInfo(
public fun BuildDataPaths.getKotlinCacheVersion(target: BuildTarget<*>): CacheFormatVersion = CacheFormatVersion(getTargetDataRoot(target))
private data class KotlinIncrementalStorageProvider(
private class KotlinIncrementalStorageProvider(
private val target: ModuleBuildTarget
) : StorageProvider<IncrementalCacheImpl>() {
override fun equals(other: Any?) = other is KotlinIncrementalStorageProvider && target == other.target
override fun hashCode() = target.hashCode()
override fun createStorage(targetDataDir: File): IncrementalCacheImpl =
IncrementalCacheImpl(targetDataDir, target)
}
@@ -18,7 +18,12 @@ package org.jetbrains.kotlin.android.synthetic.res
import org.jetbrains.kotlin.android.synthetic.AndroidConst
public data class AndroidModuleInfo(val applicationPackage: String, resDirectories: List<String>) {
public class AndroidModuleInfo(val applicationPackage: String, resDirectories: List<String>) {
override fun equals(other: Any?) = other is AndroidModuleInfo && applicationPackage == other.applicationPackage
override fun hashCode() = applicationPackage.hashCode()
val resDirectories = resDirectories.sorted()
}