run code coverage
eliminate dead and unuseful code
This commit is contained in:
@@ -22,6 +22,9 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public final class Analyzer {
|
public final class Analyzer {
|
||||||
|
|
||||||
|
private Analyzer() {
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static BindingContext analyzeFilesAndCheckErrors(@NotNull List<JetFile> files,
|
public static BindingContext analyzeFilesAndCheckErrors(@NotNull List<JetFile> files,
|
||||||
@NotNull Config config) {
|
@NotNull Config config) {
|
||||||
@@ -57,7 +60,7 @@ public final class Analyzer {
|
|||||||
@Override
|
@Override
|
||||||
public boolean apply(@Nullable PsiFile file) {
|
public boolean apply(@Nullable PsiFile file) {
|
||||||
assert file instanceof JetFile;
|
assert file instanceof JetFile;
|
||||||
boolean notLibFile = !jsLibFiles.contains(file);
|
@SuppressWarnings("UnnecessaryLocalVariable") boolean notLibFile = !jsLibFiles.contains(file);
|
||||||
return notLibFile;
|
return notLibFile;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -88,7 +91,4 @@ public final class Analyzer {
|
|||||||
@NotNull WritableScope namespaceMemberScope) {
|
@NotNull WritableScope namespaceMemberScope) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Analyzer() {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,6 @@ public final class CodeGenerator {
|
|||||||
private final TextOutput output = new DefaultTextOutput(false);
|
private final TextOutput output = new DefaultTextOutput(false);
|
||||||
|
|
||||||
public CodeGenerator() {
|
public CodeGenerator() {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void generateToConsole(@NotNull JsProgram program) {
|
|
||||||
generateCode(program);
|
|
||||||
System.out.println(output.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateToFile(@NotNull JsProgram program, @NotNull File file) throws IOException {
|
public void generateToFile(@NotNull JsProgram program, @NotNull File file) throws IOException {
|
||||||
|
|||||||
@@ -36,12 +36,6 @@ public final class StandardClasses {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void externalObject(@NotNull String nativeName) {
|
|
||||||
currentObjectName = nativeName;
|
|
||||||
assert currentFQName != null;
|
|
||||||
declareExternalTopLevelObject(currentFQName, nativeName);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void kotlinTopLevelObject(@NotNull String kotlinName) {
|
private void kotlinTopLevelObject(@NotNull String kotlinName) {
|
||||||
assert currentFQName != null;
|
assert currentFQName != null;
|
||||||
currentObjectName = kotlinName;
|
currentObjectName = kotlinName;
|
||||||
@@ -78,9 +72,8 @@ public final class StandardClasses {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static StandardClasses bindImplementations(@NotNull JsScope kotlinObjectScope,
|
public static StandardClasses bindImplementations(@NotNull JsScope kotlinObjectScope) {
|
||||||
@NotNull JsScope rootScope) {
|
StandardClasses standardClasses = new StandardClasses(kotlinObjectScope);
|
||||||
StandardClasses standardClasses = new StandardClasses(kotlinObjectScope, rootScope);
|
|
||||||
declareJetObjects(standardClasses);
|
declareJetObjects(standardClasses);
|
||||||
return standardClasses;
|
return standardClasses;
|
||||||
}
|
}
|
||||||
@@ -93,9 +86,6 @@ public final class StandardClasses {
|
|||||||
standardClasses.declare().forFQ("jet.IntRange").kotlinClass("NumberRange")
|
standardClasses.declare().forFQ("jet.IntRange").kotlinClass("NumberRange")
|
||||||
.methods("iterator", "contains").properties("start", "size", "end", "reversed");
|
.methods("iterator", "contains").properties("start", "size", "end", "reversed");
|
||||||
|
|
||||||
// standardClasses.declare().forFQ("jet.String").kotlinClass("String").
|
|
||||||
// properties("length");
|
|
||||||
|
|
||||||
standardClasses.declare().forFQ("jet.Any.toString").kotlinFunction("toString");
|
standardClasses.declare().forFQ("jet.Any.toString").kotlinFunction("toString");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,20 +93,14 @@ public final class StandardClasses {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private final JsScope kotlinScope;
|
private final JsScope kotlinScope;
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private final JsScope rootScope;
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final Map<String, JsName> standardObjects = new HashMap<String, JsName>();
|
private final Map<String, JsName> standardObjects = new HashMap<String, JsName>();
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private final Map<String, JsName> externalObjects = new HashMap<String, JsName>();
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final Map<String, JsScope> scopeMap = new HashMap<String, JsScope>();
|
private final Map<String, JsScope> scopeMap = new HashMap<String, JsScope>();
|
||||||
|
|
||||||
private StandardClasses(@NotNull JsScope kotlinScope, @NotNull JsScope rootScope) {
|
private StandardClasses(@NotNull JsScope kotlinScope) {
|
||||||
this.rootScope = rootScope;
|
|
||||||
this.kotlinScope = kotlinScope;
|
this.kotlinScope = kotlinScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,10 +116,6 @@ public final class StandardClasses {
|
|||||||
declareTopLevelObjectInScope(kotlinScope, standardObjects, fullQualifiedName, kotlinLibName);
|
declareTopLevelObjectInScope(kotlinScope, standardObjects, fullQualifiedName, kotlinLibName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void declareExternalTopLevelObject(@NotNull String fullQualifiedName, @NotNull String externalObjectName) {
|
|
||||||
declareTopLevelObjectInScope(rootScope, externalObjects, fullQualifiedName, externalObjectName);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void declareInner(@NotNull String fullQualifiedClassName,
|
private void declareInner(@NotNull String fullQualifiedClassName,
|
||||||
@NotNull String shortMethodName,
|
@NotNull String shortMethodName,
|
||||||
@NotNull String javascriptName) {
|
@NotNull String javascriptName) {
|
||||||
@@ -165,15 +145,6 @@ public final class StandardClasses {
|
|||||||
return standardObjects.containsKey(getFQName(descriptor));
|
return standardObjects.containsKey(getFQName(descriptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExternalObject(@NotNull DeclarationDescriptor descriptor) {
|
|
||||||
return externalObjects.containsKey(getFQName(descriptor));
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public JsName getExternalObjectName(@NotNull DeclarationDescriptor descriptor) {
|
|
||||||
return externalObjects.get(getFQName(descriptor));
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JsName getStandardObjectName(@NotNull DeclarationDescriptor descriptor) {
|
public JsName getStandardObjectName(@NotNull DeclarationDescriptor descriptor) {
|
||||||
return standardObjects.get(getFQName(descriptor));
|
return standardObjects.get(getFQName(descriptor));
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class StaticContext {
|
|||||||
DeclarationFacade declarations = DeclarationFacade.createFacade(scope);
|
DeclarationFacade declarations = DeclarationFacade.createFacade(scope);
|
||||||
Intrinsics intrinsics = Intrinsics.standardLibraryIntrinsics(library);
|
Intrinsics intrinsics = Intrinsics.standardLibraryIntrinsics(library);
|
||||||
StandardClasses standardClasses =
|
StandardClasses standardClasses =
|
||||||
StandardClasses.bindImplementations(namer.getKotlinScope(), jsRootScope);
|
StandardClasses.bindImplementations(namer.getKotlinScope());
|
||||||
return new StaticContext(program, bindingContext, declarations, aliaser,
|
return new StaticContext(program, bindingContext, declarations, aliaser,
|
||||||
namer, intrinsics, standardClasses, scope);
|
namer, intrinsics, standardClasses, scope);
|
||||||
}
|
}
|
||||||
@@ -111,21 +111,6 @@ public class StaticContext {
|
|||||||
return standardClasses;
|
return standardClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Declarations getLibraryDeclarations() {
|
|
||||||
return declarationFacade.getJetLibraryDeclarations();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Declarations getNativeDeclarations() {
|
|
||||||
return declarationFacade.getKotlinDeclarations();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Declarations getKotlinDeclarations() {
|
|
||||||
return declarationFacade.getKotlinDeclarations();
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: helper method outdated
|
//TODO: helper method outdated
|
||||||
@NotNull
|
@NotNull
|
||||||
public NamingScope getScopeForDescriptor(@NotNull DeclarationDescriptor descriptor) {
|
public NamingScope getScopeForDescriptor(@NotNull DeclarationDescriptor descriptor) {
|
||||||
|
|||||||
@@ -105,12 +105,10 @@ public final class TranslationContext {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JsName getNameForDescriptor(@NotNull DeclarationDescriptor descriptor) {
|
public JsName getNameForDescriptor(@NotNull DeclarationDescriptor descriptor) {
|
||||||
|
//TODO: rewrite
|
||||||
if (aliaser().hasAliasForDeclaration(descriptor)) {
|
if (aliaser().hasAliasForDeclaration(descriptor)) {
|
||||||
return aliaser().getAliasForDeclaration(descriptor);
|
return aliaser().getAliasForDeclaration(descriptor);
|
||||||
}
|
}
|
||||||
if (standardClasses().isExternalObject(descriptor)) {
|
|
||||||
return standardClasses().getExternalObjectName(descriptor);
|
|
||||||
}
|
|
||||||
if (standardClasses().isStandardObject(descriptor)) {
|
if (standardClasses().isStandardObject(descriptor)) {
|
||||||
return standardClasses().getStandardObjectName(descriptor);
|
return standardClasses().getStandardObjectName(descriptor);
|
||||||
}
|
}
|
||||||
@@ -195,6 +193,7 @@ public final class TranslationContext {
|
|||||||
return dynamicContext.jsBlock();
|
return dynamicContext.jsBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: deletE?
|
||||||
@NotNull
|
@NotNull
|
||||||
private DeclarationFacade declarationFacade() {
|
private DeclarationFacade declarationFacade() {
|
||||||
return staticContext.getDeclarationFacade();
|
return staticContext.getDeclarationFacade();
|
||||||
|
|||||||
+5
-12
@@ -35,6 +35,8 @@ public abstract class AbstractDeclarationVisitor extends DeclarationDescriptorVi
|
|||||||
|
|
||||||
abstract protected boolean accept(@NotNull DeclarationDescriptor descriptor);
|
abstract protected boolean accept(@NotNull DeclarationDescriptor descriptor);
|
||||||
|
|
||||||
|
abstract public void traverseNamespace(@NotNull NamespaceDescriptor namespace, @NotNull DeclarationContext context);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected Declarations declarations() {
|
protected Declarations declarations() {
|
||||||
return declarations;
|
return declarations;
|
||||||
@@ -100,9 +102,7 @@ public abstract class AbstractDeclarationVisitor extends DeclarationDescriptorVi
|
|||||||
@Override
|
@Override
|
||||||
public Void visitConstructorDescriptor(@NotNull ConstructorDescriptor descriptor,
|
public Void visitConstructorDescriptor(@NotNull ConstructorDescriptor descriptor,
|
||||||
@NotNull DeclarationContext context) {
|
@NotNull DeclarationContext context) {
|
||||||
if (!accept(descriptor)) {
|
assert accept(descriptor) : "Must accept constructor fot he class we accepted";
|
||||||
return null;
|
|
||||||
}
|
|
||||||
JsName alreadyDeclaredClassName = declarations.getName(descriptor.getContainingDeclaration());
|
JsName alreadyDeclaredClassName = declarations.getName(descriptor.getContainingDeclaration());
|
||||||
//already defined in
|
//already defined in
|
||||||
declarations.putName(descriptor, alreadyDeclaredClassName);
|
declarations.putName(descriptor, alreadyDeclaredClassName);
|
||||||
@@ -161,17 +161,10 @@ public abstract class AbstractDeclarationVisitor extends DeclarationDescriptorVi
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void traverseNamespace(@NotNull NamespaceDescriptor descriptor, @NotNull DeclarationContext context) {
|
|
||||||
if (!accept(descriptor)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DeclarationContext namespaceContext = extractNamespaceDeclaration(descriptor, context);
|
|
||||||
declareMembers(descriptor, namespaceContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private DeclarationContext extractNamespaceDeclaration(@NotNull NamespaceDescriptor descriptor,
|
protected DeclarationContext extractNamespaceDeclaration(@NotNull NamespaceDescriptor descriptor,
|
||||||
@NotNull DeclarationContext context) {
|
@NotNull DeclarationContext context) {
|
||||||
String nameForNamespace = getNameForNamespace(descriptor);
|
String nameForNamespace = getNameForNamespace(descriptor);
|
||||||
JsName namespaceName = doDeclareName(descriptor, context, nameForNamespace);
|
JsName namespaceName = doDeclareName(descriptor, context, nameForNamespace);
|
||||||
NamingScope namespaceScope = doDeclareScope(descriptor, context, "namespace " + namespaceName.getIdent());
|
NamingScope namespaceScope = doDeclareScope(descriptor, context, "namespace " + namespaceName.getIdent());
|
||||||
|
|||||||
-5
@@ -106,11 +106,6 @@ public class AnnotatedDeclarationVisitor extends AbstractDeclarationVisitor {
|
|||||||
throw new AssertionError("Use isAnnotatedClass to check");
|
throw new AssertionError("Use isAnnotatedClass to check");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAnnotatedDeclaration(@NotNull DeclarationDescriptor descriptor) {
|
|
||||||
return hasClassAnnotation(descriptor) || hasFunctionAnnotation(descriptor)
|
|
||||||
|| declaredInAnnotatedClass(descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAnnotatedFunction(@NotNull FunctionDescriptor functionDescriptor) {
|
public boolean isAnnotatedFunction(@NotNull FunctionDescriptor functionDescriptor) {
|
||||||
return hasFunctionAnnotation(functionDescriptor) || declaredInAnnotatedClass(functionDescriptor);
|
return hasFunctionAnnotation(functionDescriptor) || declaredInAnnotatedClass(functionDescriptor);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
@@ -3,6 +3,7 @@ package org.jetbrains.k2js.translate.context.declaration;
|
|||||||
import com.google.dart.compiler.backend.js.ast.JsName;
|
import com.google.dart.compiler.backend.js.ast.JsName;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
import org.jetbrains.k2js.translate.context.NamingScope;
|
import org.jetbrains.k2js.translate.context.NamingScope;
|
||||||
|
|
||||||
import static org.jetbrains.k2js.translate.context.declaration.AnnotationsUtils.doesNotHaveInternalAnnotations;
|
import static org.jetbrains.k2js.translate.context.declaration.AnnotationsUtils.doesNotHaveInternalAnnotations;
|
||||||
@@ -42,4 +43,10 @@ public final class KotlinDeclarationVisitor extends AbstractDeclarationVisitor {
|
|||||||
protected boolean accept(@NotNull DeclarationDescriptor descriptor) {
|
protected boolean accept(@NotNull DeclarationDescriptor descriptor) {
|
||||||
return (doesNotHaveInternalAnnotations(descriptor));
|
return (doesNotHaveInternalAnnotations(descriptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void traverseNamespace(@NotNull NamespaceDescriptor descriptor, @NotNull DeclarationContext context) {
|
||||||
|
DeclarationContext namespaceContext = extractNamespaceDeclaration(descriptor, context);
|
||||||
|
declareMembers(descriptor, namespaceContext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import org.jetbrains.jet.lang.psi.JetParameter;
|
|||||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||||
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
||||||
import org.jetbrains.k2js.translate.general.Translation;
|
import org.jetbrains.k2js.translate.general.Translation;
|
||||||
import org.jetbrains.k2js.translate.reference.ReferenceTranslator;
|
|
||||||
import org.jetbrains.k2js.translate.utils.BindingUtils;
|
import org.jetbrains.k2js.translate.utils.BindingUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -107,9 +106,8 @@ public final class ClassTranslator extends AbstractTranslator {
|
|||||||
// in future it might change
|
// in future it might change
|
||||||
if (aliaser().hasAliasForDeclaration(superClassDescriptor)) {
|
if (aliaser().hasAliasForDeclaration(superClassDescriptor)) {
|
||||||
return context().aliaser().getAliasForDeclaration(superClassDescriptor).makeRef();
|
return context().aliaser().getAliasForDeclaration(superClassDescriptor).makeRef();
|
||||||
} else {
|
|
||||||
return ReferenceTranslator.translateAsFQReference(superClassDescriptor, context());
|
|
||||||
}
|
}
|
||||||
|
throw new AssertionError("Inherited from unknown class");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
@@ -56,6 +56,15 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
|||||||
if (value instanceof Boolean) {
|
if (value instanceof Boolean) {
|
||||||
return context.program().getBooleanLiteral((Boolean) value);
|
return context.program().getBooleanLiteral((Boolean) value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: test
|
||||||
|
if (value instanceof Float) {
|
||||||
|
return context.program().getNumberLiteral((Float) value);
|
||||||
|
}
|
||||||
|
if (value instanceof Double) {
|
||||||
|
return context.program().getNumberLiteral((Double) value);
|
||||||
|
}
|
||||||
|
//TODO: all values
|
||||||
throw new AssertionError("Unsupported constant expression" + expression.toString());
|
throw new AssertionError("Unsupported constant expression" + expression.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ public final class PatternTranslator extends AbstractTranslator {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private JsExpression translateTypePattern(@NotNull JsExpression expressionToMatch,
|
private JsExpression translateTypePattern(@NotNull JsExpression expressionToMatch,
|
||||||
@NotNull JetTypePattern pattern) {
|
@NotNull JetTypePattern pattern) {
|
||||||
//TODO: HACK to make some examples work
|
|
||||||
//TODO: look into using intrinsics or other mechanisms to implement this logic
|
//TODO: look into using intrinsics or other mechanisms to implement this logic
|
||||||
JsName className = getClassReference(pattern).getName();
|
JsName className = getClassReference(pattern).getName();
|
||||||
if (className.getIdent().equals("String")) {
|
if (className.getIdent().equals("String")) {
|
||||||
|
|||||||
+5
-40
@@ -1,6 +1,8 @@
|
|||||||
package org.jetbrains.k2js.translate.expression;
|
package org.jetbrains.k2js.translate.expression;
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.*;
|
import com.google.dart.compiler.backend.js.ast.JsConditional;
|
||||||
|
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||||
|
import com.google.dart.compiler.backend.js.ast.JsNullLiteral;
|
||||||
import com.google.dart.compiler.util.AstUtil;
|
import com.google.dart.compiler.util.AstUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
@@ -12,6 +14,7 @@ import org.jetbrains.k2js.translate.reference.PropertyAccessTranslator;
|
|||||||
|
|
||||||
import static org.jetbrains.k2js.translate.general.Translation.translateAsExpression;
|
import static org.jetbrains.k2js.translate.general.Translation.translateAsExpression;
|
||||||
import static org.jetbrains.k2js.translate.utils.PsiUtils.getNotNullSimpleNameSelector;
|
import static org.jetbrains.k2js.translate.utils.PsiUtils.getNotNullSimpleNameSelector;
|
||||||
|
import static org.jetbrains.k2js.translate.utils.PsiUtils.getSelector;
|
||||||
import static org.jetbrains.k2js.translate.utils.TranslationUtils.notNullCheck;
|
import static org.jetbrains.k2js.translate.utils.TranslationUtils.notNullCheck;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,20 +50,11 @@ public final class QualifiedExpressionTranslator {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public static JsExpression translateDotQualifiedExpression(@NotNull JetDotQualifiedExpression expression,
|
public static JsExpression translateDotQualifiedExpression(@NotNull JetDotQualifiedExpression expression,
|
||||||
@NotNull TranslationContext context) {
|
@NotNull TranslationContext context) {
|
||||||
//TODO: problem with extension properties lies here
|
|
||||||
JsExpression receiver = translateReceiver(expression, context);
|
JsExpression receiver = translateReceiver(expression, context);
|
||||||
JetExpression selector = getSelector(expression);
|
JetExpression selector = getSelector(expression);
|
||||||
return translate(receiver, selector, context);
|
return translate(receiver, selector, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static JetExpression getSelector(@NotNull JetQualifiedExpression expression) {
|
|
||||||
JetExpression selector = expression.getSelectorExpression();
|
|
||||||
//TODO: util?
|
|
||||||
assert selector != null;
|
|
||||||
return selector;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static JsExpression translate(@NotNull JsExpression receiver, @NotNull JetExpression selector,
|
private static JsExpression translate(@NotNull JsExpression receiver, @NotNull JetExpression selector,
|
||||||
@NotNull TranslationContext context) {
|
@NotNull TranslationContext context) {
|
||||||
@@ -71,22 +65,7 @@ public final class QualifiedExpressionTranslator {
|
|||||||
if (selector instanceof JetCallExpression) {
|
if (selector instanceof JetCallExpression) {
|
||||||
return CallTranslator.translate((JetCallExpression) selector, receiver, context);
|
return CallTranslator.translate((JetCallExpression) selector, receiver, context);
|
||||||
}
|
}
|
||||||
return composeQualifiedExpression(receiver, translateAsExpression(selector, context));
|
throw new AssertionError("Unexpected qualified expression");
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static JsExpression composeQualifiedExpression(@NotNull JsExpression receiver, @NotNull JsExpression selector) {
|
|
||||||
//TODO: make sure that logic would not break for binary operation. check if there is a way to provide clearer logic
|
|
||||||
assert (selector instanceof JsNameRef || selector instanceof JsInvocation || selector instanceof JsBinaryOperation)
|
|
||||||
: "Selector should be a name reference or a method invocation in dot qualified expression.";
|
|
||||||
if (selector instanceof JsInvocation) {
|
|
||||||
return translateAsQualifiedInvocation(receiver, (JsInvocation) selector);
|
|
||||||
} else if (selector instanceof JsNameRef) {
|
|
||||||
return translateAsQualifiedNameReference(receiver, (JsNameRef) selector);
|
|
||||||
} else {
|
|
||||||
((JsBinaryOperation) selector).setArg1(receiver);
|
|
||||||
return selector;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -94,18 +73,4 @@ public final class QualifiedExpressionTranslator {
|
|||||||
@NotNull TranslationContext context) {
|
@NotNull TranslationContext context) {
|
||||||
return translateAsExpression(expression.getReceiverExpression(), context);
|
return translateAsExpression(expression.getReceiverExpression(), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static JsExpression translateAsQualifiedNameReference(@NotNull JsExpression receiver, @NotNull JsNameRef selector) {
|
|
||||||
selector.setQualifier(receiver);
|
|
||||||
return selector;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static JsExpression translateAsQualifiedInvocation(@NotNull JsExpression receiver, @NotNull JsInvocation selector) {
|
|
||||||
JsExpression qualifier = selector.getQualifier();
|
|
||||||
JsNameRef nameRef = (JsNameRef) qualifier;
|
|
||||||
nameRef.setQualifier(receiver);
|
|
||||||
return selector;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import static com.google.dart.compiler.util.AstUtil.convertToBlock;
|
|||||||
/**
|
/**
|
||||||
* @author Pavel Talanov
|
* @author Pavel Talanov
|
||||||
*/
|
*/
|
||||||
|
//TODO: not tested at all
|
||||||
//TODO: not implemented catch logic
|
//TODO: not implemented catch logic
|
||||||
public final class TryTranslator extends AbstractTranslator {
|
public final class TryTranslator extends AbstractTranslator {
|
||||||
|
|
||||||
|
|||||||
@@ -81,12 +81,4 @@ public final class InitializerVisitor extends TranslatorVisitor<List<JsStatement
|
|||||||
}
|
}
|
||||||
return initializerStatements;
|
return initializerStatements;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public List<JsStatement> traverse(@NotNull JetDeclaration declaration, @NotNull TranslationContext context) {
|
|
||||||
if (declaration instanceof JetClass) {
|
|
||||||
return traverseClass((JetClass) declaration, context);
|
|
||||||
}
|
|
||||||
throw new AssertionError("Cannot traverse anything else.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,8 @@ public final class Intrinsics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void declareNullConstructorIntrinsic() {
|
private void declareNullConstructorIntrinsic() {
|
||||||
FunctionDescriptor nullArrayConstructor = getFunctionByName(library.getLibraryScope(), "Array");
|
//TODO:
|
||||||
|
FunctionDescriptor nullArrayConstructor = library.getLibraryScope().getFunctions("Array").iterator().next();
|
||||||
functionIntrinsics.put(nullArrayConstructor, ArrayNullConstructorIntrinsic.INSTANCE);
|
functionIntrinsics.put(nullArrayConstructor, ArrayNullConstructorIntrinsic.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,10 +23,6 @@ public enum ArrayGetIntrinsic implements FunctionIntrinsic {
|
|||||||
assert receiver != null;
|
assert receiver != null;
|
||||||
assert arguments.size() == 1 : "Array get expression must have one argument.";
|
assert arguments.size() == 1 : "Array get expression must have one argument.";
|
||||||
JsExpression indexExpression = arguments.get(0);
|
JsExpression indexExpression = arguments.get(0);
|
||||||
// TemporaryVariable arrayExpression = context.declareTemporary(receiver);
|
|
||||||
// JsConditional indexInBoundsCheck =
|
|
||||||
// IntrinsicArrayUtils.indexInBoundsCheck(indexExpression, arrayExpression, context);
|
|
||||||
// return AstUtil.newSequence(arrayExpression.assignmentExpression(), AstUtil.newArrayAccess(receiver, indexExpression));
|
|
||||||
return new JsArrayAccess(receiver, indexExpression);
|
return new JsArrayAccess(receiver, indexExpression);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
package org.jetbrains.k2js.translate.intrinsic.array;
|
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.*;
|
|
||||||
import com.google.dart.compiler.util.AstUtil;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.k2js.translate.context.TemporaryVariable;
|
|
||||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
|
||||||
|
|
||||||
import static org.jetbrains.k2js.translate.utils.TranslationUtils.zeroLiteral;
|
|
||||||
|
|
||||||
//TODO: decide if needed
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Pavel Talanov
|
|
||||||
*/
|
|
||||||
public final class IntrinsicArrayUtils {
|
|
||||||
|
|
||||||
private IntrinsicArrayUtils() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static JsConditional indexInBoundsCheck(@NotNull JsExpression indexExpression,
|
|
||||||
@NotNull TemporaryVariable arrayTemporary,
|
|
||||||
@NotNull TranslationContext context) {
|
|
||||||
JsExpression positiveOrZero = new JsBinaryOperation
|
|
||||||
(JsBinaryOperator.GTE, indexExpression, zeroLiteral(context));
|
|
||||||
JsNameRef lengthExpression = AstUtil.newQualifiedNameRef("length");
|
|
||||||
lengthExpression.setQualifier(arrayTemporary.nameReference());
|
|
||||||
JsExpression lessThanLength = new JsBinaryOperation
|
|
||||||
(JsBinaryOperator.LT, indexExpression, lengthExpression);
|
|
||||||
JsExpression indexInBounds = AstUtil.and(positiveOrZero, lessThanLength);
|
|
||||||
JsConditional indexCheck = new JsConditional();
|
|
||||||
indexCheck.setTestExpression(indexInBounds);
|
|
||||||
indexCheck.setElseExpression(throwOutOfBoundsException());
|
|
||||||
return indexCheck;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static JsExpression throwOutOfBoundsException() {
|
|
||||||
//TODO: think about exception
|
|
||||||
return AstUtil.newQualifiedNameRef("ErrorName");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -87,6 +87,7 @@ public abstract class IncrementTranslator extends AbstractTranslator {
|
|||||||
variableReassignment, t2.nameReference());
|
variableReassignment, t2.nameReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: TEST
|
||||||
@NotNull
|
@NotNull
|
||||||
private JsExpression asPostfixWithNoReassignment() {
|
private JsExpression asPostfixWithNoReassignment() {
|
||||||
// code fragment: expr(a++)
|
// code fragment: expr(a++)
|
||||||
|
|||||||
@@ -86,19 +86,6 @@ public final class CallTranslator extends AbstractTranslator {
|
|||||||
return new CallTranslator(receiver, callee, arguments, resolvedCall, null, context);
|
return new CallTranslator(receiver, callee, arguments, resolvedCall, null, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: inspect dead code
|
|
||||||
@Nullable
|
|
||||||
private JsExpression translateCalleeIfExpressionAsFunction(@NotNull JetCallExpression callExpression) {
|
|
||||||
//TODO: util
|
|
||||||
JetExpression calleeExpression = callExpression.getCalleeExpression();
|
|
||||||
assert calleeExpression != null;
|
|
||||||
JsExpression callee = null;
|
|
||||||
if (isExpressionAsFunction(context.bindingContext(), calleeExpression)) {
|
|
||||||
callee = Translation.translateAsExpression(calleeExpression, context);
|
|
||||||
}
|
|
||||||
return callee;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private List<JsExpression> translateArgumentsForCallExpression(@NotNull JetCallExpression callExpression,
|
private List<JsExpression> translateArgumentsForCallExpression(@NotNull JetCallExpression callExpression,
|
||||||
@NotNull TranslationContext context) {
|
@NotNull TranslationContext context) {
|
||||||
|
|||||||
@@ -26,9 +26,6 @@ import static org.jetbrains.k2js.translate.utils.TranslationUtils.backingFieldRe
|
|||||||
*/
|
*/
|
||||||
public final class PropertyAccessTranslator extends AccessTranslator {
|
public final class PropertyAccessTranslator extends AccessTranslator {
|
||||||
|
|
||||||
private static final String MESSAGE = "Cannot be accessor call. Use canBeProperty*Call to ensure this method " +
|
|
||||||
"can be called safely.";
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static PropertyDescriptor getPropertyDescriptor(@NotNull JetSimpleNameExpression expression,
|
private static PropertyDescriptor getPropertyDescriptor(@NotNull JetSimpleNameExpression expression,
|
||||||
@NotNull TranslationContext context) {
|
@NotNull TranslationContext context) {
|
||||||
@@ -76,6 +73,7 @@ public final class PropertyAccessTranslator extends AccessTranslator {
|
|||||||
@NotNull TranslationContext context) {
|
@NotNull TranslationContext context) {
|
||||||
JetSimpleNameExpression selector = getSelectorAsSimpleName(expression);
|
JetSimpleNameExpression selector = getSelectorAsSimpleName(expression);
|
||||||
if (selector == null) {
|
if (selector == null) {
|
||||||
|
//TODO: never get there. review
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return canBePropertyGetterCall(selector, context);
|
return canBePropertyGetterCall(selector, context);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import com.google.dart.compiler.backend.js.ast.JsName;
|
|||||||
import com.google.dart.compiler.util.AstUtil;
|
import com.google.dart.compiler.util.AstUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||||
|
|
||||||
@@ -41,13 +40,7 @@ public final class ReferenceTranslator {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public static JsExpression translateAsLocalNameReference(@NotNull DeclarationDescriptor referencedDescriptor,
|
public static JsExpression translateAsLocalNameReference(@NotNull DeclarationDescriptor referencedDescriptor,
|
||||||
@NotNull TranslationContext context) {
|
@NotNull TranslationContext context) {
|
||||||
|
|
||||||
//TODO: prove correctness
|
//TODO: prove correctness
|
||||||
if ((referencedDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor)
|
|
||||||
&& (context.hasQualifierForDescriptor(referencedDescriptor))) {
|
|
||||||
assert context.hasQualifierForDescriptor(referencedDescriptor) : referencedDescriptor;
|
|
||||||
return translateAsFQReference(referencedDescriptor, context);
|
|
||||||
}
|
|
||||||
JsName referencedName = context.getNameForDescriptor(referencedDescriptor);
|
JsName referencedName = context.getNameForDescriptor(referencedDescriptor);
|
||||||
return referencedName.makeRef();
|
return referencedName.makeRef();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.ExpressionAsFunctionDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||||
import org.jetbrains.jet.lang.types.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.JetStandardClasses;
|
||||||
@@ -99,6 +98,7 @@ public final class BindingUtils {
|
|||||||
@NotNull DeclarationDescriptor descriptor) {
|
@NotNull DeclarationDescriptor descriptor) {
|
||||||
PsiElement result = context.get(BindingContext.DESCRIPTOR_TO_DECLARATION, descriptor);
|
PsiElement result = context.get(BindingContext.DESCRIPTOR_TO_DECLARATION, descriptor);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
|
//TODO: never get there
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
assert result instanceof JetDeclaration : "Descriptor should correspond to an element.";
|
assert result instanceof JetDeclaration : "Descriptor should correspond to an element.";
|
||||||
@@ -207,6 +207,8 @@ public final class BindingUtils {
|
|||||||
return !superClassDescriptor.equals(JetStandardClasses.getAny());
|
return !superClassDescriptor.equals(JetStandardClasses.getAny());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: check where we use there, suspicious
|
||||||
public static boolean isOwnedByNamespace(@NotNull DeclarationDescriptor descriptor) {
|
public static boolean isOwnedByNamespace(@NotNull DeclarationDescriptor descriptor) {
|
||||||
if (descriptor instanceof ConstructorDescriptor) {
|
if (descriptor instanceof ConstructorDescriptor) {
|
||||||
DeclarationDescriptor classDescriptor = descriptor.getContainingDeclaration();
|
DeclarationDescriptor classDescriptor = descriptor.getContainingDeclaration();
|
||||||
@@ -310,15 +312,4 @@ public final class BindingUtils {
|
|||||||
assert hasNextDescriptor != null : "Range expression must have a descriptor for hasNext function or property.";
|
assert hasNextDescriptor != null : "Range expression must have a descriptor for hasNext function or property.";
|
||||||
return hasNextDescriptor;
|
return hasNextDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isExpressionAsFunction(@NotNull BindingContext context,
|
|
||||||
@NotNull JetExpression calleeExpression) {
|
|
||||||
DeclarationDescriptor declarationDescriptor =
|
|
||||||
context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, calleeExpression);
|
|
||||||
if (declarationDescriptor == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return (declarationDescriptor instanceof ExpressionAsFunctionDescriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,13 +60,6 @@ public final class DescriptorUtils {
|
|||||||
return resultingList;
|
return resultingList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static FunctionDescriptor getFunctionByName(@NotNull ClassDescriptor classDescriptor,
|
|
||||||
@NotNull String name) {
|
|
||||||
JetScope scope = classDescriptor.getDefaultType().getMemberScope();
|
|
||||||
return getFunctionByName(scope, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static FunctionDescriptor getFunctionByName(@NotNull JetScope scope,
|
public static FunctionDescriptor getFunctionByName(@NotNull JetScope scope,
|
||||||
@NotNull String name) {
|
@NotNull String name) {
|
||||||
|
|||||||
@@ -17,14 +17,20 @@ public final class PsiUtils {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static JetSimpleNameExpression getSelectorAsSimpleName(@NotNull JetQualifiedExpression expression) {
|
public static JetSimpleNameExpression getSelectorAsSimpleName(@NotNull JetQualifiedExpression expression) {
|
||||||
JetExpression selectorExpression = expression.getSelectorExpression();
|
JetExpression selectorExpression = getSelector(expression);
|
||||||
assert selectorExpression != null : "Selector should not be null.";
|
|
||||||
if (!(selectorExpression instanceof JetSimpleNameExpression)) {
|
if (!(selectorExpression instanceof JetSimpleNameExpression)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (JetSimpleNameExpression) selectorExpression;
|
return (JetSimpleNameExpression) selectorExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static JetExpression getSelector(@NotNull JetQualifiedExpression expression) {
|
||||||
|
JetExpression selectorExpression = expression.getSelectorExpression();
|
||||||
|
assert selectorExpression != null : "Selector should not be null.";
|
||||||
|
return selectorExpression;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JetSimpleNameExpression getNotNullSimpleNameSelector(@NotNull JetQualifiedExpression expression) {
|
public static JetSimpleNameExpression getNotNullSimpleNameSelector(@NotNull JetQualifiedExpression expression) {
|
||||||
JetSimpleNameExpression selectorAsSimpleName = getSelectorAsSimpleName(expression);
|
JetSimpleNameExpression selectorAsSimpleName = getSelectorAsSimpleName(expression);
|
||||||
|
|||||||
@@ -49,9 +49,7 @@ public final class TranslationUtils {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private static JsExpression translateArgument(@NotNull TranslationContext context, @NotNull ValueArgument argument) {
|
private static JsExpression translateArgument(@NotNull TranslationContext context, @NotNull ValueArgument argument) {
|
||||||
JetExpression jetExpression = argument.getArgumentExpression();
|
JetExpression jetExpression = argument.getArgumentExpression();
|
||||||
if (jetExpression == null) {
|
assert jetExpression != null : "Argument with no expression";
|
||||||
throw new AssertionError("Argument with no expression encountered!");
|
|
||||||
}
|
|
||||||
return Translation.translateAsExpression(jetExpression, context);
|
return Translation.translateAsExpression(jetExpression, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,6 +146,7 @@ public final class TranslationUtils {
|
|||||||
return Translation.translateAsExpression(baseExpression, context);
|
return Translation.translateAsExpression(baseExpression, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO:
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JsExpression translateReceiver(@NotNull TranslationContext context,
|
public static JsExpression translateReceiver(@NotNull TranslationContext context,
|
||||||
@NotNull JetDotQualifiedExpression expression) {
|
@NotNull JetDotQualifiedExpression expression) {
|
||||||
|
|||||||
@@ -519,6 +519,16 @@
|
|||||||
return obj.toString();
|
return obj.toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Kotlin.jsonFromTuples = function(pairArr) {
|
||||||
|
var i = pairArr.length;
|
||||||
|
var res = {};
|
||||||
|
while (i > 0) {
|
||||||
|
--i;
|
||||||
|
res[pairArr[i][0]] = pairArr[i][1];
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright 2010 Tim Down.
|
* Copyright 2010 Tim Down.
|
||||||
|
|||||||
Reference in New Issue
Block a user