Clean up: rename Jet* to Kt*
This commit is contained in:
@@ -19,17 +19,20 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
val KotlinType.nameIfStandardType: Name?
|
||||
get() = constructor.declarationDescriptor?.takeIf(KotlinBuiltIns::isBuiltIn)?.name
|
||||
|
||||
fun KotlinType.getJetTypeFqName(printTypeArguments: Boolean): String {
|
||||
@Deprecated(message = "Use getKotlinTypeFqName(Boolean) instead")
|
||||
fun KotlinType.getJetTypeFqName(printTypeArguments: Boolean): String = getKotlinTypeFqName(printTypeArguments)
|
||||
|
||||
fun KotlinType.getKotlinTypeFqName(printTypeArguments: Boolean): String {
|
||||
val declaration = requireNotNull(constructor.declarationDescriptor) {
|
||||
"declarationDescriptor is null for constructor = $constructor with ${constructor.javaClass}"
|
||||
}
|
||||
if (declaration is TypeParameterDescriptor) {
|
||||
return StringUtil.join(declaration.upperBounds, { type -> type.getJetTypeFqName(printTypeArguments) }, "&")
|
||||
return StringUtil.join(declaration.upperBounds, { type -> type.getKotlinTypeFqName(printTypeArguments) }, "&")
|
||||
}
|
||||
|
||||
val typeArguments = arguments
|
||||
val typeArgumentsAsString = if (printTypeArguments && !typeArguments.isEmpty()) {
|
||||
val joinedTypeArguments = StringUtil.join(typeArguments, { projection -> projection.type.getJetTypeFqName(false) }, ", ")
|
||||
val joinedTypeArguments = StringUtil.join(typeArguments, { projection -> projection.type.getKotlinTypeFqName(false) }, ", ")
|
||||
|
||||
"<$joinedTypeArguments>"
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ public final class PatternBuilder {
|
||||
if (actualReceiver != null) {
|
||||
if (receiverFqName == null) return false;
|
||||
|
||||
String actualReceiverFqName = DescriptorUtilsKt.getJetTypeFqName(actualReceiver.getType(), false);
|
||||
String actualReceiverFqName = DescriptorUtilsKt.getKotlinTypeFqName(actualReceiver.getType(), false);
|
||||
|
||||
if (!actualReceiverFqName.equals(receiverFqName)) return false;
|
||||
}
|
||||
|
||||
+13
-13
@@ -111,8 +111,8 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitBlockExpression(@NotNull KtBlockExpression jetBlock, @NotNull TranslationContext context) {
|
||||
List<KtExpression> statements = jetBlock.getStatements();
|
||||
public JsNode visitBlockExpression(@NotNull KtBlockExpression ktBlockExpression, @NotNull TranslationContext context) {
|
||||
List<KtExpression> statements = ktBlockExpression.getStatements();
|
||||
JsBlock jsBlock = new JsBlock();
|
||||
for (KtExpression statement : statements) {
|
||||
JsNode jsNode = Translation.translateExpression(statement, context, jsBlock);
|
||||
@@ -131,9 +131,9 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
@Override
|
||||
public JsNode visitDestructuringDeclaration(@NotNull KtDestructuringDeclaration multiDeclaration, @NotNull TranslationContext context) {
|
||||
KtExpression jetInitializer = multiDeclaration.getInitializer();
|
||||
assert jetInitializer != null : "Initializer for multi declaration must be not null";
|
||||
JsExpression initializer = Translation.translateAsExpression(jetInitializer, context);
|
||||
KtExpression ktInitializer = multiDeclaration.getInitializer();
|
||||
assert ktInitializer != null : "Initializer for multi declaration must be not null";
|
||||
JsExpression initializer = Translation.translateAsExpression(ktInitializer, context);
|
||||
JsName parameterName = JsScope.declareTemporary();
|
||||
JsVars tempVarDeclaration = JsAstUtils.newVar(parameterName, initializer);
|
||||
MetadataProperties.setSynthetic(tempVarDeclaration, true);
|
||||
@@ -143,20 +143,20 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitReturnExpression(@NotNull KtReturnExpression jetReturnExpression, @NotNull TranslationContext context) {
|
||||
KtExpression returned = jetReturnExpression.getReturnedExpression();
|
||||
public JsNode visitReturnExpression(@NotNull KtReturnExpression ktReturnExpression, @NotNull TranslationContext context) {
|
||||
KtExpression returned = ktReturnExpression.getReturnedExpression();
|
||||
|
||||
// TODO: add related descriptor to context and use it here
|
||||
KtDeclarationWithBody parent = PsiTreeUtil.getParentOfType(jetReturnExpression, KtDeclarationWithBody.class);
|
||||
KtDeclarationWithBody parent = PsiTreeUtil.getParentOfType(ktReturnExpression, KtDeclarationWithBody.class);
|
||||
if (parent instanceof KtSecondaryConstructor) {
|
||||
ClassDescriptor classDescriptor = context.getClassDescriptor();
|
||||
assert classDescriptor != null : "Missing class descriptor in context while translating constructor: " +
|
||||
PsiUtilsKt.getTextWithLocation(jetReturnExpression);
|
||||
PsiUtilsKt.getTextWithLocation(ktReturnExpression);
|
||||
JsExpression ref = ReferenceTranslator.translateAsValueReference(classDescriptor.getThisAsReceiverParameter(), context);
|
||||
return new JsReturn(ref.source(jetReturnExpression));
|
||||
return new JsReturn(ref.source(ktReturnExpression));
|
||||
}
|
||||
|
||||
FunctionDescriptor returnTarget = getNonLocalReturnTarget(jetReturnExpression, context);
|
||||
FunctionDescriptor returnTarget = getNonLocalReturnTarget(ktReturnExpression, context);
|
||||
|
||||
JsReturn jsReturn;
|
||||
if (returned == null) {
|
||||
@@ -172,7 +172,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
KotlinType returnedType = context.bindingContext().getType(returned);
|
||||
assert returnedType != null : "Resolved return expression is expected to have type: " +
|
||||
PsiUtilsKt.getTextWithLocation(jetReturnExpression);
|
||||
PsiUtilsKt.getTextWithLocation(ktReturnExpression);
|
||||
|
||||
CallableDescriptor returnTargetOrCurrentFunction = returnTarget;
|
||||
if (returnTargetOrCurrentFunction == null) {
|
||||
@@ -188,7 +188,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
MetadataProperties.setReturnTarget(jsReturn, returnTarget);
|
||||
|
||||
return jsReturn.source(jetReturnExpression);
|
||||
return jsReturn.source(ktReturnExpression);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ public final class StringTemplateTranslator extends AbstractTranslator {
|
||||
public void visitStringTemplateEntryWithExpression(@NotNull KtStringTemplateEntryWithExpression entry) {
|
||||
KtExpression entryExpression = entry.getExpression();
|
||||
assert entryExpression != null :
|
||||
"JetStringTemplateEntryWithExpression must have not null entry expression.";
|
||||
"KtStringTemplateEntryWithExpression must have not null entry expression.";
|
||||
JsExpression translatedExpression = Translation.translateAsExpression(entryExpression, context());
|
||||
|
||||
KotlinType type = context().bindingContext().getType(entryExpression);
|
||||
|
||||
+2
-2
@@ -37,9 +37,9 @@ public abstract class TranslatorVisitor<T> extends KtVisitor<T, TranslationConte
|
||||
return emptyResult(context);
|
||||
}
|
||||
|
||||
public final void traverseContainer(@NotNull KtDeclarationContainer jetClass,
|
||||
public final void traverseContainer(@NotNull KtDeclarationContainer ktClass,
|
||||
@NotNull TranslationContext context) {
|
||||
for (KtDeclaration declaration : jetClass.getDeclarations()) {
|
||||
for (KtDeclaration declaration : ktClass.getDeclarations()) {
|
||||
declaration.accept(this, context);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -358,18 +358,18 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
|
||||
private List<JsParameter> translatePrimaryConstructorParameters() {
|
||||
List<KtParameter> parameterList = getPrimaryConstructorParameters(classDeclaration);
|
||||
List<JsParameter> result = new ArrayList<>();
|
||||
for (KtParameter jetParameter : parameterList) {
|
||||
result.add(translateParameter(jetParameter));
|
||||
for (KtParameter ktParameter : parameterList) {
|
||||
result.add(translateParameter(ktParameter));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JsParameter translateParameter(@NotNull KtParameter jetParameter) {
|
||||
DeclarationDescriptor parameterDescriptor = getDescriptorForElement(bindingContext(), jetParameter);
|
||||
private JsParameter translateParameter(@NotNull KtParameter ktParameter) {
|
||||
DeclarationDescriptor parameterDescriptor = getDescriptorForElement(bindingContext(), ktParameter);
|
||||
JsName parameterName = context().getNameForDescriptor(parameterDescriptor);
|
||||
JsParameter jsParameter = new JsParameter(parameterName);
|
||||
mayBeAddInitializerStatementForProperty(jsParameter, jetParameter);
|
||||
mayBeAddInitializerStatementForProperty(jsParameter, ktParameter);
|
||||
return jsParameter;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public class CompanionObjectIntrinsicAccessTranslator extends AbstractTranslator
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
DeclarationDescriptor referenceDescriptor = getDescriptorForReferenceExpression(context.bindingContext(), expression);
|
||||
assert referenceDescriptor != null : "JetSimpleName expression must reference a descriptor " + expression.getText();
|
||||
assert referenceDescriptor != null : "KtSimpleName expression must reference a descriptor " + expression.getText();
|
||||
return new CompanionObjectIntrinsicAccessTranslator(referenceDescriptor, context);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ public final class ReferenceAccessTranslator extends AbstractTranslator implemen
|
||||
/*package*/ static ReferenceAccessTranslator newInstance(@NotNull KtSimpleNameExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
DeclarationDescriptor referenceDescriptor = getDescriptorForReferenceExpression(context.bindingContext(), expression);
|
||||
assert referenceDescriptor != null : "JetSimpleName expression must reference a descriptor " + expression.getText();
|
||||
assert referenceDescriptor != null : "KtSimpleName expression must reference a descriptor " + expression.getText();
|
||||
return new ReferenceAccessTranslator(referenceDescriptor, context);
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ public final class BindingUtils {
|
||||
@NotNull
|
||||
private static KtParameter getParameterForDescriptor(@NotNull ValueParameterDescriptor descriptor) {
|
||||
PsiElement result = DescriptorToSourceUtils.descriptorToDeclaration(descriptor);
|
||||
assert result instanceof KtParameter : message(descriptor, "ValueParameterDescriptor should have corresponding JetParameter");
|
||||
assert result instanceof KtParameter : message(descriptor, "ValueParameterDescriptor should have corresponding KtParameter");
|
||||
return (KtParameter) result;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -132,15 +132,15 @@ public final class FunctionBodyTranslator extends AbstractTranslator {
|
||||
|
||||
@NotNull
|
||||
private JsBlock translate() {
|
||||
KtExpression jetBodyExpression = declaration.getBodyExpression();
|
||||
assert jetBodyExpression != null : "Cannot translate a body of an abstract function.";
|
||||
KtExpression ktExpression = declaration.getBodyExpression();
|
||||
assert ktExpression != null : "Cannot translate a body of an abstract function.";
|
||||
JsBlock jsBlock = new JsBlock();
|
||||
|
||||
|
||||
JsNode jsBody = Translation.translateExpression(jetBodyExpression, context(), jsBlock);
|
||||
JsNode jsBody = Translation.translateExpression(ktExpression, context(), jsBlock);
|
||||
jsBlock.getStatements().addAll(mayBeWrapWithReturn(jsBody).getStatements());
|
||||
|
||||
if (jetBodyExpression instanceof KtBlockExpression &&
|
||||
if (ktExpression instanceof KtBlockExpression &&
|
||||
descriptor.getReturnType() != null && KotlinBuiltIns.isUnit(descriptor.getReturnType()) &&
|
||||
!KotlinBuiltIns.isUnit(TranslationUtils.getReturnTypeForCoercion(descriptor))) {
|
||||
ClassDescriptor unit = context().getCurrentModule().getBuiltIns().getUnit();
|
||||
|
||||
Reference in New Issue
Block a user