Skip to content
This repository has been archived by the owner on Nov 29, 2020. It is now read-only.

Commit

Permalink
Base constructor call fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adamped committed Jan 2, 2019
1 parent cdb5580 commit d9899b5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 42 deletions.
11 changes: 6 additions & 5 deletions AST/implementation/literals.dart
Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions AST/naming.dart
Expand Up @@ -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<String>();
for (var argument in type.typeArguments) {
typeArguments.add(Types.getDartTypeName(argument));
Expand Down
23 changes: 16 additions & 7 deletions AST/signature/constructors.dart
Expand Up @@ -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
Expand All @@ -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();';
}

Expand All @@ -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) {
Expand All @@ -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)';
Expand Down
49 changes: 19 additions & 30 deletions 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(<Widget> children) {}
}
}

abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMixin<RenderSliver>>
extends RenderBox with ContainerRenderObjectMixin<RenderSliver, ParentDataClass>
implements RenderAbstractViewport {

class OutlineButton {
OutlineButton({Row child});
}

class DiagnosticableTreeMixin {}

class HitTestTarget {}

abstract class AbstractNode<T> {}

abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin implements HitTestTarget {}

mixin ContainerParentDataMixin<ChildType extends RenderObject> on ParentData {}


class RenderBox {}
class RenderSilver {}
class ParentDataClass {}
class ParentDataType {}
mixin ContainerRenderObjectMixin<ChildType extends RenderObject, ParentDataType extends ContainerParentDataMixin<ChildType>> on RenderObject {}

class _OutlineButtonWithIcon extends OutlineButton {
_OutlineButtonWithIcon({@required Widget icon,
@required Widget label,
}) : super(
child: Row(
children: <Widget>[
icon,
const SizedBox(width: 8.0),
label,
],
),
);
}

0 comments on commit d9899b5

Please sign in to comment.