mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
java.lang.Object constructor generated properly
This commit is contained in:
parent
ee10986d05
commit
50a8c85cd1
|
@ -15,7 +15,7 @@ public class ObjectNativeGenerator implements Generator {
|
||||||
@Override
|
@Override
|
||||||
public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) {
|
public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) {
|
||||||
switch (methodRef.getDescriptor().getName()) {
|
switch (methodRef.getDescriptor().getName()) {
|
||||||
case "init":
|
case "<init>":
|
||||||
generateInit(context, writer);
|
generateInit(context, writer);
|
||||||
break;
|
break;
|
||||||
case "getClass":
|
case "getClass":
|
||||||
|
|
|
@ -2,17 +2,20 @@ package org.teavm.classlib.java.lang;
|
||||||
|
|
||||||
import org.teavm.javascript.ni.GeneratedBy;
|
import org.teavm.javascript.ni.GeneratedBy;
|
||||||
import org.teavm.javascript.ni.Rename;
|
import org.teavm.javascript.ni.Rename;
|
||||||
|
import org.teavm.javascript.ni.Superclass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Alexey Andreev <konsoletyper@gmail.com>
|
* @author Alexey Andreev <konsoletyper@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
@Superclass("")
|
||||||
public class TObject {
|
public class TObject {
|
||||||
|
@Rename("fakeInit")
|
||||||
public TObject() {
|
public TObject() {
|
||||||
init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GeneratedBy(ObjectNativeGenerator.class)
|
@GeneratedBy(ObjectNativeGenerator.class)
|
||||||
|
@Rename("<init>")
|
||||||
private native void init();
|
private native void init();
|
||||||
|
|
||||||
@GeneratedBy(ObjectNativeGenerator.class)
|
@GeneratedBy(ObjectNativeGenerator.class)
|
||||||
|
|
|
@ -489,7 +489,7 @@ public class StatementGenerator implements InstructionVisitor {
|
||||||
public String findDeclaringClass(String className, MethodDescriptor method) {
|
public String findDeclaringClass(String className, MethodDescriptor method) {
|
||||||
ClassHolder cls = classSource.getClassHolder(className);
|
ClassHolder cls = classSource.getClassHolder(className);
|
||||||
while (cls != null && cls.getMethod(method) == null) {
|
while (cls != null && cls.getMethod(method) == null) {
|
||||||
cls = classSource.getClassHolder(cls.getParent());
|
cls = cls.getParent() != null ? classSource.getClassHolder(cls.getParent()) : null;
|
||||||
}
|
}
|
||||||
return cls != null ? cls.getName() : null;
|
return cls != null ? cls.getName() : null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import java.lang.annotation.Target;
|
||||||
* @author Alexey Andreev <konsoletyper@gmail.com>
|
* @author Alexey Andreev <konsoletyper@gmail.com>
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.METHOD)
|
@Target({ ElementType.METHOD, ElementType.CONSTRUCTOR })
|
||||||
public @interface Rename {
|
public @interface Rename {
|
||||||
String value();
|
String value();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package org.teavm.javascript.ni;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Alexey Andreev
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
public @interface Superclass {
|
||||||
|
String value();
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package org.teavm.model.resource;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.teavm.codegen.Mapper;
|
import org.teavm.codegen.Mapper;
|
||||||
import org.teavm.javascript.ni.Rename;
|
import org.teavm.javascript.ni.Rename;
|
||||||
|
import org.teavm.javascript.ni.Superclass;
|
||||||
import org.teavm.model.*;
|
import org.teavm.model.*;
|
||||||
import org.teavm.model.instructions.*;
|
import org.teavm.model.instructions.*;
|
||||||
|
|
||||||
|
@ -21,9 +22,15 @@ class ClassRefsRenamer implements InstructionVisitor {
|
||||||
ClassHolder renamedCls = new ClassHolder(classNameMapper.map(cls.getName()));
|
ClassHolder renamedCls = new ClassHolder(classNameMapper.map(cls.getName()));
|
||||||
renamedCls.getModifiers().addAll(cls.getModifiers());
|
renamedCls.getModifiers().addAll(cls.getModifiers());
|
||||||
renamedCls.setLevel(cls.getLevel());
|
renamedCls.setLevel(cls.getLevel());
|
||||||
if (cls.getParent() != null) {
|
String parent = cls.getParent();
|
||||||
renamedCls.setParent(classNameMapper.map(cls.getParent()));
|
AnnotationHolder superclassAnnot = cls.getAnnotations().get(Superclass.class.getName());
|
||||||
|
if (superclassAnnot != null) {
|
||||||
|
parent = superclassAnnot.getValues().get("value").getString();
|
||||||
|
if (parent.isEmpty()) {
|
||||||
|
parent = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
renamedCls.setParent(parent != null ? classNameMapper.map(parent) : null);
|
||||||
for (MethodHolder method : cls.getMethods()) {
|
for (MethodHolder method : cls.getMethods()) {
|
||||||
renamedCls.addMethod(rename(method));
|
renamedCls.addMethod(rename(method));
|
||||||
}
|
}
|
||||||
|
@ -71,7 +78,8 @@ class ClassRefsRenamer implements InstructionVisitor {
|
||||||
|
|
||||||
private void rename(AnnotationContainer source, AnnotationContainer target) {
|
private void rename(AnnotationContainer source, AnnotationContainer target) {
|
||||||
for (AnnotationHolder annot : source.all()) {
|
for (AnnotationHolder annot : source.all()) {
|
||||||
if (!annot.getType().equals(Rename.class.getName())) {
|
if (!annot.getType().equals(Rename.class.getName()) &&
|
||||||
|
!annot.getType().equals(Superclass.class.getName())) {
|
||||||
target.add(rename(annot));
|
target.add(rename(annot));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user