Completes java.lang.StringBuilder|StringBuffer

This commit is contained in:
konsoletyper 2014-03-12 15:43:26 +04:00
parent b158046a9a
commit 134196d401
5 changed files with 266 additions and 5 deletions

View File

@ -648,6 +648,10 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
return append(s, 0, s.length());
}
protected TAbstractStringBuilder append(TStringBuffer s) {
return append((TCharSequence)s);
}
protected TAbstractStringBuilder insert(int index, TCharSequence s) {
return insert(index, s, 0, s.length());
}
@ -675,8 +679,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
@Override
public TCharSequence subSequence(int start, int end) {
// TODO: implement
throw new TUnsupportedOperationException();
return substring(start, end);
}
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) {
@ -783,4 +786,38 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
}
return this;
}
public TString substring(int from, int to) {
if (from > to || from < 0 || to >= length) {
throw new TIndexOutOfBoundsException();
}
return new TString(buffer, from, to - from);
}
public TString substring(int from) {
return substring(from, length);
}
public void setCharAt(int index, char ch) {
if (index > length) {
throw new TIndexOutOfBoundsException();
}
buffer[index] = ch;
}
public int offsetByCodePoints(int index, int codePointOffset) {
return TCharacter.offsetByCodePoints(this, index, codePointOffset);
}
public int codePointCount(int beginIndex, int endIndex) {
return TCharacter.codePointCount(this, beginIndex, endIndex);
}
public int codePointAt(int index) {
return TCharacter.codePointAt(this, index);
}
public int codePointBefore(int index) {
return TCharacter.codePointBefore(this, index);
}
}

View File

@ -0,0 +1,218 @@
/*
* Copyright 2014 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.lang;
/**
*
* @author Alexey Andreev
*/
public class TStringBuffer extends TAbstractStringBuilder implements TAppendable {
public TStringBuffer(int capacity) {
super(capacity);
}
public TStringBuffer() {
super();
}
public TStringBuffer(TString value) {
super(value);
}
public TStringBuffer(TCharSequence value) {
super(value);
}
@Override
public TStringBuffer append(TString string) {
super.append(string);
return this;
}
@Override
public TStringBuffer append(int value) {
super.append(value);
return this;
}
@Override
public TStringBuffer append(long value) {
super.append(value);
return this;
}
@Override
public TStringBuffer append(float value) {
super.append(value);
return this;
}
@Override
public TStringBuffer append(double value) {
super.append(value);
return this;
}
@Override
public TStringBuffer append(char c) {
super.append(c);
return this;
}
@Override
public TStringBuffer append(char[] chars, int offset, int len) {
super.append(chars, offset, len);
return this;
}
@Override
public TStringBuffer append(char[] chars) {
super.append(chars);
return this;
}
@Override
public TStringBuffer appendCodePoint(int codePoint) {
super.appendCodePoint(codePoint);
return this;
}
@Override
public TStringBuffer append(TCharSequence s, int start, int end) {
super.append(s, start, end);
return this;
}
@Override
public TStringBuffer append(TCharSequence s) {
super.append(s);
return this;
}
@Override
public TStringBuffer append(TStringBuffer s) {
super.append(s);
return this;
}
@Override
public TStringBuffer append(TObject obj) {
super.append(obj);
return this;
}
@Override
public TStringBuffer append(boolean b) {
super.append(b);
return this;
}
@Override
public TStringBuffer insert(int target, long value) {
super.insert(target, value);
return this;
}
@Override
public TStringBuffer insert(int target, float value) {
super.insert(target, value);
return this;
}
@Override
public TStringBuffer insert(int target, double value) {
super.insert(target, value);
return this;
}
@Override
public TStringBuffer insert(int index, TCharSequence s, int start, int end) {
super.insert(index, s, start, end);
return this;
}
@Override
public TStringBuffer insert(int index, TCharSequence s) {
super.insert(index, s);
return this;
}
@Override
public TStringBuffer insert(int index, int value) {
super.insert(index, value);
return this;
}
@Override
public TStringBuffer insert(int index, char[] chars, int offset, int len) {
super.insert(index, chars, offset, len);
return this;
}
@Override
public TStringBuffer insert(int index, TObject obj) {
super.insert(index, obj);
return this;
}
@Override
public TStringBuffer insert(int index, char[] chars) {
super.insert(index, chars);
return this;
}
@Override
public TStringBuffer insert(int index, boolean b) {
super.insert(index, b);
return this;
}
@Override
public TStringBuffer insert(int index, char c) {
super.insert(index, c);
return this;
}
@Override
public TStringBuffer delete(int start, int end) {
super.delete(start, end);
return this;
}
@Override
public TStringBuffer replace(int start, int end, TString str) {
super.replace(start, end, str);
return this;
}
@Override
public TStringBuffer deleteCharAt(int index) {
deleteCharAt(index);
return this;
}
@Override
public TStringBuffer insert(int index, TString string) {
super.insert(index, string);
return this;
}
@Override
public TStringBuffer reverse() {
super.reverse();
return this;
}
}

View File

@ -102,6 +102,12 @@ public class TStringBuilder extends TAbstractStringBuilder implements TAppendabl
return this;
}
@Override
public TStringBuilder append(TStringBuffer s) {
super.append(s);
return this;
}
@Override
public TStringBuilder append(TObject obj) {
super.append(obj);

View File

@ -67,7 +67,7 @@ public class ClasspathResourceMapper implements Mapper<String, ClassHolder> {
String packageName = propertyName.substring(PACKAGE_PREFIX.length());
Transformation transformation = getTransformation(cache, packageName);
transformation.packagePrefix = properties.getProperty(propertyName) + ".";
transformation.fullPrefix = transformation.packagePrefix + transformation.packageName + ".";
transformation.fullPrefix = transformation.packagePrefix + transformation.packageName;
} else if (propertyName.startsWith(CLASS_PREFIX)) {
String packageName = propertyName.substring(CLASS_PREFIX.length());
Transformation transformation = getTransformation(cache, packageName);
@ -80,7 +80,7 @@ public class ClasspathResourceMapper implements Mapper<String, ClassHolder> {
Transformation transformation = cache.get(packageName);
if (transformation == null) {
transformation = new Transformation();
transformation.packageName = packageName;
transformation.packageName = packageName + ".";
transformation.fullPrefix = packageName + ".";
cache.put(packageName, transformation);
}

View File

@ -1102,7 +1102,7 @@ public class ProgramParser {
int b = popSingle();
int a = popSingle();
int tmp = pushSingle();
popSingle();
pushSingle();
emitAssignInsn(a, tmp);
emitAssignInsn(b, a);
emitAssignInsn(tmp, b);