Add JetPsiFactory(JetElement) function and use it
This commit is contained in:
@@ -100,7 +100,7 @@ public abstract class JetCodeFragment(
|
||||
}
|
||||
|
||||
fun importsAsImportList(): JetImportList? {
|
||||
return JetPsiFactory(_project).createFile(_myImports.makeString("\n")).getImportList()
|
||||
return JetPsiFactory(this).createFile(_myImports.makeString("\n")).getImportList()
|
||||
}
|
||||
|
||||
override fun setVisibilityChecker(checker: JavaCodeFragment.VisibilityChecker?) { }
|
||||
|
||||
@@ -46,7 +46,7 @@ public abstract class JetExpressionImpl extends JetElementImpl implements JetExp
|
||||
PsiElement parent = getParent();
|
||||
if (parent instanceof JetExpression && newElement instanceof JetExpression &&
|
||||
JetPsiUtil.areParenthesesNecessary((JetExpression) newElement, this, (JetExpression) parent)) {
|
||||
return super.replace(PsiPackage.JetPsiFactory(getProject()).createExpression("(" + newElement.getText() + ")"));
|
||||
return super.replace(PsiPackage.JetPsiFactory(this).createExpression("(" + newElement.getText() + ")"));
|
||||
}
|
||||
return super.replace(newElement);
|
||||
}
|
||||
|
||||
@@ -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(PsiPackage.JetPsiFactory(getProject()).createExpression("(" + newElement.getText() + ")"));
|
||||
return super.replace(PsiPackage.JetPsiFactory(this).createExpression("(" + newElement.getText() + ")"));
|
||||
}
|
||||
return super.replace(newElement);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ abstract class JetNamedDeclarationNotStubbed extends JetDeclarationImpl implemen
|
||||
|
||||
@Override
|
||||
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
||||
return getNameIdentifier().replace(JetPsiFactory(getProject()).createNameIdentifier(name));
|
||||
return getNameIdentifier().replace(JetPsiFactory(this).createNameIdentifier(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -77,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(getProject()).createNameIdentifier(name));
|
||||
return getNameIdentifier().replace(JetPsiFactory(this).createNameIdentifier(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -49,7 +49,7 @@ public class JetObjectDeclarationName extends JetExpressionImpl {
|
||||
}
|
||||
|
||||
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
||||
return getNameIdentifier().replace(PsiPackage.JetPsiFactory(getProject()).createNameIdentifier(name));
|
||||
return getNameIdentifier().replace(PsiPackage.JetPsiFactory(this).createNameIdentifier(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lexer.JetKeywordToken
|
||||
import org.jetbrains.jet.plugin.JetFileType
|
||||
|
||||
public fun JetPsiFactory(project: Project?): JetPsiFactory = JetPsiFactory(project!!)
|
||||
public fun JetPsiFactory(contextElement: JetElement): JetPsiFactory = JetPsiFactory(contextElement.getProject())
|
||||
|
||||
public class JetPsiFactory(private val project: Project) {
|
||||
|
||||
@@ -190,7 +191,7 @@ public class JetPsiFactory(private val project: Project) {
|
||||
}
|
||||
|
||||
public fun createWhenEntry(entryText: String): JetWhenEntry {
|
||||
val function = createFunction("fun foo() { when(12) { $entryText } }")
|
||||
val function = createFunction("fun foo() { when(12) { " + entryText + " } }")
|
||||
val whenEntry = PsiTreeUtil.findChildOfType(function, javaClass<JetWhenEntry>())
|
||||
|
||||
assert(whenEntry != null, "Couldn't generate when entry")
|
||||
@@ -200,8 +201,8 @@ public class JetPsiFactory(private val project: Project) {
|
||||
}
|
||||
|
||||
public fun createBlockStringTemplateEntry(expression: JetExpression): JetStringTemplateEntryWithExpression {
|
||||
val stringTemplateExpression = createExpression("\"\${${expression.getText()}}\"") as JetStringTemplateExpression
|
||||
return stringTemplateExpression.getEntries().first() as JetStringTemplateEntryWithExpression
|
||||
val stringTemplateExpression = createExpression("\"\${" + expression.getText() + "}\"") as JetStringTemplateExpression
|
||||
return stringTemplateExpression.getEntries()[0] as JetStringTemplateEntryWithExpression
|
||||
}
|
||||
|
||||
public fun createImportDirective(path: String): JetImportDirective {
|
||||
@@ -235,15 +236,15 @@ public class JetPsiFactory(private val project: Project) {
|
||||
}
|
||||
|
||||
public fun createClassLabel(labelName: String): JetSimpleNameExpression {
|
||||
return (createExpression("this@$labelName") as JetThisExpression).getTargetLabel()!!
|
||||
return (createExpression("this@" + labelName) as JetThisExpression).getTargetLabel()!!
|
||||
}
|
||||
|
||||
public fun createFieldIdentifier(fieldName: String): JetExpression {
|
||||
return createExpression("$$fieldName")
|
||||
return createExpression("$" + fieldName)
|
||||
}
|
||||
|
||||
public fun createBinaryExpression(lhs: String, op: String, rhs: String): JetBinaryExpression {
|
||||
return createExpression("$lhs $op $rhs") as JetBinaryExpression
|
||||
return createExpression(lhs + " " + op + " " + rhs) as JetBinaryExpression
|
||||
}
|
||||
|
||||
public fun createBinaryExpression(lhs: JetExpression?, op: String, rhs: JetExpression?): JetBinaryExpression {
|
||||
@@ -549,7 +550,7 @@ public class JetPsiFactory(private val project: Project) {
|
||||
}
|
||||
|
||||
public fun createFunctionBody(bodyText: String): JetExpression {
|
||||
return createFunction("fun foo() {\n$bodyText\n}").getBodyExpression()!!
|
||||
return createFunction("fun foo() {\n" + bodyText + "\n}").getBodyExpression()!!
|
||||
}
|
||||
|
||||
public fun createEmptyClassObject(): JetClassObject {
|
||||
|
||||
@@ -110,7 +110,7 @@ public fun JetBlockExpression.prependElement(element: JetElement): JetElement =
|
||||
addBefore(element, getLBrace()!!.getNextSibling()!!)!! as JetElement
|
||||
|
||||
public fun JetElement.wrapInBlock(): JetBlockExpression {
|
||||
val block = JetPsiFactory(getProject()).createEmptyBody() as JetBlockExpression
|
||||
val block = JetPsiFactory(this).createEmptyBody() as JetBlockExpression
|
||||
block.appendElement(this)
|
||||
return block
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
@@ -173,17 +172,17 @@ public class DelegatedPropertyResolver {
|
||||
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
||||
expressionTypingServices, trace, scope,
|
||||
DataFlowInfo.EMPTY, TypeUtils.NO_EXPECTED_TYPE);
|
||||
Project project = expressionTypingServices.getProject();
|
||||
|
||||
boolean hasThis = propertyDescriptor.getReceiverParameter() != null || propertyDescriptor.getExpectedThisObject() != null;
|
||||
|
||||
List<JetExpression> arguments = Lists.newArrayList();
|
||||
arguments.add(JetPsiFactory(project).createExpression(hasThis ? "this" : "null"));
|
||||
JetPsiFactory psiFactory = JetPsiFactory(delegateExpression);
|
||||
arguments.add(psiFactory.createExpression(hasThis ? "this" : "null"));
|
||||
|
||||
arguments.add(JetPsiFactory(project).createExpression(KotlinBuiltIns.getInstance().getPropertyMetadataImpl().getName().asString() +
|
||||
"(\"" +
|
||||
propertyDescriptor.getName().asString() +
|
||||
"\")"));
|
||||
arguments.add(psiFactory.createExpression(KotlinBuiltIns.getInstance().getPropertyMetadataImpl().getName().asString() +
|
||||
"(\"" +
|
||||
propertyDescriptor.getName().asString() +
|
||||
"\")"));
|
||||
|
||||
if (!isGet) {
|
||||
JetReferenceExpression fakeArgument = (JetReferenceExpression) createFakeExpressionOfType(expressionTypingServices.getProject(), trace,
|
||||
@@ -195,7 +194,7 @@ public class DelegatedPropertyResolver {
|
||||
}
|
||||
|
||||
Name functionName = Name.identifier(isGet ? "get" : "set");
|
||||
JetReferenceExpression fakeCalleeExpression = JetPsiFactory(project).createSimpleName(functionName.asString());
|
||||
JetReferenceExpression fakeCalleeExpression = psiFactory.createSimpleName(functionName.asString());
|
||||
|
||||
ExpressionReceiver receiver = new ExpressionReceiver(delegateExpression, delegateType);
|
||||
Call call = CallMaker.makeCallWithExpressions(fakeCalleeExpression, receiver, null, fakeCalleeExpression, arguments, Call.CallType.DEFAULT);
|
||||
|
||||
@@ -264,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(call.getCallElement().getProject()).createExpression( "invoke");
|
||||
this.fakeInvokeExpression = (JetSimpleNameExpression) JetPsiFactory(call.getCallElement()).createExpression( "invoke");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+3
-2
@@ -109,8 +109,9 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
return getTypeInfoWhenOnlyOneBranchIsPresent(
|
||||
elseBranch, elseScope, elseInfo, thenInfo, contextWithExpectedType, ifExpression, isStatement);
|
||||
}
|
||||
JetBlockExpression thenBlock = JetPsiFactory(ifExpression.getProject()).wrapInABlock(thenBranch);
|
||||
JetBlockExpression elseBlock = JetPsiFactory(ifExpression.getProject()).wrapInABlock(elseBranch);
|
||||
JetPsiFactory psiFactory = JetPsiFactory(ifExpression);
|
||||
JetBlockExpression thenBlock = psiFactory.wrapInABlock(thenBranch);
|
||||
JetBlockExpression elseBlock = psiFactory.wrapInABlock(elseBranch);
|
||||
Call callForIf = createCallForSpecialConstruction(ifExpression, ifExpression, Lists.newArrayList(thenBlock, elseBlock));
|
||||
MutableDataFlowInfoForArguments dataFlowInfoForArguments =
|
||||
createDataFlowInfoForArgumentsForIfCall(callForIf, thenInfo, elseInfo);
|
||||
|
||||
+1
-3
@@ -209,19 +209,17 @@ public class ExpressionTypingUtils {
|
||||
* Check that function or property with the given qualified name can be resolved in given scope and called on given receiver
|
||||
*
|
||||
* @param callableFQN
|
||||
* @param project
|
||||
* @param scope
|
||||
* @return
|
||||
*/
|
||||
public static List<CallableDescriptor> canFindSuitableCall(
|
||||
@NotNull FqName callableFQN,
|
||||
@NotNull Project project,
|
||||
@NotNull JetExpression receiverExpression,
|
||||
@NotNull JetType receiverType,
|
||||
@NotNull JetScope scope,
|
||||
@NotNull ModuleDescriptor module
|
||||
) {
|
||||
JetImportDirective importDirective = JetPsiFactory(project).createImportDirective(callableFQN.asString());
|
||||
JetImportDirective importDirective = JetPsiFactory(receiverExpression).createImportDirective(callableFQN.asString());
|
||||
|
||||
Collection<? extends DeclarationDescriptor> declarationDescriptors = new QualifiedExpressionResolver()
|
||||
.analyseImportReference(importDirective, scope, new BindingTraceContext(), module);
|
||||
|
||||
Reference in New Issue
Block a user