rename Jet* classes to Kt*
This commit is contained in:
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.js.analyzer.JsAnalysisResult;
|
||||
import org.jetbrains.kotlin.js.config.Config;
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.*;
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory;
|
||||
|
||||
@@ -42,7 +42,7 @@ public final class TopDownAnalyzerFacadeForJS {
|
||||
|
||||
@NotNull
|
||||
public static JsAnalysisResult analyzeFiles(
|
||||
@NotNull Collection<JetFile> files,
|
||||
@NotNull Collection<KtFile> files,
|
||||
@NotNull Config config
|
||||
) {
|
||||
BindingTrace trace = new BindingTraceContext();
|
||||
@@ -65,12 +65,12 @@ public final class TopDownAnalyzerFacadeForJS {
|
||||
|
||||
@NotNull
|
||||
public static JsAnalysisResult analyzeFilesWithGivenTrace(
|
||||
@NotNull Collection<JetFile> files,
|
||||
@NotNull Collection<KtFile> files,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull ModuleContext moduleContext,
|
||||
@NotNull Config config
|
||||
) {
|
||||
Collection<JetFile> allFiles = Config.withJsLibAdded(files, config);
|
||||
Collection<KtFile> allFiles = Config.withJsLibAdded(files, config);
|
||||
|
||||
LazyTopDownAnalyzerForTopLevel analyzerForJs = InjectionKt.createTopDownAnalyzerForJs(
|
||||
moduleContext, trace,
|
||||
@@ -80,9 +80,9 @@ public final class TopDownAnalyzerFacadeForJS {
|
||||
return JsAnalysisResult.success(trace, moduleContext.getModule());
|
||||
}
|
||||
|
||||
public static void checkForErrors(@NotNull Collection<JetFile> allFiles, @NotNull BindingContext bindingContext) {
|
||||
public static void checkForErrors(@NotNull Collection<KtFile> allFiles, @NotNull BindingContext bindingContext) {
|
||||
AnalyzingUtils.throwExceptionOnErrors(bindingContext);
|
||||
for (JetFile file : allFiles) {
|
||||
for (KtFile file : allFiles) {
|
||||
AnalyzingUtils.checkForSyntacticErrors(file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.js.PredefinedAnnotation.*
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.Severity
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.js.config.LibrarySourcesConfig
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticWithParameters1
|
||||
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils
|
||||
@@ -42,7 +42,7 @@ public class SuppressUninitializedErrorsForNativeDeclarations : DiagnosticsWithS
|
||||
if (diagnostic.getFactory() != Errors.UNINITIALIZED_VARIABLE) return false
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val diagnosticWithParameters = diagnostic as DiagnosticWithParameters1<JetSimpleNameExpression, VariableDescriptor>
|
||||
val diagnosticWithParameters = diagnostic as DiagnosticWithParameters1<KtSimpleNameExpression, VariableDescriptor>
|
||||
|
||||
val variableDescriptor = diagnosticWithParameters.getA()
|
||||
|
||||
@@ -54,6 +54,6 @@ public class SuppressWarningsFromExternalModules : DiagnosticsWithSuppression.Di
|
||||
override fun isSuppressed(diagnostic: Diagnostic): Boolean {
|
||||
val file = diagnostic.getPsiFile()
|
||||
return diagnostic.getSeverity() == Severity.WARNING &&
|
||||
file is JetFile && file.getUserData(LibrarySourcesConfig.EXTERNAL_MODULE_NAME) != null
|
||||
file is KtFile && file.getUserData(LibrarySourcesConfig.EXTERNAL_MODULE_NAME) != null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentProvider;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatformKt;
|
||||
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil;
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||
@@ -48,7 +48,7 @@ public abstract class Config {
|
||||
@NotNull
|
||||
private final LockBasedStorageManager storageManager = new LockBasedStorageManager();
|
||||
@NotNull
|
||||
private final List<JetFile> sourceFilesFromLibraries = new SmartList<JetFile>();
|
||||
private final List<KtFile> sourceFilesFromLibraries = new SmartList<KtFile>();
|
||||
@NotNull
|
||||
private final EcmaVersion target;
|
||||
|
||||
@@ -111,7 +111,7 @@ public abstract class Config {
|
||||
|
||||
public abstract boolean checkLibFilesAndReportErrors(@NotNull Function1<String, Unit> report);
|
||||
|
||||
protected abstract void init(@NotNull List<JetFile> sourceFilesInLibraries, @NotNull List<KotlinJavascriptMetadata> metadata);
|
||||
protected abstract void init(@NotNull List<KtFile> sourceFilesInLibraries, @NotNull List<KotlinJavascriptMetadata> metadata);
|
||||
|
||||
@NotNull
|
||||
public List<ModuleDescriptorImpl> getModuleDescriptors() {
|
||||
@@ -130,7 +130,7 @@ public abstract class Config {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JetFile> getSourceFilesFromLibraries() {
|
||||
public List<KtFile> getSourceFilesFromLibraries() {
|
||||
init();
|
||||
return sourceFilesFromLibraries;
|
||||
}
|
||||
@@ -169,8 +169,8 @@ public abstract class Config {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<JetFile> withJsLibAdded(@NotNull Collection<JetFile> files, @NotNull Config config) {
|
||||
Collection<JetFile> allFiles = Lists.newArrayList();
|
||||
public static Collection<KtFile> withJsLibAdded(@NotNull Collection<KtFile> files, @NotNull Config config) {
|
||||
Collection<KtFile> allFiles = Lists.newArrayList();
|
||||
allFiles.addAll(files);
|
||||
allFiles.addAll(config.getSourceFilesFromLibraries());
|
||||
return allFiles;
|
||||
|
||||
@@ -29,9 +29,9 @@ import kotlin.jvm.functions.Function1;
|
||||
import kotlin.jvm.functions.Function2;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.idea.JetFileType;
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType;
|
||||
import org.jetbrains.kotlin.js.JavaScript;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadata;
|
||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils;
|
||||
import org.jetbrains.kotlin.utils.LibraryUtils;
|
||||
@@ -88,7 +88,7 @@ public class LibrarySourcesConfig extends Config {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(@NotNull final List<JetFile> sourceFilesInLibraries, @NotNull final List<KotlinJavascriptMetadata> metadata) {
|
||||
protected void init(@NotNull final List<KtFile> sourceFilesInLibraries, @NotNull final List<KotlinJavascriptMetadata> metadata) {
|
||||
if (files.isEmpty()) return;
|
||||
|
||||
final PsiManager psiManager = PsiManager.getInstance(getProject());
|
||||
@@ -234,12 +234,12 @@ public class LibrarySourcesConfig extends Config {
|
||||
}
|
||||
}
|
||||
|
||||
protected static JetFile getJetFileByVirtualFile(VirtualFile file, String moduleName, PsiManager psiManager) {
|
||||
protected static KtFile getJetFileByVirtualFile(VirtualFile file, String moduleName, PsiManager psiManager) {
|
||||
PsiFile psiFile = psiManager.findFile(file);
|
||||
assert psiFile != null;
|
||||
|
||||
setupPsiFile(psiFile, moduleName);
|
||||
return (JetFile) psiFile;
|
||||
return (KtFile) psiFile;
|
||||
}
|
||||
|
||||
protected static void setupPsiFile(PsiFile psiFile, String moduleName) {
|
||||
@@ -247,11 +247,11 @@ public class LibrarySourcesConfig extends Config {
|
||||
}
|
||||
|
||||
private static class JetFileCollector extends VirtualFileVisitor {
|
||||
private final List<JetFile> jetFiles;
|
||||
private final List<KtFile> jetFiles;
|
||||
private final String moduleName;
|
||||
private final PsiManager psiManager;
|
||||
|
||||
private JetFileCollector(List<JetFile> files, String name, PsiManager manager) {
|
||||
private JetFileCollector(List<KtFile> files, String name, PsiManager manager) {
|
||||
moduleName = name;
|
||||
psiManager = manager;
|
||||
jetFiles = files;
|
||||
@@ -259,7 +259,7 @@ public class LibrarySourcesConfig extends Config {
|
||||
|
||||
@Override
|
||||
public boolean visitFile(@NotNull VirtualFile file) {
|
||||
if (!file.isDirectory() && StringUtil.notNullize(file.getExtension()).equalsIgnoreCase(JetFileType.EXTENSION)) {
|
||||
if (!file.isDirectory() && StringUtil.notNullize(file.getExtension()).equalsIgnoreCase(KotlinFileType.EXTENSION)) {
|
||||
jetFiles.add(getJetFileByVirtualFile(file, moduleName, psiManager));
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -22,9 +22,9 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
|
||||
public val JetType.nameIfStandardType: Name?
|
||||
public val KtType.nameIfStandardType: Name?
|
||||
get() {
|
||||
val descriptor = getConstructor().getDeclarationDescriptor()
|
||||
|
||||
@@ -35,7 +35,7 @@ public val JetType.nameIfStandardType: Name?
|
||||
return null
|
||||
}
|
||||
|
||||
public fun JetType.getJetTypeFqName(printTypeArguments: Boolean): String {
|
||||
public fun KtType.getJetTypeFqName(printTypeArguments: Boolean): String {
|
||||
val declaration = requireNotNull(getConstructor().getDeclarationDescriptor())
|
||||
if (declaration is TypeParameterDescriptor) {
|
||||
return StringUtil.join(declaration.getUpperBounds(), { type -> type.getJetTypeFqName(printTypeArguments) }, "&")
|
||||
|
||||
@@ -20,30 +20,30 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticFactory0;
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory1;
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory2;
|
||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration;
|
||||
import org.jetbrains.kotlin.psi.JetElement;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.JetNamedDeclaration;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration;
|
||||
import org.jetbrains.kotlin.psi.KtElement;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
|
||||
import static org.jetbrains.kotlin.diagnostics.PositioningStrategies.*;
|
||||
import static org.jetbrains.kotlin.diagnostics.Severity.ERROR;
|
||||
import static org.jetbrains.kotlin.diagnostics.Severity.WARNING;
|
||||
|
||||
public interface ErrorsJs {
|
||||
DiagnosticFactory1<JetElement, JetType> NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN = DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
DiagnosticFactory1<JetElement, String> NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER = DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
DiagnosticFactory1<JetElement, String> NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS = DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
DiagnosticFactory0<JetDeclaration> NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE = DiagnosticFactory0.create(ERROR, DECLARATION_RETURN_TYPE);
|
||||
DiagnosticFactory0<JetDeclaration> NATIVE_SETTER_WRONG_RETURN_TYPE = DiagnosticFactory0.create(ERROR, DECLARATION_RETURN_TYPE);
|
||||
DiagnosticFactory2<JetElement, Integer, String> NATIVE_INDEXER_WRONG_PARAMETER_COUNT = DiagnosticFactory2.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
DiagnosticFactory1<JetExpression, JsCallData> JSCODE_ERROR = DiagnosticFactory1.create(ERROR, JsCodePositioningStrategy.INSTANCE$);
|
||||
DiagnosticFactory1<JetExpression, JsCallData> JSCODE_WARNING = DiagnosticFactory1.create(WARNING, JsCodePositioningStrategy.INSTANCE$);
|
||||
DiagnosticFactory0<JetExpression> JSCODE_ARGUMENT_SHOULD_BE_CONSTANT = DiagnosticFactory0.create(ERROR, DEFAULT);
|
||||
DiagnosticFactory1<JetElement, JetElement> NOT_SUPPORTED = DiagnosticFactory1.create(ERROR, DEFAULT);
|
||||
DiagnosticFactory1<JetElement, JetElement> REFERENCE_TO_BUILTIN_MEMBERS_NOT_SUPPORTED = DiagnosticFactory1.create(ERROR, DEFAULT);
|
||||
DiagnosticFactory1<JetNamedDeclaration, String> NON_TOPLEVEL_CLASS_DECLARATION = DiagnosticFactory1.create(ERROR, DECLARATION_NAME);
|
||||
DiagnosticFactory0<JetExpression> JSCODE_NO_JAVASCRIPT_PRODUCED = DiagnosticFactory0.create(ERROR, DEFAULT);
|
||||
DiagnosticFactory1<KtElement, KtType> NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN = DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
DiagnosticFactory1<KtElement, String> NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER = DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
DiagnosticFactory1<KtElement, String> NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS = DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
DiagnosticFactory0<KtDeclaration> NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE = DiagnosticFactory0.create(ERROR, DECLARATION_RETURN_TYPE);
|
||||
DiagnosticFactory0<KtDeclaration> NATIVE_SETTER_WRONG_RETURN_TYPE = DiagnosticFactory0.create(ERROR, DECLARATION_RETURN_TYPE);
|
||||
DiagnosticFactory2<KtElement, Integer, String> NATIVE_INDEXER_WRONG_PARAMETER_COUNT = DiagnosticFactory2.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
DiagnosticFactory1<KtExpression, JsCallData> JSCODE_ERROR = DiagnosticFactory1.create(ERROR, JsCodePositioningStrategy.INSTANCE$);
|
||||
DiagnosticFactory1<KtExpression, JsCallData> JSCODE_WARNING = DiagnosticFactory1.create(WARNING, JsCodePositioningStrategy.INSTANCE$);
|
||||
DiagnosticFactory0<KtExpression> JSCODE_ARGUMENT_SHOULD_BE_CONSTANT = DiagnosticFactory0.create(ERROR, DEFAULT);
|
||||
DiagnosticFactory1<KtElement, KtElement> NOT_SUPPORTED = DiagnosticFactory1.create(ERROR, DEFAULT);
|
||||
DiagnosticFactory1<KtElement, KtElement> REFERENCE_TO_BUILTIN_MEMBERS_NOT_SUPPORTED = DiagnosticFactory1.create(ERROR, DEFAULT);
|
||||
DiagnosticFactory1<KtNamedDeclaration, String> NON_TOPLEVEL_CLASS_DECLARATION = DiagnosticFactory1.create(ERROR, DECLARATION_NAME);
|
||||
DiagnosticFactory0<KtExpression> JSCODE_NO_JAVASCRIPT_PRODUCED = DiagnosticFactory0.create(ERROR, DEFAULT);
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
Object _initializer = new Object() {
|
||||
|
||||
@@ -31,10 +31,10 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticFactory1
|
||||
import org.jetbrains.kotlin.js.parser.parse
|
||||
import org.jetbrains.kotlin.js.patterns.DescriptorPredicate
|
||||
import org.jetbrains.kotlin.js.patterns.PatternBuilder
|
||||
import org.jetbrains.kotlin.psi.JetCallExpression
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.JetLiteralStringTemplateEntry
|
||||
import org.jetbrains.kotlin.psi.JetStringTemplateExpression
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtLiteralStringTemplateEntry
|
||||
import org.jetbrains.kotlin.psi.KtStringTemplateExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.TemporaryBindingTrace
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
@@ -69,7 +69,7 @@ public class JsCallChecker(
|
||||
if (context.isAnnotationContext || !resolvedCall.isJsCall()) return
|
||||
|
||||
val expression = resolvedCall.getCall().getCallElement()
|
||||
if (expression !is JetCallExpression) return
|
||||
if (expression !is KtCallExpression) return
|
||||
|
||||
val arguments = expression.getValueArgumentList()?.getArguments()
|
||||
val argument = arguments?.firstOrNull()?.getArgumentExpression() ?: return
|
||||
@@ -102,7 +102,7 @@ public class JsCallChecker(
|
||||
}
|
||||
|
||||
class JsCodeErrorReporter(
|
||||
private val nodeToReport: JetExpression,
|
||||
private val nodeToReport: KtExpression,
|
||||
private val code: String,
|
||||
private val trace: BindingTrace
|
||||
) : ErrorReporter {
|
||||
@@ -116,7 +116,7 @@ class JsCodeErrorReporter(
|
||||
}
|
||||
|
||||
private fun report(
|
||||
diagnosticFactory: DiagnosticFactory1<JetExpression, JsCallData>,
|
||||
diagnosticFactory: DiagnosticFactory1<KtExpression, JsCallData>,
|
||||
message: String,
|
||||
startPosition: CodePosition,
|
||||
endPosition: CodePosition
|
||||
@@ -173,8 +173,8 @@ private fun String.offsetOf(position: CodePosition): Int {
|
||||
return length()
|
||||
}
|
||||
|
||||
private val JetExpression.isConstantStringLiteral: Boolean
|
||||
get() = this is JetStringTemplateExpression && getEntries().all { it is JetLiteralStringTemplateEntry }
|
||||
private val KtExpression.isConstantStringLiteral: Boolean
|
||||
get() = this is KtStringTemplateExpression && getEntries().all { it is KtLiteralStringTemplateEntry }
|
||||
|
||||
open class JsCallData(val reportRange: TextRange, val message: String)
|
||||
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.js.resolve.diagnostics
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.diagnostics.PositioningStrategy
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticWithParameters3
|
||||
import org.jetbrains.kotlin.diagnostics.ParametrizedDiagnostic
|
||||
import org.jetbrains.kotlin.js.resolve.diagnostics.JsCallData
|
||||
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticWithParameters1
|
||||
public object JsCodePositioningStrategy : PositioningStrategy<PsiElement>() {
|
||||
override fun markDiagnostic(diagnostic: ParametrizedDiagnostic<out PsiElement>): List<TextRange> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val diagnosticWithParameters = diagnostic as DiagnosticWithParameters1<JetExpression, JsCallData>
|
||||
val diagnosticWithParameters = diagnostic as DiagnosticWithParameters1<KtExpression, JsCallData>
|
||||
val textRange = diagnosticWithParameters.getA().reportRange
|
||||
return listOf(textRange)
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.js.PredefinedAnnotation
|
||||
import org.jetbrains.kotlin.js.resolve.diagnostics.ErrorsJs
|
||||
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetNamedFunction
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
@@ -36,17 +36,17 @@ import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
||||
|
||||
private abstract class AbstractNativeAnnotationsChecker(private val requiredAnnotation: PredefinedAnnotation) : DeclarationChecker {
|
||||
|
||||
open fun additionalCheck(declaration: JetNamedFunction, descriptor: FunctionDescriptor, diagnosticHolder: DiagnosticSink) {}
|
||||
open fun additionalCheck(declaration: KtNamedFunction, descriptor: FunctionDescriptor, diagnosticHolder: DiagnosticSink) {}
|
||||
|
||||
override fun check(
|
||||
declaration: JetDeclaration,
|
||||
declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
diagnosticHolder: DiagnosticSink,
|
||||
bindingContext: BindingContext
|
||||
) {
|
||||
val annotationDescriptor = descriptor.getAnnotations().findAnnotation(requiredAnnotation.fqName) ?: return
|
||||
|
||||
if (declaration !is JetNamedFunction || descriptor !is FunctionDescriptor) {
|
||||
if (declaration !is KtNamedFunction || descriptor !is FunctionDescriptor) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ private abstract class AbstractNativeIndexerChecker(
|
||||
private val requiredParametersCount: Int
|
||||
) : AbstractNativeAnnotationsChecker(requiredAnnotation) {
|
||||
|
||||
override fun additionalCheck(declaration: JetNamedFunction, descriptor: FunctionDescriptor, diagnosticHolder: DiagnosticSink) {
|
||||
override fun additionalCheck(declaration: KtNamedFunction, descriptor: FunctionDescriptor, diagnosticHolder: DiagnosticSink) {
|
||||
val parameters = descriptor.getValueParameters()
|
||||
val builtIns = descriptor.builtIns
|
||||
if (parameters.size() > 0) {
|
||||
@@ -96,7 +96,7 @@ private abstract class AbstractNativeIndexerChecker(
|
||||
}
|
||||
|
||||
public class NativeGetterChecker : AbstractNativeIndexerChecker(PredefinedAnnotation.NATIVE_GETTER, "getter", requiredParametersCount = 1) {
|
||||
override fun additionalCheck(declaration: JetNamedFunction, descriptor: FunctionDescriptor, diagnosticHolder: DiagnosticSink) {
|
||||
override fun additionalCheck(declaration: KtNamedFunction, descriptor: FunctionDescriptor, diagnosticHolder: DiagnosticSink) {
|
||||
super.additionalCheck(declaration, descriptor, diagnosticHolder)
|
||||
|
||||
val returnType = descriptor.getReturnType()
|
||||
@@ -107,7 +107,7 @@ public class NativeGetterChecker : AbstractNativeIndexerChecker(PredefinedAnnota
|
||||
}
|
||||
|
||||
public class NativeSetterChecker : AbstractNativeIndexerChecker(PredefinedAnnotation.NATIVE_SETTER, "setter", requiredParametersCount = 2) {
|
||||
override fun additionalCheck(declaration: JetNamedFunction, descriptor: FunctionDescriptor, diagnosticHolder: DiagnosticSink) {
|
||||
override fun additionalCheck(declaration: KtNamedFunction, descriptor: FunctionDescriptor, diagnosticHolder: DiagnosticSink) {
|
||||
super.additionalCheck(declaration, descriptor, diagnosticHolder)
|
||||
|
||||
val returnType = descriptor.getReturnType()
|
||||
|
||||
@@ -32,12 +32,12 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
|
||||
class ClassDeclarationChecker : DeclarationChecker {
|
||||
override fun check(
|
||||
declaration: JetDeclaration,
|
||||
declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
diagnosticHolder: DiagnosticSink,
|
||||
bindingContext: BindingContext
|
||||
) {
|
||||
if (declaration !is JetClassOrObject || declaration is JetObjectDeclaration || declaration is JetEnumEntry) return
|
||||
if (declaration !is KtClassOrObject || declaration is KtObjectDeclaration || declaration is KtEnumEntry) return
|
||||
|
||||
// hack to avoid to get diagnostics when compile kotlin builtins
|
||||
val fqNameUnsafe = DescriptorUtils.getFqName(descriptor)
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
|
||||
class KotlinJavascriptAnnotationAndConstantLoader(
|
||||
module: ModuleDescriptor
|
||||
@@ -82,7 +82,7 @@ class KotlinJavascriptAnnotationAndConstantLoader(
|
||||
override fun loadPropertyConstant(
|
||||
container: ProtoContainer,
|
||||
proto: ProtoBuf.Property,
|
||||
expectedType: JetType
|
||||
expectedType: KtType
|
||||
): ConstantValue<*>? {
|
||||
if (!proto.hasExtension(JsProtoBuf.compileTimeValue)) return null
|
||||
val value = proto.getExtension(JsProtoBuf.compileTimeValue)
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.serialization.AnnotationSerializer
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.SerializerExtension
|
||||
import org.jetbrains.kotlin.serialization.StringTableImpl
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
|
||||
public class KotlinJavascriptSerializerExtension : SerializerExtension() {
|
||||
private val stringTable = StringTableImpl()
|
||||
@@ -64,7 +64,7 @@ public class KotlinJavascriptSerializerExtension : SerializerExtension() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun serializeType(type: JetType, proto: ProtoBuf.Type.Builder) {
|
||||
override fun serializeType(type: KtType, proto: ProtoBuf.Type.Builder) {
|
||||
for (annotation in type.annotations) {
|
||||
proto.addExtension(JsProtoBuf.typeAnnotation, annotationSerializer.serializeAnnotation(annotation))
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||
import org.jetbrains.kotlin.idea.JetFileType;
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType;
|
||||
import org.jetbrains.kotlin.js.JavaScript;
|
||||
import org.jetbrains.kotlin.js.config.Config;
|
||||
import org.jetbrains.kotlin.js.config.EcmaVersion;
|
||||
@@ -45,8 +45,8 @@ import org.jetbrains.kotlin.js.test.rhino.RhinoResultChecker;
|
||||
import org.jetbrains.kotlin.js.test.utils.DirectiveTestUtils;
|
||||
import org.jetbrains.kotlin.js.test.utils.JsTestUtils;
|
||||
import org.jetbrains.kotlin.js.translate.context.Namer;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory;
|
||||
import org.jetbrains.kotlin.resolve.lazy.KotlinTestWithEnvironment;
|
||||
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||
|
||||
@@ -172,7 +172,7 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
) throws Exception {
|
||||
Project project = getProject();
|
||||
List<String> allFiles = withAdditionalKotlinFiles(files);
|
||||
List<JetFile> jetFiles = createJetFileList(project, allFiles, null);
|
||||
List<KtFile> jetFiles = createJetFileList(project, allFiles, null);
|
||||
|
||||
Config config = createConfig(getProject(), moduleName, version, libraries);
|
||||
File outputFile = new File(getOutputFilePath(testName, version));
|
||||
@@ -185,7 +185,7 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
}
|
||||
|
||||
protected void translateFiles(
|
||||
@NotNull List<JetFile> jetFiles,
|
||||
@NotNull List<KtFile> jetFiles,
|
||||
@NotNull File outputFile,
|
||||
@NotNull MainCallParameters mainCallParameters,
|
||||
@NotNull Config config
|
||||
@@ -225,8 +225,8 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void processJsProgram(@NotNull JsProgram program, @NotNull List<JetFile> jetFiles) throws Exception {
|
||||
for (JetFile file : jetFiles) {
|
||||
protected void processJsProgram(@NotNull JsProgram program, @NotNull List<KtFile> jetFiles) throws Exception {
|
||||
for (KtFile file : jetFiles) {
|
||||
String text = file.getText();
|
||||
DirectiveTestUtils.processDirectives(program, text);
|
||||
}
|
||||
@@ -254,9 +254,9 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
List<String> additionalFiles = Lists.newArrayList();
|
||||
|
||||
// add all kotlin files from testData/_commonFiles
|
||||
additionalFiles.addAll(JsTestUtils.getFilesInDirectoryByExtension(TEST_DATA_DIR_PATH + COMMON_FILES_DIR, JetFileType.EXTENSION));
|
||||
additionalFiles.addAll(JsTestUtils.getFilesInDirectoryByExtension(TEST_DATA_DIR_PATH + COMMON_FILES_DIR, KotlinFileType.EXTENSION));
|
||||
// add all kotlin files from <testDir>/_commonFiles
|
||||
additionalFiles.addAll(JsTestUtils.getFilesInDirectoryByExtension(pathToTestDir() + COMMON_FILES_DIR, JetFileType.EXTENSION));
|
||||
additionalFiles.addAll(JsTestUtils.getFilesInDirectoryByExtension(pathToTestDir() + COMMON_FILES_DIR, KotlinFileType.EXTENSION));
|
||||
|
||||
return additionalFiles;
|
||||
}
|
||||
@@ -347,8 +347,8 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
return allFiles;
|
||||
}
|
||||
|
||||
private static List<JetFile> createJetFileList(@NotNull Project project, @NotNull List<String> list, @Nullable String root) {
|
||||
List<JetFile> libFiles = Lists.newArrayList();
|
||||
private static List<KtFile> createJetFileList(@NotNull Project project, @NotNull List<String> list, @Nullable String root) {
|
||||
List<KtFile> libFiles = Lists.newArrayList();
|
||||
|
||||
PsiManager psiManager = PsiManager.getInstance(project);
|
||||
VirtualFileSystem fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL);
|
||||
@@ -360,7 +360,7 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
//TODO logging?
|
||||
assert virtualFile != null;
|
||||
PsiFile psiFile = psiManager.findFile(virtualFile);
|
||||
libFiles.add((JetFile) psiFile);
|
||||
libFiles.add((KtFile) psiFile);
|
||||
}
|
||||
return libFiles;
|
||||
}
|
||||
@@ -368,8 +368,8 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
@NotNull
|
||||
protected String getPackageName(@NotNull String filename) throws IOException {
|
||||
String content = FileUtil.loadFile(new File(filename), true);
|
||||
JetPsiFactory psiFactory = new JetPsiFactory(getProject());
|
||||
JetFile jetFile = psiFactory.createFile(content);
|
||||
KtPsiFactory psiFactory = new KtPsiFactory(getProject());
|
||||
KtFile jetFile = psiFactory.createFile(content);
|
||||
String packageName = jetFile.getPackageFqName().asString();
|
||||
return packageName.isEmpty() ? Namer.getRootPackageName() : packageName;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.js.facade.exceptions.TranslationException;
|
||||
import org.jetbrains.kotlin.js.inline.JsInliner;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.Translation;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics;
|
||||
|
||||
@@ -54,7 +54,7 @@ public final class K2JSTranslator {
|
||||
|
||||
@NotNull
|
||||
public TranslationResult translate(
|
||||
@NotNull List<JetFile> files,
|
||||
@NotNull List<KtFile> files,
|
||||
@NotNull MainCallParameters mainCallParameters
|
||||
) throws TranslationException {
|
||||
return translate(files, mainCallParameters, null);
|
||||
@@ -62,7 +62,7 @@ public final class K2JSTranslator {
|
||||
|
||||
@NotNull
|
||||
public TranslationResult translate(
|
||||
@NotNull List<JetFile> files,
|
||||
@NotNull List<KtFile> files,
|
||||
@NotNull MainCallParameters mainCallParameters,
|
||||
@Nullable JsAnalysisResult analysisResult
|
||||
) throws TranslationException {
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.js.config.Config
|
||||
import org.jetbrains.kotlin.js.sourceMap.JsSourceGenerationVisitor
|
||||
import org.jetbrains.kotlin.js.sourceMap.SourceMap3Builder
|
||||
import org.jetbrains.kotlin.js.sourceMap.SourceMapBuilder
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
|
||||
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil
|
||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils
|
||||
@@ -43,7 +43,7 @@ public abstract class TranslationResult protected constructor(public val diagnos
|
||||
|
||||
public class Success(
|
||||
private val config: Config,
|
||||
private val files: List<JetFile>,
|
||||
private val files: List<KtFile>,
|
||||
public val program: JsProgram,
|
||||
diagnostics: Diagnostics,
|
||||
private val moduleDescriptor: ModuleDescriptor
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.js.translate.callTranslator
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.psi.JetSuperExpression
|
||||
import org.jetbrains.kotlin.psi.KtSuperExpression
|
||||
import com.google.dart.compiler.backend.js.ast.JsExpression
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||
import com.google.dart.compiler.backend.js.ast.JsName
|
||||
@@ -41,7 +41,7 @@ fun CallInfo.isNative(): Boolean = AnnotationsUtils.isNativeObject(callableDescr
|
||||
|
||||
fun CallInfo.isSuperInvocation(): Boolean {
|
||||
val dispatchReceiver = resolvedCall.getDispatchReceiver()
|
||||
return dispatchReceiver is ExpressionReceiver && dispatchReceiver.getExpression() is JetSuperExpression
|
||||
return dispatchReceiver is ExpressionReceiver && dispatchReceiver.getExpression() is KtSuperExpression
|
||||
}
|
||||
|
||||
val VariableAccessInfo.variableDescriptor: VariableDescriptor
|
||||
|
||||
+9
-9
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.js.translate.reference.CallArgumentTranslator
|
||||
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils
|
||||
import org.jetbrains.kotlin.js.translate.utils.PsiUtils
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
@@ -256,31 +256,31 @@ object DynamicOperatorCallCase : FunctionCallCase() {
|
||||
fun canApply(callInfo: FunctionCallInfo): Boolean =
|
||||
callInfo.callableDescriptor.isDynamic() &&
|
||||
callInfo.resolvedCall.getCall().getCallElement() let {
|
||||
it is JetOperationExpression &&
|
||||
PsiUtils.getOperationToken(it) let { (it == JetTokens.NOT_IN || OperatorTable.hasCorrespondingOperator(it)) }
|
||||
it is KtOperationExpression &&
|
||||
PsiUtils.getOperationToken(it) let { (it == KtTokens.NOT_IN || OperatorTable.hasCorrespondingOperator(it)) }
|
||||
}
|
||||
|
||||
override fun FunctionCallInfo.dispatchReceiver(): JsExpression {
|
||||
val callElement = resolvedCall.getCall().getCallElement() as JetOperationExpression
|
||||
val callElement = resolvedCall.getCall().getCallElement() as KtOperationExpression
|
||||
val operationToken = PsiUtils.getOperationToken(callElement)
|
||||
|
||||
val arguments = argumentsInfo.translateArguments
|
||||
|
||||
return when (callElement) {
|
||||
is JetBinaryExpression -> {
|
||||
is KtBinaryExpression -> {
|
||||
// `!in` translated as `in` and will be wrapped by negation operation in BinaryOperationTranslator#translateAsOverloadedBinaryOperation by mayBeWrapWithNegation
|
||||
val operationTokenToFind = if (operationToken == JetTokens.NOT_IN) JetTokens.IN_KEYWORD else operationToken
|
||||
val operationTokenToFind = if (operationToken == KtTokens.NOT_IN) KtTokens.IN_KEYWORD else operationToken
|
||||
val binaryOperator = OperatorTable.getBinaryOperator(operationTokenToFind)
|
||||
|
||||
if (operationTokenToFind == JetTokens.IN_KEYWORD)
|
||||
if (operationTokenToFind == KtTokens.IN_KEYWORD)
|
||||
JsBinaryOperation(binaryOperator, arguments[0], dispatchReceiver)
|
||||
else
|
||||
JsBinaryOperation(binaryOperator, dispatchReceiver, arguments[0])
|
||||
}
|
||||
is JetPrefixExpression -> {
|
||||
is KtPrefixExpression -> {
|
||||
JsPrefixOperation(OperatorTable.getUnaryOperator(operationToken), dispatchReceiver)
|
||||
}
|
||||
is JetPostfixExpression -> {
|
||||
is KtPostfixExpression -> {
|
||||
// TODO drop hack with ":JsExpression" when KT-5569 will be fixed
|
||||
@Suppress("USELESS_CAST")
|
||||
(JsPostfixOperation(OperatorTable.getUnaryOperator(operationToken), dispatchReceiver) as JsExpression)
|
||||
|
||||
@@ -21,7 +21,7 @@ import gnu.trove.THashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
@@ -35,7 +35,7 @@ public class AliasingContext {
|
||||
private Map<DeclarationDescriptor, JsExpression> aliasesForDescriptors;
|
||||
|
||||
@Nullable
|
||||
private final Map<JetExpression, JsExpression> aliasesForExpressions;
|
||||
private final Map<KtExpression, JsExpression> aliasesForExpressions;
|
||||
|
||||
@Nullable
|
||||
private final AliasingContext parent;
|
||||
@@ -43,7 +43,7 @@ public class AliasingContext {
|
||||
private AliasingContext(
|
||||
@Nullable AliasingContext parent,
|
||||
@Nullable Map<DeclarationDescriptor, JsExpression> aliasesForDescriptors,
|
||||
@Nullable Map<JetExpression, JsExpression> aliasesForExpressions
|
||||
@Nullable Map<KtExpression, JsExpression> aliasesForExpressions
|
||||
) {
|
||||
this.parent = parent;
|
||||
this.aliasesForDescriptors = aliasesForDescriptors;
|
||||
@@ -61,7 +61,7 @@ public class AliasingContext {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AliasingContext withExpressionsAliased(@NotNull Map<JetExpression, JsExpression> aliasesForExpressions) {
|
||||
public AliasingContext withExpressionsAliased(@NotNull Map<KtExpression, JsExpression> aliasesForExpressions) {
|
||||
return new AliasingContext(this, null, aliasesForExpressions);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class AliasingContext {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JsExpression getAliasForExpression(@NotNull JetExpression element) {
|
||||
public JsExpression getAliasForExpression(@NotNull KtExpression element) {
|
||||
JsExpression alias = aliasesForExpressions == null ? null : aliasesForExpressions.get(element);
|
||||
return alias != null || parent == null ? alias : parent.getAliasForExpression(element);
|
||||
}
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.js.config.Config;
|
||||
import org.jetbrains.kotlin.js.translate.intrinsic.Intrinsics;
|
||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
|
||||
@@ -140,7 +140,7 @@ public class TranslationContext {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public TranslationContext innerContextWithAliasesForExpressions(@NotNull Map<JetExpression, JsExpression> aliases) {
|
||||
public TranslationContext innerContextWithAliasesForExpressions(@NotNull Map<KtExpression, JsExpression> aliases) {
|
||||
return this.innerWithAliasingContext(aliasingContext.withExpressionsAliased(aliases));
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -42,13 +42,13 @@ import org.jetbrains.kotlin.js.translate.utils.JsDescriptorUtils.getSupertypesWi
|
||||
import org.jetbrains.kotlin.js.translate.utils.PsiUtils.getPrimaryConstructorParameters
|
||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils.simpleReturnFunction
|
||||
import org.jetbrains.kotlin.js.translate.utils.jsAstUtils.toInvocationWith
|
||||
import org.jetbrains.kotlin.psi.JetClass
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject
|
||||
import org.jetbrains.kotlin.psi.JetObjectDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetSecondaryConstructor
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtSecondaryConstructor
|
||||
import org.jetbrains.kotlin.resolve.BindingContextUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.*
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import org.jetbrains.kotlin.types.TypeUtils.topologicallySortSuperclassesAndRecordAllInstances
|
||||
import org.jetbrains.kotlin.utils.identity
|
||||
@@ -58,7 +58,7 @@ import java.util.*
|
||||
* Generates a definition of a single class.
|
||||
*/
|
||||
public class ClassTranslator private constructor(
|
||||
private val classDeclaration: JetClassOrObject,
|
||||
private val classDeclaration: KtClassOrObject,
|
||||
context: TranslationContext
|
||||
) : AbstractTranslator(context) {
|
||||
|
||||
@@ -190,7 +190,7 @@ public class ClassTranslator private constructor(
|
||||
for (type in supertypes) {
|
||||
supertypeConstructors.add(type.getConstructor())
|
||||
}
|
||||
val sortedAllSuperTypes = topologicallySortSuperclassesAndRecordAllInstances(descriptor.getDefaultType(), HashMap<TypeConstructor, Set<JetType>>(), HashSet<TypeConstructor>())
|
||||
val sortedAllSuperTypes = topologicallySortSuperclassesAndRecordAllInstances(descriptor.getDefaultType(), HashMap<TypeConstructor, Set<KtType>>(), HashSet<TypeConstructor>())
|
||||
val supertypesRefs = ArrayList<JsExpression>()
|
||||
for (typeConstructor in sortedAllSuperTypes) {
|
||||
if (supertypeConstructors.contains(typeConstructor)) {
|
||||
@@ -269,7 +269,7 @@ public class ClassTranslator private constructor(
|
||||
}
|
||||
|
||||
companion object {
|
||||
public fun translate(classDeclaration: JetClass, context: TranslationContext): List<JsPropertyInitializer> {
|
||||
public fun translate(classDeclaration: KtClass, context: TranslationContext): List<JsPropertyInitializer> {
|
||||
val result = arrayListOf<JsPropertyInitializer>()
|
||||
|
||||
val classDescriptor = getClassDescriptor(context.bindingContext(), classDeclaration)
|
||||
@@ -286,16 +286,16 @@ public class ClassTranslator private constructor(
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
public fun generateClassCreation(classDeclaration: JetClassOrObject, context: TranslationContext): JsInvocation {
|
||||
public fun generateClassCreation(classDeclaration: KtClassOrObject, context: TranslationContext): JsInvocation {
|
||||
return ClassTranslator(classDeclaration, context).translate()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
public fun generateObjectLiteral(objectDeclaration: JetObjectDeclaration, context: TranslationContext): JsExpression {
|
||||
public fun generateObjectLiteral(objectDeclaration: KtObjectDeclaration, context: TranslationContext): JsExpression {
|
||||
return ClassTranslator(objectDeclaration, context).translateObjectLiteralExpression()
|
||||
}
|
||||
|
||||
private fun generateSecondaryConstructor(constructor: JetSecondaryConstructor, context: TranslationContext): JsPropertyInitializer {
|
||||
private fun generateSecondaryConstructor(constructor: KtSecondaryConstructor, context: TranslationContext): JsPropertyInitializer {
|
||||
val constructorDescriptor = BindingUtils.getDescriptorForElement(context.bindingContext(), constructor) as ConstructorDescriptor
|
||||
val classDescriptor = constructorDescriptor.getContainingDeclaration()
|
||||
|
||||
|
||||
+9
-9
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.js.translate.initializer.ClassInitializerTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.utils.BindingUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -67,15 +67,15 @@ public class DeclarationBodyVisitor extends TranslatorVisitor<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitClass(@NotNull JetClass expression, TranslationContext context) {
|
||||
public Void visitClass(@NotNull KtClass expression, TranslationContext context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitEnumEntry(@NotNull JetEnumEntry enumEntry, TranslationContext data) {
|
||||
public Void visitEnumEntry(@NotNull KtEnumEntry enumEntry, TranslationContext data) {
|
||||
JsExpression jsEnumEntryCreation;
|
||||
ClassDescriptor descriptor = getClassDescriptor(data.bindingContext(), enumEntry);
|
||||
List<JetType> supertypes = getSupertypesWithoutFakes(descriptor);
|
||||
List<KtType> supertypes = getSupertypesWithoutFakes(descriptor);
|
||||
if (enumEntry.getBody() != null || supertypes.size() > 1) {
|
||||
jsEnumEntryCreation = ClassTranslator.generateClassCreation(enumEntry, data);
|
||||
} else {
|
||||
@@ -87,7 +87,7 @@ public class DeclarationBodyVisitor extends TranslatorVisitor<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitObjectDeclaration(@NotNull JetObjectDeclaration declaration, TranslationContext context) {
|
||||
public Void visitObjectDeclaration(@NotNull KtObjectDeclaration declaration, TranslationContext context) {
|
||||
if (!declaration.isCompanion()) {
|
||||
// parsed it in initializer visitor => no additional actions are needed
|
||||
return null;
|
||||
@@ -101,7 +101,7 @@ public class DeclarationBodyVisitor extends TranslatorVisitor<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitNamedFunction(@NotNull JetNamedFunction expression, TranslationContext context) {
|
||||
public Void visitNamedFunction(@NotNull KtNamedFunction expression, TranslationContext context) {
|
||||
FunctionDescriptor descriptor = getFunctionDescriptor(context.bindingContext(), expression);
|
||||
if (descriptor.getModality() == Modality.ABSTRACT) {
|
||||
return null;
|
||||
@@ -113,20 +113,20 @@ public class DeclarationBodyVisitor extends TranslatorVisitor<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitProperty(@NotNull JetProperty expression, TranslationContext context) {
|
||||
public Void visitProperty(@NotNull KtProperty expression, TranslationContext context) {
|
||||
PropertyDescriptor propertyDescriptor = BindingUtils.getPropertyDescriptor(context.bindingContext(), expression);
|
||||
PropertyTranslatorKt.translateAccessors(propertyDescriptor, expression, result, context);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitAnonymousInitializer(@NotNull JetClassInitializer expression, TranslationContext context) {
|
||||
public Void visitAnonymousInitializer(@NotNull KtClassInitializer expression, TranslationContext context) {
|
||||
// parsed it in initializer visitor => no additional actions are needed
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitSecondaryConstructor(@NotNull JetSecondaryConstructor constructor, TranslationContext data) {
|
||||
public Void visitSecondaryConstructor(@NotNull KtSecondaryConstructor constructor, TranslationContext data) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -32,14 +32,14 @@ import org.jetbrains.kotlin.js.translate.utils.ManglingUtils.getMangledMemberNam
|
||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils.simpleReturnFunction
|
||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils.translateFunctionAsEcma5PropertyDescriptor
|
||||
import org.jetbrains.kotlin.js.translate.utils.generateDelegateCall
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject
|
||||
import org.jetbrains.kotlin.psi.JetDelegationSpecifier
|
||||
import org.jetbrains.kotlin.psi.JetDelegatorByExpressionSpecifier
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtDelegationSpecifier
|
||||
import org.jetbrains.kotlin.psi.KtDelegatorByExpressionSpecifier
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import java.util.*
|
||||
|
||||
public class DelegationTranslator(
|
||||
private val classDeclaration: JetClassOrObject,
|
||||
private val classDeclaration: KtClassOrObject,
|
||||
context: TranslationContext
|
||||
) : AbstractTranslator(context) {
|
||||
|
||||
@@ -47,10 +47,10 @@ public class DelegationTranslator(
|
||||
BindingUtils.getClassDescriptor(context.bindingContext(), classDeclaration);
|
||||
|
||||
private val delegationBySpecifiers =
|
||||
classDeclaration.getDelegationSpecifiers().filterIsInstance<JetDelegatorByExpressionSpecifier>();
|
||||
classDeclaration.getDelegationSpecifiers().filterIsInstance<KtDelegatorByExpressionSpecifier>();
|
||||
|
||||
private class Field (val name: String, val generateField: Boolean)
|
||||
private val fields = HashMap<JetDelegatorByExpressionSpecifier, Field>()
|
||||
private val fields = HashMap<KtDelegatorByExpressionSpecifier, Field>()
|
||||
|
||||
init {
|
||||
for (specifier in delegationBySpecifiers) {
|
||||
@@ -88,7 +88,7 @@ public class DelegationTranslator(
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSuperClass(specifier: JetDelegationSpecifier): ClassDescriptor =
|
||||
private fun getSuperClass(specifier: KtDelegationSpecifier): ClassDescriptor =
|
||||
CodegenUtil.getSuperClassByDelegationSpecifier(specifier, bindingContext())
|
||||
|
||||
private fun generateDelegates(toClass: ClassDescriptor, field: Field, properties: MutableList<JsPropertyInitializer>) {
|
||||
|
||||
+8
-8
@@ -27,10 +27,10 @@ import org.jetbrains.kotlin.js.translate.initializer.InitializerUtils.generateIn
|
||||
import org.jetbrains.kotlin.js.translate.initializer.InitializerVisitor
|
||||
import org.jetbrains.kotlin.js.translate.utils.BindingUtils.getPropertyDescriptor
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils
|
||||
import org.jetbrains.kotlin.psi.JetClass
|
||||
import org.jetbrains.kotlin.psi.JetClassInitializer
|
||||
import org.jetbrains.kotlin.psi.JetObjectDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetProperty
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
import org.jetbrains.kotlin.psi.KtClassInitializer
|
||||
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
|
||||
class FileDeclarationVisitor(
|
||||
val context: TranslationContext,
|
||||
@@ -50,17 +50,17 @@ class FileDeclarationVisitor(
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitClass(expression: JetClass, context: TranslationContext?): Void? {
|
||||
public override fun visitClass(expression: KtClass, context: TranslationContext?): Void? {
|
||||
result.addAll(ClassTranslator.translate(expression, context!!))
|
||||
return null
|
||||
}
|
||||
|
||||
public override fun visitObjectDeclaration(declaration: JetObjectDeclaration, context: TranslationContext?): Void? {
|
||||
public override fun visitObjectDeclaration(declaration: KtObjectDeclaration, context: TranslationContext?): Void? {
|
||||
InitializerUtils.generateObjectInitializer(declaration, initializerStatements, context!!)
|
||||
return null
|
||||
}
|
||||
|
||||
public override fun visitProperty(expression: JetProperty, context: TranslationContext?): Void? {
|
||||
public override fun visitProperty(expression: KtProperty, context: TranslationContext?): Void? {
|
||||
context!! // hack
|
||||
|
||||
super.visitProperty(expression, context)
|
||||
@@ -78,7 +78,7 @@ class FileDeclarationVisitor(
|
||||
return null
|
||||
}
|
||||
|
||||
public override fun visitAnonymousInitializer(expression: JetClassInitializer, context: TranslationContext?): Void? {
|
||||
public override fun visitAnonymousInitializer(expression: KtClassInitializer, context: TranslationContext?): Void? {
|
||||
expression.accept(initializerVisitor, initializerContext)
|
||||
return null
|
||||
}
|
||||
|
||||
+5
-5
@@ -23,8 +23,8 @@ import org.jetbrains.kotlin.descriptors.*;
|
||||
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.psi.JetClassOrObject;
|
||||
import org.jetbrains.kotlin.psi.JetParameter;
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject;
|
||||
import org.jetbrains.kotlin.psi.KtParameter;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -34,7 +34,7 @@ class JsDataClassGenerator extends DataClassMethodGenerator {
|
||||
private final TranslationContext context;
|
||||
private final List<? super JsPropertyInitializer> output;
|
||||
|
||||
JsDataClassGenerator(JetClassOrObject klass, TranslationContext context, List<? super JsPropertyInitializer> output) {
|
||||
JsDataClassGenerator(KtClassOrObject klass, TranslationContext context, List<? super JsPropertyInitializer> output) {
|
||||
super(klass, context.bindingContext());
|
||||
this.context = context;
|
||||
this.output = output;
|
||||
@@ -48,7 +48,7 @@ class JsDataClassGenerator extends DataClassMethodGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateCopyFunction(@NotNull FunctionDescriptor function, @NotNull List<JetParameter> constructorParameters) {
|
||||
public void generateCopyFunction(@NotNull FunctionDescriptor function, @NotNull List<KtParameter> constructorParameters) {
|
||||
JsFunction functionObj = generateJsMethod(function);
|
||||
JsFunctionScope funScope = functionObj.getScope();
|
||||
|
||||
@@ -56,7 +56,7 @@ class JsDataClassGenerator extends DataClassMethodGenerator {
|
||||
|
||||
List<JsExpression> constructorArguments = new ArrayList<JsExpression>(constructorParameters.size());
|
||||
for (int i = 0; i < constructorParameters.size(); i++) {
|
||||
JetParameter constructorParam = constructorParameters.get(i);
|
||||
KtParameter constructorParam = constructorParameters.get(i);
|
||||
JsName paramName = funScope.declareName(constructorParam.getName());
|
||||
|
||||
functionObj.getParameters().add(new JsParameter(paramName));
|
||||
|
||||
+5
-5
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.js.translate.context.Namer;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.BindingContextUtils;
|
||||
|
||||
@@ -33,15 +33,15 @@ import java.util.*;
|
||||
import static com.google.dart.compiler.backend.js.ast.JsVars.JsVar;
|
||||
|
||||
public final class PackageDeclarationTranslator extends AbstractTranslator {
|
||||
private final Iterable<JetFile> files;
|
||||
private final Iterable<KtFile> files;
|
||||
private final Map<PackageFragmentDescriptor, PackageTranslator> packageFragmentToTranslator =
|
||||
new LinkedHashMap<PackageFragmentDescriptor, PackageTranslator>();
|
||||
|
||||
public static List<JsStatement> translateFiles(@NotNull Collection<JetFile> files, @NotNull TranslationContext context) {
|
||||
public static List<JsStatement> translateFiles(@NotNull Collection<KtFile> files, @NotNull TranslationContext context) {
|
||||
return new PackageDeclarationTranslator(files, context).translate();
|
||||
}
|
||||
|
||||
private PackageDeclarationTranslator(@NotNull Iterable<JetFile> files, @NotNull TranslationContext context) {
|
||||
private PackageDeclarationTranslator(@NotNull Iterable<KtFile> files, @NotNull TranslationContext context) {
|
||||
super(context);
|
||||
|
||||
this.files = files;
|
||||
@@ -52,7 +52,7 @@ public final class PackageDeclarationTranslator extends AbstractTranslator {
|
||||
// predictable order
|
||||
Map<FqName, DefineInvocation> packageFqNameToDefineInvocation = new THashMap<FqName, DefineInvocation>();
|
||||
|
||||
for (JetFile file : files) {
|
||||
for (KtFile file : files) {
|
||||
PackageFragmentDescriptor packageFragment =
|
||||
BindingContextUtils.getNotNull(context().bindingContext(), BindingContext.FILE_TO_PACKAGE_FRAGMENT, file);
|
||||
|
||||
|
||||
+4
-4
@@ -27,8 +27,8 @@ import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.BindingUtils;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -64,8 +64,8 @@ final class PackageTranslator extends AbstractTranslator {
|
||||
this.visitor = visitor;
|
||||
}
|
||||
|
||||
public void translate(JetFile file) {
|
||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||
public void translate(KtFile file) {
|
||||
for (KtDeclaration declaration : file.getDeclarations()) {
|
||||
if (!AnnotationsUtils.isPredefinedObject(BindingUtils.getDescriptorForElement(bindingContext(), declaration))) {
|
||||
declaration.accept(visitor, context());
|
||||
}
|
||||
|
||||
+7
-7
@@ -32,8 +32,8 @@ import org.jetbrains.kotlin.js.translate.utils.TranslationUtils.backingFieldRefe
|
||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils.translateFunctionAsEcma5PropertyDescriptor
|
||||
import org.jetbrains.kotlin.js.translate.utils.jsAstUtils.addParameter
|
||||
import org.jetbrains.kotlin.js.translate.utils.jsAstUtils.addStatement
|
||||
import org.jetbrains.kotlin.psi.JetProperty
|
||||
import org.jetbrains.kotlin.psi.JetPropertyAccessor
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
import org.jetbrains.kotlin.psi.KtPropertyAccessor
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
@@ -45,7 +45,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||
|
||||
public fun translateAccessors(
|
||||
descriptor: PropertyDescriptor,
|
||||
declaration: JetProperty?,
|
||||
declaration: KtProperty?,
|
||||
result: MutableList<JsPropertyInitializer>,
|
||||
context: TranslationContext
|
||||
) {
|
||||
@@ -85,7 +85,7 @@ public fun MutableList<JsPropertyInitializer>.addGetterAndSetter(
|
||||
|
||||
private class PropertyTranslator(
|
||||
val descriptor: PropertyDescriptor,
|
||||
val declaration: JetProperty?,
|
||||
val declaration: KtProperty?,
|
||||
context: TranslationContext
|
||||
) : AbstractTranslator(context) {
|
||||
|
||||
@@ -105,11 +105,11 @@ private class PropertyTranslator(
|
||||
|
||||
private fun hasCustomSetter() = declaration?.getSetter() != null && getCustomSetterDeclaration().hasBody()
|
||||
|
||||
private fun getCustomGetterDeclaration(): JetPropertyAccessor =
|
||||
private fun getCustomGetterDeclaration(): KtPropertyAccessor =
|
||||
declaration?.getGetter() ?:
|
||||
throw IllegalStateException("declaration and getter should not be null descriptor=${descriptor} declaration=${declaration}")
|
||||
|
||||
private fun getCustomSetterDeclaration(): JetPropertyAccessor =
|
||||
private fun getCustomSetterDeclaration(): KtPropertyAccessor =
|
||||
declaration?.getSetter() ?:
|
||||
throw IllegalStateException("declaration and setter should not be null descriptor=${descriptor} declaration=${declaration}")
|
||||
|
||||
@@ -207,7 +207,7 @@ private class PropertyTranslator(
|
||||
private fun generateDefaultAccessor(accessorDescriptor: PropertyAccessorDescriptor, function: JsFunction): JsPropertyInitializer =
|
||||
translateFunctionAsEcma5PropertyDescriptor(function, accessorDescriptor, context())
|
||||
|
||||
private fun translateCustomAccessor(expression: JetPropertyAccessor): JsPropertyInitializer =
|
||||
private fun translateCustomAccessor(expression: KtPropertyAccessor): JsPropertyInitializer =
|
||||
Translation.functionTranslator(expression, context()).translateAsEcma5PropertyDescriptor()
|
||||
|
||||
private fun accessorDescription(accessorDescriptor: PropertyAccessorDescriptor): String {
|
||||
|
||||
+6
-6
@@ -25,13 +25,13 @@ import org.jetbrains.kotlin.js.translate.general.Translation.patternTranslator
|
||||
import org.jetbrains.kotlin.js.translate.general.Translation.translateAsStatementAndMergeInBlockIfNeeded
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils.convertToBlock
|
||||
import org.jetbrains.kotlin.psi.JetCatchClause
|
||||
import org.jetbrains.kotlin.psi.JetTypeReference
|
||||
import org.jetbrains.kotlin.psi.KtCatchClause
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.BindingContextUtils.getNotNull
|
||||
|
||||
class CatchTranslator(
|
||||
val catches: List<JetCatchClause>,
|
||||
val catches: List<KtCatchClause>,
|
||||
context: TranslationContext
|
||||
) : AbstractTranslator(context) {
|
||||
|
||||
@@ -76,7 +76,7 @@ class CatchTranslator(
|
||||
translateCatches(parameterRef, catches.iterator()))
|
||||
}
|
||||
|
||||
private fun translateCatches(parameterRef: JsNameRef, catches: Iterator<JetCatchClause>): JsStatement {
|
||||
private fun translateCatches(parameterRef: JsNameRef, catches: Iterator<KtCatchClause>): JsStatement {
|
||||
if (!catches.hasNext()) return JsThrow(parameterRef)
|
||||
|
||||
val catch = catches.next()
|
||||
@@ -98,7 +98,7 @@ class CatchTranslator(
|
||||
return JsIf(typeCheck, thenBlock, elseBlock)
|
||||
}
|
||||
|
||||
private fun translateCatchBody(context: TranslationContext, catchClause: JetCatchClause): JsBlock {
|
||||
private fun translateCatchBody(context: TranslationContext, catchClause: KtCatchClause): JsBlock {
|
||||
val catchBody = catchClause.getCatchBody()
|
||||
val jsCatchBody =
|
||||
if (catchBody != null)
|
||||
@@ -109,7 +109,7 @@ class CatchTranslator(
|
||||
return convertToBlock(jsCatchBody)
|
||||
}
|
||||
|
||||
private val JetTypeReference.isThrowable: Boolean
|
||||
private val KtTypeReference.isThrowable: Boolean
|
||||
get() {
|
||||
val jetType = getNotNull(bindingContext(), BindingContext.TYPE, this)
|
||||
val jetTypeName = jetType.getJetTypeFqName(false)
|
||||
|
||||
+58
-58
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.js.translate.operation.UnaryOperationTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.reference.*;
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.BindingContextUtils;
|
||||
@@ -45,7 +45,7 @@ import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
||||
import org.jetbrains.kotlin.resolve.constants.NullValue;
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
|
||||
import java.util.List;
|
||||
@@ -69,15 +69,15 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitConstantExpression(@NotNull JetConstantExpression expression, @NotNull TranslationContext context) {
|
||||
public JsNode visitConstantExpression(@NotNull KtConstantExpression expression, @NotNull TranslationContext context) {
|
||||
return translateConstantExpression(expression, context).source(expression);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JsNode translateConstantExpression(@NotNull JetConstantExpression expression, @NotNull TranslationContext context) {
|
||||
private static JsNode translateConstantExpression(@NotNull KtConstantExpression expression, @NotNull TranslationContext context) {
|
||||
CompileTimeConstant<?> compileTimeValue = ConstantExpressionEvaluator.getConstant(expression, context.bindingContext());
|
||||
assert compileTimeValue != null : message(expression, "Expression is not compile time value: " + expression.getText() + " ");
|
||||
JetType expectedType = context.bindingContext().getType(expression);
|
||||
KtType expectedType = context.bindingContext().getType(expression);
|
||||
ConstantValue<?> constant = compileTimeValue.toConstantValue(expectedType != null ? expectedType : TypeUtils.NO_EXPECTED_TYPE);
|
||||
if (constant instanceof NullValue) {
|
||||
return JsLiteral.NULL;
|
||||
@@ -109,10 +109,10 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitBlockExpression(@NotNull JetBlockExpression jetBlock, @NotNull TranslationContext context) {
|
||||
List<JetExpression> statements = jetBlock.getStatements();
|
||||
public JsNode visitBlockExpression(@NotNull KtBlockExpression jetBlock, @NotNull TranslationContext context) {
|
||||
List<KtExpression> statements = jetBlock.getStatements();
|
||||
JsBlock jsBlock = new JsBlock();
|
||||
for (JetExpression statement : statements) {
|
||||
for (KtExpression statement : statements) {
|
||||
JsNode jsNode = Translation.translateExpression(statement, context, jsBlock);
|
||||
JsStatement jsStatement = convertToStatement(jsNode);
|
||||
if (!JsAstUtils.isEmptyStatement(jsStatement)) {
|
||||
@@ -123,8 +123,8 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsNode visitMultiDeclaration(@NotNull JetMultiDeclaration multiDeclaration, @NotNull TranslationContext context) {
|
||||
JetExpression jetInitializer = multiDeclaration.getInitializer();
|
||||
public JsNode visitMultiDeclaration(@NotNull KtMultiDeclaration 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);
|
||||
return MultiDeclarationTranslator.translate(multiDeclaration, context.scope().declareTemporary(), initializer, context);
|
||||
@@ -132,13 +132,13 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitReturnExpression(@NotNull JetReturnExpression jetReturnExpression,
|
||||
public JsNode visitReturnExpression(@NotNull KtReturnExpression jetReturnExpression,
|
||||
@NotNull TranslationContext context) {
|
||||
JetExpression returned = jetReturnExpression.getReturnedExpression();
|
||||
KtExpression returned = jetReturnExpression.getReturnedExpression();
|
||||
|
||||
// TODO: add related descriptor to context and use it here
|
||||
JetDeclarationWithBody parent = PsiTreeUtil.getParentOfType(jetReturnExpression, JetDeclarationWithBody.class);
|
||||
if (parent instanceof JetSecondaryConstructor) {
|
||||
KtDeclarationWithBody parent = PsiTreeUtil.getParentOfType(jetReturnExpression, KtDeclarationWithBody.class);
|
||||
if (parent instanceof KtSecondaryConstructor) {
|
||||
return new JsReturn(new JsNameRef(Namer.ANOTHER_THIS_PARAMETER_NAME)).source(jetReturnExpression);
|
||||
}
|
||||
if (returned == null) {
|
||||
@@ -153,9 +153,9 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitParenthesizedExpression(@NotNull JetParenthesizedExpression expression,
|
||||
public JsNode visitParenthesizedExpression(@NotNull KtParenthesizedExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
JetExpression expressionInside = expression.getExpression();
|
||||
KtExpression expressionInside = expression.getExpression();
|
||||
if (expressionInside != null) {
|
||||
return Translation.translateExpression(expressionInside, context);
|
||||
}
|
||||
@@ -164,7 +164,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitBinaryExpression(@NotNull JetBinaryExpression expression,
|
||||
public JsNode visitBinaryExpression(@NotNull KtBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return BinaryOperationTranslator.translate(expression, context);
|
||||
}
|
||||
@@ -172,7 +172,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
@Override
|
||||
@NotNull
|
||||
// assume it is a local variable declaration
|
||||
public JsNode visitProperty(@NotNull JetProperty expression, @NotNull TranslationContext context) {
|
||||
public JsNode visitProperty(@NotNull KtProperty expression, @NotNull TranslationContext context) {
|
||||
VariableDescriptor descriptor = BindingContextUtils.getNotNull(context.bindingContext(), BindingContext.VARIABLE, expression);
|
||||
JsExpression initializer = translateInitializerForProperty(expression, context);
|
||||
if (initializer != null && JsAstUtils.isEmptyExpression(initializer)) {
|
||||
@@ -190,14 +190,14 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitCallableReferenceExpression(@NotNull JetCallableReferenceExpression expression, @NotNull TranslationContext context) {
|
||||
public JsNode visitCallableReferenceExpression(@NotNull KtCallableReferenceExpression expression, @NotNull TranslationContext context) {
|
||||
return CallableReferenceTranslator.INSTANCE$.translate(expression, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitCallExpression(
|
||||
@NotNull JetCallExpression expression,
|
||||
@NotNull KtCallExpression expression,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
return CallExpressionTranslator.translate(expression, null, context).source(expression);
|
||||
@@ -205,7 +205,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitIfExpression(@NotNull JetIfExpression expression, @NotNull TranslationContext context) {
|
||||
public JsNode visitIfExpression(@NotNull KtIfExpression expression, @NotNull TranslationContext context) {
|
||||
assert expression.getCondition() != null : "condition should not ne null: " + expression.getText();
|
||||
JsExpression testExpression = Translation.translateAsExpression(expression.getCondition(), context);
|
||||
if (JsAstUtils.isEmptyExpression(testExpression)) {
|
||||
@@ -214,8 +214,8 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
boolean isKotlinExpression = BindingContextUtilsKt.isUsedAsExpression(expression, context.bindingContext());
|
||||
|
||||
JetExpression thenExpression = expression.getThen();
|
||||
JetExpression elseExpression = expression.getElse();
|
||||
KtExpression thenExpression = expression.getThen();
|
||||
KtExpression elseExpression = expression.getElse();
|
||||
|
||||
JsStatement thenStatement =
|
||||
thenExpression != null ? Translation.translateAsStatementAndMergeInBlockIfNeeded(thenExpression, context) : null;
|
||||
@@ -236,26 +236,26 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsExpression visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression,
|
||||
public JsExpression visitSimpleNameExpression(@NotNull KtSimpleNameExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return ReferenceTranslator.translateSimpleNameWithQualifier(expression, null, context).source(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitWhileExpression(@NotNull JetWhileExpression expression, @NotNull TranslationContext context) {
|
||||
public JsNode visitWhileExpression(@NotNull KtWhileExpression expression, @NotNull TranslationContext context) {
|
||||
return LoopTranslator.createWhile(false, expression, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitDoWhileExpression(@NotNull JetDoWhileExpression expression, @NotNull TranslationContext context) {
|
||||
public JsNode visitDoWhileExpression(@NotNull KtDoWhileExpression expression, @NotNull TranslationContext context) {
|
||||
return LoopTranslator.createWhile(true, expression, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitStringTemplateExpression(@NotNull JetStringTemplateExpression expression,
|
||||
public JsNode visitStringTemplateExpression(@NotNull KtStringTemplateExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
JsStringLiteral stringLiteral = resolveAsStringConstant(expression, context);
|
||||
if (stringLiteral != null) {
|
||||
@@ -265,13 +265,13 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JsNode resolveAsTemplate(@NotNull JetStringTemplateExpression expression,
|
||||
private static JsNode resolveAsTemplate(@NotNull KtStringTemplateExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return StringTemplateTranslator.translate(expression, context);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JsStringLiteral resolveAsStringConstant(@NotNull JetExpression expression,
|
||||
private static JsStringLiteral resolveAsStringConstant(@NotNull KtExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
Object value = getCompileTimeValue(context.bindingContext(), expression);
|
||||
if (value == null) {
|
||||
@@ -284,16 +284,16 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitDotQualifiedExpression(@NotNull JetDotQualifiedExpression expression,
|
||||
public JsNode visitDotQualifiedExpression(@NotNull KtDotQualifiedExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return QualifiedExpressionTranslator.translateQualifiedExpression(expression, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsNode visitLabeledExpression(
|
||||
@NotNull JetLabeledExpression expression, TranslationContext context
|
||||
@NotNull KtLabeledExpression expression, TranslationContext context
|
||||
) {
|
||||
JetExpression baseExpression = expression.getBaseExpression();
|
||||
KtExpression baseExpression = expression.getBaseExpression();
|
||||
assert baseExpression != null;
|
||||
|
||||
if (BindingContextUtilsKt.isUsedAsExpression(expression, context.bindingContext())) {
|
||||
@@ -316,7 +316,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitPrefixExpression(
|
||||
@NotNull JetPrefixExpression expression,
|
||||
@NotNull KtPrefixExpression expression,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
return UnaryOperationTranslator.translate(expression, context).source(expression);
|
||||
@@ -324,46 +324,46 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitPostfixExpression(@NotNull JetPostfixExpression expression,
|
||||
public JsNode visitPostfixExpression(@NotNull KtPostfixExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return UnaryOperationTranslator.translate(expression, context).source(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitIsExpression(@NotNull JetIsExpression expression,
|
||||
public JsNode visitIsExpression(@NotNull KtIsExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return Translation.patternTranslator(context).translateIsExpression(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitSafeQualifiedExpression(@NotNull JetSafeQualifiedExpression expression,
|
||||
public JsNode visitSafeQualifiedExpression(@NotNull KtSafeQualifiedExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return QualifiedExpressionTranslator.translateQualifiedExpression(expression, context).source(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JsNode visitWhenExpression(@NotNull JetWhenExpression expression,
|
||||
public JsNode visitWhenExpression(@NotNull KtWhenExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return WhenTranslator.translate(expression, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitBinaryWithTypeRHSExpression(@NotNull JetBinaryExpressionWithTypeRHS expression,
|
||||
public JsNode visitBinaryWithTypeRHSExpression(@NotNull KtBinaryExpressionWithTypeRHS expression,
|
||||
@NotNull TranslationContext context) {
|
||||
JsExpression jsExpression = Translation.translateAsExpression(expression.getLeft(), context);
|
||||
|
||||
if (expression.getOperationReference().getReferencedNameElementType() != JetTokens.AS_KEYWORD)
|
||||
if (expression.getOperationReference().getReferencedNameElementType() != KtTokens.AS_KEYWORD)
|
||||
return jsExpression.source(expression);
|
||||
|
||||
JetTypeReference right = expression.getRight();
|
||||
KtTypeReference right = expression.getRight();
|
||||
assert right != null;
|
||||
|
||||
JetType rightType = BindingContextUtils.getNotNull(context.bindingContext(), BindingContext.TYPE, right);
|
||||
JetType leftType = BindingContextUtils.getTypeNotNull(context.bindingContext(), expression.getLeft());
|
||||
KtType rightType = BindingContextUtils.getNotNull(context.bindingContext(), BindingContext.TYPE, right);
|
||||
KtType leftType = BindingContextUtils.getTypeNotNull(context.bindingContext(), expression.getLeft());
|
||||
if (TypeUtils.isNullableType(rightType) || !TypeUtils.isNullableType(leftType)) {
|
||||
return jsExpression.source(expression);
|
||||
}
|
||||
@@ -373,14 +373,14 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
return TranslationUtils.sure(jsExpression, context).source(expression);
|
||||
}
|
||||
|
||||
private static String getReferencedName(JetSimpleNameExpression expression) {
|
||||
private static String getReferencedName(KtSimpleNameExpression expression) {
|
||||
return expression.getReferencedName()
|
||||
.replaceAll("^@", "")
|
||||
.replaceAll("(?:^`(.*)`$)", "$1");
|
||||
}
|
||||
|
||||
private static JsNameRef getTargetLabel(JetExpressionWithLabel expression, TranslationContext context) {
|
||||
JetSimpleNameExpression labelElement = expression.getTargetLabel();
|
||||
private static JsNameRef getTargetLabel(KtExpressionWithLabel expression, TranslationContext context) {
|
||||
KtSimpleNameExpression labelElement = expression.getTargetLabel();
|
||||
if (labelElement == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -395,27 +395,27 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitBreakExpression(@NotNull JetBreakExpression expression,
|
||||
public JsNode visitBreakExpression(@NotNull KtBreakExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return new JsBreak(getTargetLabel(expression, context)).source(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitContinueExpression(@NotNull JetContinueExpression expression,
|
||||
public JsNode visitContinueExpression(@NotNull KtContinueExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return new JsContinue(getTargetLabel(expression, context)).source(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitFunctionLiteralExpression(@NotNull JetFunctionLiteralExpression expression, @NotNull TranslationContext context) {
|
||||
public JsNode visitFunctionLiteralExpression(@NotNull KtFunctionLiteralExpression expression, @NotNull TranslationContext context) {
|
||||
return new LiteralFunctionTranslator(context).translate(expression.getFunctionLiteral());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitNamedFunction(@NotNull JetNamedFunction expression, @NotNull TranslationContext context) {
|
||||
public JsNode visitNamedFunction(@NotNull KtNamedFunction expression, @NotNull TranslationContext context) {
|
||||
JsExpression alias = new LiteralFunctionTranslator(context).translate(expression);
|
||||
|
||||
FunctionDescriptor descriptor = getFunctionDescriptor(context.bindingContext(), expression);
|
||||
@@ -432,7 +432,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitThisExpression(@NotNull JetThisExpression expression, @NotNull TranslationContext context) {
|
||||
public JsNode visitThisExpression(@NotNull KtThisExpression expression, @NotNull TranslationContext context) {
|
||||
DeclarationDescriptor thisExpression =
|
||||
getDescriptorForReferenceExpression(context.bindingContext(), expression.getInstanceReference());
|
||||
assert thisExpression != null : "This expression must reference a descriptor: " + expression.getText();
|
||||
@@ -442,14 +442,14 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitArrayAccessExpression(@NotNull JetArrayAccessExpression expression,
|
||||
public JsNode visitArrayAccessExpression(@NotNull KtArrayAccessExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return AccessTranslationUtils.translateAsGet(expression, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitSuperExpression(@NotNull JetSuperExpression expression, @NotNull TranslationContext context) {
|
||||
public JsNode visitSuperExpression(@NotNull KtSuperExpression expression, @NotNull TranslationContext context) {
|
||||
DeclarationDescriptor superClassDescriptor = context.bindingContext().get(BindingContext.REFERENCE_TARGET, expression.getInstanceReference());
|
||||
assert superClassDescriptor != null: message(expression);
|
||||
return translateAsFQReference(superClassDescriptor, context);
|
||||
@@ -457,7 +457,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitForExpression(@NotNull JetForExpression expression,
|
||||
public JsNode visitForExpression(@NotNull KtForExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return LoopTranslator.translateForExpression(expression, context).source(expression);
|
||||
}
|
||||
@@ -465,7 +465,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitTryExpression(
|
||||
@NotNull JetTryExpression expression,
|
||||
@NotNull KtTryExpression expression,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
return new TryTranslator(expression, context).translate();
|
||||
@@ -473,23 +473,23 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitThrowExpression(@NotNull JetThrowExpression expression,
|
||||
public JsNode visitThrowExpression(@NotNull KtThrowExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
JetExpression thrownExpression = expression.getThrownExpression();
|
||||
KtExpression thrownExpression = expression.getThrownExpression();
|
||||
assert thrownExpression != null : "Thrown expression must not be null";
|
||||
return new JsThrow(translateAsExpression(thrownExpression, context)).source(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitObjectLiteralExpression(@NotNull JetObjectLiteralExpression expression,
|
||||
public JsNode visitObjectLiteralExpression(@NotNull KtObjectLiteralExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return ClassTranslator.generateObjectLiteral(expression.getObjectDeclaration(), context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitObjectDeclaration(@NotNull JetObjectDeclaration expression,
|
||||
public JsNode visitObjectDeclaration(@NotNull KtObjectDeclaration expression,
|
||||
@NotNull TranslationContext context) {
|
||||
DeclarationDescriptor descriptor = getDescriptorForElement(context.bindingContext(), expression);
|
||||
JsName name = context.getNameForDescriptor(descriptor);
|
||||
|
||||
+6
-6
@@ -27,8 +27,8 @@ import org.jetbrains.kotlin.js.translate.context.Namer;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils;
|
||||
import org.jetbrains.kotlin.psi.JetDeclarationWithBody;
|
||||
import org.jetbrains.kotlin.psi.JetFunctionLiteralExpression;
|
||||
import org.jetbrains.kotlin.psi.KtDeclarationWithBody;
|
||||
import org.jetbrains.kotlin.psi.KtFunctionLiteralExpression;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
|
||||
@@ -44,7 +44,7 @@ import static org.jetbrains.kotlin.js.translate.utils.JsAstUtils.setParameters;
|
||||
|
||||
public final class FunctionTranslator extends AbstractTranslator {
|
||||
@NotNull
|
||||
public static FunctionTranslator newInstance(@NotNull JetDeclarationWithBody function,
|
||||
public static FunctionTranslator newInstance(@NotNull KtDeclarationWithBody function,
|
||||
@NotNull TranslationContext context) {
|
||||
return new FunctionTranslator(function, context);
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public final class FunctionTranslator extends AbstractTranslator {
|
||||
@NotNull
|
||||
private TranslationContext functionBodyContext;
|
||||
@NotNull
|
||||
private final JetDeclarationWithBody functionDeclaration;
|
||||
private final KtDeclarationWithBody functionDeclaration;
|
||||
@Nullable
|
||||
private JsName extensionFunctionReceiverName;
|
||||
@NotNull
|
||||
@@ -60,7 +60,7 @@ public final class FunctionTranslator extends AbstractTranslator {
|
||||
@NotNull
|
||||
private final FunctionDescriptor descriptor;
|
||||
|
||||
private FunctionTranslator(@NotNull JetDeclarationWithBody functionDeclaration, @NotNull TranslationContext context) {
|
||||
private FunctionTranslator(@NotNull KtDeclarationWithBody functionDeclaration, @NotNull TranslationContext context) {
|
||||
super(context);
|
||||
this.descriptor = getFunctionDescriptor(context.bindingContext(), functionDeclaration);
|
||||
this.functionDeclaration = functionDeclaration;
|
||||
@@ -160,6 +160,6 @@ public final class FunctionTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
private boolean isExtensionFunction() {
|
||||
return DescriptorUtils.isExtension(descriptor) && !(functionDeclaration instanceof JetFunctionLiteralExpression);
|
||||
return DescriptorUtils.isExtension(descriptor) && !(functionDeclaration instanceof KtFunctionLiteralExpression);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -30,11 +30,11 @@ import org.jetbrains.kotlin.js.translate.utils.BindingUtils.getFunctionDescripto
|
||||
import org.jetbrains.kotlin.js.translate.utils.FunctionBodyTranslator.translateFunctionBody
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils
|
||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils.simpleReturnFunction
|
||||
import org.jetbrains.kotlin.psi.JetDeclarationWithBody
|
||||
import org.jetbrains.kotlin.psi.KtDeclarationWithBody
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||
|
||||
class LiteralFunctionTranslator(context: TranslationContext) : AbstractTranslator(context) {
|
||||
fun translate(declaration: JetDeclarationWithBody): JsExpression {
|
||||
fun translate(declaration: KtDeclarationWithBody): JsExpression {
|
||||
val invokingContext = context()
|
||||
val descriptor = getFunctionDescriptor(invokingContext.bindingContext(), declaration)
|
||||
|
||||
|
||||
+10
-10
@@ -35,15 +35,15 @@ import org.jetbrains.kotlin.js.translate.utils.PsiUtils.getLoopParameter
|
||||
import org.jetbrains.kotlin.js.translate.utils.PsiUtils.getLoopRange
|
||||
import org.jetbrains.kotlin.js.translate.utils.TemporariesUtils.temporariesInitialization
|
||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.psi.JetBinaryExpression
|
||||
import org.jetbrains.kotlin.psi.JetForExpression
|
||||
import org.jetbrains.kotlin.psi.JetMultiDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetWhileExpressionBase
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtBinaryExpression
|
||||
import org.jetbrains.kotlin.psi.KtForExpression
|
||||
import org.jetbrains.kotlin.psi.KtMultiDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtWhileExpressionBase
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.getClassDescriptorForType
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
|
||||
public fun createWhile(doWhile: Boolean, expression: JetWhileExpressionBase, context: TranslationContext): JsNode {
|
||||
public fun createWhile(doWhile: Boolean, expression: KtWhileExpressionBase, context: TranslationContext): JsNode {
|
||||
val conditionExpression = expression.getCondition() ?:
|
||||
throw IllegalArgumentException("condition expression should not be null: ${expression.getText()}")
|
||||
val conditionBlock = JsBlock()
|
||||
@@ -95,7 +95,7 @@ public fun createWhile(doWhile: Boolean, expression: JetWhileExpressionBase, con
|
||||
return result.source(expression)!!
|
||||
}
|
||||
|
||||
public fun translateForExpression(expression: JetForExpression, context: TranslationContext): JsStatement {
|
||||
public fun translateForExpression(expression: KtForExpression, context: TranslationContext): JsStatement {
|
||||
val loopRange = getLoopRange(expression)
|
||||
val rangeType = getTypeForExpression(context.bindingContext(), loopRange)
|
||||
|
||||
@@ -106,7 +106,7 @@ public fun translateForExpression(expression: JetForExpression, context: Transla
|
||||
}
|
||||
|
||||
fun isForOverRangeLiteral(): Boolean =
|
||||
loopRange is JetBinaryExpression && loopRange.getOperationToken() == JetTokens.RANGE && isForOverRange()
|
||||
loopRange is KtBinaryExpression && loopRange.getOperationToken() == KtTokens.RANGE && isForOverRange()
|
||||
|
||||
fun isForOverArray(): Boolean {
|
||||
//TODO: better check
|
||||
@@ -115,7 +115,7 @@ public fun translateForExpression(expression: JetForExpression, context: Transla
|
||||
getClassDescriptorForType(rangeType).getName().asString() == "IntArray"
|
||||
}
|
||||
|
||||
val multiParameter: JetMultiDeclaration? = expression.getMultiParameter();
|
||||
val multiParameter: KtMultiDeclaration? = expression.getMultiParameter();
|
||||
|
||||
fun declareParameter(): JsName {
|
||||
val loopParameter = getLoopParameter(expression)
|
||||
@@ -150,7 +150,7 @@ public fun translateForExpression(expression: JetForExpression, context: Transla
|
||||
|
||||
// TODO: implement reverse semantics
|
||||
fun translateForOverLiteralRange(): JsStatement {
|
||||
if (loopRange !is JetBinaryExpression) throw IllegalStateException("expected JetBinaryExpression, but ${loopRange.getText()}")
|
||||
if (loopRange !is KtBinaryExpression) throw IllegalStateException("expected JetBinaryExpression, but ${loopRange.getText()}")
|
||||
|
||||
val startBlock = JsBlock()
|
||||
val leftExpression = TranslationUtils.translateLeftExpression(context, loopRange, startBlock)
|
||||
|
||||
+6
-7
@@ -23,14 +23,13 @@ import com.google.dart.compiler.backend.js.ast.JsVars;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.kotlin.js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.reference.CallExpressionTranslator;
|
||||
import org.jetbrains.kotlin.psi.JetMultiDeclaration;
|
||||
import org.jetbrains.kotlin.psi.JetMultiDeclarationEntry;
|
||||
import org.jetbrains.kotlin.psi.KtMultiDeclaration;
|
||||
import org.jetbrains.kotlin.psi.KtMultiDeclarationEntry;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.BindingContextUtils;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
@@ -45,7 +44,7 @@ public class MultiDeclarationTranslator extends AbstractTranslator {
|
||||
// if multiObjectName was init, initializer must be null
|
||||
@NotNull
|
||||
public static JsVars translate(
|
||||
@NotNull JetMultiDeclaration multiDeclaration,
|
||||
@NotNull KtMultiDeclaration multiDeclaration,
|
||||
@NotNull JsName multiObjectName,
|
||||
@Nullable JsExpression initializer,
|
||||
@NotNull TranslationContext context
|
||||
@@ -54,14 +53,14 @@ public class MultiDeclarationTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final JetMultiDeclaration multiDeclaration;
|
||||
private final KtMultiDeclaration multiDeclaration;
|
||||
@NotNull
|
||||
private final JsName multiObjectName;
|
||||
@Nullable
|
||||
private final JsExpression initializer;
|
||||
|
||||
private MultiDeclarationTranslator(
|
||||
@NotNull JetMultiDeclaration multiDeclaration,
|
||||
@NotNull KtMultiDeclaration multiDeclaration,
|
||||
@NotNull JsName multiObjectName,
|
||||
@Nullable JsExpression initializer,
|
||||
@NotNull TranslationContext context
|
||||
@@ -79,7 +78,7 @@ public class MultiDeclarationTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
JsNameRef multiObjNameRef = multiObjectName.makeRef();
|
||||
for (JetMultiDeclarationEntry entry : multiDeclaration.getEntries()) {
|
||||
for (KtMultiDeclarationEntry entry : multiDeclaration.getEntries()) {
|
||||
ResolvedCall<FunctionDescriptor> entryInitCall = context().bindingContext().get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
|
||||
assert entryInitCall != null : "Entry init call must be not null";
|
||||
JsExpression entryInitializer = CallTranslator.translate(context(), entryInitCall, multiObjNameRef);
|
||||
|
||||
+14
-14
@@ -29,11 +29,11 @@ import org.jetbrains.kotlin.js.patterns.NamePredicate;
|
||||
import org.jetbrains.kotlin.js.translate.utils.BindingUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.JetIsExpression;
|
||||
import org.jetbrains.kotlin.psi.JetTypeReference;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.psi.KtIsExpression;
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
|
||||
import static org.jetbrains.kotlin.js.translate.utils.BindingUtils.getTypeByReference;
|
||||
import static org.jetbrains.kotlin.js.translate.utils.JsAstUtils.*;
|
||||
@@ -50,9 +50,9 @@ public final class PatternTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsExpression translateIsExpression(@NotNull JetIsExpression expression) {
|
||||
public JsExpression translateIsExpression(@NotNull KtIsExpression expression) {
|
||||
JsExpression left = Translation.translateAsExpression(expression.getLeftHandSide(), context());
|
||||
JetTypeReference typeReference = expression.getTypeReference();
|
||||
KtTypeReference typeReference = expression.getTypeReference();
|
||||
assert typeReference != null;
|
||||
JsExpression result = translateIsCheck(left, typeReference);
|
||||
if (expression.isNegated()) {
|
||||
@@ -62,8 +62,8 @@ public final class PatternTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsExpression translateIsCheck(@NotNull JsExpression subject, @NotNull JetTypeReference typeReference) {
|
||||
JetType type = BindingUtils.getTypeByReference(bindingContext(), typeReference);
|
||||
public JsExpression translateIsCheck(@NotNull JsExpression subject, @NotNull KtTypeReference typeReference) {
|
||||
KtType type = BindingUtils.getTypeByReference(bindingContext(), typeReference);
|
||||
JsExpression checkFunReference = getIsTypeCheckCallable(type);
|
||||
JsInvocation isCheck = new JsInvocation(checkFunReference, subject);
|
||||
|
||||
@@ -75,7 +75,7 @@ public final class PatternTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsExpression getIsTypeCheckCallable(@NotNull JetType type) {
|
||||
public JsExpression getIsTypeCheckCallable(@NotNull KtType type) {
|
||||
JsExpression builtinCheck = getIsTypeCheckCallableForBuiltin(type);
|
||||
if (builtinCheck != null) return builtinCheck;
|
||||
|
||||
@@ -94,7 +94,7 @@ public final class PatternTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JsExpression getIsTypeCheckCallableForBuiltin(@NotNull JetType type) {
|
||||
private JsExpression getIsTypeCheckCallableForBuiltin(@NotNull KtType type) {
|
||||
Name typeName = DescriptorUtilsKt.getNameIfStandardType(type);
|
||||
|
||||
if (NamePredicate.STRING.apply(typeName)) {
|
||||
@@ -142,24 +142,24 @@ public final class PatternTranslator extends AbstractTranslator {
|
||||
return or(TranslationUtils.isNullCheck(expressionToMatch), isCheck);
|
||||
}
|
||||
|
||||
private boolean isNullable(JetTypeReference typeReference) {
|
||||
private boolean isNullable(KtTypeReference typeReference) {
|
||||
return getTypeByReference(bindingContext(), typeReference).isMarkedNullable();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JsNameRef getClassNameReference(@NotNull JetType type) {
|
||||
private JsNameRef getClassNameReference(@NotNull KtType type) {
|
||||
ClassDescriptor referencedClass = DescriptorUtils.getClassDescriptorForType(type);
|
||||
return context().getQualifiedReference(referencedClass);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsExpression translateExpressionPattern(@NotNull JsExpression expressionToMatch, @NotNull JetExpression patternExpression) {
|
||||
public JsExpression translateExpressionPattern(@NotNull JsExpression expressionToMatch, @NotNull KtExpression patternExpression) {
|
||||
JsExpression expressionToMatchAgainst = translateExpressionForExpressionPattern(patternExpression);
|
||||
return equality(expressionToMatch, expressionToMatchAgainst);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsExpression translateExpressionForExpressionPattern(@NotNull JetExpression patternExpression) {
|
||||
public JsExpression translateExpressionForExpressionPattern(@NotNull KtExpression patternExpression) {
|
||||
return Translation.translateAsExpression(patternExpression, context());
|
||||
}
|
||||
}
|
||||
|
||||
+12
-12
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.js.translate.general.Translation;
|
||||
import org.jetbrains.kotlin.js.translate.intrinsic.functions.factories.TopLevelFIF;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -38,15 +38,15 @@ import static org.jetbrains.kotlin.js.translate.utils.ErrorReportingUtils.messag
|
||||
import static org.jetbrains.kotlin.js.translate.utils.JsAstUtils.sum;
|
||||
|
||||
public final class StringTemplateTranslator extends AbstractTranslator {
|
||||
private final JetStringTemplateEntry[] expressionEntries;
|
||||
private final KtStringTemplateEntry[] expressionEntries;
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translate(@NotNull JetStringTemplateExpression expression,
|
||||
public static JsExpression translate(@NotNull KtStringTemplateExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return (new StringTemplateTranslator(expression, context).translate());
|
||||
}
|
||||
|
||||
private StringTemplateTranslator(@NotNull JetStringTemplateExpression expression,
|
||||
private StringTemplateTranslator(@NotNull KtStringTemplateExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
super(context);
|
||||
|
||||
@@ -57,13 +57,13 @@ public final class StringTemplateTranslator extends AbstractTranslator {
|
||||
@NotNull
|
||||
private JsExpression translate() {
|
||||
EntryVisitor entryVisitor = new EntryVisitor();
|
||||
for (JetStringTemplateEntry entry : expressionEntries) {
|
||||
for (KtStringTemplateEntry entry : expressionEntries) {
|
||||
entry.accept(entryVisitor);
|
||||
}
|
||||
return entryVisitor.getResultingExpression();
|
||||
}
|
||||
|
||||
private final class EntryVisitor extends JetVisitorVoid {
|
||||
private final class EntryVisitor extends KtVisitorVoid {
|
||||
|
||||
@Nullable
|
||||
private JsExpression resultingExpression = null;
|
||||
@@ -78,8 +78,8 @@ public final class StringTemplateTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitStringTemplateEntryWithExpression(@NotNull JetStringTemplateEntryWithExpression entry) {
|
||||
JetExpression entryExpression = entry.getExpression();
|
||||
public void visitStringTemplateEntryWithExpression(@NotNull KtStringTemplateEntryWithExpression entry) {
|
||||
KtExpression entryExpression = entry.getExpression();
|
||||
assert entryExpression != null :
|
||||
"JetStringTemplateEntryWithExpression must have not null entry expression.";
|
||||
JsExpression translatedExpression = Translation.translateAsExpression(entryExpression, context());
|
||||
@@ -88,7 +88,7 @@ public final class StringTemplateTranslator extends AbstractTranslator {
|
||||
return;
|
||||
}
|
||||
|
||||
JetType type = context().bindingContext().getType(entryExpression);
|
||||
KtType type = context().bindingContext().getType(entryExpression);
|
||||
if (type == null || type.isMarkedNullable()) {
|
||||
append(TopLevelFIF.TO_STRING.apply((JsExpression) null, Collections.singletonList(translatedExpression), context()));
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public final class StringTemplateTranslator extends AbstractTranslator {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean mustCallToString(@NotNull JetType type) {
|
||||
private boolean mustCallToString(@NotNull KtType type) {
|
||||
Name typeName = DescriptorUtilsKt.getNameIfStandardType(type);
|
||||
if (typeName != null) {
|
||||
//TODO: this is a hacky optimization, should use some generic approach
|
||||
@@ -115,12 +115,12 @@ public final class StringTemplateTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLiteralStringTemplateEntry(@NotNull JetLiteralStringTemplateEntry entry) {
|
||||
public void visitLiteralStringTemplateEntry(@NotNull KtLiteralStringTemplateEntry entry) {
|
||||
appendText(entry.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEscapeStringTemplateEntry(@NotNull JetEscapeStringTemplateEntry entry) {
|
||||
public void visitEscapeStringTemplateEntry(@NotNull KtEscapeStringTemplateEntry entry) {
|
||||
appendText(entry.getUnescapedValue());
|
||||
}
|
||||
|
||||
|
||||
@@ -17,15 +17,15 @@
|
||||
package org.jetbrains.kotlin.js.translate.expression
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.*
|
||||
import org.jetbrains.kotlin.psi.JetTryExpression
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.KtTryExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator
|
||||
import org.jetbrains.kotlin.js.translate.general.Translation.translateAsStatementAndMergeInBlockIfNeeded
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils.convertToBlock
|
||||
|
||||
public class TryTranslator(
|
||||
val expression: JetTryExpression,
|
||||
val expression: KtTryExpression,
|
||||
context: TranslationContext
|
||||
) : AbstractTranslator(context) {
|
||||
public fun translate(): JsTry {
|
||||
@@ -40,7 +40,7 @@ public class TryTranslator(
|
||||
return JsTry(tryBlock, catchBlock, finallyBlock)
|
||||
}
|
||||
|
||||
private fun translateAsBlock(expression: JetExpression?): JsBlock? {
|
||||
private fun translateAsBlock(expression: KtExpression?): JsBlock? {
|
||||
if (expression == null) return null
|
||||
|
||||
val statement = translateAsStatementAndMergeInBlockIfNeeded(expression, context())
|
||||
|
||||
+25
-25
@@ -31,22 +31,22 @@ import static org.jetbrains.kotlin.js.translate.utils.JsAstUtils.negated;
|
||||
|
||||
public final class WhenTranslator extends AbstractTranslator {
|
||||
@Nullable
|
||||
public static JsNode translate(@NotNull JetWhenExpression expression, @NotNull TranslationContext context) {
|
||||
public static JsNode translate(@NotNull KtWhenExpression expression, @NotNull TranslationContext context) {
|
||||
return new WhenTranslator(expression, context).translate();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final JetWhenExpression whenExpression;
|
||||
private final KtWhenExpression whenExpression;
|
||||
|
||||
@Nullable
|
||||
private final JsExpression expressionToMatch;
|
||||
|
||||
private WhenTranslator(@NotNull JetWhenExpression expression, @NotNull TranslationContext context) {
|
||||
private WhenTranslator(@NotNull KtWhenExpression expression, @NotNull TranslationContext context) {
|
||||
super(context);
|
||||
|
||||
whenExpression = expression;
|
||||
|
||||
JetExpression subject = expression.getSubjectExpression();
|
||||
KtExpression subject = expression.getSubjectExpression();
|
||||
if (subject != null) {
|
||||
JsExpression subjectExpression = Translation.translateAsExpression(subject, context);
|
||||
if (TranslationUtils.isCacheNeeded(subjectExpression)) {
|
||||
@@ -68,7 +68,7 @@ public final class WhenTranslator extends AbstractTranslator {
|
||||
|
||||
JsIf currentIf = null;
|
||||
JsIf resultIf = null;
|
||||
for (JetWhenEntry entry : whenExpression.getEntries()) {
|
||||
for (KtWhenEntry entry : whenExpression.getEntries()) {
|
||||
JsBlock statementBlock = new JsBlock();
|
||||
JsStatement statement = translateEntryExpression(entry, context(), statementBlock);
|
||||
|
||||
@@ -99,17 +99,17 @@ public final class WhenTranslator extends AbstractTranslator {
|
||||
|
||||
@NotNull
|
||||
private static JsStatement translateEntryExpression(
|
||||
@NotNull JetWhenEntry entry,
|
||||
@NotNull KtWhenEntry entry,
|
||||
@NotNull TranslationContext context,
|
||||
@NotNull JsBlock block) {
|
||||
JetExpression expressionToExecute = entry.getExpression();
|
||||
KtExpression expressionToExecute = entry.getExpression();
|
||||
assert expressionToExecute != null : "WhenEntry should have whenExpression to execute.";
|
||||
return Translation.translateAsStatement(expressionToExecute, context, block);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JsExpression translateConditions(@NotNull JetWhenEntry entry, @NotNull TranslationContext context) {
|
||||
JetWhenCondition[] conditions = entry.getConditions();
|
||||
private JsExpression translateConditions(@NotNull KtWhenEntry entry, @NotNull TranslationContext context) {
|
||||
KtWhenCondition[] conditions = entry.getConditions();
|
||||
|
||||
assert conditions.length > 0 : "When entry (not else) should have at least one condition";
|
||||
|
||||
@@ -126,7 +126,7 @@ public final class WhenTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JsExpression translateOrCondition(@NotNull JsExpression leftExpression, @NotNull JetWhenCondition condition, @NotNull TranslationContext context) {
|
||||
private JsExpression translateOrCondition(@NotNull JsExpression leftExpression, @NotNull KtWhenCondition condition, @NotNull TranslationContext context) {
|
||||
TranslationContext rightContext = context.innerBlock();
|
||||
JsExpression rightExpression = translateCondition(condition, rightContext);
|
||||
context.moveVarsFrom(rightContext);
|
||||
@@ -143,15 +143,15 @@ public final class WhenTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JsExpression translateCondition(@NotNull JetWhenCondition condition, @NotNull TranslationContext context) {
|
||||
if ((condition instanceof JetWhenConditionIsPattern) || (condition instanceof JetWhenConditionWithExpression)) {
|
||||
private JsExpression translateCondition(@NotNull KtWhenCondition condition, @NotNull TranslationContext context) {
|
||||
if ((condition instanceof KtWhenConditionIsPattern) || (condition instanceof KtWhenConditionWithExpression)) {
|
||||
return translatePatternCondition(condition, context);
|
||||
}
|
||||
throw new AssertionError("Unsupported when condition " + condition.getClass());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JsExpression translatePatternCondition(@NotNull JetWhenCondition condition, @NotNull TranslationContext context) {
|
||||
private JsExpression translatePatternCondition(@NotNull KtWhenCondition condition, @NotNull TranslationContext context) {
|
||||
JsExpression patternMatchExpression = translateWhenConditionToBooleanExpression(condition, context);
|
||||
if (isNegated(condition)) {
|
||||
return negated(patternMatchExpression);
|
||||
@@ -160,30 +160,30 @@ public final class WhenTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JsExpression translateWhenConditionToBooleanExpression(@NotNull JetWhenCondition condition, @NotNull TranslationContext context) {
|
||||
if (condition instanceof JetWhenConditionIsPattern) {
|
||||
return translateIsCondition((JetWhenConditionIsPattern) condition, context);
|
||||
private JsExpression translateWhenConditionToBooleanExpression(@NotNull KtWhenCondition condition, @NotNull TranslationContext context) {
|
||||
if (condition instanceof KtWhenConditionIsPattern) {
|
||||
return translateIsCondition((KtWhenConditionIsPattern) condition, context);
|
||||
}
|
||||
else if (condition instanceof JetWhenConditionWithExpression) {
|
||||
return translateExpressionCondition((JetWhenConditionWithExpression) condition, context);
|
||||
else if (condition instanceof KtWhenConditionWithExpression) {
|
||||
return translateExpressionCondition((KtWhenConditionWithExpression) condition, context);
|
||||
}
|
||||
throw new AssertionError("Wrong type of JetWhenCondition");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JsExpression translateIsCondition(@NotNull JetWhenConditionIsPattern conditionIsPattern, @NotNull TranslationContext context) {
|
||||
private JsExpression translateIsCondition(@NotNull KtWhenConditionIsPattern conditionIsPattern, @NotNull TranslationContext context) {
|
||||
JsExpression expressionToMatch = getExpressionToMatch();
|
||||
assert expressionToMatch != null : "An is-check is not allowed in when() without subject.";
|
||||
|
||||
JetTypeReference typeReference = conditionIsPattern.getTypeReference();
|
||||
KtTypeReference typeReference = conditionIsPattern.getTypeReference();
|
||||
assert typeReference != null : "An is-check must have a type reference.";
|
||||
|
||||
return Translation.patternTranslator(context).translateIsCheck(expressionToMatch, typeReference);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JsExpression translateExpressionCondition(@NotNull JetWhenConditionWithExpression condition, @NotNull TranslationContext context) {
|
||||
JetExpression patternExpression = condition.getExpression();
|
||||
private JsExpression translateExpressionCondition(@NotNull KtWhenConditionWithExpression condition, @NotNull TranslationContext context) {
|
||||
KtExpression patternExpression = condition.getExpression();
|
||||
assert patternExpression != null : "Expression pattern should have an expression.";
|
||||
|
||||
JsExpression expressionToMatch = getExpressionToMatch();
|
||||
@@ -200,9 +200,9 @@ public final class WhenTranslator extends AbstractTranslator {
|
||||
return expressionToMatch;
|
||||
}
|
||||
|
||||
private static boolean isNegated(@NotNull JetWhenCondition condition) {
|
||||
if (condition instanceof JetWhenConditionIsPattern) {
|
||||
return ((JetWhenConditionIsPattern)condition).isNegated();
|
||||
private static boolean isNegated(@NotNull KtWhenCondition condition) {
|
||||
if (condition instanceof KtWhenConditionIsPattern) {
|
||||
return ((KtWhenConditionIsPattern)condition).isNegated();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
+13
-13
@@ -27,12 +27,12 @@ import org.jetbrains.kotlin.descriptors.Modality;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.js.translate.utils.BindingUtils;
|
||||
import org.jetbrains.kotlin.psi.JetClass;
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.KtClass;
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -48,7 +48,7 @@ public class JetTestFunctionDetector {
|
||||
Annotations annotations = functionDescriptor.getAnnotations();
|
||||
for (AnnotationDescriptor annotation : annotations) {
|
||||
// TODO ideally we should find the fully qualified name here...
|
||||
JetType type = annotation.getType();
|
||||
KtType type = annotation.getType();
|
||||
String name = type.toString();
|
||||
if (name.equals("Test")) {
|
||||
return true;
|
||||
@@ -67,10 +67,10 @@ public class JetTestFunctionDetector {
|
||||
@NotNull
|
||||
public static List<FunctionDescriptor> getTestFunctionDescriptors(
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull Collection<JetFile> files
|
||||
@NotNull Collection<KtFile> files
|
||||
) {
|
||||
List<FunctionDescriptor> answer = Lists.newArrayList();
|
||||
for (JetFile file : files) {
|
||||
for (KtFile file : files) {
|
||||
answer.addAll(getTestFunctions(bindingContext, file.getDeclarations()));
|
||||
}
|
||||
return answer;
|
||||
@@ -79,14 +79,14 @@ public class JetTestFunctionDetector {
|
||||
@NotNull
|
||||
private static List<FunctionDescriptor> getTestFunctions(
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull List<JetDeclaration> declarations
|
||||
@NotNull List<KtDeclaration> declarations
|
||||
) {
|
||||
List<FunctionDescriptor> answer = Lists.newArrayList();
|
||||
for (JetDeclaration declaration : declarations) {
|
||||
JetScope scope = null;
|
||||
for (KtDeclaration declaration : declarations) {
|
||||
KtScope scope = null;
|
||||
|
||||
if (declaration instanceof JetClass) {
|
||||
JetClass klass = (JetClass) declaration;
|
||||
if (declaration instanceof KtClass) {
|
||||
KtClass klass = (KtClass) declaration;
|
||||
ClassDescriptor classDescriptor = BindingUtils.getClassDescriptor(bindingContext, klass);
|
||||
|
||||
if (classDescriptor.getModality() != Modality.ABSTRACT) {
|
||||
|
||||
@@ -43,10 +43,10 @@ import org.jetbrains.kotlin.js.translate.test.JSTester;
|
||||
import org.jetbrains.kotlin.js.translate.test.QUnitTester;
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.mutator.AssignToExpressionMutator;
|
||||
import org.jetbrains.kotlin.psi.JetDeclarationWithBody;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.JetNamedFunction;
|
||||
import org.jetbrains.kotlin.psi.KtDeclarationWithBody;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction;
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.BindingContextUtilsKt;
|
||||
|
||||
@@ -69,7 +69,7 @@ public final class Translation {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static FunctionTranslator functionTranslator(@NotNull JetDeclarationWithBody function,
|
||||
public static FunctionTranslator functionTranslator(@NotNull KtDeclarationWithBody function,
|
||||
@NotNull TranslationContext context) {
|
||||
return FunctionTranslator.newInstance(function, context);
|
||||
}
|
||||
@@ -80,12 +80,12 @@ public final class Translation {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsNode translateExpression(@NotNull JetExpression expression, @NotNull TranslationContext context) {
|
||||
public static JsNode translateExpression(@NotNull KtExpression expression, @NotNull TranslationContext context) {
|
||||
return translateExpression(expression, context, context.dynamicContext().jsBlock());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsNode translateExpression(@NotNull JetExpression expression, @NotNull TranslationContext context, @NotNull JsBlock block) {
|
||||
public static JsNode translateExpression(@NotNull KtExpression expression, @NotNull TranslationContext context, @NotNull JsBlock block) {
|
||||
JsExpression aliasForExpression = context.aliasingContext().getAliasForExpression(expression);
|
||||
if (aliasForExpression != null) {
|
||||
return aliasForExpression;
|
||||
@@ -105,18 +105,18 @@ public final class Translation {
|
||||
|
||||
//NOTE: use with care
|
||||
@NotNull
|
||||
public static JsNode doTranslateExpression(JetExpression expression, TranslationContext context) {
|
||||
public static JsNode doTranslateExpression(KtExpression expression, TranslationContext context) {
|
||||
return expression.accept(new ExpressionVisitor(), context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translateAsExpression(@NotNull JetExpression expression, @NotNull TranslationContext context) {
|
||||
public static JsExpression translateAsExpression(@NotNull KtExpression expression, @NotNull TranslationContext context) {
|
||||
return translateAsExpression(expression, context, context.dynamicContext().jsBlock());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translateAsExpression(
|
||||
@NotNull JetExpression expression,
|
||||
@NotNull KtExpression expression,
|
||||
@NotNull TranslationContext context,
|
||||
@NotNull JsBlock block
|
||||
) {
|
||||
@@ -138,13 +138,13 @@ public final class Translation {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsStatement translateAsStatement(@NotNull JetExpression expression, @NotNull TranslationContext context) {
|
||||
public static JsStatement translateAsStatement(@NotNull KtExpression expression, @NotNull TranslationContext context) {
|
||||
return translateAsStatement(expression, context, context.dynamicContext().jsBlock());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsStatement translateAsStatement(
|
||||
@NotNull JetExpression expression,
|
||||
@NotNull KtExpression expression,
|
||||
@NotNull TranslationContext context,
|
||||
@NotNull JsBlock block) {
|
||||
return convertToStatement(translateExpression(expression, context, block));
|
||||
@@ -152,7 +152,7 @@ public final class Translation {
|
||||
|
||||
@NotNull
|
||||
public static JsStatement translateAsStatementAndMergeInBlockIfNeeded(
|
||||
@NotNull JetExpression expression,
|
||||
@NotNull KtExpression expression,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
JsBlock block = new JsBlock();
|
||||
@@ -162,7 +162,7 @@ public final class Translation {
|
||||
|
||||
@NotNull
|
||||
public static TranslationContext generateAst(@NotNull BindingTrace bindingTrace,
|
||||
@NotNull Collection<JetFile> files, @NotNull MainCallParameters mainCallParameters,
|
||||
@NotNull Collection<KtFile> files, @NotNull MainCallParameters mainCallParameters,
|
||||
@NotNull ModuleDescriptor moduleDescriptor,
|
||||
@NotNull Config config)
|
||||
throws TranslationException {
|
||||
@@ -178,7 +178,7 @@ public final class Translation {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static TranslationContext doGenerateAst(@NotNull BindingTrace bindingTrace, @NotNull Collection<JetFile> files,
|
||||
private static TranslationContext doGenerateAst(@NotNull BindingTrace bindingTrace, @NotNull Collection<KtFile> files,
|
||||
@NotNull MainCallParameters mainCallParameters,
|
||||
@NotNull ModuleDescriptor moduleDescriptor,
|
||||
@NotNull Config config) throws MainFunctionNotFoundException {
|
||||
@@ -213,7 +213,7 @@ public final class Translation {
|
||||
}
|
||||
}
|
||||
|
||||
private static void mayBeGenerateTests(@NotNull Collection<JetFile> files, @NotNull Config config,
|
||||
private static void mayBeGenerateTests(@NotNull Collection<KtFile> files, @NotNull Config config,
|
||||
@NotNull JsBlock rootBlock, @NotNull TranslationContext context) {
|
||||
JSTester tester = config.isTestConfig() ? new JSRhinoUnitTester() : new QUnitTester();
|
||||
tester.initialize(context, rootBlock);
|
||||
@@ -223,10 +223,10 @@ public final class Translation {
|
||||
|
||||
//TODO: determine whether should throw exception
|
||||
@Nullable
|
||||
private static JsStatement generateCallToMain(@NotNull TranslationContext context, @NotNull Collection<JetFile> files,
|
||||
private static JsStatement generateCallToMain(@NotNull TranslationContext context, @NotNull Collection<KtFile> files,
|
||||
@NotNull List<String> arguments) throws MainFunctionNotFoundException {
|
||||
MainFunctionDetector mainFunctionDetector = new MainFunctionDetector(context.bindingContext());
|
||||
JetNamedFunction mainFunction = mainFunctionDetector.getMainFunction(files);
|
||||
KtNamedFunction mainFunction = mainFunctionDetector.getMainFunction(files);
|
||||
if (mainFunction == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+8
-8
@@ -19,27 +19,27 @@ package org.jetbrains.kotlin.js.translate.general;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.js.resolve.diagnostics.ErrorsJs;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration;
|
||||
import org.jetbrains.kotlin.psi.JetDeclarationContainer;
|
||||
import org.jetbrains.kotlin.psi.JetElement;
|
||||
import org.jetbrains.kotlin.psi.JetVisitor;
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration;
|
||||
import org.jetbrains.kotlin.psi.KtDeclarationContainer;
|
||||
import org.jetbrains.kotlin.psi.KtElement;
|
||||
import org.jetbrains.kotlin.psi.KtVisitor;
|
||||
|
||||
/**
|
||||
* This class is a base class for all visitors.
|
||||
*/
|
||||
public abstract class TranslatorVisitor<T> extends JetVisitor<T, TranslationContext> {
|
||||
public abstract class TranslatorVisitor<T> extends KtVisitor<T, TranslationContext> {
|
||||
|
||||
protected abstract T emptyResult(@NotNull TranslationContext context);
|
||||
|
||||
@Override
|
||||
public T visitJetElement(@NotNull JetElement expression, TranslationContext context) {
|
||||
public T visitJetElement(@NotNull KtElement expression, TranslationContext context) {
|
||||
context.bindingTrace().report(ErrorsJs.NOT_SUPPORTED.on(expression, expression));
|
||||
return emptyResult(context);
|
||||
}
|
||||
|
||||
public final void traverseContainer(@NotNull JetDeclarationContainer jetClass,
|
||||
public final void traverseContainer(@NotNull KtDeclarationContainer jetClass,
|
||||
@NotNull TranslationContext context) {
|
||||
for (JetDeclaration declaration : jetClass.getDeclarations()) {
|
||||
for (KtDeclaration declaration : jetClass.getDeclarations()) {
|
||||
declaration.accept(this, context);
|
||||
}
|
||||
}
|
||||
|
||||
+15
-15
@@ -28,11 +28,11 @@ import org.jetbrains.kotlin.js.translate.declaration.DelegationTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.reference.CallArgumentTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.utils.jsAstUtils.AstUtilsKt;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -45,14 +45,14 @@ import static org.jetbrains.kotlin.resolve.DescriptorUtils.getClassDescriptorFor
|
||||
|
||||
public final class ClassInitializerTranslator extends AbstractTranslator {
|
||||
@NotNull
|
||||
private final JetClassOrObject classDeclaration;
|
||||
private final KtClassOrObject classDeclaration;
|
||||
@NotNull
|
||||
private final List<JsStatement> initializerStatements = new SmartList<JsStatement>();
|
||||
private final JsFunction initFunction;
|
||||
private final TranslationContext context;
|
||||
|
||||
public ClassInitializerTranslator(
|
||||
@NotNull JetClassOrObject classDeclaration,
|
||||
@NotNull KtClassOrObject classDeclaration,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
super(context);
|
||||
@@ -68,7 +68,7 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JsFunction createInitFunction(JetClassOrObject declaration, TranslationContext context) {
|
||||
private static JsFunction createInitFunction(KtClassOrObject declaration, TranslationContext context) {
|
||||
//TODO: it's inconsistent that we have scope for class and function for constructor, currently have problems implementing better way
|
||||
ClassDescriptor classDescriptor = getClassDescriptor(context.bindingContext(), declaration);
|
||||
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
||||
@@ -114,7 +114,7 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsExpression generateEnumEntryInstanceCreation(@NotNull JetType enumClassType) {
|
||||
public JsExpression generateEnumEntryInstanceCreation(@NotNull KtType enumClassType) {
|
||||
ResolvedCall<FunctionDescriptor> superCall = getSuperCall();
|
||||
|
||||
if (superCall == null) {
|
||||
@@ -127,7 +127,7 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
private void mayBeAddCallToSuperMethod(JsFunction initializer) {
|
||||
if (classDeclaration.hasModifier(JetTokens.ENUM_KEYWORD)) {
|
||||
if (classDeclaration.hasModifier(KtTokens.ENUM_KEYWORD)) {
|
||||
addCallToSuperMethod(Collections.<JsExpression>emptyList(), initializer);
|
||||
return;
|
||||
}
|
||||
@@ -135,7 +135,7 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
|
||||
ResolvedCall<FunctionDescriptor> superCall = getSuperCall();
|
||||
if (superCall == null) return;
|
||||
|
||||
if (classDeclaration instanceof JetEnumEntry) {
|
||||
if (classDeclaration instanceof KtEnumEntry) {
|
||||
JsExpression expression = CallTranslator.translate(context(), superCall, null);
|
||||
JsExpression fixedInvocation = AstUtilsKt.toInvocationWith(expression, JsLiteral.THIS);
|
||||
initializerStatements.add(0, fixedInvocation.makeStmt());
|
||||
@@ -158,9 +158,9 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
|
||||
|
||||
@Nullable
|
||||
private ResolvedCall<FunctionDescriptor> getSuperCall() {
|
||||
for (JetDelegationSpecifier specifier : classDeclaration.getDelegationSpecifiers()) {
|
||||
if (specifier instanceof JetDelegatorToSuperCall) {
|
||||
JetDelegatorToSuperCall superCall = (JetDelegatorToSuperCall) specifier;
|
||||
for (KtDelegationSpecifier specifier : classDeclaration.getDelegationSpecifiers()) {
|
||||
if (specifier instanceof KtDelegatorToSuperCall) {
|
||||
KtDelegatorToSuperCall superCall = (KtDelegatorToSuperCall) specifier;
|
||||
//noinspection unchecked
|
||||
return (ResolvedCall<FunctionDescriptor>) CallUtilKt.getResolvedCallWithAssert(superCall, bindingContext());
|
||||
}
|
||||
@@ -170,16 +170,16 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
|
||||
|
||||
@NotNull
|
||||
List<JsParameter> translatePrimaryConstructorParameters() {
|
||||
List<JetParameter> parameterList = getPrimaryConstructorParameters(classDeclaration);
|
||||
List<KtParameter> parameterList = getPrimaryConstructorParameters(classDeclaration);
|
||||
List<JsParameter> result = new ArrayList<JsParameter>();
|
||||
for (JetParameter jetParameter : parameterList) {
|
||||
for (KtParameter jetParameter : parameterList) {
|
||||
result.add(translateParameter(jetParameter));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JsParameter translateParameter(@NotNull JetParameter jetParameter) {
|
||||
private JsParameter translateParameter(@NotNull KtParameter jetParameter) {
|
||||
DeclarationDescriptor parameterDescriptor =
|
||||
getDescriptorForElement(bindingContext(), jetParameter);
|
||||
JsName parameterName = context().getNameForDescriptor(parameterDescriptor);
|
||||
@@ -189,7 +189,7 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
private void mayBeAddInitializerStatementForProperty(@NotNull JsParameter jsParameter,
|
||||
@NotNull JetParameter jetParameter) {
|
||||
@NotNull KtParameter jetParameter) {
|
||||
PropertyDescriptor propertyDescriptor =
|
||||
getPropertyDescriptorForConstructorParameter(bindingContext(), jetParameter);
|
||||
if (propertyDescriptor == null) {
|
||||
|
||||
+6
-6
@@ -26,9 +26,9 @@ import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.declaration.ClassTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.general.Translation;
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.JetObjectDeclaration;
|
||||
import org.jetbrains.kotlin.psi.JetProperty;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.psi.KtObjectDeclaration;
|
||||
import org.jetbrains.kotlin.psi.KtProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -48,8 +48,8 @@ public final class InitializerUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JsStatement generateInitializerForDelegate(@NotNull TranslationContext context, @NotNull JetProperty property) {
|
||||
JetExpression delegate = property.getDelegateExpression();
|
||||
public static JsStatement generateInitializerForDelegate(@NotNull TranslationContext context, @NotNull KtProperty property) {
|
||||
KtExpression delegate = property.getDelegateExpression();
|
||||
if (delegate != null) {
|
||||
JsExpression value = Translation.translateAsExpression(delegate, context);
|
||||
String name = property.getName();
|
||||
@@ -60,7 +60,7 @@ public final class InitializerUtils {
|
||||
}
|
||||
|
||||
public static void generateObjectInitializer(
|
||||
@NotNull JetObjectDeclaration declaration,
|
||||
@NotNull KtObjectDeclaration declaration,
|
||||
@NotNull List<JsStatement> initializers,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
|
||||
+7
-7
@@ -43,8 +43,8 @@ public final class InitializerVisitor extends TranslatorVisitor<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Void visitProperty(@NotNull JetProperty property, @NotNull TranslationContext context) {
|
||||
JetExpression initializer = property.getInitializer();
|
||||
public final Void visitProperty(@NotNull KtProperty property, @NotNull TranslationContext context) {
|
||||
KtExpression initializer = property.getInitializer();
|
||||
if (initializer != null) {
|
||||
result.add(generateInitializerForProperty(context, getPropertyDescriptor(context.bindingContext(), property),
|
||||
Translation.translateAsExpression(initializer, context)));
|
||||
@@ -57,8 +57,8 @@ public final class InitializerVisitor extends TranslatorVisitor<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitAnonymousInitializer(@NotNull JetClassInitializer initializer, @NotNull TranslationContext context) {
|
||||
JetExpression initializerBody = initializer.getBody();
|
||||
public Void visitAnonymousInitializer(@NotNull KtClassInitializer initializer, @NotNull TranslationContext context) {
|
||||
KtExpression initializerBody = initializer.getBody();
|
||||
if (initializerBody != null) {
|
||||
result.add(translateAsStatementAndMergeInBlockIfNeeded(initializerBody, context));
|
||||
}
|
||||
@@ -67,12 +67,12 @@ public final class InitializerVisitor extends TranslatorVisitor<Void> {
|
||||
|
||||
@Override
|
||||
// Not interested in other types of declarations, they do not contain initializers.
|
||||
public Void visitDeclaration(@NotNull JetDeclaration expression, @NotNull TranslationContext context) {
|
||||
public Void visitDeclaration(@NotNull KtDeclaration expression, @NotNull TranslationContext context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitObjectDeclaration(@NotNull JetObjectDeclaration declaration, @NotNull TranslationContext context) {
|
||||
public Void visitObjectDeclaration(@NotNull KtObjectDeclaration declaration, @NotNull TranslationContext context) {
|
||||
if (!declaration.isCompanion()) {
|
||||
InitializerUtils.generateObjectInitializer(declaration, result, context);
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public final class InitializerVisitor extends TranslatorVisitor<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitSecondaryConstructor(@NotNull JetSecondaryConstructor constructor, TranslationContext data) {
|
||||
public Void visitSecondaryConstructor(@NotNull KtSecondaryConstructor constructor, TranslationContext data) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.js.translate.intrinsic.objects.ObjectIntrinsic;
|
||||
import org.jetbrains.kotlin.js.translate.intrinsic.objects.ObjectIntrinsics;
|
||||
import org.jetbrains.kotlin.js.translate.intrinsic.operation.BinaryOperationIntrinsic;
|
||||
import org.jetbrains.kotlin.js.translate.intrinsic.operation.BinaryOperationIntrinsics;
|
||||
import org.jetbrains.kotlin.psi.JetBinaryExpression;
|
||||
import org.jetbrains.kotlin.psi.KtBinaryExpression;
|
||||
|
||||
/**
|
||||
* Provides mechanism to substitute method calls /w native constructs directly.
|
||||
@@ -38,7 +38,7 @@ public final class Intrinsics {
|
||||
|
||||
@NotNull
|
||||
public BinaryOperationIntrinsic getBinaryOperationIntrinsic(
|
||||
@NotNull JetBinaryExpression expression,
|
||||
@NotNull KtBinaryExpression expression,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
return binaryOperationIntrinsics.getIntrinsic(expression, context);
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.js.translate.intrinsic.functions.basic.FunctionIntri
|
||||
import org.jetbrains.kotlin.js.translate.operation.OperatorTable;
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsDescriptorUtils;
|
||||
import org.jetbrains.kotlin.lexer.JetToken;
|
||||
import org.jetbrains.kotlin.lexer.KtToken;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions;
|
||||
@@ -179,7 +179,7 @@ public enum PrimitiveBinaryOperationFIF implements FunctionIntrinsicFactory {
|
||||
|
||||
@NotNull
|
||||
private static JsBinaryOperator getOperator(@NotNull FunctionDescriptor descriptor) {
|
||||
JetToken token = OperatorConventions.BINARY_OPERATION_NAMES.inverse().get(descriptor.getName());
|
||||
KtToken token = OperatorConventions.BINARY_OPERATION_NAMES.inverse().get(descriptor.getName());
|
||||
if (token == null) {
|
||||
token = OperatorConventions.BOOLEAN_OPERATIONS.inverse().get(descriptor.getName());
|
||||
}
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.js.translate.intrinsic.functions.basic.FunctionIntri
|
||||
import org.jetbrains.kotlin.js.translate.operation.OperatorTable;
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsDescriptorUtils;
|
||||
import org.jetbrains.kotlin.lexer.JetToken;
|
||||
import org.jetbrains.kotlin.lexer.KtToken;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions;
|
||||
@@ -199,7 +199,7 @@ public enum PrimitiveUnaryOperationFIF implements FunctionIntrinsicFactory {
|
||||
jsOperator = JsUnaryOperator.BIT_NOT;
|
||||
}
|
||||
else {
|
||||
JetToken jetToken = OperatorConventions.UNARY_OPERATION_NAMES_WITH_DEPRECATED_INVERTED.get(name);
|
||||
KtToken jetToken = OperatorConventions.UNARY_OPERATION_NAMES_WITH_DEPRECATED_INVERTED.get(name);
|
||||
jsOperator = OperatorTable.getUnaryOperator(jetToken);
|
||||
}
|
||||
|
||||
|
||||
+13
-14
@@ -27,19 +27,18 @@ import org.jetbrains.kotlin.js.patterns.DescriptorPredicate;
|
||||
import org.jetbrains.kotlin.js.patterns.NamePredicate;
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform;
|
||||
import org.jetbrains.kotlin.js.translate.callTranslator.CallInfo;
|
||||
import org.jetbrains.kotlin.js.translate.context.Namer;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.intrinsic.functions.basic.FunctionIntrinsic;
|
||||
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.BindingUtils;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.JetQualifiedExpression;
|
||||
import org.jetbrains.kotlin.psi.JetReferenceExpression;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.psi.KtQualifiedExpression;
|
||||
import org.jetbrains.kotlin.psi.KtReferenceExpression;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -179,15 +178,15 @@ public final class TopLevelFIF extends CompositeFIF {
|
||||
JsExpression thisOrReceiver = getThisOrReceiverOrNull(callInfo);
|
||||
assert thisOrReceiver != null;
|
||||
if (expressionReceiver != null) {
|
||||
JetExpression expression = expressionReceiver.getExpression();
|
||||
JetReferenceExpression referenceExpression = null;
|
||||
if (expression instanceof JetReferenceExpression) {
|
||||
referenceExpression = (JetReferenceExpression) expression;
|
||||
KtExpression expression = expressionReceiver.getExpression();
|
||||
KtReferenceExpression referenceExpression = null;
|
||||
if (expression instanceof KtReferenceExpression) {
|
||||
referenceExpression = (KtReferenceExpression) expression;
|
||||
}
|
||||
else if (expression instanceof JetQualifiedExpression) {
|
||||
JetExpression candidate = ((JetQualifiedExpression) expression).getReceiverExpression();
|
||||
if (candidate instanceof JetReferenceExpression) {
|
||||
referenceExpression = (JetReferenceExpression) candidate;
|
||||
else if (expression instanceof KtQualifiedExpression) {
|
||||
KtExpression candidate = ((KtQualifiedExpression) expression).getReceiverExpression();
|
||||
if (candidate instanceof KtReferenceExpression) {
|
||||
referenceExpression = (KtReferenceExpression) candidate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +219,7 @@ public final class TopLevelFIF extends CompositeFIF {
|
||||
@NotNull List<JsExpression> arguments,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
JetType keyType = callInfo.getResolvedCall().getTypeArguments().values().iterator().next();
|
||||
KtType keyType = callInfo.getResolvedCall().getTypeArguments().values().iterator().next();
|
||||
Name keyTypeName = DescriptorUtilsKt.getNameIfStandardType(keyType);
|
||||
String collectionClassName = null;
|
||||
if (keyTypeName != null) {
|
||||
|
||||
+6
-6
@@ -19,9 +19,9 @@ package org.jetbrains.kotlin.js.translate.intrinsic.operation
|
||||
import com.google.common.collect.ImmutableSet
|
||||
import com.google.dart.compiler.backend.js.ast.*
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.psi.JetBinaryExpression
|
||||
import org.jetbrains.kotlin.psi.KtBinaryExpression
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.lexer.JetToken
|
||||
import org.jetbrains.kotlin.lexer.KtToken
|
||||
import org.jetbrains.kotlin.js.patterns.PatternBuilder.pattern
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||
import org.jetbrains.kotlin.js.translate.operation.OperatorTable
|
||||
@@ -36,28 +36,28 @@ object CompareToBOIF : BinaryOperationIntrinsicFactory {
|
||||
val PRIMITIVE_COMPARE_TO = pattern("Int|Short|Byte|Double|Float|Char|String.compareTo")
|
||||
|
||||
private object CompareToIntrinsic : AbstractBinaryOperationIntrinsic() {
|
||||
override fun apply(expression: JetBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression {
|
||||
override fun apply(expression: KtBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression {
|
||||
val operator = OperatorTable.getBinaryOperator(getOperationToken(expression))
|
||||
return JsBinaryOperation(operator, left, right)
|
||||
}
|
||||
}
|
||||
|
||||
private object CompareToCharIntrinsic : AbstractBinaryOperationIntrinsic() {
|
||||
override fun apply(expression: JetBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression {
|
||||
override fun apply(expression: KtBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression {
|
||||
val operator = OperatorTable.getBinaryOperator(getOperationToken(expression))
|
||||
return JsBinaryOperation(operator, left, JsAstUtils.charToInt(right))
|
||||
}
|
||||
}
|
||||
|
||||
private object CompareCharToPrimitiveIntrinsic : AbstractBinaryOperationIntrinsic() {
|
||||
override fun apply(expression: JetBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression {
|
||||
override fun apply(expression: KtBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression {
|
||||
val operator = OperatorTable.getBinaryOperator(getOperationToken(expression))
|
||||
return JsBinaryOperation(operator, JsAstUtils.charToInt(left), right)
|
||||
}
|
||||
}
|
||||
|
||||
private object CompareToFunctionIntrinsic : AbstractBinaryOperationIntrinsic() {
|
||||
override fun apply(expression: JetBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression {
|
||||
override fun apply(expression: KtBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression {
|
||||
val operator = OperatorTable.getBinaryOperator(getOperationToken(expression))
|
||||
val compareTo = JsAstUtils.compareTo(left, right)
|
||||
return JsBinaryOperation(operator, compareTo, JsNumberLiteral.ZERO)
|
||||
|
||||
+7
-7
@@ -29,8 +29,8 @@ import org.jetbrains.kotlin.js.translate.utils.JsAstUtils
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsDescriptorUtils
|
||||
import org.jetbrains.kotlin.js.translate.utils.PsiUtils.getOperationToken
|
||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.psi.JetBinaryExpression
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtBinaryExpression
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
@@ -42,14 +42,14 @@ object EqualsBOIF : BinaryOperationIntrinsicFactory {
|
||||
val LONG_EQUALS_ANY = pattern("Long.equals")
|
||||
|
||||
private object LONG_EQUALS_ANY_INTRINSIC : AbstractBinaryOperationIntrinsic() {
|
||||
override fun apply(expression: JetBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression {
|
||||
override fun apply(expression: KtBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression {
|
||||
val invokeEquals = JsAstUtils.equalsForObject(left, right)
|
||||
return if (expression.isNegated()) JsAstUtils.not(invokeEquals) else invokeEquals
|
||||
}
|
||||
}
|
||||
|
||||
private object EqualsIntrinsic : AbstractBinaryOperationIntrinsic() {
|
||||
override fun apply(expression: JetBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression {
|
||||
override fun apply(expression: KtBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression {
|
||||
val isNegated = expression.isNegated()
|
||||
if (right == JsLiteral.NULL || left == JsLiteral.NULL) {
|
||||
return TranslationUtils.nullCheck(if (right == JsLiteral.NULL) left else right, isNegated)
|
||||
@@ -73,7 +73,7 @@ object EqualsBOIF : BinaryOperationIntrinsicFactory {
|
||||
return if (isNegated) JsAstUtils.negated(result) else result
|
||||
}
|
||||
|
||||
private fun canUseSimpleEquals(expression: JetBinaryExpression, context: TranslationContext): Boolean {
|
||||
private fun canUseSimpleEquals(expression: KtBinaryExpression, context: TranslationContext): Boolean {
|
||||
val left = expression.getLeft()
|
||||
assert(left != null) { "No left-hand side: " + expression.getText() }
|
||||
val typeName = JsDescriptorUtils.getNameIfStandardType(left!!, context)
|
||||
@@ -82,7 +82,7 @@ object EqualsBOIF : BinaryOperationIntrinsicFactory {
|
||||
}
|
||||
|
||||
object EnumEqualsIntrinsic : AbstractBinaryOperationIntrinsic() {
|
||||
override fun apply(expression: JetBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsBinaryOperation {
|
||||
override fun apply(expression: KtBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsBinaryOperation {
|
||||
val operator = if (expression.isNegated()) JsBinaryOperator.REF_NEQ else JsBinaryOperator.REF_EQ
|
||||
return JsBinaryOperation(operator, left, right)
|
||||
}
|
||||
@@ -102,5 +102,5 @@ object EqualsBOIF : BinaryOperationIntrinsicFactory {
|
||||
else -> null
|
||||
}
|
||||
|
||||
private fun JetBinaryExpression.isNegated() = getOperationToken(this) == JetTokens.EXCLEQ
|
||||
private fun KtBinaryExpression.isNegated() = getOperationToken(this) == KtTokens.EXCLEQ
|
||||
}
|
||||
|
||||
+4
-4
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.js.translate.utils.JsAstUtils.invokeMethod
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils.longFromInt
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsDescriptorUtils
|
||||
import org.jetbrains.kotlin.js.translate.utils.PsiUtils.getOperationToken
|
||||
import org.jetbrains.kotlin.psi.JetBinaryExpression
|
||||
import org.jetbrains.kotlin.psi.KtBinaryExpression
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.utils.identity as ID
|
||||
|
||||
@@ -45,21 +45,21 @@ public object LongCompareToBOIF : BinaryOperationIntrinsicFactory {
|
||||
val LONG_COMPARE_TO_LONG_PATTERN = pattern("Long.compareTo(Long)")
|
||||
|
||||
private object FLOATING_POINT_COMPARE_TO_LONG : AbstractBinaryOperationIntrinsic() {
|
||||
override fun apply(expression: JetBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression {
|
||||
override fun apply(expression: KtBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression {
|
||||
val operator = OperatorTable.getBinaryOperator(getOperationToken(expression))
|
||||
return JsBinaryOperation(operator, left, invokeMethod(right, Namer.LONG_TO_NUMBER))
|
||||
}
|
||||
}
|
||||
|
||||
private object LONG_COMPARE_TO_FLOATING_POINT : AbstractBinaryOperationIntrinsic() {
|
||||
override fun apply(expression: JetBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression {
|
||||
override fun apply(expression: KtBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression {
|
||||
val operator = OperatorTable.getBinaryOperator(getOperationToken(expression))
|
||||
return JsBinaryOperation(operator, invokeMethod(left, Namer.LONG_TO_NUMBER), right)
|
||||
}
|
||||
}
|
||||
|
||||
private class CompareToBinaryIntrinsic(val toLeft: (JsExpression) -> JsExpression, val toRight: (JsExpression) -> JsExpression) : AbstractBinaryOperationIntrinsic() {
|
||||
override fun apply(expression: JetBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression {
|
||||
override fun apply(expression: KtBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression {
|
||||
val operator = OperatorTable.getBinaryOperator(getOperationToken(expression))
|
||||
val compareInvocation = compareForObject(toLeft(left), toRight(right))
|
||||
return JsBinaryOperation(operator, compareInvocation, JsNumberLiteral.ZERO)
|
||||
|
||||
+11
-11
@@ -17,8 +17,8 @@
|
||||
package org.jetbrains.kotlin.js.translate.intrinsic.operation
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.psi.JetBinaryExpression
|
||||
import org.jetbrains.kotlin.lexer.JetToken
|
||||
import org.jetbrains.kotlin.psi.KtBinaryExpression
|
||||
import org.jetbrains.kotlin.lexer.KtToken
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||
import org.jetbrains.kotlin.js.translate.utils.BindingUtils.getCallableDescriptorForOperationExpression
|
||||
import org.jetbrains.kotlin.js.translate.utils.PsiUtils.getOperationToken
|
||||
@@ -28,18 +28,18 @@ import com.google.common.collect.ImmutableSet
|
||||
|
||||
public interface BinaryOperationIntrinsic {
|
||||
|
||||
fun apply(expression: JetBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression
|
||||
fun apply(expression: KtBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression
|
||||
|
||||
fun exists(): Boolean
|
||||
}
|
||||
|
||||
public class BinaryOperationIntrinsics {
|
||||
|
||||
private val intrinsicCache = THashMap<Pair<JetToken, FunctionDescriptor>, BinaryOperationIntrinsic>()
|
||||
private val intrinsicCache = THashMap<Pair<KtToken, FunctionDescriptor>, BinaryOperationIntrinsic>()
|
||||
|
||||
private val factories = listOf(LongCompareToBOIF, EqualsBOIF, CompareToBOIF)
|
||||
|
||||
public fun getIntrinsic(expression: JetBinaryExpression, context: TranslationContext): BinaryOperationIntrinsic {
|
||||
public fun getIntrinsic(expression: KtBinaryExpression, context: TranslationContext): BinaryOperationIntrinsic {
|
||||
val token = getOperationToken(expression)
|
||||
val descriptor = getCallableDescriptorForOperationExpression(context.bindingContext(), expression)
|
||||
if (descriptor == null || descriptor !is FunctionDescriptor) {
|
||||
@@ -49,16 +49,16 @@ public class BinaryOperationIntrinsics {
|
||||
return lookUpCache(token, descriptor) ?: computeAndCacheIntrinsic(token, descriptor)
|
||||
}
|
||||
|
||||
private fun lookUpCache(token: JetToken, descriptor: FunctionDescriptor): BinaryOperationIntrinsic? =
|
||||
private fun lookUpCache(token: KtToken, descriptor: FunctionDescriptor): BinaryOperationIntrinsic? =
|
||||
intrinsicCache.get(Pair(token, descriptor))
|
||||
|
||||
private fun computeAndCacheIntrinsic(token: JetToken, descriptor: FunctionDescriptor): BinaryOperationIntrinsic {
|
||||
private fun computeAndCacheIntrinsic(token: KtToken, descriptor: FunctionDescriptor): BinaryOperationIntrinsic {
|
||||
val result = computeIntrinsic(token, descriptor)
|
||||
intrinsicCache.put(Pair(token, descriptor), result)
|
||||
return result
|
||||
}
|
||||
|
||||
private fun computeIntrinsic(token: JetToken, descriptor: FunctionDescriptor): BinaryOperationIntrinsic {
|
||||
private fun computeIntrinsic(token: KtToken, descriptor: FunctionDescriptor): BinaryOperationIntrinsic {
|
||||
for (factory in factories) {
|
||||
if (factory.getSupportTokens().contains(token)) {
|
||||
val intrinsic = factory.getIntrinsic(descriptor)
|
||||
@@ -73,14 +73,14 @@ public class BinaryOperationIntrinsics {
|
||||
|
||||
interface BinaryOperationIntrinsicFactory {
|
||||
|
||||
public fun getSupportTokens(): ImmutableSet<out JetToken>
|
||||
public fun getSupportTokens(): ImmutableSet<out KtToken>
|
||||
|
||||
public fun getIntrinsic(descriptor: FunctionDescriptor): BinaryOperationIntrinsic?
|
||||
}
|
||||
|
||||
abstract class AbstractBinaryOperationIntrinsic : BinaryOperationIntrinsic {
|
||||
|
||||
public override abstract fun apply(expression: JetBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression
|
||||
public override abstract fun apply(expression: KtBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression
|
||||
|
||||
public override fun exists(): Boolean = true
|
||||
}
|
||||
@@ -88,6 +88,6 @@ abstract class AbstractBinaryOperationIntrinsic : BinaryOperationIntrinsic {
|
||||
object NO_INTRINSIC : AbstractBinaryOperationIntrinsic() {
|
||||
override fun exists(): Boolean = false
|
||||
|
||||
override fun apply(expression: JetBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression =
|
||||
override fun apply(expression: KtBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression =
|
||||
throw UnsupportedOperationException("BinaryOperationIntrinsic#NO_INTRINSIC_#apply")
|
||||
}
|
||||
|
||||
+12
-12
@@ -21,11 +21,11 @@ import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.kotlin.psi.JetBinaryExpression;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.lexer.KtToken;
|
||||
import org.jetbrains.kotlin.psi.KtBinaryExpression;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
||||
import org.jetbrains.kotlin.lexer.JetToken;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.reference.AccessTranslationUtils;
|
||||
@@ -41,12 +41,12 @@ import static org.jetbrains.kotlin.js.translate.utils.TranslationUtils.translate
|
||||
|
||||
public abstract class AssignmentTranslator extends AbstractTranslator {
|
||||
|
||||
public static boolean isAssignmentOperator(JetToken operationToken) {
|
||||
public static boolean isAssignmentOperator(KtToken operationToken) {
|
||||
return (OperatorConventions.ASSIGNMENT_OPERATIONS.keySet().contains(operationToken) || isAssignment(operationToken));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translate(@NotNull JetBinaryExpression expression,
|
||||
public static JsExpression translate(@NotNull KtBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
if (hasCorrespondingFunctionIntrinsic(context, expression)) {
|
||||
return IntrinsicAssignmentTranslator.doTranslate(expression, context);
|
||||
@@ -55,25 +55,25 @@ public abstract class AssignmentTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected final JetBinaryExpression expression;
|
||||
protected final KtBinaryExpression expression;
|
||||
protected final AccessTranslator accessTranslator;
|
||||
protected final boolean isVariableReassignment;
|
||||
@NotNull
|
||||
protected final JsExpression right;
|
||||
|
||||
protected AssignmentTranslator(@NotNull JetBinaryExpression expression,
|
||||
protected AssignmentTranslator(@NotNull KtBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
super(context);
|
||||
this.expression = expression;
|
||||
this.isVariableReassignment = isVariableReassignment(context.bindingContext(), expression);
|
||||
JetExpression left = expression.getLeft();
|
||||
KtExpression left = expression.getLeft();
|
||||
assert left != null : "No left-hand side: " + expression.getText();
|
||||
|
||||
JsBlock rightBlock = new JsBlock();
|
||||
this.right = translateRightExpression(context, expression, rightBlock);
|
||||
|
||||
if (isValProperty(left, context)) {
|
||||
JetSimpleNameExpression simpleName = getSimpleName(left);
|
||||
KtSimpleNameExpression simpleName = getSimpleName(left);
|
||||
assert simpleName != null;
|
||||
this.accessTranslator = BackingFieldAccessTranslator.newInstance(simpleName, context);
|
||||
} else {
|
||||
@@ -84,10 +84,10 @@ public abstract class AssignmentTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
private static boolean isValProperty(
|
||||
@NotNull JetExpression expression,
|
||||
@NotNull KtExpression expression,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
JetSimpleNameExpression simpleNameExpression = getSimpleName(expression);
|
||||
KtSimpleNameExpression simpleNameExpression = getSimpleName(expression);
|
||||
|
||||
if (simpleNameExpression != null) {
|
||||
DeclarationDescriptor descriptor = getDescriptorForReferenceExpression(context.bindingContext(), simpleNameExpression);
|
||||
|
||||
+31
-31
@@ -30,14 +30,14 @@ import org.jetbrains.kotlin.js.translate.intrinsic.functions.factories.TopLevelF
|
||||
import org.jetbrains.kotlin.js.translate.intrinsic.operation.BinaryOperationIntrinsic;
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils;
|
||||
import org.jetbrains.kotlin.lexer.JetToken;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.psi.JetBinaryExpression;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.lexer.KtToken;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.psi.KtBinaryExpression;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.BindingContextUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
||||
|
||||
@@ -52,44 +52,44 @@ import static org.jetbrains.kotlin.js.translate.utils.PsiUtils.*;
|
||||
public final class BinaryOperationTranslator extends AbstractTranslator {
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translate(@NotNull JetBinaryExpression expression,
|
||||
public static JsExpression translate(@NotNull KtBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
JsExpression jsExpression = new BinaryOperationTranslator(expression, context).translate();
|
||||
return jsExpression.source(expression);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
/*package*/ static JsExpression translateAsOverloadedCall(@NotNull JetBinaryExpression expression,
|
||||
/*package*/ static JsExpression translateAsOverloadedCall(@NotNull KtBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
JsExpression jsExpression = (new BinaryOperationTranslator(expression, context)).translateAsOverloadedBinaryOperation();
|
||||
return jsExpression.source(expression);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final JetBinaryExpression expression;
|
||||
private final KtBinaryExpression expression;
|
||||
|
||||
@NotNull
|
||||
private final JetExpression leftJetExpression;
|
||||
private final KtExpression leftKtExpression;
|
||||
|
||||
@NotNull
|
||||
private final JetExpression rightJetExpression;
|
||||
private final KtExpression rightKtExpression;
|
||||
|
||||
@NotNull
|
||||
private final JetToken operationToken;
|
||||
private final KtToken operationToken;
|
||||
|
||||
@Nullable
|
||||
private final CallableDescriptor operationDescriptor;
|
||||
|
||||
private BinaryOperationTranslator(@NotNull JetBinaryExpression expression,
|
||||
private BinaryOperationTranslator(@NotNull KtBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
super(context);
|
||||
this.expression = expression;
|
||||
|
||||
assert expression.getLeft() != null : "Binary expression should have a left expression: " + expression.getText();
|
||||
leftJetExpression = expression.getLeft();
|
||||
leftKtExpression = expression.getLeft();
|
||||
|
||||
assert expression.getRight() != null : "Binary expression should have a right expression: " + expression.getText();
|
||||
rightJetExpression = expression.getRight();
|
||||
rightKtExpression = expression.getRight();
|
||||
|
||||
this.operationToken = getOperationToken(expression);
|
||||
this.operationDescriptor = getCallableDescriptorForOperationExpression(bindingContext(), expression);
|
||||
@@ -101,7 +101,7 @@ public final class BinaryOperationTranslator extends AbstractTranslator {
|
||||
if (intrinsic.exists()) {
|
||||
return applyIntrinsic(intrinsic);
|
||||
}
|
||||
if (operationToken == JetTokens.ELVIS) {
|
||||
if (operationToken == KtTokens.ELVIS) {
|
||||
return translateElvis();
|
||||
}
|
||||
if (isAssignmentOperator(operationToken)) {
|
||||
@@ -123,13 +123,13 @@ public final class BinaryOperationTranslator extends AbstractTranslator {
|
||||
|
||||
@NotNull
|
||||
private JsExpression translateElvis() {
|
||||
JsExpression leftExpression = Translation.translateAsExpression(leftJetExpression, context());
|
||||
JsExpression leftExpression = Translation.translateAsExpression(leftKtExpression, context());
|
||||
if (JsAstUtils.isEmptyExpression(leftExpression)) {
|
||||
return leftExpression;
|
||||
}
|
||||
|
||||
JsBlock rightBlock = new JsBlock();
|
||||
JsExpression rightExpression = Translation.translateAsExpression(rightJetExpression, context(), rightBlock);
|
||||
JsExpression rightExpression = Translation.translateAsExpression(rightKtExpression, context(), rightBlock);
|
||||
|
||||
if (rightBlock.isEmpty()) {
|
||||
return TranslationUtils.notNullConditional(leftExpression, rightExpression, context());
|
||||
@@ -168,13 +168,13 @@ public final class BinaryOperationTranslator extends AbstractTranslator {
|
||||
|
||||
@NotNull
|
||||
private JsExpression applyIntrinsic(@NotNull BinaryOperationIntrinsic intrinsic) {
|
||||
JsExpression leftExpression = Translation.translateAsExpression(leftJetExpression, context());
|
||||
JsExpression leftExpression = Translation.translateAsExpression(leftKtExpression, context());
|
||||
if (JsAstUtils.isEmptyExpression(leftExpression)) {
|
||||
return leftExpression;
|
||||
}
|
||||
|
||||
JsBlock rightBlock = new JsBlock();
|
||||
JsExpression rightExpression = Translation.translateAsExpression(rightJetExpression, context(), rightBlock);
|
||||
JsExpression rightExpression = Translation.translateAsExpression(rightKtExpression, context(), rightBlock);
|
||||
|
||||
if (rightBlock.isEmpty()) {
|
||||
return intrinsic.apply(expression, leftExpression, rightExpression, context());
|
||||
@@ -206,13 +206,13 @@ public final class BinaryOperationTranslator extends AbstractTranslator {
|
||||
private JsExpression translateAsUnOverloadableBinaryOperation() {
|
||||
assert OperatorConventions.NOT_OVERLOADABLE.contains(operationToken);
|
||||
JsBinaryOperator operator = OperatorTable.getBinaryOperator(operationToken);
|
||||
JsExpression leftExpression = Translation.translateAsExpression(leftJetExpression, context());
|
||||
JsExpression leftExpression = Translation.translateAsExpression(leftKtExpression, context());
|
||||
if (JsAstUtils.isEmptyExpression(leftExpression)) {
|
||||
return leftExpression;
|
||||
}
|
||||
|
||||
JsBlock rightBlock = new JsBlock();
|
||||
JsExpression rightExpression = Translation.translateAsExpression(rightJetExpression, context(), rightBlock);
|
||||
JsExpression rightExpression = Translation.translateAsExpression(rightKtExpression, context(), rightBlock);
|
||||
|
||||
if (rightBlock.isEmpty()) {
|
||||
return new JsBinaryOperation(operator, leftExpression, rightExpression);
|
||||
@@ -222,8 +222,8 @@ public final class BinaryOperationTranslator extends AbstractTranslator {
|
||||
return new JsBinaryOperation(operator, leftExpression, rightExpression);
|
||||
}
|
||||
|
||||
assert operationToken.equals(JetTokens.ANDAND) || operationToken.equals(JetTokens.OROR) : "Unsupported binary operation: " + expression.getText();
|
||||
boolean isOror = operationToken.equals(JetTokens.OROR);
|
||||
assert operationToken.equals(KtTokens.ANDAND) || operationToken.equals(KtTokens.OROR) : "Unsupported binary operation: " + expression.getText();
|
||||
boolean isOror = operationToken.equals(KtTokens.OROR);
|
||||
JsExpression literalResult = isOror ? JsLiteral.TRUE : JsLiteral.FALSE;
|
||||
leftExpression = isOror ? not(leftExpression) : leftExpression;
|
||||
|
||||
@@ -255,20 +255,20 @@ public final class BinaryOperationTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
private boolean isEquals() {
|
||||
return operationToken == JetTokens.EQEQ || operationToken == JetTokens.EXCLEQ;
|
||||
return operationToken == KtTokens.EQEQ || operationToken == KtTokens.EXCLEQ;
|
||||
}
|
||||
|
||||
private JsExpression translateEquals() {
|
||||
JsExpression left = Translation.translateAsExpression(leftJetExpression, context());
|
||||
JsExpression right = Translation.translateAsExpression(rightJetExpression, context());
|
||||
JsExpression left = Translation.translateAsExpression(leftKtExpression, context());
|
||||
JsExpression right = Translation.translateAsExpression(rightKtExpression, context());
|
||||
|
||||
if (left == JsLiteral.NULL || right == JsLiteral.NULL) {
|
||||
JsBinaryOperator operator = operationToken == JetTokens.EXCLEQ ? JsBinaryOperator.NEQ : JsBinaryOperator.EQ;
|
||||
JsBinaryOperator operator = operationToken == KtTokens.EXCLEQ ? JsBinaryOperator.NEQ : JsBinaryOperator.EQ;
|
||||
return new JsBinaryOperation(operator, left, right);
|
||||
}
|
||||
|
||||
JetType leftType = context().bindingContext().getType(leftJetExpression);
|
||||
JetType rightType = context().bindingContext().getType(rightJetExpression);
|
||||
KtType leftType = context().bindingContext().getType(leftKtExpression);
|
||||
KtType rightType = context().bindingContext().getType(rightKtExpression);
|
||||
|
||||
if (leftType != null && TypeUtils.isNullableType(leftType) || rightType != null && TypeUtils.isNullableType(rightType)) {
|
||||
return mayBeWrapWithNegation(TopLevelFIF.KOTLIN_EQUALS.apply(left, Collections.singletonList(right), context()));
|
||||
@@ -287,9 +287,9 @@ public final class BinaryOperationTranslator extends AbstractTranslator {
|
||||
@NotNull
|
||||
private JsExpression getReceiver() {
|
||||
if (isInOrNotInOperation(expression)) {
|
||||
return Translation.translateAsExpression(rightJetExpression, context());
|
||||
return Translation.translateAsExpression(rightKtExpression, context());
|
||||
} else {
|
||||
return Translation.translateAsExpression(leftJetExpression, context());
|
||||
return Translation.translateAsExpression(leftKtExpression, context());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -24,8 +24,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.kotlin.lexer.JetToken;
|
||||
import org.jetbrains.kotlin.psi.JetBinaryExpression;
|
||||
import org.jetbrains.kotlin.lexer.KtToken;
|
||||
import org.jetbrains.kotlin.psi.KtBinaryExpression;
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
||||
|
||||
import static org.jetbrains.kotlin.js.translate.utils.BindingUtils.getCallableDescriptorForOperationExpression;
|
||||
@@ -36,7 +36,7 @@ import static org.jetbrains.kotlin.js.translate.utils.PsiUtils.getOperationToken
|
||||
public final class CompareToTranslator extends AbstractTranslator {
|
||||
|
||||
public static boolean isCompareToCall(
|
||||
@NotNull JetToken operationToken,
|
||||
@NotNull KtToken operationToken,
|
||||
@Nullable CallableDescriptor operationDescriptor
|
||||
) {
|
||||
if (!OperatorConventions.COMPARISON_OPERATIONS.contains(operationToken) || operationDescriptor == null) return false;
|
||||
@@ -45,16 +45,16 @@ public final class CompareToTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translate(@NotNull JetBinaryExpression expression,
|
||||
public static JsExpression translate(@NotNull KtBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return (new CompareToTranslator(expression, context)).translate();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final JetBinaryExpression expression;
|
||||
private final KtBinaryExpression expression;
|
||||
|
||||
private CompareToTranslator(
|
||||
@NotNull JetBinaryExpression expression,
|
||||
@NotNull KtBinaryExpression expression,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
super(context);
|
||||
|
||||
+7
-7
@@ -28,8 +28,8 @@ import org.jetbrains.kotlin.js.translate.context.TemporaryVariable;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.reference.CachedAccessTranslator;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.JetUnaryExpression;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.psi.KtUnaryExpression;
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.DynamicCallsKt;
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
||||
|
||||
@@ -52,7 +52,7 @@ public abstract class IncrementTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translate(@NotNull JetUnaryExpression expression,
|
||||
public static JsExpression translate(@NotNull KtUnaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
if (hasCorrespondingFunctionIntrinsic(context, expression) || isDynamic(context, expression)) {
|
||||
return IntrinsicIncrementTranslator.doTranslate(expression, context);
|
||||
@@ -61,15 +61,15 @@ public abstract class IncrementTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected final JetUnaryExpression expression;
|
||||
protected final KtUnaryExpression expression;
|
||||
@NotNull
|
||||
protected final CachedAccessTranslator accessTranslator;
|
||||
|
||||
protected IncrementTranslator(@NotNull JetUnaryExpression expression,
|
||||
protected IncrementTranslator(@NotNull KtUnaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
super(context);
|
||||
this.expression = expression;
|
||||
JetExpression baseExpression = getBaseExpression(expression);
|
||||
KtExpression baseExpression = getBaseExpression(expression);
|
||||
this.accessTranslator = getCachedAccessTranslator(baseExpression, context());
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public abstract class IncrementTranslator extends AbstractTranslator {
|
||||
@NotNull
|
||||
abstract JsExpression operationExpression(@NotNull JsExpression receiver);
|
||||
|
||||
private static boolean isDynamic(TranslationContext context, JetUnaryExpression expression) {
|
||||
private static boolean isDynamic(TranslationContext context, KtUnaryExpression expression) {
|
||||
CallableDescriptor operationDescriptor = getCallableDescriptorForOperationExpression(context.bindingContext(), expression);
|
||||
return DynamicCallsKt.isDynamic(operationDescriptor);
|
||||
}
|
||||
|
||||
+9
-9
@@ -21,9 +21,9 @@ import com.google.dart.compiler.backend.js.ast.JsBinaryOperator;
|
||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.lexer.JetToken;
|
||||
import org.jetbrains.kotlin.psi.JetBinaryExpression;
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.lexer.KtToken;
|
||||
import org.jetbrains.kotlin.psi.KtBinaryExpression;
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
||||
|
||||
import static org.jetbrains.kotlin.js.translate.utils.PsiUtils.getOperationToken;
|
||||
@@ -33,12 +33,12 @@ public final class IntrinsicAssignmentTranslator extends AssignmentTranslator {
|
||||
|
||||
|
||||
@NotNull
|
||||
public static JsExpression doTranslate(@NotNull JetBinaryExpression expression,
|
||||
public static JsExpression doTranslate(@NotNull KtBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return (new IntrinsicAssignmentTranslator(expression, context)).translate();
|
||||
}
|
||||
|
||||
private IntrinsicAssignmentTranslator(@NotNull JetBinaryExpression expression,
|
||||
private IntrinsicAssignmentTranslator(@NotNull KtBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
super(expression, context);
|
||||
}
|
||||
@@ -53,7 +53,7 @@ public final class IntrinsicAssignmentTranslator extends AssignmentTranslator {
|
||||
|
||||
@NotNull
|
||||
private JsExpression translateAsAssignmentOperation() {
|
||||
if (expression.getLeft() instanceof JetSimpleNameExpression) {
|
||||
if (expression.getLeft() instanceof KtSimpleNameExpression) {
|
||||
return translateAsPlainAssignmentOperation();
|
||||
}
|
||||
return translateAsAssignToCounterpart();
|
||||
@@ -69,9 +69,9 @@ public final class IntrinsicAssignmentTranslator extends AssignmentTranslator {
|
||||
|
||||
@NotNull
|
||||
private JsBinaryOperator getCounterpartOperator() {
|
||||
JetToken assignmentOperationToken = getOperationToken(expression);
|
||||
KtToken assignmentOperationToken = getOperationToken(expression);
|
||||
assert OperatorConventions.ASSIGNMENT_OPERATIONS.containsKey(assignmentOperationToken);
|
||||
JetToken counterpartToken = OperatorConventions.ASSIGNMENT_OPERATION_COUNTERPARTS.get(assignmentOperationToken);
|
||||
KtToken counterpartToken = OperatorConventions.ASSIGNMENT_OPERATION_COUNTERPARTS.get(assignmentOperationToken);
|
||||
assert OperatorTable.hasCorrespondingBinaryOperator(counterpartToken) :
|
||||
"Unsupported token encountered: " + counterpartToken.toString();
|
||||
return OperatorTable.getBinaryOperator(counterpartToken);
|
||||
@@ -85,7 +85,7 @@ public final class IntrinsicAssignmentTranslator extends AssignmentTranslator {
|
||||
|
||||
@NotNull
|
||||
private JsBinaryOperator getAssignmentOperator() {
|
||||
JetToken token = getOperationToken(expression);
|
||||
KtToken token = getOperationToken(expression);
|
||||
assert OperatorConventions.ASSIGNMENT_OPERATIONS.containsKey(token);
|
||||
assert OperatorTable.hasCorrespondingBinaryOperator(token) :
|
||||
"Unsupported token encountered: " + token.toString();
|
||||
|
||||
+10
-10
@@ -19,10 +19,10 @@ package org.jetbrains.kotlin.js.translate.operation;
|
||||
import com.google.dart.compiler.backend.js.ast.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.lexer.JetToken;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.psi.JetUnaryExpression;
|
||||
import org.jetbrains.kotlin.lexer.KtToken;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.psi.KtUnaryExpression;
|
||||
|
||||
import static org.jetbrains.kotlin.js.translate.utils.PsiUtils.getOperationToken;
|
||||
import static org.jetbrains.kotlin.js.translate.utils.PsiUtils.isPrefix;
|
||||
@@ -31,13 +31,13 @@ import static org.jetbrains.kotlin.js.translate.utils.PsiUtils.isPrefix;
|
||||
public final class IntrinsicIncrementTranslator extends IncrementTranslator {
|
||||
|
||||
@NotNull
|
||||
public static JsExpression doTranslate(@NotNull JetUnaryExpression expression,
|
||||
public static JsExpression doTranslate(@NotNull KtUnaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return (new IntrinsicIncrementTranslator(expression, context))
|
||||
.translate();
|
||||
}
|
||||
|
||||
private IntrinsicIncrementTranslator(@NotNull JetUnaryExpression expression,
|
||||
private IntrinsicIncrementTranslator(@NotNull KtUnaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
super(expression, context);
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public final class IntrinsicIncrementTranslator extends IncrementTranslator {
|
||||
}
|
||||
|
||||
private boolean isPrimitiveExpressionIncrement() {
|
||||
return expression.getBaseExpression() instanceof JetSimpleNameExpression;
|
||||
return expression.getBaseExpression() instanceof KtSimpleNameExpression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -75,11 +75,11 @@ public final class IntrinsicIncrementTranslator extends IncrementTranslator {
|
||||
@NotNull
|
||||
private JsBinaryOperation unaryAsBinary(@NotNull JsExpression leftExpression) {
|
||||
JsNumberLiteral oneLiteral = program().getNumberLiteral(1);
|
||||
JetToken token = getOperationToken(expression);
|
||||
if (token.equals(JetTokens.PLUSPLUS)) {
|
||||
KtToken token = getOperationToken(expression);
|
||||
if (token.equals(KtTokens.PLUSPLUS)) {
|
||||
return new JsBinaryOperation(JsBinaryOperator.ADD, leftExpression, oneLiteral);
|
||||
}
|
||||
if (token.equals(JetTokens.MINUSMINUS)) {
|
||||
if (token.equals(KtTokens.MINUSMINUS)) {
|
||||
return new JsBinaryOperation(JsBinaryOperator.SUB, leftExpression, oneLiteral);
|
||||
}
|
||||
throw new AssertionError("This method should be called only for increment and decrement operators");
|
||||
|
||||
+35
-35
@@ -20,65 +20,65 @@ import com.google.common.collect.ImmutableBiMap;
|
||||
import com.google.dart.compiler.backend.js.ast.JsBinaryOperator;
|
||||
import com.google.dart.compiler.backend.js.ast.JsUnaryOperator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.lexer.JetToken;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.lexer.KtToken;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class OperatorTable {
|
||||
|
||||
//TODO : not all operators , add and test bit operators
|
||||
private static final Map<JetToken, JsBinaryOperator> binaryOperatorsMap = ImmutableBiMap.<JetToken, JsBinaryOperator>builder()
|
||||
.put(JetTokens.PLUS, JsBinaryOperator.ADD)
|
||||
.put(JetTokens.MINUS, JsBinaryOperator.SUB)
|
||||
.put(JetTokens.MUL, JsBinaryOperator.MUL)
|
||||
.put(JetTokens.DIV, JsBinaryOperator.DIV)
|
||||
.put(JetTokens.EQ, JsBinaryOperator.ASG)
|
||||
.put(JetTokens.GT, JsBinaryOperator.GT)
|
||||
.put(JetTokens.GTEQ, JsBinaryOperator.GTE)
|
||||
.put(JetTokens.LT, JsBinaryOperator.LT)
|
||||
.put(JetTokens.LTEQ, JsBinaryOperator.LTE)
|
||||
.put(JetTokens.ANDAND, JsBinaryOperator.AND)
|
||||
.put(JetTokens.OROR, JsBinaryOperator.OR)
|
||||
.put(JetTokens.PERC, JsBinaryOperator.MOD)
|
||||
.put(JetTokens.PLUSEQ, JsBinaryOperator.ASG_ADD)
|
||||
.put(JetTokens.MINUSEQ, JsBinaryOperator.ASG_SUB)
|
||||
.put(JetTokens.DIVEQ, JsBinaryOperator.ASG_DIV)
|
||||
.put(JetTokens.MULTEQ, JsBinaryOperator.ASG_MUL)
|
||||
.put(JetTokens.PERCEQ, JsBinaryOperator.ASG_MOD)
|
||||
.put(JetTokens.IN_KEYWORD, JsBinaryOperator.INOP)
|
||||
.put(JetTokens.EQEQEQ, JsBinaryOperator.REF_EQ)
|
||||
.put(JetTokens.EXCLEQEQEQ, JsBinaryOperator.REF_NEQ)
|
||||
private static final Map<KtToken, JsBinaryOperator> binaryOperatorsMap = ImmutableBiMap.<KtToken, JsBinaryOperator>builder()
|
||||
.put(KtTokens.PLUS, JsBinaryOperator.ADD)
|
||||
.put(KtTokens.MINUS, JsBinaryOperator.SUB)
|
||||
.put(KtTokens.MUL, JsBinaryOperator.MUL)
|
||||
.put(KtTokens.DIV, JsBinaryOperator.DIV)
|
||||
.put(KtTokens.EQ, JsBinaryOperator.ASG)
|
||||
.put(KtTokens.GT, JsBinaryOperator.GT)
|
||||
.put(KtTokens.GTEQ, JsBinaryOperator.GTE)
|
||||
.put(KtTokens.LT, JsBinaryOperator.LT)
|
||||
.put(KtTokens.LTEQ, JsBinaryOperator.LTE)
|
||||
.put(KtTokens.ANDAND, JsBinaryOperator.AND)
|
||||
.put(KtTokens.OROR, JsBinaryOperator.OR)
|
||||
.put(KtTokens.PERC, JsBinaryOperator.MOD)
|
||||
.put(KtTokens.PLUSEQ, JsBinaryOperator.ASG_ADD)
|
||||
.put(KtTokens.MINUSEQ, JsBinaryOperator.ASG_SUB)
|
||||
.put(KtTokens.DIVEQ, JsBinaryOperator.ASG_DIV)
|
||||
.put(KtTokens.MULTEQ, JsBinaryOperator.ASG_MUL)
|
||||
.put(KtTokens.PERCEQ, JsBinaryOperator.ASG_MOD)
|
||||
.put(KtTokens.IN_KEYWORD, JsBinaryOperator.INOP)
|
||||
.put(KtTokens.EQEQEQ, JsBinaryOperator.REF_EQ)
|
||||
.put(KtTokens.EXCLEQEQEQ, JsBinaryOperator.REF_NEQ)
|
||||
.build();
|
||||
|
||||
private static final ImmutableBiMap<JetToken, JsUnaryOperator> unaryOperatorsMap = ImmutableBiMap.<JetToken, JsUnaryOperator>builder()
|
||||
.put(JetTokens.PLUSPLUS, JsUnaryOperator.INC)
|
||||
.put(JetTokens.MINUSMINUS, JsUnaryOperator.DEC)
|
||||
.put(JetTokens.EXCL, JsUnaryOperator.NOT)
|
||||
.put(JetTokens.MINUS, JsUnaryOperator.NEG)
|
||||
.put(JetTokens.PLUS, JsUnaryOperator.POS)
|
||||
private static final ImmutableBiMap<KtToken, JsUnaryOperator> unaryOperatorsMap = ImmutableBiMap.<KtToken, JsUnaryOperator>builder()
|
||||
.put(KtTokens.PLUSPLUS, JsUnaryOperator.INC)
|
||||
.put(KtTokens.MINUSMINUS, JsUnaryOperator.DEC)
|
||||
.put(KtTokens.EXCL, JsUnaryOperator.NOT)
|
||||
.put(KtTokens.MINUS, JsUnaryOperator.NEG)
|
||||
.put(KtTokens.PLUS, JsUnaryOperator.POS)
|
||||
.build();
|
||||
|
||||
private OperatorTable() {
|
||||
}
|
||||
|
||||
public static boolean hasCorrespondingOperator(@NotNull JetToken token) {
|
||||
public static boolean hasCorrespondingOperator(@NotNull KtToken token) {
|
||||
return binaryOperatorsMap.containsKey(token) || unaryOperatorsMap.containsKey(token);
|
||||
}
|
||||
|
||||
public static boolean hasCorrespondingBinaryOperator(@NotNull JetToken token) {
|
||||
public static boolean hasCorrespondingBinaryOperator(@NotNull KtToken token) {
|
||||
return binaryOperatorsMap.containsKey(token);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public JsBinaryOperator getBinaryOperator(@NotNull JetToken token) {
|
||||
assert JetTokens.OPERATIONS.contains(token) : "Token should represent an operation!";
|
||||
static public JsBinaryOperator getBinaryOperator(@NotNull KtToken token) {
|
||||
assert KtTokens.OPERATIONS.contains(token) : "Token should represent an operation!";
|
||||
return binaryOperatorsMap.get(token);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public JsUnaryOperator getUnaryOperator(@NotNull JetToken token) {
|
||||
assert JetTokens.OPERATIONS.contains(token) : "Token should represent an operation!";
|
||||
static public JsUnaryOperator getUnaryOperator(@NotNull KtToken token) {
|
||||
assert KtTokens.OPERATIONS.contains(token) : "Token should represent an operation!";
|
||||
return unaryOperatorsMap.get(token);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -21,14 +21,14 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.kotlin.js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.psi.JetBinaryExpression;
|
||||
import org.jetbrains.kotlin.psi.KtBinaryExpression;
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
|
||||
public final class OverloadedAssignmentTranslator extends AssignmentTranslator {
|
||||
|
||||
@NotNull
|
||||
public static JsExpression doTranslate(@NotNull JetBinaryExpression expression,
|
||||
public static JsExpression doTranslate(@NotNull KtBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return (new OverloadedAssignmentTranslator(expression, context)).translate();
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public final class OverloadedAssignmentTranslator extends AssignmentTranslator {
|
||||
@NotNull
|
||||
private final ResolvedCall<? extends FunctionDescriptor> resolvedCall;
|
||||
|
||||
private OverloadedAssignmentTranslator(@NotNull JetBinaryExpression expression,
|
||||
private OverloadedAssignmentTranslator(@NotNull KtBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
super(expression, context);
|
||||
resolvedCall = CallUtilKt.getFunctionResolvedCallWithAssert(expression, context.bindingContext());
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.kotlin.js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.psi.JetUnaryExpression;
|
||||
import org.jetbrains.kotlin.psi.KtUnaryExpression;
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
|
||||
@@ -31,7 +31,7 @@ public final class OverloadedIncrementTranslator extends IncrementTranslator {
|
||||
private final ResolvedCall<? extends FunctionDescriptor> resolvedCall;
|
||||
|
||||
/*package*/ OverloadedIncrementTranslator(
|
||||
@NotNull JetUnaryExpression expression,
|
||||
@NotNull KtUnaryExpression expression,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
super(expression, context);
|
||||
|
||||
+14
-14
@@ -25,16 +25,16 @@ import org.jetbrains.kotlin.js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.psi.JetConstantExpression;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.JetUnaryExpression;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.psi.KtConstantExpression;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.psi.KtUnaryExpression;
|
||||
import org.jetbrains.kotlin.resolve.BindingContextUtils;
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
|
||||
import static org.jetbrains.kotlin.js.translate.general.Translation.translateAsExpression;
|
||||
import static org.jetbrains.kotlin.js.translate.utils.BindingUtils.getCompileTimeValue;
|
||||
@@ -49,20 +49,20 @@ public final class UnaryOperationTranslator {
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translate(
|
||||
@NotNull JetUnaryExpression expression,
|
||||
@NotNull KtUnaryExpression expression,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
IElementType operationToken = expression.getOperationReference().getReferencedNameElementType();
|
||||
if (operationToken == JetTokens.EXCLEXCL) {
|
||||
JetExpression baseExpression = getBaseExpression(expression);
|
||||
JetType type = BindingContextUtils.getTypeNotNull(context.bindingContext(), baseExpression);
|
||||
if (operationToken == KtTokens.EXCLEXCL) {
|
||||
KtExpression baseExpression = getBaseExpression(expression);
|
||||
KtType type = BindingContextUtils.getTypeNotNull(context.bindingContext(), baseExpression);
|
||||
JsExpression translatedExpression = translateAsExpression(baseExpression, context);
|
||||
return type.isMarkedNullable() ? sure(translatedExpression, context) : translatedExpression;
|
||||
}
|
||||
|
||||
if (operationToken == JetTokens.MINUS) {
|
||||
JetExpression baseExpression = getBaseExpression(expression);
|
||||
if (baseExpression instanceof JetConstantExpression) {
|
||||
if (operationToken == KtTokens.MINUS) {
|
||||
KtExpression baseExpression = getBaseExpression(expression);
|
||||
if (baseExpression instanceof KtConstantExpression) {
|
||||
CompileTimeConstant<?> compileTimeValue = ConstantExpressionEvaluator.getConstant(expression, context.bindingContext());
|
||||
assert compileTimeValue != null : message(expression, "Expression is not compile time value: " + expression.getText() + " ");
|
||||
Object value = getCompileTimeValue(context.bindingContext(), expression, compileTimeValue);
|
||||
@@ -85,8 +85,8 @@ public final class UnaryOperationTranslator {
|
||||
return CallTranslator.translate(context, resolvedCall, baseExpression);
|
||||
}
|
||||
|
||||
private static boolean isExclForBinaryEqualLikeExpr(@NotNull JetUnaryExpression expression, @NotNull JsExpression baseExpression) {
|
||||
if (getOperationToken(expression).equals(JetTokens.EXCL)) {
|
||||
private static boolean isExclForBinaryEqualLikeExpr(@NotNull KtUnaryExpression expression, @NotNull JsExpression baseExpression) {
|
||||
if (getOperationToken(expression).equals(KtTokens.EXCL)) {
|
||||
if (baseExpression instanceof JsBinaryOperation) {
|
||||
return isEqualLikeOperator(((JsBinaryOperation) baseExpression).getOperator());
|
||||
}
|
||||
|
||||
+3
-3
@@ -22,21 +22,21 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.kotlin.psi.JetCallExpression;
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression;
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
|
||||
public abstract class AbstractCallExpressionTranslator extends AbstractTranslator {
|
||||
|
||||
@NotNull
|
||||
protected final JetCallExpression expression;
|
||||
protected final KtCallExpression expression;
|
||||
@NotNull
|
||||
protected final ResolvedCall<? extends FunctionDescriptor> resolvedCall;
|
||||
@Nullable
|
||||
protected final JsExpression receiver;
|
||||
|
||||
protected AbstractCallExpressionTranslator(
|
||||
@NotNull JetCallExpression expression,
|
||||
@NotNull KtCallExpression expression,
|
||||
@Nullable JsExpression receiver,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
|
||||
+15
-15
@@ -33,36 +33,36 @@ public final class AccessTranslationUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AccessTranslator getAccessTranslator(@NotNull JetExpression referenceExpression,
|
||||
public static AccessTranslator getAccessTranslator(@NotNull KtExpression referenceExpression,
|
||||
@NotNull TranslationContext context) {
|
||||
return getAccessTranslator(referenceExpression, context, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AccessTranslator getAccessTranslator(@NotNull JetExpression referenceExpression,
|
||||
public static AccessTranslator getAccessTranslator(@NotNull KtExpression referenceExpression,
|
||||
@NotNull TranslationContext context, boolean forceOrderOfEvaluation) {
|
||||
assert ((referenceExpression instanceof JetReferenceExpression) ||
|
||||
(referenceExpression instanceof JetQualifiedExpression));
|
||||
if (referenceExpression instanceof JetQualifiedExpression) {
|
||||
return QualifiedExpressionTranslator.getAccessTranslator((JetQualifiedExpression) referenceExpression, context, forceOrderOfEvaluation);
|
||||
assert ((referenceExpression instanceof KtReferenceExpression) ||
|
||||
(referenceExpression instanceof KtQualifiedExpression));
|
||||
if (referenceExpression instanceof KtQualifiedExpression) {
|
||||
return QualifiedExpressionTranslator.getAccessTranslator((KtQualifiedExpression) referenceExpression, context, forceOrderOfEvaluation);
|
||||
}
|
||||
if (referenceExpression instanceof JetSimpleNameExpression) {
|
||||
return ReferenceTranslator.getAccessTranslator((JetSimpleNameExpression) referenceExpression, context);
|
||||
if (referenceExpression instanceof KtSimpleNameExpression) {
|
||||
return ReferenceTranslator.getAccessTranslator((KtSimpleNameExpression) referenceExpression, context);
|
||||
}
|
||||
assert referenceExpression instanceof JetArrayAccessExpression;
|
||||
return getArrayAccessTranslator((JetArrayAccessExpression) referenceExpression, context, forceOrderOfEvaluation);
|
||||
assert referenceExpression instanceof KtArrayAccessExpression;
|
||||
return getArrayAccessTranslator((KtArrayAccessExpression) referenceExpression, context, forceOrderOfEvaluation);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static AccessTranslator getArrayAccessTranslator(
|
||||
@NotNull JetArrayAccessExpression expression,
|
||||
@NotNull KtArrayAccessExpression expression,
|
||||
@NotNull TranslationContext context,
|
||||
boolean forceOrderOfEvaluation
|
||||
) {
|
||||
TranslationContext accessArrayContext;
|
||||
if (forceOrderOfEvaluation) {
|
||||
Map<JetExpression, JsExpression> indexesMap = new LinkedHashMap<JetExpression, JsExpression>();
|
||||
for(JetExpression indexExpression : expression.getIndexExpressions()) {
|
||||
Map<KtExpression, JsExpression> indexesMap = new LinkedHashMap<KtExpression, JsExpression>();
|
||||
for(KtExpression indexExpression : expression.getIndexExpressions()) {
|
||||
JsExpression jsIndexExpression = Translation.translateAsExpression(indexExpression, context);
|
||||
if (TranslationUtils.isCacheNeeded(jsIndexExpression)) {
|
||||
TemporaryVariable temporaryVariable = context.declareTemporary(null);
|
||||
@@ -80,13 +80,13 @@ public final class AccessTranslationUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static CachedAccessTranslator getCachedAccessTranslator(@NotNull JetExpression referenceExpression,
|
||||
public static CachedAccessTranslator getCachedAccessTranslator(@NotNull KtExpression referenceExpression,
|
||||
@NotNull TranslationContext context) {
|
||||
return getAccessTranslator(referenceExpression, context).getCached();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translateAsGet(@NotNull JetExpression expression,
|
||||
public static JsExpression translateAsGet(@NotNull KtExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return (getAccessTranslator(expression, context)).translateAsGet();
|
||||
}
|
||||
|
||||
+12
-12
@@ -26,8 +26,8 @@ import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.general.Translation;
|
||||
import org.jetbrains.kotlin.js.translate.utils.BindingUtils;
|
||||
import org.jetbrains.kotlin.psi.JetArrayAccessExpression;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.KtArrayAccessExpression;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.psi.ValueArgument;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
@@ -38,15 +38,15 @@ import java.util.*;
|
||||
public class ArrayAccessTranslator extends AbstractTranslator implements AccessTranslator {
|
||||
|
||||
/*package*/
|
||||
static ArrayAccessTranslator newInstance(@NotNull JetArrayAccessExpression expression,
|
||||
static ArrayAccessTranslator newInstance(@NotNull KtArrayAccessExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return new ArrayAccessTranslator(expression, context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final JetArrayAccessExpression expression;
|
||||
private final KtArrayAccessExpression expression;
|
||||
|
||||
protected ArrayAccessTranslator(@NotNull JetArrayAccessExpression expression,
|
||||
protected ArrayAccessTranslator(@NotNull KtArrayAccessExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
super(context);
|
||||
this.expression = expression;
|
||||
@@ -87,7 +87,7 @@ public class ArrayAccessTranslator extends AbstractTranslator implements AccessT
|
||||
|
||||
@NotNull
|
||||
protected JsExpression getArrayExpression() {
|
||||
JetExpression arrayExpression = expression.getArrayExpression();
|
||||
KtExpression arrayExpression = expression.getArrayExpression();
|
||||
assert arrayExpression != null : "Code with parsing errors shouldn't be translated";
|
||||
return Translation.translateAsExpression(arrayExpression, context());
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class ArrayAccessTranslator extends AbstractTranslator implements AccessT
|
||||
ValueArgument valueArgument = ((ExpressionValueArgument) lastArgument).getValueArgument();
|
||||
assert valueArgument != null;
|
||||
|
||||
JetExpression element = valueArgument.getArgumentExpression();
|
||||
KtExpression element = valueArgument.getArgumentExpression();
|
||||
return context().innerContextWithAliasesForExpressions(Collections.singletonMap(element, toSetTo));
|
||||
}
|
||||
|
||||
@@ -117,16 +117,16 @@ public class ArrayAccessTranslator extends AbstractTranslator implements AccessT
|
||||
@Override
|
||||
public CachedAccessTranslator getCached() {
|
||||
List<TemporaryVariable> temporaries = new ArrayList<TemporaryVariable>();
|
||||
Map<JetExpression, JsExpression> aliases = new HashMap<JetExpression, JsExpression>();
|
||||
Map<KtExpression, JsExpression> aliases = new HashMap<KtExpression, JsExpression>();
|
||||
|
||||
TemporaryVariable temporaryArrayExpression = context().declareTemporary(getArrayExpression());
|
||||
temporaries.add(temporaryArrayExpression);
|
||||
|
||||
for (JetExpression jetExpression : expression.getIndexExpressions()) {
|
||||
JsExpression jsExpression = Translation.translateAsExpression(jetExpression, context());
|
||||
for (KtExpression ktExpression : expression.getIndexExpressions()) {
|
||||
JsExpression jsExpression = Translation.translateAsExpression(ktExpression, context());
|
||||
TemporaryVariable temporaryVariable = context().declareTemporary(jsExpression);
|
||||
temporaries.add(temporaryVariable);
|
||||
aliases.put(jetExpression, temporaryVariable.reference());
|
||||
aliases.put(ktExpression, temporaryVariable.reference());
|
||||
}
|
||||
return new CachedArrayAccessTranslator(expression, context().innerContextWithAliasesForExpressions(aliases),
|
||||
temporaryArrayExpression, temporaries);
|
||||
@@ -139,7 +139,7 @@ public class ArrayAccessTranslator extends AbstractTranslator implements AccessT
|
||||
private final List<TemporaryVariable> declaredTemporaries;
|
||||
|
||||
protected CachedArrayAccessTranslator(
|
||||
@NotNull JetArrayAccessExpression expression,
|
||||
@NotNull KtArrayAccessExpression expression,
|
||||
@NotNull TranslationContext context,
|
||||
@NotNull TemporaryVariable temporaryArrayExpression,
|
||||
@NotNull List<TemporaryVariable> temporaries
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptorKt;
|
||||
import org.jetbrains.kotlin.js.translate.context.TemporaryVariable;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -38,7 +38,7 @@ public final class BackingFieldAccessTranslator extends AbstractTranslator imple
|
||||
private final PropertyDescriptor descriptor;
|
||||
|
||||
/*package*/
|
||||
public static BackingFieldAccessTranslator newInstance(@NotNull JetSimpleNameExpression expression,
|
||||
public static BackingFieldAccessTranslator newInstance(@NotNull KtSimpleNameExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
PropertyDescriptor referencedProperty = SyntheticFieldDescriptorKt.getReferencedProperty(
|
||||
getDescriptorForReferenceExpression(context.bindingContext(), expression)
|
||||
|
||||
+3
-3
@@ -29,10 +29,10 @@ import org.jetbrains.kotlin.js.translate.expression.PatternTranslator
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator
|
||||
import org.jetbrains.kotlin.js.translate.general.Translation
|
||||
import org.jetbrains.kotlin.js.translate.utils.*
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.ValueArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
|
||||
import java.util.ArrayList
|
||||
import java.util.Collections
|
||||
@@ -336,7 +336,7 @@ public class CallArgumentTranslator private constructor(
|
||||
|
||||
}
|
||||
|
||||
private fun Map<TypeParameterDescriptor, JetType>.addReifiedTypeArgsTo(
|
||||
private fun Map<TypeParameterDescriptor, KtType>.addReifiedTypeArgsTo(
|
||||
info: CallArgumentTranslator.ArgumentsInfo,
|
||||
context: TranslationContext
|
||||
): CallArgumentTranslator.ArgumentsInfo {
|
||||
|
||||
+7
-7
@@ -25,8 +25,8 @@ import org.jetbrains.kotlin.js.parser.ParserUtilsKt;
|
||||
import org.jetbrains.kotlin.js.resolve.diagnostics.JsCallChecker;
|
||||
import org.jetbrains.kotlin.js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.psi.JetCallExpression;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.psi.ValueArgument;
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
@@ -43,7 +43,7 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl
|
||||
|
||||
@NotNull
|
||||
public static JsNode translate(
|
||||
@NotNull JetCallExpression expression,
|
||||
@NotNull KtCallExpression expression,
|
||||
@Nullable JsExpression receiver,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
@@ -62,7 +62,7 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl
|
||||
return callExpression;
|
||||
}
|
||||
|
||||
public static boolean shouldBeInlined(@NotNull JetCallExpression expression, @NotNull TranslationContext context) {
|
||||
public static boolean shouldBeInlined(@NotNull KtCallExpression expression, @NotNull TranslationContext context) {
|
||||
if (!context.getConfig().isInlineEnabled()) return false;
|
||||
|
||||
CallableDescriptor descriptor = getFunctionDescriptor(expression, context);
|
||||
@@ -83,7 +83,7 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl
|
||||
}
|
||||
|
||||
private CallExpressionTranslator(
|
||||
@NotNull JetCallExpression expression,
|
||||
@NotNull KtCallExpression expression,
|
||||
@Nullable JsExpression receiver,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
@@ -98,7 +98,7 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl
|
||||
@NotNull
|
||||
private JsNode translateJsCode() {
|
||||
List<? extends ValueArgument> arguments = expression.getValueArguments();
|
||||
JetExpression argumentExpression = arguments.get(0).getArgumentExpression();
|
||||
KtExpression argumentExpression = arguments.get(0).getArgumentExpression();
|
||||
assert argumentExpression != null;
|
||||
|
||||
List<JsStatement> statements = parseJsCode(argumentExpression);
|
||||
@@ -119,7 +119,7 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<JsStatement> parseJsCode(@NotNull JetExpression jsCodeExpression) {
|
||||
private List<JsStatement> parseJsCode(@NotNull KtExpression jsCodeExpression) {
|
||||
String jsCode = JsCallChecker.extractStringValue(getConstant(jsCodeExpression, context().bindingContext()));
|
||||
|
||||
assert jsCode != null : "jsCode must be compile time string " + jsCodeExpression.getText();
|
||||
|
||||
+5
-5
@@ -25,13 +25,13 @@ import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils
|
||||
import org.jetbrains.kotlin.js.translate.utils.BindingUtils
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsDescriptorUtils
|
||||
import org.jetbrains.kotlin.psi.JetCallableReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtCallableReferenceExpression
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import java.util.ArrayList
|
||||
|
||||
object CallableReferenceTranslator {
|
||||
|
||||
fun translate(expression: JetCallableReferenceExpression, context: TranslationContext): JsExpression {
|
||||
fun translate(expression: KtCallableReferenceExpression, context: TranslationContext): JsExpression {
|
||||
val descriptor = BindingUtils.getDescriptorForReferenceExpression(context.bindingContext(), expression.getCallableReference())
|
||||
return when (descriptor) {
|
||||
is PropertyDescriptor ->
|
||||
@@ -43,12 +43,12 @@ object CallableReferenceTranslator {
|
||||
}
|
||||
}
|
||||
|
||||
private fun reportNotSupported(context: TranslationContext, expression: JetCallableReferenceExpression): JsExpression {
|
||||
private fun reportNotSupported(context: TranslationContext, expression: KtCallableReferenceExpression): JsExpression {
|
||||
context.bindingTrace().report(ErrorsJs.REFERENCE_TO_BUILTIN_MEMBERS_NOT_SUPPORTED.on(expression, expression))
|
||||
return context.getEmptyExpression()
|
||||
}
|
||||
|
||||
private fun translateForFunction(descriptor: FunctionDescriptor, context: TranslationContext, expression: JetCallableReferenceExpression): JsExpression {
|
||||
private fun translateForFunction(descriptor: FunctionDescriptor, context: TranslationContext, expression: KtCallableReferenceExpression): JsExpression {
|
||||
return when {
|
||||
// TODO Support for callable reference to builtin functions and members
|
||||
JsDescriptorUtils.isBuiltin(descriptor) ->
|
||||
@@ -64,7 +64,7 @@ object CallableReferenceTranslator {
|
||||
}
|
||||
}
|
||||
|
||||
private fun translateForProperty(descriptor: PropertyDescriptor, context: TranslationContext, expression: JetCallableReferenceExpression): JsExpression {
|
||||
private fun translateForProperty(descriptor: PropertyDescriptor, context: TranslationContext, expression: KtCallableReferenceExpression): JsExpression {
|
||||
return when {
|
||||
// TODO Support for callable reference to builtin properties
|
||||
JsDescriptorUtils.isBuiltin(descriptor) ->
|
||||
|
||||
+4
-4
@@ -26,8 +26,8 @@ import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.intrinsic.objects.ObjectIntrinsic;
|
||||
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils;
|
||||
import org.jetbrains.kotlin.psi.JetReferenceExpression;
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.psi.KtReferenceExpression;
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -40,7 +40,7 @@ import static org.jetbrains.kotlin.resolve.DescriptorUtils.isNonCompanionObject;
|
||||
public class CompanionObjectAccessTranslator extends AbstractTranslator implements CachedAccessTranslator {
|
||||
@NotNull
|
||||
/*package*/ static CompanionObjectAccessTranslator newInstance(
|
||||
@NotNull JetSimpleNameExpression expression,
|
||||
@NotNull KtSimpleNameExpression expression,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
DeclarationDescriptor referenceDescriptor = getDescriptorForReferenceExpression(context.bindingContext(), expression);
|
||||
@@ -49,7 +49,7 @@ public class CompanionObjectAccessTranslator extends AbstractTranslator implemen
|
||||
}
|
||||
|
||||
/*package*/ static boolean isCompanionObjectReference(
|
||||
@NotNull JetReferenceExpression expression,
|
||||
@NotNull KtReferenceExpression expression,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
DeclarationDescriptor descriptor = getDescriptorForReferenceExpression(context.bindingContext(), expression);
|
||||
|
||||
+18
-18
@@ -39,7 +39,7 @@ public final class QualifiedExpressionTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AccessTranslator getAccessTranslator(@NotNull JetQualifiedExpression expression,
|
||||
public static AccessTranslator getAccessTranslator(@NotNull KtQualifiedExpression expression,
|
||||
@NotNull TranslationContext context, boolean forceOrderOfEvaluation) {
|
||||
JsExpression receiver = translateReceiver(expression, context);
|
||||
if (forceOrderOfEvaluation && receiver != null) {
|
||||
@@ -52,30 +52,30 @@ public final class QualifiedExpressionTranslator {
|
||||
|
||||
@NotNull
|
||||
public static JsNode translateQualifiedExpression(
|
||||
@NotNull JetQualifiedExpression expression,
|
||||
@NotNull KtQualifiedExpression expression,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
JsExpression receiver = translateReceiver(expression, context);
|
||||
JetExpression selector = getSelector(expression);
|
||||
KtExpression selector = getSelector(expression);
|
||||
return dispatchToCorrectTranslator(receiver, selector, context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JsNode dispatchToCorrectTranslator(
|
||||
@Nullable JsExpression receiver,
|
||||
@NotNull JetExpression selector,
|
||||
@NotNull KtExpression selector,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
if (ReferenceTranslator.canBePropertyAccess(selector, context)) {
|
||||
assert selector instanceof JetSimpleNameExpression : "Selectors for properties must be simple names.";
|
||||
return VariableAccessTranslator.newInstance(context, (JetSimpleNameExpression)selector, receiver).translateAsGet();
|
||||
assert selector instanceof KtSimpleNameExpression : "Selectors for properties must be simple names.";
|
||||
return VariableAccessTranslator.newInstance(context, (KtSimpleNameExpression)selector, receiver).translateAsGet();
|
||||
}
|
||||
if (selector instanceof JetCallExpression) {
|
||||
if (selector instanceof KtCallExpression) {
|
||||
return invokeCallExpressionTranslator(receiver, selector, context);
|
||||
}
|
||||
//TODO: never get there
|
||||
if (selector instanceof JetSimpleNameExpression) {
|
||||
return ReferenceTranslator.translateSimpleNameWithQualifier((JetSimpleNameExpression) selector, receiver, context);
|
||||
if (selector instanceof KtSimpleNameExpression) {
|
||||
return ReferenceTranslator.translateSimpleNameWithQualifier((KtSimpleNameExpression) selector, receiver, context);
|
||||
}
|
||||
throw new AssertionError("Unexpected qualified expression: " + selector.getText());
|
||||
}
|
||||
@@ -83,20 +83,20 @@ public final class QualifiedExpressionTranslator {
|
||||
@NotNull
|
||||
private static JsNode invokeCallExpressionTranslator(
|
||||
@Nullable JsExpression receiver,
|
||||
@NotNull JetExpression selector,
|
||||
@NotNull KtExpression selector,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
try {
|
||||
return CallExpressionTranslator.translate((JetCallExpression) selector, receiver, context);
|
||||
return CallExpressionTranslator.translate((KtCallExpression) selector, receiver, context);
|
||||
} catch (RuntimeException e) {
|
||||
throw ErrorReportingUtils.reportErrorWithLocation(selector, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JsExpression translateReceiver(@NotNull JetQualifiedExpression expression,
|
||||
private static JsExpression translateReceiver(@NotNull KtQualifiedExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
JetExpression receiverExpression = expression.getReceiverExpression();
|
||||
KtExpression receiverExpression = expression.getReceiverExpression();
|
||||
if (isFullQualifierForExpression(receiverExpression, context)) {
|
||||
return null;
|
||||
}
|
||||
@@ -104,19 +104,19 @@ public final class QualifiedExpressionTranslator {
|
||||
}
|
||||
|
||||
//TODO: prove correctness
|
||||
private static boolean isFullQualifierForExpression(@Nullable JetExpression receiverExpression, @NotNull TranslationContext context) {
|
||||
private static boolean isFullQualifierForExpression(@Nullable KtExpression receiverExpression, @NotNull TranslationContext context) {
|
||||
if (receiverExpression == null) {
|
||||
return false;
|
||||
}
|
||||
if (receiverExpression instanceof JetReferenceExpression) {
|
||||
if (receiverExpression instanceof KtReferenceExpression) {
|
||||
DeclarationDescriptor descriptorForReferenceExpression =
|
||||
getDescriptorForReferenceExpression(context.bindingContext(), (JetReferenceExpression)receiverExpression);
|
||||
getDescriptorForReferenceExpression(context.bindingContext(), (KtReferenceExpression)receiverExpression);
|
||||
if (descriptorForReferenceExpression instanceof PackageViewDescriptor) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (receiverExpression instanceof JetQualifiedExpression) {
|
||||
return isFullQualifierForExpression(((JetQualifiedExpression)receiverExpression).getSelectorExpression(), context);
|
||||
if (receiverExpression instanceof KtQualifiedExpression) {
|
||||
return isFullQualifierForExpression(((KtQualifiedExpression)receiverExpression).getSelectorExpression(), context);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.js.translate.context.TemporaryVariable;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -34,7 +34,7 @@ import static org.jetbrains.kotlin.js.translate.utils.BindingUtils.getDescriptor
|
||||
public final class ReferenceAccessTranslator extends AbstractTranslator implements CachedAccessTranslator {
|
||||
|
||||
@NotNull
|
||||
/*package*/ static ReferenceAccessTranslator newInstance(@NotNull JetSimpleNameExpression expression,
|
||||
/*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();
|
||||
|
||||
+14
-15
@@ -20,20 +20,19 @@ import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor;
|
||||
import org.jetbrains.kotlin.js.translate.context.Namer;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.BindingUtils;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.JetQualifiedExpression;
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.psi.KtQualifiedExpression;
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
|
||||
import static org.jetbrains.kotlin.js.translate.utils.BindingUtils.getDescriptorForReferenceExpression;
|
||||
import static org.jetbrains.kotlin.js.translate.utils.JsAstUtils.setQualifier;
|
||||
import static org.jetbrains.kotlin.js.translate.utils.PsiUtils.getSelectorAsSimpleName;
|
||||
import static org.jetbrains.kotlin.psi.JetPsiUtil.isBackingFieldReference;
|
||||
import static org.jetbrains.kotlin.psi.KtPsiUtil.isBackingFieldReference;
|
||||
|
||||
public final class ReferenceTranslator {
|
||||
|
||||
@@ -41,14 +40,14 @@ public final class ReferenceTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translateSimpleName(@NotNull JetSimpleNameExpression expression,
|
||||
public static JsExpression translateSimpleName(@NotNull KtSimpleNameExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return getAccessTranslator(expression, context).translateAsGet();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translateSimpleNameWithQualifier(
|
||||
@NotNull JetSimpleNameExpression expression,
|
||||
@NotNull KtSimpleNameExpression expression,
|
||||
@Nullable JsExpression qualifier,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
@@ -95,13 +94,13 @@ public final class ReferenceTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AccessTranslator getAccessTranslator(@NotNull JetSimpleNameExpression referenceExpression,
|
||||
public static AccessTranslator getAccessTranslator(@NotNull KtSimpleNameExpression referenceExpression,
|
||||
@NotNull TranslationContext context) {
|
||||
return getAccessTranslator(referenceExpression, null, context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AccessTranslator getAccessTranslator(@NotNull JetSimpleNameExpression referenceExpression,
|
||||
public static AccessTranslator getAccessTranslator(@NotNull KtSimpleNameExpression referenceExpression,
|
||||
@Nullable JsExpression receiver,
|
||||
@NotNull TranslationContext context) {
|
||||
if (isBackingFieldReference(referenceExpression, getDescriptorForReferenceExpression(context.bindingContext(), referenceExpression))) {
|
||||
@@ -116,13 +115,13 @@ public final class ReferenceTranslator {
|
||||
return ReferenceAccessTranslator.newInstance(referenceExpression, context);
|
||||
}
|
||||
|
||||
public static boolean canBePropertyAccess(@NotNull JetExpression expression, @NotNull TranslationContext context) {
|
||||
JetSimpleNameExpression simpleNameExpression = null;
|
||||
if (expression instanceof JetQualifiedExpression) {
|
||||
simpleNameExpression = getSelectorAsSimpleName((JetQualifiedExpression) expression);
|
||||
public static boolean canBePropertyAccess(@NotNull KtExpression expression, @NotNull TranslationContext context) {
|
||||
KtSimpleNameExpression simpleNameExpression = null;
|
||||
if (expression instanceof KtQualifiedExpression) {
|
||||
simpleNameExpression = getSelectorAsSimpleName((KtQualifiedExpression) expression);
|
||||
}
|
||||
else if (expression instanceof JetSimpleNameExpression) {
|
||||
simpleNameExpression = (JetSimpleNameExpression) expression;
|
||||
else if (expression instanceof KtSimpleNameExpression) {
|
||||
simpleNameExpression = (KtSimpleNameExpression) expression;
|
||||
}
|
||||
|
||||
if (simpleNameExpression == null) return false;
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.context.TemporaryVariable;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.kotlin.psi.JetReferenceExpression;
|
||||
import org.jetbrains.kotlin.psi.KtReferenceExpression;
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall;
|
||||
@@ -35,7 +35,7 @@ import java.util.List;
|
||||
public class VariableAccessTranslator extends AbstractTranslator implements AccessTranslator {
|
||||
public static VariableAccessTranslator newInstance(
|
||||
@NotNull TranslationContext context,
|
||||
@NotNull JetReferenceExpression referenceExpression,
|
||||
@NotNull KtReferenceExpression referenceExpression,
|
||||
@Nullable JsExpression receiver
|
||||
) {
|
||||
ResolvedCall<?> resolvedCall = CallUtilKt.getResolvedCallWithAssert(referenceExpression, context.bindingContext());
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.JetTestFunctionDetector;
|
||||
import org.jetbrains.kotlin.js.translate.reference.ReferenceTranslator;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -39,7 +39,7 @@ public final class JSTestGenerator {
|
||||
}
|
||||
|
||||
public static void generateTestCalls(@NotNull TranslationContext context,
|
||||
@NotNull Collection<JetFile> files, @NotNull JSTester tester) {
|
||||
@NotNull Collection<KtFile> files, @NotNull JSTester tester) {
|
||||
List<FunctionDescriptor> functionDescriptors = JetTestFunctionDetector.getTestFunctionDescriptors(context.bindingContext(), files);
|
||||
doGenerateTestCalls(functionDescriptors, context, tester);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
|
||||
import java.util.List;
|
||||
@@ -60,56 +60,56 @@ public final class BindingUtils {
|
||||
|
||||
@NotNull
|
||||
public static ClassDescriptor getClassDescriptor(@NotNull BindingContext context,
|
||||
@NotNull JetClassOrObject declaration) {
|
||||
@NotNull KtClassOrObject declaration) {
|
||||
return BindingContextUtils.getNotNull(context, BindingContext.CLASS, declaration);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static FunctionDescriptor getFunctionDescriptor(@NotNull BindingContext context,
|
||||
@NotNull JetDeclarationWithBody declaration) {
|
||||
@NotNull KtDeclarationWithBody declaration) {
|
||||
return getDescriptorForExpression(context, declaration, FunctionDescriptor.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PropertyDescriptor getPropertyDescriptor(@NotNull BindingContext context,
|
||||
@NotNull JetProperty declaration) {
|
||||
@NotNull KtProperty declaration) {
|
||||
return getDescriptorForExpression(context, declaration, PropertyDescriptor.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JetParameter getParameterForDescriptor(@NotNull ValueParameterDescriptor descriptor) {
|
||||
private static KtParameter getParameterForDescriptor(@NotNull ValueParameterDescriptor descriptor) {
|
||||
PsiElement result = DescriptorToSourceUtils.descriptorToDeclaration(descriptor);
|
||||
assert result instanceof JetParameter : message(descriptor, "ValueParameterDescriptor should have corresponding JetParameter");
|
||||
return (JetParameter) result;
|
||||
assert result instanceof KtParameter : message(descriptor, "ValueParameterDescriptor should have corresponding JetParameter");
|
||||
return (KtParameter) result;
|
||||
}
|
||||
|
||||
public static boolean hasAncestorClass(@NotNull BindingContext context, @NotNull JetClassOrObject classDeclaration) {
|
||||
public static boolean hasAncestorClass(@NotNull BindingContext context, @NotNull KtClassOrObject classDeclaration) {
|
||||
ClassDescriptor classDescriptor = getClassDescriptor(context, classDeclaration);
|
||||
List<ClassDescriptor> superclassDescriptors = DescriptorUtils.getSuperclassDescriptors(classDescriptor);
|
||||
return (JsDescriptorUtils.findAncestorClass(superclassDescriptors) != null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetType getTypeByReference(@NotNull BindingContext context,
|
||||
@NotNull JetTypeReference typeReference) {
|
||||
public static KtType getTypeByReference(@NotNull BindingContext context,
|
||||
@NotNull KtTypeReference typeReference) {
|
||||
return BindingContextUtils.getNotNull(context, BindingContext.TYPE, typeReference);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ClassDescriptor getClassDescriptorForTypeReference(@NotNull BindingContext context,
|
||||
@NotNull JetTypeReference typeReference) {
|
||||
@NotNull KtTypeReference typeReference) {
|
||||
return DescriptorUtils.getClassDescriptorForType(getTypeByReference(context, typeReference));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PropertyDescriptor getPropertyDescriptorForConstructorParameter(@NotNull BindingContext context,
|
||||
@NotNull JetParameter parameter) {
|
||||
@NotNull KtParameter parameter) {
|
||||
return context.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static DeclarationDescriptor getDescriptorForReferenceExpression(@NotNull BindingContext context,
|
||||
@NotNull JetReferenceExpression reference) {
|
||||
@NotNull KtReferenceExpression reference) {
|
||||
if (BindingContextUtils.isExpressionWithValidReference(reference, context)) {
|
||||
return BindingContextUtils.getNotNull(context, BindingContext.REFERENCE_TARGET, reference);
|
||||
}
|
||||
@@ -118,20 +118,20 @@ public final class BindingUtils {
|
||||
|
||||
@Nullable
|
||||
public static DeclarationDescriptor getNullableDescriptorForReferenceExpression(@NotNull BindingContext context,
|
||||
@NotNull JetReferenceExpression reference) {
|
||||
@NotNull KtReferenceExpression reference) {
|
||||
return context.get(BindingContext.REFERENCE_TARGET, reference);
|
||||
}
|
||||
|
||||
public static boolean isVariableReassignment(@NotNull BindingContext context, @NotNull JetExpression expression) {
|
||||
public static boolean isVariableReassignment(@NotNull BindingContext context, @NotNull KtExpression expression) {
|
||||
return BindingContextUtils.getNotNull(context, BindingContext.VARIABLE_REASSIGNMENT, expression);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static CallableDescriptor getCallableDescriptorForOperationExpression(
|
||||
@NotNull BindingContext context,
|
||||
@NotNull JetOperationExpression expression
|
||||
@NotNull KtOperationExpression expression
|
||||
) {
|
||||
JetSimpleNameExpression operationReference = expression.getOperationReference();
|
||||
KtSimpleNameExpression operationReference = expression.getOperationReference();
|
||||
DeclarationDescriptor descriptorForReferenceExpression =
|
||||
getNullableDescriptorForReferenceExpression(context, operationReference);
|
||||
|
||||
@@ -149,7 +149,7 @@ public final class BindingUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Object getCompileTimeValue(@NotNull BindingContext context, @NotNull JetExpression expression) {
|
||||
public static Object getCompileTimeValue(@NotNull BindingContext context, @NotNull KtExpression expression) {
|
||||
CompileTimeConstant<?> compileTimeValue = ConstantExpressionEvaluator.getConstant(expression, context);
|
||||
if (compileTimeValue != null) {
|
||||
return getCompileTimeValue(context, expression, compileTimeValue);
|
||||
@@ -158,17 +158,17 @@ public final class BindingUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Object getCompileTimeValue(@NotNull BindingContext context, @NotNull JetExpression expression, @NotNull CompileTimeConstant<?> constant) {
|
||||
JetType expectedType = context.getType(expression);
|
||||
public static Object getCompileTimeValue(@NotNull BindingContext context, @NotNull KtExpression expression, @NotNull CompileTimeConstant<?> constant) {
|
||||
KtType expectedType = context.getType(expression);
|
||||
return constant.getValue(expectedType == null ? TypeUtils.NO_EXPECTED_TYPE : expectedType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetExpression getDefaultArgument(@NotNull ValueParameterDescriptor parameterDescriptor) {
|
||||
public static KtExpression getDefaultArgument(@NotNull ValueParameterDescriptor parameterDescriptor) {
|
||||
ValueParameterDescriptor descriptorWhichDeclaresDefaultValue =
|
||||
getOriginalDescriptorWhichDeclaresDefaultValue(parameterDescriptor);
|
||||
JetParameter psiParameter = getParameterForDescriptor(descriptorWhichDeclaresDefaultValue);
|
||||
JetExpression defaultValue = psiParameter.getDefaultValue();
|
||||
KtParameter psiParameter = getParameterForDescriptor(descriptorWhichDeclaresDefaultValue);
|
||||
KtExpression defaultValue = psiParameter.getDefaultValue();
|
||||
assert defaultValue != null : message(parameterDescriptor, "No default value found in PSI");
|
||||
return defaultValue;
|
||||
}
|
||||
@@ -187,31 +187,31 @@ public final class BindingUtils {
|
||||
|
||||
@NotNull
|
||||
public static ResolvedCall<FunctionDescriptor> getIteratorFunction(@NotNull BindingContext context,
|
||||
@NotNull JetExpression rangeExpression) {
|
||||
@NotNull KtExpression rangeExpression) {
|
||||
return BindingContextUtils.getNotNull(context, BindingContext.LOOP_RANGE_ITERATOR_RESOLVED_CALL, rangeExpression);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ResolvedCall<FunctionDescriptor> getNextFunction(@NotNull BindingContext context,
|
||||
@NotNull JetExpression rangeExpression) {
|
||||
@NotNull KtExpression rangeExpression) {
|
||||
return BindingContextUtils.getNotNull(context, BindingContext.LOOP_RANGE_NEXT_RESOLVED_CALL, rangeExpression);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ResolvedCall<FunctionDescriptor> getHasNextCallable(@NotNull BindingContext context,
|
||||
@NotNull JetExpression rangeExpression) {
|
||||
@NotNull KtExpression rangeExpression) {
|
||||
return BindingContextUtils.getNotNull(context, BindingContext.LOOP_RANGE_HAS_NEXT_RESOLVED_CALL, rangeExpression);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetType getTypeForExpression(@NotNull BindingContext context,
|
||||
@NotNull JetExpression expression) {
|
||||
public static KtType getTypeForExpression(@NotNull BindingContext context,
|
||||
@NotNull KtExpression expression) {
|
||||
return BindingContextUtils.getTypeNotNull(context, expression);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ResolvedCall<FunctionDescriptor> getResolvedCallForArrayAccess(@NotNull BindingContext context,
|
||||
@NotNull JetArrayAccessExpression arrayAccessExpression,
|
||||
@NotNull KtArrayAccessExpression arrayAccessExpression,
|
||||
boolean isGet) {
|
||||
return BindingContextUtils.getNotNull(context, isGet ? INDEXED_LVALUE_GET : INDEXED_LVALUE_SET, arrayAccessExpression);
|
||||
}
|
||||
|
||||
+2
-2
@@ -20,14 +20,14 @@ import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
|
||||
public final class ErrorReportingUtils {
|
||||
private ErrorReportingUtils() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static RuntimeException reportErrorWithLocation(@NotNull JetExpression selector, @NotNull RuntimeException e) {
|
||||
public static RuntimeException reportErrorWithLocation(@NotNull KtExpression selector, @NotNull RuntimeException e) {
|
||||
return reportErrorWithLocation(e, DiagnosticUtils.atLocation(selector));
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -25,10 +25,10 @@ import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.general.Translation;
|
||||
import org.jetbrains.kotlin.js.translate.utils.mutator.Mutator;
|
||||
import org.jetbrains.kotlin.psi.JetDeclarationWithBody;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.KtDeclarationWithBody;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -41,7 +41,7 @@ public final class FunctionBodyTranslator extends AbstractTranslator {
|
||||
|
||||
@NotNull
|
||||
public static JsBlock translateFunctionBody(@NotNull FunctionDescriptor descriptor,
|
||||
@NotNull JetDeclarationWithBody declarationWithBody,
|
||||
@NotNull KtDeclarationWithBody declarationWithBody,
|
||||
@NotNull TranslationContext functionBodyContext) {
|
||||
return (new FunctionBodyTranslator(descriptor, declarationWithBody, functionBodyContext)).translate();
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public final class FunctionBodyTranslator extends AbstractTranslator {
|
||||
if (!DescriptorUtilsKt.hasDefaultValue(valueParameter)) continue;
|
||||
|
||||
JsNameRef jsNameRef = functionBodyContext.getNameForDescriptor(valueParameter).makeRef();
|
||||
JetExpression defaultArgument = getDefaultArgument(valueParameter);
|
||||
KtExpression defaultArgument = getDefaultArgument(valueParameter);
|
||||
JsBlock defaultArgBlock = new JsBlock();
|
||||
JsExpression defaultValue = Translation.translateAsExpression(defaultArgument, functionBodyContext, defaultArgBlock);
|
||||
JsStatement assignStatement = assignment(jsNameRef, defaultValue).makeStmt();
|
||||
@@ -72,10 +72,10 @@ public final class FunctionBodyTranslator extends AbstractTranslator {
|
||||
@NotNull
|
||||
private final FunctionDescriptor descriptor;
|
||||
@NotNull
|
||||
private final JetDeclarationWithBody declaration;
|
||||
private final KtDeclarationWithBody declaration;
|
||||
|
||||
private FunctionBodyTranslator(@NotNull FunctionDescriptor descriptor,
|
||||
@NotNull JetDeclarationWithBody declaration,
|
||||
@NotNull KtDeclarationWithBody declaration,
|
||||
@NotNull TranslationContext context) {
|
||||
super(context);
|
||||
this.descriptor = descriptor;
|
||||
@@ -84,7 +84,7 @@ public final class FunctionBodyTranslator extends AbstractTranslator {
|
||||
|
||||
@NotNull
|
||||
private JsBlock translate() {
|
||||
JetExpression jetBodyExpression = declaration.getBodyExpression();
|
||||
KtExpression jetBodyExpression = declaration.getBodyExpression();
|
||||
assert jetBodyExpression != null : "Cannot translate a body of an abstract function.";
|
||||
JsBlock jsBlock = new JsBlock(setDefaultValueForArguments(descriptor, context()));
|
||||
jsBlock.getStatements().addAll(mayBeWrapWithReturn(Translation.translateExpression(jetBodyExpression, context(), jsBlock)).getStatements());
|
||||
@@ -100,7 +100,7 @@ public final class FunctionBodyTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
private boolean mustAddReturnToGeneratedFunctionBody() {
|
||||
JetType functionReturnType = descriptor.getReturnType();
|
||||
KtType functionReturnType = descriptor.getReturnType();
|
||||
assert functionReturnType != null : "Function return typed type must be resolved.";
|
||||
return (!declaration.hasBlockBody()) && (!KotlinBuiltIns.isUnit(functionReturnType));
|
||||
}
|
||||
|
||||
@@ -27,11 +27,11 @@ import org.jetbrains.kotlin.js.config.LibrarySourcesConfig;
|
||||
import org.jetbrains.kotlin.js.descriptorUtils.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -80,11 +80,11 @@ public final class JsDescriptorUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<JetType> getSupertypesWithoutFakes(ClassDescriptor descriptor) {
|
||||
Collection<JetType> supertypes = descriptor.getTypeConstructor().getSupertypes();
|
||||
return ContainerUtil.filter(supertypes, new Condition<JetType>() {
|
||||
public static List<KtType> getSupertypesWithoutFakes(ClassDescriptor descriptor) {
|
||||
Collection<KtType> supertypes = descriptor.getTypeConstructor().getSupertypes();
|
||||
return ContainerUtil.filter(supertypes, new Condition<KtType>() {
|
||||
@Override
|
||||
public boolean value(JetType type) {
|
||||
public boolean value(KtType type) {
|
||||
ClassDescriptor classDescriptor = getClassDescriptorForType(type);
|
||||
|
||||
return !FAKE_CLASSES.contains(getFqNameSafe(classDescriptor).asString()) &&
|
||||
@@ -160,8 +160,8 @@ public final class JsDescriptorUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Name getNameIfStandardType(@NotNull JetExpression expression, @NotNull TranslationContext context) {
|
||||
JetType type = context.bindingContext().getType(expression);
|
||||
public static Name getNameIfStandardType(@NotNull KtExpression expression, @NotNull TranslationContext context) {
|
||||
KtType type = context.bindingContext().getType(expression);
|
||||
return type != null ? DescriptorUtilsKt.getNameIfStandardType(type) : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.name.FqNameUnsafe;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -154,7 +154,7 @@ public class ManglingUtils {
|
||||
private static String getSimpleMangledName(@NotNull CallableMemberDescriptor descriptor) {
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
|
||||
JetScope jetScope = null;
|
||||
KtScope jetScope = null;
|
||||
|
||||
String nameToCompare = descriptor.getName().asString();
|
||||
|
||||
@@ -175,7 +175,7 @@ public class ManglingUtils {
|
||||
if (jetScope != null) {
|
||||
final String finalNameToCompare = nameToCompare;
|
||||
|
||||
Collection<DeclarationDescriptor> declarations = jetScope.getDescriptors(DescriptorKindFilter.CALLABLES, JetScope.Companion.getALL_NAME_FILTER());
|
||||
Collection<DeclarationDescriptor> declarations = jetScope.getDescriptors(DescriptorKindFilter.CALLABLES, KtScope.Companion.getALL_NAME_FILTER());
|
||||
List<CallableDescriptor> overloadedFunctions =
|
||||
CollectionsKt.flatMap(declarations, new Function1<DeclarationDescriptor, Iterable<? extends CallableDescriptor>>() {
|
||||
@Override
|
||||
|
||||
@@ -21,8 +21,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.lexer.JetToken;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.lexer.KtToken;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
@@ -37,103 +37,103 @@ public final class PsiUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetSimpleNameExpression getSimpleName(@NotNull JetExpression expression) {
|
||||
if (expression instanceof JetSimpleNameExpression) {
|
||||
return (JetSimpleNameExpression) expression;
|
||||
public static KtSimpleNameExpression getSimpleName(@NotNull KtExpression expression) {
|
||||
if (expression instanceof KtSimpleNameExpression) {
|
||||
return (KtSimpleNameExpression) expression;
|
||||
}
|
||||
|
||||
if (expression instanceof JetQualifiedExpression) {
|
||||
return getSelectorAsSimpleName((JetQualifiedExpression) expression);
|
||||
if (expression instanceof KtQualifiedExpression) {
|
||||
return getSelectorAsSimpleName((KtQualifiedExpression) expression);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetSimpleNameExpression getSelectorAsSimpleName(@NotNull JetQualifiedExpression expression) {
|
||||
JetExpression selectorExpression = getSelector(expression);
|
||||
if (!(selectorExpression instanceof JetSimpleNameExpression)) {
|
||||
public static KtSimpleNameExpression getSelectorAsSimpleName(@NotNull KtQualifiedExpression expression) {
|
||||
KtExpression selectorExpression = getSelector(expression);
|
||||
if (!(selectorExpression instanceof KtSimpleNameExpression)) {
|
||||
return null;
|
||||
}
|
||||
return (JetSimpleNameExpression) selectorExpression;
|
||||
return (KtSimpleNameExpression) selectorExpression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetExpression getSelector(@NotNull JetQualifiedExpression expression) {
|
||||
JetExpression selectorExpression = expression.getSelectorExpression();
|
||||
public static KtExpression getSelector(@NotNull KtQualifiedExpression expression) {
|
||||
KtExpression selectorExpression = expression.getSelectorExpression();
|
||||
assert selectorExpression != null : "Selector should not be null.";
|
||||
return selectorExpression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetSimpleNameExpression getNotNullSimpleNameSelector(@NotNull JetQualifiedExpression expression) {
|
||||
JetSimpleNameExpression selectorAsSimpleName = getSelectorAsSimpleName(expression);
|
||||
public static KtSimpleNameExpression getNotNullSimpleNameSelector(@NotNull KtQualifiedExpression expression) {
|
||||
KtSimpleNameExpression selectorAsSimpleName = getSelectorAsSimpleName(expression);
|
||||
assert selectorAsSimpleName != null;
|
||||
return selectorAsSimpleName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetToken getOperationToken(@NotNull JetOperationExpression expression) {
|
||||
JetSimpleNameExpression operationExpression = expression.getOperationReference();
|
||||
public static KtToken getOperationToken(@NotNull KtOperationExpression expression) {
|
||||
KtSimpleNameExpression operationExpression = expression.getOperationReference();
|
||||
IElementType elementType = operationExpression.getReferencedNameElementType();
|
||||
assert elementType instanceof JetToken : "Expected JetToken type, but " + elementType.getClass() + ", expression: " + expression.getText();
|
||||
return (JetToken) elementType;
|
||||
assert elementType instanceof KtToken : "Expected KtToken type, but " + elementType.getClass() + ", expression: " + expression.getText();
|
||||
return (KtToken) elementType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetExpression getBaseExpression(@NotNull JetUnaryExpression expression) {
|
||||
JetExpression baseExpression = expression.getBaseExpression();
|
||||
public static KtExpression getBaseExpression(@NotNull KtUnaryExpression expression) {
|
||||
KtExpression baseExpression = expression.getBaseExpression();
|
||||
assert baseExpression != null;
|
||||
return baseExpression;
|
||||
}
|
||||
|
||||
public static boolean isPrefix(@NotNull JetUnaryExpression expression) {
|
||||
return (expression instanceof JetPrefixExpression);
|
||||
public static boolean isPrefix(@NotNull KtUnaryExpression expression) {
|
||||
return (expression instanceof KtPrefixExpression);
|
||||
}
|
||||
|
||||
public static boolean isAssignment(JetToken token) {
|
||||
return (token == JetTokens.EQ);
|
||||
public static boolean isAssignment(KtToken token) {
|
||||
return (token == KtTokens.EQ);
|
||||
}
|
||||
|
||||
public static boolean isInOrNotInOperation(@NotNull JetBinaryExpression binaryExpression) {
|
||||
public static boolean isInOrNotInOperation(@NotNull KtBinaryExpression binaryExpression) {
|
||||
return isInOperation(binaryExpression) || isNotInOperation(binaryExpression);
|
||||
}
|
||||
|
||||
public static boolean isNotInOperation(@NotNull JetBinaryExpression binaryExpression) {
|
||||
return (binaryExpression.getOperationToken() == JetTokens.NOT_IN);
|
||||
public static boolean isNotInOperation(@NotNull KtBinaryExpression binaryExpression) {
|
||||
return (binaryExpression.getOperationToken() == KtTokens.NOT_IN);
|
||||
}
|
||||
|
||||
public static boolean isNegatedOperation(@NotNull JetBinaryExpression binaryExpression) {
|
||||
return (binaryExpression.getOperationToken() == JetTokens.EXCLEQ) || isNotInOperation(binaryExpression);
|
||||
public static boolean isNegatedOperation(@NotNull KtBinaryExpression binaryExpression) {
|
||||
return (binaryExpression.getOperationToken() == KtTokens.EXCLEQ) || isNotInOperation(binaryExpression);
|
||||
}
|
||||
|
||||
private static boolean isInOperation(@NotNull JetBinaryExpression binaryExpression) {
|
||||
return (binaryExpression.getOperationToken() == JetTokens.IN_KEYWORD);
|
||||
private static boolean isInOperation(@NotNull KtBinaryExpression binaryExpression) {
|
||||
return (binaryExpression.getOperationToken() == KtTokens.IN_KEYWORD);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetParameter getLoopParameter(@NotNull JetForExpression expression) {
|
||||
public static KtParameter getLoopParameter(@NotNull KtForExpression expression) {
|
||||
return expression.getLoopParameter();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<JetParameter> getPrimaryConstructorParameters(@NotNull JetClassOrObject classDeclaration) {
|
||||
if (classDeclaration instanceof JetClass) {
|
||||
public static List<KtParameter> getPrimaryConstructorParameters(@NotNull KtClassOrObject classDeclaration) {
|
||||
if (classDeclaration instanceof KtClass) {
|
||||
return classDeclaration.getPrimaryConstructorParameters();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetExpression getLoopRange(@NotNull JetForExpression expression) {
|
||||
JetExpression rangeExpression = expression.getLoopRange();
|
||||
public static KtExpression getLoopRange(@NotNull KtForExpression expression) {
|
||||
KtExpression rangeExpression = expression.getLoopRange();
|
||||
assert rangeExpression != null;
|
||||
return rangeExpression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static CallableDescriptor getFunctionDescriptor(
|
||||
@NotNull JetCallExpression expression,
|
||||
@NotNull KtCallExpression expression,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
ResolvedCall<?> resolvedCall = CallUtilKt.getResolvedCall(expression, context.bindingContext());
|
||||
|
||||
+13
-13
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.Translation;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -168,10 +168,10 @@ public final class TranslationUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JsExpression translateInitializerForProperty(@NotNull JetProperty declaration,
|
||||
public static JsExpression translateInitializerForProperty(@NotNull KtProperty declaration,
|
||||
@NotNull TranslationContext context) {
|
||||
JsExpression jsInitExpression = null;
|
||||
JetExpression initializer = declaration.getInitializer();
|
||||
KtExpression initializer = declaration.getInitializer();
|
||||
if (initializer != null) {
|
||||
jsInitExpression = Translation.translateAsExpression(initializer, context);
|
||||
}
|
||||
@@ -180,51 +180,51 @@ public final class TranslationUtils {
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translateBaseExpression(@NotNull TranslationContext context,
|
||||
@NotNull JetUnaryExpression expression) {
|
||||
JetExpression baseExpression = PsiUtils.getBaseExpression(expression);
|
||||
@NotNull KtUnaryExpression expression) {
|
||||
KtExpression baseExpression = PsiUtils.getBaseExpression(expression);
|
||||
return Translation.translateAsExpression(baseExpression, context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translateLeftExpression(@NotNull TranslationContext context,
|
||||
@NotNull JetBinaryExpression expression) {
|
||||
@NotNull KtBinaryExpression expression) {
|
||||
return translateLeftExpression(context, expression, context.dynamicContext().jsBlock());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translateLeftExpression(
|
||||
@NotNull TranslationContext context,
|
||||
@NotNull JetBinaryExpression expression,
|
||||
@NotNull KtBinaryExpression expression,
|
||||
@NotNull JsBlock block
|
||||
) {
|
||||
JetExpression left = expression.getLeft();
|
||||
KtExpression left = expression.getLeft();
|
||||
assert left != null : "Binary expression should have a left expression: " + expression.getText();
|
||||
return Translation.translateAsExpression(left, context, block);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translateRightExpression(@NotNull TranslationContext context,
|
||||
@NotNull JetBinaryExpression expression) {
|
||||
@NotNull KtBinaryExpression expression) {
|
||||
return translateRightExpression(context, expression, context.dynamicContext().jsBlock());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translateRightExpression(
|
||||
@NotNull TranslationContext context,
|
||||
@NotNull JetBinaryExpression expression,
|
||||
@NotNull KtBinaryExpression expression,
|
||||
@NotNull JsBlock block) {
|
||||
JetExpression rightExpression = expression.getRight();
|
||||
KtExpression rightExpression = expression.getRight();
|
||||
assert rightExpression != null : "Binary expression should have a right expression";
|
||||
return Translation.translateAsExpression(rightExpression, context, block);
|
||||
}
|
||||
|
||||
public static boolean hasCorrespondingFunctionIntrinsic(@NotNull TranslationContext context,
|
||||
@NotNull JetOperationExpression expression) {
|
||||
@NotNull KtOperationExpression expression) {
|
||||
CallableDescriptor operationDescriptor = getCallableDescriptorForOperationExpression(context.bindingContext(), expression);
|
||||
|
||||
if (operationDescriptor == null || !(operationDescriptor instanceof FunctionDescriptor)) return true;
|
||||
|
||||
JetType returnType = operationDescriptor.getReturnType();
|
||||
KtType returnType = operationDescriptor.getReturnType();
|
||||
if (returnType != null && (KotlinBuiltIns.isChar(returnType) || KotlinBuiltIns.isLong(returnType))) return false;
|
||||
|
||||
if (context.intrinsics().getFunctionIntrinsic((FunctionDescriptor) operationDescriptor).exists()) return true;
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.js.inline.util.isCallInvocation
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||
import org.jetbrains.kotlin.js.translate.reference.CallExpressionTranslator
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineStrategy
|
||||
|
||||
@@ -43,7 +43,7 @@ import org.jetbrains.kotlin.resolve.inline.InlineStrategy
|
||||
*/
|
||||
fun setInlineCallMetadata(
|
||||
expression: JsExpression,
|
||||
psiElement: JetExpression,
|
||||
psiElement: KtExpression,
|
||||
resolvedCall: ResolvedCall<*>,
|
||||
context: TranslationContext
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user