提交 3c9c7e6e 编写于 作者: P Pavel V. Talanov

Introduce AnalyzeSingleFileUtil.

上级 1eb38baa
......@@ -32,15 +32,14 @@ import com.intellij.psi.util.PsiTreeUtil;
import jet.Tuple2;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.analyzer.AnalyzerFacadeWithCache;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.FqName;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil;
import org.jetbrains.jet.resolve.DescriptorRenderer;
import org.jetbrains.jet.util.slicedmap.WritableSlice;
......@@ -67,9 +66,7 @@ public class JetSourceNavigationHelper {
}
final List<JetFile> libraryFiles = findAllSourceFilesWhichContainIdentifier(declaration);
for (JetFile libraryFile : libraryFiles) {
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFileWithCache(libraryFile,
AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
.getBindingContext();
BindingContext bindingContext = AnalyzeSingleFileUtil.analyzeSingleFileWithCache(libraryFile).getBindingContext();
D descriptor = bindingContext.get(slice, fqName);
if (descriptor != null) {
return new Tuple2<BindingContext, D>(bindingContext, descriptor);
......
......@@ -37,6 +37,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil;
import org.jetbrains.jet.resolve.DescriptorRenderer;
import java.awt.*;
......@@ -196,9 +197,7 @@ public class JetFunctionParameterInfoHandler implements
JetValueArgumentList argumentList = (JetValueArgumentList)parameterOwner;
if (descriptor instanceof FunctionDescriptor) {
JetFile file = (JetFile)argumentList.getContainingFile();
BindingContext bindingContext =
AnalyzerFacadeForJVM.analyzeFileWithCache(file, AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
.getBindingContext();
BindingContext bindingContext = AnalyzeSingleFileUtil.getContextForSingleFile(file);
FunctionDescriptor functionDescriptor = (FunctionDescriptor)descriptor;
StringBuilder builder = new StringBuilder();
List<ValueParameterDescriptor> valueParameters = functionDescriptor.getValueParameters();
......@@ -357,10 +356,7 @@ public class JetFunctionParameterInfoHandler implements
else {
return null;
}
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFileWithCache(
(JetFile)file,
AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
.getBindingContext();
BindingContext bindingContext = AnalyzeSingleFileUtil.getContextForSingleFile((JetFile)file);
JetExpression calleeExpression = callExpression.getCalleeExpression();
if (calleeExpression == null) return null;
JetSimpleNameExpression refExpression = null;
......
/*
* Copyright 2010-2012 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.project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.analyzer.AnalyzerFacadeWithCache;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.BindingContext;
/**
* @author Pavel Talanov
*/
public final class AnalyzeSingleFileUtil {
private AnalyzeSingleFileUtil() {
}
@NotNull
public static AnalyzeExhaust analyzeSingleFileWithCache(@NotNull JetFile file) {
return AnalyzerFacadeProvider.getAnalyzerFacadeWithCacheForFile(file)
.analyzeFileWithCache(file, AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER);
}
@NotNull
public static BindingContext getContextForSingleFile(@NotNull JetFile file) {
return analyzeSingleFileWithCache(file).getBindingContext();
}
}
......@@ -34,6 +34,9 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.plugin.JetBundle;
import org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil;
import static org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil.getContextForSingleFile;
/**
* @author svtk
......@@ -74,9 +77,7 @@ public class ChangeVariableMutabilityFix implements IntentionAction {
if (property != null) return property;
JetSimpleNameExpression simpleNameExpression = PsiTreeUtil.getParentOfType(elementAtCaret, JetSimpleNameExpression.class);
if (simpleNameExpression != null) {
BindingContext bindingContext =
AnalyzerFacadeForJVM.analyzeFileWithCache(file, AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
.getBindingContext();
BindingContext bindingContext = getContextForSingleFile(file);
VariableDescriptor descriptor = BindingContextUtils.extractVariableDescriptorIfAny(bindingContext, simpleNameExpression, true);
if (descriptor != null) {
PsiElement declaration = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, descriptor);
......
......@@ -34,10 +34,13 @@ import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.plugin.JetPluginUtil;
import org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil;
import org.jetbrains.jet.util.QualifiedNamesUtil;
import java.util.List;
import static org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil.getContextForSingleFile;
/**
* @author svtk
*/
......@@ -55,8 +58,7 @@ public class ImportInsertHelper {
if (JetPluginUtil.checkTypeIsStandard(type, file.getProject()) || ErrorUtils.isErrorType(type)) {
return;
}
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFileWithCache(file, AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
.getBindingContext();
BindingContext bindingContext = getContextForSingleFile(file);
PsiElement element = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, type.getMemberScope().getContainingDeclaration());
if (element != null && element.getContainingFile() == file) { //declaration is in the same file, so no import is needed
return;
......
......@@ -33,6 +33,8 @@ import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.types.DeferredType;
import org.jetbrains.jet.lang.types.JetType;
import static org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil.getContextForSingleFile;
/**
* @author svtk
*/
......@@ -57,9 +59,7 @@ public class QuickFixUtil {
public static JetType getDeclarationReturnType(JetNamedDeclaration declaration) {
PsiFile file = declaration.getContainingFile();
if (!(file instanceof JetFile)) return null;
BindingContext bindingContext =
AnalyzerFacadeForJVM.analyzeFileWithCache((JetFile)file, AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
.getBindingContext();
BindingContext bindingContext = getContextForSingleFile((JetFile) file);
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
if (!(descriptor instanceof CallableDescriptor)) return null;
JetType type = ((CallableDescriptor)descriptor).getReturnType();
......
......@@ -36,6 +36,8 @@ import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil.getContextForSingleFile;
/**
* User: Alefas
* Date: 31.01.12
......@@ -68,9 +70,7 @@ public class JetNameSuggester {
public static String[] suggestNames(JetExpression expression, JetNameValidator validator) {
ArrayList<String> result = new ArrayList<String>();
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFileWithCache((JetFile)expression.getContainingFile(),
AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
.getBindingContext();
BindingContext bindingContext = getContextForSingleFile((JetFile) expression.getContainingFile());
JetType jetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
if (jetType != null) {
addNamesForType(result, jetType, validator);
......
......@@ -44,6 +44,8 @@ import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import static org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil.getContextForSingleFile;
/**
* User: Alefas
* Date: 25.01.12
......@@ -106,9 +108,7 @@ public class JetRefactoringUtil {
}
if (addExpression) {
JetExpression expression = (JetExpression)element;
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFileWithCache((JetFile)expression.getContainingFile(),
AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
.getBindingContext();
BindingContext bindingContext = getContextForSingleFile((JetFile)expression.getContainingFile());
JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
if (expressionType == null || !(expressionType instanceof NamespaceType) &&
!JetTypeChecker.INSTANCE.equalTypes(JetStandardLibrary.
......
......@@ -48,6 +48,8 @@ import org.jetbrains.jet.plugin.refactoring.*;
import java.util.*;
import static org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil.getContextForSingleFile;
/**
* User: Alefas
* Date: 25.01.12
......@@ -99,9 +101,7 @@ public class JetIntroduceVariableHandler extends JetIntroduceHandlerBase {
return;
}
}
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFileWithCache((JetFile)expression.getContainingFile(),
AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
.getBindingContext();
BindingContext bindingContext = getContextForSingleFile((JetFile)expression.getContainingFile());
final JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression); //can be null or error type
if (expressionType instanceof NamespaceType) {
showErrorHint(project, editor, JetRefactoringBundle.message("cannot.refactor.namespace.expression"));
......@@ -372,9 +372,7 @@ public class JetIntroduceVariableHandler extends JetIntroduceHandlerBase {
final ArrayList<JetExpression> result = new ArrayList<JetExpression>();
final BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFileWithCache((JetFile)expression.getContainingFile(),
AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
.getBindingContext();
final BindingContext bindingContext = getContextForSingleFile((JetFile)expression.getContainingFile());
JetVisitorVoid visitor = new JetVisitorVoid() {
@Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册