diff --git a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/JavaPrettyPrint.g b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/JavaPrettyPrint.g index b875235..0769cc9 100644 --- a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/JavaPrettyPrint.g +++ b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/JavaPrettyPrint.g @@ -247,6 +247,10 @@ options { // (${var}) -> () ret = Regex.Replace(ret, "\\$\\{[\\w:]+?\\}", String.Empty); } + // If we have a generic type then we can scrub its generic arguments + // by susbstituting with an empty dictionary, now tidy up the brackets + // and commas + ret = Regex.Replace(ret, "\\s*<(\\s*,\\s*)*>\\s*", String.Empty); return ret; } diff --git a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/NetMaker.g b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/NetMaker.g index f2c66df..5a9c226 100644 --- a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/NetMaker.g +++ b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/NetMaker.g @@ -38,6 +38,13 @@ scope PrimitiveRep { bool primitiveTypeAsObject; } +// When this scope is true, then strip generic arguments from types +// (In Java the runtime doesn't know the generic types so e.g. instanceof Set +// must be just instanceof Set). +scope MkNonGeneric { + bool scrubGenericArgs; +} + @namespace { Twiglet.CS2J.Translator.Transform } @header @@ -497,12 +504,13 @@ scope PrimitiveRep { } public compilation_unit -scope NSContext, PrimitiveRep; +scope NSContext, PrimitiveRep, MkNonGeneric; @init { Imports = new Set(); $PrimitiveRep::primitiveTypeAsObject = false; + $MkNonGeneric::scrubGenericArgs = false; // TODO: Do we need to ensure we have access to System? If so, can add it here. $NSContext::namespaces = SearchPath ?? new List(); @@ -1020,7 +1028,7 @@ type_or_generic[String prefix] returns [TypeRepTemplate dotNetType, List {dateArgs}? $ople ->^($le $le1 $le2) - | ^(INSTANCEOF non_assignment_expression non_nullable_type) {$dotNetType = BoolType; } + | ^(INSTANCEOF non_assignment_expression { $MkNonGeneric::scrubGenericArgs = true; } non_nullable_type) {$dotNetType = BoolType; } | ^('<<' n7=non_assignment_expression non_assignment_expression) {$dotNetType = $n7.dotNetType; } | ^(RIGHT_SHIFT n8=non_assignment_expression non_assignment_expression) {$dotNetType = $n8.dotNetType; } // TODO: need to munge these numeric types