From ee036770c394e6796a3f8977f069372f2976b95c Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Mon, 14 Jul 2014 20:59:05 +0400 Subject: [PATCH] Add JetPsiFactory(JetElement) function and use it --- .../jetbrains/jet/lang/psi/JetCodeFragment.kt | 2 +- .../jet/lang/psi/JetExpressionImpl.java | 2 +- .../jet/lang/psi/JetExpressionImplStub.java | 2 +- .../psi/JetNamedDeclarationNotStubbed.java | 2 +- .../jet/lang/psi/JetNamedDeclarationStub.java | 2 +- .../lang/psi/JetObjectDeclarationName.java | 2 +- .../jetbrains/jet/lang/psi/JetPsiFactory.kt | 15 ++++++----- .../jet/lang/psi/psiUtil/jetPsiUtil.kt | 2 +- .../resolve/DelegatedPropertyResolver.java | 15 +++++------ .../lang/resolve/calls/CallTransformer.java | 2 +- .../ControlStructureTypingVisitor.java | 5 ++-- .../expressions/ExpressionTypingUtils.java | 4 +-- .../JetAddFunctionToClassifierAction.java | 4 +-- .../JetChangeFunctionSignatureAction.java | 4 +-- .../jet/plugin/caches/JetShortNamesCache.java | 4 +-- .../KotlinCopyPasteReferenceProcessor.kt | 11 ++++---- .../OverrideImplementMethodsHandler.java | 3 +-- .../plugin/codeInsight/ShortenReferences.kt | 2 +- .../MoveDeclarationsOutHelper.java | 4 +-- .../expression/KotlinNotSurrounder.java | 2 +- .../KotlinParenthesesSurrounder.java | 2 +- .../KotlinStringTemplateSurrounder.java | 2 +- .../expression/KotlinWhenSurrounder.java | 2 +- .../codeInsight/unwrap/KotlinUnwrappers.java | 2 +- .../extractFunctionForDebuggerUtil.kt | 4 +-- .../plugin/intentions/AddBracesIntention.kt | 2 +- .../ConvertAssertToIfWithThrowIntention.kt | 2 +- .../ConvertIfWithThrowToAssertIntention.kt | 2 +- .../ConvertNegatedBooleanSequenceIntention.kt | 2 +- ...atedExpressionWithDemorgansLawIntention.kt | 2 +- .../intentions/ConvertToBlockBodyAction.kt | 2 +- .../ConvertToConcatenatedStringIntention.kt | 2 +- .../ConvertToExpressionBodyAction.kt | 2 +- .../ConvertToForEachFunctionCallIntention.kt | 2 +- .../ConvertToForEachLoopIntention.kt | 2 +- .../ConvertToStringTemplateIntention.kt | 2 +- .../InsertCurlyBracesToTemplateIntention.kt | 2 +- .../intentions/InsertExplicitTypeArguments.kt | 2 +- .../intentions/InvertIfConditionIntention.kt | 2 +- .../MakeTypeExplicitInLambdaIntention.kt | 2 +- .../MakeTypeImplicitInLambdaIntention.kt | 2 +- .../MoveLambdaInsideParenthesesIntention.kt | 2 +- .../MoveLambdaOutsideParenthesesIntention.kt | 2 +- .../intentions/OperatorToFunctionIntention.kt | 10 +++---- .../ReconstructTypeInCastOrIsAction.java | 2 +- .../intentions/RemoveBracesIntention.kt | 8 +++--- .../RemoveCurlyBracesFromTemplateIntention.kt | 2 +- ...thExplicitFunctionLiteralParamIntention.kt | 2 +- ...laceWithDotQualifiedMethodCallIntention.kt | 2 +- .../ReplaceWithInfixFunctionCallIntention.kt | 2 +- .../ReplaceWithOperatorAssignIntention.kt | 2 +- ...placeWithTraditionalAssignmentIntention.kt | 2 +- .../SimplifyBooleanWithConstantsIntention.kt | 4 +-- ...implifyNegatedBinaryExpressionIntention.kt | 2 +- .../SpecifyTypeExplicitlyAction.java | 2 +- .../jet/plugin/intentions/SplitIfIntention.kt | 4 +-- .../plugin/intentions/SwapBinaryExpression.kt | 2 +- .../jetbrains/jet/plugin/intentions/Utils.kt | 7 +++-- .../ReplaceBinaryInfixIntention.kt | 2 +- .../ReplaceContainsIntention.kt | 2 +- .../ReplaceGetIntention.kt | 2 +- .../ReplaceInvokeIntention.kt | 2 +- .../ReplaceUnaryPrefixIntention.kt | 2 +- .../BranchedFoldingUtils.java | 20 ++++---------- .../BranchedUnfoldingUtils.java | 12 +++------ .../branchedTransformations/IfThenUtils.kt | 9 ++++--- .../branchedTransformationUtils.kt | 12 ++++----- .../intentions/DoubleBangToIfThenIntention.kt | 4 +-- .../intentions/SafeAccessToIfThenIntention.kt | 2 +- .../ConvertMemberToExtension.java | 2 +- .../declarations/DeclarationUtils.java | 4 +-- .../plugin/quickfix/AddFunctionBodyFix.java | 2 +- .../plugin/quickfix/AddNameToArgumentFix.java | 2 +- .../AddSemicolonAfterFunctionCallFix.java | 2 +- .../quickfix/AddStarProjectionsFix.java | 2 +- .../plugin/quickfix/AddWhenElseBranchFix.java | 2 +- .../plugin/quickfix/CastExpressionFix.java | 2 +- .../quickfix/ChangeAccessorTypeFix.java | 2 +- .../ChangeFunctionLiteralReturnTypeFix.java | 2 +- .../quickfix/ChangeFunctionReturnTypeFix.java | 6 ++--- .../quickfix/ChangeParameterTypeFix.java | 2 +- .../quickfix/ChangeToBackingFieldFix.java | 2 +- .../ChangeToConstructorInvocationFix.java | 2 +- .../ChangeToFunctionInvocationFix.java | 2 +- .../quickfix/ChangeToPropertyNameFix.java | 2 +- .../quickfix/ChangeToStarProjectionFix.java | 2 +- .../jet/plugin/quickfix/ChangeTypeFix.java | 2 +- .../quickfix/ChangeVariableMutabilityFix.java | 2 +- .../quickfix/ChangeVariableTypeFix.java | 2 +- .../quickfix/CreateFunctionFromUsageFix.kt | 12 ++++----- .../quickfix/KotlinSuppressIntentionAction.kt | 21 ++++++--------- .../quickfix/MoveWhenElseBranchFix.java | 2 +- .../jet/plugin/quickfix/ReplaceCallFix.java | 2 +- .../plugin/quickfix/ReplaceInfixCallFix.java | 2 +- ...ReplaceOperationInBinaryExpressionFix.java | 2 +- .../usages/JetFunctionDefinitionUsage.java | 2 +- .../extractFunction/ExtractionData.kt | 2 +- .../extractFunction/ExtractionDescriptor.kt | 5 ++-- .../extractFunction/extractFunctionUtils.kt | 4 +-- .../inline/KotlinInlineValHandler.java | 11 ++++---- .../KotlinChangePropertyActions.java | 4 +-- .../KotlinInplaceVariableIntroducer.java | 3 +-- .../KotlinIntroduceVariableHandler.java | 26 ++++++++++--------- .../plugin/refactoring/jetRefactoringUtil.kt | 6 ++--- .../references/JetSimpleNameReference.kt | 3 +-- 105 files changed, 192 insertions(+), 220 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetCodeFragment.kt b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetCodeFragment.kt index 520cf6bc687..75391044b12 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetCodeFragment.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetCodeFragment.kt @@ -100,7 +100,7 @@ public abstract class JetCodeFragment( } fun importsAsImportList(): JetImportList? { - return JetPsiFactory(_project).createFile(_myImports.makeString("\n")).getImportList() + return JetPsiFactory(this).createFile(_myImports.makeString("\n")).getImportList() } override fun setVisibilityChecker(checker: JavaCodeFragment.VisibilityChecker?) { } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetExpressionImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetExpressionImpl.java index e665eae3c56..797a915ee4d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetExpressionImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetExpressionImpl.java @@ -46,7 +46,7 @@ public abstract class JetExpressionImpl extends JetElementImpl implements JetExp PsiElement parent = getParent(); if (parent instanceof JetExpression && newElement instanceof JetExpression && JetPsiUtil.areParenthesesNecessary((JetExpression) newElement, this, (JetExpression) parent)) { - return super.replace(PsiPackage.JetPsiFactory(getProject()).createExpression("(" + newElement.getText() + ")")); + return super.replace(PsiPackage.JetPsiFactory(this).createExpression("(" + newElement.getText() + ")")); } return super.replace(newElement); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetExpressionImplStub.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetExpressionImplStub.java index 20cb6872019..d399b89f4e1 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetExpressionImplStub.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetExpressionImplStub.java @@ -44,7 +44,7 @@ public abstract class JetExpressionImplStub extends JetEl PsiElement parent = getParent(); if (parent instanceof JetExpression && newElement instanceof JetExpression && JetPsiUtil.areParenthesesNecessary((JetExpression) newElement, this, (JetExpression) parent)) { - return super.replace(PsiPackage.JetPsiFactory(getProject()).createExpression("(" + newElement.getText() + ")")); + return super.replace(PsiPackage.JetPsiFactory(this).createExpression("(" + newElement.getText() + ")")); } return super.replace(newElement); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclarationNotStubbed.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclarationNotStubbed.java index 81073e024de..1316c7f4bfe 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclarationNotStubbed.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclarationNotStubbed.java @@ -64,7 +64,7 @@ abstract class JetNamedDeclarationNotStubbed extends JetDeclarationImpl implemen @Override public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException { - return getNameIdentifier().replace(JetPsiFactory(getProject()).createNameIdentifier(name)); + return getNameIdentifier().replace(JetPsiFactory(this).createNameIdentifier(name)); } @Override diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclarationStub.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclarationStub.java index d9cb3ac26f2..23894f93f3d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclarationStub.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedDeclarationStub.java @@ -77,7 +77,7 @@ abstract class JetNamedDeclarationStub extends J @Override public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException { - return getNameIdentifier().replace(JetPsiFactory(getProject()).createNameIdentifier(name)); + return getNameIdentifier().replace(JetPsiFactory(this).createNameIdentifier(name)); } @Override diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetObjectDeclarationName.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetObjectDeclarationName.java index 7d372f1dc07..4235ddc5b2b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetObjectDeclarationName.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetObjectDeclarationName.java @@ -49,7 +49,7 @@ public class JetObjectDeclarationName extends JetExpressionImpl { } public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException { - return getNameIdentifier().replace(PsiPackage.JetPsiFactory(getProject()).createNameIdentifier(name)); + return getNameIdentifier().replace(PsiPackage.JetPsiFactory(this).createNameIdentifier(name)); } @Override diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiFactory.kt b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiFactory.kt index 3e7457e2170..d790a02a59f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiFactory.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiFactory.kt @@ -27,6 +27,7 @@ import org.jetbrains.jet.lexer.JetKeywordToken import org.jetbrains.jet.plugin.JetFileType public fun JetPsiFactory(project: Project?): JetPsiFactory = JetPsiFactory(project!!) +public fun JetPsiFactory(contextElement: JetElement): JetPsiFactory = JetPsiFactory(contextElement.getProject()) public class JetPsiFactory(private val project: Project) { @@ -190,7 +191,7 @@ public class JetPsiFactory(private val project: Project) { } public fun createWhenEntry(entryText: String): JetWhenEntry { - val function = createFunction("fun foo() { when(12) { $entryText } }") + val function = createFunction("fun foo() { when(12) { " + entryText + " } }") val whenEntry = PsiTreeUtil.findChildOfType(function, javaClass()) assert(whenEntry != null, "Couldn't generate when entry") @@ -200,8 +201,8 @@ public class JetPsiFactory(private val project: Project) { } public fun createBlockStringTemplateEntry(expression: JetExpression): JetStringTemplateEntryWithExpression { - val stringTemplateExpression = createExpression("\"\${${expression.getText()}}\"") as JetStringTemplateExpression - return stringTemplateExpression.getEntries().first() as JetStringTemplateEntryWithExpression + val stringTemplateExpression = createExpression("\"\${" + expression.getText() + "}\"") as JetStringTemplateExpression + return stringTemplateExpression.getEntries()[0] as JetStringTemplateEntryWithExpression } public fun createImportDirective(path: String): JetImportDirective { @@ -235,15 +236,15 @@ public class JetPsiFactory(private val project: Project) { } public fun createClassLabel(labelName: String): JetSimpleNameExpression { - return (createExpression("this@$labelName") as JetThisExpression).getTargetLabel()!! + return (createExpression("this@" + labelName) as JetThisExpression).getTargetLabel()!! } public fun createFieldIdentifier(fieldName: String): JetExpression { - return createExpression("$$fieldName") + return createExpression("$" + fieldName) } public fun createBinaryExpression(lhs: String, op: String, rhs: String): JetBinaryExpression { - return createExpression("$lhs $op $rhs") as JetBinaryExpression + return createExpression(lhs + " " + op + " " + rhs) as JetBinaryExpression } public fun createBinaryExpression(lhs: JetExpression?, op: String, rhs: JetExpression?): JetBinaryExpression { @@ -549,7 +550,7 @@ public class JetPsiFactory(private val project: Project) { } public fun createFunctionBody(bodyText: String): JetExpression { - return createFunction("fun foo() {\n$bodyText\n}").getBodyExpression()!! + return createFunction("fun foo() {\n" + bodyText + "\n}").getBodyExpression()!! } public fun createEmptyClassObject(): JetClassObject { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/psiUtil/jetPsiUtil.kt b/compiler/frontend/src/org/jetbrains/jet/lang/psi/psiUtil/jetPsiUtil.kt index b3cdd22f1de..cf41f24c4b4 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/psiUtil/jetPsiUtil.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/psiUtil/jetPsiUtil.kt @@ -110,7 +110,7 @@ public fun JetBlockExpression.prependElement(element: JetElement): JetElement = addBefore(element, getLBrace()!!.getNextSibling()!!)!! as JetElement public fun JetElement.wrapInBlock(): JetBlockExpression { - val block = JetPsiFactory(getProject()).createEmptyBody() as JetBlockExpression + val block = JetPsiFactory(this).createEmptyBody() as JetBlockExpression block.appendElement(this) return block } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegatedPropertyResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegatedPropertyResolver.java index 08a233c19d8..499a036c511 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegatedPropertyResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegatedPropertyResolver.java @@ -17,7 +17,6 @@ package org.jetbrains.jet.lang.resolve; import com.google.common.collect.Lists; -import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; @@ -173,17 +172,17 @@ public class DelegatedPropertyResolver { ExpressionTypingContext context = ExpressionTypingContext.newContext( expressionTypingServices, trace, scope, DataFlowInfo.EMPTY, TypeUtils.NO_EXPECTED_TYPE); - Project project = expressionTypingServices.getProject(); boolean hasThis = propertyDescriptor.getReceiverParameter() != null || propertyDescriptor.getExpectedThisObject() != null; List arguments = Lists.newArrayList(); - arguments.add(JetPsiFactory(project).createExpression(hasThis ? "this" : "null")); + JetPsiFactory psiFactory = JetPsiFactory(delegateExpression); + arguments.add(psiFactory.createExpression(hasThis ? "this" : "null")); - arguments.add(JetPsiFactory(project).createExpression(KotlinBuiltIns.getInstance().getPropertyMetadataImpl().getName().asString() + - "(\"" + - propertyDescriptor.getName().asString() + - "\")")); + arguments.add(psiFactory.createExpression(KotlinBuiltIns.getInstance().getPropertyMetadataImpl().getName().asString() + + "(\"" + + propertyDescriptor.getName().asString() + + "\")")); if (!isGet) { JetReferenceExpression fakeArgument = (JetReferenceExpression) createFakeExpressionOfType(expressionTypingServices.getProject(), trace, @@ -195,7 +194,7 @@ public class DelegatedPropertyResolver { } Name functionName = Name.identifier(isGet ? "get" : "set"); - JetReferenceExpression fakeCalleeExpression = JetPsiFactory(project).createSimpleName(functionName.asString()); + JetReferenceExpression fakeCalleeExpression = psiFactory.createSimpleName(functionName.asString()); ExpressionReceiver receiver = new ExpressionReceiver(delegateExpression, delegateType); Call call = CallMaker.makeCallWithExpressions(fakeCalleeExpression, receiver, null, fakeCalleeExpression, arguments, Call.CallType.DEFAULT); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallTransformer.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallTransformer.java index 3bef8a93fe4..2280b8c03b8 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallTransformer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallTransformer.java @@ -264,7 +264,7 @@ public class CallTransformer { this.outerCall = call; this.explicitExtensionReceiver = explicitExtensionReceiver; this.calleeExpressionAsThisObject = calleeExpressionAsThisObject; - this.fakeInvokeExpression = (JetSimpleNameExpression) JetPsiFactory(call.getCallElement().getProject()).createExpression( "invoke"); + this.fakeInvokeExpression = (JetSimpleNameExpression) JetPsiFactory(call.getCallElement()).createExpression( "invoke"); } @NotNull diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java index 0f53bafe241..5a8db92d6d2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java @@ -109,8 +109,9 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { return getTypeInfoWhenOnlyOneBranchIsPresent( elseBranch, elseScope, elseInfo, thenInfo, contextWithExpectedType, ifExpression, isStatement); } - JetBlockExpression thenBlock = JetPsiFactory(ifExpression.getProject()).wrapInABlock(thenBranch); - JetBlockExpression elseBlock = JetPsiFactory(ifExpression.getProject()).wrapInABlock(elseBranch); + JetPsiFactory psiFactory = JetPsiFactory(ifExpression); + JetBlockExpression thenBlock = psiFactory.wrapInABlock(thenBranch); + JetBlockExpression elseBlock = psiFactory.wrapInABlock(elseBranch); Call callForIf = createCallForSpecialConstruction(ifExpression, ifExpression, Lists.newArrayList(thenBlock, elseBlock)); MutableDataFlowInfoForArguments dataFlowInfoForArguments = createDataFlowInfoForArgumentsForIfCall(callForIf, thenInfo, elseInfo); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java index 80be5d9c82b..5e86ca96cc4 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java @@ -209,19 +209,17 @@ public class ExpressionTypingUtils { * Check that function or property with the given qualified name can be resolved in given scope and called on given receiver * * @param callableFQN - * @param project * @param scope * @return */ public static List canFindSuitableCall( @NotNull FqName callableFQN, - @NotNull Project project, @NotNull JetExpression receiverExpression, @NotNull JetType receiverType, @NotNull JetScope scope, @NotNull ModuleDescriptor module ) { - JetImportDirective importDirective = JetPsiFactory(project).createImportDirective(callableFQN.asString()); + JetImportDirective importDirective = JetPsiFactory(receiverExpression).createImportDirective(callableFQN.asString()); Collection declarationDescriptors = new QualifiedExpressionResolver() .analyseImportReference(importDirective, scope, new BindingTraceContext(), module); diff --git a/idea/src/org/jetbrains/jet/plugin/actions/JetAddFunctionToClassifierAction.java b/idea/src/org/jetbrains/jet/plugin/actions/JetAddFunctionToClassifierAction.java index fe79b7ed288..a2c9d9dedd3 100644 --- a/idea/src/org/jetbrains/jet/plugin/actions/JetAddFunctionToClassifierAction.java +++ b/idea/src/org/jetbrains/jet/plugin/actions/JetAddFunctionToClassifierAction.java @@ -65,7 +65,7 @@ public class JetAddFunctionToClassifierAction implements QuestionAction { } private static void addFunction( - @NotNull final Project project, + @NotNull Project project, @NotNull final ClassDescriptor typeDescriptor, @NotNull final FunctionDescriptor functionDescriptor ) { @@ -82,7 +82,7 @@ public class JetAddFunctionToClassifierAction implements QuestionAction { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { - JetPsiFactory psiFactory = PsiPackage.JetPsiFactory(project); + JetPsiFactory psiFactory = PsiPackage.JetPsiFactory(classifierDeclaration); JetClassBody body = classifierDeclaration.getBody(); if (body == null) { PsiElement whitespaceBefore = classifierDeclaration.add(psiFactory.createWhiteSpace()); diff --git a/idea/src/org/jetbrains/jet/plugin/actions/JetChangeFunctionSignatureAction.java b/idea/src/org/jetbrains/jet/plugin/actions/JetChangeFunctionSignatureAction.java index 3b4465cdcdd..274b8454c96 100644 --- a/idea/src/org/jetbrains/jet/plugin/actions/JetChangeFunctionSignatureAction.java +++ b/idea/src/org/jetbrains/jet/plugin/actions/JetChangeFunctionSignatureAction.java @@ -119,14 +119,14 @@ public class JetChangeFunctionSignatureAction implements QuestionAction { }; } - private static void changeSignature(final JetNamedFunction element, final Project project, FunctionDescriptor signature) { + private static void changeSignature(final JetNamedFunction element, Project project, FunctionDescriptor signature) { final String signatureString = CodeInsightUtils.createFunctionSignatureStringFromDescriptor( signature, /* shortTypeNames = */ false); PsiDocumentManager.getInstance(project).commitAllDocuments(); - final JetPsiFactory psiFactory = PsiPackage.JetPsiFactory(project); + final JetPsiFactory psiFactory = PsiPackage.JetPsiFactory(element); CommandProcessor.getInstance().executeCommand(project, new Runnable() { @Override public void run() { diff --git a/idea/src/org/jetbrains/jet/plugin/caches/JetShortNamesCache.java b/idea/src/org/jetbrains/jet/plugin/caches/JetShortNamesCache.java index 565e30ed451..ad20346a2b6 100644 --- a/idea/src/org/jetbrains/jet/plugin/caches/JetShortNamesCache.java +++ b/idea/src/org/jetbrains/jet/plugin/caches/JetShortNamesCache.java @@ -244,7 +244,7 @@ public class JetShortNamesCache extends PsiShortNamesCache { } }); for (FqName fqName : topLevelFunctionFqNames) { - JetImportDirective importDirective = JetPsiFactory(project).createImportDirective(new ImportPath(fqName, false)); + JetImportDirective importDirective = JetPsiFactory(expression).createImportDirective(new ImportPath(fqName, false)); Collection declarationDescriptors = new QualifiedExpressionResolver().analyseImportReference( importDirective, jetScope, new BindingTraceContext(), resolveSession.getModuleDescriptor()); for (DeclarationDescriptor declarationDescriptor : declarationDescriptors) { @@ -314,7 +314,7 @@ public class JetShortNamesCache extends PsiShortNamesCache { // Iterate through the function with attempt to resolve found functions for (FqName functionFQN : functionFQNs) { for (CallableDescriptor functionDescriptor : ExpressionTypingUtils.canFindSuitableCall( - functionFQN, project, receiverExpression, expressionType, scope, resolveSession.getModuleDescriptor())) { + functionFQN, receiverExpression, expressionType, scope, resolveSession.getModuleDescriptor())) { resultDescriptors.add(functionDescriptor); } diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/KotlinCopyPasteReferenceProcessor.kt b/idea/src/org/jetbrains/jet/plugin/codeInsight/KotlinCopyPasteReferenceProcessor.kt index d66b0007e0c..9ef641aefb3 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/KotlinCopyPasteReferenceProcessor.kt +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/KotlinCopyPasteReferenceProcessor.kt @@ -311,8 +311,8 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor().getSimpleName()}." @@ -325,18 +325,19 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor()) LOG.assertTrue(typeReference != null, "JetUserType is expected to have parent of type JetTypeReference:\n" + "At: ${DiagnosticUtils.atLocation(expression)}\nFILE:\n${expression.getContainingFile()!!.getText()}") - typeReference!!.replace(JetPsiFactory(project).createType("$prefixToInsert.${typeReference.getText()}")) + typeReference!!.replace(psiFactory.createType("$prefixToInsert.${typeReference.getText()}")) } else { - expression.replace(createQualifiedExpression(project, fqName.asString())) + expression.replace(createQualifiedExpression(psiFactory, fqName.asString())) } } diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/OverrideImplementMethodsHandler.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/OverrideImplementMethodsHandler.java index 4f0baba5547..ccf3faf2acc 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/OverrideImplementMethodsHandler.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/OverrideImplementMethodsHandler.java @@ -82,8 +82,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns ) { JetClassBody body = classOrObject.getBody(); if (body == null) { - Project project = classOrObject.getProject(); - JetPsiFactory psiFactory = JetPsiFactory(project); + JetPsiFactory psiFactory = JetPsiFactory(classOrObject); classOrObject.add(psiFactory.createWhiteSpace()); body = (JetClassBody) classOrObject.add(psiFactory.createEmptyClassBody()); } diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/ShortenReferences.kt b/idea/src/org/jetbrains/jet/plugin/codeInsight/ShortenReferences.kt index 881120ece6c..c32165c4139 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/ShortenReferences.kt +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/ShortenReferences.kt @@ -191,7 +191,7 @@ public object ShortenReferences { if (referenceExpression == null) return val typeArgumentList = userType.getTypeArgumentList() val text = referenceExpression.getText() + (if (typeArgumentList != null) typeArgumentList.getText() else "") - val newUserType = JetPsiFactory(userType.getProject()).createType(text).getTypeElement()!! + val newUserType = JetPsiFactory(userType).createType(text).getTypeElement()!! userType.replace(newUserType) } } diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/MoveDeclarationsOutHelper.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/MoveDeclarationsOutHelper.java index 06364c13228..2fa8279db5a 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/MoveDeclarationsOutHelper.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/MoveDeclarationsOutHelper.java @@ -95,7 +95,7 @@ public class MoveDeclarationsOutHelper { private static JetBinaryExpression createVariableAssignment(@NotNull JetProperty property) { String propertyName = property.getName(); assert propertyName != null : "Property should have a name " + property.getText(); - JetBinaryExpression assignment = (JetBinaryExpression) JetPsiFactory(property.getProject()).createExpression(propertyName + " = x"); + JetBinaryExpression assignment = (JetBinaryExpression) JetPsiFactory(property).createExpression(propertyName + " = x"); JetExpression right = assignment.getRight(); assert right != null : "Created binary expression should have a right part " + assignment.getText(); JetExpression initializer = property.getInitializer(); @@ -134,7 +134,7 @@ public class MoveDeclarationsOutHelper { typeString = DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(propertyType); } - return JetPsiFactory(property.getProject()).createProperty(property.getName(), typeString, property.isVar(), initializer); + return JetPsiFactory(property).createProperty(property.getName(), typeString, property.isVar(), initializer); } private static boolean needToDeclareOut(@NotNull PsiElement element, int lastStatementOffset, @NotNull SearchScope scope) { diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/expression/KotlinNotSurrounder.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/expression/KotlinNotSurrounder.java index c18571d017d..37c21391801 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/expression/KotlinNotSurrounder.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/expression/KotlinNotSurrounder.java @@ -47,7 +47,7 @@ public class KotlinNotSurrounder extends KotlinExpressionSurrounder { @Nullable @Override public TextRange surroundExpression(@NotNull Project project, @NotNull Editor editor, @NotNull JetExpression expression) { - JetPrefixExpression prefixExpr = (JetPrefixExpression) JetPsiFactory(project).createExpression("!(a)"); + JetPrefixExpression prefixExpr = (JetPrefixExpression) JetPsiFactory(expression).createExpression("!(a)"); JetParenthesizedExpression parenthesizedExpression = (JetParenthesizedExpression) prefixExpr.getBaseExpression(); assert parenthesizedExpression != null : "JetParenthesizedExpression should exists for " + prefixExpr.getText() + " expression"; JetExpression expressionWithoutParentheses = parenthesizedExpression.getExpression(); diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/expression/KotlinParenthesesSurrounder.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/expression/KotlinParenthesesSurrounder.java index d7f86bde3b3..0e7c71beb49 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/expression/KotlinParenthesesSurrounder.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/expression/KotlinParenthesesSurrounder.java @@ -42,7 +42,7 @@ public class KotlinParenthesesSurrounder extends KotlinExpressionSurrounder { @Nullable @Override public TextRange surroundExpression( @NotNull Project project, @NotNull Editor editor, @NotNull JetExpression expression) { - JetParenthesizedExpression parenthesizedExpression = (JetParenthesizedExpression) JetPsiFactory(project).createExpression("(a)"); + JetParenthesizedExpression parenthesizedExpression = (JetParenthesizedExpression) JetPsiFactory(expression).createExpression("(a)"); JetExpression expressionWithoutParentheses = parenthesizedExpression.getExpression(); assert expressionWithoutParentheses != null : "JetExpression should exists for " + parenthesizedExpression.getText() + " expression"; expressionWithoutParentheses.replace(expression); diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/expression/KotlinStringTemplateSurrounder.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/expression/KotlinStringTemplateSurrounder.java index b2a6c1961fd..dded6d72876 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/expression/KotlinStringTemplateSurrounder.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/expression/KotlinStringTemplateSurrounder.java @@ -44,7 +44,7 @@ public class KotlinStringTemplateSurrounder extends KotlinExpressionSurrounder { @Nullable @Override public TextRange surroundExpression(@NotNull Project project, @NotNull Editor editor, @NotNull JetExpression expression) { - JetStringTemplateExpression stringTemplateExpression = (JetStringTemplateExpression) JetPsiFactory(project).createExpression( + JetStringTemplateExpression stringTemplateExpression = (JetStringTemplateExpression) JetPsiFactory(expression).createExpression( getCodeTemplate(expression) ); JetStringTemplateEntry templateEntry = stringTemplateExpression.getEntries()[0]; diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/expression/KotlinWhenSurrounder.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/expression/KotlinWhenSurrounder.java index 26a848ec469..e387108fef2 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/expression/KotlinWhenSurrounder.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/surroundWith/expression/KotlinWhenSurrounder.java @@ -49,7 +49,7 @@ public class KotlinWhenSurrounder extends KotlinExpressionSurrounder { @Nullable @Override public TextRange surroundExpression(@NotNull Project project, @NotNull Editor editor, @NotNull JetExpression expression) { - JetWhenExpression whenExpression = (JetWhenExpression) JetPsiFactory(project).createExpression(getCodeTemplate(expression)); + JetWhenExpression whenExpression = (JetWhenExpression) JetPsiFactory(expression).createExpression(getCodeTemplate(expression)); JetExpression subjectExpression = whenExpression.getSubjectExpression(); assert subjectExpression != null : "JetExpression should exists for " + whenExpression.getText() + " expression"; subjectExpression.replace(expression); diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/unwrap/KotlinUnwrappers.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/unwrap/KotlinUnwrappers.java index c95a4bcf976..cfb9c2f1397 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/unwrap/KotlinUnwrappers.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/unwrap/KotlinUnwrappers.java @@ -74,7 +74,7 @@ public class KotlinUnwrappers { @Override protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException { JetIfExpression ifExpr = (JetIfExpression) element; - context.replace(ifExpr, JetPsiFactory(ifExpr.getProject()).createIf(ifExpr.getCondition(), ifExpr.getThen(), null)); + context.replace(ifExpr, JetPsiFactory(ifExpr).createIf(ifExpr.getCondition(), ifExpr.getThen(), null)); } } diff --git a/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/extractFunctionForDebuggerUtil.kt b/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/extractFunctionForDebuggerUtil.kt index 75e04693c0a..1c5e41fccf4 100644 --- a/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/extractFunctionForDebuggerUtil.kt +++ b/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/extractFunctionForDebuggerUtil.kt @@ -110,7 +110,7 @@ private fun addImportsToFile(newImportList: JetImportList?, tmpFile: JetFile) { if (newImportList != null) { val tmpFileImportList = tmpFile.getImportList() val packageDirective = tmpFile.getPackageDirective() - val psiFactory = JetPsiFactory(tmpFile.getProject()) + val psiFactory = JetPsiFactory(tmpFile) if (tmpFileImportList == null) { tmpFile.addAfter(psiFactory.createNewLine(), packageDirective) tmpFile.addAfter(newImportList, tmpFile.getPackageDirective()) @@ -126,7 +126,7 @@ private fun addDebugExpressionBeforeContextElement(codeFragment: JetCodeFragment val parent = contextElement.getParent() if (parent == null) return null - val psiFactory = JetPsiFactory(contextElement.getProject()) + val psiFactory = JetPsiFactory(codeFragment) parent.addBefore(psiFactory.createNewLine(), contextElement) val debugExpression = codeFragment.getContentElement() diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/AddBracesIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/AddBracesIntention.kt index 76dae44934e..7057592ef35 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/AddBracesIntention.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/AddBracesIntention.kt @@ -53,7 +53,7 @@ public class AddBracesIntention : JetSelfTargetingIntention(" if (element.getNextSibling()?.getText() == ";") { element.getNextSibling()!!.delete() } - val psiFactory = JetPsiFactory(element.getProject()) + val psiFactory = JetPsiFactory(element) val newElement = bodyNode!!.getPsi()!!.replace(psiFactory.createFunctionBody(bodyNode.getText())) //handles the case of the block statement being on a new line diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertAssertToIfWithThrowIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertAssertToIfWithThrowIntention.kt index 7c075cca1cb..6bcf056bd69 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertAssertToIfWithThrowIntention.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertAssertToIfWithThrowIntention.kt @@ -61,7 +61,7 @@ public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention "$expression $operatorText $negated" } ) - val newExpression = JetPsiFactory(element.getProject()).createExpression("$negatedExpression)") + val newExpression = JetPsiFactory(element).createExpression("$negatedExpression)") val insertedElement = element.replace(newExpression) val insertedElementParent = insertedElement.getParent() as? JetParenthesizedExpression ?: return diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertNegatedExpressionWithDemorgansLawIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertNegatedExpressionWithDemorgansLawIntention.kt index 839d20d4b15..8b6ca9bfdac 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertNegatedExpressionWithDemorgansLawIntention.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertNegatedExpressionWithDemorgansLawIntention.kt @@ -64,7 +64,7 @@ public class ConvertNegatedExpressionWithDemorgansLawIntention : JetSelfTargetin val negatedExpression = negatedElements.subList(0, negatedElements.lastIndex).foldRight( "${negatedElements.last()}", { negated, exp -> "$exp $operatorText $negated" }) - val newExpression = JetPsiFactory(element.getProject()).createExpression(negatedExpression) + val newExpression = JetPsiFactory(element).createExpression(negatedExpression) element.replace(newExpression) } diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToBlockBodyAction.kt b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToBlockBodyAction.kt index c3f7e1bcb49..fee4f1c6f19 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToBlockBodyAction.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToBlockBodyAction.kt @@ -44,7 +44,7 @@ public class ConvertToBlockBodyAction : PsiElementBaseIntentionAction() { val oldBodyText = body.getText()!! val newBodyText = if (needReturn) "return ${oldBodyText}" else oldBodyText - return JetPsiFactory(project).createFunctionBody(newBodyText) + return JetPsiFactory(declaration).createFunctionBody(newBodyText) } if (declaration is JetNamedFunction) { diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToConcatenatedStringIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToConcatenatedStringIntention.kt index dd6a7c0f39c..cdf063617ed 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToConcatenatedStringIntention.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToConcatenatedStringIntention.kt @@ -32,7 +32,7 @@ public class ConvertToConcatenatedStringIntention : JetSelfTargetingIntention body.getText() ?: throw AssertionError("Body of ForExpression shouldn't be empty: expressionText = ${element.getText()}") }) - element.replace(JetPsiFactory(element.getProject()).createExpression("${buildReceiverText(element)}.forEach { $bodyText }")) + element.replace(JetPsiFactory(element).createExpression("${buildReceiverText(element)}.forEach { $bodyText }")) } } \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToForEachLoopIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToForEachLoopIntention.kt index 89199e4a9cc..ec580dd4588 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToForEachLoopIntention.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToForEachLoopIntention.kt @@ -113,6 +113,6 @@ public class ConvertToForEachLoopIntention : JetSelfTargetingIntention "" + descriptor.getName() + ": " + DescriptorRenderer.SOURCE_CODE.renderType(descriptor.getType()) }).makeString(", ", "(", ")") - val psiFactory = JetPsiFactory(element.getProject()) + val psiFactory = JetPsiFactory(element) val newParameterList = psiFactory.createParameterList(parameterString) val oldParameterList = functionLiteral.getValueParameterList() if (oldParameterList != null) { diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/MakeTypeImplicitInLambdaIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/MakeTypeImplicitInLambdaIntention.kt index 671955c0655..73e99989d9e 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/MakeTypeImplicitInLambdaIntention.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/MakeTypeImplicitInLambdaIntention.kt @@ -42,7 +42,7 @@ public class MakeTypeImplicitInLambdaIntention : JetSelfTargetingIntention return } - val transformed = JetPsiFactory(element.getProject()).createExpression(transformation) + val transformed = JetPsiFactory(element).createExpression(transformation) element.replace(transformed) } @@ -177,7 +177,7 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention 42 }") as JetFunctionLiteralExpression + val newExpr = JetPsiFactory(simpleNameExpression).createExpression("{ it -> 42 }") as JetFunctionLiteralExpression funcExpr.addRangeAfter(newExpr.getFunctionLiteral().getValueParameterList(), newExpr.getFunctionLiteral().getArrowNode()!!.getPsi(), funcExpr.getOpenBraceNode().getPsi()) diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/ReplaceWithDotQualifiedMethodCallIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/ReplaceWithDotQualifiedMethodCallIntention.kt index d9e7990d369..e67f87e2cc4 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/ReplaceWithDotQualifiedMethodCallIntention.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/ReplaceWithDotQualifiedMethodCallIntention.kt @@ -42,7 +42,7 @@ public class ReplaceWithDotQualifiedMethodCallIntention : JetSelfTargetingIntent } ) - val replacement = JetPsiFactory(element.getProject()).createExpression(replacementExpressionStringBuilder.toString()) + val replacement = JetPsiFactory(element).createExpression(replacementExpressionStringBuilder.toString()) element.replace(replacement) } } \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/ReplaceWithInfixFunctionCallIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/ReplaceWithInfixFunctionCallIntention.kt index 14fe5ca6fd8..2ccaeca6bf9 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/ReplaceWithInfixFunctionCallIntention.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/ReplaceWithInfixFunctionCallIntention.kt @@ -109,7 +109,7 @@ public open class ReplaceWithInfixFunctionCallIntention : JetSelfTargetingIntent functionLiteralArguments.first().getText() ) - val replacement = JetPsiFactory(element.getProject()).createExpression("$leftHandText $operatorText ${rightHandTextStringBuilder.toString()}") + val replacement = JetPsiFactory(element).createExpression("$leftHandText $operatorText ${rightHandTextStringBuilder.toString()}") parent.replace(replacement) } diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/ReplaceWithOperatorAssignIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/ReplaceWithOperatorAssignIntention.kt index 8c3ac9ac96a..2bb7f0a62b5 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/ReplaceWithOperatorAssignIntention.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/ReplaceWithOperatorAssignIntention.kt @@ -111,6 +111,6 @@ public class ReplaceWithOperatorAssignIntention : JetSelfTargetingIntention { diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyAction.java b/idea/src/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyAction.java index 31a652e20b9..5fa0c331204 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyAction.java +++ b/idea/src/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyAction.java @@ -264,7 +264,7 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction { } private static void addTypeAnnotationSilently(Project project, JetNamedDeclaration namedDeclaration, PsiElement anchor) { - JetPsiFactory psiFactory = PsiPackage.JetPsiFactory(project); + JetPsiFactory psiFactory = PsiPackage.JetPsiFactory(namedDeclaration); namedDeclaration.addAfter(psiFactory.createType("Any"), anchor); namedDeclaration.addAfter(psiFactory.createColon(), anchor); } diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/SplitIfIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/SplitIfIntention.kt index dad1d7b066b..26597be3728 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/SplitIfIntention.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/SplitIfIntention.kt @@ -59,7 +59,7 @@ public class SplitIfIntention : JetSelfTargetingIntention("split. val elseExpression = ifExpression.getElse() val thenExpression = ifExpression.getThen() - val psiFactory = JetPsiFactory(element.getProject()) + val psiFactory = JetPsiFactory(element) if (currentElement.getReferencedNameElementType() == JetTokens.ANDAND) { ifExpression.replace( psiFactory.createIf(leftExpression, psiFactory.wrapInABlock( @@ -80,7 +80,7 @@ public class SplitIfIntention : JetSelfTargetingIntention("split. val startOffset = element.getRight()!!.getTextOffset() - condition.getTextOffset() val rightString = condition.getText()!![startOffset, condition.getTextLength()].toString() - return JetPsiFactory(element.getProject()).createExpression(rightString) + return JetPsiFactory(element).createExpression(rightString) } fun isCursorOnIfKeyword(element: JetIfExpression, editor: Editor): Boolean { diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/SwapBinaryExpression.kt b/idea/src/org/jetbrains/jet/plugin/intentions/SwapBinaryExpression.kt index 244f27691ea..77c030b8228 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/SwapBinaryExpression.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/SwapBinaryExpression.kt @@ -61,7 +61,7 @@ public class SwapBinaryExpression : JetSelfTargetingIntention ifExpression.getCondition()?.let { condition -> val orBranches = condition.splitToOrBranches() @@ -304,7 +304,7 @@ public fun JetWhenExpression.transformToIf() { } } - val builder = JetPsiFactory(getProject()).IfChainBuilder() + val builder = JetPsiFactory(this).IfChainBuilder() for (entry in getEntries()) { val branch = entry.getExpression() @@ -365,7 +365,7 @@ public fun JetWhenExpression.mergeWithNext() { val block = if (this is JetBlockExpression) this else replaced(wrapInBlock()) for (element in that.blockExpressionsOrSingle()) { val expression = block.appendElement(element) - block.addBefore(JetPsiFactory(getProject()).createNewLine(), expression) + block.addBefore(JetPsiFactory(this).createNewLine(), expression) } block } diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/DoubleBangToIfThenIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/DoubleBangToIfThenIntention.kt index 95616270578..7c4528df69c 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/DoubleBangToIfThenIntention.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/DoubleBangToIfThenIntention.kt @@ -45,11 +45,10 @@ public class DoubleBangToIfThenIntention : JetSelfTargetingIntentioncreateDeclaration(extensionText); PsiElement added = file.addAfter(extension, outermostParent); diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/declarations/DeclarationUtils.java b/idea/src/org/jetbrains/jet/plugin/intentions/declarations/DeclarationUtils.java index 028bf91d3c1..c2966cd9703 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/declarations/DeclarationUtils.java +++ b/idea/src/org/jetbrains/jet/plugin/intentions/declarations/DeclarationUtils.java @@ -96,8 +96,6 @@ public class DeclarationUtils { // returns assignment which replaces initializer @NotNull public static JetBinaryExpression splitPropertyDeclaration(@NotNull JetProperty property) { - Project project = property.getProject(); - PsiElement parent = property.getParent(); assertNotNull(parent); @@ -105,7 +103,7 @@ public class DeclarationUtils { JetExpression initializer = property.getInitializer(); assertNotNull(initializer); - JetPsiFactory psiFactory = JetPsiFactory(project); + JetPsiFactory psiFactory = JetPsiFactory(property); //noinspection ConstantConditions, unchecked JetBinaryExpression newInitializer = psiFactory.createBinaryExpression( psiFactory.createSimpleName(property.getName()), "=", initializer diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/AddFunctionBodyFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/AddFunctionBodyFix.java index 11c8e1de1bc..e5e6993f528 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/AddFunctionBodyFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/AddFunctionBodyFix.java @@ -58,7 +58,7 @@ public class AddFunctionBodyFix extends JetIntentionAction { @Override public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException { JetFunction newElement = (JetFunction) element.copy(); - JetPsiFactory psiFactory = JetPsiFactory(project); + JetPsiFactory psiFactory = JetPsiFactory(file); if (!(newElement.getLastChild() instanceof PsiWhiteSpace)) { newElement.add(psiFactory.createWhiteSpace()); } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/AddNameToArgumentFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/AddNameToArgumentFix.java index 883e293a3ba..077b183f8eb 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/AddNameToArgumentFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/AddNameToArgumentFix.java @@ -145,7 +145,7 @@ public class AddNameToArgumentFix extends JetIntentionAction { private static JetValueArgument getParsedArgumentWithName(@NotNull String name, @NotNull JetValueArgument argument) { JetExpression argumentExpression = argument.getArgumentExpression(); assert argumentExpression != null : "Argument should be already parsed."; - return JetPsiFactory(argument.getProject()).createArgumentWithName(name, argumentExpression); + return JetPsiFactory(argument).createArgumentWithName(name, argumentExpression); } @NotNull diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/AddSemicolonAfterFunctionCallFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/AddSemicolonAfterFunctionCallFix.java index 06607cb9893..e8f373fe1f0 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/AddSemicolonAfterFunctionCallFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/AddSemicolonAfterFunctionCallFix.java @@ -61,7 +61,7 @@ public class AddSemicolonAfterFunctionCallFix extends JetIntentionAction PsiElement whenCloseBrace = element.getCloseBrace(); assert (whenCloseBrace != null) : "isAvailable should check if close brace exist"; - JetPsiFactory psiFactory = JetPsiFactory(project); + JetPsiFactory psiFactory = JetPsiFactory(file); JetWhenEntry entry = psiFactory.createWhenEntry(ELSE_ENTRY_TEXT); PsiElement insertedBranch = element.addBefore(entry, whenCloseBrace); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/CastExpressionFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/CastExpressionFix.java index 4ab567b60d2..4527300355b 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/CastExpressionFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/CastExpressionFix.java @@ -68,7 +68,7 @@ public class CastExpressionFix extends JetIntentionAction { @Override public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException { - JetPsiFactory psiFactory = JetPsiFactory(project); + JetPsiFactory psiFactory = JetPsiFactory(file); JetBinaryExpressionWithTypeRHS castedExpression = (JetBinaryExpressionWithTypeRHS) psiFactory.createExpression("(" + element.getText() + ") as " + renderedType); if (JetPsiUtil.areParenthesesUseless((JetParenthesizedExpression) castedExpression.getLeft())) { diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeAccessorTypeFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeAccessorTypeFix.java index 04c3eb8a4f4..d4b5716f1df 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeAccessorTypeFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeAccessorTypeFix.java @@ -67,7 +67,7 @@ public class ChangeAccessorTypeFix extends JetIntentionAction else { SpecifyTypeExplicitlyAction.removeTypeAnnotation(element); if (!(KotlinBuiltIns.getInstance().isUnit(type) && element.hasBlockBody())) { - addReturnTypeAnnotation(project, element, renderedType); + addReturnTypeAnnotation(element, renderedType); } } } - public static void addReturnTypeAnnotation(Project project, JetFunction function, String typeText) { + public static void addReturnTypeAnnotation(JetFunction function, String typeText) { PsiElement elementToPrecedeType = function.getValueParameterList(); if (elementToPrecedeType == null) elementToPrecedeType = function.getNameIdentifier(); assert elementToPrecedeType != null : "Return type of function without name can't mismatch anything"; @@ -123,7 +123,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction // if a function doesn't have a value parameter list, a syntax error is raised, and it should follow the function name elementToPrecedeType = elementToPrecedeType.getNextSibling(); } - JetPsiFactory psiFactory = JetPsiFactory(project); + JetPsiFactory psiFactory = JetPsiFactory(function); function.addAfter(psiFactory.createType(typeText), elementToPrecedeType); function.addAfter(psiFactory.createColon(), elementToPrecedeType); } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeParameterTypeFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeParameterTypeFix.java index 4a09e00849d..f03d00e322c 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeParameterTypeFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeParameterTypeFix.java @@ -67,6 +67,6 @@ public class ChangeParameterTypeFix extends JetIntentionAction { public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException { JetTypeReference typeReference = element.getTypeReference(); assert typeReference != null : "Parameter without type annotation cannot cause type mismatch"; - typeReference.replace(JetPsiFactory(project).createType(renderedType)); + typeReference.replace(JetPsiFactory(file).createType(renderedType)); } } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToBackingFieldFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToBackingFieldFix.java index 8704dba5fe1..8d03981d6f2 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToBackingFieldFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToBackingFieldFix.java @@ -46,7 +46,7 @@ public class ChangeToBackingFieldFix extends JetIntentionAction delegationSpecifiers = aClass.getDelegationSpecifiers(); assert delegationSpecifiers.size() == 1; JetDelegationSpecifier specifier = delegationSpecifiers.iterator().next(); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToFunctionInvocationFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToFunctionInvocationFix.java index d998096097c..e36aa569e39 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToFunctionInvocationFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToFunctionInvocationFix.java @@ -48,7 +48,7 @@ public class ChangeToFunctionInvocationFix extends JetIntentionAction { @Override public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException { - element.replace(JetPsiFactory(project).createType(renderedType)); + element.replace(JetPsiFactory(file).createType(renderedType)); } @NotNull diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeVariableMutabilityFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeVariableMutabilityFix.java index 26b291fefdf..fa7d8b8e766 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeVariableMutabilityFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeVariableMutabilityFix.java @@ -88,7 +88,7 @@ public class ChangeVariableMutabilityFix implements IntentionAction { public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { JetProperty property = getCorrespondingProperty(editor, (JetFile)file); assert property != null; - property.getValOrVarNode().getPsi().replace(JetPsiFactory(project).createValOrVarNode(isVar ? "val" : "var").getPsi()); + property.getValOrVarNode().getPsi().replace(JetPsiFactory(property).createValOrVarNode(isVar ? "val" : "var").getPsi()); } @Override diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeVariableTypeFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeVariableTypeFix.java index fafed03726d..fbfe1a6ac03 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeVariableTypeFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeVariableTypeFix.java @@ -83,7 +83,7 @@ public class ChangeVariableTypeFix extends JetIntentionAction "p$i: Any" }.makeString(", ") val returnTypeString = if (isUnit) "" else ": Any" - val psiFactory = JetPsiFactory(project) + val psiFactory = JetPsiFactory(currentFile) if (isExtension) { // create as extension function val ownerTypeString = selectedReceiverType.renderedType!! @@ -638,7 +637,7 @@ public class CreateFunctionFromUsageFix internal ( containingFile = ownerClass.getContainingJetFile() NavigationUtil.activateFileWithPsiElement(containingFile) - containingFileEditor = FileEditorManager.getInstance(project)!!.getSelectedTextEditor()!! + containingFileEditor = FileEditorManager.getInstance(currentFile.getProject())!!.getSelectedTextEditor()!! var classBody = ownerClass.getBody() if (classBody == null) { @@ -738,7 +737,7 @@ public class CreateFunctionFromUsageFix internal ( typeRefsToShorten: MutableList, parameterTypeExpressions: List, returnTypeExpression: TypeExpression?) { if (isExtension) { - val receiverTypeRef = JetPsiFactory(func.getProject()).createType(selectedReceiverType.theType.renderLong(typeParameterNameMap)) + val receiverTypeRef = JetPsiFactory(func).createType(selectedReceiverType.theType.renderLong(typeParameterNameMap)) replaceWithLongerName(receiverTypeRef, selectedReceiverType.theType) val funcReceiverTypeRef = func.getReceiverTypeRef() @@ -799,7 +798,7 @@ public class CreateFunctionFromUsageFix internal ( throw IncorrectOperationException("Failed to parse file template", e) } - val newBodyExpression = JetPsiFactory(func.getProject()).createFunctionBody(bodyText) + val newBodyExpression = JetPsiFactory(func).createFunctionBody(bodyText) func.getBodyExpression()!!.replace(newBodyExpression) } @@ -867,8 +866,7 @@ public class CreateFunctionFromUsageFix internal ( } private fun replaceWithLongerName(typeRef: JetTypeReference, theType: JetType) { - val project = typeRef.getProject() - val fullyQualifiedReceiverTypeRef = JetPsiFactory(project).createType(theType.renderLong(typeParameterNameMap)) + val fullyQualifiedReceiverTypeRef = JetPsiFactory(typeRef).createType(theType.renderLong(typeParameterNameMap)) typeRef.replace(fullyQualifiedReceiverTypeRef) } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/KotlinSuppressIntentionAction.kt b/idea/src/org/jetbrains/jet/plugin/quickfix/KotlinSuppressIntentionAction.kt index 8082fdbad05..42795e88fa1 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/KotlinSuppressIntentionAction.kt +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/KotlinSuppressIntentionAction.kt @@ -53,14 +53,13 @@ public class KotlinSuppressIntentionAction( } private fun suppressAtModifierListOwner(suppressAt: JetModifierListOwner, id: String) { - val project = suppressAt.getProject() val modifierList = suppressAt.getModifierList() - val psiFactory = JetPsiFactory(project) + val psiFactory = JetPsiFactory(suppressAt) if (modifierList == null) { // create a modifier list from scratch val newModifierList = psiFactory.createModifierList(suppressAnnotationText(id)) val replaced = JetPsiUtil.replaceModifierList(suppressAt, newModifierList) - val whiteSpace = project.createWhiteSpace(kind) + val whiteSpace = psiFactory.createWhiteSpace(kind) suppressAt.addAfter(whiteSpace, replaced) } else { @@ -69,7 +68,7 @@ public class KotlinSuppressIntentionAction( // no [suppress] annotation val newAnnotation = psiFactory.createAnnotation(suppressAnnotationText(id)) val addedAnnotation = modifierList.addBefore(newAnnotation, modifierList.getFirstChild()) - val whiteSpace = project.createWhiteSpace(kind) + val whiteSpace = psiFactory.createWhiteSpace(kind) modifierList.addAfter(whiteSpace, addedAnnotation) } else { @@ -94,12 +93,10 @@ public class KotlinSuppressIntentionAction( val suppressAt = caretBox.expression assert(suppressAt !is JetDeclaration, "Declarations should have been checked for above") - val project = suppressAt.getProject() - val parentheses = JetPsiPrecedences.getPrecedence(suppressAt) > JetPsiPrecedences.PRECEDENCE_OF_PREFIX_EXPRESSION val placeholderText = "PLACEHOLDER_ID" val inner = if (parentheses) "($placeholderText)" else placeholderText - val annotatedExpression = JetPsiFactory(project).createExpression(suppressAnnotationText(id) + "\n" + inner) + val annotatedExpression = JetPsiFactory(suppressAt).createExpression(suppressAnnotationText(id) + "\n" + inner) val copy = suppressAt.copy()!! @@ -112,11 +109,9 @@ public class KotlinSuppressIntentionAction( } private fun addArgumentToSuppressAnnotation(entry: JetAnnotationEntry, id: String) { - val project = entry.getProject() - // add new arguments to an existing entry val args = entry.getValueArgumentList() - val psiFactory = JetPsiFactory(project) + val psiFactory = JetPsiFactory(entry) val newArgList = psiFactory.createCallArguments("($id)") if (args == null) { // new argument list @@ -149,9 +144,9 @@ public class KotlinSuppressIntentionAction( } public class AnnotationHostKind(val kind: String, val name: String, val newLineNeeded: Boolean) -private fun Project.createWhiteSpace(kind: AnnotationHostKind): PsiElement { - val psiFactory = JetPsiFactory(this) - return if (kind.newLineNeeded) psiFactory.createNewLine() else psiFactory.createWhiteSpace() + +private fun JetPsiFactory.createWhiteSpace(kind: AnnotationHostKind): PsiElement { + return if (kind.newLineNeeded) createNewLine() else createWhiteSpace() } private class CaretBox( diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/MoveWhenElseBranchFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/MoveWhenElseBranchFix.java index 473806f3753..7977b0e8eaf 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/MoveWhenElseBranchFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/MoveWhenElseBranchFix.java @@ -73,7 +73,7 @@ public class MoveWhenElseBranchFix extends JetIntentionAction int cursorOffset = editor.getCaretModel().getOffset() - elseEntry.getTextOffset(); PsiElement insertedBranch = element.addAfter(elseEntry, lastEntry); - element.addAfter(JetPsiFactory(project).createNewLine(), lastEntry); + element.addAfter(JetPsiFactory(file).createNewLine(), lastEntry); element.deleteChildRange(elseEntry, elseEntry); JetWhenEntry insertedWhenEntry = (JetWhenEntry) CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(insertedBranch); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceCallFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceCallFix.java index 2134496a7c1..153116c16d8 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceCallFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceCallFix.java @@ -77,7 +77,7 @@ public class ReplaceCallFix implements IntentionAction { JetExpression selector = callExpression.getSelectorExpression(); if (selector != null) { - JetQualifiedExpression newElement = (JetQualifiedExpression) JetPsiFactory(project).createExpression( + JetQualifiedExpression newElement = (JetQualifiedExpression) JetPsiFactory(callExpression).createExpression( callExpression.getReceiverExpression().getText() + (toSafe ? "?." : ".") + selector.getText() ); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceInfixCallFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceInfixCallFix.java index 69784760aec..10f4f84fbf5 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceInfixCallFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceInfixCallFix.java @@ -54,7 +54,7 @@ public class ReplaceInfixCallFix extends JetIntentionAction assert left != null && right != null : "Preconditions checked by factory"; String newText = left.getText() + "?." + element.getOperationReference().getText() + "(" + right.getText() + ")"; - JetQualifiedExpression newElement = (JetQualifiedExpression) JetPsiFactory(project).createExpression(newText); + JetQualifiedExpression newElement = (JetQualifiedExpression) JetPsiFactory(file).createExpression(newText); element.replace(newElement); } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceOperationInBinaryExpressionFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceOperationInBinaryExpressionFix.java index 3873ffd4e07..7e99645517e 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceOperationInBinaryExpressionFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceOperationInBinaryExpressionFix.java @@ -44,7 +44,7 @@ public abstract class ReplaceOperationInBinaryExpressionFix { //TODO use ChangeFunctionReturnTypeFix.invoke when JetTypeCodeFragment.getType() is ready if (!KotlinBuiltIns.getInstance().getUnitType().toString().equals(returnTypeText)) - ChangeFunctionReturnTypeFix.addReturnTypeAnnotation(getProject(), function, returnTypeText); + ChangeFunctionReturnTypeFix.addReturnTypeAnnotation(function, returnTypeText); } } else diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/ExtractionData.kt b/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/ExtractionData.kt index 00fadc61bb7..1cba3fda403 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/ExtractionData.kt +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/ExtractionData.kt @@ -103,7 +103,7 @@ class ExtractionData( val originalStartOffset = originalElements.first?.let { e -> e.getTextRange()!!.getStartOffset() } - private val itFakeDeclaration by Delegates.lazy { JetPsiFactory(project).createParameter("it", "Any?") } + private val itFakeDeclaration by Delegates.lazy { JetPsiFactory(originalFile).createParameter("it", "Any?") } val refOffsetToDeclaration by Delegates.lazy { fun isExtractableIt(descriptor: DeclarationDescriptor, context: BindingContext): Boolean { diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/ExtractionDescriptor.kt b/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/ExtractionDescriptor.kt index d41364b6d25..41b3adefb11 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/ExtractionDescriptor.kt +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/ExtractionDescriptor.kt @@ -71,7 +71,7 @@ class RenameReplacement(override val parameter: Parameter): ParameterReplacement [suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")] override fun invoke(e: JetElement): JetElement { val thisExpr = e.getParent() as? JetThisExpression - return (thisExpr ?: e).replaced(JetPsiFactory(e.getProject()).createSimpleName(parameter.nameForRef)) + return (thisExpr ?: e).replaced(JetPsiFactory(e).createSimpleName(parameter.nameForRef)) } } @@ -81,8 +81,7 @@ class AddPrefixReplacement(override val parameter: Parameter): ParameterReplacem [suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")] override fun invoke(e: JetElement): JetElement { val selector = (e.getParent() as? JetCallExpression) ?: e - val newExpr = selector.replace( - JetPsiFactory(e.getProject()).createExpression("${parameter.nameForRef}.${selector.getText()}") + val newExpr = selector.replace(JetPsiFactory(e).createExpression("${parameter.nameForRef}.${selector.getText()}") ) as JetQualifiedExpression return with(newExpr.getSelectorExpression()!!) { if (this is JetCallExpression) getCalleeExpression()!! else this } diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/extractFunctionUtils.kt b/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/extractFunctionUtils.kt index fe0d1c973e6..481608a9502 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/extractFunctionUtils.kt +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/extractFunctionUtils.kt @@ -797,9 +797,7 @@ fun ExtractionDescriptor.generateFunction( inTempFile: Boolean = false, nameByOffset: MutableMap = HashMap() ): JetNamedFunction { - val project = extractionData.project - - val psiFactory = JetPsiFactory(project) + val psiFactory = JetPsiFactory(extractionData.originalFile) fun createFunction(): JetNamedFunction { return with(extractionData) { if (inTempFile) { diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/inline/KotlinInlineValHandler.java b/idea/src/org/jetbrains/jet/plugin/refactoring/inline/KotlinInlineValHandler.java index cc54c2e841d..34b96092af9 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/inline/KotlinInlineValHandler.java +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/inline/KotlinInlineValHandler.java @@ -271,7 +271,7 @@ public class KotlinInlineValHandler extends InlineActionHandler { } } - JetPsiFactory psiFactory = JetPsiFactory(containingFile.getProject()); + JetPsiFactory psiFactory = JetPsiFactory(containingFile); for (JetFunctionLiteralExpression functionLiteralExpression : functionsToAddParameters) { JetFunctionLiteral functionLiteral = functionLiteralExpression.getFunctionLiteral(); @@ -334,7 +334,7 @@ public class KotlinInlineValHandler extends InlineActionHandler { } } - JetPsiFactory psiFactory = JetPsiFactory(containingFile.getProject()); + JetPsiFactory psiFactory = JetPsiFactory(containingFile); for (JetCallExpression call : callsToAddArguments) { call.addAfter(psiFactory.createTypeArguments("<" + typeArguments + ">"), call.getCalleeExpression()); ShortenReferences.instance$.process(call.getTypeArgumentList()); @@ -379,11 +379,12 @@ public class KotlinInlineValHandler extends InlineActionHandler { @NotNull PsiElement referenceElement, @NotNull JetExpression newExpression ) { - if (referenceElement.getParent() instanceof JetSimpleNameStringTemplateEntry && + PsiElement parent = referenceElement.getParent(); + if (parent instanceof JetSimpleNameStringTemplateEntry && !(newExpression instanceof JetSimpleNameExpression)) { JetBlockStringTemplateEntry templateEntry = - (JetBlockStringTemplateEntry) referenceElement.getParent().replace( - JetPsiFactory(referenceElement.getProject()).createBlockStringTemplateEntry(newExpression)); + (JetBlockStringTemplateEntry) parent.replace( + JetPsiFactory((JetElement) parent).createBlockStringTemplateEntry(newExpression)); JetExpression expression = templateEntry.getExpression(); assert expression != null; return expression; diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/KotlinChangePropertyActions.java b/idea/src/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/KotlinChangePropertyActions.java index de55373c024..f8c89f18047 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/KotlinChangePropertyActions.java +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/KotlinChangePropertyActions.java @@ -26,9 +26,9 @@ public class KotlinChangePropertyActions { private KotlinChangePropertyActions() { } - public static void declareValueOrVariable(Project project, boolean isVariable, JetProperty property) { + public static void declareValueOrVariable(boolean isVariable, JetProperty property) { ASTNode node; - JetPsiFactory psiFactory = PsiPackage.JetPsiFactory(project); + JetPsiFactory psiFactory = PsiPackage.JetPsiFactory(property); if (isVariable) { node = psiFactory.createVarNode(); } diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/KotlinInplaceVariableIntroducer.java b/idea/src/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/KotlinInplaceVariableIntroducer.java index d19febc1fd7..bf81536a70b 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/KotlinInplaceVariableIntroducer.java +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/KotlinInplaceVariableIntroducer.java @@ -84,8 +84,7 @@ public class KotlinInplaceVariableIntroducer extends InplaceVariableIntroducer propertyRef = new Ref(); final ArrayList references = new ArrayList(); final Ref reference = new Ref(); - final Runnable introduceRunnable = introduceVariable(project, expression, suggestedNames, allReplaces, commonContainer, + final Runnable introduceRunnable = introduceVariable(expression, suggestedNames, allReplaces, commonContainer, commonParent, replaceOccurrence, propertyRef, references, reference, finalNoTypeInference, finalNeedParentheses, expressionType); final boolean finalReplaceOccurrence = replaceOccurrence; @@ -241,16 +241,18 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase { } } - private static Runnable introduceVariable(final @NotNull Project project, final JetExpression expression, - final String[] suggestedNames, - final List allReplaces, final PsiElement commonContainer, - final PsiElement commonParent, final boolean replaceOccurrence, - final Ref propertyRef, - final ArrayList references, - final Ref reference, - final boolean noTypeInference, - final boolean needParentheses, - final JetType expressionType) { + private static Runnable introduceVariable( + final JetExpression expression, + final String[] suggestedNames, + final List allReplaces, final PsiElement commonContainer, + final PsiElement commonParent, final boolean replaceOccurrence, + final Ref propertyRef, + final ArrayList references, + final Ref reference, + final boolean noTypeInference, + final boolean needParentheses, + final JetType expressionType + ) { return new Runnable() { @Override public void run() { @@ -272,7 +274,7 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase { else { variableText += expression.getText(); } - JetPsiFactory psiFactory = JetPsiFactory(project); + JetPsiFactory psiFactory = JetPsiFactory(expression); JetProperty property = psiFactory.createProperty(variableText); PsiElement anchor = calculateAnchor(commonParent, commonContainer, allReplaces); if (anchor == null) return; diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/jetRefactoringUtil.kt b/idea/src/org/jetbrains/jet/plugin/refactoring/jetRefactoringUtil.kt index 629dc695107..03da1dcba45 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/jetRefactoringUtil.kt +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/jetRefactoringUtil.kt @@ -71,10 +71,8 @@ import com.intellij.openapi.ui.popup.LightweightWindowEvent fun JetSimpleNameExpression.changeQualifiedName(fqName: FqName): JetElement { assert (!fqName.isRoot(), "Can't set empty FqName for element $this") - val project = getProject() - val shortName = fqName.shortName().asString() - val psiFactory = JetPsiFactory(project) + val psiFactory = JetPsiFactory(this) val fqNameBase = (getParent() as? JetCallExpression)?.let { parent -> val callCopy = parent.copy() as JetCallExpression callCopy.getCalleeExpression()!!.replace(psiFactory.createSimpleName(shortName)).getParent()!!.getText() @@ -143,7 +141,7 @@ public fun PsiElement.isInJavaSourceRoot(): Boolean = !JavaProjectRootsUtil.isOutsideJavaSourceRoot(getContainingFile()) public inline fun JetFile.createTempCopy(textTransform: (String) -> String): JetFile { - val tmpFile = JetPsiFactory(getProject()).createFile(getName(), textTransform(getText() ?: "")) + val tmpFile = JetPsiFactory(this).createFile(getName(), textTransform(getText() ?: "")) tmpFile.setOriginalFile(this) tmpFile.skipVisibilityCheck = skipVisibilityCheck return tmpFile diff --git a/idea/src/org/jetbrains/jet/plugin/references/JetSimpleNameReference.kt b/idea/src/org/jetbrains/jet/plugin/references/JetSimpleNameReference.kt index 6adea408fcd..f43858f1c6f 100644 --- a/idea/src/org/jetbrains/jet/plugin/references/JetSimpleNameReference.kt +++ b/idea/src/org/jetbrains/jet/plugin/references/JetSimpleNameReference.kt @@ -38,8 +38,7 @@ public class JetSimpleNameReference( public override fun handleElementRename(newElementName: String?): PsiElement? { if (newElementName == null) return null; - val project = expression.getProject() - val psiFactory = JetPsiFactory(project) + val psiFactory = JetPsiFactory(expression) val element = when (expression.getReferencedNameElementType()) { JetTokens.FIELD_IDENTIFIER -> psiFactory.createFieldIdentifier(newElementName) JetTokens.LABEL_IDENTIFIER -> psiFactory.createClassLabel(newElementName)