mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
Use the Enum hack fpr all used enums. Before it was for the enums in the libraries
This commit is contained in:
parent
bf0b43fd1a
commit
8d17e7cfc5
@ -190,19 +190,6 @@ public class ModuleGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( classFile.isEnum() ) {
|
|
||||||
//temporary Hack because the generated Enum.valueOf(String) use Reflection which currently is not supported
|
|
||||||
for( MethodInfo method : classFile.getMethods() ) {
|
|
||||||
if( "valueOf".equals( method.getName() ) && method.getType().startsWith( "(Ljava/lang/String;)" ) ) {
|
|
||||||
FunctionName valueOf = new FunctionName( method );
|
|
||||||
String replaceForEnums = ReplacementForEnums.class.getName().replace( ".", "/" );
|
|
||||||
ClassFile file = classFileLoader.get( replaceForEnums );
|
|
||||||
MethodInfo method2 = file.getMethod( "valueOf_", "(Ljava/lang/String;)L" + replaceForEnums + ";" );
|
|
||||||
functions.addReplacement( valueOf, method2 );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
iterateMethods( classFile, m -> prepareMethod( m ) );
|
iterateMethods( classFile, m -> prepareMethod( m ) );
|
||||||
}
|
}
|
||||||
@ -234,6 +221,17 @@ public class ModuleGenerator {
|
|||||||
MethodInfo method = null;
|
MethodInfo method = null;
|
||||||
ClassFile classFile = classFileLoader.get( next.className );
|
ClassFile classFile = classFileLoader.get( next.className );
|
||||||
if( classFile != null ) {
|
if( classFile != null ) {
|
||||||
|
|
||||||
|
//temporary Hack because the generated Enum.valueOf(String) use Reflection which currently is not supported
|
||||||
|
if( classFile.isEnum() && "valueOf".equals( next.methodName ) && next.signature.startsWith( "(Ljava/lang/String;)" ) ) {
|
||||||
|
System.err.println( next.signatureName );
|
||||||
|
String replaceForEnums = ReplacementForEnums.class.getName().replace( ".", "/" );
|
||||||
|
ClassFile file = classFileLoader.get( replaceForEnums );
|
||||||
|
classFileLoader.partial( next.className, file );
|
||||||
|
MethodInfo method2 = classFile.getMethod( "valueOf_", next.signature );
|
||||||
|
functions.addReplacement( next, method2 );
|
||||||
|
}
|
||||||
|
|
||||||
sourceFile = classFile.getSourceFile();
|
sourceFile = classFile.getSourceFile();
|
||||||
className = classFile.getThisClass().getName();
|
className = classFile.getThisClass().getName();
|
||||||
method = classFile.getMethod( next.methodName, next.signature );
|
method = classFile.getMethod( next.methodName, next.signature );
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2021 Volker Berlin (i-net software)
|
Copyright 2021 - 2022 Volker Berlin (i-net software)
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@ -24,20 +24,30 @@ import java.util.Map;
|
|||||||
*
|
*
|
||||||
* @author Volker Berlin
|
* @author Volker Berlin
|
||||||
*/
|
*/
|
||||||
public enum ReplacementForEnums {
|
public abstract class ReplacementForEnums {
|
||||||
;
|
|
||||||
private transient Map<String, ReplacementForEnums> enumConstantDirectory;
|
private static transient Map<String, ReplacementForEnums> enumConstantDirectory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Placeholder for existing public method.
|
||||||
|
*/
|
||||||
|
public native String name();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Placeholder for existing public method.
|
||||||
|
*/
|
||||||
|
public native static ReplacementForEnums[] values();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replacement code for generated Enum.valueOf( String )
|
* Replacement code for generated Enum.valueOf( String )
|
||||||
* @param name the enum name
|
* @param name the enum name
|
||||||
* @return The singleton instance for the name
|
* @return The singleton instance for the name
|
||||||
*/
|
*/
|
||||||
ReplacementForEnums valueOf_( String name ) {
|
static ReplacementForEnums valueOf_( String name ) {
|
||||||
Map<String, ReplacementForEnums> map = enumConstantDirectory;
|
Map<String, ReplacementForEnums> map = enumConstantDirectory;
|
||||||
if( map == null ) {
|
if( map == null ) {
|
||||||
ReplacementForEnums[] universe = values();
|
ReplacementForEnums[] universe = values();
|
||||||
map = new HashMap<>( 2 * universe.length );
|
map = new HashMap<>( universe.length );
|
||||||
for( ReplacementForEnums constant : universe ) {
|
for( ReplacementForEnums constant : universe ) {
|
||||||
map.put( constant.name(), constant );
|
map.put( constant.name(), constant );
|
||||||
}
|
}
|
||||||
@ -51,6 +61,6 @@ public enum ReplacementForEnums {
|
|||||||
if( name == null ) {
|
if( name == null ) {
|
||||||
throw new NullPointerException( "Name is null" );
|
throw new NullPointerException( "Name is null" );
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException( "No enum constant " + getClass().getCanonicalName() + "." + name );
|
throw new IllegalArgumentException( "No enum constant " + ReplacementForEnums.class + "." + name );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user