Minor code simplifications using Kotlin
This commit is contained in:
@@ -57,9 +57,7 @@ public class WritableScopeImpl(scope: JetScope,
|
|||||||
|
|
||||||
private var implicitReceiver: ReceiverParameterDescriptor? = null
|
private var implicitReceiver: ReceiverParameterDescriptor? = null
|
||||||
|
|
||||||
override fun getContainingDeclaration(): DeclarationDescriptor {
|
override fun getContainingDeclaration(): DeclarationDescriptor = ownerDeclarationDescriptor
|
||||||
return ownerDeclarationDescriptor
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun importScope(imported: JetScope) {
|
override fun importScope(imported: JetScope) {
|
||||||
checkMayWrite()
|
checkMayWrite()
|
||||||
@@ -129,15 +127,10 @@ public class WritableScopeImpl(scope: JetScope,
|
|||||||
checkMayRead()
|
checkMayRead()
|
||||||
|
|
||||||
val superResult = super.getDeclarationsByLabel(labelName)
|
val superResult = super.getDeclarationsByLabel(labelName)
|
||||||
val labelsToDescriptors = getLabelsToDescriptors()
|
val declarationDescriptors = getLabelsToDescriptors()[labelName]
|
||||||
val declarationDescriptors = labelsToDescriptors.get(labelName)
|
if (declarationDescriptors == null) return superResult
|
||||||
if (declarationDescriptors == null) {
|
|
||||||
return superResult
|
|
||||||
}
|
|
||||||
if (superResult.isEmpty()) return declarationDescriptors
|
if (superResult.isEmpty()) return declarationDescriptors
|
||||||
val result = ArrayList(declarationDescriptors)
|
return declarationDescriptors + superResult
|
||||||
result.addAll(superResult)
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addLabeledDeclaration(descriptor: DeclarationDescriptor) {
|
override fun addLabeledDeclaration(descriptor: DeclarationDescriptor) {
|
||||||
@@ -207,17 +200,12 @@ public class WritableScopeImpl(scope: JetScope,
|
|||||||
override fun getLocalVariable(name: Name): VariableDescriptor? {
|
override fun getLocalVariable(name: Name): VariableDescriptor? {
|
||||||
checkMayRead()
|
checkMayRead()
|
||||||
|
|
||||||
val variableOrClassDescriptors = getVariableOrClassDescriptors()
|
val descriptor = getVariableOrClassDescriptors()[name]
|
||||||
val descriptor = variableOrClassDescriptors.get(name)
|
if (descriptor is VariableDescriptor && !getPropertyGroups()[name].contains(descriptor)) {
|
||||||
if (descriptor is VariableDescriptor && !getPropertyGroups().get(name).contains(descriptor)) {
|
|
||||||
return descriptor
|
return descriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
val variableDescriptor = workerScope.getLocalVariable(name)
|
return workerScope.getLocalVariable(name) ?: super.getLocalVariable(name)
|
||||||
if (variableDescriptor != null) {
|
|
||||||
return variableDescriptor
|
|
||||||
}
|
|
||||||
return super.getLocalVariable(name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getPropertyGroups(): SetMultimap<Name, VariableDescriptor> {
|
private fun getPropertyGroups(): SetMultimap<Name, VariableDescriptor> {
|
||||||
@@ -256,8 +244,7 @@ public class WritableScopeImpl(scope: JetScope,
|
|||||||
override fun addTypeParameterDescriptor(typeParameterDescriptor: TypeParameterDescriptor) {
|
override fun addTypeParameterDescriptor(typeParameterDescriptor: TypeParameterDescriptor) {
|
||||||
checkMayWrite()
|
checkMayWrite()
|
||||||
|
|
||||||
val name = typeParameterDescriptor.getName()
|
addClassifierAlias(typeParameterDescriptor.getName(), typeParameterDescriptor)
|
||||||
addClassifierAlias(name, typeParameterDescriptor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addClassifierDescriptor(classDescriptor: ClassifierDescriptor) {
|
override fun addClassifierDescriptor(classDescriptor: ClassifierDescriptor) {
|
||||||
@@ -305,18 +292,20 @@ public class WritableScopeImpl(scope: JetScope,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkForPropertyRedeclaration(name: Name, variableDescriptor: VariableDescriptor) {
|
private fun checkForPropertyRedeclaration(name: Name, variableDescriptor: VariableDescriptor) {
|
||||||
val properties = getPropertyGroups().get(name)
|
val properties = getPropertyGroups()[name]
|
||||||
val receiverParameter = variableDescriptor.getExtensionReceiverParameter()
|
val receiverParameter = variableDescriptor.getExtensionReceiverParameter()
|
||||||
for (oldProperty in properties) {
|
for (oldProperty in properties) {
|
||||||
val receiverParameterForOldVariable = oldProperty.getExtensionReceiverParameter()
|
val receiverParameterForOldVariable = oldProperty.getExtensionReceiverParameter()
|
||||||
if (((receiverParameter != null && receiverParameterForOldVariable != null) && (JetTypeChecker.DEFAULT.equalTypes(receiverParameter.getType(), receiverParameterForOldVariable.getType())))) {
|
if (receiverParameter != null
|
||||||
|
&& receiverParameterForOldVariable != null
|
||||||
|
&& JetTypeChecker.DEFAULT.equalTypes(receiverParameter.getType(), receiverParameterForOldVariable.getType())) {
|
||||||
redeclarationHandler.handleRedeclaration(oldProperty, variableDescriptor)
|
redeclarationHandler.handleRedeclaration(oldProperty, variableDescriptor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkForRedeclaration(name: Name, classifierDescriptor: DeclarationDescriptor) {
|
private fun checkForRedeclaration(name: Name, classifierDescriptor: DeclarationDescriptor) {
|
||||||
val originalDescriptor = getVariableOrClassDescriptors().get(name)
|
val originalDescriptor = getVariableOrClassDescriptors()[name]
|
||||||
if (originalDescriptor != null) {
|
if (originalDescriptor != null) {
|
||||||
redeclarationHandler.handleRedeclaration(originalDescriptor, classifierDescriptor)
|
redeclarationHandler.handleRedeclaration(originalDescriptor, classifierDescriptor)
|
||||||
}
|
}
|
||||||
@@ -325,25 +314,17 @@ public class WritableScopeImpl(scope: JetScope,
|
|||||||
override fun getClassifier(name: Name): ClassifierDescriptor? {
|
override fun getClassifier(name: Name): ClassifierDescriptor? {
|
||||||
checkMayRead()
|
checkMayRead()
|
||||||
|
|
||||||
val variableOrClassDescriptors = getVariableOrClassDescriptors()
|
return getVariableOrClassDescriptors()[name] as? ClassifierDescriptor
|
||||||
val descriptor = variableOrClassDescriptors.get(name)
|
?: workerScope.getClassifier(name)
|
||||||
if (descriptor is ClassifierDescriptor) return descriptor
|
?: super.getClassifier(name)
|
||||||
|
|
||||||
val classifierDescriptor = workerScope.getClassifier(name)
|
|
||||||
if (classifierDescriptor != null) return classifierDescriptor
|
|
||||||
|
|
||||||
return super.getClassifier(name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getPackage(name: Name): PackageViewDescriptor? {
|
override fun getPackage(name: Name): PackageViewDescriptor? {
|
||||||
checkMayRead()
|
checkMayRead()
|
||||||
|
|
||||||
val aliased = getPackageAliases().get(name)
|
return getPackageAliases().get(name)
|
||||||
if (aliased != null) return aliased
|
?: workerScope.getPackage(name)
|
||||||
|
?: super.getPackage(name)
|
||||||
val packageView = workerScope.getPackage(name)
|
|
||||||
if (packageView != null) return packageView
|
|
||||||
return super.getPackage(name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setImplicitReceiver(implicitReceiver: ReceiverParameterDescriptor) {
|
override fun setImplicitReceiver(implicitReceiver: ReceiverParameterDescriptor) {
|
||||||
@@ -356,25 +337,21 @@ public class WritableScopeImpl(scope: JetScope,
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun computeImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> {
|
override fun computeImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> {
|
||||||
val implicitReceiverHierarchy = ArrayList<ReceiverParameterDescriptor>()
|
return if (implicitReceiver != null)
|
||||||
if (implicitReceiver != null) {
|
listOf(implicitReceiver!!) + super.computeImplicitReceiversHierarchy()
|
||||||
implicitReceiverHierarchy.add(implicitReceiver)
|
else
|
||||||
}
|
super.computeImplicitReceiversHierarchy()
|
||||||
implicitReceiverHierarchy.addAll(super.computeImplicitReceiversHierarchy())
|
|
||||||
return implicitReceiverHierarchy
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addToDeclared(descriptor: DeclarationDescriptor) {
|
private fun addToDeclared(descriptor: DeclarationDescriptor) {
|
||||||
declaredDescriptorsAccessibleBySimpleName.put(descriptor.getName(), descriptor)
|
declaredDescriptorsAccessibleBySimpleName.put(descriptor.getName(), descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDeclaredDescriptorsAccessibleBySimpleName(): Multimap<Name, DeclarationDescriptor> {
|
override fun getDeclaredDescriptorsAccessibleBySimpleName(): Multimap<Name, DeclarationDescriptor>
|
||||||
return declaredDescriptorsAccessibleBySimpleName
|
= declaredDescriptorsAccessibleBySimpleName
|
||||||
}
|
|
||||||
|
|
||||||
override fun getOwnDeclaredDescriptors(): Collection<DeclarationDescriptor> {
|
override fun getOwnDeclaredDescriptors(): Collection<DeclarationDescriptor>
|
||||||
return declaredDescriptorsAccessibleBySimpleName.values()
|
= declaredDescriptorsAccessibleBySimpleName.values()
|
||||||
}
|
|
||||||
|
|
||||||
override fun printAdditionalScopeStructure(p: Printer) {
|
override fun printAdditionalScopeStructure(p: Printer) {
|
||||||
p.println("allDescriptorsDone = ", allDescriptorsDone)
|
p.println("allDescriptorsDone = ", allDescriptorsDone)
|
||||||
|
|||||||
Reference in New Issue
Block a user