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:
@@ -304,6 +304,9 @@
|
||||
<item name='com.intellij.psi.PsiExpressionStatement'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.intellij.psi.PsiFileFactory com.intellij.psi.PsiFileFactory getInstance(com.intellij.openapi.project.Project)'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='com.intellij.psi.PsiFileFactory com.intellij.psi.PsiFileFactory getInstance(com.intellij.openapi.project.Project) 0'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
|
||||
@@ -76,6 +76,7 @@ import java.util.*;
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.*;
|
||||
import static org.jetbrains.jet.codegen.JvmCodegenUtil.*;
|
||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.*;
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.getNotNull;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.isVarCapturedInClosure;
|
||||
@@ -2561,7 +2562,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
}
|
||||
}
|
||||
fakeFunctionCall.append(")");
|
||||
return (JetCallExpression) JetPsiFactory.createExpression(state.getProject(), fakeFunctionCall.toString());
|
||||
return (JetCallExpression) JetPsiFactory(state.getProject()).createExpression(fakeFunctionCall.toString());
|
||||
}
|
||||
|
||||
private void computeAndSaveArguments(@NotNull List<? extends ValueArgument> fakeArguments, @NotNull ExpressionCodegen codegen) {
|
||||
@@ -2581,7 +2582,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
) {
|
||||
if (receiver == null) return NO_RECEIVER;
|
||||
|
||||
JetExpression receiverExpression = JetPsiFactory.createExpression(state.getProject(), "callableReferenceFakeReceiver");
|
||||
JetExpression receiverExpression = JetPsiFactory(state.getProject()).createExpression("callableReferenceFakeReceiver");
|
||||
codegen.tempVariables.put(receiverExpression, receiverParameterStackValue(signature));
|
||||
return new ExpressionReceiver(receiverExpression, receiver.getType());
|
||||
}
|
||||
@@ -3938,7 +3939,7 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
}
|
||||
|
||||
private Call makeFakeCall(ReceiverValue initializerAsReceiver) {
|
||||
JetSimpleNameExpression fake = JetPsiFactory.createSimpleName(state.getProject(), "fake");
|
||||
JetSimpleNameExpression fake = JetPsiFactory(state.getProject()).createSimpleName("fake");
|
||||
return CallMaker.makeCall(fake, initializerAsReceiver);
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -22,13 +22,14 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.TypeParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.ExternalAnnotationResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaField;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class AlternativeFieldSignatureData extends ElementAlternativeSignatureData {
|
||||
private JetType altReturnType;
|
||||
|
||||
@@ -47,7 +48,7 @@ public class AlternativeFieldSignatureData extends ElementAlternativeSignatureDa
|
||||
}
|
||||
|
||||
setAnnotated(true);
|
||||
JetProperty altPropertyDeclaration = JetPsiFactory.createProperty(project, signature);
|
||||
JetProperty altPropertyDeclaration = JetPsiFactory(project).createProperty(signature);
|
||||
|
||||
try {
|
||||
checkForSyntaxErrors(altPropertyDeclaration);
|
||||
|
||||
+2
-1
@@ -41,6 +41,7 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
import static org.jetbrains.jet.lang.resolve.java.resolver.TypeUsage.MEMBER_SIGNATURE_CONTRAVARIANT;
|
||||
import static org.jetbrains.jet.lang.resolve.java.resolver.TypeUsage.UPPER_BOUND;
|
||||
|
||||
@@ -76,7 +77,7 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
||||
}
|
||||
|
||||
setAnnotated(true);
|
||||
altFunDeclaration = JetPsiFactory.createFunction(project, signature);
|
||||
altFunDeclaration = JetPsiFactory(project).createFunction(signature);
|
||||
|
||||
originalToAltTypeParameters = DescriptorResolverUtils.recreateTypeParametersAndReturnMapping(methodTypeParameters, null);
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiModifiableCodeBlock;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.ReadOnly;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -42,6 +43,7 @@ public class JetBlockExpression extends JetExpressionImpl implements JetStatemen
|
||||
return visitor.visitBlockExpression(this, data);
|
||||
}
|
||||
|
||||
@ReadOnly
|
||||
@NotNull
|
||||
public List<JetElement> getStatements() {
|
||||
return Arrays.asList(findChildrenByClass(JetElement.class));
|
||||
|
||||
@@ -100,7 +100,7 @@ public abstract class JetCodeFragment(
|
||||
}
|
||||
|
||||
fun importsAsImportList(): JetImportList? {
|
||||
return JetPsiFactory.createFile(_project, _myImports.makeString("\n")).getImportList()
|
||||
return JetPsiFactory(_project).createFile(_myImports.makeString("\n")).getImportList()
|
||||
}
|
||||
|
||||
override fun setVisibilityChecker(checker: JavaCodeFragment.VisibilityChecker?) { }
|
||||
|
||||
@@ -46,7 +46,7 @@ public abstract class JetExpressionImpl extends JetElementImpl implements JetExp
|
||||
PsiElement parent = getParent();
|
||||
if (parent instanceof JetExpression && newElement instanceof JetExpression &&
|
||||
JetPsiUtil.areParenthesesNecessary((JetExpression) newElement, this, (JetExpression) parent)) {
|
||||
return super.replace(JetPsiFactory.createExpression(getProject(), "(" + newElement.getText() + ")"));
|
||||
return super.replace(PsiPackage.JetPsiFactory(getProject()).createExpression("(" + newElement.getText() + ")"));
|
||||
}
|
||||
return super.replace(newElement);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public abstract class JetExpressionImplStub<T extends StubElement> extends JetEl
|
||||
PsiElement parent = getParent();
|
||||
if (parent instanceof JetExpression && newElement instanceof JetExpression &&
|
||||
JetPsiUtil.areParenthesesNecessary((JetExpression) newElement, this, (JetExpression) parent)) {
|
||||
return super.replace(JetPsiFactory.createExpression(getProject(), "(" + newElement.getText() + ")"));
|
||||
return super.replace(PsiPackage.JetPsiFactory(getProject()).createExpression("(" + newElement.getText() + ")"));
|
||||
}
|
||||
return super.replace(newElement);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ import javax.inject.Inject;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class JetImportsFactory {
|
||||
@NotNull
|
||||
private Project project;
|
||||
@@ -47,7 +49,7 @@ public class JetImportsFactory {
|
||||
return directive;
|
||||
}
|
||||
|
||||
JetImportDirective createdDirective = JetPsiFactory.createImportDirective(project, importPath);
|
||||
JetImportDirective createdDirective = JetPsiFactory(project).createImportDirective(importPath);
|
||||
importsCache.put(importPath, createdDirective);
|
||||
|
||||
return createdDirective;
|
||||
|
||||
@@ -21,10 +21,11 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
// TODO: Remove when all named declarations get stubs
|
||||
@Deprecated
|
||||
abstract class JetNamedDeclarationNotStubbed extends JetDeclarationImpl implements JetNamedDeclaration {
|
||||
@@ -63,7 +64,7 @@ abstract class JetNamedDeclarationNotStubbed extends JetDeclarationImpl implemen
|
||||
|
||||
@Override
|
||||
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
||||
return getNameIdentifier().replace(JetPsiFactory.createNameIdentifier(getProject(), name));
|
||||
return getNameIdentifier().replace(JetPsiFactory(getProject()).createNameIdentifier(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,6 +30,8 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
abstract class JetNamedDeclarationStub<T extends PsiJetStubWithFqName> extends JetDeclarationStub<T> implements JetNamedDeclaration {
|
||||
public JetNamedDeclarationStub(@NotNull T stub, @NotNull IStubElementType nodeType) {
|
||||
super(stub, nodeType);
|
||||
@@ -75,7 +77,7 @@ abstract class JetNamedDeclarationStub<T extends PsiJetStubWithFqName> extends J
|
||||
|
||||
@Override
|
||||
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
||||
return getNameIdentifier().replace(JetPsiFactory.createNameIdentifier(getProject(), name));
|
||||
return getNameIdentifier().replace(JetPsiFactory(getProject()).createNameIdentifier(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -49,7 +49,7 @@ public class JetObjectDeclarationName extends JetExpressionImpl {
|
||||
}
|
||||
|
||||
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
||||
return getNameIdentifier().replace(JetPsiFactory.createNameIdentifier(getProject(), name));
|
||||
return getNameIdentifier().replace(PsiPackage.JetPsiFactory(getProject()).createNameIdentifier(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -110,7 +110,7 @@ public fun JetBlockExpression.prependElement(element: JetElement): JetElement =
|
||||
addBefore(element, getLBrace()!!.getNextSibling()!!)!! as JetElement
|
||||
|
||||
public fun JetElement.wrapInBlock(): JetBlockExpression {
|
||||
val block = JetPsiFactory.createEmptyBody(getProject()) as JetBlockExpression
|
||||
val block = JetPsiFactory(getProject()).createEmptyBody() as JetBlockExpression
|
||||
block.appendElement(this)
|
||||
return block
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.Renderers;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition;
|
||||
@@ -48,8 +47,7 @@ import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.psi.JetPsiFactory.createExpression;
|
||||
import static org.jetbrains.jet.lang.psi.JetPsiFactory.createSimpleName;
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
import static org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage.getCalleeExpressionIfAny;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
@@ -180,9 +178,12 @@ public class DelegatedPropertyResolver {
|
||||
boolean hasThis = propertyDescriptor.getReceiverParameter() != null || propertyDescriptor.getExpectedThisObject() != null;
|
||||
|
||||
List<JetExpression> arguments = Lists.newArrayList();
|
||||
arguments.add(createExpression(project, hasThis ? "this" : "null"));
|
||||
arguments.add(JetPsiFactory(project).createExpression(hasThis ? "this" : "null"));
|
||||
|
||||
arguments.add(createExpression(project, KotlinBuiltIns.getInstance().getPropertyMetadataImpl().getName().asString() + "(\"" + propertyDescriptor.getName().asString() + "\")"));
|
||||
arguments.add(JetPsiFactory(project).createExpression(KotlinBuiltIns.getInstance().getPropertyMetadataImpl().getName().asString() +
|
||||
"(\"" +
|
||||
propertyDescriptor.getName().asString() +
|
||||
"\")"));
|
||||
|
||||
if (!isGet) {
|
||||
JetReferenceExpression fakeArgument = (JetReferenceExpression) createFakeExpressionOfType(expressionTypingServices.getProject(), trace,
|
||||
@@ -194,7 +195,7 @@ public class DelegatedPropertyResolver {
|
||||
}
|
||||
|
||||
Name functionName = Name.identifier(isGet ? "get" : "set");
|
||||
JetReferenceExpression fakeCalleeExpression = createSimpleName(project, functionName.asString());
|
||||
JetReferenceExpression fakeCalleeExpression = JetPsiFactory(project).createSimpleName(functionName.asString());
|
||||
|
||||
ExpressionReceiver receiver = new ExpressionReceiver(delegateExpression, delegateType);
|
||||
Call call = CallMaker.makeCallWithExpressions(fakeCalleeExpression, receiver, null, fakeCalleeExpression, arguments, Call.CallType.DEFAULT);
|
||||
|
||||
@@ -48,6 +48,8 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
/**
|
||||
* CallTransformer treats specially 'variable as function' call case, other cases keeps unchanged (base realization).
|
||||
*
|
||||
@@ -262,7 +264,7 @@ public class CallTransformer<D extends CallableDescriptor, F extends D> {
|
||||
this.outerCall = call;
|
||||
this.explicitExtensionReceiver = explicitExtensionReceiver;
|
||||
this.calleeExpressionAsThisObject = calleeExpressionAsThisObject;
|
||||
this.fakeInvokeExpression = (JetSimpleNameExpression) JetPsiFactory.createExpression(call.getCallElement().getProject(), "invoke");
|
||||
this.fakeInvokeExpression = (JetSimpleNameExpression) JetPsiFactory(call.getCallElement().getProject()).createExpression( "invoke");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+3
-2
@@ -43,6 +43,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.context.ContextDependency.INDEPENDENT;
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
@@ -108,8 +109,8 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
return getTypeInfoWhenOnlyOneBranchIsPresent(
|
||||
elseBranch, elseScope, elseInfo, thenInfo, contextWithExpectedType, ifExpression, isStatement);
|
||||
}
|
||||
JetBlockExpression thenBlock = JetPsiFactory.wrapInABlock(thenBranch);
|
||||
JetBlockExpression elseBlock = JetPsiFactory.wrapInABlock(elseBranch);
|
||||
JetBlockExpression thenBlock = JetPsiFactory(ifExpression.getProject()).wrapInABlock(thenBranch);
|
||||
JetBlockExpression elseBlock = JetPsiFactory(ifExpression.getProject()).wrapInABlock(elseBranch);
|
||||
Call callForIf = createCallForSpecialConstruction(ifExpression, ifExpression, Lists.newArrayList(thenBlock, elseBlock));
|
||||
MutableDataFlowInfoForArguments dataFlowInfoForArguments =
|
||||
createDataFlowInfoForArgumentsForIfCall(callForIf, thenInfo, elseInfo);
|
||||
|
||||
+4
-3
@@ -57,6 +57,7 @@ import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
|
||||
|
||||
@@ -220,7 +221,7 @@ public class ExpressionTypingUtils {
|
||||
@NotNull JetScope scope,
|
||||
@NotNull ModuleDescriptor module
|
||||
) {
|
||||
JetImportDirective importDirective = JetPsiFactory.createImportDirective(project, callableFQN.asString());
|
||||
JetImportDirective importDirective = JetPsiFactory(project).createImportDirective(callableFQN.asString());
|
||||
|
||||
Collection<? extends DeclarationDescriptor> declarationDescriptors = new QualifiedExpressionResolver()
|
||||
.analyseImportReference(importDirective, scope, new BindingTraceContext(), module);
|
||||
@@ -332,7 +333,7 @@ public class ExpressionTypingUtils {
|
||||
@NotNull String argumentName,
|
||||
@NotNull JetType argumentType
|
||||
) {
|
||||
JetExpression fakeExpression = JetPsiFactory.createExpression(project, argumentName);
|
||||
JetExpression fakeExpression = JetPsiFactory(project).createExpression(argumentName);
|
||||
trace.record(EXPRESSION_TYPE, fakeExpression, argumentType);
|
||||
trace.record(PROCESSED, fakeExpression);
|
||||
return fakeExpression;
|
||||
@@ -364,7 +365,7 @@ public class ExpressionTypingUtils {
|
||||
@NotNull List<JetExpression> valueArguments,
|
||||
@NotNull Name name
|
||||
) {
|
||||
final JetReferenceExpression fake = JetPsiFactory.createSimpleName(expressionTypingServices.getProject(), "fake");
|
||||
final JetReferenceExpression fake = JetPsiFactory(expressionTypingServices.getProject()).createSimpleName("fake");
|
||||
TemporaryBindingTrace fakeTrace = TemporaryBindingTrace.create(context.trace, "trace to resolve fake call for", name);
|
||||
Call call = CallMaker.makeCallWithExpressions(fake, receiver, null, fake, valueArguments);
|
||||
OverloadResolutionResults<FunctionDescriptor> results =
|
||||
|
||||
+2
-2
@@ -25,7 +25,6 @@ import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory1;
|
||||
import org.jetbrains.jet.lang.psi.Call;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
@@ -42,6 +41,7 @@ import javax.inject.Inject;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||
import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.isBoolean;
|
||||
|
||||
@@ -67,7 +67,7 @@ public class ForLoopConventionsChecker {
|
||||
}
|
||||
|
||||
public boolean isVariableIterable(@NotNull VariableDescriptor variableDescriptor, @NotNull JetScope scope) {
|
||||
JetExpression expression = JetPsiFactory.createExpression(project, "fake");
|
||||
JetExpression expression = JetPsiFactory(project).createExpression("fake");
|
||||
ExpressionReceiver expressionReceiver = new ExpressionReceiver(expression, variableDescriptor.getType());
|
||||
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
||||
expressionTypingServices,
|
||||
|
||||
@@ -58,7 +58,6 @@ import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.diagnostics.Severity;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.JvmResolveUtil;
|
||||
@@ -92,6 +91,7 @@ import static org.jetbrains.jet.ConfigurationKind.JDK_AND_ANNOTATIONS;
|
||||
import static org.jetbrains.jet.cli.jvm.JVMConfigurationKeys.ANNOTATIONS_PATH_KEY;
|
||||
import static org.jetbrains.jet.cli.jvm.JVMConfigurationKeys.CLASSPATH_KEY;
|
||||
import static org.jetbrains.jet.jvm.compiler.LoadDescriptorUtil.compileKotlinToDirAndGetAnalyzeExhaust;
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class JetTestUtils {
|
||||
private static final Pattern KT_FILES = Pattern.compile(".*?.kt");
|
||||
@@ -812,7 +812,7 @@ public class JetTestUtils {
|
||||
|
||||
public static JetFile loadJetFile(@NotNull Project project, @NotNull File ioFile) throws IOException {
|
||||
String text = FileUtil.loadFile(ioFile, true);
|
||||
return JetPsiFactory.createPhysicalFile(project, ioFile.getName(), text);
|
||||
return JetPsiFactory(project).createPhysicalFile(ioFile.getName(), text);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -32,6 +32,8 @@ import java.util.Collection;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class JetPsiUtilTest extends JetLiteFixture {
|
||||
public void testUnquotedIdentifier() {
|
||||
Assert.assertEquals("", JetPsiUtil.unquoteIdentifier(""));
|
||||
@@ -70,7 +72,7 @@ public class JetPsiUtilTest extends JetLiteFixture {
|
||||
|
||||
public void testIsLocalClass() throws IOException {
|
||||
String text = FileUtil.loadFile(new File(getTestDataPath() + "/psiUtil/isLocalClass.kt"), true);
|
||||
JetClass aClass = JetPsiFactory.createClass(getProject(), text);
|
||||
JetClass aClass = JetPsiFactory(getProject()).createClass(text);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<JetClassOrObject> classOrObjects = PsiTreeUtil.collectElementsOfType(aClass, JetClassOrObject.class);
|
||||
@@ -101,7 +103,7 @@ public class JetPsiUtilTest extends JetLiteFixture {
|
||||
|
||||
private ImportPath getImportPathFromParsed(String text) {
|
||||
JetImportDirective importDirective =
|
||||
PsiTreeUtil.findChildOfType(JetPsiFactory.createFile(getProject(), text), JetImportDirective.class);
|
||||
PsiTreeUtil.findChildOfType(JetPsiFactory(getProject()).createFile(text), JetImportDirective.class);
|
||||
|
||||
assertNotNull("At least one import directive is expected", importDirective);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class JetSimpleNameExpressionTest() : JetLiteFixture() {
|
||||
assertReceiver("1 to 2", "1")
|
||||
}
|
||||
private fun assertReceiver(exprString: String, expected: String) {
|
||||
val expression = JetPsiFactory.createExpression(getProject(), exprString) as JetBinaryExpression
|
||||
val expression = JetPsiFactory(getProject()).createExpression(exprString) as JetBinaryExpression
|
||||
Assert.assertEquals(expected, expression.getOperationReference().getReceiverExpression()!!.getText())
|
||||
}
|
||||
override fun createEnvironment(): JetCoreEnvironment {
|
||||
|
||||
+3
-1
@@ -44,6 +44,8 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public abstract class AbstractLazyResolveDescriptorRendererTest extends KotlinTestWithEnvironment {
|
||||
@Override
|
||||
protected JetCoreEnvironment createEnvironment() {
|
||||
@@ -57,7 +59,7 @@ public abstract class AbstractLazyResolveDescriptorRendererTest extends KotlinTe
|
||||
protected void doTest(@NotNull String testFile) throws IOException {
|
||||
String fileText = FileUtil.loadFile(new File(testFile), true);
|
||||
|
||||
JetFile psiFile = JetPsiFactory.createFile(getProject(), fileText);
|
||||
JetFile psiFile = JetPsiFactory(getProject()).createFile(fileText);
|
||||
Collection<JetFile> files = Lists.newArrayList(psiFile);
|
||||
|
||||
final ModuleDescriptorImpl lazyModule = AnalyzerFacadeForJVM.createJavaModule("<lazy module>");
|
||||
|
||||
+2
-2
@@ -24,7 +24,6 @@ import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.test.util.RecursiveDescriptorComparator;
|
||||
@@ -35,6 +34,7 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
import static org.jetbrains.jet.test.util.DescriptorValidator.ValidationVisitor.ALLOW_ERROR_TYPES;
|
||||
import static org.jetbrains.jet.test.util.DescriptorValidator.ValidationVisitor.FORBID_ERROR_TYPES;
|
||||
|
||||
@@ -63,7 +63,7 @@ public abstract class AbstractLazyResolveRecursiveComparingTest extends KotlinTe
|
||||
new JetTestUtils.TestFileFactoryNoModules<JetFile>() {
|
||||
@Override
|
||||
public JetFile create(String fileName, String text, Map<String, String> directives) {
|
||||
return JetPsiFactory.createFile(getProject(), fileName, text);
|
||||
return JetPsiFactory(getProject()).createFile(fileName, text);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public abstract class AbstractJetParsingTest extends ParsingTestCase {
|
||||
static {
|
||||
System.setProperty("idea.platform.prefix", "Idea");
|
||||
@@ -108,11 +110,12 @@ public abstract class AbstractJetParsingTest extends ParsingTestCase {
|
||||
}
|
||||
|
||||
private PsiFile createFile(@NotNull String filePath, @NotNull IElementType fileType) throws Exception {
|
||||
JetPsiFactory psiFactory = JetPsiFactory(myProject);
|
||||
if (fileType == JetNodeTypes.EXPRESSION_CODE_FRAGMENT) {
|
||||
return JetPsiFactory.createExpressionCodeFragment(myProject, loadFile(filePath), null);
|
||||
return psiFactory.createExpressionCodeFragment(loadFile(filePath), null);
|
||||
}
|
||||
else if (fileType == JetNodeTypes.BLOCK_CODE_FRAGMENT) {
|
||||
return JetPsiFactory.createBlockCodeFragment(myProject, loadFile(filePath), null);
|
||||
return psiFactory.createBlockCodeFragment(loadFile(filePath), null);
|
||||
}
|
||||
else {
|
||||
return createPsiFile(FileUtil.getNameWithoutExtension(PathUtil.getFileName(filePath)), loadFile(filePath));
|
||||
|
||||
@@ -45,7 +45,7 @@ public abstract class AbstractResolvedCallsTest() : JetLiteFixture() {
|
||||
public fun doTest(filePath: String) {
|
||||
val text = JetTestUtils.doLoadFile(File(filePath))!!
|
||||
|
||||
val jetFile = JetPsiFactory.createFile(getProject(), text.replace("<caret>", ""))
|
||||
val jetFile = JetPsiFactory(getProject()).createFile(text.replace("<caret>", ""))
|
||||
val bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegration(jetFile).getBindingContext()
|
||||
|
||||
val element = jetFile.findElementAt(text.indexOf("<caret>"))
|
||||
|
||||
@@ -70,7 +70,7 @@ public class MyDeclarations(
|
||||
return JetTypeImpl(Annotations.EMPTY, IntegerValueTypeConstructor(number.toLong()), false, listOf(), JetScope.EMPTY)
|
||||
}
|
||||
return typeResolver.resolveType(
|
||||
scopeToResolveTypeParameters, JetPsiFactory.createType(project, name),
|
||||
scopeToResolveTypeParameters, JetPsiFactory(project).createType(name),
|
||||
JetTestUtils.DUMMY_TRACE, true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.KotlinTestWithEnvironment;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.LazyResolveTestUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
@@ -33,6 +32,8 @@ import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class BoundsSubstitutorTest extends KotlinTestWithEnvironment {
|
||||
@Override
|
||||
protected JetCoreEnvironment createEnvironment() {
|
||||
@@ -70,7 +71,7 @@ public class BoundsSubstitutorTest extends KotlinTestWithEnvironment {
|
||||
//}
|
||||
|
||||
private void doTest(String text, String expected) {
|
||||
JetFile jetFile = JetPsiFactory.createFile(getProject(), "fun.kt", text);
|
||||
JetFile jetFile = JetPsiFactory(getProject()).createFile("fun.kt", text);
|
||||
ModuleDescriptor module = LazyResolveTestUtil.resolveLazily(Collections.singletonList(jetFile), getEnvironment());
|
||||
Collection<FunctionDescriptor> functions = module.getPackage(FqName.ROOT).getMemberScope().getFunctions(Name.identifier("f"));
|
||||
assert functions.size() == 1 : "Many functions defined";
|
||||
|
||||
@@ -43,6 +43,8 @@ import org.jetbrains.jet.storage.LockBasedStorageManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
||||
private final JetDefaultModalityModifiersTestCase tc = new JetDefaultModalityModifiersTestCase();
|
||||
|
||||
@@ -80,7 +82,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
||||
}
|
||||
|
||||
private JetScope createScope(JetScope libraryScope) {
|
||||
JetFile file = JetPsiFactory.createFile(getProject(), "abstract class C { abstract fun foo(); abstract val a: Int }");
|
||||
JetFile file = JetPsiFactory(getProject()).createFile("abstract class C { abstract fun foo(); abstract val a: Int }");
|
||||
List<JetDeclaration> declarations = file.getDeclarations();
|
||||
JetDeclaration aClass = declarations.get(0);
|
||||
assert aClass instanceof JetClass;
|
||||
@@ -106,7 +108,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
||||
}
|
||||
|
||||
private void testClassModality(String classDeclaration, ClassKind kind, Modality expectedModality) {
|
||||
JetClass aClass = JetPsiFactory.createClass(getProject(), classDeclaration);
|
||||
JetClass aClass = JetPsiFactory(getProject()).createClass(classDeclaration);
|
||||
ClassDescriptorWithResolutionScopes classDescriptor = createClassDescriptor(kind, aClass);
|
||||
|
||||
assertEquals(expectedModality, classDescriptor.getModality());
|
||||
@@ -114,7 +116,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
||||
|
||||
|
||||
private void testFunctionModality(String classWithFunction, ClassKind kind, Modality expectedFunctionModality) {
|
||||
JetClass aClass = JetPsiFactory.createClass(getProject(), classWithFunction);
|
||||
JetClass aClass = JetPsiFactory(getProject()).createClass(classWithFunction);
|
||||
ClassDescriptorWithResolutionScopes classDescriptor = createClassDescriptor(kind, aClass);
|
||||
|
||||
List<JetDeclaration> declarations = aClass.getDeclarations();
|
||||
@@ -127,7 +129,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
||||
}
|
||||
|
||||
private void testPropertyModality(String classWithProperty, ClassKind kind, Modality expectedPropertyModality) {
|
||||
JetClass aClass = JetPsiFactory.createClass(getProject(), classWithProperty);
|
||||
JetClass aClass = JetPsiFactory(getProject()).createClass(classWithProperty);
|
||||
ClassDescriptorWithResolutionScopes classDescriptor = createClassDescriptor(kind, aClass);
|
||||
|
||||
List<JetDeclaration> declarations = aClass.getDeclarations();
|
||||
@@ -140,7 +142,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
||||
|
||||
|
||||
private void testPropertyAccessorModality(String classWithPropertyWithAccessor, ClassKind kind, Modality expectedPropertyAccessorModality, boolean isGetter) {
|
||||
JetClass aClass = JetPsiFactory.createClass(getProject(), classWithPropertyWithAccessor);
|
||||
JetClass aClass = JetPsiFactory(getProject()).createClass(classWithPropertyWithAccessor);
|
||||
ClassDescriptorWithResolutionScopes classDescriptor = createClassDescriptor(kind, aClass);
|
||||
|
||||
List<JetDeclaration> declarations = aClass.getDeclarations();
|
||||
|
||||
@@ -25,12 +25,13 @@ import org.jetbrains.jet.di.InjectorForTests;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.OverloadUtil;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class JetOverloadTest extends JetLiteFixture {
|
||||
|
||||
private ModuleDescriptor root = JetTestUtils.createEmptyModule("<test_root>");
|
||||
@@ -178,7 +179,7 @@ public class JetOverloadTest extends JetLiteFixture {
|
||||
}
|
||||
|
||||
private FunctionDescriptor makeFunction(String funDecl) {
|
||||
JetNamedFunction function = JetPsiFactory.createFunction(getProject(), funDecl);
|
||||
JetNamedFunction function = JetPsiFactory(getProject()).createFunction(funDecl);
|
||||
return descriptorResolver.resolveFunctionDescriptor(root, KotlinBuiltIns.getInstance().getBuiltInsPackageScope(), function,
|
||||
JetTestUtils.DUMMY_TRACE, DataFlowInfo.EMPTY);
|
||||
}
|
||||
|
||||
@@ -25,12 +25,13 @@ import org.jetbrains.jet.di.InjectorForTests;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.OverridingUtil;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class JetOverridingTest extends JetLiteFixture {
|
||||
|
||||
private ModuleDescriptor root = JetTestUtils.createEmptyModule("<test_root>");
|
||||
@@ -168,7 +169,7 @@ public class JetOverridingTest extends JetLiteFixture {
|
||||
}
|
||||
|
||||
private FunctionDescriptor makeFunction(String funDecl) {
|
||||
JetNamedFunction function = JetPsiFactory.createFunction(getProject(), funDecl);
|
||||
JetNamedFunction function = JetPsiFactory(getProject()).createFunction(funDecl);
|
||||
return descriptorResolver.resolveFunctionDescriptor(root, KotlinBuiltIns.getInstance().getBuiltInsPackageScope(), function,
|
||||
JetTestUtils.DUMMY_TRACE, DataFlowInfo.EMPTY);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ReceiverParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.TypeResolver;
|
||||
@@ -56,6 +55,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
|
||||
private KotlinBuiltIns builtIns;
|
||||
@@ -533,14 +534,14 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
|
||||
private void assertType(String expression, JetType expectedType) {
|
||||
Project project = getProject();
|
||||
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
|
||||
JetExpression jetExpression = JetPsiFactory(project).createExpression(expression);
|
||||
JetType type = expressionTypingServices.getType(scopeWithImports, jetExpression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfo.EMPTY, JetTestUtils.DUMMY_TRACE);
|
||||
assertTrue(type + " != " + expectedType, type.equals(expectedType));
|
||||
}
|
||||
|
||||
private void assertErrorType(String expression) {
|
||||
Project project = getProject();
|
||||
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
|
||||
JetExpression jetExpression = JetPsiFactory(project).createExpression(expression);
|
||||
JetType type = expressionTypingServices.safeGetType(scopeWithImports, jetExpression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfo.EMPTY, JetTestUtils.DUMMY_TRACE);
|
||||
assertTrue("Error type expected but " + type + " returned", type.isError());
|
||||
}
|
||||
@@ -560,7 +561,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
return Lists.<ReceiverParameterDescriptor>newArrayList(new ReceiverParameterDescriptorImpl(
|
||||
getContainingDeclaration(),
|
||||
thisType,
|
||||
new ExpressionReceiver(JetPsiFactory.createExpression(getProject(), expression), thisType)
|
||||
new ExpressionReceiver(JetPsiFactory(getProject()).createExpression(expression), thisType)
|
||||
));
|
||||
}
|
||||
};
|
||||
@@ -573,7 +574,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
|
||||
private void assertType(JetScope scope, String expression, String expectedTypeStr) {
|
||||
Project project = getProject();
|
||||
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
|
||||
JetExpression jetExpression = JetPsiFactory(project).createExpression(expression);
|
||||
JetType type = expressionTypingServices.getType(
|
||||
addImports(scope), jetExpression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfo.EMPTY, new BindingTraceContext());
|
||||
JetType expectedType = expectedTypeStr == null ? null : makeType(expectedTypeStr);
|
||||
@@ -613,6 +614,6 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
}
|
||||
|
||||
private JetType makeType(JetScope scope, String typeStr) {
|
||||
return typeResolver.resolveType(scope, JetPsiFactory.createType(getProject(), typeStr), JetTestUtils.DUMMY_TRACE, true);
|
||||
return typeResolver.resolveType(scope, JetPsiFactory(getProject()).createType(typeStr), JetTestUtils.DUMMY_TRACE, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
@@ -53,6 +52,8 @@ import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
|
||||
private JetScope scope;
|
||||
@@ -81,7 +82,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
|
||||
private JetScope getContextScope() throws IOException {
|
||||
// todo comments
|
||||
String text = FileUtil.loadFile(new File("compiler/testData/type-substitutor.kt"), true);
|
||||
JetFile jetFile = JetPsiFactory.createFile(getProject(), text);
|
||||
JetFile jetFile = JetPsiFactory(getProject()).createFile(text);
|
||||
ModuleDescriptor module = LazyResolveTestUtil.resolveLazily(Collections.singletonList(jetFile), getEnvironment());
|
||||
JetScope topLevelDeclarations = module.getPackage(FqName.ROOT).getMemberScope();
|
||||
ClassifierDescriptor contextClass = topLevelDeclarations.getClassifier(Name.identifier("___Context"));
|
||||
@@ -137,7 +138,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
|
||||
}
|
||||
|
||||
private JetType resolveType(String typeStr) {
|
||||
JetTypeReference jetTypeReference = JetPsiFactory.createType(getProject(), typeStr);
|
||||
JetTypeReference jetTypeReference = JetPsiFactory(getProject()).createType(typeStr);
|
||||
AnalyzingUtils.checkForSyntacticErrors(jetTypeReference);
|
||||
BindingTrace trace = new BindingTraceContext();
|
||||
JetType type = injector.getTypeResolver().resolveType(scope, jetTypeReference, trace, true);
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.jetbrains.jet.di.InjectorForTests;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.TypeParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeProjection;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.jet.lang.resolve.TypeResolver;
|
||||
@@ -44,6 +43,8 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
|
||||
public class TypeUnifierTest extends JetLiteFixture {
|
||||
private Set<TypeConstructor> variables;
|
||||
|
||||
@@ -207,7 +208,7 @@ public class TypeUnifierTest extends JetLiteFixture {
|
||||
withX.addClassifierDescriptor(y);
|
||||
withX.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
JetTypeProjection projection = JetPsiFactory.createTypeArguments(getProject(), "<" + typeStr + ">").getArguments().get(0);
|
||||
JetTypeProjection projection = JetPsiFactory(getProject()).createTypeArguments("<" + typeStr + ">").getArguments().get(0);
|
||||
|
||||
JetTypeReference typeReference = projection.getTypeReference();
|
||||
assert typeReference != null;
|
||||
|
||||
@@ -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
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user