[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:
+1
-1
@@ -21,7 +21,7 @@ object TypeParser {
|
|||||||
contextElement: KtElement,
|
contextElement: KtElement,
|
||||||
scopeForTypeParameters: KtElement,
|
scopeForTypeParameters: KtElement,
|
||||||
): KtType {
|
): KtType {
|
||||||
val type = KtPsiFactory(contextElement).createType(stringType)
|
val type = KtPsiFactory(contextElement.project).createType(stringType)
|
||||||
return convertType(type.typeElement ?: incorrectType(type), scopeForTypeParameters)
|
return convertType(type.typeElement ?: incorrectType(type), scopeForTypeParameters)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -146,7 +146,7 @@ abstract class KtLightClassForFacadeBase constructor(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
val psiFactory = KtPsiFactory(this)
|
val psiFactory = KtPsiFactory(project)
|
||||||
val annotationText = "${JVM_NAME_SHORT}(\"$name\")"
|
val annotationText = "${JVM_NAME_SHORT}(\"$name\")"
|
||||||
val newFileAnnotationList = psiFactory.createFileAnnotationListWithAnnotation(annotationText)
|
val newFileAnnotationList = psiFactory.createFileAnnotationListWithAnnotation(annotationText)
|
||||||
val annotationList = file.fileAnnotationList
|
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
|
// Only classes may be mentioned in 'extends' list, thus create super call instead simple type reference
|
||||||
val entryToAdd =
|
val entryToAdd =
|
||||||
if ((reference.parent as? PsiReferenceList)?.role == PsiReferenceList.Role.IMPLEMENTS_LIST && role == PsiReferenceList.Role.EXTENDS_LIST) {
|
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
|
} else entry
|
||||||
// TODO: implement KtSuperListEntry qualification/shortening when inserting reference from another context
|
// TODO: implement KtSuperListEntry qualification/shortening when inserting reference from another context
|
||||||
if (entry.parent != superTypeList) {
|
if (entry.parent != superTypeList) {
|
||||||
|
|||||||
+1
-1
@@ -58,7 +58,7 @@ abstract class KtLightMethodImpl protected constructor(
|
|||||||
|
|
||||||
val nameExpression = jvmNameAnnotation?.let { JvmFileClassUtil.getLiteralStringEntryFromAnnotation(it) }
|
val nameExpression = jvmNameAnnotation?.let { JvmFileClassUtil.getLiteralStringEntryFromAnnotation(it) }
|
||||||
if (nameExpression != null) {
|
if (nameExpression != null) {
|
||||||
nameExpression.replace(KtPsiFactory(this).createLiteralStringTemplateEntry(name))
|
nameExpression.replace(KtPsiFactory(project).createLiteralStringTemplateEntry(name))
|
||||||
} else {
|
} else {
|
||||||
val toRename = kotlinOrigin as? PsiNamedElement ?: cannotModify()
|
val toRename = kotlinOrigin as? PsiNamedElement ?: cannotModify()
|
||||||
toRename.setName(newNameForOrigin)
|
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) {
|
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);
|
return CallMaker.makeCall(fake, initializerAsReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -233,7 +233,7 @@ public class FunctionReferenceGenerationStrategy extends FunctionGenerationStrat
|
|||||||
) {
|
) {
|
||||||
if (receiver == null) return null;
|
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));
|
codegen.tempVariables.put(receiverExpression, receiverParameterStackValue(signature, codegen));
|
||||||
return ExpressionReceiver.Companion.create(receiverExpression, receiver.getType(), BindingContext.EMPTY);
|
return ExpressionReceiver.Companion.create(receiverExpression, receiver.getType(), BindingContext.EMPTY);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -370,7 +370,7 @@ class DelegatedPropertyResolver(
|
|||||||
val hasThis = propertyDescriptor.extensionReceiverParameter != null || propertyDescriptor.dispatchReceiverParameter != null
|
val hasThis = propertyDescriptor.extensionReceiverParameter != null || propertyDescriptor.dispatchReceiverParameter != null
|
||||||
|
|
||||||
val arguments = Lists.newArrayList<KtExpression>()
|
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.createExpression(if (hasThis) "this" else "null"))
|
||||||
arguments.add(psiFactory.createExpressionForProperty())
|
arguments.add(psiFactory.createExpressionForProperty())
|
||||||
|
|
||||||
@@ -458,7 +458,7 @@ class DelegatedPropertyResolver(
|
|||||||
context: ExpressionTypingContext
|
context: ExpressionTypingContext
|
||||||
): OverloadResolutionResults<FunctionDescriptor> {
|
): OverloadResolutionResults<FunctionDescriptor> {
|
||||||
val propertyHasReceiver = propertyDescriptor.dispatchReceiverParameter != null
|
val propertyHasReceiver = propertyDescriptor.dispatchReceiverParameter != null
|
||||||
val arguments = KtPsiFactory(delegateExpression, markGenerated = false).run {
|
val arguments = KtPsiFactory(delegateExpression.project, markGenerated = false).run {
|
||||||
listOf(
|
listOf(
|
||||||
createExpression(if (propertyHasReceiver) "this" else "null"),
|
createExpression(if (propertyHasReceiver) "this" else "null"),
|
||||||
createExpressionForProperty()
|
createExpressionForProperty()
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ public class CallTransformer {
|
|||||||
this.explicitExtensionReceiver = explicitExtensionReceiver;
|
this.explicitExtensionReceiver = explicitExtensionReceiver;
|
||||||
this.calleeExpressionAsDispatchReceiver = calleeExpressionAsDispatchReceiver;
|
this.calleeExpressionAsDispatchReceiver = calleeExpressionAsDispatchReceiver;
|
||||||
this.fakeInvokeExpression =
|
this.fakeInvokeExpression =
|
||||||
(KtSimpleNameExpression) KtPsiFactoryKt.KtPsiFactory(call.getCallElement(), false)
|
(KtSimpleNameExpression) new KtPsiFactory(call.getCallElement().getProject(), false)
|
||||||
.createExpression(OperatorNameConventions.INVOKE.asString());
|
.createExpression(OperatorNameConventions.INVOKE.asString());
|
||||||
itIsVariableAsFunctionCall = functionCall;
|
itIsVariableAsFunctionCall = functionCall;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -107,7 +107,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
return getTypeInfoWhenOnlyOneBranchIsPresent(
|
return getTypeInfoWhenOnlyOneBranchIsPresent(
|
||||||
elseBranch, elseScope, elseInfo, thenInfo, context, ifExpression);
|
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 thenBlock = psiFactory.wrapInABlockWrapper(thenBranch);
|
||||||
KtBlockExpression elseBlock = psiFactory.wrapInABlockWrapper(elseBranch);
|
KtBlockExpression elseBlock = psiFactory.wrapInABlockWrapper(elseBranch);
|
||||||
Call callForIf = createCallForSpecialConstruction(ifExpression, ifExpression, Lists.newArrayList(thenBlock, elseBlock));
|
Call callForIf = createCallForSpecialConstruction(ifExpression, ifExpression, Lists.newArrayList(thenBlock, elseBlock));
|
||||||
|
|||||||
+1
-1
@@ -271,7 +271,7 @@ class DoubleColonExpressionResolver(
|
|||||||
private fun KtQualifiedExpression.buildNewExpressionForReservedGenericPropertyCallChainResolution(): KtExpression? {
|
private fun KtQualifiedExpression.buildNewExpressionForReservedGenericPropertyCallChainResolution(): KtExpression? {
|
||||||
val parts = this.getQualifierChainParts()?.map { it.getQualifiedNameStringPart() ?: return null } ?: return null
|
val parts = this.getQualifierChainParts()?.map { it.getQualifiedNameStringPart() ?: return null } ?: return null
|
||||||
val qualifiedExpressionText = parts.joinToString(separator = ".")
|
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? {
|
private fun resolveReservedExpressionOnLHS(expression: KtExpression, c: ExpressionTypingContext): DoubleColonLHS.Expression? {
|
||||||
|
|||||||
+1
-1
@@ -93,7 +93,7 @@ public class ExpressionTypingUtils {
|
|||||||
@NotNull String argumentName,
|
@NotNull String argumentName,
|
||||||
@NotNull KotlinType argumentType
|
@NotNull KotlinType argumentType
|
||||||
) {
|
) {
|
||||||
KtExpression fakeExpression = KtPsiFactoryKt.KtPsiFactory(project, false).createExpression(argumentName);
|
KtExpression fakeExpression = new KtPsiFactory(project, false).createExpression(argumentName);
|
||||||
trace.recordType(fakeExpression, argumentType);
|
trace.recordType(fakeExpression, argumentType);
|
||||||
trace.record(PROCESSED, fakeExpression);
|
trace.record(PROCESSED, fakeExpression);
|
||||||
return fakeExpression;
|
return fakeExpression;
|
||||||
|
|||||||
+1
-1
@@ -334,7 +334,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun wrapWhenEntryExpressionsAsSpecialCallArguments(expression: KtWhenExpression): List<KtExpression> {
|
private fun wrapWhenEntryExpressionsAsSpecialCallArguments(expression: KtWhenExpression): List<KtExpression> {
|
||||||
val psiFactory = KtPsiFactory(expression)
|
val psiFactory = KtPsiFactory(expression.project)
|
||||||
return expression.entries.mapNotNull { whenEntry ->
|
return expression.entries.mapNotNull { whenEntry ->
|
||||||
whenEntry.expression?.let { psiFactory.wrapInABlockWrapper(it) }
|
whenEntry.expression?.let { psiFactory.wrapInABlockWrapper(it) }
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@ open class KtLightPsiLiteral(
|
|||||||
|
|
||||||
override fun replace(newElement: PsiElement): PsiElement {
|
override fun replace(newElement: PsiElement): PsiElement {
|
||||||
val value = (newElement as? PsiLiteral)?.value as? String ?: return this
|
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
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ object EditCommaSeparatedListHelper {
|
|||||||
list.add(item) as TItem
|
list.add(item) as TItem
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var comma = KtPsiFactory(list).createComma()
|
var comma = KtPsiFactory(list.project).createComma()
|
||||||
return if (anchor != null) {
|
return if (anchor != null) {
|
||||||
comma = list.addAfter(comma, anchor)
|
comma = list.addAfter(comma, anchor)
|
||||||
list.addAfter(item, comma) as TItem
|
list.addAfter(item, comma) as TItem
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ abstract class KtClassOrObject :
|
|||||||
return EditCommaSeparatedListHelper.addItem(it, superTypeListEntries, superTypeListEntry)
|
return EditCommaSeparatedListHelper.addItem(it, superTypeListEntries, superTypeListEntry)
|
||||||
}
|
}
|
||||||
|
|
||||||
val psiFactory = KtPsiFactory(this)
|
val psiFactory = KtPsiFactory(project)
|
||||||
val specifierListToAdd = psiFactory.createSuperTypeCallEntry("A()").replace(superTypeListEntry).parent
|
val specifierListToAdd = psiFactory.createSuperTypeCallEntry("A()").replace(superTypeListEntry).parent
|
||||||
val colon = addBefore(psiFactory.createColon(), getBody())
|
val colon = addBefore(psiFactory.createColon(), getBody())
|
||||||
return (addAfter(specifierListToAdd, colon) as KtSuperTypeList).entries.first()
|
return (addAfter(specifierListToAdd, colon) as KtSuperTypeList).entries.first()
|
||||||
@@ -202,7 +202,7 @@ abstract class KtClassOrObject :
|
|||||||
fun KtClassOrObject.getOrCreateBody(): KtClassBody {
|
fun KtClassOrObject.getOrCreateBody(): KtClassBody {
|
||||||
getBody()?.let { return it }
|
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
|
if (this is KtEnumEntry) return addAfter(newBody, initializerList ?: nameIdentifier) as KtClassBody
|
||||||
return add(newBody) as KtClassBody
|
return add(newBody) as KtClassBody
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ abstract class KtCodeFragment(
|
|||||||
|
|
||||||
fun importsAsImportList(): KtImportList? {
|
fun importsAsImportList(): KtImportList? {
|
||||||
if (imports.isNotEmpty() && context != null) {
|
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
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,15 +35,14 @@ abstract class KtExpressionImpl(node: ASTNode) : KtElementImpl(node), KtExpressi
|
|||||||
when (parent) {
|
when (parent) {
|
||||||
is KtExpression, is KtValueArgument -> {
|
is KtExpression, is KtValueArgument -> {
|
||||||
if (KtPsiUtil.areParenthesesNecessary(newElement, expression, parent as KtElement)) {
|
if (KtPsiUtil.areParenthesesNecessary(newElement, expression, parent as KtElement)) {
|
||||||
return rawReplaceHandler(
|
val factory = KtPsiFactory(expression.project)
|
||||||
KtPsiFactory(expression).createExpressionByPattern("($0)", newElement, reformat = reformat)
|
return rawReplaceHandler(factory.createExpressionByPattern("($0)", newElement, reformat = reformat))
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is KtSimpleNameStringTemplateEntry -> {
|
is KtSimpleNameStringTemplateEntry -> {
|
||||||
if (newElement !is KtSimpleNameExpression && !newElement.isThisWithoutLabel()) {
|
if (newElement !is KtSimpleNameExpression && !newElement.isThisWithoutLabel()) {
|
||||||
val newEntry =
|
val factory = KtPsiFactory(expression.project)
|
||||||
parent.replace(KtPsiFactory(expression).createBlockStringTemplateEntry(newElement)) as KtBlockStringTemplateEntry
|
val newEntry = parent.replace(factory.createBlockStringTemplateEntry(newElement)) as KtBlockStringTemplateEntry
|
||||||
return newEntry.expression!!
|
return newEntry.expression!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ open class KtFile(viewProvider: FileViewProvider, val isCompiled: Boolean) :
|
|||||||
if (packageDirective != null) {
|
if (packageDirective != null) {
|
||||||
packageDirective.fqName = value
|
packageDirective.fqName = value
|
||||||
} else {
|
} else {
|
||||||
val newPackageDirective = KtPsiFactory(this).createPackageDirectiveIfNeeded(value) ?: return
|
val newPackageDirective = KtPsiFactory(project).createPackageDirectiveIfNeeded(value) ?: return
|
||||||
addAfter(newPackageDirective, null)
|
addAfter(newPackageDirective, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class KtImportAlias : KtElementImplStub<KotlinImportAliasStub>, PsiNameIdentifie
|
|||||||
override fun getName() = stub?.getName() ?: nameIdentifier?.text
|
override fun getName() = stub?.getName() ?: nameIdentifier?.text
|
||||||
|
|
||||||
override fun setName(name: String): PsiElement {
|
override fun setName(name: String): PsiElement {
|
||||||
nameIdentifier?.replace(KtPsiFactory(this).createNameIdentifier(name))
|
nameIdentifier?.replace(KtPsiFactory(project).createNameIdentifier(name))
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class KtImportsFactory {
|
|||||||
return directive;
|
return directive;
|
||||||
}
|
}
|
||||||
|
|
||||||
KtImportDirective createdDirective = KtPsiFactoryKt.KtPsiFactory(project, false).createImportDirective(importPath);
|
KtImportDirective createdDirective = new KtPsiFactory(project, false).createImportDirective(importPath);
|
||||||
importsCache.put(importPath, createdDirective);
|
importsCache.put(importPath, createdDirective);
|
||||||
|
|
||||||
return createdDirective;
|
return createdDirective;
|
||||||
@@ -58,6 +58,6 @@ public class KtImportsFactory {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Collection<KtImportDirective> createImportDirectivesNotCached(@NotNull Collection<ImportPath> importPaths) {
|
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.name.Name;
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.psi.KtPsiFactoryKt.KtPsiFactory;
|
|
||||||
|
|
||||||
// TODO: Remove when all named declarations get stubs
|
// TODO: Remove when all named declarations get stubs
|
||||||
@Deprecated
|
@Deprecated
|
||||||
abstract class KtNamedDeclarationNotStubbed extends KtDeclarationImpl implements KtNamedDeclaration {
|
abstract class KtNamedDeclarationNotStubbed extends KtDeclarationImpl implements KtNamedDeclaration {
|
||||||
@@ -67,7 +65,7 @@ abstract class KtNamedDeclarationNotStubbed extends KtDeclarationImpl implements
|
|||||||
PsiElement identifier = getNameIdentifier();
|
PsiElement identifier = getNameIdentifier();
|
||||||
if (identifier == null) throw new IncorrectOperationException();
|
if (identifier == null) throw new IncorrectOperationException();
|
||||||
|
|
||||||
return identifier.replace(KtPsiFactory(this).createNameIdentifier(name));
|
return identifier.replace(new KtPsiFactory(getProject()).createNameIdentifier(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -32,8 +32,6 @@ import org.jetbrains.kotlin.util.OperatorNameConventions;
|
|||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.psi.KtPsiFactoryKt.KtPsiFactory;
|
|
||||||
|
|
||||||
abstract class KtNamedDeclarationStub<T extends KotlinStubWithFqName<?>> extends KtDeclarationStub<T> implements KtNamedDeclaration {
|
abstract class KtNamedDeclarationStub<T extends KotlinStubWithFqName<?>> extends KtDeclarationStub<T> implements KtNamedDeclaration {
|
||||||
public KtNamedDeclarationStub(@NotNull T stub, @NotNull IStubElementType nodeType) {
|
public KtNamedDeclarationStub(@NotNull T stub, @NotNull IStubElementType nodeType) {
|
||||||
super(stub, nodeType);
|
super(stub, nodeType);
|
||||||
@@ -99,8 +97,7 @@ abstract class KtNamedDeclarationStub<T extends KotlinStubWithFqName<?>> extends
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PsiElement newIdentifier =
|
PsiElement newIdentifier = new KtPsiFactory(getProject()).createNameIdentifierIfPossible(KtPsiUtilKt.quoteIfNeeded(name));
|
||||||
KtPsiFactory(this).createNameIdentifierIfPossible(KtPsiUtilKt.quoteIfNeeded(name));
|
|
||||||
if (newIdentifier != null) {
|
if (newIdentifier != null) {
|
||||||
KtPsiUtilKt.astReplace(identifier, newIdentifier);
|
KtPsiUtilKt.astReplace(identifier, newIdentifier);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class KtPrimaryConstructor : KtConstructor<KtPrimaryConstructor> {
|
|||||||
override fun getContainingClassOrObject() = parent as KtClassOrObject
|
override fun getContainingClassOrObject() = parent as KtClassOrObject
|
||||||
|
|
||||||
private fun getOrCreateConstructorKeyword(): PsiElement {
|
private fun getOrCreateConstructorKeyword(): PsiElement {
|
||||||
return getConstructorKeyword() ?: addBefore(KtPsiFactory(this).createConstructorKeyword(), valueParameterList!!)
|
return getConstructorKeyword() ?: addBefore(KtPsiFactory(project).createConstructorKeyword(), valueParameterList!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeRedundantConstructorKeywordAndSpace() {
|
fun removeRedundantConstructorKeywordAndSpace() {
|
||||||
@@ -53,7 +53,7 @@ class KtPrimaryConstructor : KtConstructor<KtPrimaryConstructor> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (modifier == KtTokens.PUBLIC_KEYWORD) return
|
if (modifier == KtTokens.PUBLIC_KEYWORD) return
|
||||||
val newModifierList = KtPsiFactory(this).createModifierList(modifier)
|
val newModifierList = KtPsiFactory(project).createModifierList(modifier)
|
||||||
addBefore(newModifierList, getOrCreateConstructorKeyword())
|
addBefore(newModifierList, getOrCreateConstructorKeyword())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,14 +21,19 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.isIdentifier
|
import org.jetbrains.kotlin.psi.psiUtil.isIdentifier
|
||||||
import org.jetbrains.kotlin.resolve.ImportPath
|
import org.jetbrains.kotlin.resolve.ImportPath
|
||||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
|
||||||
import org.jetbrains.kotlin.utils.checkWithAttachment
|
import org.jetbrains.kotlin.utils.checkWithAttachment
|
||||||
|
|
||||||
@JvmOverloads
|
@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
|
@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)
|
KtPsiFactory(elementForProject.project, markGenerated)
|
||||||
|
|
||||||
private const val DO_NOT_ANALYZE_NOTIFICATION = "This file was created by KtPsiFactory and should not be analyzed\n" +
|
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`
|
* 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.
|
* 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 {
|
fun createValKeyword(): PsiElement {
|
||||||
val property = createProperty("val x = 1")
|
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 {
|
fun createFile(@NonNls fileName: String, @NonNls text: String): KtFile {
|
||||||
val file = doCreateFile(fileName, text)
|
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
|
return file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Call 'createFile()' on a contextual 'KtPsiFactory' instead")
|
||||||
fun createAnalyzableFile(@NonNls fileName: String, @NonNls text: String, contextToAnalyzeIn: PsiElement): KtFile {
|
fun createAnalyzableFile(@NonNls fileName: String, @NonNls text: String, contextToAnalyzeIn: PsiElement): KtFile {
|
||||||
val file = doCreateFile(fileName, text)
|
val file = doCreateFile(fileName, text)
|
||||||
file.analysisContext = contextToAnalyzeIn
|
file.analysisContext = contextToAnalyzeIn
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Call 'createPhysicalFile() on a contextual 'KtPsiFactory' instead")
|
||||||
fun createFileWithLightClassSupport(@NonNls fileName: String, @NonNls text: String, contextToAnalyzeIn: PsiElement): KtFile {
|
fun createFileWithLightClassSupport(@NonNls fileName: String, @NonNls text: String, contextToAnalyzeIn: PsiElement): KtFile {
|
||||||
val file = createPhysicalFile(fileName, text)
|
val file = createPhysicalFile(fileName, text)
|
||||||
file.analysisContext = contextToAnalyzeIn
|
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 {
|
fun createPhysicalFile(@NonNls fileName: String, @NonNls text: String): KtFile {
|
||||||
return PsiFileFactory.getInstance(project).createFileFromText(
|
val time = LocalTimeCounter.currentTime()
|
||||||
fileName,
|
val file = PsiFileFactory.getInstance(project).createFileFromText(fileName, KotlinFileType.INSTANCE, text, time, true) as KtFile
|
||||||
KotlinFileType.INSTANCE,
|
file.analysisContext = this@KtPsiFactory.context
|
||||||
text,
|
return file
|
||||||
LocalTimeCounter.currentTime(),
|
|
||||||
true
|
|
||||||
) as KtFile
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createProperty(
|
fun createProperty(
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ private fun KtModifierListOwner.addModifierList(newModifierList: KtModifierList)
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createModifierList(text: String, owner: KtModifierListOwner): 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) {
|
fun KtModifierListOwner.setModifierList(newModifierList: KtModifierList) {
|
||||||
@@ -55,7 +55,7 @@ fun addAnnotationEntry(owner: KtModifierListOwner, annotationEntry: KtAnnotation
|
|||||||
internal fun addModifier(modifierList: KtModifierList, modifier: KtModifierKeywordToken) {
|
internal fun addModifier(modifierList: KtModifierList, modifier: KtModifierKeywordToken) {
|
||||||
if (modifierList.hasModifier(modifier)) return
|
if (modifierList.hasModifier(modifier)) return
|
||||||
|
|
||||||
val newModifier = KtPsiFactory(modifierList).createModifier(modifier)
|
val newModifier = KtPsiFactory(modifierList.project).createModifier(modifier)
|
||||||
val modifierToReplace = MODIFIERS_TO_REPLACE[modifier]
|
val modifierToReplace = MODIFIERS_TO_REPLACE[modifier]
|
||||||
?.mapNotNull { modifierList.getModifier(it) }
|
?.mapNotNull { modifierList.getModifier(it) }
|
||||||
?.firstOrNull()
|
?.firstOrNull()
|
||||||
@@ -113,7 +113,7 @@ fun removeModifier(owner: KtModifierListOwner, modifier: KtModifierKeywordToken)
|
|||||||
|
|
||||||
val lastChild = it.lastChild
|
val lastChild = it.lastChild
|
||||||
if (lastChild is PsiComment) {
|
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 {
|
fun KtFunctionLiteral.getOrCreateParameterList(): KtParameterList {
|
||||||
valueParameterList?.let { return it }
|
valueParameterList?.let { return it }
|
||||||
|
|
||||||
val psiFactory = KtPsiFactory(this)
|
val psiFactory = KtPsiFactory(project)
|
||||||
|
|
||||||
val anchor = lBrace
|
val anchor = lBrace
|
||||||
val newParameterList = addAfter(psiFactory.createLambdaParameterList("x"), anchor) as KtParameterList
|
val newParameterList = addAfter(psiFactory.createLambdaParameterList("x"), anchor) as KtParameterList
|
||||||
@@ -589,7 +589,7 @@ fun KtFunctionLiteral.findLabelAndCall(): Pair<Name?, KtCallExpression?> {
|
|||||||
fun KtCallExpression.getOrCreateValueArgumentList(): KtValueArgumentList {
|
fun KtCallExpression.getOrCreateValueArgumentList(): KtValueArgumentList {
|
||||||
valueArgumentList?.let { return it }
|
valueArgumentList?.let { return it }
|
||||||
return addAfter(
|
return addAfter(
|
||||||
KtPsiFactory(this).createCallArguments("()"),
|
KtPsiFactory(project).createCallArguments("()"),
|
||||||
typeArgumentList ?: calleeExpression,
|
typeArgumentList ?: calleeExpression,
|
||||||
) as KtValueArgumentList
|
) as KtValueArgumentList
|
||||||
}
|
}
|
||||||
@@ -598,7 +598,7 @@ fun KtCallExpression.addTypeArgument(typeArgument: KtTypeProjection) {
|
|||||||
if (typeArgumentList != null) {
|
if (typeArgumentList != null) {
|
||||||
typeArgumentList?.addArgument(typeArgument)
|
typeArgumentList?.addArgument(typeArgument)
|
||||||
} else {
|
} else {
|
||||||
addAfter(KtPsiFactory(this).createTypeArguments("<${typeArgument.text}>"), calleeExpression)
|
addAfter(KtPsiFactory(project).createTypeArguments("<${typeArgument.text}>"), calleeExpression)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
|
|||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.psi.KtExpression;
|
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.model.ResolvedCall;
|
||||||
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults;
|
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults;
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfoFactory;
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfoFactory;
|
||||||
@@ -49,7 +50,6 @@ import org.jetbrains.kotlin.types.expressions.FakeCallKind;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.psi.KtPsiFactoryKt.KtPsiFactory;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
public class ExpectedResolveDataUtil {
|
public class ExpectedResolveDataUtil {
|
||||||
@@ -156,7 +156,7 @@ public class ExpectedResolveDataUtil {
|
|||||||
new BindingTraceContext(), lexicalScope,
|
new BindingTraceContext(), lexicalScope,
|
||||||
DataFlowInfoFactory.EMPTY, TypeUtils.NO_EXPECTED_TYPE, languageVersionSettings, container.getDataFlowValueFactory());
|
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 traceWithFakeArgumentInfo =
|
||||||
TemporaryBindingTrace.create(context.trace, "trace to store fake argument for", name);
|
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.lexer.KtTokens;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.psi.KtFile;
|
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.resolve.lazy.JvmResolveUtil;
|
||||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||||
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase;
|
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase;
|
||||||
@@ -594,7 +594,7 @@ public class KotlinTestUtils {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public static KtFile loadJetFile(@NotNull Project project, @NotNull File ioFile) throws IOException {
|
public static KtFile loadJetFile(@NotNull Project project, @NotNull File ioFile) throws IOException {
|
||||||
String text = FileUtil.loadFile(ioFile, true);
|
String text = FileUtil.loadFile(ioFile, true);
|
||||||
return KtPsiFactoryKt.KtPsiFactory(project).createPhysicalFile(ioFile.getName(), text);
|
return new KtPsiFactory(project).createPhysicalFile(ioFile.getName(), text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ public abstract class AbstractParsingTest extends KtParsingTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private PsiFile createFile(@NotNull String filePath, @NotNull IElementType fileType, @NotNull String fileContent) {
|
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) {
|
if (fileType == KtNodeTypes.EXPRESSION_CODE_FRAGMENT) {
|
||||||
return psiFactory.createExpressionCodeFragment(fileContent, null);
|
return psiFactory.createExpressionCodeFragment(fileContent, null);
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class KtPsiUtilTest extends KotlinTestWithEnvironment {
|
|||||||
|
|
||||||
public void testIsLocalClass() throws IOException {
|
public void testIsLocalClass() throws IOException {
|
||||||
String text = FileUtil.loadFile(new File(KtTestUtil.getTestDataPathBase() + "/psiUtil/isLocalClass.kt"), true);
|
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")
|
@SuppressWarnings("unchecked")
|
||||||
Collection<KtClassOrObject> classOrObjects = PsiTreeUtil.collectElementsOfType(aClass, KtClassOrObject.class);
|
Collection<KtClassOrObject> classOrObjects = PsiTreeUtil.collectElementsOfType(aClass, KtClassOrObject.class);
|
||||||
@@ -123,7 +123,7 @@ public class KtPsiUtilTest extends KotlinTestWithEnvironment {
|
|||||||
|
|
||||||
private ImportPath getImportPathFromParsed(String text) {
|
private ImportPath getImportPathFromParsed(String text) {
|
||||||
KtImportDirective importDirective =
|
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);
|
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.FqName;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.psi.KtFile;
|
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.renderer.DescriptorRenderer;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||||
@@ -70,7 +70,7 @@ public class BoundsSubstitutorTest extends KotlinTestWithEnvironment {
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
private void doTest(String text, String expected) {
|
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();
|
ModuleDescriptor module = JvmResolveUtil.analyze(ktFile, getEnvironment()).getModuleDescriptor();
|
||||||
Collection<? extends SimpleFunctionDescriptor> functions =
|
Collection<? extends SimpleFunctionDescriptor> functions =
|
||||||
module.getPackage(FqName.ROOT).getMemberScope().getContributedFunctions(Name.identifier("f"), NoLookupLocation.FROM_TEST);
|
module.getPackage(FqName.ROOT).getMemberScope().getContributedFunctions(Name.identifier("f"), NoLookupLocation.FROM_TEST);
|
||||||
|
|||||||
@@ -92,8 +92,7 @@ public class DefaultModalityModifiersTest extends KotlinTestWithEnvironment {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private LexicalScope createScope(@NotNull MemberScope libraryScope) {
|
private LexicalScope createScope(@NotNull MemberScope libraryScope) {
|
||||||
KtFile file =
|
KtFile file = new KtPsiFactory(getProject()).createFile("abstract class C { abstract fun foo(); abstract val a: Int }");
|
||||||
KtPsiFactoryKt.KtPsiFactory(getProject()).createFile("abstract class C { abstract fun foo(); abstract val a: Int }");
|
|
||||||
KtDeclaration aClass = file.getDeclarations().get(0);
|
KtDeclaration aClass = file.getDeclarations().get(0);
|
||||||
assert aClass instanceof KtClass;
|
assert aClass instanceof KtClass;
|
||||||
AnalysisResult bindingContext = JvmResolveUtil.analyzeAndCheckForErrors(file, getEnvironment());
|
AnalysisResult bindingContext = JvmResolveUtil.analyzeAndCheckForErrors(file, getEnvironment());
|
||||||
@@ -129,7 +128,7 @@ public class DefaultModalityModifiersTest extends KotlinTestWithEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void testClassModality(String classDeclaration, ClassKind kind, Modality expectedModality) {
|
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);
|
ClassDescriptorWithResolutionScopes classDescriptor = createClassDescriptor(kind, aClass);
|
||||||
|
|
||||||
assertEquals(expectedModality, classDescriptor.getModality());
|
assertEquals(expectedModality, classDescriptor.getModality());
|
||||||
@@ -137,7 +136,7 @@ public class DefaultModalityModifiersTest extends KotlinTestWithEnvironment {
|
|||||||
|
|
||||||
|
|
||||||
private void testFunctionModality(String classWithFunction, ClassKind kind, Modality expectedFunctionModality) {
|
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);
|
ClassDescriptorWithResolutionScopes classDescriptor = createClassDescriptor(kind, aClass);
|
||||||
|
|
||||||
List<KtDeclaration> declarations = aClass.getDeclarations();
|
List<KtDeclaration> declarations = aClass.getDeclarations();
|
||||||
@@ -150,7 +149,7 @@ public class DefaultModalityModifiersTest extends KotlinTestWithEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void testPropertyModality(String classWithProperty, ClassKind kind, Modality expectedPropertyModality) {
|
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);
|
ClassDescriptorWithResolutionScopes classDescriptor = createClassDescriptor(kind, aClass);
|
||||||
|
|
||||||
List<KtDeclaration> declarations = aClass.getDeclarations();
|
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) {
|
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);
|
ClassDescriptorWithResolutionScopes classDescriptor = createClassDescriptor(kind, aClass);
|
||||||
|
|
||||||
List<KtDeclaration> declarations = aClass.getDeclarations();
|
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.FunctionDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
||||||
import org.jetbrains.kotlin.psi.KtNamedFunction;
|
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.FunctionDescriptorResolver;
|
||||||
import org.jetbrains.kotlin.resolve.OverloadChecker;
|
import org.jetbrains.kotlin.resolve.OverloadChecker;
|
||||||
import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator;
|
import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator;
|
||||||
@@ -168,7 +168,7 @@ public class KotlinOverloadTest extends KotlinTestWithEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private FunctionDescriptor makeFunction(String funDecl) {
|
private FunctionDescriptor makeFunction(String funDecl) {
|
||||||
KtNamedFunction function = KtPsiFactoryKt.KtPsiFactory(getProject()).createFunction(funDecl);
|
KtNamedFunction function = new KtPsiFactory(getProject()).createFunction(funDecl);
|
||||||
LexicalScope scope = TypeTestUtilsKt.builtInPackageAsLexicalScope(module);
|
LexicalScope scope = TypeTestUtilsKt.builtInPackageAsLexicalScope(module);
|
||||||
return functionDescriptorResolver.resolveFunctionDescriptor(
|
return functionDescriptorResolver.resolveFunctionDescriptor(
|
||||||
module, scope, function, DummyTraces.DUMMY_TRACE, DataFlowInfoFactory.EMPTY, null
|
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.FunctionDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
||||||
import org.jetbrains.kotlin.psi.KtNamedFunction;
|
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.FunctionDescriptorResolver;
|
||||||
import org.jetbrains.kotlin.resolve.OverridingUtil;
|
import org.jetbrains.kotlin.resolve.OverridingUtil;
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfoFactory;
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfoFactory;
|
||||||
@@ -169,7 +169,7 @@ public class KotlinOverridingTest extends KotlinTestWithEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private FunctionDescriptor makeFunction(String funDecl) {
|
private FunctionDescriptor makeFunction(String funDecl) {
|
||||||
KtNamedFunction function = KtPsiFactoryKt.KtPsiFactory(getProject()).createFunction(funDecl);
|
KtNamedFunction function = new KtPsiFactory(getProject()).createFunction(funDecl);
|
||||||
LexicalScope scope = TypeTestUtilsKt.builtInPackageAsLexicalScope(module);
|
LexicalScope scope = TypeTestUtilsKt.builtInPackageAsLexicalScope(module);
|
||||||
return functionDescriptorResolver.resolveFunctionDescriptor(
|
return functionDescriptorResolver.resolveFunctionDescriptor(
|
||||||
module, scope, function, DummyTraces.DUMMY_TRACE, DataFlowInfoFactory.EMPTY, null
|
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.annotations.Annotations;
|
||||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl;
|
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl;
|
||||||
import org.jetbrains.kotlin.descriptors.impl.ReceiverParameterDescriptorImpl;
|
import org.jetbrains.kotlin.descriptors.impl.ReceiverParameterDescriptorImpl;
|
||||||
import org.jetbrains.kotlin.psi.KtExpression;
|
import org.jetbrains.kotlin.psi.*;
|
||||||
import org.jetbrains.kotlin.psi.KtFile;
|
|
||||||
import org.jetbrains.kotlin.psi.KtPsiFactoryKt;
|
|
||||||
import org.jetbrains.kotlin.psi.KtTypeReference;
|
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||||
import org.jetbrains.kotlin.resolve.BindingTraceContext;
|
import org.jetbrains.kotlin.resolve.BindingTraceContext;
|
||||||
import org.jetbrains.kotlin.resolve.TypeResolver;
|
import org.jetbrains.kotlin.resolve.TypeResolver;
|
||||||
@@ -532,7 +529,7 @@ public class KotlinTypeCheckerTest extends KotlinTestWithEnvironment {
|
|||||||
|
|
||||||
private void assertType(String expression, KotlinType expectedType) {
|
private void assertType(String expression, KotlinType expectedType) {
|
||||||
Project project = getProject();
|
Project project = getProject();
|
||||||
KtExpression ktExpression = KtPsiFactoryKt.KtPsiFactory(project).createExpression(expression);
|
KtExpression ktExpression = new KtPsiFactory(project).createExpression(expression);
|
||||||
KotlinType type = expressionTypingServices.getType(
|
KotlinType type = expressionTypingServices.getType(
|
||||||
scopeWithImports, ktExpression, TypeUtils.NO_EXPECTED_TYPE,
|
scopeWithImports, ktExpression, TypeUtils.NO_EXPECTED_TYPE,
|
||||||
DataFlowInfoFactory.EMPTY, InferenceSession.Companion.getDefault(),
|
DataFlowInfoFactory.EMPTY, InferenceSession.Companion.getDefault(),
|
||||||
@@ -562,7 +559,7 @@ public class KotlinTypeCheckerTest extends KotlinTestWithEnvironment {
|
|||||||
|
|
||||||
private void assertType(LexicalScope scope, String expression, String expectedTypeStr) {
|
private void assertType(LexicalScope scope, String expression, String expectedTypeStr) {
|
||||||
Project project = getProject();
|
Project project = getProject();
|
||||||
KtExpression ktExpression = KtPsiFactoryKt.KtPsiFactory(project).createExpression(expression);
|
KtExpression ktExpression = new KtPsiFactory(project).createExpression(expression);
|
||||||
KotlinType type = expressionTypingServices.getType(
|
KotlinType type = expressionTypingServices.getType(
|
||||||
scope, ktExpression, TypeUtils.NO_EXPECTED_TYPE,
|
scope, ktExpression, TypeUtils.NO_EXPECTED_TYPE,
|
||||||
DataFlowInfoFactory.EMPTY, InferenceSession.Companion.getDefault(),
|
DataFlowInfoFactory.EMPTY, InferenceSession.Companion.getDefault(),
|
||||||
@@ -585,7 +582,7 @@ public class KotlinTypeCheckerTest extends KotlinTestWithEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private KotlinType makeType(LexicalScope scope, String typeStr) {
|
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);
|
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.incremental.components.NoLookupLocation;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.psi.KtFile;
|
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.psi.KtTypeReference;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||||
import org.jetbrains.kotlin.resolve.*;
|
import org.jetbrains.kotlin.resolve.*;
|
||||||
@@ -80,7 +80,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
|
|||||||
private LexicalScope getContextScope() throws IOException {
|
private LexicalScope getContextScope() throws IOException {
|
||||||
// todo comments
|
// todo comments
|
||||||
String text = FileUtil.loadFile(new File("compiler/testData/type-substitutor.kt"), true);
|
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());
|
AnalysisResult analysisResult = JvmResolveUtil.analyze(ktFile, getEnvironment());
|
||||||
ModuleDescriptor module = analysisResult.getModuleDescriptor();
|
ModuleDescriptor module = analysisResult.getModuleDescriptor();
|
||||||
|
|
||||||
@@ -145,7 +145,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private KotlinType resolveType(String typeStr) {
|
private KotlinType resolveType(String typeStr) {
|
||||||
KtTypeReference jetTypeReference = KtPsiFactoryKt.KtPsiFactory(getProject()).createType(typeStr);
|
KtTypeReference jetTypeReference = new KtPsiFactory(getProject()).createType(typeStr);
|
||||||
AnalyzingUtils.checkForSyntacticErrors(jetTypeReference);
|
AnalyzingUtils.checkForSyntacticErrors(jetTypeReference);
|
||||||
BindingTrace trace = new BindingTraceContext();
|
BindingTrace trace = new BindingTraceContext();
|
||||||
KotlinType type = container.getTypeResolver().resolveType(scope, jetTypeReference, trace, true);
|
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.annotations.Annotations;
|
||||||
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl;
|
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
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.KtTypeProjection;
|
||||||
import org.jetbrains.kotlin.psi.KtTypeReference;
|
import org.jetbrains.kotlin.psi.KtTypeReference;
|
||||||
import org.jetbrains.kotlin.resolve.TypeResolver;
|
import org.jetbrains.kotlin.resolve.TypeResolver;
|
||||||
@@ -206,8 +206,7 @@ public class TypeUnifierTest extends KotlinTestWithEnvironment {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
KtTypeProjection projection = KtPsiFactoryKt
|
KtTypeProjection projection = new KtPsiFactory(getProject()).createTypeArguments("<" + typeStr + ">").getArguments().get(0);
|
||||||
.KtPsiFactory(getProject()).createTypeArguments("<" + typeStr + ">").getArguments().get(0);
|
|
||||||
|
|
||||||
KtTypeReference typeReference = projection.getTypeReference();
|
KtTypeReference typeReference = projection.getTypeReference();
|
||||||
assert typeReference != null;
|
assert typeReference != null;
|
||||||
|
|||||||
Reference in New Issue
Block a user