From ea3f550b589fcb613b7a25ba0a0ec4f065a89ecf Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Tue, 4 Oct 2022 02:15:30 +0900 Subject: [PATCH] [FE] Support analyzable files throughout all 'KtPsiFactory' API Before, the only way of getting analyzable elements was to create an analyzable file by using 'createAnalyzableFile()'. So made all utilities available in 'KtPsiFactory' useless as they delegate to 'createFile()' that always set the 'doNotAnalyze' flag. The new behavior is to pass the 'analysisContext' instead if it is passed to the 'KtPsiFactory' constructor. The newly appeared API is going to be used in the Kotlin's UAST implementation. --- .../test/framework/services/TypeParser.kt | 2 +- .../classes/KtLightClassForFacadeBase.kt | 2 +- .../kotlin/asJava/classes/implUtils.kt | 2 +- .../asJava/elements/KtLightMethodImpl.kt | 2 +- .../kotlin/codegen/ExpressionCodegen.java | 2 +- .../FunctionReferenceGenerationStrategy.java | 2 +- .../resolve/DelegatedPropertyResolver.kt | 4 +- .../kotlin/resolve/calls/CallTransformer.java | 2 +- .../ControlStructureTypingVisitor.java | 2 +- .../DoubleColonExpressionResolver.kt | 2 +- .../expressions/ExpressionTypingUtils.java | 2 +- .../PatternMatchingTypingVisitor.kt | 2 +- .../asJava/elements/KtLightPsiLiteral.kt | 2 +- .../psi/EditCommaSeparatedListHelper.kt | 2 +- .../jetbrains/kotlin/psi/KtClassOrObject.kt | 4 +- .../jetbrains/kotlin/psi/KtCodeFragment.kt | 2 +- .../jetbrains/kotlin/psi/KtExpressionImpl.kt | 9 ++-- .../src/org/jetbrains/kotlin/psi/KtFile.kt | 2 +- .../org/jetbrains/kotlin/psi/KtImportAlias.kt | 2 +- .../kotlin/psi/KtImportsFactory.java | 4 +- .../psi/KtNamedDeclarationNotStubbed.java | 4 +- .../kotlin/psi/KtNamedDeclarationStub.java | 5 +- .../kotlin/psi/KtPrimaryConstructor.kt | 4 +- .../org/jetbrains/kotlin/psi/KtPsiFactory.kt | 51 ++++++++++++++----- .../jetbrains/kotlin/psi/addRemoveModifier.kt | 6 +-- .../jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt | 6 +-- .../resolve/ExpectedResolveDataUtil.java | 4 +- .../kotlin/test/KotlinTestUtils.java | 4 +- .../kotlin/parsing/AbstractParsingTest.java | 2 +- .../jetbrains/kotlin/psi/KtPsiUtilTest.java | 4 +- .../kotlin/types/BoundsSubstitutorTest.java | 4 +- .../types/DefaultModalityModifiersTest.java | 11 ++-- .../kotlin/types/KotlinOverloadTest.java | 4 +- .../kotlin/types/KotlinOverridingTest.java | 4 +- .../kotlin/types/KotlinTypeCheckerTest.java | 11 ++-- .../kotlin/types/TypeSubstitutorTest.java | 6 +-- .../kotlin/types/TypeUnifierTest.java | 5 +- 37 files changed, 102 insertions(+), 86 deletions(-) diff --git a/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/services/TypeParser.kt b/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/services/TypeParser.kt index 2276e205f13..17c6a37983f 100644 --- a/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/services/TypeParser.kt +++ b/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/services/TypeParser.kt @@ -21,7 +21,7 @@ object TypeParser { contextElement: KtElement, scopeForTypeParameters: KtElement, ): KtType { - val type = KtPsiFactory(contextElement).createType(stringType) + val type = KtPsiFactory(contextElement.project).createType(stringType) return convertType(type.typeElement ?: incorrectType(type), scopeForTypeParameters) } diff --git a/analysis/light-classes-base/src/org/jetbrains/kotlin/asJava/classes/KtLightClassForFacadeBase.kt b/analysis/light-classes-base/src/org/jetbrains/kotlin/asJava/classes/KtLightClassForFacadeBase.kt index d960253d5cc..47eef88fae8 100644 --- a/analysis/light-classes-base/src/org/jetbrains/kotlin/asJava/classes/KtLightClassForFacadeBase.kt +++ b/analysis/light-classes-base/src/org/jetbrains/kotlin/asJava/classes/KtLightClassForFacadeBase.kt @@ -146,7 +146,7 @@ abstract class KtLightClassForFacadeBase constructor( continue } - val psiFactory = KtPsiFactory(this) + val psiFactory = KtPsiFactory(project) val annotationText = "${JVM_NAME_SHORT}(\"$name\")" val newFileAnnotationList = psiFactory.createFileAnnotationListWithAnnotation(annotationText) val annotationList = file.fileAnnotationList diff --git a/analysis/light-classes-base/src/org/jetbrains/kotlin/asJava/classes/implUtils.kt b/analysis/light-classes-base/src/org/jetbrains/kotlin/asJava/classes/implUtils.kt index dc91c5d7728..988ac391318 100644 --- a/analysis/light-classes-base/src/org/jetbrains/kotlin/asJava/classes/implUtils.kt +++ b/analysis/light-classes-base/src/org/jetbrains/kotlin/asJava/classes/implUtils.kt @@ -48,7 +48,7 @@ fun PsiReferenceList.addSuperTypeEntry( // Only classes may be mentioned in 'extends' list, thus create super call instead simple type reference val entryToAdd = if ((reference.parent as? PsiReferenceList)?.role == PsiReferenceList.Role.IMPLEMENTS_LIST && role == PsiReferenceList.Role.EXTENDS_LIST) { - KtPsiFactory(this).createSuperTypeCallEntry("${entry.text}()") + KtPsiFactory(project).createSuperTypeCallEntry("${entry.text}()") } else entry // TODO: implement KtSuperListEntry qualification/shortening when inserting reference from another context if (entry.parent != superTypeList) { diff --git a/analysis/light-classes-base/src/org/jetbrains/kotlin/asJava/elements/KtLightMethodImpl.kt b/analysis/light-classes-base/src/org/jetbrains/kotlin/asJava/elements/KtLightMethodImpl.kt index d5cf041cce8..8baeb454c25 100644 --- a/analysis/light-classes-base/src/org/jetbrains/kotlin/asJava/elements/KtLightMethodImpl.kt +++ b/analysis/light-classes-base/src/org/jetbrains/kotlin/asJava/elements/KtLightMethodImpl.kt @@ -58,7 +58,7 @@ abstract class KtLightMethodImpl protected constructor( val nameExpression = jvmNameAnnotation?.let { JvmFileClassUtil.getLiteralStringEntryFromAnnotation(it) } if (nameExpression != null) { - nameExpression.replace(KtPsiFactory(this).createLiteralStringTemplateEntry(name)) + nameExpression.replace(KtPsiFactory(project).createLiteralStringTemplateEntry(name)) } else { val toRename = kotlinOrigin as? PsiNamedElement ?: cannotModify() toRename.setName(newNameForOrigin) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index bc9cdf2b790..d0368f0cba2 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -5375,7 +5375,7 @@ The "returned" value of try expression with no finally is either the last expres } public Call makeFakeCall(ReceiverValue initializerAsReceiver) { - KtSimpleNameExpression fake = KtPsiFactoryKt.KtPsiFactory(state.getProject(), false).createSimpleName("fake"); + KtSimpleNameExpression fake = new KtPsiFactory(state.getProject(), false).createSimpleName("fake"); return CallMaker.makeCall(fake, initializerAsReceiver); } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java index 1a58376c340..eaad38eab58 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java @@ -233,7 +233,7 @@ public class FunctionReferenceGenerationStrategy extends FunctionGenerationStrat ) { if (receiver == null) return null; - KtExpression receiverExpression = KtPsiFactoryKt.KtPsiFactory(state.getProject(), false).createExpression("callableReferenceFakeReceiver"); + KtExpression receiverExpression = new KtPsiFactory(state.getProject(), false).createExpression("callableReferenceFakeReceiver"); codegen.tempVariables.put(receiverExpression, receiverParameterStackValue(signature, codegen)); return ExpressionReceiver.Companion.create(receiverExpression, receiver.getType(), BindingContext.EMPTY); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt index 130cc871ec6..2fe941ea5c6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt @@ -370,7 +370,7 @@ class DelegatedPropertyResolver( val hasThis = propertyDescriptor.extensionReceiverParameter != null || propertyDescriptor.dispatchReceiverParameter != null val arguments = Lists.newArrayList() - val psiFactory = KtPsiFactory(delegateExpression, markGenerated = false) + val psiFactory = KtPsiFactory(delegateExpression.project, markGenerated = false) arguments.add(psiFactory.createExpression(if (hasThis) "this" else "null")) arguments.add(psiFactory.createExpressionForProperty()) @@ -458,7 +458,7 @@ class DelegatedPropertyResolver( context: ExpressionTypingContext ): OverloadResolutionResults { val propertyHasReceiver = propertyDescriptor.dispatchReceiverParameter != null - val arguments = KtPsiFactory(delegateExpression, markGenerated = false).run { + val arguments = KtPsiFactory(delegateExpression.project, markGenerated = false).run { listOf( createExpression(if (propertyHasReceiver) "this" else "null"), createExpressionForProperty() diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallTransformer.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallTransformer.java index 584a75116f4..b55544c56b0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallTransformer.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallTransformer.java @@ -107,7 +107,7 @@ public class CallTransformer { this.explicitExtensionReceiver = explicitExtensionReceiver; this.calleeExpressionAsDispatchReceiver = calleeExpressionAsDispatchReceiver; this.fakeInvokeExpression = - (KtSimpleNameExpression) KtPsiFactoryKt.KtPsiFactory(call.getCallElement(), false) + (KtSimpleNameExpression) new KtPsiFactory(call.getCallElement().getProject(), false) .createExpression(OperatorNameConventions.INVOKE.asString()); itIsVariableAsFunctionCall = functionCall; } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java index 88f350c043d..88035f16732 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java @@ -107,7 +107,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { return getTypeInfoWhenOnlyOneBranchIsPresent( elseBranch, elseScope, elseInfo, thenInfo, context, ifExpression); } - KtPsiFactory psiFactory = KtPsiFactoryKt.KtPsiFactory(ifExpression, false); + KtPsiFactory psiFactory = new KtPsiFactory(ifExpression.getProject(), false); KtBlockExpression thenBlock = psiFactory.wrapInABlockWrapper(thenBranch); KtBlockExpression elseBlock = psiFactory.wrapInABlockWrapper(elseBranch); Call callForIf = createCallForSpecialConstruction(ifExpression, ifExpression, Lists.newArrayList(thenBlock, elseBlock)); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt index 49d408e32c6..32ff7acf072 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt @@ -271,7 +271,7 @@ class DoubleColonExpressionResolver( private fun KtQualifiedExpression.buildNewExpressionForReservedGenericPropertyCallChainResolution(): KtExpression? { val parts = this.getQualifierChainParts()?.map { it.getQualifiedNameStringPart() ?: return null } ?: return null val qualifiedExpressionText = parts.joinToString(separator = ".") - return KtPsiFactory(this, markGenerated = false).createExpression(qualifiedExpressionText) + return KtPsiFactory(project, markGenerated = false).createExpression(qualifiedExpressionText) } private fun resolveReservedExpressionOnLHS(expression: KtExpression, c: ExpressionTypingContext): DoubleColonLHS.Expression? { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingUtils.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingUtils.java index a0a3b501c0b..2afb2cf2d21 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingUtils.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingUtils.java @@ -93,7 +93,7 @@ public class ExpressionTypingUtils { @NotNull String argumentName, @NotNull KotlinType argumentType ) { - KtExpression fakeExpression = KtPsiFactoryKt.KtPsiFactory(project, false).createExpression(argumentName); + KtExpression fakeExpression = new KtPsiFactory(project, false).createExpression(argumentName); trace.recordType(fakeExpression, argumentType); trace.record(PROCESSED, fakeExpression); return fakeExpression; diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.kt index 5be3005aa66..f9843c6f9ae 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.kt @@ -334,7 +334,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping } private fun wrapWhenEntryExpressionsAsSpecialCallArguments(expression: KtWhenExpression): List { - val psiFactory = KtPsiFactory(expression) + val psiFactory = KtPsiFactory(expression.project) return expression.entries.mapNotNull { whenEntry -> whenEntry.expression?.let { psiFactory.wrapInABlockWrapper(it) } } diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/KtLightPsiLiteral.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/KtLightPsiLiteral.kt index edcb4c4a6dc..fa54e1977ad 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/KtLightPsiLiteral.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/KtLightPsiLiteral.kt @@ -34,7 +34,7 @@ open class KtLightPsiLiteral( override fun replace(newElement: PsiElement): PsiElement { val value = (newElement as? PsiLiteral)?.value as? String ?: return this - kotlinOrigin.replace(KtPsiFactory(this).createExpression("\"${StringUtil.escapeStringCharacters(value)}\"")) + kotlinOrigin.replace(KtPsiFactory(project).createExpression("\"${StringUtil.escapeStringCharacters(value)}\"")) return this } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/EditCommaSeparatedListHelper.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/EditCommaSeparatedListHelper.kt index aa033893b74..f3646ac4409 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/EditCommaSeparatedListHelper.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/EditCommaSeparatedListHelper.kt @@ -45,7 +45,7 @@ object EditCommaSeparatedListHelper { list.add(item) as TItem } } else { - var comma = KtPsiFactory(list).createComma() + var comma = KtPsiFactory(list.project).createComma() return if (anchor != null) { comma = list.addAfter(comma, anchor) list.addAfter(item, comma) as TItem diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtClassOrObject.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/KtClassOrObject.kt index 801828c399b..9d2514d42b6 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtClassOrObject.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtClassOrObject.kt @@ -53,7 +53,7 @@ abstract class KtClassOrObject : return EditCommaSeparatedListHelper.addItem(it, superTypeListEntries, superTypeListEntry) } - val psiFactory = KtPsiFactory(this) + val psiFactory = KtPsiFactory(project) val specifierListToAdd = psiFactory.createSuperTypeCallEntry("A()").replace(superTypeListEntry).parent val colon = addBefore(psiFactory.createColon(), getBody()) return (addAfter(specifierListToAdd, colon) as KtSuperTypeList).entries.first() @@ -202,7 +202,7 @@ abstract class KtClassOrObject : fun KtClassOrObject.getOrCreateBody(): KtClassBody { getBody()?.let { return it } - val newBody = KtPsiFactory(this).createEmptyClassBody() + val newBody = KtPsiFactory(project).createEmptyClassBody() if (this is KtEnumEntry) return addAfter(newBody, initializerList ?: nameIdentifier) as KtClassBody return add(newBody) as KtClassBody } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtCodeFragment.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/KtCodeFragment.kt index 4a8a97e3467..57e9a287fba 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtCodeFragment.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtCodeFragment.kt @@ -151,7 +151,7 @@ abstract class KtCodeFragment( fun importsAsImportList(): KtImportList? { if (imports.isNotEmpty() && context != null) { - return KtPsiFactory(this).createAnalyzableFile("imports_for_codeFragment.kt", imports.joinToString("\n"), context).importList + return KtPsiFactory.contextual(context).createFile("imports_for_codeFragment.kt", imports.joinToString("\n")).importList } return null } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtExpressionImpl.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/KtExpressionImpl.kt index 0dfb2152c40..e98cbd7976e 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtExpressionImpl.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtExpressionImpl.kt @@ -35,15 +35,14 @@ abstract class KtExpressionImpl(node: ASTNode) : KtElementImpl(node), KtExpressi when (parent) { is KtExpression, is KtValueArgument -> { if (KtPsiUtil.areParenthesesNecessary(newElement, expression, parent as KtElement)) { - return rawReplaceHandler( - KtPsiFactory(expression).createExpressionByPattern("($0)", newElement, reformat = reformat) - ) + val factory = KtPsiFactory(expression.project) + return rawReplaceHandler(factory.createExpressionByPattern("($0)", newElement, reformat = reformat)) } } is KtSimpleNameStringTemplateEntry -> { if (newElement !is KtSimpleNameExpression && !newElement.isThisWithoutLabel()) { - val newEntry = - parent.replace(KtPsiFactory(expression).createBlockStringTemplateEntry(newElement)) as KtBlockStringTemplateEntry + val factory = KtPsiFactory(expression.project) + val newEntry = parent.replace(factory.createBlockStringTemplateEntry(newElement)) as KtBlockStringTemplateEntry return newEntry.expression!! } } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtFile.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/KtFile.kt index 80195aa050a..230a5d79f04 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtFile.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtFile.kt @@ -94,7 +94,7 @@ open class KtFile(viewProvider: FileViewProvider, val isCompiled: Boolean) : if (packageDirective != null) { packageDirective.fqName = value } else { - val newPackageDirective = KtPsiFactory(this).createPackageDirectiveIfNeeded(value) ?: return + val newPackageDirective = KtPsiFactory(project).createPackageDirectiveIfNeeded(value) ?: return addAfter(newPackageDirective, null) } } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtImportAlias.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/KtImportAlias.kt index 3f78de63db5..4aa4cc37ab6 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtImportAlias.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtImportAlias.kt @@ -39,7 +39,7 @@ class KtImportAlias : KtElementImplStub, PsiNameIdentifie override fun getName() = stub?.getName() ?: nameIdentifier?.text override fun setName(name: String): PsiElement { - nameIdentifier?.replace(KtPsiFactory(this).createNameIdentifier(name)) + nameIdentifier?.replace(KtPsiFactory(project).createNameIdentifier(name)) return this } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtImportsFactory.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtImportsFactory.java index 1ca4bb0483b..e331e2a66a2 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtImportsFactory.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtImportsFactory.java @@ -45,7 +45,7 @@ public class KtImportsFactory { return directive; } - KtImportDirective createdDirective = KtPsiFactoryKt.KtPsiFactory(project, false).createImportDirective(importPath); + KtImportDirective createdDirective = new KtPsiFactory(project, false).createImportDirective(importPath); importsCache.put(importPath, createdDirective); return createdDirective; @@ -58,6 +58,6 @@ public class KtImportsFactory { @NotNull public Collection createImportDirectivesNotCached(@NotNull Collection importPaths) { - return KtPsiFactoryKt.KtPsiFactory(project, false).createImportDirectives(importPaths); + return new KtPsiFactory(project, false).createImportDirectives(importPaths); } } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedDeclarationNotStubbed.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedDeclarationNotStubbed.java index 78653833884..544f8089eb6 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedDeclarationNotStubbed.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedDeclarationNotStubbed.java @@ -24,8 +24,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.lexer.KtTokens; -import static org.jetbrains.kotlin.psi.KtPsiFactoryKt.KtPsiFactory; - // TODO: Remove when all named declarations get stubs @Deprecated abstract class KtNamedDeclarationNotStubbed extends KtDeclarationImpl implements KtNamedDeclaration { @@ -67,7 +65,7 @@ abstract class KtNamedDeclarationNotStubbed extends KtDeclarationImpl implements PsiElement identifier = getNameIdentifier(); if (identifier == null) throw new IncorrectOperationException(); - return identifier.replace(KtPsiFactory(this).createNameIdentifier(name)); + return identifier.replace(new KtPsiFactory(getProject()).createNameIdentifier(name)); } @Override diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedDeclarationStub.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedDeclarationStub.java index eb6d4f4cfa0..f2f9e347e92 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedDeclarationStub.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedDeclarationStub.java @@ -32,8 +32,6 @@ import org.jetbrains.kotlin.util.OperatorNameConventions; import java.util.Set; -import static org.jetbrains.kotlin.psi.KtPsiFactoryKt.KtPsiFactory; - abstract class KtNamedDeclarationStub> extends KtDeclarationStub implements KtNamedDeclaration { public KtNamedDeclarationStub(@NotNull T stub, @NotNull IStubElementType nodeType) { super(stub, nodeType); @@ -99,8 +97,7 @@ abstract class KtNamedDeclarationStub> extends } } - PsiElement newIdentifier = - KtPsiFactory(this).createNameIdentifierIfPossible(KtPsiUtilKt.quoteIfNeeded(name)); + PsiElement newIdentifier = new KtPsiFactory(getProject()).createNameIdentifierIfPossible(KtPsiUtilKt.quoteIfNeeded(name)); if (newIdentifier != null) { KtPsiUtilKt.astReplace(identifier, newIdentifier); } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtPrimaryConstructor.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/KtPrimaryConstructor.kt index e283b19572f..2676e26b3c5 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtPrimaryConstructor.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtPrimaryConstructor.kt @@ -34,7 +34,7 @@ class KtPrimaryConstructor : KtConstructor { override fun getContainingClassOrObject() = parent as KtClassOrObject private fun getOrCreateConstructorKeyword(): PsiElement { - return getConstructorKeyword() ?: addBefore(KtPsiFactory(this).createConstructorKeyword(), valueParameterList!!) + return getConstructorKeyword() ?: addBefore(KtPsiFactory(project).createConstructorKeyword(), valueParameterList!!) } fun removeRedundantConstructorKeywordAndSpace() { @@ -53,7 +53,7 @@ class KtPrimaryConstructor : KtConstructor { } } else { if (modifier == KtTokens.PUBLIC_KEYWORD) return - val newModifierList = KtPsiFactory(this).createModifierList(modifier) + val newModifierList = KtPsiFactory(project).createModifierList(modifier) addBefore(newModifierList, getOrCreateConstructorKeyword()) } } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt index 2abe2fe0a59..d36ceb3ee0c 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt @@ -21,14 +21,19 @@ import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.psiUtil.isIdentifier import org.jetbrains.kotlin.resolve.ImportPath -import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments import org.jetbrains.kotlin.utils.checkWithAttachment @JvmOverloads -fun KtPsiFactory(project: Project?, markGenerated: Boolean = true): KtPsiFactory = KtPsiFactory(project!!, markGenerated) +@JvmName("KtPsiFactory") +@Suppress("FunctionName", "unused") +@Deprecated("Use 'KtPsiFactory' constructor instead", level = DeprecationLevel.HIDDEN) +fun KtPsiFactoryOld(project: Project?, markGenerated: Boolean = true): KtPsiFactory = KtPsiFactory(project!!, markGenerated) @JvmOverloads -fun KtPsiFactory(elementForProject: PsiElement, markGenerated: Boolean = true): KtPsiFactory = +@JvmName("KtPsiFactory") +@Suppress("FunctionName", "unused") +@Deprecated("Use 'KtPsiFactory' constructor instead", level = DeprecationLevel.HIDDEN) +fun KtPsiFactoryOld(elementForProject: PsiElement, markGenerated: Boolean = true): KtPsiFactory = KtPsiFactory(elementForProject.project, markGenerated) private const val DO_NOT_ANALYZE_NOTIFICATION = "This file was created by KtPsiFactory and should not be analyzed\n" + @@ -43,7 +48,25 @@ var KtFile.analysisContext: PsiElement? by UserDataProperty(Key.create("ANALYSIS * to be inserted in the user source code (this ensures that the elements will be formatted correctly). In other cases, `markGenerated` * should be false, which saves time and memory. */ -class KtPsiFactory @JvmOverloads constructor(private val project: Project, val markGenerated: Boolean = true) { +class KtPsiFactory private constructor( + private val project: Project, + private val markGenerated: Boolean, + private val context: PsiElement? +) { + companion object { + @JvmStatic + @JvmOverloads + fun contextual(context: PsiElement, markGenerated: Boolean = true): KtPsiFactory { + return KtPsiFactory(context.project, markGenerated, context) + } + } + + @JvmOverloads + constructor(project: Project, markGenerated: Boolean = true) : this(project, markGenerated, context = null) + + @JvmOverloads + @Deprecated("Use 'KtPsiFactory(project, markGenerated)' or 'KtPsiFactory.contextual(context, markGenerated)' instead") + constructor(element: KtElement, markGenerated: Boolean = true) : this(element.project, markGenerated, context = null) fun createValKeyword(): PsiElement { val property = createProperty("val x = 1") @@ -217,17 +240,24 @@ class KtPsiFactory @JvmOverloads constructor(private val project: Project, val m fun createFile(@NonNls fileName: String, @NonNls text: String): KtFile { val file = doCreateFile(fileName, text) - file.doNotAnalyze = DO_NOT_ANALYZE_NOTIFICATION + val analysisContext = this@KtPsiFactory.context + if (analysisContext != null) { + file.analysisContext = analysisContext + } else { + file.doNotAnalyze = DO_NOT_ANALYZE_NOTIFICATION + } return file } + @Deprecated("Call 'createFile()' on a contextual 'KtPsiFactory' instead") fun createAnalyzableFile(@NonNls fileName: String, @NonNls text: String, contextToAnalyzeIn: PsiElement): KtFile { val file = doCreateFile(fileName, text) file.analysisContext = contextToAnalyzeIn return file } + @Deprecated("Call 'createPhysicalFile() on a contextual 'KtPsiFactory' instead") fun createFileWithLightClassSupport(@NonNls fileName: String, @NonNls text: String, contextToAnalyzeIn: PsiElement): KtFile { val file = createPhysicalFile(fileName, text) file.analysisContext = contextToAnalyzeIn @@ -235,13 +265,10 @@ class KtPsiFactory @JvmOverloads constructor(private val project: Project, val m } fun createPhysicalFile(@NonNls fileName: String, @NonNls text: String): KtFile { - return PsiFileFactory.getInstance(project).createFileFromText( - fileName, - KotlinFileType.INSTANCE, - text, - LocalTimeCounter.currentTime(), - true - ) as KtFile + val time = LocalTimeCounter.currentTime() + val file = PsiFileFactory.getInstance(project).createFileFromText(fileName, KotlinFileType.INSTANCE, text, time, true) as KtFile + file.analysisContext = this@KtPsiFactory.context + return file } fun createProperty( diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/addRemoveModifier.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/addRemoveModifier.kt index 541164fac70..f8031ae28b6 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/addRemoveModifier.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/addRemoveModifier.kt @@ -22,7 +22,7 @@ private fun KtModifierListOwner.addModifierList(newModifierList: KtModifierList) } private fun createModifierList(text: String, owner: KtModifierListOwner): KtModifierList { - return owner.addModifierList(KtPsiFactory(owner).createModifierList(text)) + return owner.addModifierList(KtPsiFactory(owner.project).createModifierList(text)) } fun KtModifierListOwner.setModifierList(newModifierList: KtModifierList) { @@ -55,7 +55,7 @@ fun addAnnotationEntry(owner: KtModifierListOwner, annotationEntry: KtAnnotation internal fun addModifier(modifierList: KtModifierList, modifier: KtModifierKeywordToken) { if (modifierList.hasModifier(modifier)) return - val newModifier = KtPsiFactory(modifierList).createModifier(modifier) + val newModifier = KtPsiFactory(modifierList.project).createModifier(modifier) val modifierToReplace = MODIFIERS_TO_REPLACE[modifier] ?.mapNotNull { modifierList.getModifier(it) } ?.firstOrNull() @@ -113,7 +113,7 @@ fun removeModifier(owner: KtModifierListOwner, modifier: KtModifierKeywordToken) val lastChild = it.lastChild if (lastChild is PsiComment) { - it.addAfter(KtPsiFactory(owner).createNewLine(), lastChild) + it.addAfter(KtPsiFactory(owner.project).createNewLine(), lastChild) } } } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt index 1c40ba8798b..8acaf5c0760 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt @@ -548,7 +548,7 @@ fun isDoubleColonReceiver(expression: KtExpression) = fun KtFunctionLiteral.getOrCreateParameterList(): KtParameterList { valueParameterList?.let { return it } - val psiFactory = KtPsiFactory(this) + val psiFactory = KtPsiFactory(project) val anchor = lBrace val newParameterList = addAfter(psiFactory.createLambdaParameterList("x"), anchor) as KtParameterList @@ -589,7 +589,7 @@ fun KtFunctionLiteral.findLabelAndCall(): Pair { fun KtCallExpression.getOrCreateValueArgumentList(): KtValueArgumentList { valueArgumentList?.let { return it } return addAfter( - KtPsiFactory(this).createCallArguments("()"), + KtPsiFactory(project).createCallArguments("()"), typeArgumentList ?: calleeExpression, ) as KtValueArgumentList } @@ -598,7 +598,7 @@ fun KtCallExpression.addTypeArgument(typeArgument: KtTypeProjection) { if (typeArgumentList != null) { typeArgumentList?.addArgument(typeArgument) } else { - addAfter(KtPsiFactory(this).createTypeArguments("<${typeArgument.text}>"), calleeExpression) + addAfter(KtPsiFactory(project).createTypeArguments("<${typeArgument.text}>"), calleeExpression) } } diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/ExpectedResolveDataUtil.java b/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/ExpectedResolveDataUtil.java index 88f0322bf8d..83077a8ed99 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/ExpectedResolveDataUtil.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/ExpectedResolveDataUtil.java @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.incremental.components.NoLookupLocation; import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.KtExpression; +import org.jetbrains.kotlin.psi.KtPsiFactory; import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults; import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfoFactory; @@ -49,7 +50,6 @@ import org.jetbrains.kotlin.types.expressions.FakeCallKind; import java.util.*; -import static org.jetbrains.kotlin.psi.KtPsiFactoryKt.KtPsiFactory; import static org.junit.Assert.assertNotNull; public class ExpectedResolveDataUtil { @@ -156,7 +156,7 @@ public class ExpectedResolveDataUtil { new BindingTraceContext(), lexicalScope, DataFlowInfoFactory.EMPTY, TypeUtils.NO_EXPECTED_TYPE, languageVersionSettings, container.getDataFlowValueFactory()); - KtExpression callElement = KtPsiFactory(project).createExpression(name); + KtExpression callElement = new KtPsiFactory(project).createExpression(name); TemporaryBindingTrace traceWithFakeArgumentInfo = TemporaryBindingTrace.create(context.trace, "trace to store fake argument for", name); diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java index 322b2cba33c..240c3c5aecd 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java @@ -44,7 +44,7 @@ import org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil; import org.jetbrains.kotlin.lexer.KtTokens; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.KtFile; -import org.jetbrains.kotlin.psi.KtPsiFactoryKt; +import org.jetbrains.kotlin.psi.KtPsiFactory; import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil; import org.jetbrains.kotlin.storage.LockBasedStorageManager; import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase; @@ -594,7 +594,7 @@ public class KotlinTestUtils { @NotNull public static KtFile loadJetFile(@NotNull Project project, @NotNull File ioFile) throws IOException { String text = FileUtil.loadFile(ioFile, true); - return KtPsiFactoryKt.KtPsiFactory(project).createPhysicalFile(ioFile.getName(), text); + return new KtPsiFactory(project).createPhysicalFile(ioFile.getName(), text); } @NotNull diff --git a/compiler/tests/org/jetbrains/kotlin/parsing/AbstractParsingTest.java b/compiler/tests/org/jetbrains/kotlin/parsing/AbstractParsingTest.java index 3202ac98e2a..306c26cebda 100644 --- a/compiler/tests/org/jetbrains/kotlin/parsing/AbstractParsingTest.java +++ b/compiler/tests/org/jetbrains/kotlin/parsing/AbstractParsingTest.java @@ -121,7 +121,7 @@ public abstract class AbstractParsingTest extends KtParsingTestCase { } private PsiFile createFile(@NotNull String filePath, @NotNull IElementType fileType, @NotNull String fileContent) { - KtPsiFactory psiFactory = KtPsiFactoryKt.KtPsiFactory(myProject); + KtPsiFactory psiFactory = new KtPsiFactory(myProject); if (fileType == KtNodeTypes.EXPRESSION_CODE_FRAGMENT) { return psiFactory.createExpressionCodeFragment(fileContent, null); diff --git a/compiler/tests/org/jetbrains/kotlin/psi/KtPsiUtilTest.java b/compiler/tests/org/jetbrains/kotlin/psi/KtPsiUtilTest.java index facb9be4042..564470faf75 100644 --- a/compiler/tests/org/jetbrains/kotlin/psi/KtPsiUtilTest.java +++ b/compiler/tests/org/jetbrains/kotlin/psi/KtPsiUtilTest.java @@ -86,7 +86,7 @@ public class KtPsiUtilTest extends KotlinTestWithEnvironment { public void testIsLocalClass() throws IOException { String text = FileUtil.loadFile(new File(KtTestUtil.getTestDataPathBase() + "/psiUtil/isLocalClass.kt"), true); - KtClass aClass = KtPsiFactoryKt.KtPsiFactory(getProject()).createClass(text); + KtClass aClass = new KtPsiFactory(getProject()).createClass(text); @SuppressWarnings("unchecked") Collection classOrObjects = PsiTreeUtil.collectElementsOfType(aClass, KtClassOrObject.class); @@ -123,7 +123,7 @@ public class KtPsiUtilTest extends KotlinTestWithEnvironment { private ImportPath getImportPathFromParsed(String text) { KtImportDirective importDirective = - PsiTreeUtil.findChildOfType(KtPsiFactoryKt.KtPsiFactory(getProject()).createFile(text), KtImportDirective.class); + PsiTreeUtil.findChildOfType(new KtPsiFactory(getProject()).createFile(text), KtImportDirective.class); assertNotNull("At least one import directive is expected", importDirective); diff --git a/compiler/tests/org/jetbrains/kotlin/types/BoundsSubstitutorTest.java b/compiler/tests/org/jetbrains/kotlin/types/BoundsSubstitutorTest.java index 91789ef7b34..62f34dc47dc 100644 --- a/compiler/tests/org/jetbrains/kotlin/types/BoundsSubstitutorTest.java +++ b/compiler/tests/org/jetbrains/kotlin/types/BoundsSubstitutorTest.java @@ -25,7 +25,7 @@ import org.jetbrains.kotlin.incremental.components.NoLookupLocation; import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.KtFile; -import org.jetbrains.kotlin.psi.KtPsiFactoryKt; +import org.jetbrains.kotlin.psi.KtPsiFactory; import org.jetbrains.kotlin.renderer.DescriptorRenderer; import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil; import org.jetbrains.kotlin.test.ConfigurationKind; @@ -70,7 +70,7 @@ public class BoundsSubstitutorTest extends KotlinTestWithEnvironment { //} private void doTest(String text, String expected) { - KtFile ktFile = KtPsiFactoryKt.KtPsiFactory(getProject()).createFile("fun.kt", text); + KtFile ktFile = new KtPsiFactory(getProject()).createFile("fun.kt", text); ModuleDescriptor module = JvmResolveUtil.analyze(ktFile, getEnvironment()).getModuleDescriptor(); Collection functions = module.getPackage(FqName.ROOT).getMemberScope().getContributedFunctions(Name.identifier("f"), NoLookupLocation.FROM_TEST); diff --git a/compiler/tests/org/jetbrains/kotlin/types/DefaultModalityModifiersTest.java b/compiler/tests/org/jetbrains/kotlin/types/DefaultModalityModifiersTest.java index 3fab73cf253..9a5aaf57fee 100644 --- a/compiler/tests/org/jetbrains/kotlin/types/DefaultModalityModifiersTest.java +++ b/compiler/tests/org/jetbrains/kotlin/types/DefaultModalityModifiersTest.java @@ -92,8 +92,7 @@ public class DefaultModalityModifiersTest extends KotlinTestWithEnvironment { @NotNull private LexicalScope createScope(@NotNull MemberScope libraryScope) { - KtFile file = - KtPsiFactoryKt.KtPsiFactory(getProject()).createFile("abstract class C { abstract fun foo(); abstract val a: Int }"); + KtFile file = new KtPsiFactory(getProject()).createFile("abstract class C { abstract fun foo(); abstract val a: Int }"); KtDeclaration aClass = file.getDeclarations().get(0); assert aClass instanceof KtClass; AnalysisResult bindingContext = JvmResolveUtil.analyzeAndCheckForErrors(file, getEnvironment()); @@ -129,7 +128,7 @@ public class DefaultModalityModifiersTest extends KotlinTestWithEnvironment { } private void testClassModality(String classDeclaration, ClassKind kind, Modality expectedModality) { - KtClass aClass = KtPsiFactoryKt.KtPsiFactory(getProject()).createClass(classDeclaration); + KtClass aClass = new KtPsiFactory(getProject()).createClass(classDeclaration); ClassDescriptorWithResolutionScopes classDescriptor = createClassDescriptor(kind, aClass); assertEquals(expectedModality, classDescriptor.getModality()); @@ -137,7 +136,7 @@ public class DefaultModalityModifiersTest extends KotlinTestWithEnvironment { private void testFunctionModality(String classWithFunction, ClassKind kind, Modality expectedFunctionModality) { - KtClass aClass = KtPsiFactoryKt.KtPsiFactory(getProject()).createClass(classWithFunction); + KtClass aClass = new KtPsiFactory(getProject()).createClass(classWithFunction); ClassDescriptorWithResolutionScopes classDescriptor = createClassDescriptor(kind, aClass); List declarations = aClass.getDeclarations(); @@ -150,7 +149,7 @@ public class DefaultModalityModifiersTest extends KotlinTestWithEnvironment { } private void testPropertyModality(String classWithProperty, ClassKind kind, Modality expectedPropertyModality) { - KtClass aClass = KtPsiFactoryKt.KtPsiFactory(getProject()).createClass(classWithProperty); + KtClass aClass = new KtPsiFactory(getProject()).createClass(classWithProperty); ClassDescriptorWithResolutionScopes classDescriptor = createClassDescriptor(kind, aClass); List declarations = aClass.getDeclarations(); @@ -166,7 +165,7 @@ public class DefaultModalityModifiersTest extends KotlinTestWithEnvironment { private void testPropertyAccessorModality(String classWithPropertyWithAccessor, ClassKind kind, Modality expectedPropertyAccessorModality, boolean isGetter) { - KtClass aClass = KtPsiFactoryKt.KtPsiFactory(getProject()).createClass(classWithPropertyWithAccessor); + KtClass aClass = new KtPsiFactory(getProject()).createClass(classWithPropertyWithAccessor); ClassDescriptorWithResolutionScopes classDescriptor = createClassDescriptor(kind, aClass); List declarations = aClass.getDeclarations(); diff --git a/compiler/tests/org/jetbrains/kotlin/types/KotlinOverloadTest.java b/compiler/tests/org/jetbrains/kotlin/types/KotlinOverloadTest.java index 6185df28e47..6d69795670a 100644 --- a/compiler/tests/org/jetbrains/kotlin/types/KotlinOverloadTest.java +++ b/compiler/tests/org/jetbrains/kotlin/types/KotlinOverloadTest.java @@ -22,7 +22,7 @@ import org.jetbrains.kotlin.container.DslKt; import org.jetbrains.kotlin.descriptors.FunctionDescriptor; import org.jetbrains.kotlin.descriptors.ModuleDescriptor; import org.jetbrains.kotlin.psi.KtNamedFunction; -import org.jetbrains.kotlin.psi.KtPsiFactoryKt; +import org.jetbrains.kotlin.psi.KtPsiFactory; import org.jetbrains.kotlin.resolve.FunctionDescriptorResolver; import org.jetbrains.kotlin.resolve.OverloadChecker; import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator; @@ -168,7 +168,7 @@ public class KotlinOverloadTest extends KotlinTestWithEnvironment { } private FunctionDescriptor makeFunction(String funDecl) { - KtNamedFunction function = KtPsiFactoryKt.KtPsiFactory(getProject()).createFunction(funDecl); + KtNamedFunction function = new KtPsiFactory(getProject()).createFunction(funDecl); LexicalScope scope = TypeTestUtilsKt.builtInPackageAsLexicalScope(module); return functionDescriptorResolver.resolveFunctionDescriptor( module, scope, function, DummyTraces.DUMMY_TRACE, DataFlowInfoFactory.EMPTY, null diff --git a/compiler/tests/org/jetbrains/kotlin/types/KotlinOverridingTest.java b/compiler/tests/org/jetbrains/kotlin/types/KotlinOverridingTest.java index f047c239f97..b565c5187fe 100644 --- a/compiler/tests/org/jetbrains/kotlin/types/KotlinOverridingTest.java +++ b/compiler/tests/org/jetbrains/kotlin/types/KotlinOverridingTest.java @@ -22,7 +22,7 @@ import org.jetbrains.kotlin.container.DslKt; import org.jetbrains.kotlin.descriptors.FunctionDescriptor; import org.jetbrains.kotlin.descriptors.ModuleDescriptor; import org.jetbrains.kotlin.psi.KtNamedFunction; -import org.jetbrains.kotlin.psi.KtPsiFactoryKt; +import org.jetbrains.kotlin.psi.KtPsiFactory; import org.jetbrains.kotlin.resolve.FunctionDescriptorResolver; import org.jetbrains.kotlin.resolve.OverridingUtil; import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfoFactory; @@ -169,7 +169,7 @@ public class KotlinOverridingTest extends KotlinTestWithEnvironment { } private FunctionDescriptor makeFunction(String funDecl) { - KtNamedFunction function = KtPsiFactoryKt.KtPsiFactory(getProject()).createFunction(funDecl); + KtNamedFunction function = new KtPsiFactory(getProject()).createFunction(funDecl); LexicalScope scope = TypeTestUtilsKt.builtInPackageAsLexicalScope(module); return functionDescriptorResolver.resolveFunctionDescriptor( module, scope, function, DummyTraces.DUMMY_TRACE, DataFlowInfoFactory.EMPTY, null diff --git a/compiler/tests/org/jetbrains/kotlin/types/KotlinTypeCheckerTest.java b/compiler/tests/org/jetbrains/kotlin/types/KotlinTypeCheckerTest.java index a8483b987f6..247998ddb8c 100644 --- a/compiler/tests/org/jetbrains/kotlin/types/KotlinTypeCheckerTest.java +++ b/compiler/tests/org/jetbrains/kotlin/types/KotlinTypeCheckerTest.java @@ -25,10 +25,7 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentProvider; import org.jetbrains.kotlin.descriptors.annotations.Annotations; import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl; import org.jetbrains.kotlin.descriptors.impl.ReceiverParameterDescriptorImpl; -import org.jetbrains.kotlin.psi.KtExpression; -import org.jetbrains.kotlin.psi.KtFile; -import org.jetbrains.kotlin.psi.KtPsiFactoryKt; -import org.jetbrains.kotlin.psi.KtTypeReference; +import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.resolve.BindingContext; import org.jetbrains.kotlin.resolve.BindingTraceContext; import org.jetbrains.kotlin.resolve.TypeResolver; @@ -532,7 +529,7 @@ public class KotlinTypeCheckerTest extends KotlinTestWithEnvironment { private void assertType(String expression, KotlinType expectedType) { Project project = getProject(); - KtExpression ktExpression = KtPsiFactoryKt.KtPsiFactory(project).createExpression(expression); + KtExpression ktExpression = new KtPsiFactory(project).createExpression(expression); KotlinType type = expressionTypingServices.getType( scopeWithImports, ktExpression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfoFactory.EMPTY, InferenceSession.Companion.getDefault(), @@ -562,7 +559,7 @@ public class KotlinTypeCheckerTest extends KotlinTestWithEnvironment { private void assertType(LexicalScope scope, String expression, String expectedTypeStr) { Project project = getProject(); - KtExpression ktExpression = KtPsiFactoryKt.KtPsiFactory(project).createExpression(expression); + KtExpression ktExpression = new KtPsiFactory(project).createExpression(expression); KotlinType type = expressionTypingServices.getType( scope, ktExpression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfoFactory.EMPTY, InferenceSession.Companion.getDefault(), @@ -585,7 +582,7 @@ public class KotlinTypeCheckerTest extends KotlinTestWithEnvironment { } private KotlinType makeType(LexicalScope scope, String typeStr) { - KtTypeReference typeReference = KtPsiFactoryKt.KtPsiFactory(getProject()).createType(typeStr); + KtTypeReference typeReference = new KtPsiFactory(getProject()).createType(typeStr); return typeResolver.resolveTypeWithPossibleIntersections(scope, typeReference, DummyTraces.DUMMY_TRACE); } } diff --git a/compiler/tests/org/jetbrains/kotlin/types/TypeSubstitutorTest.java b/compiler/tests/org/jetbrains/kotlin/types/TypeSubstitutorTest.java index 810cc2e68db..f4b529bbec9 100644 --- a/compiler/tests/org/jetbrains/kotlin/types/TypeSubstitutorTest.java +++ b/compiler/tests/org/jetbrains/kotlin/types/TypeSubstitutorTest.java @@ -32,7 +32,7 @@ import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages; import org.jetbrains.kotlin.incremental.components.NoLookupLocation; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.KtFile; -import org.jetbrains.kotlin.psi.KtPsiFactoryKt; +import org.jetbrains.kotlin.psi.KtPsiFactory; import org.jetbrains.kotlin.psi.KtTypeReference; import org.jetbrains.kotlin.renderer.DescriptorRenderer; import org.jetbrains.kotlin.resolve.*; @@ -80,7 +80,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment { private LexicalScope getContextScope() throws IOException { // todo comments String text = FileUtil.loadFile(new File("compiler/testData/type-substitutor.kt"), true); - KtFile ktFile = KtPsiFactoryKt.KtPsiFactory(getProject()).createFile(text); + KtFile ktFile = new KtPsiFactory(getProject()).createFile(text); AnalysisResult analysisResult = JvmResolveUtil.analyze(ktFile, getEnvironment()); ModuleDescriptor module = analysisResult.getModuleDescriptor(); @@ -145,7 +145,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment { } private KotlinType resolveType(String typeStr) { - KtTypeReference jetTypeReference = KtPsiFactoryKt.KtPsiFactory(getProject()).createType(typeStr); + KtTypeReference jetTypeReference = new KtPsiFactory(getProject()).createType(typeStr); AnalyzingUtils.checkForSyntacticErrors(jetTypeReference); BindingTrace trace = new BindingTraceContext(); KotlinType type = container.getTypeResolver().resolveType(scope, jetTypeReference, trace, true); diff --git a/compiler/tests/org/jetbrains/kotlin/types/TypeUnifierTest.java b/compiler/tests/org/jetbrains/kotlin/types/TypeUnifierTest.java index 1f0f6bc9f31..1b269d09550 100644 --- a/compiler/tests/org/jetbrains/kotlin/types/TypeUnifierTest.java +++ b/compiler/tests/org/jetbrains/kotlin/types/TypeUnifierTest.java @@ -30,7 +30,7 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor; import org.jetbrains.kotlin.descriptors.annotations.Annotations; import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl; import org.jetbrains.kotlin.name.Name; -import org.jetbrains.kotlin.psi.KtPsiFactoryKt; +import org.jetbrains.kotlin.psi.KtPsiFactory; import org.jetbrains.kotlin.psi.KtTypeProjection; import org.jetbrains.kotlin.psi.KtTypeReference; import org.jetbrains.kotlin.resolve.TypeResolver; @@ -206,8 +206,7 @@ public class TypeUnifierTest extends KotlinTestWithEnvironment { } ); - KtTypeProjection projection = KtPsiFactoryKt - .KtPsiFactory(getProject()).createTypeArguments("<" + typeStr + ">").getArguments().get(0); + KtTypeProjection projection = new KtPsiFactory(getProject()).createTypeArguments("<" + typeStr + ">").getArguments().get(0); KtTypeReference typeReference = projection.getTypeReference(); assert typeReference != null;