compiler: cleanup 'public', property access syntax

This commit is contained in:
Dmitry Jemerov
2016-01-07 17:57:35 +01:00
parent b72ea1ff07
commit 117a0d8b7b
488 changed files with 3147 additions and 3287 deletions
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.psi.psiUtil.isAncestor
/**
* Tested in OutOfBlockModificationTestGenerated
*/
public class KotlinCodeBlockModificationListener(modificationTracker: PsiModificationTracker) : PsiTreeChangePreprocessor {
class KotlinCodeBlockModificationListener(modificationTracker: PsiModificationTracker) : PsiTreeChangePreprocessor {
private val myModificationTracker = modificationTracker as PsiModificationTrackerImpl
override fun treeChanged(event: PsiTreeChangeEventImpl) {
@@ -106,7 +106,7 @@ public class KotlinCodeBlockModificationListener(modificationTracker: PsiModific
return false
}
public fun isInsideCodeBlock(element: PsiElement?): Boolean {
fun isInsideCodeBlock(element: PsiElement?): Boolean {
if (element is PsiFileSystemItem) return false
if (element == null || element.parent == null) return true
@@ -137,7 +137,7 @@ public class KotlinCodeBlockModificationListener(modificationTracker: PsiModific
return false
}
public fun isBlockDeclaration(declaration: KtDeclaration): Boolean {
fun isBlockDeclaration(declaration: KtDeclaration): Boolean {
return BLOCK_DECLARATION_TYPES.any { it.isInstance(declaration) }
}
@@ -23,9 +23,9 @@ import com.intellij.psi.scope.PsiScopeProcessor
import com.intellij.psi.ResolveState
import com.intellij.psi.PsiElement
public class KotlinLightTypeParameterListBuilder(manager: PsiManager): LightTypeParameterListBuilder(manager, KotlinLanguage.INSTANCE) {
class KotlinLightTypeParameterListBuilder(manager: PsiManager): LightTypeParameterListBuilder(manager, KotlinLanguage.INSTANCE) {
override fun processDeclarations(processor: PsiScopeProcessor, state: ResolveState, lastParent: PsiElement?, place: PsiElement): Boolean {
return getTypeParameters().all { processor.execute(it, state) }
return typeParameters.all { processor.execute(it, state) }
}
override fun getText(): String? = ""
@@ -20,6 +20,6 @@ import com.intellij.psi.PsiClass;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.psi.KtClassOrObject
public interface KtLightClass : PsiClass, KtLightElement<KtClassOrObject, PsiClass> {
public fun getFqName(): FqName
interface KtLightClass : PsiClass, KtLightElement<KtClassOrObject, PsiClass> {
fun getFqName(): FqName
}
@@ -50,7 +50,7 @@ import org.jetbrains.kotlin.resolve.jvm.JvmClassName
import java.util.*
import javax.swing.Icon
public open class KtLightClassForExplicitDeclaration(
open class KtLightClassForExplicitDeclaration(
protected val classFqName: FqName, // FqName of (possibly inner) class
protected val classOrObject: KtClassOrObject)
: KtWrappingLightClass(classOrObject.manager), KtJavaMirrorMarker, StubBasedPsiElement<KotlinClassOrObjectStub<out KtClassOrObject>> {
@@ -395,7 +395,7 @@ public open class KtLightClassForExplicitDeclaration(
FINAL_KEYWORD to PsiModifier.FINAL)
public fun create(classOrObject: KtClassOrObject): KtLightClassForExplicitDeclaration? {
fun create(classOrObject: KtClassOrObject): KtLightClassForExplicitDeclaration? {
val fqName = predictFqName(classOrObject) ?: return null
if (classOrObject is KtObjectDeclaration && classOrObject.isObjectLiteral()) {
@@ -414,11 +414,11 @@ public open class KtLightClassForExplicitDeclaration(
return if (internalName == null) null else JvmClassName.byInternalName(internalName).fqNameForClassNameWithoutDollars
}
public fun getLightClassData(classOrObject: KtClassOrObject): LightClassData {
fun getLightClassData(classOrObject: KtClassOrObject): LightClassData {
return getLightClassCachedValue(classOrObject).value
}
public fun getLightClassCachedValue(classOrObject: KtClassOrObject): CachedValue<WithFileStubAndExtraDiagnostics> {
fun getLightClassCachedValue(classOrObject: KtClassOrObject): CachedValue<WithFileStubAndExtraDiagnostics> {
val outermostClassOrObject = getOutermostClassOrObject(classOrObject)
var value = outermostClassOrObject.getUserData(JAVA_API_STUB)
if (value == null) {
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtFile
import javax.swing.Icon
public class KtLightClassForFacade private constructor(
class KtLightClassForFacade private constructor(
manager: PsiManager,
private val facadeClassFqName: FqName,
private val searchScope: GlobalSearchScope,
@@ -46,7 +46,7 @@ public class KtLightClassForFacade private constructor(
private data class StubCacheKey(val fqName: FqName, val searchScope: GlobalSearchScope)
public class FacadeStubCache(private val project: Project) {
class FacadeStubCache(private val project: Project) {
private inner class FacadeCacheData {
val cache = object : SLRUCache<StubCacheKey, CachedValue<KotlinFacadeLightClassData>>(20, 30) {
override fun createValue(key: StubCacheKey): CachedValue<KotlinFacadeLightClassData> {
@@ -60,20 +60,20 @@ public class KtLightClassForFacade private constructor(
{ CachedValueProvider.Result.create(FacadeCacheData(), PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT) },
/*trackValue = */ false)
public operator fun get(qualifiedName: FqName, searchScope: GlobalSearchScope): CachedValue<KotlinFacadeLightClassData> {
operator fun get(qualifiedName: FqName, searchScope: GlobalSearchScope): CachedValue<KotlinFacadeLightClassData> {
synchronized (cachedValue) {
return cachedValue.getValue().cache.get(StubCacheKey(qualifiedName, searchScope))
return cachedValue.value.cache.get(StubCacheKey(qualifiedName, searchScope))
}
}
companion object {
public fun getInstance(project: Project): FacadeStubCache {
fun getInstance(project: Project): FacadeStubCache {
return ServiceManager.getService<FacadeStubCache>(project, FacadeStubCache::class.java)
}
}
}
public val files: Collection<KtFile> = files.toSet() // needed for hashCode
val files: Collection<KtFile> = files.toSet() // needed for hashCode
private val hashCode: Int =
computeHashCode()
@@ -143,7 +143,7 @@ public class KtLightClassForFacade private constructor(
override fun getQualifiedName() = facadeClassFqName.asString()
override fun isValid() = files.all { it.isValid() }
override fun isValid() = files.all { it.isValid }
override fun copy() = KtLightClassForFacade(getManager(), facadeClassFqName, searchScope, lightClassDataCache, files, deprecated)
@@ -156,7 +156,7 @@ public class KtLightClassForFacade private constructor(
override fun getNavigationElement() = files.iterator().next()
override fun isEquivalentTo(another: PsiElement?): Boolean {
return another is PsiClass && Comparing.equal(another.getQualifiedName(), getQualifiedName())
return another is PsiClass && Comparing.equal(another.qualifiedName, getQualifiedName())
}
override fun getElementIcon(flags: Int): Icon? = throw UnsupportedOperationException("This should be done by JetIconProvider")
@@ -189,7 +189,7 @@ public class KtLightClassForFacade private constructor(
override fun toString() = "${KtLightClassForFacade::class.java.simpleName}:$facadeClassFqName"
companion object Factory {
public fun createForFacade(
fun createForFacade(
manager: PsiManager,
facadeClassFqName: FqName,
searchScope: GlobalSearchScope,
@@ -21,7 +21,7 @@ import com.intellij.util.IncorrectOperationException
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtClassOrObject
public open class KtLightClassForInterfaceDefaultImpls(
open class KtLightClassForInterfaceDefaultImpls(
classFqName: FqName,
classOrObject: KtClassOrObject)
: KtLightClassForExplicitDeclaration(classFqName, classOrObject){
@@ -20,8 +20,8 @@ import org.jetbrains.kotlin.psi.KtDeclaration
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiNamedElement
public interface KtLightElement<T : KtDeclaration, D : PsiElement> : PsiNamedElement {
public fun getOrigin(): T?
interface KtLightElement<T : KtDeclaration, D : PsiElement> : PsiNamedElement {
fun getOrigin(): T?
public fun getDelegate(): D
fun getDelegate(): D
}
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtEnumEntry
public interface KtLightField : PsiField, KtLightElement<KtDeclaration, PsiField>
interface KtLightField : PsiField, KtLightElement<KtDeclaration, PsiField>
// Copied from com.intellij.psi.impl.light.LightField
sealed class KtLightFieldImpl(
@@ -108,14 +108,14 @@ sealed class KtLightFieldImpl(
override fun getInitializingClass(): PsiEnumConstantInitializer? = initializingClass
override fun getOrCreateInitializingClass(): PsiEnumConstantInitializer =
initializingClass ?: throw UnsupportedOperationException("Can't create enum constant body: ${getDelegate().getName()}")
initializingClass ?: throw UnsupportedOperationException("Can't create enum constant body: ${getDelegate().name}")
override fun resolveConstructor() = getDelegate().resolveConstructor()
override fun resolveMethod() = getDelegate().resolveMethod()
override fun resolveMethodGenerics() = getDelegate().resolveMethodGenerics()
}
public class KtLightFieldForDeclaration(origin: KtDeclaration?, delegate: PsiField, containingClass: KtLightClass)
class KtLightFieldForDeclaration(origin: KtDeclaration?, delegate: PsiField, containingClass: KtLightClass)
: KtLightFieldImpl(origin, delegate, containingClass)
companion object Factory {
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind
public interface KtLightMethod : PsiMethod, KtLightElement<KtDeclaration, PsiMethod> {
interface KtLightMethod : PsiMethod, KtLightElement<KtDeclaration, PsiMethod> {
val isDelegated: Boolean
}
@@ -96,7 +96,7 @@ sealed class KtLightMethodImpl(
return this
}
public override fun delete() {
override fun delete() {
origin?.let {
if (it.isValid) {
it.delete()
@@ -147,7 +147,7 @@ abstract class LightClassDataProvider<T : WithFileStubAndExtraDiagnostics>(
fakeFile.isPhysical = false
javaFileStub.setPsi(fakeFile)
javaFileStub.psi = fakeFile
return javaFileStub
}
@@ -31,11 +31,11 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
public object LightClassUtil {
object LightClassUtil {
fun findClass(fqn: FqName, stub: StubElement<*>): PsiClass? {
if (stub is PsiClassStub<*> && Comparing.equal(fqn.asString(), stub.qualifiedName)) {
return stub.getPsi()
return stub.psi
}
if (stub is PsiClassStub<*> || stub is PsiFileStub<*>) {
@@ -48,22 +48,22 @@ public object LightClassUtil {
return null
}/*package*/
public fun getPsiClass(classOrObject: KtClassOrObject?): PsiClass? {
fun getPsiClass(classOrObject: KtClassOrObject?): PsiClass? {
if (classOrObject == null) return null
return LightClassGenerationSupport.getInstance(classOrObject.project).getPsiClass(classOrObject)
}
public fun getLightClassAccessorMethod(accessor: KtPropertyAccessor): PsiMethod? =
fun getLightClassAccessorMethod(accessor: KtPropertyAccessor): PsiMethod? =
getLightClassAccessorMethods(accessor).firstOrNull()
public fun getLightClassAccessorMethods(accessor: KtPropertyAccessor): List<PsiMethod> {
fun getLightClassAccessorMethods(accessor: KtPropertyAccessor): List<PsiMethod> {
val property = accessor.getNonStrictParentOfType<KtProperty>() ?: return emptyList()
val wrappers = getPsiMethodWrappers(property, true)
return wrappers.filter { wrapper -> (accessor.isGetter && !JvmAbi.isSetterName(wrapper.name)) ||
(accessor.isSetter && JvmAbi.isSetterName(wrapper.name)) }
}
public fun getLightFieldForCompanionObject(companionObject: KtClassOrObject): PsiField? {
fun getLightFieldForCompanionObject(companionObject: KtClassOrObject): PsiField? {
val outerPsiClass = getWrappingClass(companionObject)
if (outerPsiClass != null) {
for (fieldOfParent in outerPsiClass.fields) {
@@ -75,7 +75,7 @@ public object LightClassUtil {
return null
}
public fun getLightClassPropertyMethods(property: KtProperty): PropertyAccessorsPsiMethods {
fun getLightClassPropertyMethods(property: KtProperty): PropertyAccessorsPsiMethods {
val getter = property.getter
val setter = property.setter
@@ -109,15 +109,15 @@ public object LightClassUtil {
return null
}
public fun getLightClassPropertyMethods(parameter: KtParameter): PropertyAccessorsPsiMethods {
fun getLightClassPropertyMethods(parameter: KtParameter): PropertyAccessorsPsiMethods {
return extractPropertyAccessors(parameter, null, null)
}
public fun getLightClassMethod(function: KtFunction): PsiMethod? {
fun getLightClassMethod(function: KtFunction): PsiMethod? {
return getPsiMethodWrapper(function)
}
public fun getLightClassMethods(function: KtFunction): List<PsiMethod> {
fun getLightClassMethods(function: KtFunction): List<PsiMethod> {
return getPsiMethodWrappers(function, true)
}
@@ -189,7 +189,7 @@ public object LightClassUtil {
return null
}
public fun canGenerateLightClass(declaration: KtDeclaration): Boolean {
fun canGenerateLightClass(declaration: KtDeclaration): Boolean {
//noinspection unchecked
return PsiTreeUtil.getParentOfType(declaration, KtFunction::class.java, KtProperty::class.java) == null
}
@@ -206,7 +206,7 @@ public object LightClassUtil {
}
for (wrapper in wrappers) {
if (JvmAbi.isSetterName(wrapper.getName())) {
if (JvmAbi.isSetterName(wrapper.name)) {
if (setterWrapper == null || setterWrapper === specialSetter) {
setterWrapper = wrapper
}
@@ -228,7 +228,7 @@ public object LightClassUtil {
return PropertyAccessorsPsiMethods(getterWrapper, setterWrapper, backingField, additionalAccessors)
}
public fun buildLightTypeParameterList(
fun buildLightTypeParameterList(
owner: PsiTypeParameterListOwner,
declaration: KtDeclaration): PsiTypeParameterList {
val builder = KotlinLightTypeParameterListBuilder(owner.manager)
@@ -244,9 +244,9 @@ public object LightClassUtil {
return builder
}
public class PropertyAccessorsPsiMethods(public val getter: PsiMethod?,
public val setter: PsiMethod?,
public val backingField: PsiField?,
class PropertyAccessorsPsiMethods(val getter: PsiMethod?,
val setter: PsiMethod?,
val backingField: PsiField?,
additionalAccessors: List<PsiMethod>) : Iterable<PsiMethod> {
private val allMethods: List<PsiMethod>
val allDeclarations: List<PsiNamedElement>
@@ -30,12 +30,12 @@ import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.*
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind.*
public fun getJvmSignatureDiagnostics(element: PsiElement, otherDiagnostics: Diagnostics, moduleScope: GlobalSearchScope): Diagnostics? {
fun getJvmSignatureDiagnostics(element: PsiElement, otherDiagnostics: Diagnostics, moduleScope: GlobalSearchScope): Diagnostics? {
fun getDiagnosticsForFileFacade(file: KtFile): Diagnostics? {
val project = file.project
val cache = KtLightClassForFacade.FacadeStubCache.getInstance(project)
val facadeFqName = NoResolveFileClassesProvider.getFileClassInfo(file).facadeClassFqName
return cache[facadeFqName, moduleScope].getValue()?.extraDiagnostics
return cache[facadeFqName, moduleScope].value?.extraDiagnostics
}
fun getDiagnosticsForClass(ktClassOrObject: KtClassOrObject): Diagnostics {
@@ -46,13 +46,13 @@ public fun getJvmSignatureDiagnostics(element: PsiElement, otherDiagnostics: Dia
//TODO: enable this diagnostic when light classes for scripts are ready
if ((element.containingFile as? KtFile)?.isScript ?: false) return null
var parent = element.getParent()
var parent = element.parent
if (element is KtPropertyAccessor) {
parent = parent?.getParent()
parent = parent?.parent
}
if (element is KtParameter && element.hasValOrVar()) {
// property declared in constructor
val parentClass = (parent?.getParent()?.getParent() as? KtClass)
val parentClass = (parent?.parent?.parent as? KtClass)
if (parentClass != null) {
return getDiagnosticsForClass(parentClass)
}
@@ -87,14 +87,14 @@ class FilteredJvmDiagnostics(val jvmDiagnostics: Diagnostics, val otherDiagnosti
private fun alreadyReported(psiElement: PsiElement): Boolean {
val higherPriority = setOf<DiagnosticFactory<*>>(
CONFLICTING_OVERLOADS, REDECLARATION, NOTHING_TO_OVERRIDE, MANY_IMPL_MEMBER_NOT_IMPLEMENTED)
return otherDiagnostics.forElement(psiElement).any { it.getFactory() in higherPriority }
return otherDiagnostics.forElement(psiElement).any { it.factory in higherPriority }
|| psiElement is KtPropertyAccessor && alreadyReported(psiElement.getParent()!!)
}
override fun forElement(psiElement: PsiElement): Collection<Diagnostic> {
val jvmDiagnosticFactories = setOf(CONFLICTING_JVM_DECLARATIONS, ACCIDENTAL_OVERRIDE, CONFLICTING_INHERITED_JVM_DECLARATIONS)
fun Diagnostic.data() = cast(this, jvmDiagnosticFactories).getA()
val (conflicting, other) = jvmDiagnostics.forElement(psiElement).partition { it.getFactory() in jvmDiagnosticFactories }
val (conflicting, other) = jvmDiagnostics.forElement(psiElement).partition { it.factory in jvmDiagnosticFactories }
if (alreadyReported(psiElement)) {
// CONFLICTING_OVERLOADS already reported, no need to duplicate it
return other
@@ -132,7 +132,7 @@ class FilteredJvmDiagnostics(val jvmDiagnostics: Diagnostics, val otherDiagnosti
override fun all(): Collection<Diagnostic> {
return jvmDiagnostics.all()
.map { it.getPsiElement() }
.map { it.psiElement }
.toSet()
.flatMap { forElement(it) }
}
@@ -28,15 +28,15 @@ import org.jetbrains.kotlin.utils.addToStdlib.singletonList
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
import java.util.*
public fun KtClassOrObject.toLightClass(): KtLightClass? = LightClassUtil.getPsiClass(this) as KtLightClass?
fun KtClassOrObject.toLightClass(): KtLightClass? = LightClassUtil.getPsiClass(this) as KtLightClass?
public fun KtFile.findFacadeClass(): KtLightClass? {
fun KtFile.findFacadeClass(): KtLightClass? {
return LightClassGenerationSupport.getInstance(project)
.getFacadeClassesInPackage(packageFqName, this.useScope as? GlobalSearchScope ?: GlobalSearchScope.projectScope(project))
.firstOrNull { it is KtLightClassForFacade && this in it.files } as? KtLightClass
}
public fun KtDeclaration.toLightElements(): List<PsiNamedElement> =
fun KtDeclaration.toLightElements(): List<PsiNamedElement> =
when (this) {
is KtClassOrObject -> LightClassUtil.getPsiClass(this).singletonOrEmptyList()
is KtNamedFunction,
@@ -53,7 +53,7 @@ public fun KtDeclaration.toLightElements(): List<PsiNamedElement> =
else -> listOf()
}
public fun PsiElement.toLightMethods(): List<PsiMethod> =
fun PsiElement.toLightMethods(): List<PsiMethod> =
when (this) {
is KtFunction -> LightClassUtil.getLightClassMethods(this)
is KtProperty -> LightClassUtil.getLightClassPropertyMethods(this).toList()
@@ -64,7 +64,7 @@ public fun PsiElement.toLightMethods(): List<PsiMethod> =
else -> listOf()
}
public fun PsiElement.getRepresentativeLightMethod(): PsiMethod? =
fun PsiElement.getRepresentativeLightMethod(): PsiMethod? =
when (this) {
is KtFunction -> LightClassUtil.getLightClassMethod(this)
is KtProperty -> LightClassUtil.getLightClassPropertyMethods(this).getter
@@ -74,7 +74,7 @@ public fun PsiElement.getRepresentativeLightMethod(): PsiMethod? =
else -> null
}
public fun KtParameter.toPsiParameters(): Collection<PsiParameter> {
fun KtParameter.toPsiParameters(): Collection<PsiParameter> {
val paramList = getNonStrictParentOfType<KtParameterList>() ?: return emptyList()
val paramIndex = paramList.getParameters().indexOf(this)
@@ -88,10 +88,10 @@ public fun KtParameter.toPsiParameters(): Collection<PsiParameter> {
else -> null
} ?: return emptyList()
return methods.map { it.getParameterList().getParameters()[lightParamIndex] }
return methods.map { it.parameterList.parameters[lightParamIndex] }
}
public fun KtTypeParameter.toPsiTypeParameters(): List<PsiTypeParameter> {
fun KtTypeParameter.toPsiTypeParameters(): List<PsiTypeParameter> {
val paramList = getNonStrictParentOfType<KtTypeParameterList>()
if (paramList == null) return listOf()
@@ -99,14 +99,14 @@ public fun KtTypeParameter.toPsiTypeParameters(): List<PsiTypeParameter> {
val jetDeclaration = paramList.getNonStrictParentOfType<KtDeclaration>() ?: return listOf()
val lightOwners = jetDeclaration.toLightElements()
return lightOwners.map { lightOwner -> (lightOwner as PsiTypeParameterListOwner).getTypeParameters()[paramIndex] }
return lightOwners.map { lightOwner -> (lightOwner as PsiTypeParameterListOwner).typeParameters[paramIndex] }
}
// Returns original declaration if given PsiElement is a Kotlin light element, and element itself otherwise
public val PsiElement.unwrapped: PsiElement?
val PsiElement.unwrapped: PsiElement?
get() = if (this is KtLightElement<*, *>) getOrigin() else this
public val PsiElement.namedUnwrappedElement: PsiNamedElement?
val PsiElement.namedUnwrappedElement: PsiNamedElement?
get() = unwrapped?.getNonStrictParentOfType<PsiNamedElement>()