Rewrite JetPsiFactory to kotlin, make project a property
Instead of passing to every function All static methods are now member functions
This commit is contained in:
@@ -33,10 +33,7 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.Modality;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetClassBody;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
@@ -85,11 +82,12 @@ public class JetAddFunctionToClassifierAction implements QuestionAction {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
JetPsiFactory psiFactory = PsiPackage.JetPsiFactory(project);
|
||||
JetClassBody body = classifierDeclaration.getBody();
|
||||
if (body == null) {
|
||||
PsiElement whitespaceBefore = classifierDeclaration.add(JetPsiFactory.createWhiteSpace(project));
|
||||
body = (JetClassBody) classifierDeclaration.addAfter(JetPsiFactory.createEmptyClassBody(project), whitespaceBefore);
|
||||
classifierDeclaration.addAfter(JetPsiFactory.createNewLine(project), body);
|
||||
PsiElement whitespaceBefore = classifierDeclaration.add(psiFactory.createWhiteSpace());
|
||||
body = (JetClassBody) classifierDeclaration.addAfter(psiFactory.createEmptyClassBody(), whitespaceBefore);
|
||||
classifierDeclaration.addAfter(psiFactory.createNewLine(), body);
|
||||
}
|
||||
|
||||
String functionBody = "";
|
||||
@@ -100,7 +98,7 @@ public class JetAddFunctionToClassifierAction implements QuestionAction {
|
||||
functionBody = "{ throw UnsupportedOperationException() }";
|
||||
}
|
||||
}
|
||||
JetNamedFunction functionElement = JetPsiFactory.createFunction(project, signatureString + functionBody);
|
||||
JetNamedFunction functionElement = psiFactory.createFunction(signatureString + functionBody);
|
||||
PsiElement anchor = body.getRBrace();
|
||||
JetNamedFunction insertedFunctionElement = (JetNamedFunction) body.addBefore(functionElement, anchor);
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.psi.PsiPackage;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.plugin.codeInsight.CodeInsightUtils;
|
||||
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences;
|
||||
@@ -38,7 +39,6 @@ import org.jetbrains.jet.plugin.codeInsight.ShortenReferences;
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -126,6 +126,7 @@ public class JetChangeFunctionSignatureAction implements QuestionAction {
|
||||
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
|
||||
final JetPsiFactory psiFactory = PsiPackage.JetPsiFactory(project);
|
||||
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -137,17 +138,17 @@ public class JetChangeFunctionSignatureAction implements QuestionAction {
|
||||
|
||||
if (bodyExpression != null) {
|
||||
if (element.hasBlockBody()) {
|
||||
newElement = JetPsiFactory.createFunction(project, signatureString + "{}");
|
||||
newElement = psiFactory.createFunction(signatureString + "{}");
|
||||
}
|
||||
else {
|
||||
newElement = JetPsiFactory.createFunction(project, signatureString + "= \"dummy\"");
|
||||
newElement = psiFactory.createFunction(signatureString + "= \"dummy\"");
|
||||
}
|
||||
JetExpression newBodyExpression = newElement.getBodyExpression();
|
||||
assert newBodyExpression != null;
|
||||
newBodyExpression.replace(bodyExpression);
|
||||
}
|
||||
else {
|
||||
newElement = JetPsiFactory.createFunction(project, signatureString);
|
||||
newElement = psiFactory.createFunction(signatureString);
|
||||
}
|
||||
newElement = (JetNamedFunction) element.replace(newElement);
|
||||
ShortenReferences.instance$.process(newElement);
|
||||
|
||||
@@ -54,6 +54,7 @@ import org.jetbrains.jet.plugin.stubindex.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
import static org.jetbrains.jet.plugin.caches.JetFromJavaDescriptorHelper.getTopLevelFunctionFqNames;
|
||||
|
||||
/**
|
||||
@@ -243,7 +244,7 @@ public class JetShortNamesCache extends PsiShortNamesCache {
|
||||
}
|
||||
});
|
||||
for (FqName fqName : topLevelFunctionFqNames) {
|
||||
JetImportDirective importDirective = JetPsiFactory.createImportDirective(project, new ImportPath(fqName, false));
|
||||
JetImportDirective importDirective = JetPsiFactory(project).createImportDirective(new ImportPath(fqName, false));
|
||||
Collection<? extends DeclarationDescriptor> declarationDescriptors = new QualifiedExpressionResolver().analyseImportReference(
|
||||
importDirective, jetScope, new BindingTraceContext(), resolveSession.getModuleDescriptor());
|
||||
for (DeclarationDescriptor declarationDescriptor : declarationDescriptors) {
|
||||
|
||||
@@ -57,10 +57,8 @@ import com.intellij.openapi.diagnostic.Logger
|
||||
import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression
|
||||
import org.jetbrains.jet.lang.psi.JetUserType
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils
|
||||
import org.jetbrains.jet.plugin.imports.*
|
||||
import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getReceiverExpression
|
||||
import org.jetbrains.jet.utils.*
|
||||
|
||||
@@ -314,7 +312,7 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor<Refere
|
||||
private object LengthenReferences {
|
||||
|
||||
private fun createQualifiedExpression(project: Project, text: String): JetDotQualifiedExpression {
|
||||
val newExpression = JetPsiFactory.createExpression(project, text)
|
||||
val newExpression = JetPsiFactory(project).createExpression(text)
|
||||
LOG.assertTrue(newExpression is JetDotQualifiedExpression,
|
||||
"\"${newExpression.getText()}\" is ${newExpression.javaClass}," +
|
||||
"not ${javaClass<JetDotQualifiedExpression>().getSimpleName()}."
|
||||
@@ -335,7 +333,7 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor<Refere
|
||||
val typeReference = PsiTreeUtil.getParentOfType(expression, javaClass<JetTypeReference>())
|
||||
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.createType(project, "$prefixToInsert.${typeReference.getText()}"))
|
||||
typeReference!!.replace(JetPsiFactory(project).createType("$prefixToInsert.${typeReference.getText()}"))
|
||||
}
|
||||
else {
|
||||
expression.replace(createQualifiedExpression(project, fqName.asString()))
|
||||
|
||||
@@ -45,6 +45,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public abstract class OverrideImplementMethodsHandler implements LanguageCodeInsightActionHandler {
|
||||
|
||||
private static final DescriptorRenderer OVERRIDE_RENDERER = new DescriptorRendererBuilder()
|
||||
@@ -81,8 +83,9 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
JetClassBody body = classOrObject.getBody();
|
||||
if (body == null) {
|
||||
Project project = classOrObject.getProject();
|
||||
classOrObject.add(JetPsiFactory.createWhiteSpace(project));
|
||||
body = (JetClassBody) classOrObject.add(JetPsiFactory.createEmptyClassBody(project));
|
||||
JetPsiFactory psiFactory = JetPsiFactory(project);
|
||||
classOrObject.add(psiFactory.createWhiteSpace());
|
||||
body = (JetClassBody) classOrObject.add(psiFactory.createEmptyClassBody());
|
||||
}
|
||||
|
||||
PsiElement afterAnchor = findInsertAfterAnchor(editor, body);
|
||||
@@ -162,7 +165,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
else {
|
||||
body.append(initializer);
|
||||
}
|
||||
return JetPsiFactory.createProperty(project, OVERRIDE_RENDERER.render(newDescriptor) + body);
|
||||
return JetPsiFactory(project).createProperty(OVERRIDE_RENDERER.render(newDescriptor) + body);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -201,7 +204,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
boolean returnsNotUnit = returnType != null && !builtIns.getUnitType().equals(returnType);
|
||||
String body = "{" + (returnsNotUnit && !isAbstractFun ? "return " : "") + delegationBuilder.toString() + "}";
|
||||
|
||||
return JetPsiFactory.createFunction(project, OVERRIDE_RENDERER.render(newDescriptor) + body);
|
||||
return JetPsiFactory(project).createFunction(OVERRIDE_RENDERER.render(newDescriptor) + body);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -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.createType(userType.getProject(), text).getTypeElement()!!
|
||||
val newUserType = JetPsiFactory(userType.getProject()).createType(text).getTypeElement()!!
|
||||
userType.replace(newUserType)
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -37,8 +37,7 @@ import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.JetPsiFactory.createExpression;
|
||||
import static org.jetbrains.jet.lang.psi.JetPsiFactory.createNewLine;
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class MoveDeclarationsOutHelper {
|
||||
|
||||
@@ -53,7 +52,8 @@ public class MoveDeclarationsOutHelper {
|
||||
List<JetProperty> propertiesDeclarations = new ArrayList<JetProperty>();
|
||||
|
||||
// Dummy element to add new declarations at the beginning
|
||||
PsiElement dummyFirstStatement = container.addBefore(createExpression(project, "dummyStatement "), statements[0]);
|
||||
JetPsiFactory psiFactory = JetPsiFactory(project);
|
||||
PsiElement dummyFirstStatement = container.addBefore(psiFactory.createExpression("dummyStatement "), statements[0]);
|
||||
|
||||
try {
|
||||
SearchScope scope = new LocalSearchScope(container);
|
||||
@@ -66,14 +66,14 @@ public class MoveDeclarationsOutHelper {
|
||||
JetProperty declaration = createVariableDeclaration(property, generateDefaultInitializers);
|
||||
declaration = (JetProperty) container.addBefore(declaration, dummyFirstStatement);
|
||||
propertiesDeclarations.add(declaration);
|
||||
container.addAfter(createNewLine(project), declaration);
|
||||
container.addAfter(psiFactory.createNewLine(), declaration);
|
||||
|
||||
JetBinaryExpression assignment = createVariableAssignment(property);
|
||||
resultStatements.add(property.replace(assignment));
|
||||
}
|
||||
else {
|
||||
PsiElement newStatement = container.addBefore(statement, dummyFirstStatement);
|
||||
container.addAfter(createNewLine(project), newStatement);
|
||||
container.addAfter(psiFactory.createNewLine(), newStatement);
|
||||
container.deleteChildRange(statement, statement);
|
||||
}
|
||||
}
|
||||
@@ -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) createExpression(property.getProject(), propertyName + " = x");
|
||||
JetBinaryExpression assignment = (JetBinaryExpression) JetPsiFactory(property.getProject()).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.createProperty(property.getProject(), property.getName(), typeString, property.isVar(), initializer);
|
||||
return JetPsiFactory(property.getProject()).createProperty(property.getName(), typeString, property.isVar(), initializer);
|
||||
}
|
||||
|
||||
private static boolean needToDeclareOut(@NotNull PsiElement element, int lastStatementOffset, @NotNull SearchScope scope) {
|
||||
|
||||
+3
-2
@@ -26,11 +26,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetParenthesizedExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetPrefixExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.plugin.codeInsight.surroundWith.KotlinSurrounderUtils;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class KotlinNotSurrounder extends KotlinExpressionSurrounder {
|
||||
@Override
|
||||
public String getTemplateDescription() {
|
||||
@@ -46,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.createExpression(project, "!(a)");
|
||||
JetPrefixExpression prefixExpr = (JetPrefixExpression) JetPsiFactory(project).createExpression("!(a)");
|
||||
JetParenthesizedExpression parenthesizedExpression = (JetParenthesizedExpression) prefixExpr.getBaseExpression();
|
||||
assert parenthesizedExpression != null : "JetParenthesizedExpression should exists for " + prefixExpr.getText() + " expression";
|
||||
JetExpression expressionWithoutParentheses = parenthesizedExpression.getExpression();
|
||||
|
||||
+3
-2
@@ -25,7 +25,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetParenthesizedExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class KotlinParenthesesSurrounder extends KotlinExpressionSurrounder {
|
||||
@Override
|
||||
@@ -41,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.createExpression(project, "(a)");
|
||||
JetParenthesizedExpression parenthesizedExpression = (JetParenthesizedExpression) JetPsiFactory(project).createExpression("(a)");
|
||||
JetExpression expressionWithoutParentheses = parenthesizedExpression.getExpression();
|
||||
assert expressionWithoutParentheses != null : "JetExpression should exists for " + parenthesizedExpression.getText() + " expression";
|
||||
expressionWithoutParentheses.replace(expression);
|
||||
|
||||
+9
-2
@@ -22,9 +22,14 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.JetConstantExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetStringTemplateEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetStringTemplateExpression;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class KotlinStringTemplateSurrounder extends KotlinExpressionSurrounder {
|
||||
@Override
|
||||
public String getTemplateDescription() {
|
||||
@@ -39,7 +44,9 @@ public class KotlinStringTemplateSurrounder extends KotlinExpressionSurrounder {
|
||||
@Nullable
|
||||
@Override
|
||||
public TextRange surroundExpression(@NotNull Project project, @NotNull Editor editor, @NotNull JetExpression expression) {
|
||||
JetStringTemplateExpression stringTemplateExpression = (JetStringTemplateExpression)JetPsiFactory.createExpression(project, getCodeTemplate(expression));
|
||||
JetStringTemplateExpression stringTemplateExpression = (JetStringTemplateExpression) JetPsiFactory(project).createExpression(
|
||||
getCodeTemplate(expression)
|
||||
);
|
||||
JetStringTemplateEntry templateEntry = stringTemplateExpression.getEntries()[0];
|
||||
JetExpression innerExpression = templateEntry.getExpression();
|
||||
assert innerExpression != null : "JetExpression should exists for " + stringTemplateExpression.toString();
|
||||
|
||||
+7
-2
@@ -25,11 +25,16 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetWhenCondition;
|
||||
import org.jetbrains.jet.lang.psi.JetWhenEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetWhenExpression;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.plugin.codeInsight.surroundWith.KotlinSurrounderUtils;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class KotlinWhenSurrounder extends KotlinExpressionSurrounder {
|
||||
@Override
|
||||
public String getTemplateDescription() {
|
||||
@@ -44,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.createExpression(project, getCodeTemplate(expression));
|
||||
JetWhenExpression whenExpression = (JetWhenExpression) JetPsiFactory(project).createExpression(getCodeTemplate(expression));
|
||||
JetExpression subjectExpression = whenExpression.getSubjectExpression();
|
||||
assert subjectExpression != null : "JetExpression should exists for " + whenExpression.getText() + " expression";
|
||||
subjectExpression.replace(expression);
|
||||
|
||||
+5
-2
@@ -27,6 +27,8 @@ import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.plugin.codeInsight.surroundWith.KotlinSurrounderUtils;
|
||||
import org.jetbrains.jet.plugin.codeInsight.surroundWith.MoveDeclarationsOutHelper;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class KotlinFunctionLiteralSurrounder extends KotlinStatementsSurrounder {
|
||||
@Nullable
|
||||
@Override
|
||||
@@ -38,9 +40,10 @@ public class KotlinFunctionLiteralSurrounder extends KotlinStatementsSurrounder
|
||||
return null;
|
||||
}
|
||||
|
||||
JetCallExpression callExpression = (JetCallExpression) JetPsiFactory.createExpression(project, "run {\n}");
|
||||
JetPsiFactory psiFactory = JetPsiFactory(project);
|
||||
JetCallExpression callExpression = (JetCallExpression) psiFactory.createExpression("run {\n}");
|
||||
callExpression = (JetCallExpression) container.addAfter(callExpression, statements[statements.length - 1]);
|
||||
container.addBefore(JetPsiFactory.createWhiteSpace(project), callExpression);
|
||||
container.addBefore(psiFactory.createWhiteSpace(), callExpression);
|
||||
|
||||
JetFunctionLiteralExpression bodyExpression = (JetFunctionLiteralExpression) callExpression.getFunctionLiteralArguments().get(0);
|
||||
assert bodyExpression != null : "Body expression should exists for " + callExpression.getText();
|
||||
|
||||
+3
-2
@@ -27,10 +27,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetBlockExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetIfExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.plugin.codeInsight.surroundWith.KotlinSurrounderUtils;
|
||||
import org.jetbrains.jet.plugin.codeInsight.surroundWith.MoveDeclarationsOutHelper;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public abstract class KotlinIfSurrounderBase extends KotlinStatementsSurrounder {
|
||||
|
||||
@Nullable
|
||||
@@ -43,7 +44,7 @@ public abstract class KotlinIfSurrounderBase extends KotlinStatementsSurrounder
|
||||
return null;
|
||||
}
|
||||
|
||||
JetIfExpression ifExpression = (JetIfExpression) JetPsiFactory.createExpression(project, getCodeTemplate());
|
||||
JetIfExpression ifExpression = (JetIfExpression) JetPsiFactory(project).createExpression(getCodeTemplate());
|
||||
ifExpression = (JetIfExpression) container.addAfter(ifExpression, statements[statements.length - 1]);
|
||||
|
||||
// TODO move a comment for first statement
|
||||
|
||||
+7
-2
@@ -23,10 +23,15 @@ import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.JetBlockExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetTryExpression;
|
||||
import org.jetbrains.jet.plugin.codeInsight.surroundWith.KotlinSurrounderUtils;
|
||||
import org.jetbrains.jet.plugin.codeInsight.surroundWith.MoveDeclarationsOutHelper;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public abstract class KotlinTrySurrounderBase extends KotlinStatementsSurrounder {
|
||||
|
||||
@Nullable
|
||||
@@ -39,7 +44,7 @@ public abstract class KotlinTrySurrounderBase extends KotlinStatementsSurrounder
|
||||
return null;
|
||||
}
|
||||
|
||||
JetTryExpression tryExpression = (JetTryExpression) JetPsiFactory.createExpression(project, getCodeTemplate());
|
||||
JetTryExpression tryExpression = (JetTryExpression) JetPsiFactory(project).createExpression(getCodeTemplate());
|
||||
tryExpression = (JetTryExpression) container.addAfter(tryExpression, statements[statements.length - 1]);
|
||||
|
||||
// TODO move a comment for first statement
|
||||
|
||||
@@ -22,6 +22,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class KotlinUnwrappers {
|
||||
private KotlinUnwrappers() {
|
||||
}
|
||||
@@ -72,7 +74,7 @@ public class KotlinUnwrappers {
|
||||
@Override
|
||||
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
|
||||
JetIfExpression ifExpr = (JetIfExpression) element;
|
||||
context.replace(ifExpr, JetPsiFactory.createIf(ifExpr.getProject(), ifExpr.getCondition(), ifExpr.getThen(), null));
|
||||
context.replace(ifExpr, JetPsiFactory(ifExpr.getProject()).createIf(ifExpr.getCondition(), ifExpr.getThen(), null));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@ import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class JetExpressionMover extends AbstractJetUpDownMover {
|
||||
|
||||
private static final Predicate<JetElement> IS_CALL_EXPRESSION = new Predicate<JetElement>() {
|
||||
@@ -549,7 +551,7 @@ public class JetExpressionMover extends AbstractJetUpDownMover {
|
||||
PsiElement parent = element.getParent();
|
||||
assert parent != null;
|
||||
|
||||
parent.addAfter(JetPsiFactory.createComma(parent.getProject()), element);
|
||||
parent.addAfter(JetPsiFactory(parent.getProject()).createComma(), element);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-4
@@ -110,14 +110,15 @@ private fun addImportsToFile(newImportList: JetImportList?, tmpFile: JetFile) {
|
||||
if (newImportList != null) {
|
||||
val tmpFileImportList = tmpFile.getImportList()
|
||||
val packageDirective = tmpFile.getPackageDirective()
|
||||
val psiFactory = JetPsiFactory(tmpFile.getProject())
|
||||
if (tmpFileImportList == null) {
|
||||
tmpFile.addAfter(JetPsiFactory.createNewLine(tmpFile.getProject()), packageDirective)
|
||||
tmpFile.addAfter(psiFactory.createNewLine(), packageDirective)
|
||||
tmpFile.addAfter(newImportList, tmpFile.getPackageDirective())
|
||||
}
|
||||
else {
|
||||
tmpFileImportList.replace(newImportList)
|
||||
}
|
||||
tmpFile.addAfter(JetPsiFactory.createNewLine(tmpFile.getProject()), packageDirective)
|
||||
tmpFile.addAfter(psiFactory.createNewLine(), packageDirective)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +126,8 @@ private fun addDebugExpressionBeforeContextElement(codeFragment: JetCodeFragment
|
||||
val parent = contextElement.getParent()
|
||||
if (parent == null) return null
|
||||
|
||||
parent.addBefore(JetPsiFactory.createNewLine(contextElement.getProject()), contextElement)
|
||||
val psiFactory = JetPsiFactory(contextElement.getProject())
|
||||
parent.addBefore(psiFactory.createNewLine(), contextElement)
|
||||
|
||||
val debugExpression = codeFragment.getContentElement()
|
||||
if (debugExpression == null) return null
|
||||
@@ -133,7 +135,7 @@ private fun addDebugExpressionBeforeContextElement(codeFragment: JetCodeFragment
|
||||
val newDebugExpression = parent.addBefore(debugExpression, contextElement)
|
||||
if (newDebugExpression == null) return null
|
||||
|
||||
parent.addBefore(JetPsiFactory.createNewLine(contextElement.getProject()), contextElement)
|
||||
parent.addBefore(psiFactory.createNewLine(), contextElement)
|
||||
|
||||
return newDebugExpression as JetExpression
|
||||
}
|
||||
|
||||
@@ -16,17 +16,9 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.intentions
|
||||
|
||||
import org.jetbrains.jet.lang.psi.JetIfExpression
|
||||
import org.jetbrains.jet.lang.psi.JetWhileExpression
|
||||
import org.jetbrains.jet.lang.psi.JetForExpression
|
||||
import org.jetbrains.jet.lang.psi.JetDoWhileExpression
|
||||
import org.jetbrains.jet.lang.psi.JetExpressionImpl
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||
import org.jetbrains.jet.lang.psi.JetBlockExpression
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.lang.ASTNode
|
||||
import org.jetbrains.jet.JetNodeTypes
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
@@ -61,14 +53,15 @@ public class AddBracesIntention : JetSelfTargetingIntention<JetExpressionImpl>("
|
||||
if (element.getNextSibling()?.getText() == ";") {
|
||||
element.getNextSibling()!!.delete()
|
||||
}
|
||||
val newElement = bodyNode!!.getPsi()!!.replace(JetPsiFactory.createFunctionBody(element.getProject(), bodyNode.getText()))
|
||||
val psiFactory = JetPsiFactory(element.getProject())
|
||||
val newElement = bodyNode!!.getPsi()!!.replace(psiFactory.createFunctionBody(bodyNode.getText()))
|
||||
|
||||
//handles the case of the block statement being on a new line
|
||||
if (newElement.getPrevSibling() is PsiWhiteSpace) {
|
||||
newElement.getPrevSibling()!!.replace(JetPsiFactory.createWhiteSpace(element.getProject()))
|
||||
newElement.getPrevSibling()!!.replace(psiFactory.createWhiteSpace())
|
||||
} else {
|
||||
//handles the case of no space between condition and statement
|
||||
newElement.addBefore(JetPsiFactory.createWhiteSpace(element.getProject()), newElement.getFirstChild())
|
||||
newElement.addBefore(psiFactory.createWhiteSpace(), newElement.getFirstChild())
|
||||
}
|
||||
if (expressionKind == ExpressionKind.DOWHILE) {
|
||||
newElement.getNextSibling()?.delete()
|
||||
|
||||
@@ -61,6 +61,7 @@ public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention<Jet
|
||||
val condition = args[0]?.getArgumentExpression()
|
||||
val lambdas = element.getFunctionLiteralArguments()
|
||||
|
||||
val psiFactory = JetPsiFactory(element.getProject())
|
||||
val messageExpr =
|
||||
if (args.size == 2) {
|
||||
args[1]?.getArgumentExpression()
|
||||
@@ -69,7 +70,7 @@ public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention<Jet
|
||||
element.getFunctionLiteralArguments()[0]
|
||||
}
|
||||
else {
|
||||
JetPsiFactory.createExpression(element.getProject(), "\"Assertion failed\"")
|
||||
psiFactory.createExpression("\"Assertion failed\"")
|
||||
}
|
||||
|
||||
if (condition == null || messageExpr == null) return
|
||||
@@ -85,11 +86,11 @@ public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention<Jet
|
||||
"${messageExpr.getText()}"
|
||||
}
|
||||
|
||||
val assertTypeRef = JetPsiFactory.createType(element.getProject(), "java.lang.AssertionError")
|
||||
val assertTypeRef = psiFactory.createType("java.lang.AssertionError")
|
||||
ShortenReferences.process(assertTypeRef)
|
||||
|
||||
val text = "if (!true) { throw ${assertTypeRef.getText()}(${message}) }"
|
||||
val ifExpression = JetPsiFactory.createExpression(element.getProject(), text) as JetIfExpression
|
||||
val ifExpression = psiFactory.createExpression(text) as JetIfExpression
|
||||
|
||||
val ifCondition = ifExpression.getCondition() as JetPrefixExpression
|
||||
ifCondition.getBaseExpression()?.replace(condition)
|
||||
|
||||
@@ -71,7 +71,8 @@ public class ConvertIfWithThrowToAssertIntention :
|
||||
""
|
||||
}
|
||||
|
||||
val negatedCondition = JetPsiFactory.createExpression(element.getProject(), "!true") as JetPrefixExpression
|
||||
val psiFactory = JetPsiFactory(element.getProject())
|
||||
val negatedCondition = psiFactory.createExpression("!true") as JetPrefixExpression
|
||||
negatedCondition.getBaseExpression()!!.replace(condition)
|
||||
condition.replace(negatedCondition)
|
||||
|
||||
@@ -82,7 +83,7 @@ public class ConvertIfWithThrowToAssertIntention :
|
||||
}
|
||||
|
||||
val assertText = "kotlin.assert(${element.getCondition()?.getText()} $paramText)"
|
||||
val assertExpr = JetPsiFactory.createExpression(element.getProject(), assertText)
|
||||
val assertExpr = psiFactory.createExpression(assertText)
|
||||
|
||||
val newExpr = element.replace(assertExpr) as JetExpression
|
||||
ShortenReferences.process(newExpr)
|
||||
|
||||
+1
-3
@@ -20,11 +20,9 @@ import org.jetbrains.jet.lang.psi.JetBinaryExpression
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import org.jetbrains.jet.lang.psi.JetPrefixExpression
|
||||
import org.jetbrains.jet.lexer.JetTokens
|
||||
import com.intellij.psi.impl.source.tree.PsiErrorElementImpl
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||
import org.jetbrains.jet.lang.psi.JetParenthesizedExpression
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil
|
||||
import org.jetbrains.jet.lang.psi.JetExpression
|
||||
import java.util.LinkedList
|
||||
|
||||
|
||||
@@ -56,7 +54,7 @@ public class ConvertNegatedBooleanSequenceIntention : JetSelfTargetingIntention<
|
||||
"!(${bareExpressions.last()}", { negated, expression -> "$expression $operatorText $negated" }
|
||||
)
|
||||
|
||||
val newExpression = JetPsiFactory.createExpression(element.getProject(), "$negatedExpression)")
|
||||
val newExpression = JetPsiFactory(element.getProject()).createExpression("$negatedExpression)")
|
||||
|
||||
val insertedElement = element.replace(newExpression)
|
||||
val insertedElementParent = insertedElement.getParent() as? JetParenthesizedExpression ?: return
|
||||
|
||||
+1
-4
@@ -19,16 +19,13 @@ package org.jetbrains.jet.plugin.intentions
|
||||
import org.jetbrains.jet.lang.psi.JetParenthesizedExpression
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import org.jetbrains.jet.lang.psi.JetBinaryExpression
|
||||
import com.intellij.psi.util.PsiUtil
|
||||
import org.jetbrains.jet.lexer.JetTokens
|
||||
import org.jetbrains.jet.lang.psi.JetPrefixExpression
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||
import com.intellij.psi.impl.source.tree.PsiErrorElementImpl
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil
|
||||
import org.jetbrains.jet.lang.psi.JetExpression
|
||||
import org.jetbrains.jet.lang.psi.JetConstantExpression
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||
import java.util.ArrayList
|
||||
import java.util.LinkedList
|
||||
import org.jetbrains.jet.plugin.JetBundle
|
||||
|
||||
@@ -67,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.createExpression(element.getProject(), negatedExpression)
|
||||
val newExpression = JetPsiFactory(element.getProject()).createExpression(negatedExpression)
|
||||
element.replace(newExpression)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,15 +21,9 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.psi.JetBlockExpression
|
||||
import org.jetbrains.jet.plugin.JetBundle
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.lang.types.TypeUtils
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import org.jetbrains.jet.lexer.JetTokens
|
||||
import org.jetbrains.jet.lang.types.JetType
|
||||
|
||||
public class ConvertToBlockBodyAction : PsiElementBaseIntentionAction() {
|
||||
override fun getFamilyName(): String = JetBundle.message("convert.to.block.body.action.family.name")
|
||||
@@ -50,7 +44,7 @@ public class ConvertToBlockBodyAction : PsiElementBaseIntentionAction() {
|
||||
|
||||
val oldBodyText = body.getText()!!
|
||||
val newBodyText = if (needReturn) "return ${oldBodyText}" else oldBodyText
|
||||
return JetPsiFactory.createFunctionBody(project, newBodyText)
|
||||
return JetPsiFactory(project).createFunctionBody(newBodyText)
|
||||
}
|
||||
|
||||
if (declaration is JetNamedFunction) {
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ public class ConvertToConcatenatedStringIntention : JetSelfTargetingIntention<Je
|
||||
.makeString(separator = "+")
|
||||
.replaceAll("""$quote\+$quote""", "")
|
||||
|
||||
val replacement = JetPsiFactory.createExpression(element.getProject(), result)
|
||||
val replacement = JetPsiFactory(element.getProject()).createExpression(result)
|
||||
|
||||
element.replace(replacement)
|
||||
}
|
||||
|
||||
@@ -21,15 +21,10 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.psi.JetBlockExpression
|
||||
import org.jetbrains.jet.plugin.JetBundle
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.lang.types.TypeUtils
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import org.jetbrains.jet.lexer.JetTokens
|
||||
import org.jetbrains.jet.lang.types.JetType
|
||||
|
||||
public class ConvertToExpressionBodyAction : PsiElementBaseIntentionAction() {
|
||||
override fun getFamilyName(): String = JetBundle.message("convert.to.expression.body.action.family.name")
|
||||
@@ -51,7 +46,7 @@ public class ConvertToExpressionBodyAction : PsiElementBaseIntentionAction() {
|
||||
}
|
||||
|
||||
val body = declaration.getBodyExpression()!!
|
||||
declaration.addBefore(JetPsiFactory.createEQ(project), body)
|
||||
declaration.addBefore(JetPsiFactory(project).createEQ(), body)
|
||||
body.replace(value)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -62,6 +62,6 @@ public class ConvertToForEachFunctionCallIntention : JetSelfTargetingIntention<J
|
||||
else -> body.getText() ?: throw AssertionError("Body of ForExpression shouldn't be empty: expressionText = ${element.getText()}")
|
||||
})
|
||||
|
||||
element.replace(JetPsiFactory.createExpression(element.getProject(), "${buildReceiverText(element)}.forEach { $bodyText }"))
|
||||
element.replace(JetPsiFactory(element.getProject()).createExpression("${buildReceiverText(element)}.forEach { $bodyText }"))
|
||||
}
|
||||
}
|
||||
@@ -113,6 +113,6 @@ public class ConvertToForEachLoopIntention : JetSelfTargetingIntention<JetExpres
|
||||
|
||||
val functionLiteral = getFunctionLiteralArgument(element)!!
|
||||
|
||||
element.replace(JetPsiFactory.createExpression(element.getProject(), generateLoopText(receiver, functionLiteral)))
|
||||
element.replace(JetPsiFactory(element.getProject()).createExpression(generateLoopText(receiver, functionLiteral)))
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class ConvertToStringTemplateIntention : JetSelfTargetingIntention<JetBin
|
||||
|
||||
val rightStr = mkString(element.getRight(), false)
|
||||
val resultStr = fold(element.getLeft(), rightStr)
|
||||
val expr = JetPsiFactory.createExpression(element.getProject(), resultStr)
|
||||
val expr = JetPsiFactory(element.getProject()).createExpression(resultStr)
|
||||
|
||||
element.replace(expr)
|
||||
}
|
||||
|
||||
+1
-1
@@ -28,6 +28,6 @@ public class InsertCurlyBracesToTemplateIntention : JetSelfTargetingIntention<Je
|
||||
override fun applyTo(element: JetSimpleNameStringTemplateEntry, editor: Editor) {
|
||||
val expression = element.getExpression()
|
||||
if (expression == null) return
|
||||
element.replace(JetPsiFactory.createBlockStringTemplateEntry(element.getProject(), expression))
|
||||
element.replace(JetPsiFactory(element.getProject()).createBlockStringTemplateEntry(expression))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,10 +55,11 @@ public class InsertExplicitTypeArguments : JetSelfTargetingIntention<JetCallExpr
|
||||
val args = resolvedCall.getTypeArguments()
|
||||
val types = resolvedCall.getCandidateDescriptor().getTypeParameters()
|
||||
|
||||
val psiFactory = JetPsiFactory(element.getProject())
|
||||
val typeArgs = types.map {
|
||||
assert(args[it] != null, "there is a null in the type arguments to transform")
|
||||
val typeToCompute = DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(args[it]!!);
|
||||
val computedTypeRef = JetPsiFactory.createType(element.getProject(), typeToCompute)
|
||||
val computedTypeRef = psiFactory.createType(typeToCompute)
|
||||
ShortenReferences.process(computedTypeRef)
|
||||
computedTypeRef.getText()
|
||||
}.makeString(", ", "<", ">")
|
||||
@@ -67,7 +68,7 @@ public class InsertExplicitTypeArguments : JetSelfTargetingIntention<JetCallExpr
|
||||
if (name == null) return
|
||||
|
||||
val valueAndFunctionArguments = element.getText()?.substring(name.size) ?: throw AssertionError("InsertExplicitTypeArguments intention shouldn't be applicable for empty call expression")
|
||||
val expr = JetPsiFactory.createExpression(element.getProject(), "$name$typeArgs${valueAndFunctionArguments}")
|
||||
val expr = psiFactory.createExpression("$name$typeArgs${valueAndFunctionArguments}")
|
||||
element.replace(expr)
|
||||
}
|
||||
}
|
||||
@@ -30,9 +30,6 @@ import org.jetbrains.jet.lang.psi.JetPsiUtil
|
||||
import org.jetbrains.jet.lang.psi.JetParenthesizedExpression
|
||||
import org.jetbrains.jet.lexer.JetSingleValueToken
|
||||
import org.jetbrains.jet.lexer.JetKeywordToken
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.JetElement
|
||||
import org.jetbrains.jet.lang.psi.JetForExpression
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction
|
||||
import org.jetbrains.jet.lang.psi.JetBlockExpression
|
||||
|
||||
@@ -67,6 +64,8 @@ public class InvertIfConditionIntention : JetSelfTargetingIntention<JetIfExpress
|
||||
}
|
||||
|
||||
override fun applyTo(element: JetIfExpression, editor: Editor) {
|
||||
val psiFactory = JetPsiFactory(element.getProject())
|
||||
|
||||
fun isNegatableOperator(token: IElementType): Boolean {
|
||||
return token in array(JetTokens.EQEQ, JetTokens.EXCLEQ, JetTokens.EQEQEQ, JetTokens.EXCLEQEQEQ, JetTokens.IS_KEYWORD, JetTokens.NOT_IS, JetTokens.IN_KEYWORD, JetTokens.NOT_IN, JetTokens.LT, JetTokens.LTEQ, JetTokens.GT, JetTokens.GTEQ)
|
||||
}
|
||||
@@ -99,7 +98,7 @@ public class InvertIfConditionIntention : JetSelfTargetingIntention<JetIfExpress
|
||||
|
||||
fun negateExpressionText(element: JetExpression): String {
|
||||
val negatedParenthesizedExpressionText = "!(${element.getText()})"
|
||||
val possibleNewExpression = JetPsiFactory.createExpression(element.getProject(), negatedParenthesizedExpressionText) as JetUnaryExpression
|
||||
val possibleNewExpression = psiFactory.createExpression(negatedParenthesizedExpressionText) as JetUnaryExpression
|
||||
val innerExpression = possibleNewExpression.getBaseExpression() as JetParenthesizedExpression
|
||||
|
||||
return when {
|
||||
@@ -109,7 +108,7 @@ public class InvertIfConditionIntention : JetSelfTargetingIntention<JetIfExpress
|
||||
}
|
||||
|
||||
fun getNegation(element: JetExpression): JetExpression {
|
||||
return JetPsiFactory.createExpression(element.getProject(), when (element) {
|
||||
return psiFactory.createExpression(when (element) {
|
||||
is JetBinaryExpression -> {
|
||||
val operator = element.getOperationToken()!!
|
||||
|
||||
@@ -159,10 +158,10 @@ public class InvertIfConditionIntention : JetSelfTargetingIntention<JetIfExpress
|
||||
}
|
||||
|
||||
val thenBranch = element.getThen()
|
||||
val elseBranch = element.getElse() ?: JetPsiFactory.createEmptyBody(element.getProject())
|
||||
val elseBranch = element.getElse() ?: psiFactory.createEmptyBody()
|
||||
|
||||
element.replace(JetPsiFactory.createIf(element.getProject(), replacementCondition, when (elseBranch) {
|
||||
is JetIfExpression -> JetPsiFactory.wrapInABlock(elseBranch)
|
||||
element.replace(psiFactory.createIf(replacementCondition, when (elseBranch) {
|
||||
is JetIfExpression -> psiFactory.wrapInABlock(elseBranch)
|
||||
else -> elseBranch
|
||||
}, if (thenBranch is JetBlockExpression && thenBranch.getStatements().isEmpty()) null else thenBranch))
|
||||
}
|
||||
|
||||
@@ -63,7 +63,8 @@ public class MakeTypeExplicitInLambdaIntention : JetSelfTargetingIntention<JetFu
|
||||
val parameterString = valueParameters.map({descriptor -> "" + descriptor.getName() +
|
||||
": " + DescriptorRenderer.SOURCE_CODE.renderType(descriptor.getType())
|
||||
}).makeString(", ", "(", ")")
|
||||
val newParameterList = JetPsiFactory.createParameterList(element.getProject(), parameterString)
|
||||
val psiFactory = JetPsiFactory(element.getProject())
|
||||
val newParameterList = psiFactory.createParameterList(parameterString)
|
||||
val oldParameterList = functionLiteral.getValueParameterList()
|
||||
if (oldParameterList != null) {
|
||||
oldParameterList.replace(newParameterList)
|
||||
@@ -72,11 +73,11 @@ public class MakeTypeExplicitInLambdaIntention : JetSelfTargetingIntention<JetFu
|
||||
val openBraceElement = functionLiteral.getOpenBraceNode().getPsi()
|
||||
val nextSibling = openBraceElement?.getNextSibling()
|
||||
val addNewline = nextSibling is PsiWhiteSpace && nextSibling.getText()?.contains("\n") ?: false
|
||||
val (whitespace, arrow) = JetPsiFactory.createWhitespaceAndArrow(element.getProject())
|
||||
val (whitespace, arrow) = psiFactory.createWhitespaceAndArrow()
|
||||
functionLiteral.addRangeAfter(whitespace, arrow, openBraceElement)
|
||||
functionLiteral.addAfter(newParameterList, openBraceElement)
|
||||
if (addNewline) {
|
||||
functionLiteral.addAfter(JetPsiFactory.createNewLine(element.getProject()), openBraceElement)
|
||||
functionLiteral.addAfter(psiFactory.createNewLine(), openBraceElement)
|
||||
}
|
||||
}
|
||||
ShortenReferences.process(element.getValueParameters())
|
||||
@@ -85,8 +86,8 @@ public class MakeTypeExplicitInLambdaIntention : JetSelfTargetingIntention<JetFu
|
||||
val expectedReturnType = func.getReturnType()
|
||||
if (hasImplicitReturnType(element) && expectedReturnType != null) {
|
||||
val paramList = functionLiteral.getValueParameterList()
|
||||
val returnTypeColon = JetPsiFactory.createColon(element.getProject())
|
||||
val returnTypeExpr = JetPsiFactory.createType(element.getProject(), DescriptorRenderer.SOURCE_CODE.renderType(expectedReturnType))
|
||||
val returnTypeColon = psiFactory.createColon()
|
||||
val returnTypeExpr = psiFactory.createType(DescriptorRenderer.SOURCE_CODE.renderType(expectedReturnType))
|
||||
ShortenReferences.process(returnTypeExpr)
|
||||
functionLiteral.addAfter(returnTypeExpr, paramList)
|
||||
functionLiteral.addAfter(returnTypeColon, paramList)
|
||||
@@ -97,7 +98,7 @@ public class MakeTypeExplicitInLambdaIntention : JetSelfTargetingIntention<JetFu
|
||||
if (hasImplicitReceiverType(element) && expectedReceiverType != null) {
|
||||
val receiverTypeString = DescriptorRenderer.SOURCE_CODE.renderType(expectedReceiverType)
|
||||
val paramListString = functionLiteral.getValueParameterList()?.getText()
|
||||
val paramListWithReceiver = JetPsiFactory.createExpression(element.getProject(), receiverTypeString + "." + paramListString)
|
||||
val paramListWithReceiver = psiFactory.createExpression(receiverTypeString + "." + paramListString)
|
||||
ShortenReferences.process(paramListWithReceiver)
|
||||
functionLiteral.getValueParameterList()?.replace(paramListWithReceiver)
|
||||
}
|
||||
|
||||
@@ -42,12 +42,13 @@ public class MakeTypeImplicitInLambdaIntention : JetSelfTargetingIntention<JetFu
|
||||
val functionLiteral = element.getFunctionLiteral()
|
||||
val oldParameterList = functionLiteral.getValueParameterList()
|
||||
|
||||
val psiFactory = JetPsiFactory(element.getProject())
|
||||
if (hasExplicitReturnType(element)) {
|
||||
val childAfterParamList = oldParameterList?.getNextSibling()
|
||||
val arrow = functionLiteral.getArrowNode()?.getPsi()
|
||||
val childBeforeArrow = arrow?.getPrevSibling()
|
||||
functionLiteral.deleteChildRange(childAfterParamList, childBeforeArrow)
|
||||
val whiteSpaceBeforeArrow = JetPsiFactory.createWhiteSpace(element.getProject())
|
||||
val whiteSpaceBeforeArrow = psiFactory.createWhiteSpace()
|
||||
functionLiteral.addBefore(whiteSpaceBeforeArrow, arrow)
|
||||
}
|
||||
|
||||
@@ -61,7 +62,7 @@ public class MakeTypeImplicitInLambdaIntention : JetSelfTargetingIntention<JetFu
|
||||
val parameterString = oldParameterList!!.getParameters().map({ parameter ->
|
||||
parameter.getNameIdentifier()!!.getText()
|
||||
}).makeString(", ", "(", ")")
|
||||
val newParameterList = JetPsiFactory.createParameterList(element.getProject(), parameterString)
|
||||
val newParameterList = psiFactory.createParameterList(parameterString)
|
||||
oldParameterList.replace(newParameterList)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -49,6 +49,6 @@ public class MoveLambdaInsideParenthesesIntention : JetSelfTargetingIntention<Je
|
||||
sb.append("$literalName = ")
|
||||
}
|
||||
val newExpression = "$funName${sb.toString()}${element.getFunctionLiteralArguments()[0].getText()})"
|
||||
element.replace(JetPsiFactory.createExpression(element.getProject(),newExpression))
|
||||
element.replace(JetPsiFactory(element.getProject()).createExpression(newExpression))
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -49,6 +49,6 @@ public class MoveLambdaOutsideParenthesesIntention : JetSelfTargetingIntention<J
|
||||
} else {
|
||||
"$calleeText$params $functionLiteral"
|
||||
}
|
||||
element.replace(JetPsiFactory.createExpression(element.getProject(), newCall))
|
||||
element.replace(JetPsiFactory(element.getProject()).createExpression(newCall))
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
|
||||
}
|
||||
|
||||
val transformation = "$base.$call"
|
||||
val transformed = JetPsiFactory.createExpression(element.getProject(), transformation)
|
||||
val transformed = JetPsiFactory(element.getProject()).createExpression(transformation)
|
||||
element.replace(transformed)
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
|
||||
}
|
||||
|
||||
val transformation = "$base.$call"
|
||||
val transformed = JetPsiFactory.createExpression(element.getProject(), transformation)
|
||||
val transformed = JetPsiFactory(element.getProject()).createExpression(transformation)
|
||||
element.replace(transformed)
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
|
||||
else -> return
|
||||
}
|
||||
|
||||
val transformed = JetPsiFactory.createExpression(element.getProject(), transformation)
|
||||
val transformed = JetPsiFactory(element.getProject()).createExpression(transformation)
|
||||
|
||||
element.replace(transformed)
|
||||
}
|
||||
@@ -177,7 +177,7 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
|
||||
replaced = element
|
||||
}
|
||||
|
||||
val transformed = JetPsiFactory.createExpression(element.getProject(), transformation)
|
||||
val transformed = JetPsiFactory(element.getProject()).createExpression(transformation)
|
||||
replaced.replace(transformed)
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
|
||||
val funcLitArgs = element.getFunctionLiteralArguments()
|
||||
val calleeText = callee.getText()
|
||||
val transformation = if (argumentString == null) "$calleeText.invoke" else "$calleeText.invoke($argumentString)"
|
||||
val transformed = JetPsiFactory.createExpression(element.getProject(), transformation)
|
||||
val transformed = JetPsiFactory(element.getProject()).createExpression(transformation)
|
||||
funcLitArgs.forEach { transformed.add(it) }
|
||||
callee.getParent()!!.replace(transformed)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.jetbrains.jet.plugin.codeInsight.ShortenReferences;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
import java.util.Collections;
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class ReconstructTypeInCastOrIsAction extends PsiElementBaseIntentionAction {
|
||||
@NotNull
|
||||
@@ -45,7 +45,7 @@ public class ReconstructTypeInCastOrIsAction extends PsiElementBaseIntentionActi
|
||||
assert typeRef != null : "Must be checked by isAvailable(): " + element;
|
||||
|
||||
JetType type = getReconstructedType(typeRef);
|
||||
JetTypeReference newType = JetPsiFactory.createType(project, DescriptorRenderer.SOURCE_CODE.renderType(type));
|
||||
JetTypeReference newType = JetPsiFactory(project).createType(DescriptorRenderer.SOURCE_CODE.renderType(type));
|
||||
JetTypeReference replaced = (JetTypeReference) typeRef.replace(newType);
|
||||
ShortenReferences.instance$.process(replaced);
|
||||
}
|
||||
|
||||
@@ -18,19 +18,10 @@ package org.jetbrains.jet.plugin.intentions
|
||||
|
||||
import org.jetbrains.jet.lang.psi.JetBlockExpression
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||
import org.jetbrains.jet.lang.psi.JetWhileExpression
|
||||
import org.jetbrains.jet.lang.psi.JetIfExpression
|
||||
import org.jetbrains.jet.lang.psi.JetDoWhileExpression
|
||||
import org.jetbrains.jet.lang.psi.JetForExpression
|
||||
import org.jetbrains.jet.lang.psi.JetExpressionImpl
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
import com.intellij.psi.PsiComment
|
||||
import org.jetbrains.jet.lang.psi.JetExpression
|
||||
import org.jetbrains.jet.plugin.intentions.declarations.JetDeclarationJoinLinesHandler
|
||||
import org.jetbrains.jet.lang.psi.JetProperty
|
||||
|
||||
public class RemoveBracesIntention : JetSelfTargetingIntention<JetExpressionImpl>("remove.braces", javaClass()) {
|
||||
override fun isApplicableTo(element: JetExpressionImpl): Boolean {
|
||||
@@ -63,7 +54,7 @@ public class RemoveBracesIntention : JetSelfTargetingIntention<JetExpressionImpl
|
||||
val newElement = jetBlockElement.replace(firstStatement.copy())
|
||||
|
||||
if (expressionKind == ExpressionKind.DOWHILE) {
|
||||
newElement.getParent()!!.addAfter(JetPsiFactory.createNewLine(project), newElement)
|
||||
newElement.getParent()!!.addAfter(JetPsiFactory(project).createNewLine(), newElement)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,10 +65,10 @@ public class RemoveBracesIntention : JetSelfTargetingIntention<JetExpressionImpl
|
||||
if (sibling is PsiComment) {
|
||||
//cleans up extra whitespace
|
||||
if (element.getPrevSibling() is PsiWhiteSpace) {
|
||||
element.getPrevSibling()!!.replace(JetPsiFactory.createNewLine(element.getProject()))
|
||||
element.getPrevSibling()!!.replace(JetPsiFactory(element.getProject()).createNewLine())
|
||||
}
|
||||
val commentElement = element.getParent()!!.addBefore(sibling as PsiComment, element.getPrevSibling())
|
||||
element.getParent()!!.addBefore(JetPsiFactory.createNewLine(element.getProject()), commentElement)
|
||||
element.getParent()!!.addBefore(JetPsiFactory(element.getProject()).createNewLine(), commentElement)
|
||||
}
|
||||
sibling = sibling!!.getNextSibling()
|
||||
}
|
||||
|
||||
+1
-1
@@ -46,6 +46,6 @@ public class RemoveCurlyBracesFromTemplateIntention : JetSelfTargetingIntention<
|
||||
val tripleQuotes = parent.getFirstChild()?.getText()?.startsWith("\"\"\"")
|
||||
if (tripleQuotes == null) return
|
||||
val newExpression = if (tripleQuotes) "\"\"\"${sb.toString()}\"\"\"" else "\"${sb.toString()}\""
|
||||
parent.replace(JetPsiFactory.createExpression(element.getProject(), newExpression))
|
||||
parent.replace(JetPsiFactory(element.getProject()).createExpression(newExpression))
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -30,7 +30,6 @@ import org.jetbrains.jet.plugin.JetBundle
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils
|
||||
import org.jetbrains.jet.lang.psi.JetFunctionLiteral
|
||||
import org.jetbrains.jet.plugin.references.JetReference
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils
|
||||
@@ -44,7 +43,7 @@ public class ReplaceItWithExplicitFunctionLiteralParamIntention() : PsiElementBa
|
||||
|
||||
val funcExpr = DescriptorToSourceUtils.descriptorToDeclaration(target.getContainingDeclaration()!!) as JetFunctionLiteral
|
||||
|
||||
val newExpr = JetPsiFactory.createExpression(project, "{ it -> 42 }") as JetFunctionLiteralExpression
|
||||
val newExpr = JetPsiFactory(project).createExpression("{ it -> 42 }") as JetFunctionLiteralExpression
|
||||
funcExpr.addRangeAfter(newExpr.getFunctionLiteral().getValueParameterList(),
|
||||
newExpr.getFunctionLiteral().getArrowNode()!!.getPsi(),
|
||||
funcExpr.getOpenBraceNode().getPsi())
|
||||
|
||||
+1
-5
@@ -17,15 +17,11 @@
|
||||
package org.jetbrains.jet.plugin.intentions
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.jet.lang.psi.JetBinaryExpression
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||
import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression
|
||||
import org.jetbrains.jet.lang.psi.JetParenthesizedExpression
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions
|
||||
import com.google.common.collect.ImmutableSet
|
||||
import org.jetbrains.jet.lexer.JetTokens
|
||||
import org.jetbrains.jet.lexer.JetToken
|
||||
|
||||
public class ReplaceWithDotQualifiedMethodCallIntention : JetSelfTargetingIntention<JetBinaryExpression>("replace.with.dot.qualified.method.call.intention", javaClass()) {
|
||||
override fun isApplicableTo(element: JetBinaryExpression): Boolean {
|
||||
@@ -46,7 +42,7 @@ public class ReplaceWithDotQualifiedMethodCallIntention : JetSelfTargetingIntent
|
||||
}
|
||||
)
|
||||
|
||||
val replacement = JetPsiFactory.createExpression(element.getProject(), replacementExpressionStringBuilder.toString())
|
||||
val replacement = JetPsiFactory(element.getProject()).createExpression(replacementExpressionStringBuilder.toString())
|
||||
element.replace(replacement)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -109,7 +109,7 @@ public open class ReplaceWithInfixFunctionCallIntention : JetSelfTargetingIntent
|
||||
functionLiteralArguments.first().getText()
|
||||
)
|
||||
|
||||
val replacement = JetPsiFactory.createExpression(element.getProject(), "$leftHandText $operatorText ${rightHandTextStringBuilder.toString()}")
|
||||
val replacement = JetPsiFactory(element.getProject()).createExpression("$leftHandText $operatorText ${rightHandTextStringBuilder.toString()}")
|
||||
|
||||
parent.replace(replacement)
|
||||
}
|
||||
|
||||
@@ -111,6 +111,6 @@ public class ReplaceWithOperatorAssignIntention : JetSelfTargetingIntention<JetB
|
||||
}
|
||||
}
|
||||
|
||||
element.replace(JetPsiFactory.createExpression(element.getProject(), buildReplacement(element.getLeft() as JetSimpleNameExpression, element.getRight() as JetBinaryExpression, StringBuilder())))
|
||||
element.replace(JetPsiFactory(element.getProject()).createExpression(buildReplacement(element.getLeft() as JetSimpleNameExpression, element.getRight() as JetBinaryExpression, StringBuilder())))
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -53,6 +53,6 @@ public class ReplaceWithTraditionalAssignmentIntention : JetSelfTargetingIntenti
|
||||
return replacementStringBuilder.toString()
|
||||
}
|
||||
|
||||
element.replace(JetPsiFactory.createExpression(element.getProject(), buildReplacement(element)))
|
||||
element.replace(JetPsiFactory(element.getProject()).createExpression(buildReplacement(element)))
|
||||
}
|
||||
}
|
||||
+8
-6
@@ -67,10 +67,11 @@ public class SimplifyBooleanWithConstantsIntention : JetSelfTargetingIntention<J
|
||||
}
|
||||
|
||||
private fun simplifyBoolean(element: JetExpression) : JetExpression {
|
||||
val psiFactory = JetPsiFactory(element.getProject())
|
||||
if (element.canBeReducedToTrue())
|
||||
return JetPsiFactory.createExpression(element.getProject(), "true")
|
||||
return psiFactory.createExpression("true")
|
||||
if (element.canBeReducedToFalse())
|
||||
return JetPsiFactory.createExpression(element.getProject(), "false")
|
||||
return psiFactory.createExpression("false")
|
||||
when (element) {
|
||||
is JetParenthesizedExpression -> {
|
||||
val expr = element.getExpression()
|
||||
@@ -81,7 +82,7 @@ public class SimplifyBooleanWithConstantsIntention : JetSelfTargetingIntention<J
|
||||
val simpText = simplified.getText()
|
||||
if (simpText == null) return element
|
||||
// wrap in new parentheses to keep the user's original format
|
||||
return JetPsiFactory.createExpression(element.getProject(), "($simpText)")
|
||||
return psiFactory.createExpression("($simpText)")
|
||||
}
|
||||
// if we now have a simpleName, constant, or parenthesized we don't need parentheses
|
||||
return simplified
|
||||
@@ -102,7 +103,7 @@ public class SimplifyBooleanWithConstantsIntention : JetSelfTargetingIntention<J
|
||||
|
||||
val opText = element.getOperationReference().getText()
|
||||
if (opText == null) return element
|
||||
return JetPsiFactory.createBinaryExpression(element.getProject(), simpleLeft, opText, simpleRight)
|
||||
return psiFactory.createBinaryExpression(simpleLeft, opText, simpleRight)
|
||||
}
|
||||
else -> return element
|
||||
}
|
||||
@@ -114,10 +115,11 @@ public class SimplifyBooleanWithConstantsIntention : JetSelfTargetingIntention<J
|
||||
operation: IElementType
|
||||
): JetExpression {
|
||||
assert(booleanConstantOperand.canBeReducedToBooleanConstant(null), "should only be called when we know it can be reduced")
|
||||
val psiFactory = JetPsiFactory(otherOperand.getProject())
|
||||
if (booleanConstantOperand.canBeReducedToTrue() && operation == JetTokens.OROR)
|
||||
return JetPsiFactory.createExpression(otherOperand.getProject(), "true")
|
||||
return psiFactory.createExpression("true")
|
||||
if (booleanConstantOperand.canBeReducedToFalse() && operation == JetTokens.ANDAND)
|
||||
return JetPsiFactory.createExpression(otherOperand.getProject(), "false")
|
||||
return psiFactory.createExpression("false")
|
||||
return simplifyBoolean(otherOperand)
|
||||
}
|
||||
|
||||
|
||||
+7
-6
@@ -74,14 +74,15 @@ public class SimplifyNegatedBinaryExpressionIntention : JetSelfTargetingIntentio
|
||||
val expression = element.unparenthesize()!!
|
||||
val invertedOperation = JetPsiUtil.getOperationToken(expression as JetOperationExpression)!!.negate()!!
|
||||
|
||||
val psiFactory = JetPsiFactory(expression.getProject())
|
||||
element.replace(
|
||||
when (expression) {
|
||||
is JetIsExpression -> JetPsiFactory.createExpression(
|
||||
expression.getProject(),
|
||||
"${expression.getLeftHandSide().getText() ?: ""} ${invertedOperation.getValue()} ${expression.getTypeRef()?.getText() ?: ""}"
|
||||
)
|
||||
is JetBinaryExpression -> JetPsiFactory.createBinaryExpression(
|
||||
expression.getProject(),
|
||||
is JetIsExpression -> {
|
||||
psiFactory.createExpression(
|
||||
"${expression.getLeftHandSide().getText() ?: ""} ${invertedOperation.getValue()} ${expression.getTypeRef()?.getText() ?: ""}"
|
||||
)
|
||||
}
|
||||
is JetBinaryExpression -> psiFactory.createBinaryExpression(
|
||||
expression.getLeft(),
|
||||
invertedOperation.getValue(),
|
||||
expression.getRight()
|
||||
|
||||
@@ -264,8 +264,9 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
|
||||
}
|
||||
|
||||
private static void addTypeAnnotationSilently(Project project, JetNamedDeclaration namedDeclaration, PsiElement anchor) {
|
||||
namedDeclaration.addAfter(JetPsiFactory.createType(project, "Any"), anchor);
|
||||
namedDeclaration.addAfter(JetPsiFactory.createColon(project), anchor);
|
||||
JetPsiFactory psiFactory = PsiPackage.JetPsiFactory(project);
|
||||
namedDeclaration.addAfter(psiFactory.createType("Any"), anchor);
|
||||
namedDeclaration.addAfter(psiFactory.createColon(), anchor);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -59,14 +59,19 @@ public class SplitIfIntention : JetSelfTargetingIntention<JetExpression>("split.
|
||||
val elseExpression = ifExpression.getElse()
|
||||
val thenExpression = ifExpression.getThen()
|
||||
|
||||
val psiFactory = JetPsiFactory(element.getProject())
|
||||
if (currentElement.getReferencedNameElementType() == JetTokens.ANDAND) {
|
||||
ifExpression.replace(JetPsiFactory.createIf(element.getProject(), leftExpression,
|
||||
JetPsiFactory.wrapInABlock(JetPsiFactory.createIf(element.getProject(), rightExpression, thenExpression,
|
||||
elseExpression)), elseExpression))
|
||||
ifExpression.replace(
|
||||
psiFactory.createIf(leftExpression, psiFactory.wrapInABlock(
|
||||
psiFactory.createIf(rightExpression, thenExpression, elseExpression)
|
||||
),
|
||||
elseExpression)
|
||||
)
|
||||
}
|
||||
else {
|
||||
ifExpression.replace(JetPsiFactory.createIf(element.getProject(), leftExpression, thenExpression,
|
||||
JetPsiFactory.createIf(element.getProject(), rightExpression, thenExpression, elseExpression)))
|
||||
ifExpression.replace(psiFactory.createIf(leftExpression, thenExpression,
|
||||
psiFactory.createIf(rightExpression, thenExpression, elseExpression))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +80,7 @@ public class SplitIfIntention : JetSelfTargetingIntention<JetExpression>("split.
|
||||
val startOffset = element.getRight()!!.getTextOffset() - condition.getTextOffset()
|
||||
val rightString = condition.getText()!![startOffset, condition.getTextLength()].toString()
|
||||
|
||||
return JetPsiFactory.createExpression(element.getProject(), rightString)
|
||||
return JetPsiFactory(element.getProject()).createExpression(rightString)
|
||||
}
|
||||
|
||||
fun isCursorOnIfKeyword(element: JetIfExpression, editor: Editor): Boolean {
|
||||
|
||||
@@ -61,11 +61,12 @@ public class SwapBinaryExpression : JetSelfTargetingIntention<JetBinaryExpressio
|
||||
}
|
||||
val left = leftSubject(element)!!
|
||||
val right = rightSubject(element)!!
|
||||
val newRight = JetPsiFactory.createExpression(element.getProject(), left.getText())
|
||||
val newLeft = JetPsiFactory.createExpression(element.getProject(), right.getText())
|
||||
val psiFactory = JetPsiFactory(element.getProject())
|
||||
val newRight = psiFactory.createExpression(left.getText()!!)
|
||||
val newLeft = psiFactory.createExpression(right.getText()!!)
|
||||
left.replace(newLeft)
|
||||
right.replace(newRight)
|
||||
element.replace(JetPsiFactory.createBinaryExpression(element.getProject(), element.getLeft(), convertedOperator, element.getRight()))
|
||||
element.replace(psiFactory.createBinaryExpression(element.getLeft(), convertedOperator, element.getRight()))
|
||||
}
|
||||
|
||||
private fun leftSubject(element: JetBinaryExpression): JetExpression? {
|
||||
|
||||
@@ -27,12 +27,12 @@ import org.jetbrains.jet.lexer.JetTokens
|
||||
import org.jetbrains.jet.plugin.caches.resolve.getLazyResolveSession
|
||||
|
||||
fun specifyTypeExplicitly(declaration: JetNamedFunction, typeText: String) {
|
||||
specifyTypeExplicitly(declaration, JetPsiFactory.createType(declaration.getProject(), typeText))
|
||||
specifyTypeExplicitly(declaration, JetPsiFactory(declaration.getProject()).createType(typeText))
|
||||
}
|
||||
|
||||
fun specifyTypeExplicitly(declaration: JetNamedFunction, `type`: JetType) {
|
||||
if (`type`.isError()) return
|
||||
val typeReference = JetPsiFactory.createType(declaration.getProject(), DescriptorRenderer.SOURCE_CODE.renderType(`type`))
|
||||
val typeReference = JetPsiFactory(declaration.getProject()).createType(DescriptorRenderer.SOURCE_CODE.renderType(`type`))
|
||||
specifyTypeExplicitly(declaration, typeReference)
|
||||
ShortenReferences.process(declaration.getReturnTypeRef()!!)
|
||||
}
|
||||
@@ -41,7 +41,7 @@ fun specifyTypeExplicitly(declaration: JetNamedFunction, typeReference: JetTypeR
|
||||
val project = declaration.getProject()
|
||||
val anchor = declaration.getValueParameterList() ?: return/*incomplete declaration*/
|
||||
declaration.addAfter(typeReference, anchor)
|
||||
declaration.addAfter(JetPsiFactory.createColon(project), anchor)
|
||||
declaration.addAfter(JetPsiFactory(project).createColon(), anchor)
|
||||
}
|
||||
|
||||
fun expressionType(expression: JetExpression): JetType? {
|
||||
|
||||
+1
-2
@@ -50,8 +50,7 @@ public open class ReplaceBinaryInfixIntention : AttributeCallReplacementIntentio
|
||||
val argument = (handleErrors(editor, call.getPositionalArguments()) ?: return)[0].getArgumentExpression()
|
||||
|
||||
call.element.replace(
|
||||
JetPsiFactory.createBinaryExpression(
|
||||
call.element.getProject(),
|
||||
JetPsiFactory(call.element.getProject()).createBinaryExpression(
|
||||
call.element.getReceiverExpression(),
|
||||
lookup(call.functionName)!!, // Lookup must succeed
|
||||
argument
|
||||
|
||||
+3
-3
@@ -42,6 +42,7 @@ public open class ReplaceContainsIntention : AttributeCallReplacementIntention("
|
||||
val argument = (handleErrors(editor, call.getPositionalArguments()) ?: return)[0].getArgumentExpression()
|
||||
|
||||
// Append semicolon to previous statement if needed
|
||||
val psiFactory = JetPsiFactory(call.element.getProject())
|
||||
if (argument is JetFunctionLiteralExpression) {
|
||||
val previousElement = JetPsiUtil.skipSiblingsBackwardByPredicate(call.element) {
|
||||
// I checked, it can't be null.
|
||||
@@ -49,12 +50,11 @@ public open class ReplaceContainsIntention : AttributeCallReplacementIntention("
|
||||
}
|
||||
if (previousElement != null && previousElement is JetExpression) {
|
||||
// If the parent is null, something is very wrong.
|
||||
previousElement.getParent()!!.addAfter(JetPsiFactory.createSemicolon(call.element.getProject()), previousElement)
|
||||
previousElement.getParent()!!.addAfter(psiFactory.createSemicolon(), previousElement)
|
||||
}
|
||||
}
|
||||
|
||||
call.element.replace(JetPsiFactory.createBinaryExpression(
|
||||
call.element.getProject(),
|
||||
call.element.replace(psiFactory.createBinaryExpression(
|
||||
argument,
|
||||
"in",
|
||||
call.element.getReceiverExpression()
|
||||
|
||||
+1
-2
@@ -29,8 +29,7 @@ public open class ReplaceGetIntention : AttributeCallReplacementIntention("repla
|
||||
it.getArgumentExpression()?.getText() ?: ""
|
||||
}.makeString(", ")
|
||||
|
||||
call.element.replace(JetPsiFactory.createExpression(
|
||||
call.element.getProject(),
|
||||
call.element.replace(JetPsiFactory(call.element.getProject()).createExpression(
|
||||
"${call.element.getReceiverExpression().getText()}[${argumentString}]"
|
||||
))
|
||||
}
|
||||
|
||||
+1
-2
@@ -26,8 +26,7 @@ public open class ReplaceInvokeIntention : AttributeCallReplacementIntention("re
|
||||
}
|
||||
|
||||
override fun replaceCall(call: CallDescription, editor: Editor) {
|
||||
call.element.replace(JetPsiFactory.createExpression(
|
||||
call.element.getProject(),
|
||||
call.element.replace(JetPsiFactory(call.element.getProject()).createExpression(
|
||||
call.element.getReceiverExpression().getText() +
|
||||
(call.callElement.getTypeArgumentList()?.getText() ?: "") +
|
||||
(call.callElement.getValueArgumentList()?.getText() ?: "") +
|
||||
|
||||
+1
-2
@@ -44,8 +44,7 @@ public open class ReplaceUnaryPrefixIntention : AttributeCallReplacementIntentio
|
||||
}
|
||||
|
||||
override fun replaceCall(call: CallDescription, editor: Editor) {
|
||||
call.element.replace(JetPsiFactory.createExpression(
|
||||
call.element.getProject(),
|
||||
call.element.replace(JetPsiFactory(call.element.getProject()).createExpression(
|
||||
lookup(call.functionName)!! + call.element.getReceiverExpression().getText()
|
||||
))
|
||||
}
|
||||
|
||||
+9
-6
@@ -25,6 +25,8 @@ import org.jetbrains.jet.lang.psi.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class BranchedFoldingUtils {
|
||||
private BranchedFoldingUtils() {
|
||||
}
|
||||
@@ -173,7 +175,7 @@ public class BranchedFoldingUtils {
|
||||
String op = thenAssignment.getOperationReference().getText();
|
||||
JetSimpleNameExpression lhs = (JetSimpleNameExpression) thenAssignment.getLeft();
|
||||
|
||||
JetBinaryExpression assignment = JetPsiFactory.createBinaryExpression(project, lhs, op, ifExpression);
|
||||
JetBinaryExpression assignment = JetPsiFactory(project).createBinaryExpression(lhs, op, ifExpression);
|
||||
JetIfExpression newIfExpression = (JetIfExpression)assignment.getRight();
|
||||
|
||||
assertNotNull(newIfExpression);
|
||||
@@ -202,7 +204,7 @@ public class BranchedFoldingUtils {
|
||||
public static void foldIfExpressionWithReturns(JetIfExpression ifExpression) {
|
||||
Project project = ifExpression.getProject();
|
||||
|
||||
JetReturnExpression newReturnExpression = JetPsiFactory.createReturn(project, ifExpression);
|
||||
JetReturnExpression newReturnExpression = JetPsiFactory(project).createReturn(ifExpression);
|
||||
JetIfExpression newIfExpression = (JetIfExpression)newReturnExpression.getReturnedExpression();
|
||||
|
||||
assertNotNull(newIfExpression);
|
||||
@@ -240,8 +242,9 @@ public class BranchedFoldingUtils {
|
||||
assertNotNull(elseRoot);
|
||||
|
||||
//noinspection ConstantConditions
|
||||
JetIfExpression newIfExpression = JetPsiFactory.createIf(project, condition, thenRoot, elseRoot);
|
||||
JetReturnExpression newReturnExpression = JetPsiFactory.createReturn(project, newIfExpression);
|
||||
JetPsiFactory psiFactory = JetPsiFactory(project);
|
||||
JetIfExpression newIfExpression = psiFactory.createIf(condition, thenRoot, elseRoot);
|
||||
JetReturnExpression newReturnExpression = psiFactory.createReturn(newIfExpression);
|
||||
|
||||
newIfExpression = (JetIfExpression)newReturnExpression.getReturnedExpression();
|
||||
|
||||
@@ -282,7 +285,7 @@ public class BranchedFoldingUtils {
|
||||
String op = firstAssignment.getOperationReference().getText();
|
||||
JetSimpleNameExpression lhs = (JetSimpleNameExpression) firstAssignment.getLeft();
|
||||
|
||||
JetBinaryExpression assignment = JetPsiFactory.createBinaryExpression(project, lhs, op, whenExpression);
|
||||
JetBinaryExpression assignment = JetPsiFactory(project).createBinaryExpression(lhs, op, whenExpression);
|
||||
JetWhenExpression newWhenExpression = (JetWhenExpression)assignment.getRight();
|
||||
|
||||
assertNotNull(newWhenExpression);
|
||||
@@ -307,7 +310,7 @@ public class BranchedFoldingUtils {
|
||||
|
||||
assert !whenExpression.getEntries().isEmpty() : FOLD_WITHOUT_CHECK;
|
||||
|
||||
JetReturnExpression newReturnExpression = JetPsiFactory.createReturn(project, whenExpression);
|
||||
JetReturnExpression newReturnExpression = JetPsiFactory(project).createReturn(whenExpression);
|
||||
JetWhenExpression newWhenExpression = (JetWhenExpression)newReturnExpression.getReturnedExpression();
|
||||
|
||||
assertNotNull(newWhenExpression);
|
||||
|
||||
+10
-6
@@ -24,6 +24,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.plugin.intentions.declarations.DeclarationUtils;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class BranchedUnfoldingUtils {
|
||||
private BranchedUnfoldingUtils() {
|
||||
}
|
||||
@@ -94,8 +96,9 @@ public class BranchedUnfoldingUtils {
|
||||
assertNotNull(elseExpr);
|
||||
|
||||
//noinspection ConstantConditions
|
||||
thenExpr.replace(JetPsiFactory.createBinaryExpression(project, lhs, op, thenExpr));
|
||||
elseExpr.replace(JetPsiFactory.createBinaryExpression(project, lhs, op, elseExpr));
|
||||
JetPsiFactory psiFactory = JetPsiFactory(project);
|
||||
thenExpr.replace(psiFactory.createBinaryExpression(lhs, op, thenExpr));
|
||||
elseExpr.replace(psiFactory.createBinaryExpression(lhs, op, elseExpr));
|
||||
|
||||
PsiElement resultElement = assignment.replace(newIfExpression);
|
||||
|
||||
@@ -119,7 +122,7 @@ public class BranchedUnfoldingUtils {
|
||||
assertNotNull(currExpr);
|
||||
|
||||
//noinspection ConstantConditions
|
||||
currExpr.replace(JetPsiFactory.createBinaryExpression(project, lhs, op, currExpr));
|
||||
currExpr.replace(JetPsiFactory(project).createBinaryExpression(lhs, op, currExpr));
|
||||
}
|
||||
|
||||
PsiElement resultElement = assignment.replace(newWhenExpression);
|
||||
@@ -152,8 +155,9 @@ public class BranchedUnfoldingUtils {
|
||||
assertNotNull(thenExpr);
|
||||
assertNotNull(elseExpr);
|
||||
|
||||
thenExpr.replace(JetPsiFactory.createReturn(project, thenExpr));
|
||||
elseExpr.replace(JetPsiFactory.createReturn(project, elseExpr));
|
||||
JetPsiFactory psiFactory = JetPsiFactory(project);
|
||||
thenExpr.replace(psiFactory.createReturn(thenExpr));
|
||||
elseExpr.replace(psiFactory.createReturn(elseExpr));
|
||||
|
||||
returnExpression.replace(newIfExpression);
|
||||
}
|
||||
@@ -172,7 +176,7 @@ public class BranchedUnfoldingUtils {
|
||||
|
||||
assertNotNull(currExpr);
|
||||
|
||||
currExpr.replace(JetPsiFactory.createReturn(project, currExpr));
|
||||
currExpr.replace(JetPsiFactory(project).createReturn(currExpr));
|
||||
}
|
||||
|
||||
returnExpression.replace(newWhenExpression);
|
||||
|
||||
@@ -121,12 +121,12 @@ fun JetExpression.evaluatesTo(other: JetExpression): Boolean {
|
||||
}
|
||||
|
||||
fun JetExpression.convertToIfNotNullExpression(conditionLhs: JetExpression, thenClause: JetExpression, elseClause: JetExpression?): JetIfExpression {
|
||||
val condition = JetPsiFactory.createExpression(this.getProject(), "${conditionLhs.getText()} != null")
|
||||
val condition = JetPsiFactory(this.getProject()).createExpression("${conditionLhs.getText()} != null")
|
||||
return this.convertToIfStatement(condition, thenClause, elseClause)
|
||||
}
|
||||
|
||||
fun JetExpression.convertToIfNullExpression(conditionLhs: JetExpression, thenClause: JetExpression): JetIfExpression {
|
||||
val condition = JetPsiFactory.createExpression(this.getProject(), "${conditionLhs.getText()} == null")
|
||||
val condition = JetPsiFactory(this.getProject()).createExpression("${conditionLhs.getText()} == null")
|
||||
return this.convertToIfStatement(condition, thenClause, null)
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ fun JetIfExpression.introduceValueForCondition(occurrenceInThenClause: JetExpres
|
||||
}
|
||||
|
||||
fun PsiElement.replace(expressionAsString: String): PsiElement =
|
||||
this.replace(JetPsiFactory.createExpression(this.getProject(), expressionAsString))
|
||||
this.replace(JetPsiFactory(this.getProject()).createExpression(expressionAsString))
|
||||
|
||||
fun JetSimpleNameExpression.inlineIfDeclaredLocallyAndOnlyUsedOnceWithPrompt(editor: Editor) {
|
||||
val declaration = this.getReference()?.resolve() as JetDeclaration
|
||||
|
||||
+11
-13
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.intentions.branchedTransformations
|
||||
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import org.jetbrains.jet.lexer.JetTokens
|
||||
import org.jetbrains.jet.plugin.util.JetPsiMatcher
|
||||
@@ -27,7 +26,6 @@ import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
import java.util.Collections
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import org.jetbrains.jet.utils.*
|
||||
|
||||
public val TRANSFORM_WITHOUT_CHECK: String = "Expression must be checked before applying transformation"
|
||||
|
||||
@@ -141,7 +139,7 @@ public fun JetWhenExpression.flatten(): JetWhenExpression {
|
||||
|
||||
val outerEntries = getEntries()
|
||||
val innerEntries = nestedWhenExpression.getEntries()
|
||||
val builder = JetPsiFactory.WhenBuilder(subjectExpression)
|
||||
val builder = JetPsiFactory(getProject()).WhenBuilder(subjectExpression)
|
||||
for (entry in outerEntries) {
|
||||
if (entry.isElse())
|
||||
continue
|
||||
@@ -152,13 +150,13 @@ public fun JetWhenExpression.flatten(): JetWhenExpression {
|
||||
builder.entry(entry)
|
||||
}
|
||||
|
||||
return replaced(builder.toExpression(getProject()))
|
||||
return replaced(builder.toExpression())
|
||||
}
|
||||
|
||||
public fun JetWhenExpression.introduceSubject(): JetWhenExpression {
|
||||
val subject = getSubjectCandidate()!!
|
||||
|
||||
val builder = JetPsiFactory.WhenBuilder(subject)
|
||||
val builder = JetPsiFactory(getProject()).WhenBuilder(subject)
|
||||
for (entry in getEntries()) {
|
||||
val branchExpression = entry.getExpression()
|
||||
if (entry.isElse()) {
|
||||
@@ -199,13 +197,13 @@ public fun JetWhenExpression.introduceSubject(): JetWhenExpression {
|
||||
builder.branchExpression(branchExpression)
|
||||
}
|
||||
|
||||
return replaced(builder.toExpression(getProject()))
|
||||
return replaced(builder.toExpression())
|
||||
}
|
||||
|
||||
public fun JetWhenExpression.eliminateSubject(): JetWhenExpression {
|
||||
val subject = getSubjectExpression()!!
|
||||
|
||||
val builder = JetPsiFactory.WhenBuilder()
|
||||
val builder = JetPsiFactory(getProject()).WhenBuilder()
|
||||
for (entry in getEntries()) {
|
||||
val branchExpression = entry.getExpression()
|
||||
|
||||
@@ -220,7 +218,7 @@ public fun JetWhenExpression.eliminateSubject(): JetWhenExpression {
|
||||
builder.branchExpression(branchExpression)
|
||||
}
|
||||
|
||||
return replaced(builder.toExpression(getProject()))
|
||||
return replaced(builder.toExpression())
|
||||
}
|
||||
|
||||
public fun JetIfExpression.canTransformToWhen(): Boolean = getThen() != null
|
||||
@@ -266,7 +264,7 @@ public fun JetIfExpression.transformToWhen() {
|
||||
override fun hasNext(): Boolean = expression != null
|
||||
}
|
||||
|
||||
val builder = JetPsiFactory.WhenBuilder()
|
||||
val builder = JetPsiFactory(getProject()).WhenBuilder()
|
||||
branchIterator(this).forEach { ifExpression ->
|
||||
ifExpression.getCondition()?.let { condition ->
|
||||
val orBranches = condition.splitToOrBranches()
|
||||
@@ -287,7 +285,7 @@ public fun JetIfExpression.transformToWhen() {
|
||||
}
|
||||
}
|
||||
|
||||
val whenExpression = builder.toExpression(getProject()).let { whenExpression ->
|
||||
val whenExpression = builder.toExpression().let { whenExpression ->
|
||||
if (whenExpression.canIntroduceSubject()) whenExpression.introduceSubject() else whenExpression
|
||||
}
|
||||
replace(whenExpression)
|
||||
@@ -306,7 +304,7 @@ public fun JetWhenExpression.transformToIf() {
|
||||
}
|
||||
}
|
||||
|
||||
val builder = JetPsiFactory.IfChainBuilder()
|
||||
val builder = JetPsiFactory(getProject()).IfChainBuilder()
|
||||
|
||||
for (entry in getEntries()) {
|
||||
val branch = entry.getExpression()
|
||||
@@ -319,7 +317,7 @@ public fun JetWhenExpression.transformToIf() {
|
||||
}
|
||||
}
|
||||
|
||||
replace(builder.toExpression(getProject()))
|
||||
replace(builder.toExpression())
|
||||
}
|
||||
|
||||
public fun JetWhenExpression.canMergeWithNext(): Boolean {
|
||||
@@ -367,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.createNewLine(getProject()), expression)
|
||||
block.addBefore(JetPsiFactory(getProject()).createNewLine(), expression)
|
||||
}
|
||||
block
|
||||
}
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ public class DoubleBangToIfThenIntention : JetSelfTargetingIntention<JetPostfixE
|
||||
val base = checkNotNull(JetPsiUtil.deparenthesize(element.getBaseExpression()), "Base expression cannot be null")
|
||||
val expressionText = formatForUseInExceptionArgument(base.getText()!!)
|
||||
|
||||
val defaultException = JetPsiFactory.createExpression(project, "throw $NULL_PTR_EXCEPTION()")
|
||||
val defaultException = JetPsiFactory(project).createExpression("throw $NULL_PTR_EXCEPTION()")
|
||||
|
||||
val isStatement = element.isStatement()
|
||||
val isStable = base.isStableVariable()
|
||||
|
||||
+3
-2
@@ -39,9 +39,10 @@ public class SafeAccessToIfThenIntention : JetSelfTargetingIntention<JetSafeQual
|
||||
|
||||
val receiverTemplate = if (receiver is JetBinaryExpression) "(%s)" else "%s"
|
||||
val receiverAsString = receiverTemplate.format(receiver.getText())
|
||||
val dotQualifiedExpression = JetPsiFactory.createExpression(element.getProject(), "${receiverAsString}.${selector!!.getText()}")
|
||||
val psiFactory = JetPsiFactory(element.getProject())
|
||||
val dotQualifiedExpression = psiFactory.createExpression("${receiverAsString}.${selector!!.getText()}")
|
||||
|
||||
val elseClause = if (element.isStatement()) null else JetPsiFactory.createExpression(element.getProject(), "null")
|
||||
val elseClause = if (element.isStatement()) null else psiFactory.createExpression("null")
|
||||
val ifExpression = element.convertToIfNotNullExpression(receiver, dotQualifiedExpression, elseClause)
|
||||
|
||||
if (!receiverIsStable) {
|
||||
|
||||
+5
-4
@@ -114,11 +114,12 @@ public class ConvertMemberToExtension extends BaseIntentionAction {
|
||||
(returnTypeRef != null ? ": " + returnTypeRef.getText() : "") +
|
||||
body(member);
|
||||
|
||||
JetDeclaration extension = JetPsiFactory.createDeclaration(project, extensionText, JetDeclaration.class);
|
||||
JetPsiFactory psiFactory = PsiPackage.JetPsiFactory(project);
|
||||
JetDeclaration extension = psiFactory.<JetDeclaration>createDeclaration(extensionText);
|
||||
|
||||
PsiElement added = file.addAfter(extension, outermostParent);
|
||||
file.addAfter(JetPsiFactory.createNewLine(project), outermostParent);
|
||||
file.addAfter(JetPsiFactory.createNewLine(project), outermostParent);
|
||||
file.addAfter(psiFactory.createNewLine(), outermostParent);
|
||||
file.addAfter(psiFactory.createNewLine(), outermostParent);
|
||||
member.delete();
|
||||
|
||||
CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(added);
|
||||
@@ -128,7 +129,7 @@ public class ConvertMemberToExtension extends BaseIntentionAction {
|
||||
int caretOffset = added.getTextRange().getStartOffset() + caretAnchor;
|
||||
JetSimpleNameExpression anchor = PsiTreeUtil.findElementOfClassAtOffset(file, caretOffset, JetSimpleNameExpression.class, false);
|
||||
if (anchor != null && CARET_ANCHOR.equals(anchor.getReferencedName())) {
|
||||
JetExpression throwException = JetPsiFactory.createExpression(project, THROW_UNSUPPORTED_OPERATION_EXCEPTION);
|
||||
JetExpression throwException = psiFactory.createExpression(THROW_UNSUPPORTED_OPERATION_EXCEPTION);
|
||||
PsiElement replaced = anchor.replace(throwException);
|
||||
TextRange range = replaced.getTextRange();
|
||||
editor.getCaretModel().moveToOffset(range.getStartOffset());
|
||||
|
||||
@@ -33,6 +33,8 @@ import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.plugin.util.JetPsiMatcher;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class DeclarationUtils {
|
||||
private DeclarationUtils() {
|
||||
}
|
||||
@@ -103,13 +105,14 @@ public class DeclarationUtils {
|
||||
JetExpression initializer = property.getInitializer();
|
||||
assertNotNull(initializer);
|
||||
|
||||
JetPsiFactory psiFactory = JetPsiFactory(project);
|
||||
//noinspection ConstantConditions, unchecked
|
||||
JetBinaryExpression newInitializer = JetPsiFactory.createBinaryExpression(
|
||||
project, JetPsiFactory.createSimpleName(project, property.getName()), "=", initializer
|
||||
JetBinaryExpression newInitializer = psiFactory.createBinaryExpression(
|
||||
psiFactory.createSimpleName(property.getName()), "=", initializer
|
||||
);
|
||||
|
||||
newInitializer = (JetBinaryExpression) parent.addAfter(newInitializer, property);
|
||||
parent.addAfter(JetPsiFactory.createNewLine(project), property);
|
||||
parent.addAfter(psiFactory.createNewLine(), property);
|
||||
|
||||
//noinspection ConstantConditions
|
||||
JetType inferredType = getPropertyTypeIfNeeded(property);
|
||||
@@ -120,7 +123,7 @@ public class DeclarationUtils {
|
||||
|
||||
//noinspection ConstantConditions
|
||||
property = (JetProperty) property.replace(
|
||||
JetPsiFactory.createProperty(project, property.getNameIdentifier().getText(), typeStr, property.isVar())
|
||||
psiFactory.createProperty(property.getNameIdentifier().getText(), typeStr, property.isVar())
|
||||
);
|
||||
|
||||
if (inferredType != null) {
|
||||
@@ -133,8 +136,7 @@ public class DeclarationUtils {
|
||||
@NotNull
|
||||
public static JetProperty changePropertyInitializer(@NotNull JetProperty property, @Nullable JetExpression initializer) {
|
||||
//noinspection ConstantConditions
|
||||
return JetPsiFactory.createProperty(
|
||||
property.getProject(),
|
||||
return JetPsiFactory(property).createProperty(
|
||||
property.getNameIdentifier().getText(),
|
||||
JetPsiUtil.getNullableText(property.getTypeRef()),
|
||||
property.isVar(),
|
||||
|
||||
@@ -31,6 +31,8 @@ import org.jetbrains.jet.lang.psi.JetFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class AddFunctionBodyFix extends JetIntentionAction<JetFunction> {
|
||||
public AddFunctionBodyFix(@NotNull JetFunction element) {
|
||||
super(element);
|
||||
@@ -56,11 +58,12 @@ public class AddFunctionBodyFix extends JetIntentionAction<JetFunction> {
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||
JetFunction newElement = (JetFunction) element.copy();
|
||||
JetPsiFactory psiFactory = JetPsiFactory(project);
|
||||
if (!(newElement.getLastChild() instanceof PsiWhiteSpace)) {
|
||||
newElement.add(JetPsiFactory.createWhiteSpace(project));
|
||||
newElement.add(psiFactory.createWhiteSpace());
|
||||
}
|
||||
if (!newElement.hasBody()) {
|
||||
newElement.add(JetPsiFactory.createEmptyBody(project));
|
||||
newElement.add(psiFactory.createEmptyBody());
|
||||
}
|
||||
element.replace(newElement);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,10 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetModifierList;
|
||||
import org.jetbrains.jet.lang.psi.JetModifierListOwner;
|
||||
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
|
||||
import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||
import org.jetbrains.jet.lexer.JetModifierKeywordToken;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
@@ -34,6 +37,7 @@ import org.jetbrains.jet.plugin.JetBundle;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
import static org.jetbrains.jet.lexer.JetTokens.*;
|
||||
|
||||
public class AddModifierFix extends JetIntentionAction<JetModifierListOwner> {
|
||||
@@ -88,7 +92,7 @@ public class AddModifierFix extends JetIntentionAction<JetModifierListOwner> {
|
||||
/*package*/ static JetModifierListOwner addModifier(@NotNull PsiElement element, @NotNull JetKeywordToken modifier, @Nullable JetModifierKeywordToken[] modifiersThatCanBeReplaced, @NotNull Project project, boolean toBeginning) {
|
||||
JetModifierListOwner newElement = (JetModifierListOwner) (element.copy());
|
||||
changeModifier(newElement, newElement.getModifierList(), newElement.getFirstChild(),
|
||||
modifiersThatCanBeReplaced, project, toBeginning, JetPsiFactory.createModifierList(project, modifier));
|
||||
modifiersThatCanBeReplaced, project, toBeginning, JetPsiFactory(project).createModifierList(modifier));
|
||||
return newElement;
|
||||
}
|
||||
|
||||
@@ -96,7 +100,7 @@ public class AddModifierFix extends JetIntentionAction<JetModifierListOwner> {
|
||||
PsiElement element, @Nullable JetModifierList modifierList, @Nullable PsiElement insertAnchor,
|
||||
JetModifierKeywordToken[] modifiersThatCanBeReplaced, Project project, boolean toBeginning, JetModifierList listWithModifier
|
||||
) {
|
||||
PsiElement whiteSpace = JetPsiFactory.createWhiteSpace(project);
|
||||
PsiElement whiteSpace = JetPsiFactory(project).createWhiteSpace();
|
||||
if (modifierList == null) {
|
||||
if (listWithModifier != null) {
|
||||
if (insertAnchor != null) {
|
||||
|
||||
@@ -33,7 +33,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.JetCallElement;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetValueArgument;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
@@ -48,6 +51,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class AddNameToArgumentFix extends JetIntentionAction<JetValueArgument> {
|
||||
|
||||
@NotNull
|
||||
@@ -140,7 +145,7 @@ public class AddNameToArgumentFix extends JetIntentionAction<JetValueArgument> {
|
||||
private static JetValueArgument getParsedArgumentWithName(@NotNull String name, @NotNull JetValueArgument argument) {
|
||||
JetExpression argumentExpression = argument.getArgumentExpression();
|
||||
assert argumentExpression != null : "Argument should be already parsed.";
|
||||
return JetPsiFactory.createArgumentWithName(argument.getProject(), name, argumentExpression);
|
||||
return JetPsiFactory(argument.getProject()).createArgumentWithName(name, argumentExpression);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -23,9 +23,14 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class AddSemicolonAfterFunctionCallFix extends JetIntentionAction<JetCallExpression> {
|
||||
JetFunctionLiteralExpression literal;
|
||||
|
||||
@@ -56,7 +61,7 @@ public class AddSemicolonAfterFunctionCallFix extends JetIntentionAction<JetCall
|
||||
int caretOffset = editor.getCaretModel().getOffset();
|
||||
element.getParent().addRangeAfter(afterArgumentList, literal, element);
|
||||
element.deleteChildRange(afterArgumentList, literal);
|
||||
element.getParent().addAfter(JetPsiFactory.createSemicolon(project), element);
|
||||
element.getParent().addAfter(JetPsiFactory(project).createSemicolon(), element);
|
||||
editor.getCaretModel().moveToOffset(caretOffset + 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.expressions.TypeReconstructionUtil;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public abstract class AddStarProjectionsFix extends JetIntentionAction<JetUserType> {
|
||||
|
||||
private final int argumentCount;
|
||||
@@ -57,7 +59,7 @@ public abstract class AddStarProjectionsFix extends JetIntentionAction<JetUserTy
|
||||
assert element.getTypeArguments().isEmpty();
|
||||
|
||||
String typeString = TypeReconstructionUtil.getTypeNameAndStarProjectionsString(element.getText(), argumentCount);
|
||||
JetTypeElement replacement = JetPsiFactory.createType(project, typeString).getTypeElement();
|
||||
JetTypeElement replacement = JetPsiFactory(project).createType(typeString).getTypeElement();
|
||||
assert replacement != null : "No type element after parsing " + typeString;
|
||||
|
||||
element.replace(replacement);
|
||||
|
||||
@@ -33,6 +33,8 @@ import org.jetbrains.jet.lang.psi.JetWhenEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetWhenExpression;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class AddWhenElseBranchFix extends JetIntentionAction<JetWhenExpression> {
|
||||
private static final String ELSE_ENTRY_TEXT = "else -> {}";
|
||||
|
||||
@@ -63,10 +65,11 @@ public class AddWhenElseBranchFix extends JetIntentionAction<JetWhenExpression>
|
||||
PsiElement whenCloseBrace = element.getCloseBrace();
|
||||
assert (whenCloseBrace != null) : "isAvailable should check if close brace exist";
|
||||
|
||||
JetWhenEntry entry = JetPsiFactory.createWhenEntry(project, ELSE_ENTRY_TEXT);
|
||||
JetPsiFactory psiFactory = JetPsiFactory(project);
|
||||
JetWhenEntry entry = psiFactory.createWhenEntry(ELSE_ENTRY_TEXT);
|
||||
|
||||
PsiElement insertedBranch = element.addBefore(entry, whenCloseBrace);
|
||||
element.addAfter(JetPsiFactory.createNewLine(project), insertedBranch);
|
||||
element.addAfter(psiFactory.createNewLine(), insertedBranch);
|
||||
|
||||
JetWhenEntry insertedWhenEntry = (JetWhenEntry) CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(insertedBranch);
|
||||
TextRange textRange = insertedWhenEntry.getTextRange();
|
||||
|
||||
@@ -34,6 +34,8 @@ import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class CastExpressionFix extends JetIntentionAction<JetExpression> {
|
||||
private final JetType type;
|
||||
private final String renderedType;
|
||||
@@ -66,14 +68,15 @@ public class CastExpressionFix extends JetIntentionAction<JetExpression> {
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||
JetPsiFactory psiFactory = JetPsiFactory(project);
|
||||
JetBinaryExpressionWithTypeRHS castedExpression =
|
||||
(JetBinaryExpressionWithTypeRHS) JetPsiFactory.createExpression(project, "(" + element.getText() + ") as " + renderedType);
|
||||
(JetBinaryExpressionWithTypeRHS) psiFactory.createExpression("(" + element.getText() + ") as " + renderedType);
|
||||
if (JetPsiUtil.areParenthesesUseless((JetParenthesizedExpression) castedExpression.getLeft())) {
|
||||
castedExpression = (JetBinaryExpressionWithTypeRHS) JetPsiFactory.createExpression(project, element.getText() + " as " + renderedType);
|
||||
castedExpression = (JetBinaryExpressionWithTypeRHS) psiFactory.createExpression(element.getText() + " as " + renderedType);
|
||||
}
|
||||
|
||||
JetParenthesizedExpression castedExpressionInParentheses =
|
||||
(JetParenthesizedExpression) element.replace(JetPsiFactory.createExpression(project, "(" + castedExpression.getText() + ")"));
|
||||
(JetParenthesizedExpression) element.replace(psiFactory.createExpression("(" + castedExpression.getText() + ")"));
|
||||
|
||||
if (JetPsiUtil.areParenthesesUseless(castedExpressionInParentheses)) {
|
||||
castedExpressionInParentheses.replace(castedExpression);
|
||||
|
||||
@@ -29,6 +29,8 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class ChangeAccessorTypeFix extends JetIntentionAction<JetPropertyAccessor> {
|
||||
private String renderedType;
|
||||
|
||||
@@ -65,7 +67,7 @@ public class ChangeAccessorTypeFix extends JetIntentionAction<JetPropertyAccesso
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||
JetPropertyAccessor newElement = (JetPropertyAccessor) element.copy();
|
||||
JetTypeReference newTypeReference = JetPsiFactory.createType(project, renderedType);
|
||||
JetTypeReference newTypeReference = JetPsiFactory(project).createType(renderedType);
|
||||
|
||||
if (element.isGetter()) {
|
||||
JetTypeReference returnTypeReference = newElement.getReturnTypeReference();
|
||||
|
||||
@@ -40,6 +40,8 @@ import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class ChangeFunctionLiteralReturnTypeFix extends JetIntentionAction<JetFunctionLiteralExpression> {
|
||||
private final String renderedType;
|
||||
private final JetTypeReference functionLiteralReturnTypeRef;
|
||||
@@ -118,7 +120,7 @@ public class ChangeFunctionLiteralReturnTypeFix extends JetIntentionAction<JetFu
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||
if (functionLiteralReturnTypeRef != null) {
|
||||
functionLiteralReturnTypeRef.replace(JetPsiFactory.createType(project, renderedType));
|
||||
functionLiteralReturnTypeRef.replace(JetPsiFactory(project).createType(renderedType));
|
||||
}
|
||||
if (appropriateQuickFix != null && appropriateQuickFix.isAvailable(project, editor, file)) {
|
||||
appropriateQuickFix.invoke(project, editor, file);
|
||||
|
||||
@@ -49,6 +49,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH;
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction> {
|
||||
private final JetType type;
|
||||
@@ -122,8 +123,9 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
|
||||
// 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();
|
||||
}
|
||||
function.addAfter(JetPsiFactory.createType(project, typeText), elementToPrecedeType);
|
||||
function.addAfter(JetPsiFactory.createColon(project), elementToPrecedeType);
|
||||
JetPsiFactory psiFactory = JetPsiFactory(project);
|
||||
function.addAfter(psiFactory.createType(typeText), elementToPrecedeType);
|
||||
function.addAfter(psiFactory.createColon(), elementToPrecedeType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -28,6 +28,8 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class ChangeParameterTypeFix extends JetIntentionAction<JetParameter> {
|
||||
private final String renderedType;
|
||||
private final String containingDeclarationName;
|
||||
@@ -65,6 +67,6 @@ public class ChangeParameterTypeFix extends JetIntentionAction<JetParameter> {
|
||||
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.createType(project, renderedType));
|
||||
typeReference.replace(JetPsiFactory(project).createType(renderedType));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class ChangeToBackingFieldFix extends JetIntentionAction<JetSimpleNameExpression> {
|
||||
public ChangeToBackingFieldFix(@NotNull JetSimpleNameExpression element) {
|
||||
super(element);
|
||||
@@ -44,7 +46,7 @@ public class ChangeToBackingFieldFix extends JetIntentionAction<JetSimpleNameExp
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||
JetSimpleNameExpression backingField = (JetSimpleNameExpression) JetPsiFactory.createExpression(project, "$" + element.getText());
|
||||
JetSimpleNameExpression backingField = (JetSimpleNameExpression) JetPsiFactory(project).createExpression("$" + element.getText());
|
||||
element.replace(backingField);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@ import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class ChangeToConstructorInvocationFix extends JetIntentionAction<JetDelegatorToSuperClass> {
|
||||
|
||||
public ChangeToConstructorInvocationFix(@NotNull JetDelegatorToSuperClass element) {
|
||||
@@ -77,7 +79,7 @@ public class ChangeToConstructorInvocationFix extends JetIntentionAction<JetDele
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||
JetDelegatorToSuperClass delegator = (JetDelegatorToSuperClass) element.copy();
|
||||
JetClass aClass = JetPsiFactory.createClass(project, "class A : " + delegator.getText() + "()");
|
||||
JetClass aClass = JetPsiFactory(project).createClass("class A : " + delegator.getText() + "()");
|
||||
List<JetDelegationSpecifier> delegationSpecifiers = aClass.getDelegationSpecifiers();
|
||||
assert delegationSpecifiers.size() == 1;
|
||||
JetDelegationSpecifier specifier = delegationSpecifiers.iterator().next();
|
||||
|
||||
@@ -23,9 +23,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class ChangeToFunctionInvocationFix extends JetIntentionAction<JetExpression> {
|
||||
|
||||
public ChangeToFunctionInvocationFix(@NotNull JetExpression element) {
|
||||
@@ -47,7 +48,7 @@ public class ChangeToFunctionInvocationFix extends JetIntentionAction<JetExpress
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||
JetExpression reference = (JetExpression) element.copy();
|
||||
element.replace(JetPsiFactory.createExpression(project, reference.getText() + "()"));
|
||||
element.replace(JetPsiFactory(project).createExpression(reference.getText() + "()"));
|
||||
}
|
||||
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
|
||||
@@ -25,6 +25,8 @@ import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class ChangeToPropertyNameFix extends JetIntentionAction<JetSimpleNameExpression> {
|
||||
public ChangeToPropertyNameFix(@NotNull JetSimpleNameExpression element) {
|
||||
super(element);
|
||||
@@ -53,7 +55,7 @@ public class ChangeToPropertyNameFix extends JetIntentionAction<JetSimpleNameExp
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||
JetSimpleNameExpression propertyName = (JetSimpleNameExpression) JetPsiFactory.createExpression(project, getPropertyName());
|
||||
JetSimpleNameExpression propertyName = (JetSimpleNameExpression) JetPsiFactory(project).createExpression(getPropertyName());
|
||||
element.replace(propertyName);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,10 +22,15 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.JetBinaryExpressionWithTypeRHS;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeElement;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.jet.lang.types.expressions.TypeReconstructionUtil;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class ChangeToStarProjectionFix extends JetIntentionAction<JetTypeElement> {
|
||||
public ChangeToStarProjectionFix(@NotNull JetTypeElement element) {
|
||||
super(element);
|
||||
@@ -48,7 +53,7 @@ public class ChangeToStarProjectionFix extends JetIntentionAction<JetTypeElement
|
||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||
for (JetTypeReference typeReference : element.getTypeArgumentsAsTypes()) {
|
||||
if (typeReference != null) {
|
||||
typeReference.replace(JetPsiFactory.createStar(project));
|
||||
typeReference.replace(JetPsiFactory(project).createStar());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,12 +27,13 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters1;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class ChangeTypeFix extends JetIntentionAction<JetTypeReference> {
|
||||
private final String renderedType;
|
||||
|
||||
@@ -55,7 +56,7 @@ public class ChangeTypeFix extends JetIntentionAction<JetTypeReference> {
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||
element.replace(JetPsiFactory.createType(project, renderedType));
|
||||
element.replace(JetPsiFactory(project).createType(renderedType));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
@@ -35,6 +34,8 @@ import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class ChangeVariableMutabilityFix implements IntentionAction {
|
||||
private boolean isVar;
|
||||
|
||||
@@ -87,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.createValOrVarNode(project, isVar ? "val" : "var").getPsi());
|
||||
property.getValOrVarNode().getPsi().replace(JetPsiFactory(project).createValOrVarNode(isVar ? "val" : "var").getPsi());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -83,21 +83,22 @@ public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclara
|
||||
SpecifyTypeExplicitlyAction.removeTypeAnnotation(element);
|
||||
PsiElement nameIdentifier = element.getNameIdentifier();
|
||||
assert nameIdentifier != null : "ChangeVariableTypeFix applied to variable without name";
|
||||
element.addAfter(JetPsiFactory.createType(project, renderedType), nameIdentifier);
|
||||
element.addAfter(JetPsiFactory.createColon(project), nameIdentifier);
|
||||
JetPsiFactory psiFactory = PsiPackage.JetPsiFactory(project);
|
||||
element.addAfter(psiFactory.createType(renderedType), nameIdentifier);
|
||||
element.addAfter(psiFactory.createColon(), nameIdentifier);
|
||||
|
||||
if (element instanceof JetProperty) {
|
||||
JetPropertyAccessor getter = ((JetProperty) element).getGetter();
|
||||
JetTypeReference getterReturnTypeRef = getter == null ? null : getter.getReturnTypeReference();
|
||||
if (getterReturnTypeRef != null) {
|
||||
getterReturnTypeRef.replace(JetPsiFactory.createType(project, renderedType));
|
||||
getterReturnTypeRef.replace(psiFactory.createType(renderedType));
|
||||
}
|
||||
|
||||
JetPropertyAccessor setter = ((JetProperty) element).getSetter();
|
||||
JetParameter setterParameter = setter == null ? null : setter.getParameter();
|
||||
JetTypeReference setterParameterTypeRef = setterParameter == null ? null : setterParameter.getTypeReference();
|
||||
if (setterParameterTypeRef != null) {
|
||||
setterParameterTypeRef.replace(JetPsiFactory.createType(project, renderedType));
|
||||
setterParameterTypeRef.replace(psiFactory.createType(renderedType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,12 +42,9 @@ import com.intellij.util.ArrayUtil
|
||||
import com.intellij.util.IncorrectOperationException
|
||||
import org.jetbrains.jet.lang.descriptors.*
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters1
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters2
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
@@ -72,7 +69,6 @@ import java.util.Properties
|
||||
import org.jetbrains.jet.plugin.caches.resolve.getAnalysisResults
|
||||
import org.jetbrains.jet.plugin.caches.resolve.getBindingContext
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory
|
||||
import org.jetbrains.jet.lang.diagnostics
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils
|
||||
|
||||
private val TYPE_PARAMETER_LIST_VARIABLE_NAME = "typeParameterList"
|
||||
@@ -627,17 +623,18 @@ public class CreateFunctionFromUsageFix internal (
|
||||
val project = currentFile.getProject()
|
||||
val parametersString = parameters.indices.map { i -> "p$i: Any" }.makeString(", ")
|
||||
val returnTypeString = if (isUnit) "" else ": Any"
|
||||
val psiFactory = JetPsiFactory(project)
|
||||
if (isExtension) {
|
||||
// create as extension function
|
||||
val ownerTypeString = selectedReceiverType.renderedType!!
|
||||
val func = JetPsiFactory.createFunction(project, "fun $ownerTypeString.$functionName($parametersString)$returnTypeString { }")
|
||||
val func = psiFactory.createFunction("fun $ownerTypeString.$functionName($parametersString)$returnTypeString { }")
|
||||
containingFile = currentFile
|
||||
containingFileEditor = currentFileEditor
|
||||
return currentFile.add(func) as JetNamedFunction
|
||||
}
|
||||
else {
|
||||
// create as regular function
|
||||
val func = JetPsiFactory.createFunction(project, "fun $functionName($parametersString)$returnTypeString { }")
|
||||
val func = psiFactory.createFunction("fun $functionName($parametersString)$returnTypeString { }")
|
||||
containingFile = ownerClass.getContainingJetFile()
|
||||
|
||||
NavigationUtil.activateFileWithPsiElement(containingFile)
|
||||
@@ -645,8 +642,8 @@ public class CreateFunctionFromUsageFix internal (
|
||||
|
||||
var classBody = ownerClass.getBody()
|
||||
if (classBody == null) {
|
||||
classBody = ownerClass.add(JetPsiFactory.createEmptyClassBody(project)) as JetClassBody
|
||||
ownerClass.addBefore(JetPsiFactory.createWhiteSpace(project), classBody)
|
||||
classBody = ownerClass.add(psiFactory.createEmptyClassBody()) as JetClassBody
|
||||
ownerClass.addBefore(psiFactory.createWhiteSpace(), classBody)
|
||||
}
|
||||
val rBrace = classBody!!.getRBrace()
|
||||
//TODO: Assert rbrace not null? It can be if the class isn't closed.
|
||||
@@ -741,7 +738,7 @@ public class CreateFunctionFromUsageFix internal (
|
||||
typeRefsToShorten: MutableList<JetTypeReference>, parameterTypeExpressions: List<TypeExpression>,
|
||||
returnTypeExpression: TypeExpression?) {
|
||||
if (isExtension) {
|
||||
val receiverTypeRef = JetPsiFactory.createType(func.getProject(), selectedReceiverType.theType.renderLong(typeParameterNameMap))
|
||||
val receiverTypeRef = JetPsiFactory(func.getProject()).createType(selectedReceiverType.theType.renderLong(typeParameterNameMap))
|
||||
replaceWithLongerName(receiverTypeRef, selectedReceiverType.theType)
|
||||
|
||||
val funcReceiverTypeRef = func.getReceiverTypeRef()
|
||||
@@ -802,7 +799,7 @@ public class CreateFunctionFromUsageFix internal (
|
||||
throw IncorrectOperationException("Failed to parse file template", e)
|
||||
}
|
||||
|
||||
val newBodyExpression = JetPsiFactory.createFunctionBody(func.getProject(), bodyText)
|
||||
val newBodyExpression = JetPsiFactory(func.getProject()).createFunctionBody(bodyText)
|
||||
func.getBodyExpression()!!.replace(newBodyExpression)
|
||||
}
|
||||
|
||||
@@ -871,7 +868,7 @@ public class CreateFunctionFromUsageFix internal (
|
||||
|
||||
private fun replaceWithLongerName(typeRef: JetTypeReference, theType: JetType) {
|
||||
val project = typeRef.getProject()
|
||||
val fullyQualifiedReceiverTypeRef = JetPsiFactory.createType(project, theType.renderLong(typeParameterNameMap))
|
||||
val fullyQualifiedReceiverTypeRef = JetPsiFactory(project).createType(theType.renderLong(typeParameterNameMap))
|
||||
typeRef.replace(fullyQualifiedReceiverTypeRef)
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@ import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
@SuppressWarnings("IntentionDescriptionNotFoundInspection")
|
||||
public class ExclExclCallFix implements IntentionAction {
|
||||
|
||||
@@ -83,14 +85,15 @@ public class ExclExclCallFix implements IntentionAction {
|
||||
return;
|
||||
}
|
||||
|
||||
JetPsiFactory psiFactory = JetPsiFactory(project);
|
||||
if (!isRemove) {
|
||||
JetExpression modifiedExpression = getExpressionForIntroduceCall(editor, file);
|
||||
JetExpression exclExclExpression = JetPsiFactory.createExpression(project, modifiedExpression.getText() + "!!");
|
||||
JetExpression exclExclExpression = psiFactory.createExpression(modifiedExpression.getText() + "!!");
|
||||
modifiedExpression.replace(exclExclExpression);
|
||||
}
|
||||
else {
|
||||
JetPostfixExpression postfixExpression = getExclExclPostfixExpression(editor, file);
|
||||
JetExpression expression = JetPsiFactory.createExpression(project, postfixExpression.getBaseExpression().getText());
|
||||
JetExpression expression = psiFactory.createExpression(postfixExpression.getBaseExpression().getText());
|
||||
postfixExpression.replace(expression);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ import org.jetbrains.k2js.analyze.AnalyzerFacadeForJS;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class ImportInsertHelper {
|
||||
private ImportInsertHelper() {
|
||||
}
|
||||
@@ -115,20 +117,21 @@ public class ImportInsertHelper {
|
||||
}
|
||||
|
||||
public static void writeImportToFile(@NotNull ImportPath importPath, @NotNull JetFile file) {
|
||||
JetPsiFactory psiFactory = JetPsiFactory(file.getProject());
|
||||
if (file instanceof JetCodeFragment) {
|
||||
JetImportDirective newDirective = JetPsiFactory.createImportDirective(file.getProject(), importPath);
|
||||
JetImportDirective newDirective = psiFactory.createImportDirective(importPath);
|
||||
((JetCodeFragment) file).addImportsFromString(newDirective.getText());
|
||||
return;
|
||||
}
|
||||
|
||||
JetImportList importList = file.getImportList();
|
||||
if (importList != null) {
|
||||
JetImportDirective newDirective = JetPsiFactory.createImportDirective(file.getProject(), importPath);
|
||||
importList.add(JetPsiFactory.createNewLine(file.getProject()));
|
||||
JetImportDirective newDirective = psiFactory.createImportDirective(importPath);
|
||||
importList.add(psiFactory.createNewLine());
|
||||
importList.add(newDirective);
|
||||
}
|
||||
else {
|
||||
JetImportList newDirective = JetPsiFactory.createImportDirectiveWithImportList(file.getProject(), importPath);
|
||||
JetImportList newDirective = psiFactory.createImportDirectiveWithImportList(importPath);
|
||||
JetPackageDirective packageDirective = file.getPackageDirective();
|
||||
if (packageDirective == null) {
|
||||
throw new IllegalStateException("Scripts are not supported: " + file.getName());
|
||||
|
||||
@@ -55,9 +55,10 @@ public class KotlinSuppressIntentionAction(
|
||||
private fun suppressAtModifierListOwner(suppressAt: JetModifierListOwner, id: String) {
|
||||
val project = suppressAt.getProject()
|
||||
val modifierList = suppressAt.getModifierList()
|
||||
val psiFactory = JetPsiFactory(project)
|
||||
if (modifierList == null) {
|
||||
// create a modifier list from scratch
|
||||
val newModifierList = JetPsiFactory.createModifierList(project, suppressAnnotationText(id))
|
||||
val newModifierList = psiFactory.createModifierList(suppressAnnotationText(id))
|
||||
val replaced = JetPsiUtil.replaceModifierList(suppressAt, newModifierList)
|
||||
val whiteSpace = project.createWhiteSpace(kind)
|
||||
suppressAt.addAfter(whiteSpace, replaced)
|
||||
@@ -66,7 +67,7 @@ public class KotlinSuppressIntentionAction(
|
||||
val entry = findSuppressAnnotation(suppressAt)
|
||||
if (entry == null) {
|
||||
// no [suppress] annotation
|
||||
val newAnnotation = JetPsiFactory.createAnnotation(project, suppressAnnotationText(id))
|
||||
val newAnnotation = psiFactory.createAnnotation(suppressAnnotationText(id))
|
||||
val addedAnnotation = modifierList.addBefore(newAnnotation, modifierList.getFirstChild())
|
||||
val whiteSpace = project.createWhiteSpace(kind)
|
||||
modifierList.addAfter(whiteSpace, addedAnnotation)
|
||||
@@ -98,7 +99,7 @@ public class KotlinSuppressIntentionAction(
|
||||
val parentheses = JetPsiPrecedences.getPrecedence(suppressAt) > JetPsiPrecedences.PRECEDENCE_OF_PREFIX_EXPRESSION
|
||||
val placeholderText = "PLACEHOLDER_ID"
|
||||
val inner = if (parentheses) "($placeholderText)" else placeholderText
|
||||
val annotatedExpression = JetPsiFactory.createExpression(project, suppressAnnotationText(id) + "\n" + inner)
|
||||
val annotatedExpression = JetPsiFactory(project).createExpression(suppressAnnotationText(id) + "\n" + inner)
|
||||
|
||||
val copy = suppressAt.copy()!!
|
||||
|
||||
@@ -115,7 +116,8 @@ public class KotlinSuppressIntentionAction(
|
||||
|
||||
// add new arguments to an existing entry
|
||||
val args = entry.getValueArgumentList()
|
||||
val newArgList = JetPsiFactory.createCallArguments(project, "($id)")
|
||||
val psiFactory = JetPsiFactory(project)
|
||||
val newArgList = psiFactory.createCallArguments("($id)")
|
||||
if (args == null) {
|
||||
// new argument list
|
||||
entry.addAfter(newArgList, entry.getLastChild())
|
||||
@@ -126,8 +128,8 @@ public class KotlinSuppressIntentionAction(
|
||||
}
|
||||
else {
|
||||
val rightParen = args.getRightParenthesis()
|
||||
args.addBefore(JetPsiFactory.createComma(project), rightParen)
|
||||
args.addBefore(JetPsiFactory.createWhiteSpace(project), rightParen)
|
||||
args.addBefore(psiFactory.createComma(), rightParen)
|
||||
args.addBefore(psiFactory.createWhiteSpace(), rightParen)
|
||||
args.addBefore(newArgList.getArguments()[0], rightParen)
|
||||
}
|
||||
}
|
||||
@@ -147,11 +149,10 @@ public class KotlinSuppressIntentionAction(
|
||||
}
|
||||
|
||||
public class AnnotationHostKind(val kind: String, val name: String, val newLineNeeded: Boolean)
|
||||
private fun Project.createWhiteSpace(kind: AnnotationHostKind): PsiElement =
|
||||
if (kind.newLineNeeded)
|
||||
JetPsiFactory.createNewLine(this)
|
||||
else
|
||||
JetPsiFactory.createWhiteSpace(this)
|
||||
private fun Project.createWhiteSpace(kind: AnnotationHostKind): PsiElement {
|
||||
val psiFactory = JetPsiFactory(this)
|
||||
return if (kind.newLineNeeded) psiFactory.createNewLine() else psiFactory.createWhiteSpace()
|
||||
}
|
||||
|
||||
private class CaretBox<out E: JetExpression>(
|
||||
val expression: E,
|
||||
|
||||
@@ -45,6 +45,8 @@ import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class MapPlatformClassToKotlinFix extends JetIntentionAction<JetReferenceExpression> {
|
||||
private static final String PRIMARY_USAGE = "PrimaryUsage";
|
||||
private static final String OTHER_USAGE = "OtherUsage";
|
||||
@@ -125,7 +127,7 @@ public class MapPlatformClassToKotlinFix extends JetIntentionAction<JetReference
|
||||
for (JetUserType usage : usages) {
|
||||
JetTypeArgumentList typeArguments = usage.getTypeArgumentList();
|
||||
String typeArgumentsString = typeArguments == null ? "" : typeArguments.getText();
|
||||
JetTypeReference replacementType = JetPsiFactory.createType(project, replacementClassName + typeArgumentsString);
|
||||
JetTypeReference replacementType = JetPsiFactory(project).createType(replacementClassName + typeArgumentsString);
|
||||
JetTypeElement replacementTypeElement = replacementType.getTypeElement();
|
||||
assert replacementTypeElement != null;
|
||||
PsiElement replacedElement = usage.replace(replacementTypeElement);
|
||||
|
||||
@@ -26,9 +26,14 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.psi.JetWhenEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetWhenExpression;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class MoveWhenElseBranchFix extends JetIntentionAction<JetWhenExpression> {
|
||||
public MoveWhenElseBranchFix(@NotNull JetWhenExpression element) {
|
||||
super(element);
|
||||
@@ -68,7 +73,7 @@ public class MoveWhenElseBranchFix extends JetIntentionAction<JetWhenExpression>
|
||||
int cursorOffset = editor.getCaretModel().getOffset() - elseEntry.getTextOffset();
|
||||
|
||||
PsiElement insertedBranch = element.addAfter(elseEntry, lastEntry);
|
||||
element.addAfter(JetPsiFactory.createNewLine(project), lastEntry);
|
||||
element.addAfter(JetPsiFactory(project).createNewLine(), lastEntry);
|
||||
element.deleteChildRange(elseEntry, elseEntry);
|
||||
JetWhenEntry insertedWhenEntry = (JetWhenEntry) CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(insertedBranch);
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class ReplaceCallFix implements IntentionAction {
|
||||
private final boolean toSafe;
|
||||
|
||||
@@ -75,8 +77,9 @@ public class ReplaceCallFix implements IntentionAction {
|
||||
|
||||
JetExpression selector = callExpression.getSelectorExpression();
|
||||
if (selector != null) {
|
||||
JetQualifiedExpression newElement = (JetQualifiedExpression) JetPsiFactory.createExpression(
|
||||
project, callExpression.getReceiverExpression().getText() + (toSafe ? "?." : ".") + selector.getText());
|
||||
JetQualifiedExpression newElement = (JetQualifiedExpression) JetPsiFactory(project).createExpression(
|
||||
callExpression.getReceiverExpression().getText() + (toSafe ? "?." : ".") + selector.getText()
|
||||
);
|
||||
|
||||
callExpression.replace(newElement);
|
||||
}
|
||||
|
||||
@@ -22,9 +22,14 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.JetBinaryExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetQualifiedExpression;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class ReplaceInfixCallFix extends JetIntentionAction<JetBinaryExpression> {
|
||||
public ReplaceInfixCallFix(@NotNull JetBinaryExpression element) {
|
||||
super(element);
|
||||
@@ -49,7 +54,7 @@ public class ReplaceInfixCallFix extends JetIntentionAction<JetBinaryExpression>
|
||||
assert left != null && right != null : "Preconditions checked by factory";
|
||||
String newText = left.getText() + "?." + element.getOperationReference().getText()
|
||||
+ "(" + right.getText() + ")";
|
||||
JetQualifiedExpression newElement = (JetQualifiedExpression) JetPsiFactory.createExpression(project, newText);
|
||||
JetQualifiedExpression newElement = (JetQualifiedExpression) JetPsiFactory(project).createExpression(newText);
|
||||
element.replace(newElement);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ public abstract class ReplaceOperationInBinaryExpressionFix<T extends JetExpress
|
||||
JetExpression left = ((JetBinaryExpressionWithTypeRHS) element).getLeft();
|
||||
JetTypeReference right = ((JetBinaryExpressionWithTypeRHS) element).getRight();
|
||||
if (right != null) {
|
||||
JetExpression expression = JetPsiFactory.createExpression(project, left.getText() + operation + right.getText());
|
||||
JetExpression expression = PsiPackage.JetPsiFactory(project).createExpression(left.getText() + operation + right.getText());
|
||||
element.replace(expression);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-3
@@ -31,7 +31,10 @@ import com.intellij.psi.PsiCodeFragment;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.changeSignature.*;
|
||||
import com.intellij.refactoring.changeSignature.CallerChooserBase;
|
||||
import com.intellij.refactoring.changeSignature.ChangeSignatureDialogBase;
|
||||
import com.intellij.refactoring.changeSignature.MethodDescriptor;
|
||||
import com.intellij.refactoring.changeSignature.ParameterTableModelItemBase;
|
||||
import com.intellij.refactoring.ui.ComboBoxVisibilityPanel;
|
||||
import com.intellij.refactoring.ui.VisibilityPanelBase;
|
||||
import com.intellij.ui.DottedBorder;
|
||||
@@ -49,7 +52,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.Visibilities;
|
||||
import org.jetbrains.jet.lang.descriptors.Visibility;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeCodeFragment;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
@@ -64,6 +66,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class JetChangeSignatureDialog extends ChangeSignatureDialogBase<
|
||||
JetParameterInfo,
|
||||
PsiElement,
|
||||
@@ -96,7 +100,7 @@ public class JetChangeSignatureDialog extends ChangeSignatureDialogBase<
|
||||
|
||||
@Override
|
||||
protected PsiCodeFragment createReturnTypeCodeFragment() {
|
||||
return JetPsiFactory.createTypeCodeFragment(myProject, myMethod.getReturnTypeText(), myMethod.getContext());
|
||||
return JetPsiFactory(myProject).createTypeCodeFragment(myMethod.getReturnTypeText(), myMethod.getContext());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+5
-2
@@ -26,6 +26,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class JetFunctionParameterTableModel extends ParameterTableModelBase<JetParameterInfo, ParameterTableModelItemBase<JetParameterInfo>> {
|
||||
private final Project project;
|
||||
|
||||
@@ -46,8 +48,9 @@ public class JetFunctionParameterTableModel extends ParameterTableModelBase<JetP
|
||||
if (parameterInfo == null) {
|
||||
parameterInfo = new JetParameterInfo(-1);
|
||||
}
|
||||
final PsiCodeFragment paramTypeCodeFragment = JetPsiFactory.createTypeCodeFragment(project, parameterInfo.getTypeText(), myTypeContext);
|
||||
final PsiCodeFragment defaultValueCodeFragment = JetPsiFactory.createExpressionCodeFragment(project, parameterInfo.getDefaultValueText(), myDefaultValueContext);
|
||||
JetPsiFactory psiFactory = JetPsiFactory(project);
|
||||
final PsiCodeFragment paramTypeCodeFragment = psiFactory.createTypeCodeFragment(parameterInfo.getTypeText(), myTypeContext);
|
||||
final PsiCodeFragment defaultValueCodeFragment = psiFactory.createExpressionCodeFragment(parameterInfo.getDefaultValueText(), myDefaultValueContext);
|
||||
return new ParameterTableModelItemBase<JetParameterInfo>(parameterInfo, paramTypeCodeFragment, defaultValueCodeFragment) {
|
||||
@Override
|
||||
public boolean isEllipsisType() {
|
||||
|
||||
+5
-3
@@ -26,6 +26,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class JetFunctionCallUsage extends JetUsageInfo<JetCallElement> {
|
||||
private final PsiElement function;
|
||||
private final boolean isInherited;
|
||||
@@ -44,7 +46,7 @@ public class JetFunctionCallUsage extends JetUsageInfo<JetCallElement> {
|
||||
JetExpression callee = element.getCalleeExpression();
|
||||
|
||||
if (callee instanceof JetSimpleNameExpression)
|
||||
callee.replace(JetPsiFactory.createSimpleName(getProject(), changeInfo.getNewName()));
|
||||
callee.replace(JetPsiFactory(getProject()).createSimpleName(changeInfo.getNewName()));
|
||||
}
|
||||
|
||||
if (arguments != null) {
|
||||
@@ -81,7 +83,7 @@ public class JetFunctionCallUsage extends JetUsageInfo<JetCallElement> {
|
||||
}
|
||||
|
||||
parametersBuilder.append(')');
|
||||
JetValueArgumentList newArguments = JetPsiFactory.createCallArguments(getProject(), parametersBuilder.toString());
|
||||
JetValueArgumentList newArguments = JetPsiFactory(getProject()).createCallArguments(parametersBuilder.toString());
|
||||
|
||||
Map<Integer, JetValueArgument> argumentMap = getParamIndexToArgumentMap(changeInfo, oldArguments);
|
||||
int argIndex = 0;
|
||||
@@ -146,7 +148,7 @@ public class JetFunctionCallUsage extends JetUsageInfo<JetCallElement> {
|
||||
|
||||
if (identifier != null) {
|
||||
String newName = parameterInfo.getInheritedName(isInherited, function, changeInfo.getFunctionDescriptor());
|
||||
identifier.replace(JetPsiFactory.createIdentifier(getProject(), newName));
|
||||
identifier.replace(JetPsiFactory(getProject()).createIdentifier(newName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+20
-12
@@ -32,6 +32,8 @@ import org.jetbrains.jet.plugin.refactoring.changeSignature.JetChangeInfo;
|
||||
import org.jetbrains.jet.plugin.refactoring.changeSignature.JetParameterInfo;
|
||||
import org.jetbrains.jet.plugin.refactoring.changeSignature.JetValVar;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class JetFunctionDefinitionUsage extends JetUsageInfo<PsiElement> {
|
||||
private final boolean isInherited;
|
||||
|
||||
@@ -44,6 +46,7 @@ public class JetFunctionDefinitionUsage extends JetUsageInfo<PsiElement> {
|
||||
public boolean processUsage(JetChangeInfo changeInfo, PsiElement element) {
|
||||
JetParameterList parameterList;
|
||||
|
||||
JetPsiFactory psiFactory = JetPsiFactory(element.getProject());
|
||||
if (element instanceof JetFunction) {
|
||||
JetFunction function = (JetFunction) element;
|
||||
parameterList = function.getValueParameterList();
|
||||
@@ -51,8 +54,9 @@ public class JetFunctionDefinitionUsage extends JetUsageInfo<PsiElement> {
|
||||
if (changeInfo.isNameChanged()) {
|
||||
PsiElement identifier = function.getNameIdentifier();
|
||||
|
||||
if (identifier != null)
|
||||
identifier.replace(JetPsiFactory.createIdentifier(element.getProject(), changeInfo.getNewName()));
|
||||
if (identifier != null) {
|
||||
identifier.replace(psiFactory.createIdentifier(changeInfo.getNewName()));
|
||||
}
|
||||
}
|
||||
if (changeInfo.isReturnTypeChanged()) {
|
||||
SpecifyTypeExplicitlyAction.removeTypeAnnotation(function);
|
||||
@@ -68,7 +72,7 @@ public class JetFunctionDefinitionUsage extends JetUsageInfo<PsiElement> {
|
||||
|
||||
if (changeInfo.isParameterSetOrOrderChanged()) {
|
||||
String parametersText = changeInfo.getNewParametersSignature(element, isInherited, 0);
|
||||
JetParameterList newParameterList = JetPsiFactory.createParameterList(getProject(), parametersText);
|
||||
JetParameterList newParameterList = psiFactory.createParameterList(parametersText);
|
||||
|
||||
if (parameterList != null)
|
||||
parameterList = (JetParameterList) parameterList.replace(newParameterList);
|
||||
@@ -99,15 +103,16 @@ public class JetFunctionDefinitionUsage extends JetUsageInfo<PsiElement> {
|
||||
private void changeVisibility(JetChangeInfo changeInfo, PsiElement element, JetParameterList parameterList) {
|
||||
JetKeywordToken newVisibilityToken = JetRefactoringUtil.getVisibilityToken(changeInfo.getNewVisibility());
|
||||
|
||||
JetPsiFactory psiFactory = JetPsiFactory(getProject());
|
||||
if (element instanceof JetFunction) {
|
||||
JetModifierList modifierList = newVisibilityToken == JetTokens.INTERNAL_KEYWORD ? null :
|
||||
JetPsiFactory.createModifierList(getProject(), newVisibilityToken);
|
||||
psiFactory.createModifierList(newVisibilityToken);
|
||||
AddModifierFix.changeModifier(element, ((JetFunction) element).getModifierList(), null,
|
||||
ChangeVisibilityModifierFix.VISIBILITY_TOKENS, getProject(), true, modifierList);
|
||||
}
|
||||
else {
|
||||
JetModifierList modifierList = newVisibilityToken == JetTokens.PUBLIC_KEYWORD ? null :
|
||||
JetPsiFactory.createConstructorModifierList(getProject(), newVisibilityToken);
|
||||
psiFactory.createConstructorModifierList(newVisibilityToken);
|
||||
AddModifierFix.changeModifier(element, ((JetClass) element).getPrimaryConstructorModifierList(), parameterList,
|
||||
ChangeVisibilityModifierFix.VISIBILITY_TOKENS, getProject(), true, modifierList);
|
||||
}
|
||||
@@ -118,20 +123,23 @@ public class JetFunctionDefinitionUsage extends JetUsageInfo<PsiElement> {
|
||||
PsiElement valOrVarNode = valOrVarAstNode != null ? valOrVarAstNode.getPsi() : null;
|
||||
JetValVar valOrVar = parameterInfo.getValOrVar();
|
||||
|
||||
JetPsiFactory psiFactory = JetPsiFactory(getProject());
|
||||
if (valOrVarNode != null) {
|
||||
if (valOrVar == JetValVar.None)
|
||||
if (valOrVar == JetValVar.None) {
|
||||
valOrVarNode.delete();
|
||||
else
|
||||
valOrVarNode.replace(JetPsiFactory.createValOrVarNode(getProject(), valOrVar.toString()).getPsi());
|
||||
}
|
||||
else {
|
||||
valOrVarNode.replace(psiFactory.createValOrVarNode(valOrVar.toString()).getPsi());
|
||||
}
|
||||
}
|
||||
else if (valOrVar != JetValVar.None) {
|
||||
PsiElement firstChild = parameter.getFirstChild();
|
||||
parameter.addBefore(JetPsiFactory.createValOrVarNode(getProject(), valOrVar.toString()).getPsi(), firstChild);
|
||||
parameter.addBefore(JetPsiFactory.createWhiteSpace(getProject()), firstChild);
|
||||
parameter.addBefore(psiFactory.createValOrVarNode(valOrVar.toString()).getPsi(), firstChild);
|
||||
parameter.addBefore(psiFactory.createWhiteSpace(), firstChild);
|
||||
}
|
||||
|
||||
if (parameterInfo.isTypeChanged()) {
|
||||
JetTypeReference newType = JetPsiFactory.createType(getProject(), parameterInfo.getTypeText());
|
||||
JetTypeReference newType = psiFactory.createType(parameterInfo.getTypeText());
|
||||
JetTypeReference typeReference = parameter.getTypeReference();
|
||||
|
||||
if (typeReference != null)
|
||||
@@ -142,7 +150,7 @@ public class JetFunctionDefinitionUsage extends JetUsageInfo<PsiElement> {
|
||||
|
||||
if (identifier != null) {
|
||||
String newName = parameterInfo.getInheritedName(isInherited, element, changeInfo.getFunctionDescriptor());
|
||||
identifier.replace(JetPsiFactory.createIdentifier(parameter.getProject(), newName));
|
||||
identifier.replace(psiFactory.createIdentifier(newName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -18,11 +18,12 @@ package org.jetbrains.jet.plugin.refactoring.changeSignature.usages;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.plugin.refactoring.changeSignature.JetChangeInfo;
|
||||
import org.jetbrains.jet.plugin.refactoring.changeSignature.JetParameterInfo;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class JetParameterUsage extends JetUsageInfo<JetSimpleNameExpression> {
|
||||
private final JetParameterInfo parameterInfo;
|
||||
private final PsiElement function;
|
||||
@@ -38,7 +39,7 @@ public class JetParameterUsage extends JetUsageInfo<JetSimpleNameExpression> {
|
||||
@Override
|
||||
public boolean processUsage(JetChangeInfo changeInfo, JetSimpleNameExpression element) {
|
||||
String newName = parameterInfo.getInheritedName(isInherited, function, changeInfo.getFunctionDescriptor());
|
||||
element.replace(JetPsiFactory.createSimpleName(element.getProject(), newName));
|
||||
element.replace(JetPsiFactory(element.getProject()).createSimpleName(newName));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,6 @@ import org.jetbrains.jet.lang.psi.JetUserType
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils
|
||||
import org.jetbrains.jet.lang.psi.JetFunctionLiteral
|
||||
import org.jetbrains.jet.lang.psi.JetClassInitializer
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getResolvedCall
|
||||
@@ -104,7 +103,7 @@ class ExtractionData(
|
||||
|
||||
val originalStartOffset = originalElements.first?.let { e -> e.getTextRange()!!.getStartOffset() }
|
||||
|
||||
private val itFakeDeclaration by Delegates.lazy { JetPsiFactory.createParameter(project, "it", null) }
|
||||
private val itFakeDeclaration by Delegates.lazy { JetPsiFactory(project).createParameter("it", "Any?") }
|
||||
|
||||
val refOffsetToDeclaration by Delegates.lazy {
|
||||
fun isExtractableIt(descriptor: DeclarationDescriptor, context: BindingContext): Boolean {
|
||||
|
||||
+2
-2
@@ -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.createSimpleName(e.getProject(), parameter.nameForRef))
|
||||
return (thisExpr ?: e).replaced(JetPsiFactory(e.getProject()).createSimpleName(parameter.nameForRef))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ class AddPrefixReplacement(override val parameter: Parameter): ParameterReplacem
|
||||
override fun invoke(e: JetElement): JetElement {
|
||||
val selector = (e.getParent() as? JetCallExpression) ?: e
|
||||
val newExpr = selector.replace(
|
||||
JetPsiFactory.createExpression(e.getProject(), "${parameter.nameForRef}.${selector.getText()}")
|
||||
JetPsiFactory(e.getProject()).createExpression("${parameter.nameForRef}.${selector.getText()}")
|
||||
) as JetQualifiedExpression
|
||||
|
||||
return with(newExpr.getSelectorExpression()!!) { if (this is JetCallExpression) getCalleeExpression()!! else this }
|
||||
|
||||
+21
-22
@@ -43,7 +43,6 @@ import com.intellij.psi.PsiNamedElement
|
||||
import org.jetbrains.jet.lang.descriptors.impl.LocalVariableDescriptor
|
||||
import org.jetbrains.jet.utils.DFS
|
||||
import org.jetbrains.jet.utils.DFS.*
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils
|
||||
import org.jetbrains.jet.plugin.caches.resolve.getLazyResolveSession
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.prependElement
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.appendElement
|
||||
@@ -68,7 +67,6 @@ import org.jetbrains.jet.lang.resolve.OverridingUtil
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.isAncestor
|
||||
import org.jetbrains.jet.plugin.intentions.declarations.DeclarationUtils
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
|
||||
private val DEFAULT_FUNCTION_NAME = "myFun"
|
||||
private val DEFAULT_RETURN_TYPE = KotlinBuiltIns.getInstance().getUnitType()
|
||||
@@ -801,13 +799,14 @@ fun ExtractionDescriptor.generateFunction(
|
||||
): JetNamedFunction {
|
||||
val project = extractionData.project
|
||||
|
||||
val psiFactory = JetPsiFactory(project)
|
||||
fun createFunction(): JetNamedFunction {
|
||||
return with(extractionData) {
|
||||
if (inTempFile) {
|
||||
createTemporaryFunction("${getFunctionText()}\n")
|
||||
}
|
||||
else {
|
||||
JetPsiFactory.createFunction(project, getFunctionText())
|
||||
psiFactory.createFunction(getFunctionText())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -841,7 +840,7 @@ fun ExtractionDescriptor.generateFunction(
|
||||
val replacingReturn: JetExpression?
|
||||
val expressionsToReplaceWithReturn: List<JetElement>
|
||||
if (controlFlow is JumpBasedControlFlow) {
|
||||
replacingReturn = JetPsiFactory.createExpression(project, if (controlFlow is ConditionalJump) "return true" else "return")
|
||||
replacingReturn = psiFactory.createExpression(if (controlFlow is ConditionalJump) "return true" else "return")
|
||||
expressionsToReplaceWithReturn = controlFlow.elementsToReplace.map { jumpElement ->
|
||||
val offsetInBody = jumpElement.getTextRange()!!.getStartOffset() - extractionData.originalStartOffset!!
|
||||
val expr = file.findElementAt(bodyOffset + offsetInBody)?.getParentByType(jumpElement.javaClass)
|
||||
@@ -869,23 +868,23 @@ fun ExtractionDescriptor.generateFunction(
|
||||
|
||||
for (param in parameters) {
|
||||
param.mirrorVarName?.let { varName ->
|
||||
body.prependElement(JetPsiFactory.createProperty(project, varName, null, true, param.name))
|
||||
body.prependElement(psiFactory.createProperty(varName, null, true, param.name))
|
||||
}
|
||||
}
|
||||
|
||||
when (controlFlow) {
|
||||
is ParameterUpdate ->
|
||||
body.appendElement(JetPsiFactory.createReturn(project, controlFlow.parameter.nameForRef))
|
||||
body.appendElement(psiFactory.createReturn(controlFlow.parameter.nameForRef))
|
||||
|
||||
is Initializer ->
|
||||
body.appendElement(JetPsiFactory.createReturn(project, controlFlow.initializedDeclaration.getName()!!))
|
||||
body.appendElement(psiFactory.createReturn(controlFlow.initializedDeclaration.getName()!!))
|
||||
|
||||
is ConditionalJump ->
|
||||
body.appendElement(JetPsiFactory.createReturn(project, "false"))
|
||||
body.appendElement(psiFactory.createReturn("false"))
|
||||
|
||||
is ExpressionEvaluation ->
|
||||
body.getStatements().last?.let {
|
||||
val newExpr = it.replaced(JetPsiFactory.createReturn(project, it.getText() ?: throw AssertionError("Return expression shouldn't be empty: code fragment = ${body.getText()}"))).getReturnedExpression()!!
|
||||
val newExpr = it.replaced(psiFactory.createReturn(it.getText() ?: throw AssertionError("Return expression shouldn't be empty: code fragment = ${body.getText()}"))).getReturnedExpression()!!
|
||||
val counterpartMap = createNameCounterpartMap(it, newExpr)
|
||||
nameByOffset.entrySet().forEach { e -> counterpartMap[e.getValue()]?.let { e.setValue(it) } }
|
||||
}
|
||||
@@ -895,7 +894,7 @@ fun ExtractionDescriptor.generateFunction(
|
||||
fun insertFunction(function: JetNamedFunction): JetNamedFunction {
|
||||
return with(extractionData) {
|
||||
val targetContainer = targetSibling.getParent()!!
|
||||
val emptyLines = JetPsiFactory.createWhiteSpace(project, "\n\n")
|
||||
val emptyLines = psiFactory.createWhiteSpace("\n\n")
|
||||
if (insertBefore) {
|
||||
val functionInFile = targetContainer.addBefore(function, targetSibling) as JetNamedFunction
|
||||
targetContainer.addBefore(emptyLines, targetSibling)
|
||||
@@ -924,7 +923,7 @@ fun ExtractionDescriptor.generateFunction(
|
||||
return
|
||||
}
|
||||
|
||||
val argumentListExt = JetPsiFactory.createCallArguments(project, "(${wrappedCall.getText()})")
|
||||
val argumentListExt = psiFactory.createCallArguments("(${wrappedCall.getText()})")
|
||||
val argumentList = enclosingCall.getValueArgumentList()
|
||||
if (argumentList == null) {
|
||||
(anchor.getPrevSibling() as? PsiWhiteSpace)?.let { it.delete() }
|
||||
@@ -933,7 +932,7 @@ fun ExtractionDescriptor.generateFunction(
|
||||
}
|
||||
|
||||
val newArgText = (argumentList.getArguments() + argumentListExt.getArguments()).map { it.getText() }.joinToString(", ", "(", ")")
|
||||
argumentList.replace(JetPsiFactory.createCallArguments(project, newArgText))
|
||||
argumentList.replace(psiFactory.createCallArguments(newArgText))
|
||||
anchor.delete()
|
||||
}
|
||||
|
||||
@@ -956,39 +955,39 @@ fun ExtractionDescriptor.generateFunction(
|
||||
|
||||
val copiedDeclarations = HashMap<JetDeclaration, JetDeclaration>()
|
||||
for (decl in controlFlow.declarationsToCopy) {
|
||||
val declCopy = JetPsiFactory.createDeclaration(project, decl.getText(), javaClass<JetDeclaration>())
|
||||
val declCopy = psiFactory.createDeclaration<JetDeclaration>(decl.getText()!!)
|
||||
copiedDeclarations[decl] = anchorParent.addBefore(declCopy, anchor) as JetDeclaration
|
||||
anchorParent.addBefore(JetPsiFactory.createNewLine(project), anchor)
|
||||
anchorParent.addBefore(psiFactory.createNewLine(), anchor)
|
||||
}
|
||||
|
||||
val wrappedCall = when (controlFlow) {
|
||||
is ExpressionEvaluationWithCallSiteReturn ->
|
||||
JetPsiFactory.createReturn(project, callText)
|
||||
psiFactory.createReturn(callText)
|
||||
|
||||
is ParameterUpdate ->
|
||||
JetPsiFactory.createExpression(project, "${controlFlow.parameter.argumentText} = $callText")
|
||||
psiFactory.createExpression("${controlFlow.parameter.argumentText} = $callText")
|
||||
|
||||
is Initializer -> {
|
||||
val newDecl = copiedDeclarations[controlFlow.initializedDeclaration] as JetProperty
|
||||
newDecl.replace(DeclarationUtils.changePropertyInitializer(newDecl, JetPsiFactory.createExpression(project, callText)))
|
||||
newDecl.replace(DeclarationUtils.changePropertyInitializer(newDecl, psiFactory.createExpression(callText)))
|
||||
null
|
||||
}
|
||||
|
||||
is ConditionalJump ->
|
||||
JetPsiFactory.createExpression(project, "if ($callText) ${controlFlow.elementToInsertAfterCall.getText()}")
|
||||
psiFactory.createExpression("if ($callText) ${controlFlow.elementToInsertAfterCall.getText()}")
|
||||
|
||||
is UnconditionalJump -> {
|
||||
anchorParent.addAfter(
|
||||
JetPsiFactory.createExpression(project, controlFlow.elementToInsertAfterCall.getText()),
|
||||
psiFactory.createExpression(controlFlow.elementToInsertAfterCall.getText()!!),
|
||||
anchor
|
||||
)
|
||||
anchorParent.addAfter(JetPsiFactory.createNewLine(project), anchor)
|
||||
anchorParent.addAfter(psiFactory.createNewLine(), anchor)
|
||||
|
||||
JetPsiFactory.createExpression(project, callText)
|
||||
psiFactory.createExpression(callText)
|
||||
}
|
||||
|
||||
else ->
|
||||
JetPsiFactory.createExpression(project, callText)
|
||||
psiFactory.createExpression(callText)
|
||||
}
|
||||
insertCall(anchor, wrappedCall)
|
||||
|
||||
|
||||
@@ -69,6 +69,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class KotlinInlineValHandler extends InlineActionHandler {
|
||||
@Override
|
||||
public boolean isEnabledForLanguage(Language l) {
|
||||
@@ -269,11 +271,12 @@ public class KotlinInlineValHandler extends InlineActionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
JetPsiFactory psiFactory = JetPsiFactory(containingFile.getProject());
|
||||
for (JetFunctionLiteralExpression functionLiteralExpression : functionsToAddParameters) {
|
||||
JetFunctionLiteral functionLiteral = functionLiteralExpression.getFunctionLiteral();
|
||||
|
||||
JetParameterList currentParameterList = functionLiteral.getValueParameterList();
|
||||
JetParameterList newParameterList = JetPsiFactory.createParameterList(containingFile.getProject(), "(" + parameters + ")");
|
||||
JetParameterList newParameterList = psiFactory.createParameterList("(" + parameters + ")");
|
||||
if (currentParameterList != null) {
|
||||
currentParameterList.replace(newParameterList);
|
||||
}
|
||||
@@ -284,7 +287,7 @@ public class KotlinInlineValHandler extends InlineActionHandler {
|
||||
PsiElement whitespaceToAdd = nextSibling instanceof PsiWhiteSpace && nextSibling.getText().contains("\n")
|
||||
? nextSibling.copy() : null;
|
||||
|
||||
Pair<PsiElement, PsiElement> whitespaceAndArrow = JetPsiFactory.createWhitespaceAndArrow(containingFile.getProject());
|
||||
Pair<PsiElement, PsiElement> whitespaceAndArrow = psiFactory.createWhitespaceAndArrow();
|
||||
functionLiteral.addRangeAfter(whitespaceAndArrow.getFirst(), whitespaceAndArrow.getSecond(), openBraceElement);
|
||||
|
||||
functionLiteral.addAfter(newParameterList, openBraceElement);
|
||||
@@ -331,9 +334,9 @@ public class KotlinInlineValHandler extends InlineActionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
JetPsiFactory psiFactory = JetPsiFactory(containingFile.getProject());
|
||||
for (JetCallExpression call : callsToAddArguments) {
|
||||
call.addAfter(JetPsiFactory.createTypeArguments(containingFile.getProject(), "<" + typeArguments + ">"),
|
||||
call.getCalleeExpression());
|
||||
call.addAfter(psiFactory.createTypeArguments("<" + typeArguments + ">"), call.getCalleeExpression());
|
||||
ShortenReferences.instance$.process(call.getTypeArgumentList());
|
||||
}
|
||||
}
|
||||
@@ -380,7 +383,7 @@ public class KotlinInlineValHandler extends InlineActionHandler {
|
||||
!(newExpression instanceof JetSimpleNameExpression)) {
|
||||
JetBlockStringTemplateEntry templateEntry =
|
||||
(JetBlockStringTemplateEntry) referenceElement.getParent().replace(
|
||||
JetPsiFactory.createBlockStringTemplateEntry(referenceElement.getProject(), newExpression));
|
||||
JetPsiFactory(referenceElement.getProject()).createBlockStringTemplateEntry(newExpression));
|
||||
JetExpression expression = templateEntry.getExpression();
|
||||
assert expression != null;
|
||||
return expression;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user