Skip to content

Commit 868a486

Browse files
committed
Expanded command line options to include the ability to compare outputs to a previous run
1 parent 20e64dd commit 868a486

File tree

1 file changed

+136
-42
lines changed

1 file changed

+136
-42
lines changed

src/javaxt/utils/src/Parser.java

Lines changed: 136 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,80 @@ public class Parser {
2323
//**************************************************************************
2424
public static void main(String[] arr) throws Exception {
2525
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"));
2826

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);
2950
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+
}
3163
}
3264
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+
}
34100
}
35101
}
36102

@@ -886,7 +952,7 @@ private static Comment parseComment(String comment){
886952
*/
887953
private static ArrayList<Class> getClasses(String s){
888954
ArrayList<Class> classes = new ArrayList<>();
889-
955+
ArrayList<JSONObject> orphanedFunctions = new ArrayList<>();
890956

891957
int i=0;
892958
Word word, p1 = null, p2 = null;
@@ -952,6 +1018,11 @@ private static ArrayList<Class> getClasses(String s){
9521018
}
9531019

9541020
}
1021+
else{
1022+
1023+
//TODO: add static functions to anonymous class (e.g. Utils.js)
1024+
1025+
}
9551026
}
9561027

9571028
i = end+1;
@@ -1394,89 +1465,91 @@ private static int getDefaultValue(int offset, Word nextWord, Config config, Str
13941465
/** Used to display all the classes, methods and properties found in a given
13951466
* file
13961467
*/
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();
13981471
ArrayList<Class> classes = new Parser(input).getClasses();
1399-
//if (true) return;
14001472
for (Class cls : classes){
14011473
String className = cls.getName();
14021474
String namespace = cls.getNamespace();
14031475
boolean isInterface = cls.isInterface();
14041476
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("-----------------------------------");
14081480
String description = cls.getDescription();
1409-
if (description!=null) System.out.println(description);
1481+
if (description!=null) printer.println(description);
14101482

14111483
ArrayList<String> extensions = cls.getSuper();
14121484
if (!extensions.isEmpty()){
1413-
System.out.print("\r\nExtends");
1485+
printer.print("\r\nExtends");
14141486
for (String ext : extensions){
1415-
System.out.print(" " + ext);
1487+
printer.print(" " + ext);
14161488
}
1417-
System.out.println("\r\n");
1489+
printer.println("\r\n");
14181490
}
14191491

14201492

14211493
ArrayList<Constructor> contructors = cls.getConstructors();
14221494
if (!contructors.isEmpty()){
1423-
System.out.println("\r\n## Constructors: ");
1495+
printer.println("\r\n## Constructors: ");
14241496
for (Constructor c : contructors){
1425-
printMethod(c);
1497+
printMethod(c, printer);
14261498
}
14271499
}
14281500

14291501

14301502
ArrayList<Config> config = cls.getConfig();
14311503
if (!config.isEmpty()){
1432-
System.out.println("\r\n## Config: ");
1504+
printer.println("\r\n## Config: ");
14331505
for (Config c : config){
1434-
printConfig(c);
1506+
printConfig(c, printer);
14351507
}
14361508
}
14371509

14381510

14391511
ArrayList<Property> properties = cls.getProperties();
14401512
if (!properties.isEmpty()){
1441-
System.out.println("\r\n## Properties: ");
1513+
printer.println("\r\n## Properties: ");
14421514
for (Property p : properties){
14431515
if (p.isPublic()){
1444-
printProperty(p);
1516+
printProperty(p, printer);
14451517
}
14461518
}
14471519
}
14481520

14491521

14501522
ArrayList<Method> methods = cls.getMethods();
14511523
if (!methods.isEmpty()){
1452-
System.out.println("\r\n## Methods: ");
1524+
printer.println("\r\n## Methods: ");
14531525
for (Method m : methods){
14541526
if (m.isPublic()){
1455-
printMethod(m);
1527+
printMethod(m, printer);
14561528
}
14571529
}
14581530
}
14591531

14601532

14611533
for (Class c : cls.getClasses()){
14621534
if (c.isPublic()){
1463-
console.log(" +" + c.getName());
1535+
printer.println(" +" + c.getName());
14641536
}
14651537
}
14661538

14671539

1468-
System.out.println("-----------------------------------");
1469-
System.out.println("\r\n");
1540+
printer.println("-----------------------------------");
1541+
printer.println("\r\n");
14701542

14711543
}
14721544

1545+
return printer.toString();
14731546
}
14741547

