@@ -23,14 +23,80 @@ public class Parser {
23
23
//**************************************************************************
24
24
public static void main (String [] arr ) throws Exception {
25
25
HashMap <String , String > args = console .parseArgs (arr );
26
- java .io .File input = new java .io .File (args .get ("-input" ));
27
- //java.io.File output = new java.io.File(args.get("-output"));
28
26
27
+ //Get input file or directory
28
+ String path = args .get ("-input" );
29
+ if (path ==null ){
30
+ if (arr .length >0 ){
31
+ path = arr [0 ];
32
+ }
33
+ else {
34
+ System .out .println ("-input file or directory is required" );
35
+ return ;
36
+ }
37
+ }
38
+
39
+
40
+
41
+ //Get test file as needed
42
+ String expectedOutput = null ;
43
+ String test = args .get ("-test" );
44
+ if (test !=null ) expectedOutput = new javaxt .io .File (test ).getText ();
45
+
46
+
47
+
48
+ //Generate output
49
+ java .io .File input = new java .io .File (path );
29
50
if (input .isFile ()){
30
- print (new javaxt .io .File (input ));
51
+ String output = parse (new javaxt .io .File (input ));
52
+ if (expectedOutput ==null ){
53
+ System .out .print (output );
54
+ }
55
+ else {
56
+ if (output .equals (expectedOutput )){
57
+ System .out .println (input + " [PASS]" );
58
+ }
59
+ else {
60
+ System .out .println (input + " [FAILED] <------" );
61
+ }
62
+ }
31
63
}
32
64
else {
33
-
65
+ String [] filter = new String []{"*.js" , "*.java" };
66
+ for (javaxt .io .File file : new javaxt .io .Directory (input ).getFiles (filter , true )){
67
+ String output = parse (file );
68
+ if (expectedOutput ==null ){
69
+ System .out .print (output );
70
+ }
71
+ else {
72
+ String t = expectedOutput .substring (0 , output .length ());
73
+ if (t .equals (output )){
74
+ System .out .println (file + " [PASS]" );
75
+ expectedOutput = expectedOutput .substring (output .length ());
76
+ }
77
+ else {
78
+ System .out .println (file + " [FAILED] <------" );
79
+ for (int i =0 ; i <output .length (); i ++){
80
+ char a = output .charAt (i );
81
+ char b = expectedOutput .charAt (i );
82
+ if (a !=b ){
83
+ int start = i -50 ;
84
+ if (start <0 ) start = 0 ;
85
+ int end = Math .min (i + 50 , output .length ());
86
+ //, expectedOutput.length()
87
+
88
+
89
+ System .out .println (output .substring (start , i ) + "|" + output .substring (i , end ));
90
+ System .out .println ("--------------------------------------------" );
91
+ System .out .println (expectedOutput .substring (start , i ) + "|" + expectedOutput .substring (i , end ));
92
+
93
+ break ;
94
+ }
95
+ }
96
+ break ;
97
+ }
98
+ }
99
+ }
34
100
}
35
101
}
36
102
@@ -886,7 +952,7 @@ private static Comment parseComment(String comment){
886
952
*/
887
953
private static ArrayList <Class > getClasses (String s ){
888
954
ArrayList <Class > classes = new ArrayList <>();
889
-
955
+ ArrayList < JSONObject > orphanedFunctions = new ArrayList <>();
890
956
891
957
int i =0 ;
892
958
Word word , p1 = null , p2 = null ;
@@ -952,6 +1018,11 @@ private static ArrayList<Class> getClasses(String s){
952
1018
}
953
1019
954
1020
}
1021
+ else {
1022
+
1023
+ //TODO: add static functions to anonymous class (e.g. Utils.js)
1024
+
1025
+ }
955
1026
}
956
1027
957
1028
i = end +1 ;
@@ -1394,89 +1465,91 @@ private static int getDefaultValue(int offset, Word nextWord, Config config, Str
1394
1465
/** Used to display all the classes, methods and properties found in a given
1395
1466
* file
1396
1467
*/
1397
- private static void print (javaxt .io .File input ) throws Exception {
1468
+ private static String parse (javaxt .io .File input ) throws Exception {
1469
+
1470
+ Printer printer = new Printer ();
1398
1471
ArrayList <Class > classes = new Parser (input ).getClasses ();
1399
- //if (true) return;
1400
1472
for (Class cls : classes ){
1401
1473
String className = cls .getName ();
1402
1474
String namespace = cls .getNamespace ();
1403
1475
boolean isInterface = cls .isInterface ();
1404
1476
if (namespace !=null ) className = namespace + "." + className ;
1405
- System . out .println ("-----------------------------------" );
1406
- System . out .println ("- " + className + (isInterface ? " (Interface)" : "" ));
1407
- System . out .println ("-----------------------------------" );
1477
+ printer .println ("-----------------------------------" );
1478
+ printer .println ("- " + className + (isInterface ? " (Interface)" : "" ));
1479
+ printer .println ("-----------------------------------" );
1408
1480
String description = cls .getDescription ();
1409
- if (description !=null ) System . out .println (description );
1481
+ if (description !=null ) printer .println (description );
1410
1482
1411
1483
ArrayList <String > extensions = cls .getSuper ();
1412
1484
if (!extensions .isEmpty ()){
1413
- System . out .print ("\r \n Extends" );
1485
+ printer .print ("\r \n Extends" );
1414
1486
for (String ext : extensions ){
1415
- System . out .print (" " + ext );
1487
+ printer .print (" " + ext );
1416
1488
}
1417
- System . out .println ("\r \n " );
1489
+ printer .println ("\r \n " );
1418
1490
}
1419
1491
1420
1492
1421
1493
ArrayList <Constructor > contructors = cls .getConstructors ();
1422
1494
if (!contructors .isEmpty ()){
1423
- System . out .println ("\r \n ## Constructors: " );
1495
+ printer .println ("\r \n ## Constructors: " );
1424
1496
for (Constructor c : contructors ){
1425
- printMethod (c );
1497
+ printMethod (c , printer );
1426
1498
}
1427
1499
}
1428
1500
1429
1501
1430
1502
ArrayList <Config > config = cls .getConfig ();
1431
1503
if (!config .isEmpty ()){
1432
- System . out .println ("\r \n ## Config: " );
1504
+ printer .println ("\r \n ## Config: " );
1433
1505
for (Config c : config ){
1434
- printConfig (c );
1506
+ printConfig (c , printer );
1435
1507
}
1436
1508
}
1437
1509
1438
1510
1439
1511
ArrayList <Property > properties = cls .getProperties ();
1440
1512
if (!properties .isEmpty ()){
1441
- System . out .println ("\r \n ## Properties: " );
1513
+ printer .println ("\r \n ## Properties: " );
1442
1514
for (Property p : properties ){
1443
1515
if (p .isPublic ()){
1444
- printProperty (p );
1516
+ printProperty (p , printer );
1445
1517
}
1446
1518
}
1447
1519
}
1448
1520
1449
1521
1450
1522
ArrayList <Method > methods = cls .getMethods ();
1451
1523
if (!methods .isEmpty ()){
1452
- System . out .println ("\r \n ## Methods: " );
1524
+ printer .println ("\r \n ## Methods: " );
1453
1525
for (Method m : methods ){
1454
1526
if (m .isPublic ()){
1455
- printMethod (m );
1527
+ printMethod (m , printer );
1456
1528
}
1457
1529
}
1458
1530
}
1459
1531
1460
1532
1461
1533
for (Class c : cls .getClasses ()){
1462
1534
if (c .isPublic ()){
1463
- console . log (" +" + c .getName ());
1535
+ printer . println (" +" + c .getName ());
1464
1536
}
1465
1537
}
1466
1538
1467
1539
1468
- System . out .println ("-----------------------------------" );
1469
- System . out .println ("\r \n " );
1540
+ printer .println ("-----------------------------------" );
1541
+ printer .println ("\r \n " );
1470
1542
1471
1543
}
1472
1544
1545
+ return printer .toString ();
1473
1546
}
1474
1547
1475
1548
1476
1549
//**************************************************************************
1477
1550
//** printMethod
1478
1551
//**************************************************************************
1479
- private static void printMethod (Method m ){
1552
+ private static void printMethod (Method m , Printer printer ){
1480
1553
String methodName = m .getName ();
1481
1554
String returnType = m .getReturnType ();
1482
1555
@@ -1493,29 +1566,29 @@ private static void printMethod(Method m){
1493
1566
}
1494
1567
1495
1568
1496
- System . out .println ("\r \n + " + methodName + "(" + params + ")" );
1569
+ printer .println ("\r \n + " + methodName + "(" + params + ")" );
1497
1570
String description = m .getDescription ();
1498
1571
if (description !=null ){
1499
- System . out .println ("\r \n - Description:\r \n " + description );
1572
+ printer .println ("\r \n - Description:\r \n " + description );
1500
1573
}
1501
1574
1502
1575
1503
1576
if (!parameters .isEmpty ()){
1504
- System . out .println ("\r \n - Parameters: " );
1577
+ printer .println ("\r \n - Parameters: " );
1505
1578
for (Parameter p : parameters ){
1506
1579
String t = p .getType ();
1507
1580
String d = p .getDescription ();
1508
1581
String param = p .getName ();
1509
1582
if (t !=null ) param += " (" + p .getType () + ")" ;
1510
1583
if (d !=null ) param += ": " + d ;
1511
1584
1512
- System . out .println (" * " + param );
1585
+ printer .println (" * " + param );
1513
1586
}
1514
1587
}
1515
1588
1516
1589
if (returnType !=null ){
1517
- System . out .println ("\r \n - Returns:" );
1518
- System . out .println (" " + returnType );
1590
+ printer .println ("\r \n - Returns:" );
1591
+ printer .println (" " + returnType );
1519
1592
1520
1593
}
1521
1594
}
@@ -1524,26 +1597,26 @@ private static void printMethod(Method m){
1524
1597
//**************************************************************************
1525
1598
//** printProperty
1526
1599
//**************************************************************************
1527
- private static void printProperty (Property property ){
1600
+ private static void printProperty (Property property , Printer printer ){
1528
1601
String name = property .getName ();
1529
1602
String description = property .getDescription ();
1530
1603
String defaultValue = property .getDefaultValue ();
1531
1604
1532
1605
1533
- System . out .println ("\r \n + " + name );
1606
+ printer .println ("\r \n + " + name );
1534
1607
if (description !=null ){
1535
- System . out .println ("\r \n - Description:\r \n " + description );
1608
+ printer .println ("\r \n - Description:\r \n " + description );
1536
1609
}
1537
1610
1538
1611
1539
- System . out .println ("\r \n - Default:\r \n " + defaultValue );
1612
+ printer .println ("\r \n - Default:\r \n " + defaultValue );
1540
1613
}
1541
1614
1542
1615
1543
1616
//**************************************************************************
1544
1617
//** printConfig
1545
1618
//**************************************************************************
1546
- private static void printConfig (Config config ){
1619
+ private static void printConfig (Config config , Printer printer ){
1547
1620
String name = config .getName ();
1548
1621
String description = config .getDescription ();
1549
1622
String defaultValue = config .getDefaultValue ();
@@ -1553,26 +1626,47 @@ private static void printConfig(Config config){
1553
1626
1554
1627
1555
1628
1556
- System . out .println ("\r \n + " + name );
1629
+ printer .println ("\r \n + " + name );
1557
1630
if (description !=null ){
1558
- System . out .println ("\r \n - Description:\r \n " + description );
1631
+ printer .println ("\r \n - Description:\r \n " + description );
1559
1632
}
1560
1633
1561
1634
if (defaultValue !=null ){
1562
- System . out .println ("\r \n - Default:\r \n " + defaultValue );
1635
+ printer .println ("\r \n - Default:\r \n " + defaultValue );
1563
1636
}
1564
1637
else {
1565
1638
for (Config c : arr ){
1566
1639
description = config .getDescription ();
1567
- System . out .println ("\r \n + " + c .getName ());
1640
+ printer .println ("\r \n + " + c .getName ());
1568
1641
if (description !=null ){
1569
- System . out .println ("\r \n - Description:\r \n " + description );
1642
+ printer .println ("\r \n - Description:\r \n " + description );
1570
1643
}
1571
1644
}
1572
1645
}
1573
1646
}
1574
1647
1575
1648
1649
+ //**************************************************************************
1650
+ //** Printer Class
1651
+ //**************************************************************************
1652
+ private static class Printer {
1653
+ private StringBuilder out ;
1654
+ public Printer (){
1655
+ out = new StringBuilder ();
1656
+ }
1657
+ public void println (String line ){
1658
+ out .append (line );
1659
+ out .append ("\r \n " );
1660
+ }
1661
+ public void print (String line ){
1662
+ out .append (line );
1663
+ }
1664
+ public String toString (){
1665
+ return out .toString ();
1666
+ }
1667
+ }
1668
+
1669
+
1576
1670
//**************************************************************************
1577
1671
//** Word Class
1578
1672
//**************************************************************************
0 commit comments