Introduce AnalyzeSingleFileUtil.
This commit is contained in:
@@ -32,15 +32,14 @@ import com.intellij.psi.util.PsiTreeUtil;
|
|||||||
import jet.Tuple2;
|
import jet.Tuple2;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.analyzer.AnalyzerFacadeWithCache;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.FqName;
|
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.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
import org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil;
|
||||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||||
|
|
||||||
@@ -67,9 +66,7 @@ public class JetSourceNavigationHelper {
|
|||||||
}
|
}
|
||||||
final List<JetFile> libraryFiles = findAllSourceFilesWhichContainIdentifier(declaration);
|
final List<JetFile> libraryFiles = findAllSourceFilesWhichContainIdentifier(declaration);
|
||||||
for (JetFile libraryFile : libraryFiles) {
|
for (JetFile libraryFile : libraryFiles) {
|
||||||
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFileWithCache(libraryFile,
|
BindingContext bindingContext = AnalyzeSingleFileUtil.analyzeSingleFileWithCache(libraryFile).getBindingContext();
|
||||||
AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
|
|
||||||
.getBindingContext();
|
|
||||||
D descriptor = bindingContext.get(slice, fqName);
|
D descriptor = bindingContext.get(slice, fqName);
|
||||||
if (descriptor != null) {
|
if (descriptor != null) {
|
||||||
return new Tuple2<BindingContext, D>(bindingContext, descriptor);
|
return new Tuple2<BindingContext, D>(bindingContext, descriptor);
|
||||||
|
|||||||
+3
-7
@@ -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.JetType;
|
||||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
import org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil;
|
||||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@@ -196,9 +197,7 @@ public class JetFunctionParameterInfoHandler implements
|
|||||||
JetValueArgumentList argumentList = (JetValueArgumentList)parameterOwner;
|
JetValueArgumentList argumentList = (JetValueArgumentList)parameterOwner;
|
||||||
if (descriptor instanceof FunctionDescriptor) {
|
if (descriptor instanceof FunctionDescriptor) {
|
||||||
JetFile file = (JetFile)argumentList.getContainingFile();
|
JetFile file = (JetFile)argumentList.getContainingFile();
|
||||||
BindingContext bindingContext =
|
BindingContext bindingContext = AnalyzeSingleFileUtil.getContextForSingleFile(file);
|
||||||
AnalyzerFacadeForJVM.analyzeFileWithCache(file, AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
|
|
||||||
.getBindingContext();
|
|
||||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor)descriptor;
|
FunctionDescriptor functionDescriptor = (FunctionDescriptor)descriptor;
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
List<ValueParameterDescriptor> valueParameters = functionDescriptor.getValueParameters();
|
List<ValueParameterDescriptor> valueParameters = functionDescriptor.getValueParameters();
|
||||||
@@ -357,10 +356,7 @@ public class JetFunctionParameterInfoHandler implements
|
|||||||
else {
|
else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFileWithCache(
|
BindingContext bindingContext = AnalyzeSingleFileUtil.getContextForSingleFile((JetFile)file);
|
||||||
(JetFile)file,
|
|
||||||
AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
|
|
||||||
.getBindingContext();
|
|
||||||
JetExpression calleeExpression = callExpression.getCalleeExpression();
|
JetExpression calleeExpression = callExpression.getCalleeExpression();
|
||||||
if (calleeExpression == null) return null;
|
if (calleeExpression == null) return null;
|
||||||
JetSimpleNameExpression refExpression = null;
|
JetSimpleNameExpression refExpression = null;
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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.BindingContextUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||||
import org.jetbrains.jet.plugin.JetBundle;
|
import org.jetbrains.jet.plugin.JetBundle;
|
||||||
|
import org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil.getContextForSingleFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author svtk
|
* @author svtk
|
||||||
@@ -74,9 +77,7 @@ public class ChangeVariableMutabilityFix implements IntentionAction {
|
|||||||
if (property != null) return property;
|
if (property != null) return property;
|
||||||
JetSimpleNameExpression simpleNameExpression = PsiTreeUtil.getParentOfType(elementAtCaret, JetSimpleNameExpression.class);
|
JetSimpleNameExpression simpleNameExpression = PsiTreeUtil.getParentOfType(elementAtCaret, JetSimpleNameExpression.class);
|
||||||
if (simpleNameExpression != null) {
|
if (simpleNameExpression != null) {
|
||||||
BindingContext bindingContext =
|
BindingContext bindingContext = getContextForSingleFile(file);
|
||||||
AnalyzerFacadeForJVM.analyzeFileWithCache(file, AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
|
|
||||||
.getBindingContext();
|
|
||||||
VariableDescriptor descriptor = BindingContextUtils.extractVariableDescriptorIfAny(bindingContext, simpleNameExpression, true);
|
VariableDescriptor descriptor = BindingContextUtils.extractVariableDescriptorIfAny(bindingContext, simpleNameExpression, true);
|
||||||
if (descriptor != null) {
|
if (descriptor != null) {
|
||||||
PsiElement declaration = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, descriptor);
|
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.ErrorUtils;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.plugin.JetPluginUtil;
|
import org.jetbrains.jet.plugin.JetPluginUtil;
|
||||||
|
import org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil;
|
||||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil.getContextForSingleFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author svtk
|
* @author svtk
|
||||||
*/
|
*/
|
||||||
@@ -55,8 +58,7 @@ public class ImportInsertHelper {
|
|||||||
if (JetPluginUtil.checkTypeIsStandard(type, file.getProject()) || ErrorUtils.isErrorType(type)) {
|
if (JetPluginUtil.checkTypeIsStandard(type, file.getProject()) || ErrorUtils.isErrorType(type)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFileWithCache(file, AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
|
BindingContext bindingContext = getContextForSingleFile(file);
|
||||||
.getBindingContext();
|
|
||||||
PsiElement element = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, type.getMemberScope().getContainingDeclaration());
|
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
|
if (element != null && element.getContainingFile() == file) { //declaration is in the same file, so no import is needed
|
||||||
return;
|
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.DeferredType;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil.getContextForSingleFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author svtk
|
* @author svtk
|
||||||
*/
|
*/
|
||||||
@@ -57,9 +59,7 @@ public class QuickFixUtil {
|
|||||||
public static JetType getDeclarationReturnType(JetNamedDeclaration declaration) {
|
public static JetType getDeclarationReturnType(JetNamedDeclaration declaration) {
|
||||||
PsiFile file = declaration.getContainingFile();
|
PsiFile file = declaration.getContainingFile();
|
||||||
if (!(file instanceof JetFile)) return null;
|
if (!(file instanceof JetFile)) return null;
|
||||||
BindingContext bindingContext =
|
BindingContext bindingContext = getContextForSingleFile((JetFile) file);
|
||||||
AnalyzerFacadeForJVM.analyzeFileWithCache((JetFile)file, AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
|
|
||||||
.getBindingContext();
|
|
||||||
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
|
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
|
||||||
if (!(descriptor instanceof CallableDescriptor)) return null;
|
if (!(descriptor instanceof CallableDescriptor)) return null;
|
||||||
JetType type = ((CallableDescriptor)descriptor).getReturnType();
|
JetType type = ((CallableDescriptor)descriptor).getReturnType();
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil.getContextForSingleFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: Alefas
|
* User: Alefas
|
||||||
* Date: 31.01.12
|
* Date: 31.01.12
|
||||||
@@ -68,9 +70,7 @@ public class JetNameSuggester {
|
|||||||
public static String[] suggestNames(JetExpression expression, JetNameValidator validator) {
|
public static String[] suggestNames(JetExpression expression, JetNameValidator validator) {
|
||||||
ArrayList<String> result = new ArrayList<String>();
|
ArrayList<String> result = new ArrayList<String>();
|
||||||
|
|
||||||
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFileWithCache((JetFile)expression.getContainingFile(),
|
BindingContext bindingContext = getContextForSingleFile((JetFile) expression.getContainingFile());
|
||||||
AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
|
|
||||||
.getBindingContext();
|
|
||||||
JetType jetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
JetType jetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
||||||
if (jetType != null) {
|
if (jetType != null) {
|
||||||
addNamesForType(result, jetType, validator);
|
addNamesForType(result, jetType, validator);
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ import java.awt.*;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil.getContextForSingleFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: Alefas
|
* User: Alefas
|
||||||
* Date: 25.01.12
|
* Date: 25.01.12
|
||||||
@@ -106,9 +108,7 @@ public class JetRefactoringUtil {
|
|||||||
}
|
}
|
||||||
if (addExpression) {
|
if (addExpression) {
|
||||||
JetExpression expression = (JetExpression)element;
|
JetExpression expression = (JetExpression)element;
|
||||||
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFileWithCache((JetFile)expression.getContainingFile(),
|
BindingContext bindingContext = getContextForSingleFile((JetFile)expression.getContainingFile());
|
||||||
AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
|
|
||||||
.getBindingContext();
|
|
||||||
JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
||||||
if (expressionType == null || !(expressionType instanceof NamespaceType) &&
|
if (expressionType == null || !(expressionType instanceof NamespaceType) &&
|
||||||
!JetTypeChecker.INSTANCE.equalTypes(JetStandardLibrary.
|
!JetTypeChecker.INSTANCE.equalTypes(JetStandardLibrary.
|
||||||
|
|||||||
+4
-6
@@ -48,6 +48,8 @@ import org.jetbrains.jet.plugin.refactoring.*;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil.getContextForSingleFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: Alefas
|
* User: Alefas
|
||||||
* Date: 25.01.12
|
* Date: 25.01.12
|
||||||
@@ -99,9 +101,7 @@ public class JetIntroduceVariableHandler extends JetIntroduceHandlerBase {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFileWithCache((JetFile)expression.getContainingFile(),
|
BindingContext bindingContext = getContextForSingleFile((JetFile)expression.getContainingFile());
|
||||||
AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
|
|
||||||
.getBindingContext();
|
|
||||||
final JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression); //can be null or error type
|
final JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression); //can be null or error type
|
||||||
if (expressionType instanceof NamespaceType) {
|
if (expressionType instanceof NamespaceType) {
|
||||||
showErrorHint(project, editor, JetRefactoringBundle.message("cannot.refactor.namespace.expression"));
|
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 ArrayList<JetExpression> result = new ArrayList<JetExpression>();
|
||||||
|
|
||||||
final BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFileWithCache((JetFile)expression.getContainingFile(),
|
final BindingContext bindingContext = getContextForSingleFile((JetFile)expression.getContainingFile());
|
||||||
AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER)
|
|
||||||
.getBindingContext();
|
|
||||||
|
|
||||||
JetVisitorVoid visitor = new JetVisitorVoid() {
|
JetVisitorVoid visitor = new JetVisitorVoid() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user