contrib/jwrapper: accept [] (and anything) in search for existing wrappers
[nit.git] / contrib / jwrapper / src / model.nit
index 8d6da40..011d0a8 100644 (file)
@@ -24,6 +24,8 @@ import opts
 import jtype_converter
 
 class JavaType
+       super Cloneable
+
        var identifier = new Array[String]
        var generic_params: nullable Array[JavaType] = null
 
@@ -121,6 +123,18 @@ class JavaType
                end
        end
 
+       # Get a copy of `self`
+       redef fun clone
+       do
+               var jtype = new JavaType
+               jtype.identifier = identifier
+               jtype.generic_params = generic_params
+               jtype.is_void = is_void
+               jtype.is_vararg = is_vararg
+               jtype.array_dimension = array_dimension
+               return jtype
+       end
+
        # Comparison based on fully qualified named
        redef fun ==(other) do return other isa JavaType and
                self.full_id == other.full_id and
@@ -148,7 +162,7 @@ class JavaClass
        var class_type: JavaType
 
        # Attributes of this class
-       var attributes = new HashMap[String, JavaType]
+       var attributes = new HashMap[String, JavaAttribute]
 
        # Methods of this class organized by their name
        var methods = new MultiHashMap[String, JavaMethod]
@@ -226,8 +240,17 @@ class JavaModel
        end
 end
 
+# A property to a Java class
+abstract class JavaProperty
+
+       # Is this property marked static?
+       var is_static: Bool
+end
+
 # A Java method, with its signature
 class JavaMethod
+       super JavaProperty
+
        # Type returned by the method
        var return_type: JavaType
 
@@ -235,6 +258,14 @@ class JavaMethod
        var params: Array[JavaType]
 end
 
+# An attribute in a Java class
+class JavaAttribute
+       super JavaProperty
+
+       # Type of the attribute
+       var java_type: JavaType
+end
+
 # A Java method, with its signature
 class JavaConstructor
        # Type of the parameters of this constructor
@@ -290,16 +321,16 @@ redef class Sys
                grep.wait
 
                # Sort out the modules, Nit class names and Java types
-               var regex = """(.+):\\s*extern +class +([a-zA-Z0-9_]+) *in *"Java" *`\\{ *([a-zA-Z0-9.$/]+) *`\\}""".to_re
+               var regex = """(.+):\\s*extern +class +([a-zA-Z0-9_]+) *in *"Java" *`\\{(.+)`\\}""".to_re
                for line in lines do
                        var matches = line.search_all(regex)
                        for match in matches do
                                var path = match[1].to_s
                                var nit_name = match[2].to_s
-                               var java_name = match[3].to_s
+                               var java_name = match[3].to_s.trim
 
                                # Debug code
-                               # print "+ Found {nit_name}:{java_name} at {path}"
+                               # print "+ Found {nit_name}: {java_name} at {path}"
 
                                var mod = modules.get_or_null(path)
                                if mod == null then