Tweak light classes to avoid computing stubs on certain api calls
Should speed up completion from java for certain cases
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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-2015 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
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.ClassFileViewProvider
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.impl.compiled.ClsFileImpl
|
||||
import com.intellij.psi.stubs.PsiClassHolderFileStub
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
open class FakeFileForLightClass(
|
||||
private val packageFqName: FqName,
|
||||
virtualFile: VirtualFile,
|
||||
psiManager: PsiManager,
|
||||
private val lightClass: KotlinLightClass,
|
||||
private val stub: () -> PsiClassHolderFileStub<*>
|
||||
) : ClsFileImpl(ClassFileViewProvider(psiManager, virtualFile)) {
|
||||
override fun getPackageName() = packageFqName.asString()
|
||||
|
||||
override fun getStub() = stub()
|
||||
|
||||
override fun getClasses() = arrayOf(lightClass)
|
||||
|
||||
override fun getNavigationElement() = this
|
||||
}
|
||||
+1
-1
@@ -465,7 +465,7 @@ public class KotlinJavaFileStubProvider<T extends WithFileStubAndExtraDiagnostic
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ClsFileImpl createFakeClsFile(
|
||||
private static ClsFileImpl createFakeClsFile(
|
||||
@NotNull Project project,
|
||||
@NotNull final FqName packageFqName,
|
||||
@NotNull Collection<JetFile> files,
|
||||
|
||||
+1
-11
@@ -19,14 +19,12 @@ package org.jetbrains.kotlin.asJava
|
||||
import com.intellij.openapi.util.Comparing
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.impl.compiled.ClsFileImpl
|
||||
import com.intellij.psi.impl.java.stubs.PsiJavaFileStub
|
||||
import com.intellij.psi.impl.light.LightClass
|
||||
import com.intellij.psi.impl.light.LightMethod
|
||||
import com.intellij.psi.scope.PsiScopeProcessor
|
||||
import com.intellij.psi.search.SearchScope
|
||||
import com.intellij.psi.stubs.IStubElementType
|
||||
import com.intellij.psi.stubs.PsiClassHolderFileStub
|
||||
import com.intellij.psi.stubs.StubElement
|
||||
import com.intellij.psi.util.CachedValue
|
||||
import com.intellij.psi.util.CachedValuesManager
|
||||
@@ -185,13 +183,7 @@ public open class KotlinLightClassForExplicitDeclaration(
|
||||
val virtualFile = classOrObject.containingFile.virtualFile
|
||||
assert(virtualFile != null) { "No virtual file for " + classOrObject.text }
|
||||
|
||||
object : ClsFileImpl(ClassFileViewProvider(getManager(), virtualFile)) {
|
||||
override fun getPackageName(): String {
|
||||
return classOrObject.getContainingJetFile().packageFqName.asString()
|
||||
}
|
||||
|
||||
override fun getStub(): PsiClassHolderFileStub<PsiJavaFile> = getJavaFileStub()
|
||||
|
||||
object : FakeFileForLightClass(classOrObject.getContainingJetFile().packageFqName, virtualFile, myManager, this, { getJavaFileStub() }) {
|
||||
override fun processDeclarations(
|
||||
processor: PsiScopeProcessor,
|
||||
state: ResolveState,
|
||||
@@ -244,8 +236,6 @@ public open class KotlinLightClassForExplicitDeclaration(
|
||||
|
||||
override fun getParent(): PsiElement? = _parent
|
||||
|
||||
override fun getContext(): PsiElement? = getParent()
|
||||
|
||||
private val _typeParameterList: PsiTypeParameterList by lazy {
|
||||
LightClassUtil.buildLightTypeParameterList(this, classOrObject)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Comparing
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.impl.compiled.ClsFileImpl
|
||||
import com.intellij.psi.impl.light.LightEmptyImplementsList
|
||||
import com.intellij.psi.impl.light.LightModifierList
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
@@ -116,8 +115,8 @@ public class KotlinLightClassForFacade private constructor(
|
||||
private val implementsList: LightEmptyImplementsList =
|
||||
LightEmptyImplementsList(manager)
|
||||
|
||||
private val packageClsFile: ClsFileImpl = KotlinJavaFileStubProvider.createFakeClsFile(manager.getProject(), packageFqName, files) {
|
||||
(getDelegate().getContainingFile() as ClsFileImpl).getStub()
|
||||
private val packageClsFile = FakeFileForLightClass(packageFqName, files.first().virtualFile!!, myManager, this) {
|
||||
lightClassDataCache.value.javaFileStub
|
||||
}
|
||||
|
||||
override fun getOrigin(): JetClassOrObject? = null
|
||||
@@ -190,8 +189,8 @@ public class KotlinLightClassForFacade private constructor(
|
||||
override fun copy() = KotlinLightClassForFacade(getManager(), facadeClassFqName, searchScope, lightClassDataCache, files, deprecated)
|
||||
|
||||
override fun getDelegate(): PsiClass {
|
||||
val psiClass = LightClassUtil.findClass(facadeClassFqName, lightClassDataCache.getValue().javaFileStub)
|
||||
?: throw IllegalStateException("Facade class $facadeClassFqName not found")
|
||||
val psiClass = LightClassUtil.findClass(facadeClassFqName, lightClassDataCache.value.javaFileStub)
|
||||
?: throw IllegalStateException("Facade class $facadeClassFqName not found")
|
||||
return psiClass
|
||||
}
|
||||
|
||||
|
||||
@@ -211,4 +211,9 @@ public abstract class KotlinWrappingLightClass extends AbstractLightClass implem
|
||||
|
||||
@Override
|
||||
public abstract int hashCode();
|
||||
|
||||
@Override
|
||||
public PsiElement getContext() {
|
||||
return getParent();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user