[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.
This commit is contained in:
Yan Zhulanow
2022-10-04 02:15:30 +09:00
committed by teamcity
parent f3c4ae8bbf
commit ea3f550b58
37 changed files with 102 additions and 86 deletions
@@ -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)
}
@@ -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
@@ -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) {
@@ -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)
@@ -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);
}
@@ -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);
}
@@ -370,7 +370,7 @@ class DelegatedPropertyResolver(
val hasThis = propertyDescriptor.extensionReceiverParameter != null || propertyDescriptor.dispatchReceiverParameter != null
val arguments = Lists.newArrayList<KtExpression>()
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<FunctionDescriptor> {
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()
@@ -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;
}
@@ -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));
@@ -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? {
@@ -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;
@@ -334,7 +334,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping
}
private fun wrapWhenEntryExpressionsAsSpecialCallArguments(expression: KtWhenExpression): List<KtExpression> {
val psiFactory = KtPsiFactory(expression)
val psiFactory = KtPsiFactory(expression.project)
return expression.entries.mapNotNull { whenEntry ->
whenEntry.expression?.let { psiFactory.wrapInABlockWrapper(it) }
}
@@ -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
}
@@ -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
@@ -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
}
@@ -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
}
@@ -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!!
}
}
@@ -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)
}
}
@@ -39,7 +39,7 @@ class KtImportAlias : KtElementImplStub<KotlinImportAliasStub>, 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
}
@@ -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<KtImportDirective> createImportDirectivesNotCached(@NotNull Collection<ImportPath> importPaths) {
return KtPsiFactoryKt.KtPsiFactory(project, false).createImportDirectives(importPaths);
return new KtPsiFactory(project, false).createImportDirectives(importPaths);
}
}
@@ -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
@@ -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<T extends KotlinStubWithFqName<?>> extends KtDeclarationStub<T> implements KtNamedDeclaration {
public KtNamedDeclarationStub(@NotNull T stub, @NotNull IStubElementType nodeType) {
super(stub, nodeType);
@@ -99,8 +97,7 @@ abstract class KtNamedDeclarationStub<T extends KotlinStubWithFqName<?>> 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);
}
@@ -34,7 +34,7 @@ class KtPrimaryConstructor : KtConstructor<KtPrimaryConstructor> {
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<KtPrimaryConstructor> {
}
} else {
if (modifier == KtTokens.PUBLIC_KEYWORD) return
val newModifierList = KtPsiFactory(this).createModifierList(modifier)
val newModifierList = KtPsiFactory(project).createModifierList(modifier)
addBefore(newModifierList, getOrCreateConstructorKeyword())
}
}
@@ -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(
@@ -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)
}
}
}
@@ -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<Name?, KtCallExpression?> {
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)
}
}
@@ -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);
@@ -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
@@ -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);
@@ -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<KtClassOrObject> 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);
@@ -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<? extends SimpleFunctionDescriptor> functions =
module.getPackage(FqName.ROOT).getMemberScope().getContributedFunctions(Name.identifier("f"), NoLookupLocation.FROM_TEST);
@@ -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<KtDeclaration> 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<KtDeclaration> 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<KtDeclaration> declarations = aClass.getDeclarations();
@@ -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
@@ -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
@@ -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);
}
}
@@ -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);
@@ -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;