diff --git a/AST/implementation/literals.dart b/AST/implementation/literals.dart index ad1b917..51cd6a4 100644 --- a/AST/implementation/literals.dart +++ b/AST/implementation/literals.dart @@ -74,13 +74,14 @@ class Literals { else if (entity.toString() == ']') { var length = args == true ? 2 : 0; csharp = csharp.substring(0, csharp.length - length) + '}'; - } else if (entity is SimpleStringLiteral) { + } + else if (entity is TypeArgumentList) + { + csharp += Implementation.processEntity(entity) + '()'; + } else { csharp += Implementation.processEntity(entity) + ', '; args = true; - } else - csharp += Implementation.processEntity(entity); - - if (entity is TypeArgumentList) csharp += '()'; + } } return csharp; } diff --git a/AST/naming.dart b/AST/naming.dart index 57f2aa3..b8ffe66 100644 --- a/AST/naming.dart +++ b/AST/naming.dart @@ -33,6 +33,14 @@ class Naming { name = getFormattedName(name, NameStyle.UpperCamelCase); if (isInterface) name = "I" + name; + + // TODO: Need to sort this out, so it does it for all, not just this particular one. + if (name == 'IObstructingPreferredSizeWidget') + { + var namespace = namespaceFromIdentifier(type.element.library.identifier); + name = namespace + "." + name; + } + var typeArguments = new List(); for (var argument in type.typeArguments) { typeArguments.add(Types.getDartTypeName(argument)); diff --git a/AST/signature/constructors.dart b/AST/signature/constructors.dart index 42219c2..50473c7 100644 --- a/AST/signature/constructors.dart +++ b/AST/signature/constructors.dart @@ -22,13 +22,14 @@ class Constructors { if (constructorName == '') code.writeln('public ${className}($parameters)'); // internal classes start with an underscore in dart - else if (constructorName == '_' || constructorName.startsWith('_')) + else if (constructorName == '_') code.writeln('internal ${className}($parameters)'); else // I'm named, hence we are turing into static methods that return an instance { + var accessibility = constructorName.startsWith('_') ? 'internal' : 'public'; isFactory = true; code.writeln( - 'public static ${className}$generics ${Naming.upperCamelCase(constructorName)}($parameters)'); + '$accessibility static ${className}$generics ${Naming.upperCamelCase(constructorName)}($parameters)'); } // Base class call @@ -50,7 +51,8 @@ class Constructors { var parameters = getBaseParameters(constructor); //TODO Get the correct constructor name in case this class does not call its own constructor! body += 'new ${className}$generics(${parameters});'; - } else + } + else body += 'new ${className}$generics();'; } @@ -74,13 +76,17 @@ class Constructors { 'A constructor is not inside a ClassElement, that should not happen.'); } + + static String getBaseParameters(ConstructorElement constructor) { // Get parameters var parameters = ""; - if (constructor is ConstructorElementImpl && - constructor.constantInitializers.length > 0) { + // TODO: I don't think we auto initialize anything when there are other constantIntializers other than a SuperConstructorInvocation + // Need to add the other code into the method body. + if (constructor is ConstructorElementImpl && constructor.constantInitializers != null && + constructor.constantInitializers.where((x) => x is SuperConstructorInvocation).length > 0) { // :) - var constantInitializer = constructor.constantInitializers.first; + var constantInitializer = constructor.constantInitializers.where((x) => x is SuperConstructorInvocation).first; var argumentList = constantInitializer.childEntities .where((x) => x is ArgumentList); if (argumentList != null && argumentList.length > 0) { @@ -91,7 +97,10 @@ class Constructors { argument is! BeginToken && argument is! SimpleToken) .map((argument) { var parameter = Naming.escapeFixedWords(Implementation.processEntity(argument)).trim(); - if (parameter == 'null' && constructor.redirectedConstructor.parameters[count].type.displayName == 'T') + if (parameter == 'null' + && constructor.redirectedConstructor != null + && constructor.redirectedConstructor.parameters != null + && constructor.redirectedConstructor.parameters[count].type.displayName == 'T') { // Can't pass null to generic type in C# (you can in Dart). parameter = 'default(T)'; diff --git a/testbed/test.dart b/testbed/test.dart index 767c5a6..82ff687 100644 --- a/testbed/test.dart +++ b/testbed/test.dart @@ -1,34 +1,23 @@ - -abstract class RenderAbstractViewport extends RenderObject { - - static RenderAbstractViewport of(RenderObject object) { - return null; - } - - final double offset; - +class Widget {} +class Row { + Row( children) {} + } } -abstract class RenderViewportBase> - extends RenderBox with ContainerRenderObjectMixin - implements RenderAbstractViewport { - +class OutlineButton { + OutlineButton({Row child}); } -class DiagnosticableTreeMixin {} - -class HitTestTarget {} - -abstract class AbstractNode {} - -abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin implements HitTestTarget {} - -mixin ContainerParentDataMixin on ParentData {} - - -class RenderBox {} -class RenderSilver {} -class ParentDataClass {} -class ParentDataType {} -mixin ContainerRenderObjectMixin> on RenderObject {} - +class _OutlineButtonWithIcon extends OutlineButton { + _OutlineButtonWithIcon({@required Widget icon, + @required Widget label, + }) : super( + child: Row( + children: [ + icon, + const SizedBox(width: 8.0), + label, + ], + ), + ); +} \ No newline at end of file