Move PsiSourceElement to psi
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.source
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtPureElement
|
||||
@@ -24,5 +23,3 @@ import org.jetbrains.kotlin.psi.KtPureElement
|
||||
class KotlinSourceElement(override val psi: KtElement) : PsiSourceElement
|
||||
|
||||
fun KtPureElement?.toSourceElement(): SourceElement = if (this == null) SourceElement.NO_SOURCE else KotlinSourceElement(psiOrParent)
|
||||
|
||||
fun SourceElement.getPsi(): PsiElement? = (this as? PsiSourceElement)?.psi
|
||||
|
||||
+4
-13
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.source
|
||||
@@ -36,3 +25,5 @@ class PsiSourceFile(val psiFile: PsiFile) : SourceFile {
|
||||
|
||||
override fun getName(): String? = psiFile.virtualFile?.name
|
||||
}
|
||||
|
||||
fun SourceElement.getPsi(): PsiElement? = (this as? PsiSourceElement)?.psi
|
||||
@@ -50,7 +50,7 @@ import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.DynamicCallsKt;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElementKt;
|
||||
import org.jetbrains.kotlin.serialization.js.ModuleKind;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
|
||||
@@ -676,7 +676,7 @@ public final class StaticContext {
|
||||
JsFunction correspondingFunction = JsAstUtils.createFunctionWithEmptyBody(fragment.getScope());
|
||||
assert (!scopeToFunction.containsKey(correspondingFunction.getScope())) : "Scope to function value overridden for " + descriptor;
|
||||
scopeToFunction.put(correspondingFunction.getScope(), correspondingFunction);
|
||||
correspondingFunction.setSource(KotlinSourceElementKt.getPsi(((CallableDescriptor) descriptor).getSource()));
|
||||
correspondingFunction.setSource(PsiSourceElementKt.getPsi(((CallableDescriptor) descriptor).getSource()));
|
||||
return correspondingFunction.getScope();
|
||||
};
|
||||
Rule<JsScope> scopeForPackage = descriptor -> {
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi.KtParameter;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.BindingContextUtils;
|
||||
import org.jetbrains.kotlin.resolve.calls.components.ArgumentsUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElementKt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -46,7 +46,7 @@ class JsDataClassGenerator extends JsEqualsHashcodeToStringGenerator {
|
||||
JsFunction functionObject = generateJsMethod(function);
|
||||
JsExpression returnExpression = JsAstUtils.pureFqn(context.getNameForDescriptor(propertyDescriptor), new JsThisRef());
|
||||
JsReturn returnStatement = new JsReturn(returnExpression);
|
||||
returnStatement.setSource(KotlinSourceElementKt.getPsi(parameter.getSource()));
|
||||
returnStatement.setSource(PsiSourceElementKt.getPsi(parameter.getSource()));
|
||||
functionObject.getBody().getStatements().add(returnStatement);
|
||||
}
|
||||
|
||||
|
||||
+8
-5
@@ -8,14 +8,17 @@ package org.jetbrains.kotlin.js.translate.declaration;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.backend.common.DataClassMethodGenerator;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.kotlin.js.backend.ast.*;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.UtilsKt;
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject;
|
||||
import org.jetbrains.kotlin.psi.KtParameter;
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElementKt;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -42,7 +45,7 @@ abstract class JsEqualsHashcodeToStringGenerator extends DataClassMethodGenerato
|
||||
JsName name = context.getNameForDescriptor(classProperties.get(i));
|
||||
JsExpression literal = new JsStringLiteral((i == 0 ? (getClassDescriptor().getName() + "(") : ", ") + printName + "=");
|
||||
JsExpression expr = new JsInvocation(context.namer().kotlin("toString"), new JsNameRef(name, new JsThisRef()));
|
||||
PsiElement source = KotlinSourceElementKt.getPsi(classProperties.get(i).getSource());
|
||||
PsiElement source = PsiSourceElementKt.getPsi(classProperties.get(i).getSource());
|
||||
JsExpression component = JsAstUtils.sum(literal, expr).source(source);
|
||||
if (result == null) {
|
||||
result = component;
|
||||
@@ -79,7 +82,7 @@ abstract class JsEqualsHashcodeToStringGenerator extends DataClassMethodGenerato
|
||||
JsExpression assignment = JsAstUtils.assignment(new JsNameRef(varName),
|
||||
new JsBinaryOperation(JsBinaryOperator.BIT_OR, newHashValue,
|
||||
new JsIntLiteral(0)));
|
||||
statements.add(assignment.source(KotlinSourceElementKt.getPsi(prop.getSource())).makeStmt());
|
||||
statements.add(assignment.source(PsiSourceElementKt.getPsi(prop.getSource())).makeStmt());
|
||||
}
|
||||
|
||||
JsReturn returnStatement = new JsReturn(new JsNameRef(varName));
|
||||
@@ -106,7 +109,7 @@ abstract class JsEqualsHashcodeToStringGenerator extends DataClassMethodGenerato
|
||||
JsExpression fieldChain = null;
|
||||
for (PropertyDescriptor prop : classProperties) {
|
||||
JsName name = context.getNameForDescriptor(prop);
|
||||
PsiElement source = KotlinSourceElementKt.getPsi(prop.getSource());
|
||||
PsiElement source = PsiSourceElementKt.getPsi(prop.getSource());
|
||||
JsExpression next = new JsInvocation(context.namer().kotlin("equals"),
|
||||
new JsNameRef(name, new JsThisRef()),
|
||||
new JsNameRef(name, new JsNameRef(paramName))).source(source);
|
||||
|
||||
+4
-6
@@ -16,15 +16,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.translate.initializer;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsExpression;
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsStatement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.kotlin.js.translate.context.Namer;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElementKt;
|
||||
|
||||
import static org.jetbrains.kotlin.js.translate.utils.TranslationUtils.assignmentToBackingField;
|
||||
|
||||
@@ -39,7 +37,7 @@ public final class InitializerUtils {
|
||||
@NotNull JsExpression value
|
||||
) {
|
||||
JsExpression assignment = assignmentToBackingField(context, descriptor, value);
|
||||
assignment.setSource(KotlinSourceElementKt.getPsi(descriptor.getSource()));
|
||||
assignment.setSource(PsiSourceElementKt.getPsi(descriptor.getSource()));
|
||||
return assignment.makeStmt();
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.js.translate.reference.ReferenceTranslator;
|
||||
import org.jetbrains.kotlin.psi.KtBlockExpression;
|
||||
import org.jetbrains.kotlin.psi.KtDeclarationWithBody;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElementKt;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -97,7 +97,7 @@ public final class FunctionBodyTranslator extends AbstractTranslator {
|
||||
JsExpression defaultValue = Translation.translateAsExpression(defaultArgument, context, defaultArgBlock);
|
||||
|
||||
// parameterName = defaultValue
|
||||
PsiElement psi = KotlinSourceElementKt.getPsi(valueParameter.getSource());
|
||||
PsiElement psi = PsiSourceElementKt.getPsi(valueParameter.getSource());
|
||||
JsStatement assignStatement = assignment(jsNameRef, defaultValue).source(psi).makeStmt();
|
||||
|
||||
JsStatement thenStatement = JsAstUtils.mergeStatementInBlockIfNeeded(assignStatement, defaultArgBlock);
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.js.translate.context.Namer;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.reference.ReferenceTranslator;
|
||||
import org.jetbrains.kotlin.name.ClassId;
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElementKt;
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -486,7 +486,7 @@ public final class JsAstUtils {
|
||||
public static JsStatement defineSimpleProperty(@NotNull JsName name, @NotNull JsExpression value, @Nullable SourceElement source) {
|
||||
JsExpression assignment = assignment(new JsNameRef(name, new JsThisRef()), value);
|
||||
if (source != null) {
|
||||
assignment.setSource(KotlinSourceElementKt.getPsi(source));
|
||||
assignment.setSource(PsiSourceElementKt.getPsi(source));
|
||||
}
|
||||
return assignment.makeStmt();
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil;
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElementKt;
|
||||
import org.jetbrains.kotlin.types.DynamicTypesKt;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
@@ -74,7 +75,7 @@ public final class TranslationUtils {
|
||||
JsExpression functionExpression = function;
|
||||
if (InlineUtil.isInline(descriptor)) {
|
||||
InlineMetadata metadata = InlineMetadata.compose(function, descriptor, context);
|
||||
PsiElement sourceInfo = KotlinSourceElementKt.getPsi(descriptor.getSource());
|
||||
PsiElement sourceInfo = PsiSourceElementKt.getPsi(descriptor.getSource());
|
||||
functionExpression = metadata.functionWithMetadata(context, sourceInfo);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user