Revert "Revert "[light classes] drop old light classes and backend: iteration #6""
This reverts commit 8db53c0ca7.
This commit is contained in:
+2
-2
@@ -12,12 +12,12 @@ import com.intellij.psi.util.CachedValuesManager
|
||||
import org.jetbrains.kotlin.asJava.KotlinAsJavaSupport
|
||||
import org.jetbrains.kotlin.asJava.KotlinExtraDiagnosticsProvider
|
||||
import org.jetbrains.kotlin.asJava.LightClassGenerationSupport
|
||||
import org.jetbrains.kotlin.asJava.builder.LightClassDataHolder
|
||||
import org.jetbrains.kotlin.asJava.builder.buildLightClass
|
||||
import org.jetbrains.kotlin.asJava.classes.getOutermostClassOrObject
|
||||
import org.jetbrains.kotlin.asJava.classes.safeIsLocal
|
||||
import org.jetbrains.kotlin.asJava.classes.safeScript
|
||||
import org.jetbrains.kotlin.asJava.classes.shouldNotBeVisibleAsLightClass
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.builder.LightClassDataHolder
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.builder.buildLightClass
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
+3
-5
@@ -6,16 +6,12 @@
|
||||
package org.jetbrains.kotlin.cli.jvm.compiler
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.asJava.LightClassBuilder
|
||||
import org.jetbrains.kotlin.asJava.LightClassGenerationSupport
|
||||
import org.jetbrains.kotlin.asJava.builder.InvalidLightClassDataHolder
|
||||
import org.jetbrains.kotlin.asJava.builder.LightClassConstructionContext
|
||||
import org.jetbrains.kotlin.asJava.builder.LightClassDataHolder
|
||||
import org.jetbrains.kotlin.asJava.builder.LightClassDataHolderImpl
|
||||
import org.jetbrains.kotlin.asJava.classes.KtUltraLightSupport
|
||||
import org.jetbrains.kotlin.asJava.classes.cleanFromAnonymousTypes
|
||||
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||
import org.jetbrains.kotlin.asJava.classes.tryGetPredefinedName
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.builder.*
|
||||
import org.jetbrains.kotlin.codegen.ClassBuilderMode
|
||||
import org.jetbrains.kotlin.codegen.JvmCodegenUtil
|
||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
|
||||
@@ -129,3 +125,5 @@ class CliLightClassGenerationSupport(
|
||||
|
||||
override fun analyzeWithContent(element: KtClassOrObject) = traceHolder.bindingContext
|
||||
}
|
||||
|
||||
typealias LightClassBuilder = (LightClassConstructionContext) -> LightClassBuilderResult
|
||||
|
||||
@@ -10,10 +10,10 @@ import com.intellij.psi.util.CachedValueProvider
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.analyzer.KotlinModificationTrackerService
|
||||
import org.jetbrains.kotlin.asJava.LightClassGenerationSupport
|
||||
import org.jetbrains.kotlin.asJava.builder.LightClassDataHolder
|
||||
import org.jetbrains.kotlin.asJava.builder.buildLightClass
|
||||
import org.jetbrains.kotlin.asJava.classes.getOutermostClassOrObject
|
||||
import org.jetbrains.kotlin.asJava.classes.safeIsLocal
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.builder.LightClassDataHolder
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.builder.buildLightClass
|
||||
import org.jetbrains.kotlin.codegen.MemberCodegen
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
|
||||
|
||||
+7
-16
@@ -1,20 +1,9 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.asJava.builder
|
||||
package org.jetbrains.kotlin.cli.jvm.compiler.builder
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.psi.PsiElement
|
||||
@@ -33,7 +22,8 @@ class KotlinLightClassBuilderFactory(private val javaFileStub: PsiJavaFileStub)
|
||||
}
|
||||
|
||||
override fun getClassBuilderMode(): ClassBuilderMode = ClassBuilderMode.LIGHT_CLASSES
|
||||
override fun newClassBuilder(origin: JvmDeclarationOrigin) = StubClassBuilder(stubStack, javaFileStub)
|
||||
override fun newClassBuilder(origin: JvmDeclarationOrigin) =
|
||||
StubClassBuilder(stubStack, javaFileStub)
|
||||
|
||||
override fun asText(builder: ClassBuilder) = throw UnsupportedOperationException("asText is not implemented")
|
||||
override fun asBytes(builder: ClassBuilder) = throw UnsupportedOperationException("asBytes is not implemented")
|
||||
@@ -42,8 +32,9 @@ class KotlinLightClassBuilderFactory(private val javaFileStub: PsiJavaFileStub)
|
||||
fun result(): PsiJavaFileStub {
|
||||
val pop = stubStack.pop()
|
||||
if (pop !== javaFileStub) {
|
||||
LOG.error("Unbalanced stack operations: " + pop)
|
||||
LOG.error("Unbalanced stack operations: $pop")
|
||||
}
|
||||
|
||||
return javaFileStub
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -3,7 +3,7 @@
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.asJava.builder
|
||||
package org.jetbrains.kotlin.cli.jvm.compiler.builder
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.progress.ProcessCanceledException
|
||||
@@ -13,6 +13,7 @@ import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.impl.compiled.ClsFileImpl
|
||||
import com.intellij.psi.impl.java.stubs.PsiJavaFileStub
|
||||
import com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl
|
||||
import org.jetbrains.kotlin.asJava.builder.ClsWrapperStubPsiFactory
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.jvm.compiler.builder
|
||||
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
|
||||
open class LightClassConstructionContext(
|
||||
val bindingContext: BindingContext,
|
||||
val module: ModuleDescriptor,
|
||||
val languageVersionSettings: LanguageVersionSettings?,
|
||||
val jvmTarget: JvmTarget,
|
||||
)
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.asJava.builder
|
||||
package org.jetbrains.kotlin.cli.jvm.compiler.builder
|
||||
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
|
||||
|
||||
+6
-16
@@ -1,20 +1,9 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.asJava.builder;
|
||||
package org.jetbrains.kotlin.cli.jvm.compiler.builder;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.impl.compiled.InnerClassSourceStrategy;
|
||||
@@ -26,6 +15,9 @@ import com.intellij.psi.stubs.StubElement;
|
||||
import com.intellij.util.containers.Stack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.asJava.builder.ClsWrapperStubPsiFactory;
|
||||
import org.jetbrains.kotlin.asJava.builder.LightElementOrigin;
|
||||
import org.jetbrains.kotlin.asJava.builder.LightElementOriginKt;
|
||||
import org.jetbrains.kotlin.codegen.AbstractClassBuilder;
|
||||
import org.jetbrains.kotlin.fileClasses.OldPackageFacadeClassUtils;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
@@ -54,7 +46,6 @@ public class StubClassBuilder extends AbstractClassBuilder {
|
||||
private StubBuildingVisitor v;
|
||||
private final Stack<StubElement> parentStack;
|
||||
private boolean isPackageClass = false;
|
||||
private int memberIndex = 0;
|
||||
|
||||
public StubClassBuilder(@NotNull Stack<StubElement> parentStack, @NotNull PsiJavaFileStub fileStub) {
|
||||
this.parentStack = parentStack;
|
||||
@@ -199,7 +190,6 @@ public class StubClassBuilder extends AbstractClassBuilder {
|
||||
}
|
||||
|
||||
last.putUserData(ClsWrapperStubPsiFactory.ORIGIN, LightElementOriginKt.toLightMemberOrigin(origin));
|
||||
last.putUserData(MemberIndex.KEY, new MemberIndex(memberIndex++));
|
||||
}
|
||||
|
||||
@Override
|
||||
+5
-1
@@ -3,10 +3,14 @@
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.asJava.builder
|
||||
package org.jetbrains.kotlin.cli.jvm.compiler.builder
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.impl.java.stubs.PsiJavaFileStub
|
||||
|
||||
fun stubComputationTrackerInstance(project: Project): StubComputationTracker? {
|
||||
return project.getComponent(StubComputationTracker::class.java)
|
||||
}
|
||||
|
||||
interface StubComputationTracker {
|
||||
fun onStubComputed(javaFileStub: PsiJavaFileStub, context: LightClassConstructionContext)
|
||||
@@ -8,8 +8,6 @@ package org.jetbrains.kotlin.asJava
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiManager
|
||||
import org.jetbrains.kotlin.asJava.builder.LightClassBuilderResult
|
||||
import org.jetbrains.kotlin.asJava.builder.LightClassConstructionContext
|
||||
import org.jetbrains.kotlin.asJava.classes.*
|
||||
import org.jetbrains.kotlin.config.AnalysisFlags
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
@@ -21,8 +19,6 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor
|
||||
|
||||
typealias LightClassBuilder = (LightClassConstructionContext) -> LightClassBuilderResult
|
||||
|
||||
abstract class LightClassGenerationSupport {
|
||||
abstract fun resolveToDescriptor(declaration: KtDeclaration): DeclarationDescriptor?
|
||||
|
||||
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.asJava.builder
|
||||
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
|
||||
open class LightClassConstructionContext(
|
||||
val bindingContext: BindingContext,
|
||||
val module: ModuleDescriptor,
|
||||
val languageVersionSettings: LanguageVersionSettings?,
|
||||
val jvmTarget: JvmTarget,
|
||||
)
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.asJava.builder
|
||||
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.openapi.util.UserDataHolder
|
||||
import com.intellij.psi.PsiMember
|
||||
import com.intellij.psi.StubBasedPsiElement
|
||||
|
||||
data class MemberIndex(private val index: Int) {
|
||||
companion object {
|
||||
@JvmField
|
||||
val KEY = Key.create<MemberIndex>("MEMBER_INDEX")
|
||||
}
|
||||
}
|
||||
|
||||
val PsiMember.memberIndex: MemberIndex?
|
||||
get() = ((this as? StubBasedPsiElement<*>)?.stub as? UserDataHolder)?.getUserData(MemberIndex.KEY)
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.asJava.builder
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
|
||||
fun stubComputationTrackerInstance(project: Project): StubComputationTracker? {
|
||||
return project.getComponent(StubComputationTracker::class.java)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ import com.intellij.psi.javadoc.PsiDocComment
|
||||
import com.intellij.psi.util.MethodSignature
|
||||
import com.intellij.psi.util.MethodSignatureBackedByPsiMethod
|
||||
import org.jetbrains.kotlin.asJava.builder.LightMemberOriginForDeclaration
|
||||
import org.jetbrains.kotlin.asJava.builder.MemberIndex
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightAbstractAnnotation
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightMethodImpl
|
||||
import org.jetbrains.kotlin.asJava.elements.KtUltraLightModifierList
|
||||
@@ -122,10 +121,7 @@ internal abstract class KtUltraLightMethod(
|
||||
|
||||
abstract val checkNeedToErasureParametersTypes: Boolean
|
||||
|
||||
override val memberIndex: MemberIndex? = null
|
||||
|
||||
override val psiTypeForNullabilityAnnotation: PsiType?
|
||||
get() = returnType
|
||||
override val psiTypeForNullabilityAnnotation: PsiType? get() = returnType
|
||||
|
||||
// These two overrides are necessary because ones from KtLightMethodImpl suppose that clsDelegate.returnTypeElement is valid
|
||||
// While here we only set return type for LightMethodBuilder (see org.jetbrains.kotlin.asJava.classes.KtUltraLightClass.asJavaMethod)
|
||||
|
||||
+1
-7
@@ -13,7 +13,6 @@ import com.intellij.psi.util.MethodSignatureBackedByPsiMethod
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.asJava.*
|
||||
import org.jetbrains.kotlin.asJava.builder.LightMemberOriginForDeclaration
|
||||
import org.jetbrains.kotlin.asJava.builder.MemberIndex
|
||||
import org.jetbrains.kotlin.asJava.classes.KtLightClass
|
||||
import org.jetbrains.kotlin.asJava.classes.cannotModify
|
||||
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||
@@ -98,8 +97,6 @@ abstract class KtLightMethodImpl protected constructor(
|
||||
return typeParameters.all { processor.execute(it, state) }
|
||||
}
|
||||
|
||||
protected abstract val memberIndex: MemberIndex?
|
||||
|
||||
/* comparing origin and member index should be enough to determine equality:
|
||||
for compiled elements origin contains delegate
|
||||
for source elements index is unique to each member
|
||||
@@ -107,13 +104,10 @@ abstract class KtLightMethodImpl protected constructor(
|
||||
override fun equals(other: Any?): Boolean = other === this ||
|
||||
other is KtLightMethodImpl &&
|
||||
other.javaClass == javaClass &&
|
||||
other.memberIndex == memberIndex &&
|
||||
other.containingClass == containingClass &&
|
||||
other.lightMemberOrigin == lightMemberOrigin
|
||||
|
||||
override fun hashCode(): Int = name.hashCode()
|
||||
.times(31).plus(containingClass.hashCode())
|
||||
.times(31).plus(memberIndex.hashCode())
|
||||
override fun hashCode(): Int = name.hashCode().times(31).plus(containingClass.hashCode())
|
||||
|
||||
abstract override fun getDefaultValue(): PsiAnnotationMemberValue?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user