code cleanup: frontend module

This commit is contained in:
Dmitry Jemerov
2015-07-21 15:12:54 +02:00
parent e6776ebd8e
commit 6bf934b472
41 changed files with 58 additions and 65 deletions
@@ -31,17 +31,15 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.JetFile
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.storage.StorageManager
import java.util.ArrayList
import java.util.HashMap
import kotlin.properties.Delegates
public trait ResolverForModule {
public interface ResolverForModule {
public val lazyResolveSession: ResolveSession
public val packageFragmentProvider: PackageFragmentProvider
}
public trait ResolverForProject<M : ModuleInfo,out R : ResolverForModule> {
public interface ResolverForProject<M : ModuleInfo,out R : ResolverForModule> {
public fun resolverForModule(moduleInfo: M): R = resolverForModuleDescriptor(descriptorForModule(moduleInfo))
public fun descriptorForModule(moduleInfo: M): ModuleDescriptor
public fun resolverForModuleDescriptor(descriptor: ModuleDescriptor): R
@@ -61,7 +59,7 @@ public class ResolverForProjectImpl<M : ModuleInfo, R : ResolverForModule>(
) : ResolverForProject<M, R> {
val resolverByModuleDescriptor: MutableMap<ModuleDescriptor, () -> R> = HashMap()
override val allModules: Collection<M> by Delegates.lazy {
override val allModules: Collection<M> by lazy {
(descriptorByModule.keySet() + delegateResolver.allModules).toSet()
}
@@ -87,9 +85,9 @@ public data class ModuleContent(
public val moduleContentScope: GlobalSearchScope
)
public trait PlatformAnalysisParameters
public interface PlatformAnalysisParameters
public trait ModuleInfo {
public interface ModuleInfo {
public val isLibrary: Boolean
get() = false
public val name: Name
@@ -98,7 +96,7 @@ public trait ModuleInfo {
public fun dependencyOnBuiltins(): DependencyOnBuiltins = DependenciesOnBuiltins.LAST
//TODO: (module refactoring) provide dependency on builtins after runtime in IDEA
public trait DependencyOnBuiltins {
public interface DependencyOnBuiltins {
public fun adjustDependencies(builtinsModule: ModuleDescriptorImpl, dependencies: MutableList<ModuleDescriptorImpl>)
}
@@ -122,7 +120,7 @@ public trait ModuleInfo {
}
}
public trait AnalyzerFacade<A : ResolverForModule, in P : PlatformAnalysisParameters> {
public interface AnalyzerFacade<A : ResolverForModule, in P : PlatformAnalysisParameters> {
public fun <M : ModuleInfo> setupResolverForProject(
projectContext: ProjectContext,
modules: Collection<M>,
@@ -97,10 +97,10 @@ public class PseudocodeVariableDataCollector(
}
//todo may be a type alias
trait InstructionDataMergeStrategy<D> :
interface InstructionDataMergeStrategy<D> :
(Instruction, Collection<MutableMap<VariableDescriptor, D>>) -> Edges<MutableMap<VariableDescriptor, D>>
public trait LexicalScopeVariableInfo {
public interface LexicalScopeVariableInfo {
val declaredIn : Map<VariableDescriptor, LexicalScope>
val scopeVariables : Map<LexicalScope, Collection<VariableDescriptor>>
}
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.lexer.JetTokens
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.PsiComment
trait UnreachableCode {
interface UnreachableCode {
val elements: Set<JetElement>
fun getUnreachableTextRanges(element: JetElement): List<TextRange>
}
@@ -19,12 +19,12 @@ package org.jetbrains.kotlin.cfg.pseudocode
import org.jetbrains.kotlin.psi.JetElement
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.InstructionWithValue
public trait PseudoValue {
public interface PseudoValue {
public val debugName: String
public val element: JetElement?
public val createdAt: InstructionWithValue?
}
public trait PseudoValueFactory {
public interface PseudoValueFactory {
public fun newValue(element: JetElement?, instruction: InstructionWithValue?): PseudoValue
}
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.checker.JetTypeChecker
public trait TypePredicate: (JetType) -> Boolean {
public interface TypePredicate: (JetType) -> Boolean {
override fun invoke(typeToCheck: JetType): Boolean
}
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.cfg.pseudocode.instructions
import org.jetbrains.kotlin.cfg.pseudocode.Pseudocode
import org.jetbrains.kotlin.cfg.pseudocode.PseudoValue
public trait Instruction {
public interface Instruction {
public var owner: Pseudocode
public val previousInstructions: Collection<Instruction>
@@ -18,6 +18,6 @@ package org.jetbrains.kotlin.cfg.pseudocode.instructions
import org.jetbrains.kotlin.psi.JetElement
public trait JetElementInstruction : Instruction {
public interface JetElementInstruction : Instruction {
public val element: JetElement
}
@@ -16,23 +16,22 @@
package org.jetbrains.kotlin.cfg.pseudocode.instructions
import org.jetbrains.kotlin.psi.JetElement
import org.jetbrains.kotlin.psi.JetDeclaration
import kotlin.properties.Delegates
import org.jetbrains.kotlin.psi.JetElement
public class LexicalScope(val parentScope: LexicalScope?, val element: JetElement) {
//todo remove after KT-4126
private val d = (parentScope?.depth ?: 0) + 1
val depth: Int get() = d
val lexicalScopeForContainingDeclaration: LexicalScope? by Delegates.lazy { computeLexicalScopeForContainingDeclaration() }
val lexicalScopeForContainingDeclaration: LexicalScope? by lazy { computeLexicalScopeForContainingDeclaration() }
private fun computeLexicalScopeForContainingDeclaration(): LexicalScope? {
var scope: LexicalScope? = this
while (scope != null) {
if (scope?.element is JetDeclaration) {
if (scope.element is JetDeclaration) {
return scope
}
scope = scope?.parentScope
scope = scope.parentScope
}
return null
}
@@ -20,6 +20,6 @@ import org.jetbrains.kotlin.cfg.pseudocode.PseudoValue
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
public trait InstructionWithReceivers: Instruction {
public interface InstructionWithReceivers: Instruction {
public val receiverValues: Map<PseudoValue, ReceiverValue>
}
@@ -19,6 +19,6 @@ package org.jetbrains.kotlin.cfg.pseudocode.instructions.eval
import org.jetbrains.kotlin.cfg.pseudocode.instructions.JetElementInstruction
import org.jetbrains.kotlin.cfg.pseudocode.PseudoValue
public trait InstructionWithValue : JetElementInstruction {
public interface InstructionWithValue : JetElementInstruction {
public val outputValue: PseudoValue?
}
@@ -18,4 +18,4 @@ package org.jetbrains.kotlin.cfg.pseudocode.instructions.jumps
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction
public trait JumpInstruction : Instruction
public interface JumpInstruction : Instruction
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.config
import java.io.File
public trait ContentRoot
public interface ContentRoot
public data class KotlinSourceRoot(public val path: String): ContentRoot
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
import org.jetbrains.kotlin.analyzer.ModuleInfo
import org.jetbrains.kotlin.psi.JetFile
public trait ExternalDeclarationsProvider {
public interface ExternalDeclarationsProvider {
companion object : ProjectExtensionDescriptor<ExternalDeclarationsProvider>(
"org.jetbrains.kotlin.externalDeclarationsProvider",
javaClass<ExternalDeclarationsProvider>()
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.psi.JetDeclaration
import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag
// Don't implement JetElement (or it will be treated as statement)
public trait KDoc : PsiComment {
public interface KDoc : PsiComment {
public fun getOwner(): JetDeclaration?
public fun getDefaultSection(): KDocSection
public fun findSectionByName(name: String): KDocSection?
@@ -33,7 +33,7 @@ object JetQualifiedExpressionImpl {
}
private fun JetQualifiedExpression.getExpression(afterOperation: Boolean): JetExpression? {
return getOperationTokenNode()?.getPsi()?.siblings(afterOperation, false)?.firstOrNull { it is JetExpression } as? JetExpression
return getOperationTokenNode().getPsi()?.siblings(afterOperation, false)?.firstOrNull { it is JetExpression } as? JetExpression
}
public fun JetQualifiedExpression.getReceiverExpression(): JetExpression {
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.psi
import com.intellij.psi.impl.source.tree.LeafPsiElement
import org.jetbrains.kotlin.name.Name
public trait ValueArgument {
public interface ValueArgument {
IfNotParsed
public fun getArgumentExpression(): JetExpression?
@@ -36,7 +36,7 @@ public trait ValueArgument {
public fun isExternal(): Boolean
}
public trait FunctionLiteralArgument : ValueArgument {
public interface FunctionLiteralArgument : ValueArgument {
public fun getFunctionLiteral(): JetFunctionLiteralExpression
override fun getArgumentExpression(): JetExpression
@@ -50,7 +50,7 @@ private fun CallableDescriptor.isPlatformStaticIn(predicate: (DeclarationDescrip
when (this) {
is PropertyAccessorDescriptor -> {
val propertyDescriptor = getCorrespondingProperty()
predicate(propertyDescriptor.getContainingDeclaration()!!) &&
predicate(propertyDescriptor.getContainingDeclaration()) &&
(hasPlatformStaticAnnotation() || propertyDescriptor.hasPlatformStaticAnnotation())
}
else -> predicate(getContainingDeclaration()) && hasPlatformStaticAnnotation()
@@ -21,7 +21,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.components.ServiceManager
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
public trait CodeAnalyzerInitializer {
public interface CodeAnalyzerInitializer {
public fun initialize(trace: BindingTrace, module: ModuleDescriptor, codeAnalyzer: KotlinCodeAnalyzer?)
public fun createTrace(): BindingTrace
@@ -83,8 +83,8 @@ public object DescriptorToSourceUtils {
if (declarationDescriptor is PropertyAccessorDescriptor) {
descriptor = (descriptor as PropertyAccessorDescriptor).getCorrespondingProperty()
}
while (!(descriptor == null || DescriptorUtils.isTopLevelDeclaration(descriptor!!))) {
descriptor = descriptor!!.getContainingDeclaration()
while (!(descriptor == null || DescriptorUtils.isTopLevelDeclaration(descriptor))) {
descriptor = descriptor.getContainingDeclaration()
}
return descriptor
}
@@ -28,13 +28,13 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.types.TypeProjectionImpl
trait TypeBinding<out P : PsiElement> {
interface TypeBinding<out P : PsiElement> {
val psiElement: P
val jetType: JetType
fun getArgumentBindings(): List<TypeArgumentBinding<P>?>
}
trait TypeArgumentBinding<out P: PsiElement> {
interface TypeArgumentBinding<out P: PsiElement> {
val typeProjection: TypeProjection
val typeParameterDescriptor: TypeParameterDescriptor?
val typeBinding: TypeBinding<P>
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.resolve.calls.context.CallResolutionContext
public trait AdditionalTypeChecker {
public interface AdditionalTypeChecker {
public class Composite(val checkers: List<AdditionalTypeChecker>): AdditionalTypeChecker {
override fun checkType(expression: JetExpression, expressionType: JetType, c: ResolutionContext<*>) {
@@ -33,14 +33,12 @@ public class InlineCheckerWrapper : CallChecker {
var parentDescriptor: DeclarationDescriptor? = context.scope.getContainingDeclaration()
while (parentDescriptor != null) {
val descriptor = parentDescriptor!!
if (InlineUtil.isInline(descriptor)) {
val checker = getChecker(descriptor as SimpleFunctionDescriptor)
if (InlineUtil.isInline(parentDescriptor)) {
val checker = getChecker(parentDescriptor as SimpleFunctionDescriptor)
checker.check(resolvedCall, context)
}
parentDescriptor = parentDescriptor?.getContainingDeclaration()
parentDescriptor = parentDescriptor.getContainingDeclaration()
}
}
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.psi.Call
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
import org.jetbrains.kotlin.resolve.calls.context.ResolutionResultsCache.CachedData
public trait ResolutionResultsCache {
public interface ResolutionResultsCache {
public data class CachedData(
val resolutionResults: OverloadResolutionResultsImpl<*>,
val deferredComputation: BasicCallResolutionContext,
@@ -38,7 +38,7 @@ public enum class ArgumentMatchStatus(val isError: Boolean = true) {
UNKNOWN()
}
public trait ArgumentMatch : ArgumentMapping {
public interface ArgumentMatch : ArgumentMapping {
public val valueParameter: ValueParameterDescriptor
public val status: ArgumentMatchStatus
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.descriptors.VariableDescriptor
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus
import org.jetbrains.kotlin.resolve.DelegatingBindingTrace
public trait VariableAsFunctionResolvedCall {
public interface VariableAsFunctionResolvedCall {
public val functionCall: ResolvedCall<FunctionDescriptor>
public val variableCall: ResolvedCall<VariableDescriptor>
}
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.expressions.OperatorConventions
public trait CallableDescriptorCollector<D : CallableDescriptor> {
public interface CallableDescriptorCollector<D : CallableDescriptor> {
public fun getNonExtensionsByName(scope: JetScope, name: Name, bindingTrace: BindingTrace): Collection<D>
@@ -67,7 +67,7 @@ public class ResolutionTaskHolder<D : CallableDescriptor, F : D>(
return internalTasks!!
}
public trait PriorityProvider<D> {
public interface PriorityProvider<D> {
public fun getPriority(candidate: D): Int
public fun getMaxPriority(): Int
@@ -20,7 +20,7 @@ import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.diagnostics.Diagnostic
import com.intellij.openapi.util.ModificationTracker
public trait Diagnostics : Iterable<Diagnostic> {
public interface Diagnostics : Iterable<Diagnostic> {
//should not be called on readonly views
//any Diagnostics object returned by BindingContext#getDiagnostics() should implement this property
public val modificationTracker: ModificationTracker
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
import org.jetbrains.kotlin.storage.StorageManager
public trait LazyClassContext {
public interface LazyClassContext {
val declarationScopeProvider: DeclarationScopeProvider
val storageManager: StorageManager
@@ -35,9 +35,8 @@ import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.util.collectionUtils.concat
import org.jetbrains.kotlin.utils.Printer
import java.util.LinkedHashSet
import kotlin.properties.Delegates
trait IndexedImports {
interface IndexedImports {
val imports: List<JetImportDirective>
fun importsForName(name: Name): Collection<JetImportDirective>
}
@@ -50,7 +49,7 @@ class AllUnderImportsIndexed(allImports: Collection<JetImportDirective>) : Index
class AliasImportsIndexed(allImports: Collection<JetImportDirective>) : IndexedImports {
override val imports = allImports.filter { !it.isAllUnder() }
private val nameToDirectives: ListMultimap<Name, JetImportDirective> by Delegates.lazy {
private val nameToDirectives: ListMultimap<Name, JetImportDirective> by lazy {
val builder = ImmutableListMultimap.builder<Name, JetImportDirective>()
for (directive in imports) {
@@ -144,6 +144,7 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
this.packages =
storageManager.createMemoizedFunctionWithNullableValues(new Function1<FqName, LazyPackageDescriptor>() {
@Override
@Nullable
public LazyPackageDescriptor invoke(FqName fqName) {
return createPackage(fqName);
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.JetScript
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor
public trait TopLevelDescriptorProvider {
public interface TopLevelDescriptorProvider {
fun getPackageFragment(fqName: FqName): LazyPackageDescriptor?
fun getScriptDescriptor(script: JetScript): ScriptDescriptor
@@ -18,6 +18,6 @@ package org.jetbrains.kotlin.resolve.lazy.declarations
import org.jetbrains.kotlin.resolve.lazy.data.JetClassLikeInfo
public trait ClassMemberDeclarationProvider : DeclarationProvider {
public interface ClassMemberDeclarationProvider : DeclarationProvider {
public fun getOwnerInfo(): JetClassLikeInfo
}
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.resolve.lazy.data.JetClassLikeInfo
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
public trait DeclarationProvider {
public interface DeclarationProvider {
public fun getDeclarations(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): List<JetDeclaration>
public fun getFunctionDeclarations(name: Name): Collection<JetNamedFunction>
@@ -21,10 +21,7 @@ import org.jetbrains.kotlin.psi.JetFile
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
public trait PackageMemberDeclarationProvider : DeclarationProvider {
/**
* Implementation of this method are not obliged to use the filters but may do so when it gives any performance advantage
*/
public interface PackageMemberDeclarationProvider : DeclarationProvider {
public fun getAllDeclaredSubPackages(nameFilter: (Name) -> Boolean): Collection<FqName>
public fun getPackageFiles(): Collection<JetFile>
@@ -83,7 +83,7 @@ public open class LazyClassMemberScope(
return result
}
private trait MemberExtractor<T : CallableMemberDescriptor> {
private interface MemberExtractor<T : CallableMemberDescriptor> {
public fun extract(extractFrom: JetType, name: Name): Collection<T>
}
@@ -20,7 +20,7 @@ import com.google.common.collect.Multimap
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.Name
public trait WritableScope : JetScope {
public interface WritableScope : JetScope {
public enum class LockLevel {
WRITING,
BOTH,
@@ -42,7 +42,7 @@ import org.jetbrains.kotlin.utils.addIfNotNull
import java.util.ArrayList
import kotlin.properties.Delegates
public trait Qualifier: ReceiverValue {
public interface Qualifier: ReceiverValue {
public val expression: JetExpression
@@ -19,6 +19,6 @@ package org.jetbrains.kotlin.resolve.source
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.SourceElement
public trait PsiSourceElement : SourceElement {
public interface PsiSourceElement : SourceElement {
public val psi: PsiElement?
}
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.resolve.BindingTrace
import kotlin.platform.platformStatic
public trait SymbolUsageValidator {
public interface SymbolUsageValidator {
public fun validateTypeUsage(targetDescriptor: ClassifierDescriptor, trace: BindingTrace, element: PsiElement) { }
@@ -307,6 +307,7 @@ public class ExpressionTypingVisitorDispatcher extends JetVisitor<JetTypeInfo, E
//////////////////////////////////////////////////////////////////////////////////////////////
@Override
public JetTypeInfo visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression, ExpressionTypingContext data) {
return basic.visitSimpleNameExpression(expression, data);
}