Refactoring: method rename resolveToExpression -> resolveToElement

This commit is contained in:
Nikolay Krasko
2013-07-11 16:35:14 +04:00
parent b6be094724
commit ab4452a508
12 changed files with 43 additions and 26 deletions
@@ -113,16 +113,16 @@ public class ResolveSessionUtils {
}
}
public static @NotNull BindingContext resolveToExpression(
public static @NotNull BindingContext resolveToElement(
@NotNull ResolveSession resolveSession,
@NotNull JetElement expression
@NotNull JetElement jetElement
) {
DelegatingBindingTrace trace = new DelegatingBindingTrace(
resolveSession.getBindingContext(), "trace to resolve expression", expression);
JetFile file = (JetFile) expression.getContainingFile();
resolveSession.getBindingContext(), "trace to resolve jetElement", jetElement);
JetFile file = (JetFile) jetElement.getContainingFile();
@SuppressWarnings("unchecked")
PsiElement topmostCandidateForAdditionalResolve = JetPsiUtil.getTopmostParentOfTypes(expression,
PsiElement topmostCandidateForAdditionalResolve = JetPsiUtil.getTopmostParentOfTypes(jetElement,
JetNamedFunction.class, JetClassInitializer.class,
JetProperty.class, JetDelegationSpecifierList.class,
JetImportDirective.class);
@@ -155,8 +155,8 @@ public class ResolveSessionUtils {
return trace.getBindingContext();
}
if (expression instanceof JetExpression) {
JetExpression jetExpression = (JetExpression) expression;
if (jetElement instanceof JetExpression) {
JetExpression jetExpression = (JetExpression) jetElement;
// Setup resolution scope explicitly
if (trace.getBindingContext().get(BindingContext.RESOLUTION_SCOPE, jetExpression) == null) {
JetScope scope = getExpressionMemberScope(resolveSession, jetExpression);
@@ -180,7 +180,7 @@ public class JetShortNamesCache extends PsiShortNamesCache {
@NotNull ResolveSession resolveSession,
@NotNull GlobalSearchScope scope
) {
BindingContext context = ResolveSessionUtils.resolveToExpression(resolveSession, expression);
BindingContext context = ResolveSessionUtils.resolveToElement(resolveSession, expression);
JetScope jetScope = context.get(BindingContext.RESOLUTION_SCOPE, expression);
if (jetScope == null) {
@@ -221,7 +221,7 @@ public class JetShortNamesCache extends PsiShortNamesCache {
return Collections.emptyList();
}
BindingContext context = ResolveSessionUtils.resolveToExpression(resolveSession, expression);
BindingContext context = ResolveSessionUtils.resolveToElement(resolveSession, expression);
JetScope jetScope = context.get(BindingContext.RESOLUTION_SCOPE, expression);
if (jetScope == null) {
@@ -302,7 +302,7 @@ public class JetShortNamesCache extends PsiShortNamesCache {
) {
Collection<DeclarationDescriptor> resultDescriptors = new ArrayList<DeclarationDescriptor>();
BindingContext context = ResolveSessionUtils.resolveToExpression(resolveSession, expression);
BindingContext context = ResolveSessionUtils.resolveToElement(resolveSession, expression);
JetExpression receiverExpression = expression.getReceiverExpression();
if (receiverExpression != null) {
@@ -1,3 +1,19 @@
/*
* Copyright 2010-2013 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.jet.plugin.codeInsight.surroundWith;
import com.intellij.openapi.editor.Editor;
@@ -31,7 +47,7 @@ public class KotlinSurrounderUtils {
@Nullable
public static JetType getExpressionType(JetExpression expression) {
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) expression.getContainingFile());
BindingContext expressionBindingContext = ResolveSessionUtils.resolveToExpression(resolveSession, expression);
BindingContext expressionBindingContext = ResolveSessionUtils.resolveToElement(resolveSession, expression);
return expressionBindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
}
@@ -40,7 +40,8 @@ import org.jetbrains.jet.renderer.DescriptorRenderer;
import java.util.ArrayList;
import java.util.List;
import static org.jetbrains.jet.lang.psi.JetPsiFactory.*;
import static org.jetbrains.jet.lang.psi.JetPsiFactory.createExpression;
import static org.jetbrains.jet.lang.psi.JetPsiFactory.createNewLine;
public class MoveDeclarationsOutHelper {
@@ -119,7 +120,7 @@ public class MoveDeclarationsOutHelper {
@NotNull
private static JetType getPropertyType(@NotNull JetProperty property) {
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) property.getContainingFile());
BindingContext expressionBindingContext = ResolveSessionUtils.resolveToExpression(resolveSession, property);
BindingContext expressionBindingContext = ResolveSessionUtils.resolveToElement(resolveSession, property);
VariableDescriptor propertyDescriptor = expressionBindingContext.get(BindingContext.VARIABLE, property);
assert propertyDescriptor != null : "Couldn't resolve property to property descriptor " + property.getText();
@@ -61,7 +61,7 @@ public class CompletionSession {
this.jetReference = jetReference;
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) position.getContainingFile());
BindingContext expressionBindingContext = ResolveSessionUtils.resolveToExpression(resolveSession, jetReference.getExpression());
BindingContext expressionBindingContext = ResolveSessionUtils.resolveToElement(resolveSession, jetReference.getExpression());
JetScope scope = expressionBindingContext.get(BindingContext.RESOLUTION_SCOPE, jetReference.getExpression());
inDescriptor = scope != null ? scope.getContainingDeclaration() : null;
@@ -72,7 +72,7 @@ public class JetPackagesContributor extends CompletionContributor {
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile(
(JetFile) simpleNameReference.getExpression().getContainingFile());
BindingContext bindingContext = ResolveSessionUtils.resolveToExpression(
BindingContext bindingContext = ResolveSessionUtils.resolveToElement(
resolveSession, simpleNameReference.getExpression());
for (LookupElement variant : DescriptorLookupConverter.collectLookupElements(
@@ -179,7 +179,7 @@ public class JetImportOptimizer implements ImportOptimizer {
@Override
public void visitForExpression(JetForExpression expression) {
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) expression.getContainingFile());
BindingContext context = ResolveSessionUtils.resolveToExpression(resolveSession, expression);
BindingContext context = ResolveSessionUtils.resolveToElement(resolveSession, expression);
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.LOOP_RANGE_ITERATOR_RESOLVED_CALL, expression.getLoopRange());
addResolvedCallFqName(resolvedCall);
@@ -189,7 +189,7 @@ public class JetImportOptimizer implements ImportOptimizer {
@Override
public void visitMultiDeclaration(JetMultiDeclaration declaration) {
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) declaration.getContainingFile());
BindingContext context = ResolveSessionUtils.resolveToExpression(resolveSession, declaration);
BindingContext context = ResolveSessionUtils.resolveToElement(resolveSession, declaration);
List<JetMultiDeclarationEntry> entries = declaration.getEntries();
for (JetMultiDeclarationEntry entry : entries) {
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
@@ -243,7 +243,7 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
if ((element instanceof JetNamedFunction && ((JetNamedFunction) element).isLocal()) ||
element instanceof JetProperty && ((JetProperty) element).isLocal()) {
bindingContext = ResolveSessionUtils.resolveToExpression(sessionForFile, (JetElement) element);
bindingContext = ResolveSessionUtils.resolveToElement(sessionForFile, (JetElement) element);
}
else {
try {
@@ -239,7 +239,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
StringBuilder builder = new StringBuilder();
PsiElement owner = context.getParameterOwner();
BindingContext bindingContext = ResolveSessionUtils.resolveToExpression(resolveSession, (JetElement) owner);
BindingContext bindingContext = ResolveSessionUtils.resolveToElement(resolveSession, (JetElement) owner);
for (int i = 0; i < valueParameters.size(); ++i) {
if (i != 0) {
@@ -384,7 +384,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile(
(JetFile) callNameExpression.getContainingFile());
BindingContext bindingContext = ResolveSessionUtils.resolveToExpression(resolveSession, callNameExpression);
BindingContext bindingContext = ResolveSessionUtils.resolveToElement(resolveSession, callNameExpression);
JetScope scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, callNameExpression);
DeclarationDescriptor placeDescriptor = null;
@@ -41,6 +41,6 @@ public final class WholeProjectAnalyzerFacade {
public static BindingContext getContextForExpression(@NotNull JetExpression jetExpression) {
ResolveSession resolveSession = getLazyResolveSessionForFile((JetFile) jetExpression.getContainingFile());
return ResolveSessionUtils.resolveToExpression(resolveSession, jetExpression);
return ResolveSessionUtils.resolveToElement(resolveSession, jetExpression);
}
}
@@ -212,7 +212,7 @@ public class KotlinInlineValHandler extends InlineActionHandler {
}
ResolveSession resolveSession = AnalyzerFacadeWithCache.getLazyResolveSession((JetFile) initializer.getContainingFile());
BindingContext context = ResolveSessionUtils.resolveToExpression(resolveSession, initializer);
BindingContext context = ResolveSessionUtils.resolveToElement(resolveSession, initializer);
SimpleFunctionDescriptor fun = context.get(BindingContext.FUNCTION, functionLiteralExpression.getFunctionLiteral());
if (fun == null || ErrorUtils.containsErrorType(fun)) {
return null;
@@ -284,7 +284,7 @@ public class KotlinInlineValHandler extends InlineActionHandler {
@NotNull ResolveSession resolveSession
) {
JetFunctionLiteral functionLiteral = functionLiteralExpression.getFunctionLiteral();
BindingContext context = ResolveSessionUtils.resolveToExpression(resolveSession, functionLiteralExpression);
BindingContext context = ResolveSessionUtils.resolveToElement(resolveSession, functionLiteralExpression);
for (Diagnostic diagnostic : context.getDiagnostics()) {
AbstractDiagnosticFactory factory = diagnostic.getFactory();
PsiElement element = diagnostic.getPsiElement();
@@ -328,7 +328,7 @@ public class KotlinInlineValHandler extends InlineActionHandler {
JetExpression callee = callExpression.getCalleeExpression();
ResolveSession resolveSession = AnalyzerFacadeWithCache.getLazyResolveSession((JetFile) initializer.getContainingFile());
BindingContext context = ResolveSessionUtils.resolveToExpression(resolveSession, initializer);
BindingContext context = ResolveSessionUtils.resolveToElement(resolveSession, initializer);
ResolvedCall<? extends CallableDescriptor> call = context.get(BindingContext.RESOLVED_CALL, callee);
if (call == null) {
return null;
@@ -353,7 +353,7 @@ public class KotlinInlineValHandler extends InlineActionHandler {
@NotNull ResolveSession resolveSession
) {
JetExpression callee = callExpression.getCalleeExpression();
BindingContext context = ResolveSessionUtils.resolveToExpression(resolveSession, callExpression);
BindingContext context = ResolveSessionUtils.resolveToElement(resolveSession, callExpression);
for (Diagnostic diagnostic : context.getDiagnostics()) {
if (diagnostic.getFactory() == Errors.TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER && diagnostic.getPsiElement() == callee) {
return true;
@@ -58,7 +58,7 @@ public class JetSimpleNameReference extends JetPsiReference {
@Override
public Object[] getVariants() {
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) getExpression().getContainingFile());
BindingContext bindingContext = ResolveSessionUtils.resolveToExpression(resolveSession, getExpression());
BindingContext bindingContext = ResolveSessionUtils.resolveToElement(resolveSession, getExpression());
return DescriptorLookupConverter.collectLookupElements(
resolveSession, bindingContext, TipsManager.getReferenceVariants(myExpression, bindingContext));