JetElement.getContainingJetFile() introduced

This commit is contained in:
Andrey Breslav
2014-04-21 18:25:17 +04:00
parent da0efe2a9e
commit 767eb04930
50 changed files with 89 additions and 62 deletions
@@ -1960,7 +1960,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
KotlinSyntheticClass.Kind.SAM_LAMBDA); KotlinSyntheticClass.Kind.SAM_LAMBDA);
} }
Type asmType = state.getSamWrapperClasses().getSamWrapperClass(samInterface, (JetFile) expression.getContainingFile()); Type asmType = state.getSamWrapperClasses().getSamWrapperClass(samInterface, expression.getContainingJetFile());
v.anew(asmType); v.anew(asmType);
v.dup(); v.dup();
@@ -344,7 +344,7 @@ public class PackageCodegen extends GenerationStateAware {
} }
public void generateClassOrObject(@NotNull JetClassOrObject classOrObject) { public void generateClassOrObject(@NotNull JetClassOrObject classOrObject) {
JetFile file = (JetFile) classOrObject.getContainingFile(); JetFile file = classOrObject.getContainingJetFile();
Type packagePartType = getPackagePartType(getPackageClassFqName(packageFragment.getFqName()), file.getVirtualFile()); Type packagePartType = getPackagePartType(getPackageClassFqName(packageFragment.getFqName()), file.getVirtualFile());
CodegenContext context = CodegenContext.STATIC.intoPackagePart(packageFragment, packagePartType); CodegenContext context = CodegenContext.STATIC.intoPackagePart(packageFragment, packagePartType);
MemberCodegen.genClassOrObject(context, classOrObject, state, null); MemberCodegen.genClassOrObject(context, classOrObject, state, null);
@@ -80,7 +80,7 @@ public final class PsiCodegenPredictor {
} }
} }
else { else {
FqName packageFqName = ((JetFile) declaration.getContainingFile()).getPackageFqName(); FqName packageFqName = declaration.getContainingJetFile().getPackageFqName();
if (declaration instanceof JetNamedFunction) { if (declaration instanceof JetNamedFunction) {
JvmClassName packageClass = JvmClassName.byFqNameWithoutInnerClasses(getPackageClassFqName(packageFqName)); JvmClassName packageClass = JvmClassName.byFqNameWithoutInnerClasses(getPackageClassFqName(packageFqName));
@@ -368,8 +368,8 @@ public class ReplInterpreter {
state.beforeCompile(); state.beforeCompile();
KotlinCodegenFacade.generatePackage( KotlinCodegenFacade.generatePackage(
state, state,
((JetFile) script.getContainingFile()).getPackageFqName(), script.getContainingJetFile().getPackageFqName(),
Collections.singleton((JetFile) script.getContainingFile()), Collections.singleton(script.getContainingJetFile()),
errorHandler); errorHandler);
} }
@@ -20,6 +20,9 @@ import com.intellij.psi.NavigatablePsiElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public interface JetElement extends NavigatablePsiElement { public interface JetElement extends NavigatablePsiElement {
@NotNull
JetFile getContainingJetFile();
<D> void acceptChildren(@NotNull JetTreeVisitor<D> visitor, D data); <D> void acceptChildren(@NotNull JetTreeVisitor<D> visitor, D data);
<R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data); <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data);
@@ -20,6 +20,7 @@ import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode; import com.intellij.lang.ASTNode;
import com.intellij.lang.Language; import com.intellij.lang.Language;
import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiReference; import com.intellij.psi.PsiReference;
import com.intellij.psi.PsiReferenceService; import com.intellij.psi.PsiReferenceService;
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry; import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
@@ -52,6 +53,14 @@ public class JetElementImpl extends ASTWrapperPsiElement implements JetElement {
} }
} }
@NotNull
@Override
public JetFile getContainingJetFile() {
PsiFile file = getContainingFile();
assert file instanceof JetFile : "JetElement not inside JetFile: " + file + " " + file.getText();
return (JetFile) file;
}
@Override @Override
public <D> void acceptChildren(@NotNull JetTreeVisitor<D> visitor, D data) { public <D> void acceptChildren(@NotNull JetTreeVisitor<D> visitor, D data) {
JetPsiUtil.visitChildren(this, visitor, data); JetPsiUtil.visitChildren(this, visitor, data);
@@ -21,6 +21,7 @@ import com.intellij.lang.ASTNode;
import com.intellij.lang.Language; import com.intellij.lang.Language;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiFile;
import com.intellij.psi.StubBasedPsiElement; import com.intellij.psi.StubBasedPsiElement;
import com.intellij.psi.stubs.IStubElementType; import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.stubs.StubElement; import com.intellij.psi.stubs.StubElement;
@@ -58,6 +59,14 @@ public class JetElementImplStub<T extends StubElement> extends StubBasedPsiEleme
} }
} }
@NotNull
@Override
public JetFile getContainingJetFile() {
PsiFile file = getContainingFile();
assert file instanceof JetFile : "JetElement not inside JetFile: " + file + " " + file.getText();
return (JetFile) file;
}
@Override @Override
public <D> void acceptChildren(@NotNull JetTreeVisitor<D> visitor, D data) { public <D> void acceptChildren(@NotNull JetTreeVisitor<D> visitor, D data) {
PsiElement child = getFirstChild(); PsiElement child = getFirstChild();
@@ -160,6 +160,12 @@ public class JetFile extends PsiFileBase implements JetDeclarationContainer, Jet
} }
} }
@NotNull
@Override
public JetFile getContainingJetFile() {
return this;
}
@Override @Override
public <D> void acceptChildren(@NotNull JetTreeVisitor<D> visitor, D data) { public <D> void acceptChildren(@NotNull JetTreeVisitor<D> visitor, D data) {
JetPsiUtil.visitChildren(this, visitor, data); JetPsiUtil.visitChildren(this, visitor, data);
@@ -321,7 +321,7 @@ public class JetPsiUtil {
public static void deleteClass(@NotNull JetClassOrObject clazz) { public static void deleteClass(@NotNull JetClassOrObject clazz) {
CheckUtil.checkWritable(clazz); CheckUtil.checkWritable(clazz);
JetFile file = (JetFile) clazz.getContainingFile(); JetFile file = clazz.getContainingJetFile();
if (isLocal(clazz) || file.getDeclarations().size() > 1) { if (isLocal(clazz) || file.getDeclarations().size() > 1) {
PsiElement parent = clazz.getParent(); PsiElement parent = clazz.getParent();
CodeEditUtil.removeChild(parent.getNode(), clazz.getNode()); CodeEditUtil.removeChild(parent.getNode(), clazz.getNode());
@@ -912,7 +912,7 @@ public class JetPsiUtil {
@Nullable @Nullable
public static String getPackageName(@NotNull JetElement element) { public static String getPackageName(@NotNull JetElement element) {
JetFile file = (JetFile) element.getContainingFile(); JetFile file = element.getContainingJetFile();
JetPackageDirective header = PsiTreeUtil.findChildOfType(file, JetPackageDirective.class); JetPackageDirective header = PsiTreeUtil.findChildOfType(file, JetPackageDirective.class);
return header != null ? header.getQualifiedName() : null; return header != null ? header.getQualifiedName() : null;
@@ -82,7 +82,7 @@ public class ImportsResolver {
// SCRIPT: process script import directives // SCRIPT: process script import directives
for (JetScript script : c.getScripts().keySet()) { for (JetScript script : c.getScripts().keySet()) {
WritableScope scriptScope = ((ScriptDescriptorImpl) c.getScripts().get(script)).getScopeForBodyResolution(); WritableScope scriptScope = ((ScriptDescriptorImpl) c.getScripts().get(script)).getScopeForBodyResolution();
processImportsInFile(lookupMode, scriptScope, ((JetFile) script.getContainingFile()).getImportDirectives(), true); processImportsInFile(lookupMode, scriptScope, script.getContainingJetFile().getImportDirectives(), true);
} }
} }
@@ -236,7 +236,7 @@ public class LazyTopDownAnalyzer {
} }
for (JetScript script : c.getScripts().keySet()) { for (JetScript script : c.getScripts().keySet()) {
resolveAndCheckImports((JetFile) script.getContainingFile(), resolveSession); resolveAndCheckImports(script.getContainingJetFile(), resolveSession);
} }
} }
@@ -64,7 +64,7 @@ public class ScriptHeaderResolver {
public void processScriptHierarchy(@NotNull TopDownAnalysisContext c, @NotNull JetScript script, @NotNull WritableScope outerScope) { public void processScriptHierarchy(@NotNull TopDownAnalysisContext c, @NotNull JetScript script, @NotNull WritableScope outerScope) {
JetFile file = (JetFile) script.getContainingFile(); JetFile file = script.getContainingJetFile();
FqName fqName = file.getPackageFqName(); FqName fqName = file.getPackageFqName();
PackageFragmentDescriptor ns = packageFragmentProvider.getOrCreateFragment(fqName); PackageFragmentDescriptor ns = packageFragmentProvider.getOrCreateFragment(fqName);
@@ -30,7 +30,7 @@ public class ScriptNameUtil {
@NotNull @NotNull
public static FqName classNameForScript(JetScript script) { public static FqName classNameForScript(JetScript script) {
JetFile file = (JetFile) script.getContainingFile(); JetFile file = script.getContainingJetFile();
JetScriptDefinition scriptDefinition = JetScriptDefinitionProvider.getInstance(file.getProject()).findScriptDefinition(file); JetScriptDefinition scriptDefinition = JetScriptDefinitionProvider.getInstance(file.getProject()).findScriptDefinition(file);
String name = file.getName(); String name = file.getName();
@@ -54,7 +54,7 @@ public class ScriptParameterResolver {
) { ) {
List<ValueParameterDescriptor> valueParameters = Lists.newArrayList(); List<ValueParameterDescriptor> valueParameters = Lists.newArrayList();
JetFile file = (JetFile) declaration.getContainingFile(); JetFile file = declaration.getContainingJetFile();
JetScriptDefinition scriptDefinition = JetScriptDefinitionProvider.getInstance(file.getProject()).findScriptDefinition(file); JetScriptDefinition scriptDefinition = JetScriptDefinitionProvider.getInstance(file.getProject()).findScriptDefinition(file);
int index = 0; int index = 0;
@@ -177,7 +177,7 @@ public class LazyImportScope implements JetScope, LazyEntity {
ImportResolveStatus status = importedScopesProvider.invoke(importDirective).importResolveStatus; ImportResolveStatus status = importedScopesProvider.invoke(importDirective).importResolveStatus;
if (status != null && !status.descriptors.isEmpty()) { if (status != null && !status.descriptors.isEmpty()) {
JetScope fileScope = resolveSession.getScopeProvider().getFileScope((JetFile) importDirective.getContainingFile()); JetScope fileScope = resolveSession.getScopeProvider().getFileScope(importDirective.getContainingJetFile());
ImportsResolver.reportUselessImport(importDirective, fileScope, status.descriptors, traceForImportResolve); ImportsResolver.reportUselessImport(importDirective, fileScope, status.descriptors, traceForImportResolve);
} }
} }
@@ -55,7 +55,7 @@ public class LazyPackageMemberScope extends AbstractLazyMemberScope<PackageFragm
@NotNull @NotNull
@Override @Override
protected JetScope getScopeForMemberDeclarationResolution(JetDeclaration declaration) { protected JetScope getScopeForMemberDeclarationResolution(JetDeclaration declaration) {
return resolveSession.getScopeProvider().getFileScope((JetFile) declaration.getContainingFile()); return resolveSession.getScopeProvider().getFileScope(declaration.getContainingJetFile());
} }
@Override @Override
@@ -58,7 +58,7 @@ public class LazyScriptDescriptor(
val jetScript: JetScript, val jetScript: JetScript,
val _priority: Int val _priority: Int
) : ScriptDescriptor, LazyEntity, DeclarationDescriptorNonRootImpl( ) : ScriptDescriptor, LazyEntity, DeclarationDescriptorNonRootImpl(
(jetScript.getContainingFile() as JetFile).getPackageFqName().let { jetScript.getContainingJetFile().getPackageFqName().let {
fqName -> fqName ->
resolveSession.getPackageFragment(fqName).sure("Package not found $fqName") resolveSession.getPackageFragment(fqName).sure("Package not found $fqName")
}, },
@@ -102,7 +102,7 @@ public class LazyScriptDescriptor(
return ChainedScope( return ChainedScope(
this, this,
"Scope for body resolution for " + this, "Scope for body resolution for " + this,
resolveSession.getScopeProvider().getFileScope(jetScript.getContainingFile() as JetFile), resolveSession.getScopeProvider().getFileScope(jetScript.getContainingJetFile()),
parametersScope parametersScope
) )
} }
@@ -124,7 +124,7 @@ public class KotlinJavaFileStubProvider<T extends WithFileStub> implements Cache
JetPsiUtil.isLocal(classOrObject), JetPsiUtil.isLocal(classOrObject),
new StubGenerationStrategy<OutermostKotlinClassLightClassData>() { new StubGenerationStrategy<OutermostKotlinClassLightClassData>() {
private JetFile getFile() { private JetFile getFile() {
return (JetFile) classOrObject.getContainingFile(); return classOrObject.getContainingJetFile();
} }
@NotNull @NotNull
@@ -66,7 +66,7 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC
@Nullable @Nullable
public static KotlinLightClassForExplicitDeclaration create(@NotNull PsiManager manager, @NotNull JetClassOrObject classOrObject) { public static KotlinLightClassForExplicitDeclaration create(@NotNull PsiManager manager, @NotNull JetClassOrObject classOrObject) {
if (LightClassUtil.belongsToKotlinBuiltIns((JetFile) classOrObject.getContainingFile())) { if (LightClassUtil.belongsToKotlinBuiltIns(classOrObject.getContainingJetFile())) {
return null; return null;
} }
@@ -288,7 +288,7 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC
@NotNull @NotNull
@Override @Override
public String getPackageName() { public String getPackageName() {
return ((JetFile) classOrObject.getContainingFile()).getPackageFqName().asString(); return classOrObject.getContainingJetFile().getPackageFqName().asString();
} }
@NotNull @NotNull
@@ -95,7 +95,7 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport
@NotNull @NotNull
@Override @Override
public LightClassConstructionContext getContextForClassOrObject(@NotNull JetClassOrObject classOrObject) { public LightClassConstructionContext getContextForClassOrObject(@NotNull JetClassOrObject classOrObject) {
ResolveSessionForBodies session = AnalyzerFacadeWithCache.getLazyResolveSessionForFile((JetFile) classOrObject.getContainingFile()); ResolveSessionForBodies session = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(classOrObject.getContainingJetFile());
if (JetPsiUtil.isLocal(classOrObject)) { if (JetPsiUtil.isLocal(classOrObject)) {
BindingContext bindingContext = session.resolveToElement(classOrObject); BindingContext bindingContext = session.resolveToElement(classOrObject);
@@ -28,13 +28,13 @@ public class KotlinCacheManagerUtil {
@NotNull @NotNull
public static KotlinDeclarationsCache getDeclarationsFromProject(@NotNull JetElement element) { public static KotlinDeclarationsCache getDeclarationsFromProject(@NotNull JetElement element) {
JetFile jetFile = (JetFile) element.getContainingFile(); JetFile jetFile = element.getContainingJetFile();
return KotlinCacheManager.getInstance(jetFile.getProject()).getDeclarationsFromProject(TargetPlatformDetector.getPlatform(jetFile)); return KotlinCacheManager.getInstance(jetFile.getProject()).getDeclarationsFromProject(TargetPlatformDetector.getPlatform(jetFile));
} }
@NotNull @NotNull
public static BindingContext getDeclarationsBindingContext(@NotNull JetElement element) { public static BindingContext getDeclarationsBindingContext(@NotNull JetElement element) {
JetFile jetFile = (JetFile) element.getContainingFile(); JetFile jetFile = element.getContainingJetFile();
KotlinDeclarationsCache declarationsCache = KotlinCacheManager.getInstance(jetFile.getProject()) KotlinDeclarationsCache declarationsCache = KotlinCacheManager.getInstance(jetFile.getProject())
.getDeclarationsFromProject(TargetPlatformDetector.getPlatform(jetFile)); .getDeclarationsFromProject(TargetPlatformDetector.getPlatform(jetFile));
return declarationsCache.getBindingContext(); return declarationsCache.getBindingContext();
@@ -63,7 +63,7 @@ class KotlinResolveCache(
try { try {
for (element in task!!.elements) { for (element in task!!.elements) {
val file = element.getContainingFile() as JetFile val file = element.getContainingJetFile()
val virtualFile = file.getVirtualFile() val virtualFile = file.getVirtualFile()
if (LightClassUtil.belongsToKotlinBuiltIns(file) if (LightClassUtil.belongsToKotlinBuiltIns(file)
|| virtualFile != null && LibraryUtil.findLibraryEntry(virtualFile, file.getProject()) != null) { || virtualFile != null && LibraryUtil.findLibraryEntry(virtualFile, file.getProject()) != null) {
@@ -94,7 +94,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
} }
List<JetElement> elementsToCompact = new ArrayList<JetElement>(); List<JetElement> elementsToCompact = new ArrayList<JetElement>();
JetFile file = (JetFile) classOrObject.getContainingFile(); JetFile file = classOrObject.getContainingJetFile();
for (JetElement element : generateOverridingMembers(selectedElements, file)) { for (JetElement element : generateOverridingMembers(selectedElements, file)) {
PsiElement added = body.addAfter(element, afterAnchor); PsiElement added = body.addAfter(element, afterAnchor);
afterAnchor = added; afterAnchor = added;
@@ -25,7 +25,7 @@ public object ShortenReferences {
} }
public fun process(elements: Iterable<JetElement>) { public fun process(elements: Iterable<JetElement>) {
for ((file, fileElements) in elements.groupBy { element -> element.getContainingFile() as JetFile }) { for ((file, fileElements) in elements.groupBy { element -> element.getContainingJetFile() }) {
// first resolve all qualified references - optimization // first resolve all qualified references - optimization
val referenceToContext = JetFileReferencesResolver.resolve(file, fileElements, visitShortNames = false) val referenceToContext = JetFileReferencesResolver.resolve(file, fileElements, visitShortNames = false)
@@ -72,7 +72,7 @@ public class JetPackagesContributor extends CompletionContributor {
result = result.withPrefixMatcher(new PlainPrefixMatcher(name.substring(0, prefixLength))); result = result.withPrefixMatcher(new PlainPrefixMatcher(name.substring(0, prefixLength)));
ResolveSessionForBodies resolveSession = AnalyzerFacadeWithCache ResolveSessionForBodies resolveSession = AnalyzerFacadeWithCache
.getLazyResolveSessionForFile((JetFile) simpleNameReference.getExpression().getContainingFile()); .getLazyResolveSessionForFile(simpleNameReference.getExpression().getContainingJetFile());
BindingContext bindingContext = resolveSession.resolveToElement(simpleNameReference.getExpression()); BindingContext bindingContext = resolveSession.resolveToElement(simpleNameReference.getExpression());
for (LookupElement variant : DescriptorLookupConverter.collectLookupElements( for (LookupElement variant : DescriptorLookupConverter.collectLookupElements(
@@ -44,7 +44,7 @@ public class MoveLambdaInsideParenthesesIntention : JetSelfTargetingIntention<Je
} }
} }
if (element.getValueArguments().any { it?.getArgumentName() != null}) { if (element.getValueArguments().any { it?.getArgumentName() != null}) {
val context = AnalyzerFacadeWithCache.analyzeFileWithCache(element.getContainingFile() as JetFile).getBindingContext() val context = AnalyzerFacadeWithCache.analyzeFileWithCache(element.getContainingJetFile()).getBindingContext()
val resolvedCall = context[BindingContext.RESOLVED_CALL, element.getCalleeExpression()] val resolvedCall = context[BindingContext.RESOLVED_CALL, element.getCalleeExpression()]
val literalName = resolvedCall?.getResultingDescriptor()?.getValueParameters()?.last?.getName().toString() val literalName = resolvedCall?.getResultingDescriptor()?.getValueParameters()?.last?.getName().toString()
sb.append("$literalName = ") sb.append("$literalName = ")
@@ -43,7 +43,7 @@ public class RemoveExplicitTypeArguments : JetSelfTargetingIntention<JetCallExpr
val context = AnalyzerFacadeWithCache.getContextForElement(element) val context = AnalyzerFacadeWithCache.getContextForElement(element)
if (element.getTypeArguments().isEmpty()) return false if (element.getTypeArguments().isEmpty()) return false
val resolveSession = AnalyzerFacadeWithCache.getLazyResolveSessionForFile((element.getContainingFile() as JetFile)) val resolveSession = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(element.getContainingJetFile())
val injector = InjectorForMacros(element.getProject(), resolveSession.getModuleDescriptor()) val injector = InjectorForMacros(element.getProject(), resolveSession.getModuleDescriptor())
val scope = context[BindingContext.RESOLUTION_SCOPE, element] val scope = context[BindingContext.RESOLUTION_SCOPE, element]
@@ -61,7 +61,7 @@ public class ReplaceWithInfixFunctionCallIntention : JetSelfTargetingIntention<J
numOfTotalValueArguments == 1 && numOfTotalValueArguments == 1 &&
callee != null) { callee != null) {
if (valueArguments?.getArguments()?.size() == 1 && valueArguments?.getArguments()?.first()?.isNamed() ?: false) { if (valueArguments?.getArguments()?.size() == 1 && valueArguments?.getArguments()?.first()?.isNamed() ?: false) {
val file: JetFile = element.getContainingFile() as JetFile val file: JetFile = element.getContainingJetFile()
val bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache(file).getBindingContext() val bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache(file).getBindingContext()
val descriptor = bindingContext.get(BindingContext.RESOLVED_CALL, callee) val descriptor = bindingContext.get(BindingContext.RESOLVED_CALL, callee)
val valueArgumentsMap = descriptor?.getValueArguments() val valueArgumentsMap = descriptor?.getValueArguments()
@@ -140,7 +140,7 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
private static boolean hasPublicMemberDiagnostic(@NotNull JetNamedDeclaration declaration) { private static boolean hasPublicMemberDiagnostic(@NotNull JetNamedDeclaration declaration) {
BindingContext bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) declaration.getContainingFile()).getBindingContext(); BindingContext bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache(declaration.getContainingJetFile()).getBindingContext();
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) { for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
//noinspection ConstantConditions //noinspection ConstantConditions
if (Errors.PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE == diagnostic.getFactory() && declaration == diagnostic.getPsiElement()) { if (Errors.PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE == diagnostic.getFactory() && declaration == diagnostic.getPsiElement()) {
@@ -152,7 +152,7 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
@NotNull @NotNull
public static JetType getTypeForDeclaration(@NotNull JetNamedDeclaration declaration) { public static JetType getTypeForDeclaration(@NotNull JetNamedDeclaration declaration) {
BindingContext bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) declaration.getContainingFile()).getBindingContext(); BindingContext bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache(declaration.getContainingJetFile()).getBindingContext();
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration); DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
JetType type; JetType type;
@@ -29,13 +29,13 @@ fun specifyTypeExplicitly(declaration: JetNamedFunction, typeReference: JetTypeR
} }
fun expressionType(expression: JetExpression): JetType? { fun expressionType(expression: JetExpression): JetType? {
val resolveSession = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(expression.getContainingFile() as JetFile) val resolveSession = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(expression.getContainingJetFile())
val bindingContext = resolveSession.resolveToElement(expression) val bindingContext = resolveSession.resolveToElement(expression)
return bindingContext.get(BindingContext.EXPRESSION_TYPE, expression) return bindingContext.get(BindingContext.EXPRESSION_TYPE, expression)
} }
fun functionReturnType(function: JetNamedFunction): JetType? { fun functionReturnType(function: JetNamedFunction): JetType? {
val resolveSession = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(function.getContainingFile() as JetFile) val resolveSession = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(function.getContainingJetFile())
val bindingContext = resolveSession.resolveToElement(function) val bindingContext = resolveSession.resolveToElement(function)
val descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, function) val descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, function)
if (descriptor == null) return null if (descriptor == null) return null
@@ -105,7 +105,7 @@ public class JetSourceNavigationHelper {
@NotNull @NotNull
private static GlobalSearchScope createLibrarySourcesScope(@NotNull JetNamedDeclaration decompiledDeclaration) { private static GlobalSearchScope createLibrarySourcesScope(@NotNull JetNamedDeclaration decompiledDeclaration) {
JetFile containingFile = (JetFile) decompiledDeclaration.getContainingFile(); JetFile containingFile = decompiledDeclaration.getContainingJetFile();
VirtualFile libraryFile = containingFile.getVirtualFile(); VirtualFile libraryFile = containingFile.getVirtualFile();
if (libraryFile == null) { if (libraryFile == null) {
return GlobalSearchScope.EMPTY_SCOPE; return GlobalSearchScope.EMPTY_SCOPE;
@@ -348,7 +348,7 @@ public class JetSourceNavigationHelper {
@Nullable @Nullable
public static PsiClass getOriginalPsiClassOrCreateLightClass(@NotNull JetClassOrObject classOrObject) { public static PsiClass getOriginalPsiClassOrCreateLightClass(@NotNull JetClassOrObject classOrObject) {
if (LightClassUtil.belongsToKotlinBuiltIns((JetFile) classOrObject.getContainingFile())) { if (LightClassUtil.belongsToKotlinBuiltIns(classOrObject.getContainingJetFile())) {
Name className = classOrObject.getNameAsName(); Name className = classOrObject.getNameAsName();
assert className != null : "Class from BuiltIns should have a name"; assert className != null : "Class from BuiltIns should have a name";
ClassDescriptor classDescriptor = KotlinBuiltIns.getInstance().getBuiltInClassByName(className); ClassDescriptor classDescriptor = KotlinBuiltIns.getInstance().getBuiltInClassByName(className);
@@ -374,7 +374,7 @@ public class JetSourceNavigationHelper {
} }
String fqName = JvmClassName.byInternalName(internalName).getFqNameForClassNameWithoutDollars().asString(); String fqName = JvmClassName.byInternalName(internalName).getFqNameForClassNameWithoutDollars().asString();
JetFile file = (JetFile) classOrObject.getContainingFile(); JetFile file = classOrObject.getContainingJetFile();
VirtualFile vFile = file.getVirtualFile(); VirtualFile vFile = file.getVirtualFile();
Project project = file.getProject(); Project project = file.getProject();
@@ -380,7 +380,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
} }
ResolveSessionForBodies resolveSession = ResolveSessionForBodies resolveSession =
AnalyzerFacadeWithCache.getLazyResolveSessionForFile((JetFile) callNameExpression.getContainingFile()); AnalyzerFacadeWithCache.getLazyResolveSessionForFile(callNameExpression.getContainingJetFile());
BindingContext bindingContext = resolveSession.resolveToElement(callNameExpression); BindingContext bindingContext = resolveSession.resolveToElement(callNameExpression);
JetScope scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, callNameExpression); JetScope scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, callNameExpression);
@@ -53,7 +53,7 @@ public final class AnalyzerFacadeWithCache {
@NotNull @NotNull
public static BindingContext getContextForElement(@NotNull JetElement jetElement) { public static BindingContext getContextForElement(@NotNull JetElement jetElement) {
ResolveSessionForBodies resolveSessionForBodies = getLazyResolveSessionForFile((JetFile) jetElement.getContainingFile()); ResolveSessionForBodies resolveSessionForBodies = getLazyResolveSessionForFile(jetElement.getContainingJetFile());
return resolveSessionForBodies.resolveToElement(jetElement); return resolveSessionForBodies.resolveToElement(jetElement);
} }
@@ -128,7 +128,7 @@ public class ResolveElementCache {
BindingTrace trace = resolveSession.getStorageManager().createSafeTrace( BindingTrace trace = resolveSession.getStorageManager().createSafeTrace(
new DelegatingBindingTrace(resolveSession.getBindingContext(), "trace to resolve element", resolveElement)); new DelegatingBindingTrace(resolveSession.getBindingContext(), "trace to resolve element", resolveElement));
JetFile file = (JetFile) resolveElement.getContainingFile(); JetFile file = resolveElement.getContainingJetFile();
if (resolveElement instanceof JetNamedFunction) { if (resolveElement instanceof JetNamedFunction) {
functionAdditionalResolve(resolveSession, (JetNamedFunction) resolveElement, trace, file); functionAdditionalResolve(resolveSession, (JetNamedFunction) resolveElement, trace, file);
@@ -144,7 +144,7 @@ public class ResolveElementCache {
} }
else if (resolveElement instanceof JetImportDirective) { else if (resolveElement instanceof JetImportDirective) {
JetImportDirective importDirective = (JetImportDirective) resolveElement; JetImportDirective importDirective = (JetImportDirective) resolveElement;
LazyImportScope scope = resolveSession.getScopeProvider().getExplicitImportsScopeForFile((JetFile) importDirective.getContainingFile()); LazyImportScope scope = resolveSession.getScopeProvider().getExplicitImportsScopeForFile(importDirective.getContainingJetFile());
scope.forceResolveAllContents(); scope.forceResolveAllContents();
} }
else if (resolveElement instanceof JetAnnotationEntry) { else if (resolveElement instanceof JetAnnotationEntry) {
@@ -346,7 +346,7 @@ public class ResolveElementCache {
ScopeProvider provider = resolveSession.getScopeProvider(); ScopeProvider provider = resolveSession.getScopeProvider();
JetDeclaration parentDeclaration = PsiTreeUtil.getParentOfType(expression, JetDeclaration.class); JetDeclaration parentDeclaration = PsiTreeUtil.getParentOfType(expression, JetDeclaration.class);
if (parentDeclaration == null) { if (parentDeclaration == null) {
return provider.getFileScope((JetFile) expression.getContainingFile()); return provider.getFileScope(expression.getContainingJetFile());
} }
return provider.getResolutionScopeForDeclaration(parentDeclaration); return provider.getResolutionScopeForDeclaration(parentDeclaration);
} }
@@ -380,7 +380,7 @@ public class ResolveElementCache {
if (expression.getParent() instanceof JetDotQualifiedExpression) { if (expression.getParent() instanceof JetDotQualifiedExpression) {
JetExpression element = ((JetDotQualifiedExpression) expression.getParent()).getReceiverExpression(); JetExpression element = ((JetDotQualifiedExpression) expression.getParent()).getReceiverExpression();
FqName fqName = ((JetFile) expression.getContainingFile()).getPackageFqName(); FqName fqName = expression.getContainingJetFile().getPackageFqName();
PackageViewDescriptor filePackage = resolveSession.getModuleDescriptor().getPackage(fqName); PackageViewDescriptor filePackage = resolveSession.getModuleDescriptor().getPackage(fqName);
assert filePackage != null : "File package should be already resolved and be found"; assert filePackage != null : "File package should be already resolved and be found";
@@ -59,7 +59,7 @@ public class JetClassOrObjectTreeNode extends AbstractPsiBasedNode<JetClassOrObj
data.setPresentableText(classOrObject.getName()); data.setPresentableText(classOrObject.getName());
AbstractTreeNode parent = getParent(); AbstractTreeNode parent = getParent();
if (JetIconProvider.getMainClass((JetFile) classOrObject.getContainingFile()) != null) { if (JetIconProvider.getMainClass(classOrObject.getContainingJetFile()) != null) {
if (parent instanceof JetFileTreeNode) { if (parent instanceof JetFileTreeNode) {
update(parent.getParent()); update(parent.getParent());
} }
@@ -65,7 +65,7 @@ public class AddNameToArgumentFix extends JetIntentionAction<JetValueArgument> {
JetExpression callee = callElement.getCalleeExpression(); JetExpression callee = callElement.getCalleeExpression();
if (!(callee instanceof JetReferenceExpression)) return Collections.emptyList(); if (!(callee instanceof JetReferenceExpression)) return Collections.emptyList();
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) argument.getContainingFile()).getBindingContext(); BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache(argument.getContainingJetFile()).getBindingContext();
ResolvedCall<?> resolvedCall = context.get(BindingContext.RESOLVED_CALL, (JetReferenceExpression) callee); ResolvedCall<?> resolvedCall = context.get(BindingContext.RESOLVED_CALL, (JetReferenceExpression) callee);
if (resolvedCall == null) return Collections.emptyList(); if (resolvedCall == null) return Collections.emptyList();
@@ -93,7 +93,7 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
} }
ResolveSessionForBodies resolveSessionForBodies = ResolveSessionForBodies resolveSessionForBodies =
AnalyzerFacadeWithCache.getLazyResolveSessionForFile((JetFile) element.getContainingFile()); AnalyzerFacadeWithCache.getLazyResolveSessionForFile(element.getContainingJetFile());
List<FqName> result = Lists.newArrayList(); List<FqName> result = Lists.newArrayList();
if (!isSuppressedTopLevelImportInPosition(element)) { if (!isSuppressedTopLevelImportInPosition(element)) {
@@ -50,7 +50,7 @@ public class ChangeFunctionLiteralReturnTypeFix extends JetIntentionAction<JetFu
renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type); renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
functionLiteralReturnTypeRef = element.getFunctionLiteral().getReturnTypeRef(); functionLiteralReturnTypeRef = element.getFunctionLiteral().getReturnTypeRef();
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) element.getContainingFile()).getBindingContext(); BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache(element.getContainingJetFile()).getBindingContext();
JetType functionLiteralType = context.get(BindingContext.EXPRESSION_TYPE, element); JetType functionLiteralType = context.get(BindingContext.EXPRESSION_TYPE, element);
assert functionLiteralType != null : "Type of function literal not available in binding context"; assert functionLiteralType != null : "Type of function literal not available in binding context";
@@ -164,7 +164,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
public IntentionAction createAction(Diagnostic diagnostic) { public IntentionAction createAction(Diagnostic diagnostic) {
JetExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetExpression.class); JetExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetExpression.class);
assert expression != null : "HAS_NEXT_FUNCTION_TYPE_MISMATCH reported on element that is not within any expression"; assert expression != null : "HAS_NEXT_FUNCTION_TYPE_MISMATCH reported on element that is not within any expression";
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) expression.getContainingFile()).getBindingContext(); BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache(expression.getContainingJetFile()).getBindingContext();
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.LOOP_RANGE_HAS_NEXT_RESOLVED_CALL, expression); ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.LOOP_RANGE_HAS_NEXT_RESOLVED_CALL, expression);
if (resolvedCall == null) return null; if (resolvedCall == null) return null;
JetFunction hasNextFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor()); JetFunction hasNextFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
@@ -184,7 +184,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
public IntentionAction createAction(Diagnostic diagnostic) { public IntentionAction createAction(Diagnostic diagnostic) {
JetBinaryExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpression.class); JetBinaryExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpression.class);
assert expression != null : "COMPARE_TO_TYPE_MISMATCH reported on element that is not within any expression"; assert expression != null : "COMPARE_TO_TYPE_MISMATCH reported on element that is not within any expression";
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) expression.getContainingFile()).getBindingContext(); BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache(expression.getContainingJetFile()).getBindingContext();
ResolvedCall<?> resolvedCall = context.get(BindingContext.RESOLVED_CALL, expression.getOperationReference()); ResolvedCall<?> resolvedCall = context.get(BindingContext.RESOLVED_CALL, expression.getOperationReference());
if (resolvedCall == null) return null; if (resolvedCall == null) return null;
PsiElement compareTo = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor()); PsiElement compareTo = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
@@ -164,7 +164,7 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
(DiagnosticWithParameters2<JetFunctionLiteral, Integer, List<JetType>>) diagnostic; (DiagnosticWithParameters2<JetFunctionLiteral, Integer, List<JetType>>) diagnostic;
JetFunctionLiteral functionLiteral = diagnosticWithParameters.getPsiElement(); JetFunctionLiteral functionLiteral = diagnosticWithParameters.getPsiElement();
BindingContext bindingContext = BindingContext bindingContext =
AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) functionLiteral.getContainingFile()).getBindingContext(); AnalyzerFacadeWithCache.analyzeFileWithCache(functionLiteral.getContainingJetFile()).getBindingContext();
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, functionLiteral); DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, functionLiteral);
if (descriptor instanceof FunctionDescriptor) { if (descriptor instanceof FunctionDescriptor) {
@@ -109,7 +109,7 @@ public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclara
@Override @Override
public IntentionAction createAction(Diagnostic diagnostic) { public IntentionAction createAction(Diagnostic diagnostic) {
JetMultiDeclarationEntry entry = ChangeFunctionReturnTypeFix.getMultiDeclarationEntryThatTypeMismatchComponentFunction(diagnostic); JetMultiDeclarationEntry entry = ChangeFunctionReturnTypeFix.getMultiDeclarationEntryThatTypeMismatchComponentFunction(diagnostic);
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) entry.getContainingFile()).getBindingContext(); BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache(entry.getContainingJetFile()).getBindingContext();
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.COMPONENT_RESOLVED_CALL, entry); ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
if (resolvedCall == null) return null; if (resolvedCall == null) return null;
JetFunction componentFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor()); JetFunction componentFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
@@ -130,7 +130,7 @@ public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclara
JetProperty property = QuickFixUtil.getParentElementOfType(diagnostic, JetProperty.class); JetProperty property = QuickFixUtil.getParentElementOfType(diagnostic, JetProperty.class);
if (property != null) { if (property != null) {
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) property.getContainingFile()).getBindingContext(); BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache(property.getContainingJetFile()).getBindingContext();
JetType lowerBoundOfOverriddenPropertiesTypes = QuickFixUtil.findLowerBoundOfOverriddenCallablesReturnTypes(context, property); JetType lowerBoundOfOverriddenPropertiesTypes = QuickFixUtil.findLowerBoundOfOverriddenCallablesReturnTypes(context, property);
DeclarationDescriptor descriptor = context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, property); DeclarationDescriptor descriptor = context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, property);
@@ -102,7 +102,7 @@ public class QuickFixUtil {
@Nullable @Nullable
public static JetParameterList getParameterListOfCallee(@NotNull JetCallExpression callExpression) { public static JetParameterList getParameterListOfCallee(@NotNull JetCallExpression callExpression) {
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) callExpression.getContainingFile()).getBindingContext(); BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache(callExpression.getContainingJetFile()).getBindingContext();
ResolvedCall<?> resolvedCall = context.get(BindingContext.RESOLVED_CALL, callExpression.getCalleeExpression()); ResolvedCall<?> resolvedCall = context.get(BindingContext.RESOLVED_CALL, callExpression.getCalleeExpression());
if (resolvedCall == null) return null; if (resolvedCall == null) return null;
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor()); PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
@@ -254,7 +254,7 @@ public class KotlinInlineValHandler extends InlineActionHandler {
} }
private static void addFunctionLiteralParameterTypes(@NotNull String parameters, @NotNull List<JetExpression> inlinedExpressions) { private static void addFunctionLiteralParameterTypes(@NotNull String parameters, @NotNull List<JetExpression> inlinedExpressions) {
JetFile containingFile = (JetFile) inlinedExpressions.get(0).getContainingFile(); JetFile containingFile = inlinedExpressions.get(0).getContainingJetFile();
List<JetFunctionLiteralExpression> functionsToAddParameters = Lists.newArrayList(); List<JetFunctionLiteralExpression> functionsToAddParameters = Lists.newArrayList();
ResolveSessionForBodies resolveSessionForBodies = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(containingFile); ResolveSessionForBodies resolveSessionForBodies = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(containingFile);
@@ -314,7 +314,7 @@ public class KotlinInlineValHandler extends InlineActionHandler {
} }
private static void addTypeArguments(@NotNull String typeArguments, @NotNull List<JetExpression> inlinedExpressions) { private static void addTypeArguments(@NotNull String typeArguments, @NotNull List<JetExpression> inlinedExpressions) {
JetFile containingFile = (JetFile) inlinedExpressions.get(0).getContainingFile(); JetFile containingFile = inlinedExpressions.get(0).getContainingJetFile();
List<JetCallExpression> callsToAddArguments = Lists.newArrayList(); List<JetCallExpression> callsToAddArguments = Lists.newArrayList();
ResolveSessionForBodies resolveSessionForBodies = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(containingFile); ResolveSessionForBodies resolveSessionForBodies = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(containingFile);
@@ -118,7 +118,7 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
} }
} }
ResolveSessionForBodies resolveSession = ResolveSessionForBodies resolveSession =
AnalyzerFacadeWithCache.getLazyResolveSessionForFile((JetFile) expression.getContainingFile()); AnalyzerFacadeWithCache.getLazyResolveSessionForFile(expression.getContainingJetFile());
BindingContext bindingContext = resolveSession.resolveToElement(expression); BindingContext bindingContext = resolveSession.resolveToElement(expression);
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
JetScope scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, expression); JetScope scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, expression);
@@ -32,7 +32,7 @@ import java.util.List;
public class KotlinMoveFilesOrDirectoriesHandler extends MoveFilesOrDirectoriesHandler { public class KotlinMoveFilesOrDirectoriesHandler extends MoveFilesOrDirectoriesHandler {
public static boolean isMovableClass(JetClassOrObject clazz) { public static boolean isMovableClass(JetClassOrObject clazz) {
if (!(clazz.getParent() instanceof JetFile)) return false; if (!(clazz.getParent() instanceof JetFile)) return false;
JetFile file = (JetFile) clazz.getContainingFile(); JetFile file = clazz.getContainingJetFile();
List<JetDeclaration> declarations = file.getDeclarations(); List<JetDeclaration> declarations = file.getDeclarations();
for (JetDeclaration declaration : declarations) { for (JetDeclaration declaration : declarations) {
if (declaration instanceof JetClassOrObject && declaration != clazz) return false; if (declaration instanceof JetClassOrObject && declaration != clazz) return false;
@@ -50,7 +50,7 @@ public class RenameJetClassProcessor extends RenamePsiElementProcessor {
JetClassOrObject classOrObject = getJetClassOrObject(element, false, null); JetClassOrObject classOrObject = getJetClassOrObject(element, false, null);
if (classOrObject != null) { if (classOrObject != null) {
JetFile file = (JetFile) classOrObject.getContainingFile(); JetFile file = classOrObject.getContainingJetFile();
VirtualFile virtualFile = file.getVirtualFile(); VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile != null) { if (virtualFile != null) {
@@ -44,7 +44,7 @@ public class JetPsiHeuristicsUtil {
if (isTopLevelDeclaration(classOrObject) && classOrObject.hasModifier(JetTokens.PRIVATE_KEYWORD)) { if (isTopLevelDeclaration(classOrObject) && classOrObject.hasModifier(JetTokens.PRIVATE_KEYWORD)) {
// The class is declared private in the targetPackage // The class is declared private in the targetPackage
// It is visible in this package and all of its subpackages // It is visible in this package and all of its subpackages
JetFile targetFile = (JetFile) classOrObject.getContainingFile(); JetFile targetFile = classOrObject.getContainingJetFile();
FqName targetPackage = targetFile.getPackageFqName(); FqName targetPackage = targetFile.getPackageFqName();
FqName fromPackage = fromFile.getPackageFqName(); FqName fromPackage = fromFile.getPackageFqName();
@@ -4,7 +4,7 @@ class A {
private fun formatElement(var element: PsiElement): String { private fun formatElement(var element: PsiElement): String {
element = JetPsiUtil.ascendIfPropertyAccessor(element) element = JetPsiUtil.ascendIfPropertyAccessor(element)
if (element is JetNamedFunction || element is JetProperty) { if (element is JetNamedFunction || element is JetProperty) {
val bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache((element.getContainingFile() as JetFile)).getBindingContext() val bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache(element.getContainingJetFile()).getBindingContext()
val declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element) val declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element)
if (declarationDescriptor is CallableMemberDescriptor) { if (declarationDescriptor is CallableMemberDescriptor) {
@@ -3,7 +3,7 @@ class A {
element = JetPsiUtil.ascendIfPropertyAccessor(element); element = JetPsiUtil.ascendIfPropertyAccessor(element);
if (element instanceof JetNamedFunction || element instanceof JetProperty) { if (element instanceof JetNamedFunction || element instanceof JetProperty) {
BindingContext bindingContext = BindingContext bindingContext =
AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) element.getContainingFile()).getBindingContext(); AnalyzerFacadeWithCache.analyzeFileWithCache(element.getContainingJetFile()).getBindingContext();
DeclarationDescriptor declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element); DeclarationDescriptor declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);
if (declarationDescriptor instanceof CallableMemberDescriptor) { if (declarationDescriptor instanceof CallableMemberDescriptor) {
@@ -122,7 +122,7 @@ public abstract class AbstractOverrideImplementTest extends LightCodeInsightFixt
final JetClassOrObject classOrObject = PsiTreeUtil.getParentOfType(elementAtCaret, JetClassOrObject.class); final JetClassOrObject classOrObject = PsiTreeUtil.getParentOfType(elementAtCaret, JetClassOrObject.class);
assertNotNull("Caret should be inside class or object", classOrObject); assertNotNull("Caret should be inside class or object", classOrObject);
final JetFile jetFile = (JetFile) classOrObject.getContainingFile(); final JetFile jetFile = classOrObject.getContainingJetFile();
final ResolveSessionForBodies resolveSession = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(jetFile); final ResolveSessionForBodies resolveSession = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(jetFile);
Set<CallableMemberDescriptor> descriptors = Set<CallableMemberDescriptor> descriptors =
handler.collectMethodsToGenerate(classOrObject, resolveSession.resolveToElement(classOrObject)); handler.collectMethodsToGenerate(classOrObject, resolveSession.resolveToElement(classOrObject));
@@ -177,7 +177,7 @@ public abstract class AbstractOverrideImplementTest extends LightCodeInsightFixt
final JetClassOrObject classOrObject = PsiTreeUtil.getParentOfType(elementAtCaret, JetClassOrObject.class); final JetClassOrObject classOrObject = PsiTreeUtil.getParentOfType(elementAtCaret, JetClassOrObject.class);
assertNotNull("Caret should be inside class or object", classOrObject); assertNotNull("Caret should be inside class or object", classOrObject);
final JetFile jetFile = (JetFile) classOrObject.getContainingFile(); final JetFile jetFile = classOrObject.getContainingJetFile();
final BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(classOrObject); final BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(classOrObject);
Set<CallableMemberDescriptor> descriptors = handler.collectMethodsToGenerate(classOrObject, bindingContext); Set<CallableMemberDescriptor> descriptors = handler.collectMethodsToGenerate(classOrObject, bindingContext);