JNI version is the default, its name should reflect that

Reviewed By: lucasr

Differential Revision: D3992777

fbshipit-source-id: cdd4cc58f3c15b5db1158f6f794394eb5c44a44d
This commit is contained in:
Emil Sjolander 2016-10-12 03:44:50 -07:00 committed by Facebook Github Bot
parent 5c728a47b9
commit 6dae68306e

View File

@ -17,7 +17,7 @@ import java.util.ArrayList;
import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.soloader.SoLoader; import com.facebook.soloader.SoLoader;
public class CSSNodeJNI implements CSSNodeAPI<CSSNodeJNI> { public class CSSNode implements CSSNodeAPI<CSSNode> {
static { static {
try { try {
@ -29,8 +29,8 @@ public class CSSNodeJNI implements CSSNodeAPI<CSSNodeJNI> {
} }
} }
private CSSNodeJNI mParent; private CSSNode mParent;
private List<CSSNodeJNI> mChildren; private List<CSSNode> mChildren;
private MeasureFunction mMeasureFunction; private MeasureFunction mMeasureFunction;
private long mNativePointer; private long mNativePointer;
private Object mData; private Object mData;
@ -60,10 +60,6 @@ public class CSSNodeJNI implements CSSNodeAPI<CSSNodeJNI> {
throw new IllegalStateException("You should not reset an attached CSSNode"); throw new IllegalStateException("You should not reset an attached CSSNode");
} }
free();
}
private void free() {
jni_CSSNodeFree(mNativePointer); jni_CSSNodeFree(mNativePointer);
mNativePointer = 0; mNativePointer = 0;
mChildren = null; mChildren = null;
@ -71,30 +67,19 @@ public class CSSNodeJNI implements CSSNodeAPI<CSSNodeJNI> {
mMeasureFunction = null; mMeasureFunction = null;
} }
@Override
protected void finalize() throws Throwable {
try {
if (mNativePointer != 0) {
free();
}
} finally {
super.finalize();
}
}
@Override @Override
public int getChildCount() { public int getChildCount() {
return mChildren.size(); return mChildren.size();
} }
@Override @Override
public CSSNodeJNI getChildAt(int i) { public CSSNode getChildAt(int i) {
return mChildren.get(i); return mChildren.get(i);
} }
private native void jni_CSSNodeInsertChild(long nativePointer, long childPointer, int index); private native void jni_CSSNodeInsertChild(long nativePointer, long childPointer, int index);
@Override @Override
public void addChildAt(CSSNodeJNI child, int i) { public void addChildAt(CSSNode child, int i) {
assertNativeInstance(); assertNativeInstance();
if (child.mParent != null) { if (child.mParent != null) {
throw new IllegalStateException("Child already has a parent, it must be removed first."); throw new IllegalStateException("Child already has a parent, it must be removed first.");
@ -107,22 +92,23 @@ public class CSSNodeJNI implements CSSNodeAPI<CSSNodeJNI> {
private native void jni_CSSNodeRemoveChild(long nativePointer, long childPointer); private native void jni_CSSNodeRemoveChild(long nativePointer, long childPointer);
@Override @Override
public CSSNodeJNI removeChildAt(int i) { public CSSNode removeChildAt(int i) {
assertNativeInstance(); assertNativeInstance();
final CSSNodeJNI child = mChildren.remove(i); final CSSNode child = mChildren.remove(i);
child.mParent = null; child.mParent = null;
jni_CSSNodeRemoveChild(mNativePointer, child.mNativePointer); jni_CSSNodeRemoveChild(mNativePointer, child.mNativePointer);
return child; return child;
} }
@Override @Override
public @Nullable CSSNodeJNI getParent() { public @Nullable
CSSNode getParent() {
return mParent; return mParent;
} }
@Override @Override
public int indexOf(CSSNodeJNI child) { public int indexOf(CSSNode child) {
return mChildren.indexOf(child); return mChildren.indexOf(child);
} }