Refactor Descriptor renderer test to avoid creating ResolveElementCache explicitly
This commit is contained in:
-42
@@ -1,42 +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.idea.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.idea.project.ResolveElementCache;
|
||||
import org.jetbrains.kotlin.psi.JetClassInitializer;
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration;
|
||||
import org.jetbrains.kotlin.psi.JetPsiUtil;
|
||||
import org.jetbrains.kotlin.renderer.AbstractDescriptorRendererTest;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform;
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode;
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession;
|
||||
|
||||
public abstract class AbstractAdditionalResolveDescriptorRendererTest extends AbstractDescriptorRendererTest {
|
||||
@NotNull
|
||||
@Override
|
||||
protected DeclarationDescriptor getDescriptor(@NotNull JetDeclaration declaration, @NotNull ResolveSession resolveSession) {
|
||||
if (declaration instanceof JetClassInitializer || JetPsiUtil.isLocal(declaration)) {
|
||||
ResolveElementCache resolveElementCache = new ResolveElementCache(resolveSession, getProject(), JvmPlatform.INSTANCE$);
|
||||
//noinspection ConstantConditions
|
||||
return resolveElementCache.resolveToElement(declaration, BodyResolveMode.FULL).get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
|
||||
}
|
||||
return resolveSession.resolveToDescriptor(declaration);
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.idea.resolve
|
||||
|
||||
import org.jetbrains.kotlin.container.ComponentProvider
|
||||
import org.jetbrains.kotlin.container.get
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.idea.project.IdeEnvironment
|
||||
import org.jetbrains.kotlin.idea.project.ResolveElementCache
|
||||
import org.jetbrains.kotlin.psi.JetClassInitializer
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetPsiUtil
|
||||
import org.jetbrains.kotlin.renderer.AbstractDescriptorRendererTest
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.TargetEnvironment
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||
|
||||
public abstract class AbstractAdditionalResolveDescriptorRendererTest : AbstractDescriptorRendererTest() {
|
||||
override fun getDescriptor(declaration: JetDeclaration, container: ComponentProvider): DeclarationDescriptor {
|
||||
if (declaration is JetClassInitializer || JetPsiUtil.isLocal(declaration)) {
|
||||
return container.get<ResolveElementCache>()
|
||||
.resolveToElement(declaration, BodyResolveMode.FULL)
|
||||
.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration)!!
|
||||
}
|
||||
return container.get<ResolveSession>().resolveToDescriptor(declaration)
|
||||
}
|
||||
|
||||
override val targetEnvironment: TargetEnvironment
|
||||
get() = IdeEnvironment
|
||||
}
|
||||
Reference in New Issue
Block a user