Drop TraceBasedJavaResolverCache, inline into LazyResolveBasedCache

This commit is contained in:
Alexander Udalov
2015-02-09 21:57:43 +03:00
parent 021315f049
commit 25775ee516
2 changed files with 13 additions and 88 deletions
@@ -17,45 +17,46 @@
package org.jetbrains.kotlin.load.java.components
import org.jetbrains.kotlin.descriptors.*
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.*
import org.jetbrains.kotlin.load.java.structure.impl.*
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.resolve.lazy.ResolveSessionUtils
import org.jetbrains.kotlin.name.FqName
import javax.inject.Inject
import kotlin.properties.Delegates
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 val traceBasedCache = TraceBasedJavaResolverCache()
private val trace: BindingTrace get() = resolveSession.getTrace()
Inject
public fun setSession(resolveSession: ResolveSession) {
this.resolveSession = resolveSession
traceBasedCache.setTrace(this.resolveSession.getTrace())
}
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) {
traceBasedCache.recordMethod(method, descriptor)
BindingContextUtils.recordFunctionDeclarationToDescriptor(trace, (method as JavaMethodImpl).getPsi(), descriptor)
}
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) {
traceBasedCache.recordField(field, descriptor)
trace.record(VARIABLE, (field as JavaFieldImpl).getPsi(), descriptor)
}
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? {
@@ -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);
}
}