arrayList simple test.
This commit is contained in:
@@ -50,7 +50,7 @@ public final class Declarations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public NamingScope getScope(@NotNull DeclarationDescriptor descriptor) {
|
/*package*/ NamingScope getScope(@NotNull DeclarationDescriptor descriptor) {
|
||||||
NamingScope scope = descriptorToScopeMap.get(descriptor.getOriginal());
|
NamingScope scope = descriptorToScopeMap.get(descriptor.getOriginal());
|
||||||
assert scope != null : "Unknown declaration";
|
assert scope != null : "Unknown declaration";
|
||||||
return scope;
|
return scope;
|
||||||
@@ -67,12 +67,12 @@ public final class Declarations {
|
|||||||
return descriptorToNameMap.containsKey(descriptor.getOriginal());
|
return descriptorToNameMap.containsKey(descriptor.getOriginal());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasQualifier(@NotNull DeclarationDescriptor descriptor) {
|
/*package*/ boolean hasQualifier(@NotNull DeclarationDescriptor descriptor) {
|
||||||
return (descriptorToQualifierMap.get(descriptor.getOriginal()) != null);
|
return (descriptorToQualifierMap.get(descriptor.getOriginal()) != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JsNameRef getQualifier(@NotNull DeclarationDescriptor descriptor) {
|
/*package*/ JsNameRef getQualifier(@NotNull DeclarationDescriptor descriptor) {
|
||||||
JsNameRef qualifier = descriptorToQualifierMap.get(descriptor.getOriginal());
|
JsNameRef qualifier = descriptorToQualifierMap.get(descriptor.getOriginal());
|
||||||
assert qualifier != null : "Cannot be null. Use hasQualifier to check.";
|
assert qualifier != null : "Cannot be null. Use hasQualifier to check.";
|
||||||
return qualifier;
|
return qualifier;
|
||||||
|
|||||||
@@ -92,13 +92,14 @@ public final class StandardClasses {
|
|||||||
private void declareStandardMethodOrProperty(@NotNull DeclarationDescriptor descriptor,
|
private void declareStandardMethodOrProperty(@NotNull DeclarationDescriptor descriptor,
|
||||||
@NotNull String kotlinLibName) {
|
@NotNull String kotlinLibName) {
|
||||||
String containingFQName = getFQName(getContainingDeclaration(descriptor));
|
String containingFQName = getFQName(getContainingDeclaration(descriptor));
|
||||||
declareStandardInnerDeclaration(containingFQName, getFQName(descriptor), kotlinLibName);
|
declareStandardInnerDeclaration(containingFQName, descriptor.getName(), kotlinLibName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void declareStandardInnerDeclaration(@NotNull String fullQualifiedClassName,
|
private void declareStandardInnerDeclaration(@NotNull String fullQualifiedClassName,
|
||||||
@NotNull String fullQualifiedMethodName,
|
@NotNull String shortMethodName,
|
||||||
@NotNull String kotlinLibName) {
|
@NotNull String kotlinLibName) {
|
||||||
JsScope classScope = scopeMap.get(fullQualifiedClassName);
|
JsScope classScope = scopeMap.get(fullQualifiedClassName);
|
||||||
|
String fullQualifiedMethodName = fullQualifiedClassName + "." + shortMethodName;
|
||||||
nameMap.put(fullQualifiedMethodName, classScope.declareName(kotlinLibName));
|
nameMap.put(fullQualifiedMethodName, classScope.declareName(kotlinLibName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,8 +96,8 @@ public final class TranslationContext {
|
|||||||
if (aliaser().hasAliasForDeclaration(descriptor)) {
|
if (aliaser().hasAliasForDeclaration(descriptor)) {
|
||||||
return aliaser().getAliasForDeclaration(descriptor);
|
return aliaser().getAliasForDeclaration(descriptor);
|
||||||
}
|
}
|
||||||
if (staticContext.getStandardClasses().isStandardObject(descriptor)) {
|
if (standardClasses().isStandardObject(descriptor)) {
|
||||||
return staticContext.getStandardClasses().getStandardObjectName(descriptor);
|
return standardClasses().getStandardObjectName(descriptor);
|
||||||
}
|
}
|
||||||
if (dynamicContext.isDeclared(descriptor)) {
|
if (dynamicContext.isDeclared(descriptor)) {
|
||||||
return dynamicContext.getLocalName(descriptor);
|
return dynamicContext.getLocalName(descriptor);
|
||||||
@@ -108,6 +108,20 @@ public final class TranslationContext {
|
|||||||
throw new AssertionError("Undefined descriptor: " + DescriptorRenderer.getFQName(descriptor));
|
throw new AssertionError("Undefined descriptor: " + DescriptorRenderer.getFQName(descriptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public JsNameRef getQualifierForDescriptor(@NotNull DeclarationDescriptor descriptor) {
|
||||||
|
if (standardClasses().isStandardObject(descriptor)) {
|
||||||
|
return namer().kotlinObject();
|
||||||
|
}
|
||||||
|
return declarations().getQualifier(descriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean hasQualifierForDescriptor(@NotNull DeclarationDescriptor descriptor) {
|
||||||
|
return (declarations().hasQualifier(descriptor) ||
|
||||||
|
standardClasses().isStandardObject(descriptor));
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JsName getNameForElement(@NotNull JetElement element) {
|
public JsName getNameForElement(@NotNull JetElement element) {
|
||||||
DeclarationDescriptor descriptor = BindingUtils.getDescriptorForElement(bindingContext(), element);
|
DeclarationDescriptor descriptor = BindingUtils.getDescriptorForElement(bindingContext(), element);
|
||||||
@@ -123,12 +137,12 @@ public final class TranslationContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isStandardObject(@NotNull DeclarationDescriptor descriptor) {
|
public boolean isStandardObject(@NotNull DeclarationDescriptor descriptor) {
|
||||||
return staticContext.getStandardClasses().isStandardObject(descriptor);
|
return standardClasses().isStandardObject(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JsName getNameForStandardObject(@NotNull DeclarationDescriptor descriptor) {
|
public JsName getNameForStandardObject(@NotNull DeclarationDescriptor descriptor) {
|
||||||
return staticContext.getStandardClasses().getStandardObjectName(descriptor);
|
return standardClasses().getStandardObjectName(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -184,6 +198,11 @@ public final class TranslationContext {
|
|||||||
return staticContext.getProgram();
|
return staticContext.getProgram();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private StandardClasses standardClasses() {
|
||||||
|
return staticContext.getStandardClasses();
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JsScope jsScope() {
|
public JsScope jsScope() {
|
||||||
return dynamicContext.jsScope();
|
return dynamicContext.jsScope();
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public final class TranslationUtils {
|
|||||||
}
|
}
|
||||||
assert BindingUtils.isOwnedByNamespace(descriptor)
|
assert BindingUtils.isOwnedByNamespace(descriptor)
|
||||||
: "Only classes and namespaces may own backing fields.";
|
: "Only classes and namespaces may own backing fields.";
|
||||||
JsNameRef qualifier = context.declarations().getQualifier(descriptor);
|
JsNameRef qualifier = context.getQualifierForDescriptor(descriptor);
|
||||||
return AstUtil.qualified(backingFieldName, qualifier);
|
return AstUtil.qualified(backingFieldName, qualifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,29 +95,18 @@ public final class TranslationUtils {
|
|||||||
return AstUtil.newAssignmentStatement(backingFieldReference, parameter.getName().makeRef());
|
return AstUtil.newAssignmentStatement(backingFieldReference, parameter.getName().makeRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean hasQualifier(@NotNull TranslationContext context, @NotNull DeclarationDescriptor descriptor) {
|
|
||||||
return context.declarations().hasQualifier(descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JsNameRef getQualifiedReference(@NotNull TranslationContext context,
|
public static JsNameRef getQualifiedReference(@NotNull TranslationContext context,
|
||||||
@NotNull DeclarationDescriptor descriptor) {
|
@NotNull DeclarationDescriptor descriptor) {
|
||||||
JsName name = context.declarations().getName(descriptor);
|
JsName name = context.declarations().getName(descriptor);
|
||||||
JsNameRef reference = name.makeRef();
|
JsNameRef reference = name.makeRef();
|
||||||
if (hasQualifier(context, descriptor)) {
|
if (context.hasQualifierForDescriptor(descriptor)) {
|
||||||
JsNameRef qualifier = getQualifier(context, descriptor);
|
JsNameRef qualifier = context.getQualifierForDescriptor(descriptor);
|
||||||
AstUtil.setQualifier(reference, qualifier);
|
AstUtil.setQualifier(reference, qualifier);
|
||||||
}
|
}
|
||||||
return reference;
|
return reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static JsNameRef getQualifier(@NotNull TranslationContext context,
|
|
||||||
@NotNull DeclarationDescriptor descriptor) {
|
|
||||||
return context.declarations().getQualifier(descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JsNameRef getThisQualifiedNameReference(@NotNull TranslationContext context,
|
public static JsNameRef getThisQualifiedNameReference(@NotNull TranslationContext context,
|
||||||
@NotNull JsName name) {
|
@NotNull JsName name) {
|
||||||
@@ -211,13 +200,12 @@ public final class TranslationUtils {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public static JsExpression getImplicitReceiver(@NotNull TranslationContext context,
|
public static JsExpression getImplicitReceiver(@NotNull TranslationContext context,
|
||||||
@NotNull DeclarationDescriptor referencedDescriptor) {
|
@NotNull DeclarationDescriptor referencedDescriptor) {
|
||||||
if (!context.isDeclared(referencedDescriptor)) return null;
|
|
||||||
|
|
||||||
if (BindingUtils.isOwnedByClass(referencedDescriptor)) {
|
if (BindingUtils.isOwnedByClass(referencedDescriptor)) {
|
||||||
return TranslationUtils.getThisQualifier(context);
|
return TranslationUtils.getThisQualifier(context);
|
||||||
}
|
}
|
||||||
if (!BindingUtils.isOwnedByNamespace(referencedDescriptor)) return null;
|
if (BindingUtils.isOwnedByNamespace(referencedDescriptor)) {
|
||||||
|
return context.getQualifierForDescriptor(referencedDescriptor);
|
||||||
return context.declarations().getQualifier(referencedDescriptor);
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -486,31 +486,31 @@ Kotlin.Array = Class.create({
|
|||||||
Kotlin.ArrayList = Class.create({
|
Kotlin.ArrayList = Class.create({
|
||||||
initialize:function (len) {
|
initialize:function (len) {
|
||||||
this.array = [];
|
this.array = [];
|
||||||
this.size = 0;
|
this.$size = 0;
|
||||||
},
|
},
|
||||||
get:function (index) {
|
get:function (index) {
|
||||||
if ((index < 0) || (index > this.size)) {
|
if ((index < 0) || (index > this.$size)) {
|
||||||
throw Kotlin.Exceptions.IndexOutOfBounds;
|
throw Kotlin.Exceptions.IndexOutOfBounds;
|
||||||
}
|
}
|
||||||
return (this.array)[index];
|
return (this.array)[index];
|
||||||
},
|
},
|
||||||
set:function (index, value) {
|
set:function (index, value) {
|
||||||
if ((index < 0) || (index > this.size)) {
|
if ((index < 0) || (index > this.$size)) {
|
||||||
throw Kotlin.Exceptions.IndexOutOfBounds;
|
throw Kotlin.Exceptions.IndexOutOfBounds;
|
||||||
}
|
}
|
||||||
(this.array)[index] = value;
|
(this.array)[index] = value;
|
||||||
},
|
},
|
||||||
size:function () {
|
size:function () {
|
||||||
return this.size;
|
return this.$size;
|
||||||
},
|
},
|
||||||
iterator:function () {
|
iterator:function () {
|
||||||
return new Kotlin.ArrayIterator(this);
|
return new Kotlin.ArrayIterator(this);
|
||||||
},
|
},
|
||||||
isEmpty:function () {
|
isEmpty:function () {
|
||||||
return (this.size == 0);
|
return (this.$size == 0);
|
||||||
},
|
},
|
||||||
add:function (element) {
|
add:function (element) {
|
||||||
this.array[size++] = element;
|
this.array[this.$size++] = element;
|
||||||
},
|
},
|
||||||
addAll:function (collection) {
|
addAll:function (collection) {
|
||||||
var it = collection.iterator();
|
var it = collection.iterator();
|
||||||
@@ -519,10 +519,10 @@ Kotlin.ArrayList = Class.create({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
remove:function (index) {
|
remove:function (index) {
|
||||||
for (var i = index; i < this.size - 1; ++i) {
|
for (var i = index; i < this.$size - 1; ++i) {
|
||||||
this.array[i] = this.array[i + 1];
|
this.array[i] = this.array[i + 1];
|
||||||
}
|
}
|
||||||
this.size--;
|
this.$size--;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user