14751548

14761549
//**************************************************************************
14771550
//** printMethod
14781551
//**************************************************************************
1479-
private static void printMethod(Method m){
1552+
private static void printMethod(Method m, Printer printer){
14801553
String methodName = m.getName();
14811554
String returnType = m.getReturnType();
14821555

@@ -1493,29 +1566,29 @@ private static void printMethod(Method m){
14931566
}
14941567

14951568

1496-
System.out.println("\r\n+ " + methodName + "(" + params + ")");
1569+
printer.println("\r\n+ " + methodName + "(" + params + ")");
14971570
String description = m.getDescription();
14981571
if (description!=null){
1499-
System.out.println("\r\n - Description:\r\n " + description);
1572+
printer.println("\r\n - Description:\r\n " + description);
15001573
}
15011574

15021575

15031576
if (!parameters.isEmpty()){
1504-
System.out.println("\r\n - Parameters: ");
1577+
printer.println("\r\n - Parameters: ");
15051578
for (Parameter p : parameters){
15061579
String t = p.getType();
15071580
String d = p.getDescription();
15081581
String param = p.getName();
15091582
if (t!=null) param += " (" + p.getType() + ")";
15101583
if (d!=null) param += ": " + d;
15111584

1512-
System.out.println(" * " + param);
1585+
printer.println(" * " + param);
15131586
}
15141587
}
15151588

15161589
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);
15191592

15201593
}
15211594
}
@@ -1524,26 +1597,26 @@ private static void printMethod(Method m){
15241597
//**************************************************************************
15251598
//** printProperty
15261599
//**************************************************************************
1527-
private static void printProperty(Property property){
1600+
private static void printProperty(Property property, Printer printer){
15281601
String name = property.getName();
15291602
String description = property.getDescription();
15301603
String defaultValue = property.getDefaultValue();
15311604

15321605

1533-
System.out.println("\r\n+ " + name);
1606+
printer.println("\r\n+ " + name);
15341607
if (description!=null){
1535-
System.out.println("\r\n - Description:\r\n " + description);
1608+
printer.println("\r\n - Description:\r\n " + description);
15361609
}
15371610

15381611

1539-
System.out.println("\r\n - Default:\r\n " + defaultValue);
1612+
printer.println("\r\n - Default:\r\n " + defaultValue);
15401613
}
15411614

15421615

15431616
//**************************************************************************
15441617
//** printConfig
15451618
//**************************************************************************
1546-
private static void printConfig(Config config){
1619+
private static void printConfig(Config config, Printer printer){
15471620
String name = config.getName();
15481621
String description = config.getDescription();
15491622
String defaultValue = config.getDefaultValue();
@@ -1553,26 +1626,47 @@ private static void printConfig(Config config){
15531626

15541627

15551628

1556-
System.out.println("\r\n+ " + name);
1629+
printer.println("\r\n+ " + name);
15571630
if (description!=null){
1558-
System.out.println("\r\n - Description:\r\n " + description);
1631+
printer.println("\r\n - Description:\r\n " + description);
15591632
}
15601633

15611634
if (defaultValue!=null){
1562-
System.out.println("\r\n - Default:\r\n " + defaultValue);
1635+
printer.println("\r\n - Default:\r\n " + defaultValue);
15631636
}
15641637
else{
15651638
for (Config c : arr){
15661639
description = config.getDescription();
1567-
System.out.println("\r\n + " + c.getName());
1640+
printer.println("\r\n + " + c.getName());
15681641
if (description!=null){
1569-
System.out.println("\r\n - Description:\r\n " + description);
1642+
printer.println("\r\n - Description:\r\n " + description);
15701643
}
15711644
}
15721645
}
15731646
}
15741647

15751648

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+
15761670
//**************************************************************************
15771671
//** Word Class
15781672
//**************************************************************************

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy