Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes for printing generics

  • Loading branch information...
commit ba61804edb4811c6f87f647085cfa9f586f473c5 1 parent 99176d7
@ribrdb ribrdb authored
Showing with 66 additions and 25 deletions.
  1. +34 −10 lib/bitescript/asm3/mirror.rb
  2. +32 −15 lib/bitescript/mirror.rb
View
44 lib/bitescript/asm3/mirror.rb
@@ -113,6 +113,20 @@ def visitEnd
end
end
+ module Generics
+ def inspect_type(type)
+ if type.kind_of?(BiteScript::ASM::Type)
+ type.class_name
+ else
+ type.to_s
+ end
+ end
+
+ def inspect_generic(type, generic_type)
+ inspect_type(generic_type || type)
+ end
+ end
+
module Annotated
def annotations
@annotations ||= {}
@@ -166,6 +180,7 @@ def modifier_string
class ClassMirror
include Annotated
include Modifiers
+ include Generics
attr_reader :type, :interfaces
attr_accessor :superclass, :signature
@@ -271,10 +286,12 @@ def inspect
kind = "class"
end
if superclass && !enum? && !interface?
- extends = "extends #{superclass.getClassName} "
+ extends = "extends #{inspect_generic(superclass, generic_superclass)} "
end
if self.interfaces && !self.interfaces.empty?
- interfaces = self.interfaces.map{|i| i.class_name}.join(', ')
+ interfaces = (self.generic_interfaces || self.interfaces).map do |i|
+ inspect_type(i)
+ end.join(', ')
if interface?
extends = "extends #{interfaces} "
else
@@ -282,7 +299,8 @@ def inspect
end
end
result = "#{inspect_annotations}#{modifier_string}#{kind} "
- result << "#{type.class_name} #{extends}{\n"
+ typevars = "<#{type_parameters.map{|p| p.to_s}.join ', '}>" if type_parameters && type_parameters.size != 0
+ result << "#{type.class_name}#{typevars} #{extends}{\n"
(getDeclaredFields + getConstructors + getDeclaredMethods).each do |f|
result << f.inspect << "\n"
end
@@ -350,6 +368,7 @@ def to_s
class FieldMirror
include Modifiers
+ include Generics
include Annotated
attr_reader :declaring_class, :name, :type, :value, :signature
@@ -367,13 +386,15 @@ def generic_type
end
def inspect
- inspect_annotations + "#{modifier_string}#{type.getClassName} #{name};"
+ typename = inspect_generic(type, signature)
+ inspect_annotations + "#{modifier_string}#{typename} #{name};"
end
end
class MethodMirror
include Modifiers
include Annotated
+ include Generics
attr_reader :declaring_class, :name, :return_type
attr_reader :argument_types, :exception_types, :signature
@@ -405,12 +426,14 @@ def type_parameters
end
def inspect
- "%s%s%s %s(%s);" % [
+ typevars = "<#{type_parameters.map{|p| p.to_s}.join ', '}> " if type_parameters && type_parameters.size != 0
+ "%s%s%s%s %s(%s);" % [
inspect_annotations,
modifier_string,
- return_type.class_name,
+ typevars,
+ inspect_generic(return_type, generic_return_type),
name,
- argument_types.map {|x| x.class_name}.join(', '),
+ (generic_parameter_types || argument_types).map {|x| inspect_type(x)}.join(', '),
]
end
end
@@ -475,6 +498,7 @@ def visitInterface
end
class GenericTypeMirror
+ include Generics
def array?
false
end
@@ -530,11 +554,11 @@ def initialize(upper_bound, lower_bound=nil)
def wildcard?
true
end
- def to_s?
+ def to_s
if lower_bound
- "? super #{lower_bound}"
+ "? super #{inspect_type(lower_bound)}"
elsif upper_bound
- "? extends #{upper_bound}"
+ "? extends #{inspect_type(upper_bound)}"
else
"?"
end
View
47 lib/bitescript/mirror.rb
@@ -112,6 +112,20 @@ def visitEnd
end
end
+ module Generics
+ def inspect_type(type)
+ if type.kind_of?(BiteScript::ASM::Type)
+ type.class_name
+ else
+ type.to_s
+ end
+ end
+
+ def inspect_generic(type, generic_type)
+ inspect_type(generic_type || type)
+ end
+ end
+
module Annotated
def annotations
@annotations ||= {}
@@ -165,6 +179,7 @@ def modifier_string
class ClassMirror
include Annotated
include Modifiers
+ include Generics
attr_reader :type, :interfaces
attr_accessor :superclass, :signature
@@ -270,22 +285,18 @@ def inspect
kind = "class"
end
if superclass && !enum? && !interface?
- extends = "extends #{superclass.getClassName} "
+ extends = "extends #{inspect_generic(superclass, generic_superclass)} "
end
if self.interfaces && !self.interfaces.empty?
- interfaces = self.interfaces.map{|i| i.class_name}.join(', ')
+ interfaces = (self.generic_interfaces || self.interfaces).map do |i|
+ inspect_type(i)
+ end.join(', ')
if interface?
extends = "extends #{interfaces} "
else
implements = "implements #{interfaces} "
end
end
- result = "#{inspect_annotations}#{modifier_string}#{kind} "
- result << "#{type.class_name} #{extends}{\n"
- (getDeclaredFields + getConstructors + getDeclaredMethods).each do |f|
- result << f.inspect << "\n"
- end
- result << "}"
end
class Builder < BiteScript::ASM::ClassVisitor
@@ -350,6 +361,7 @@ def to_s
class FieldMirror
include Modifiers
+ include Generics
include Annotated
attr_reader :declaring_class, :name, :type, :value, :signature
@@ -367,7 +379,8 @@ def generic_type
end
def inspect
- inspect_annotations + "#{modifier_string}#{type.getClassName} #{name};"
+ typename = inspect_generic(type, signature)
+ inspect_annotations + "#{modifier_string}#{typename} #{name};"
end
class Builder < BiteScript::ASM::FieldVisitor
@@ -389,6 +402,7 @@ def to_s
class MethodMirror
include Modifiers
include Annotated
+ include Generics
attr_reader :declaring_class, :name, :return_type
attr_reader :argument_types, :exception_types, :signature
@@ -420,12 +434,14 @@ def type_parameters
end
def inspect
- "%s%s%s %s(%s);" % [
+ typevars = "<#{type_parameters.map{|p| p.to_s}.join ', '}> " if type_parameters && type_parameters.size != 0
+ "%s%s%s%s %s(%s);" % [
inspect_annotations,
modifier_string,
- return_type.class_name,
+ typevars,
+ inspect_generic(return_type, generic_return_type),
name,
- argument_types.map {|x| x.class_name}.join(', '),
+ (generic_parameter_types || argument_types).map {|x| inspect_type(x)}.join(', '),
]
end
@@ -507,6 +523,7 @@ def visitInterface
end
class GenericTypeMirror
+ include Generics
def array?
false
end
@@ -562,11 +579,11 @@ def initialize(upper_bound, lower_bound=nil)
def wildcard?
true
end
- def to_s?
+ def to_s
if lower_bound
- "? super #{lower_bound}"
+ "? super #{inspect_type(lower_bound)}"
elsif upper_bound
- "? extends #{upper_bound}"
+ "? extends #{inspect_type(upper_bound)}"
else
"?"
end
Please sign in to comment.
Something went wrong with that request. Please try again.