Drop TraceBasedJavaResolverCache, inline into LazyResolveBasedCache
This commit is contained in:
+13
-12
@@ -17,45 +17,46 @@
|
|||||||
package org.jetbrains.kotlin.load.java.components
|
package org.jetbrains.kotlin.load.java.components
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
import org.jetbrains.kotlin.load.java.structure.*
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaElement
|
import org.jetbrains.kotlin.load.java.structure.impl.*
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaField
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaMethod
|
|
||||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSessionUtils
|
import org.jetbrains.kotlin.resolve.lazy.ResolveSessionUtils
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
import org.jetbrains.kotlin.name.tail
|
import org.jetbrains.kotlin.name.tail
|
||||||
|
import org.jetbrains.kotlin.resolve.BindingContext.*
|
||||||
|
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||||
|
import org.jetbrains.kotlin.resolve.BindingContextUtils
|
||||||
|
|
||||||
public class LazyResolveBasedCache() : JavaResolverCache {
|
public class LazyResolveBasedCache : JavaResolverCache {
|
||||||
private var resolveSession by Delegates.notNull<ResolveSession>()
|
private var resolveSession by Delegates.notNull<ResolveSession>()
|
||||||
private val traceBasedCache = TraceBasedJavaResolverCache()
|
|
||||||
|
private val trace: BindingTrace get() = resolveSession.getTrace()
|
||||||
|
|
||||||
Inject
|
Inject
|
||||||
public fun setSession(resolveSession: ResolveSession) {
|
public fun setSession(resolveSession: ResolveSession) {
|
||||||
this.resolveSession = resolveSession
|
this.resolveSession = resolveSession
|
||||||
traceBasedCache.setTrace(this.resolveSession.getTrace())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getClassResolvedFromSource(fqName: FqName): ClassDescriptor? {
|
override fun getClassResolvedFromSource(fqName: FqName): ClassDescriptor? {
|
||||||
return traceBasedCache.getClassResolvedFromSource(fqName) ?: findInPackageFragments(fqName)
|
return trace.get(FQNAME_TO_CLASS_DESCRIPTOR, fqName.toUnsafe()) ?: findInPackageFragments(fqName)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun recordMethod(method: JavaMethod, descriptor: SimpleFunctionDescriptor) {
|
override fun recordMethod(method: JavaMethod, descriptor: SimpleFunctionDescriptor) {
|
||||||
traceBasedCache.recordMethod(method, descriptor)
|
BindingContextUtils.recordFunctionDeclarationToDescriptor(trace, (method as JavaMethodImpl).getPsi(), descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun recordConstructor(element: JavaElement, descriptor: ConstructorDescriptor) {
|
override fun recordConstructor(element: JavaElement, descriptor: ConstructorDescriptor) {
|
||||||
traceBasedCache.recordConstructor(element, descriptor)
|
trace.record(CONSTRUCTOR, (element as JavaElementImpl<*>).getPsi(), descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun recordField(field: JavaField, descriptor: PropertyDescriptor) {
|
override fun recordField(field: JavaField, descriptor: PropertyDescriptor) {
|
||||||
traceBasedCache.recordField(field, descriptor)
|
trace.record(VARIABLE, (field as JavaFieldImpl).getPsi(), descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun recordClass(javaClass: JavaClass, descriptor: ClassDescriptor) {
|
override fun recordClass(javaClass: JavaClass, descriptor: ClassDescriptor) {
|
||||||
traceBasedCache.recordClass(javaClass, descriptor)
|
trace.record(CLASS, (javaClass as JavaClassImpl).getPsi(), descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findInPackageFragments(fullFqName: FqName): ClassDescriptor? {
|
private fun findInPackageFragments(fullFqName: FqName): ClassDescriptor? {
|
||||||
|
|||||||
-76
@@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.load.java.components;
|
|
||||||
|
|
||||||
import com.intellij.psi.PsiField;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor;
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaClass;
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaElement;
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaField;
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaMethod;
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl;
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaElementImpl;
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaFieldImpl;
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaMethodImpl;
|
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
|
||||||
import org.jetbrains.kotlin.resolve.BindingContextUtils;
|
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.resolve.BindingContext.*;
|
|
||||||
|
|
||||||
public class TraceBasedJavaResolverCache implements JavaResolverCache {
|
|
||||||
private BindingTrace trace;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public void setTrace(BindingTrace trace) {
|
|
||||||
this.trace = trace;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public ClassDescriptor getClassResolvedFromSource(@NotNull FqName fqName) {
|
|
||||||
return trace.get(FQNAME_TO_CLASS_DESCRIPTOR, fqName.toUnsafe());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void recordMethod(@NotNull JavaMethod method, @NotNull SimpleFunctionDescriptor descriptor) {
|
|
||||||
BindingContextUtils.recordFunctionDeclarationToDescriptor(trace, ((JavaMethodImpl) method).getPsi(), descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void recordConstructor(@NotNull JavaElement element, @NotNull ConstructorDescriptor descriptor) {
|
|
||||||
trace.record(CONSTRUCTOR, ((JavaElementImpl) element).getPsi(), descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void recordField(@NotNull JavaField field, @NotNull PropertyDescriptor descriptor) {
|
|
||||||
PsiField psiField = ((JavaFieldImpl) field).getPsi();
|
|
||||||
trace.record(VARIABLE, psiField, descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void recordClass(@NotNull JavaClass javaClass, @NotNull ClassDescriptor descriptor) {
|
|
||||||
trace.record(CLASS, ((JavaClassImpl) javaClass).getPsi(), descriptor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user