From 0227137e2e7c10c45727cf542cc5d94ddda44511 Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Fri, 16 Nov 2018 17:46:10 +0100 Subject: [PATCH] use constants for annotations --- src/de/inetsoftware/jwebassembly/JWebAssembly.java | 13 +++++++++++++ .../jwebassembly/module/ModuleGenerator.java | 10 +++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/de/inetsoftware/jwebassembly/JWebAssembly.java b/src/de/inetsoftware/jwebassembly/JWebAssembly.java index 3f9e4fc..7b49498 100644 --- a/src/de/inetsoftware/jwebassembly/JWebAssembly.java +++ b/src/de/inetsoftware/jwebassembly/JWebAssembly.java @@ -48,8 +48,21 @@ public class JWebAssembly { private final HashMap properties = new HashMap<>(); + /** + * Property for adding debug names to the output if true. + */ public static final String DEBUG_NAMES = "DebugNames"; + /** + * The name of the annotation for import functions. + */ + public static final String IMPORT_ANNOTATION = "de.inetsoftware.jwebassembly.api.annotation.Import"; + + /** + * The name of the annotation for export functions. + */ + public static final String EXPORT_ANNOTATION = "de.inetsoftware.jwebassembly.api.annotation.Export"; + /** * Create a instance. */ diff --git a/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java b/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java index 8f3e568..288dfd0 100644 --- a/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java +++ b/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java @@ -28,6 +28,7 @@ import de.inetsoftware.classparser.Code; import de.inetsoftware.classparser.CodeInputStream; import de.inetsoftware.classparser.LocalVariableTable; import de.inetsoftware.classparser.MethodInfo; +import de.inetsoftware.jwebassembly.JWebAssembly; import de.inetsoftware.jwebassembly.WasmException; /** @@ -118,7 +119,7 @@ public class ModuleGenerator { private void prepareMethod( MethodInfo method ) throws WasmException { try { FunctionName name = new FunctionName( method ); - Map annotationValues = method.getAnnotation( "de.inetsoftware.jwebassembly.api.annotation.Import" ); + Map annotationValues = method.getAnnotation( JWebAssembly.IMPORT_ANNOTATION ); if( annotationValues != null ) { String impoarModule = (String)annotationValues.get( "module" ); String importName = (String)annotationValues.get( "name" ); @@ -143,8 +144,11 @@ public class ModuleGenerator { private void writeMethod( MethodInfo method ) throws WasmException { CodeInputStream byteCode = null; try { + if( method.getAnnotation( JWebAssembly.IMPORT_ANNOTATION ) != null ) { + return; + } Code code = method.getCode(); - if( code != null && method.getAnnotation( "de.inetsoftware.jwebassembly.api.annotation.Import" ) == null ) { // abstract methods and interface methods does not have code + if( code != null ) { // abstract methods and interface methods does not have code FunctionName name = new FunctionName( method ); writeExport( name, method ); writer.writeMethodStart( name ); @@ -175,7 +179,7 @@ public class ModuleGenerator { * if any IOException occur */ private void writeExport( FunctionName name, MethodInfo method ) throws IOException { - Map export = method.getAnnotation( "de.inetsoftware.jwebassembly.api.annotation.Export" ); + Map export = method.getAnnotation( JWebAssembly.EXPORT_ANNOTATION ); if( export != null ) { String exportName = (String)export.get( "name" ); if( exportName == null ) {