OLD | NEW |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library servicec.plugins.cc; | 5 library servicec.plugins.cc; |
6 | 6 |
7 import 'dart:core' hide Type; | 7 import 'dart:core' hide Type; |
8 import 'dart:io' show Platform, File; | 8 import 'dart:io' show Platform, File; |
9 | 9 |
10 import 'package:strings/strings.dart' as strings; | 10 import 'package:strings/strings.dart' as strings; |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 static _JavaActionWriter fromMethod(Method method) { | 236 static _JavaActionWriter fromMethod(Method method) { |
237 return new _JavaActionWriter( | 237 return new _JavaActionWriter( |
238 method, | 238 method, |
239 method.arguments.map((f) => f.type).toList(), | 239 method.arguments.map((f) => f.type).toList(), |
240 method.arguments.map((f) => f.name).toList()); | 240 method.arguments.map((f) => f.name).toList()); |
241 } | 241 } |
242 | 242 |
243 writeTo(String outputDirectory) { | 243 writeTo(String outputDirectory) { |
244 bool boxedArguments = types.any((t) => t.isString); | 244 bool boxedArguments = types.any((t) => t.isString); |
245 writeHeader([ | 245 writeHeader([ |
246 'fletch.ImmiServiceLayer', | 246 'dartino.ImmiServiceLayer', |
247 ]); | 247 ]); |
248 writeln('public final class $className implements Action {'); | 248 writeln('public final class $className implements Action {'); |
249 writeln(); | 249 writeln(); |
250 writeln(' // Public interface.'); | 250 writeln(' // Public interface.'); |
251 writeln(); | 251 writeln(); |
252 writeln(' public void dispatch($actionFormals) {'); | 252 writeln(' public void dispatch($actionFormals) {'); |
253 writeln(' root.dispatch(new Runnable() {'); | 253 writeln(' root.dispatch(new Runnable() {'); |
254 writeln(' @Override'); | 254 writeln(' @Override'); |
255 writeln(' public void run() {'); | 255 writeln(' public void run() {'); |
256 if (boxedArguments) { | 256 if (boxedArguments) { |
257 String builder = actionArgsBuilder; | 257 String builder = actionArgsBuilder; |
258 imports.add('fletch.MessageBuilder'); | 258 imports.add('dartino.MessageBuilder'); |
259 imports.add('fletch.$builder'); | 259 imports.add('dartino.$builder'); |
260 writeln(' int space = 48 + $builder.kSize;'); | 260 writeln(' int space = 48 + $builder.kSize;'); |
261 for (int i = 0; i < types.length; ++i) { | 261 for (int i = 0; i < types.length; ++i) { |
262 if (types[i].isString) { | 262 if (types[i].isString) { |
263 writeln(' space += ${arguments[i]}.length();'); | 263 writeln(' space += ${arguments[i]}.length();'); |
264 } | 264 } |
265 } | 265 } |
266 writeln(' MessageBuilder message = new MessageBuilder(space);'); | 266 writeln(' MessageBuilder message = new MessageBuilder(space);'); |
267 writeln(' $builder args = new $builder();'); | 267 writeln(' $builder args = new $builder();'); |
268 writeln(' message.initRoot(args, $builder.kSize);'); | 268 writeln(' message.initRoot(args, $builder.kSize);'); |
269 writeln(' args.setId(id);'); | 269 writeln(' args.setId(id);'); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 | 356 |
357 _JavaNodeWriter(Struct node) | 357 _JavaNodeWriter(Struct node) |
358 : super(node.name, '${node.name}Node') { | 358 : super(node.name, '${node.name}Node') { |
359 visitStruct(node); | 359 visitStruct(node); |
360 } | 360 } |
361 | 361 |
362 visitStruct(Struct node) { | 362 visitStruct(Struct node) { |
363 this.node = node; | 363 this.node = node; |
364 actions = node.methods.map(_JavaActionWriter.fromMethod); | 364 actions = node.methods.map(_JavaActionWriter.fromMethod); |
365 writeHeader([ | 365 writeHeader([ |
366 'fletch.${nodeName}Data', | 366 'dartino.${nodeName}Data', |
367 ]); | 367 ]); |
368 writeln('public final class $nodeName implements Node {'); | 368 writeln('public final class $nodeName implements Node {'); |
369 writeln(); | 369 writeln(); |
370 writeln(' // Public interface.'); | 370 writeln(' // Public interface.'); |
371 writeln(); | 371 writeln(); |
372 forEachSlot(node, null, writeFieldGetter); | 372 forEachSlot(node, null, writeFieldGetter); |
373 actions.forEach(writeActionGetter); | 373 actions.forEach(writeActionGetter); |
374 writeln(); | 374 writeln(); |
375 writeln(' // Package private implementation.'); | 375 writeln(' // Package private implementation.'); |
376 writeln(); | 376 writeln(); |
(...skipping 29 matching lines...) Expand all Loading... |
406 String typeName = getTypeName(type); | 406 String typeName = getTypeName(type); |
407 writeln(' private $typeName $name;'); | 407 writeln(' private $typeName $name;'); |
408 } | 408 } |
409 | 409 |
410 writeFieldInitializationFromData(Type type, String name) { | 410 writeFieldInitializationFromData(Type type, String name) { |
411 String camelName = camelize(name); | 411 String camelName = camelize(name); |
412 String typeName = getTypeName(type); | 412 String typeName = getTypeName(type); |
413 if (type.isList) { | 413 if (type.isList) { |
414 String typeName = getNonListTypeName(type); | 414 String typeName = getNonListTypeName(type); |
415 String dataName = getNodeDataTypeName(type); | 415 String dataName = getNodeDataTypeName(type); |
416 imports.add('fletch.$dataName'); | 416 imports.add('dartino.$dataName'); |
417 imports.add('java.util.Collections'); | 417 imports.add('java.util.Collections'); |
418 imports.add('java.util.ArrayList'); | 418 imports.add('java.util.ArrayList'); |
419 writeln(' {'); | 419 writeln(' {'); |
420 writeln(' $dataName dataList = data.get$camelName();'); | 420 writeln(' $dataName dataList = data.get$camelName();'); |
421 writeln(' int length = dataList.size();'); | 421 writeln(' int length = dataList.size();'); |
422 writeln(' List<$typeName> list = new ArrayList<$typeName>(length);'); | 422 writeln(' List<$typeName> list = new ArrayList<$typeName>(length);'); |
423 writeln(' for (int i = 0; i < length; ++i) {'); | 423 writeln(' for (int i = 0; i < length; ++i) {'); |
424 writeln(' list.add(new $typeName(dataList.get(i), root));'); | 424 writeln(' list.add(new $typeName(dataList.get(i), root));'); |
425 writeln(' }'); | 425 writeln(' }'); |
426 writeln(' $name = Collections.unmodifiableList(list);'); | 426 writeln(' $name = Collections.unmodifiableList(list);'); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 | 467 |
468 _JavaNodePatchWriter(Struct node) | 468 _JavaNodePatchWriter(Struct node) |
469 : super(node.name, '${node.name}Patch') { | 469 : super(node.name, '${node.name}Patch') { |
470 visitStruct(node); | 470 visitStruct(node); |
471 } | 471 } |
472 | 472 |
473 visitStruct(Struct node) { | 473 visitStruct(Struct node) { |
474 this.node = node; | 474 this.node = node; |
475 actions = node.methods.map(_JavaActionWriter.fromMethod); | 475 actions = node.methods.map(_JavaActionWriter.fromMethod); |
476 writeHeader([ | 476 writeHeader([ |
477 'fletch.${patchName}Data', | 477 'dartino.${patchName}Data', |
478 'fletch.${node.name}UpdateData', | 478 'dartino.${node.name}UpdateData', |
479 'fletch.${node.name}UpdateDataList', | 479 'dartino.${node.name}UpdateDataList', |
480 'java.util.List', | 480 'java.util.List', |
481 ]); | 481 ]); |
482 write('public final class $patchName'); | 482 write('public final class $patchName'); |
483 writeln(' implements NodePatch<$nodeName, $presenterName> {'); | 483 writeln(' implements NodePatch<$nodeName, $presenterName> {'); |
484 writeln(); | 484 writeln(); |
485 writeln(' // Public interface.'); | 485 writeln(' // Public interface.'); |
486 writeln(); | 486 writeln(); |
487 writeln(' @Override'); | 487 writeln(' @Override'); |
488 write(' public boolean hasChanged()'); | 488 write(' public boolean hasChanged()'); |
489 writeln(' { return type != PatchType.IdentityNodePatch; }'); | 489 writeln(' { return type != PatchType.IdentityNodePatch; }'); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 writeln(' }'); | 611 writeln(' }'); |
612 } | 612 } |
613 } | 613 } |
614 | 614 |
615 class _AnyNodeWriter extends _JavaNodeBaseWriter { | 615 class _AnyNodeWriter extends _JavaNodeBaseWriter { |
616 final String nodeName = 'AnyNode'; | 616 final String nodeName = 'AnyNode'; |
617 | 617 |
618 _AnyNodeWriter(Map units) | 618 _AnyNodeWriter(Map units) |
619 : super('AnyNode', 'AnyNode') { | 619 : super('AnyNode', 'AnyNode') { |
620 writeHeader([ | 620 writeHeader([ |
621 'fletch.NodeData', | 621 'dartino.NodeData', |
622 ]); | 622 ]); |
623 writeln('public final class $nodeName implements Node {'); | 623 writeln('public final class $nodeName implements Node {'); |
624 writeln(); | 624 writeln(); |
625 writeln(' // Public interface.'); | 625 writeln(' // Public interface.'); |
626 writeln(); | 626 writeln(); |
627 writeln(' public boolean is(java.lang.Class clazz) {'); | 627 writeln(' public boolean is(java.lang.Class clazz) {'); |
628 writeln(' return clazz.isInstance(node);'); | 628 writeln(' return clazz.isInstance(node);'); |
629 writeln(' }'); | 629 writeln(' }'); |
630 writeln(' public <T> T as(java.lang.Class<T> clazz) {'); | 630 writeln(' public <T> T as(java.lang.Class<T> clazz) {'); |
631 writeln(' return clazz.cast(node);'); | 631 writeln(' return clazz.cast(node);'); |
(...skipping 29 matching lines...) Expand all Loading... |
661 writeln(' return new ${node.name}Node(data.get${node.name}(), root);'); | 661 writeln(' return new ${node.name}Node(data.get${node.name}(), root);'); |
662 } | 662 } |
663 } | 663 } |
664 | 664 |
665 class _AnyNodePatchWriter extends _JavaNodeBaseWriter { | 665 class _AnyNodePatchWriter extends _JavaNodeBaseWriter { |
666 final String nodeName = 'AnyNode'; | 666 final String nodeName = 'AnyNode'; |
667 | 667 |
668 _AnyNodePatchWriter(Map units) | 668 _AnyNodePatchWriter(Map units) |
669 : super('AnyNode', 'AnyNodePatch') { | 669 : super('AnyNode', 'AnyNodePatch') { |
670 writeHeader([ | 670 writeHeader([ |
671 'fletch.NodePatchData', | 671 'dartino.NodePatchData', |
672 ]); | 672 ]); |
673 write('public final class $patchName'); | 673 write('public final class $patchName'); |
674 writeln(' implements NodePatch<$nodeName, $presenterName> {'); | 674 writeln(' implements NodePatch<$nodeName, $presenterName> {'); |
675 writeln(); | 675 writeln(); |
676 writeln(' // Public interface.'); | 676 writeln(' // Public interface.'); |
677 writeln(); | 677 writeln(); |
678 writeln(' @Override'); | 678 writeln(' @Override'); |
679 write(' public boolean hasChanged()'); | 679 write(' public boolean hasChanged()'); |
680 writeln(' { return patch != null; }'); | 680 writeln(' { return patch != null; }'); |
681 writeln(' @Override'); | 681 writeln(' @Override'); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 writeln(' if (data.is$name()) {'); | 751 writeln(' if (data.is$name()) {'); |
752 writeln(' $nodeName typedPrevious = null;'); | 752 writeln(' $nodeName typedPrevious = null;'); |
753 writeln(' if (previous instanceof $nodeName) {'); | 753 writeln(' if (previous instanceof $nodeName) {'); |
754 writeln(' typedPrevious = ($nodeName)previous;'); | 754 writeln(' typedPrevious = ($nodeName)previous;'); |
755 writeln(' }'); | 755 writeln(' }'); |
756 writeln(' return new $patchName('); | 756 writeln(' return new $patchName('); |
757 writeln(' data.get$name(), typedPrevious, root);'); | 757 writeln(' data.get$name(), typedPrevious, root);'); |
758 writeln(' }'); | 758 writeln(' }'); |
759 } | 759 } |
760 } | 760 } |
OLD | NEW |