CharSequence added in to stdlib
This commit is contained in:
@@ -38,6 +38,7 @@ public class JetTypeMapper {
|
||||
public static final Type JL_NUMBER_TYPE = Type.getObjectType("java/lang/Number");
|
||||
public static final Type JL_STRING_BUILDER = Type.getObjectType("java/lang/StringBuilder");
|
||||
public static final Type JL_STRING_TYPE = Type.getObjectType("java/lang/String");
|
||||
public static final Type JL_CHAR_SEQUENCE_TYPE = Type.getObjectType("java/lang/CharSequence");
|
||||
private static final Type JL_COMPARABLE_TYPE = Type.getObjectType("java/lang/Comparable");
|
||||
|
||||
public static final Type ARRAY_GENERIC_TYPE = Type.getType(Object[].class);
|
||||
@@ -142,8 +143,6 @@ public class JetTypeMapper {
|
||||
return mapType(jetType, OwnerKind.IMPLEMENTATION, signatureVisitor);
|
||||
}
|
||||
|
||||
private HashMap<DeclarationDescriptor,Map<DeclarationDescriptor,String>> naming = new HashMap<DeclarationDescriptor, Map<DeclarationDescriptor, String>>();
|
||||
|
||||
private String getStableNameForObject(JetObjectDeclaration object, DeclarationDescriptor descriptor) {
|
||||
String local = getLocalNameForObject(object);
|
||||
if (local == null) return null;
|
||||
@@ -781,6 +780,8 @@ public class JetTypeMapper {
|
||||
|
||||
knowTypes.put(standardLibrary.getStringType(),JL_STRING_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableStringType(),JL_STRING_TYPE);
|
||||
knowTypes.put(standardLibrary.getCharSequenceType(),JL_CHAR_SEQUENCE_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableCharSequenceType(),JL_CHAR_SEQUENCE_TYPE);
|
||||
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||
|
||||
@@ -88,7 +88,7 @@ public class IntrinsicMethods {
|
||||
declareIntrinsicFunction("Boolean", "not", 0, new Not());
|
||||
|
||||
declareIntrinsicFunction("String", "plus", 1, new Concat());
|
||||
declareIntrinsicFunction("String", "get", 1, new StringGetChar());
|
||||
declareIntrinsicFunction("CharSequence", "get", 1, new StringGetChar());
|
||||
|
||||
declareOverload(myStdLib.getLibraryScope().getFunctions("toString"), 0, new ToString());
|
||||
declareOverload(myStdLib.getLibraryScope().getFunctions("equals"), 1, EQUALS);
|
||||
@@ -114,7 +114,7 @@ public class IntrinsicMethods {
|
||||
// declareIntrinsicFunction("Any", "equals", 1, new Equals());
|
||||
//
|
||||
declareIntrinsicStringMethods();
|
||||
declareIntrinsicProperty("String", "length", new StringLength());
|
||||
declareIntrinsicProperty("CharSequence", "length", new StringLength());
|
||||
|
||||
declareArrayMethods();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class StringGetChar implements IntrinsicMethod {
|
||||
receiver.put(JetTypeMapper.TYPE_OBJECT, v);
|
||||
if(arguments != null)
|
||||
codegen.gen(arguments.get(0)).put(Type.INT_TYPE, v);
|
||||
v.invokevirtual("java/lang/String", "charAt", "(I)C");
|
||||
v.invokeinterface("java/lang/CharSequence", "charAt", "(I)C");
|
||||
return StackValue.onStack(Type.CHAR_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class StringLength implements IntrinsicMethod {
|
||||
@Override
|
||||
public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, Type expectedType, PsiElement element, List<JetExpression> arguments, StackValue receiver) {
|
||||
receiver.put(JetTypeMapper.TYPE_OBJECT, v);
|
||||
v.invokevirtual("java/lang/String", "length", "()I");
|
||||
v.invokeinterface("java/lang/CharSequence", "length", "()I");
|
||||
return StackValue.onStack(Type.INT_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -179,6 +179,7 @@ public class JavaTypeTransformer {
|
||||
}
|
||||
classTypesMap.put("java.lang.Object", JetStandardClasses.getNullableAnyType());
|
||||
classTypesMap.put("java.lang.String", standardLibrary.getNullableStringType());
|
||||
classTypesMap.put("java.lang.CharSequence", standardLibrary.getNullableCharSequenceType());
|
||||
}
|
||||
return classTypesMap;
|
||||
}
|
||||
@@ -191,6 +192,7 @@ public class JavaTypeTransformer {
|
||||
classDescriptorMap.put(jvmPrimitiveType.getWrapper().getFqName(), standardLibrary.getPrimitiveClassDescriptor(primitiveType));
|
||||
}
|
||||
classDescriptorMap.put("java.lang.String", standardLibrary.getString());
|
||||
classDescriptorMap.put("java.lang.CharSequence", standardLibrary.getCharSequence());
|
||||
}
|
||||
return classDescriptorMap;
|
||||
}
|
||||
|
||||
@@ -43,13 +43,16 @@ class Boolean : Comparable<Boolean> {
|
||||
fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
class String() : Comparable<String> {
|
||||
trait CharSequence {
|
||||
fun get(index : Int) : Char
|
||||
|
||||
val length : Int
|
||||
|
||||
fun toString() : String
|
||||
}
|
||||
|
||||
class String() : Comparable<String>, CharSequence {
|
||||
fun plus(other : Any?) : String
|
||||
|
||||
fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ public class JetStandardLibrary {
|
||||
|
||||
private ClassDescriptor numberClass;
|
||||
|
||||
private ClassDescriptor charSequenceClass;
|
||||
private ClassDescriptor stringClass;
|
||||
private ClassDescriptor arrayClass;
|
||||
private ClassDescriptor iterableClass;
|
||||
@@ -59,6 +60,9 @@ public class JetStandardLibrary {
|
||||
private ClassDescriptor comparableClass;
|
||||
|
||||
private JetType stringType;
|
||||
private JetType nullableStringType;
|
||||
private JetType charSequenceType;
|
||||
private JetType nullableCharSequenceType;
|
||||
|
||||
private JetType nullableTuple0Type;
|
||||
|
||||
@@ -67,7 +71,6 @@ public class JetStandardLibrary {
|
||||
}
|
||||
|
||||
private JetType tuple0Type;
|
||||
private JetType nullableStringType;
|
||||
|
||||
private Set<FunctionDescriptor> typeInfoFunction;
|
||||
|
||||
@@ -127,6 +130,7 @@ public class JetStandardLibrary {
|
||||
this.libraryScope = JetStandardClasses.STANDARD_CLASSES_NAMESPACE.getMemberScope();
|
||||
this.numberClass = (ClassDescriptor) libraryScope.getClassifier("Number");
|
||||
this.stringClass = (ClassDescriptor) libraryScope.getClassifier("String");
|
||||
this.charSequenceClass = (ClassDescriptor) libraryScope.getClassifier("CharSequence");
|
||||
this.arrayClass = (ClassDescriptor) libraryScope.getClassifier("Array");
|
||||
|
||||
this.iterableClass = (ClassDescriptor) libraryScope.getClassifier("Iterable");
|
||||
@@ -136,6 +140,8 @@ public class JetStandardLibrary {
|
||||
this.typeInfoFunction = libraryScope.getFunctions("typeinfo");
|
||||
|
||||
this.stringType = new JetTypeImpl(getString());
|
||||
this.charSequenceType = new JetTypeImpl(getCharSequence());
|
||||
this.nullableCharSequenceType = TypeUtils.makeNullable(charSequenceType);
|
||||
this.nullableStringType = TypeUtils.makeNullable(stringType);
|
||||
|
||||
this.tuple0Type = new JetTypeImpl(JetStandardClasses.getTuple(0));
|
||||
@@ -230,6 +236,12 @@ public class JetStandardLibrary {
|
||||
return stringClass;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getCharSequence() {
|
||||
initStdClasses();
|
||||
return charSequenceClass;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getArray() {
|
||||
initStdClasses();
|
||||
@@ -311,6 +323,12 @@ public class JetStandardLibrary {
|
||||
return stringType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getCharSequenceType() {
|
||||
initStdClasses();
|
||||
return charSequenceType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getByteType() {
|
||||
return getPrimitiveJetType(PrimitiveType.BYTE);
|
||||
@@ -371,11 +389,18 @@ public class JetStandardLibrary {
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getNullableStringType() {
|
||||
initStdClasses();
|
||||
return nullableStringType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getNullableCharSequenceType() {
|
||||
initStdClasses();
|
||||
return nullableCharSequenceType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getNullablePrimitiveJetType(PrimitiveType primitiveType) {
|
||||
initStdClasses();
|
||||
|
||||
@@ -40,6 +40,8 @@ inline fun String.startsWith(prefix: String) = (this as java.lang.String).starts
|
||||
|
||||
inline fun String.startsWith(prefix: String, toffset: Int) = (this as java.lang.String).startsWith(prefix, toffset)
|
||||
|
||||
inline fun String.contains(seq: CharSequence) : Boolean = (this as java.lang.String).contains(seq)
|
||||
|
||||
inline val String.size : Int
|
||||
get() = length()
|
||||
|
||||
@@ -66,19 +68,14 @@ inline fun String(stringBuffer : java.lang.StringBuffer) = java.lang.String(stri
|
||||
|
||||
inline fun String(stringBuilder : java.lang.StringBuilder) = java.lang.String(stringBuilder) as String
|
||||
|
||||
/*
|
||||
Iterator for characters of given String
|
||||
*/
|
||||
inline fun String.iterator() : CharIterator = (this as java.lang.String).iterator()
|
||||
|
||||
/*
|
||||
Iterator for characters of given CharSequence
|
||||
*/
|
||||
inline fun java.lang.CharSequence.iterator() : CharIterator = object: jet.CharIterator() {
|
||||
inline fun CharSequence.iterator() : CharIterator = object: jet.CharIterator() {
|
||||
private var index = 0
|
||||
|
||||
public override fun nextChar(): Char = charAt(index++)
|
||||
public override fun nextChar(): Char = get(index++)
|
||||
|
||||
public override val hasNext: Boolean
|
||||
get() = index < length()
|
||||
get() = index < length
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user