122122import org .eclipse .jdt .core .dom .WhileStatement ;
123123import org .eclipse .jdt .core .dom .WildcardType ;
124124
125+ // BH 6/26/2018 -- method logging via j2s.log.methods.called and j2s.log.methods.declared
125126// BH 6/24/2018 -- synchronized(a = new Object()) {...} ---> ...; only if an assignment or not a simple function call to Object.getTreeLock()
126127// BH 6/23/2018 -- synchronized(a = new Object()) {...} ---> if(!(a = new Object()) {throw new NullPointerException()}else{...}
127128// BH 6/21/2018 -- CharSequence.subSequence() should be defined both subSequence$I$I and subSequence
@@ -257,7 +258,6 @@ private void setInnerGlobals(Java2ScriptVisitor parent, ASTNode node, String vis
257258 global_htIncludeNames = parent .global_htIncludeNames ;
258259 global_includeCount = parent .global_includeCount ;
259260 global_includes = parent .global_includes ;
260- global_j2sFlag_isDebugging = parent .global_j2sFlag_isDebugging ;
261261 global_mapBlockJavadoc = parent .global_mapBlockJavadoc ;
262262 this$0Name = parent .getQualifiedClassName ();
263263
@@ -642,6 +642,8 @@ public boolean visit(MethodDeclaration node) {
642642 // names here
643643 if (name .equals ("'main'" ))
644644 addApplication ();
645+ if (lstMethodsDeclared != null && !Modifier .isPrivate (mods ))
646+ logMethodDeclared (name );
645647 buffer .append ("\r \n Clazz.newMeth(C$, " ).append (name ).append (", function (" );
646648 @ SuppressWarnings ("unchecked" )
647649 List <ASTNode > parameters = node .parameters ();
@@ -759,8 +761,10 @@ public boolean visit(MethodInvocation node) {
759761 boolean isPrivateAndNotStatic = isPrivate && !isStatic ;
760762 Expression expression = node .getExpression ();
761763 int pt = buffer .length ();
764+ boolean doLog = (!isPrivate && htMethodsCalled != null );
762765 if (expression == null ) {
763766 // "this"
767+ doLog = false ;
764768 } else {
765769 isPrivateAndNotStatic = false ;
766770 if (expression instanceof Name ) {
@@ -772,6 +776,7 @@ public boolean visit(MethodInvocation node) {
772776 }
773777 buffer .append ("." );
774778 }
779+ int ptLog = (doLog ? buffer .length () : 0 );
775780 boolean isSpecialMethod = false ;
776781 String methodName = node .getName ().getIdentifier ();
777782 boolean isIndexOf = false ;
@@ -783,12 +788,15 @@ public boolean visit(MethodInvocation node) {
783788 buffer .setLength (pt );
784789 buffer .append (j2sName );
785790 isSpecialMethod = true ;
791+ doLog = false ;
786792 } else if (node .arguments ().size () == 0 || methodName .equals ("split" ) || methodName .equals ("replace" )) {
787793 if (j2sName .startsWith ("~" )) {
788794 buffer .append ('$' );
789795 buffer .append (j2sName .substring (1 ));
790796 isSpecialMethod = true ;
791797 } else {
798+ if (doLog && j2sName .startsWith ("C$." ))
799+ doLog = false ;
792800 buffer .append (j2sName );
793801 return false ;
794802 }
@@ -813,6 +821,10 @@ public boolean visit(MethodInvocation node) {
813821 buffer .append (qname );
814822 }
815823 }
824+ if (doLog ) {
825+ String name = className + "." + buffer .substring (ptLog );
826+ logMethodCalled (name );
827+ }
816828 if (isPrivateAndNotStatic ) {
817829 // A call to a private outer-class method from an inner class
818830 // requires
@@ -3013,6 +3025,7 @@ public boolean visit(VariableDeclarationFragment node) {
30133025 * @param isPost
30143026 * @return
30153027 */
3028+ @ SuppressWarnings ({ "null" })
30163029 private boolean addPrePost (Expression node , Expression left , String op , boolean isPost ) {
30173030 ASTNode parent = node .getParent ();
30183031 ITypeBinding leftTypeBinding = left .resolveTypeBinding ();
@@ -4689,13 +4702,54 @@ private List<Javadoc> getJ2sJavadoc(ASTNode node, boolean isPre) {
46894702 * includes @j2sDebug blocks; from j2s.compiler.mode=debug in .j2s
46904703 *
46914704 */
4692- private boolean global_j2sFlag_isDebugging = false ;
4705+ private static boolean global_j2sFlag_isDebugging = false ;
46934706
4694- public void setDebugging (boolean isDebugging ) {
4695- this . global_j2sFlag_isDebugging = isDebugging ;
4707+ public static void setDebugging (boolean isDebugging ) {
4708+ global_j2sFlag_isDebugging = isDebugging ;
46964709 }
46974710
4711+ private static List <String > lstMethodsDeclared ;
4712+
4713+ private static Map <String , String > htMethodsCalled ;
4714+
4715+ private static boolean logAllCalls ;
4716+
4717+ public static void setLogging (List <String > lstMethodsDeclared , Map <String , String > htMethodsCalled ,
4718+ boolean logAllCalls ) {
4719+ Java2ScriptVisitor .lstMethodsDeclared = lstMethodsDeclared ;
4720+ Java2ScriptVisitor .htMethodsCalled = htMethodsCalled ;
4721+ Java2ScriptVisitor .logAllCalls = logAllCalls ;
4722+ if (lstMethodsDeclared != null )
4723+ lstMethodsDeclared .clear ();
4724+ if (logAllCalls )
4725+ htMethodsCalled .clear ();
4726+ }
46984727
4728+ private void logMethodDeclared (String name ) {
4729+ if (name .startsWith ("[" )) {
4730+ String [] names = name .substring (0 , name .length () - 1 ).split ("," );
4731+ for (int i = 0 ; i < names .length ; i ++)
4732+ logMethodDeclared (names [i ]);
4733+ return ;
4734+ }
4735+ String myName = fixLogName (getQualifiedClassName ());
4736+ lstMethodsDeclared .add (myName + "." + name .substring (1 , name .length () - 1 ));
4737+ }
4738+
4739+ private void logMethodCalled (String name ) {
4740+ name = fixLogName (name );
4741+ String myName = fixLogName (getQualifiedClassName ());
4742+ if (logAllCalls )
4743+ htMethodsCalled .put (name + "," + myName , "-" );
4744+ else
4745+ htMethodsCalled .put (name , myName );
4746+ }
4747+
4748+ private String fixLogName (String name ) {
4749+ name = checkClassReplacement (name );
4750+ int pt = name .indexOf ("<" );
4751+ return (pt > 0 ? name .substring (0 , pt ) : name );
4752+ }
46994753
47004754 private static Map <String , String > htClassReplacements ;
47014755 private static List <String > lstPackageReplacements ;
@@ -5538,4 +5592,5 @@ public static void dumpStack() {
55385592 e .printStackTrace ();
55395593 }
55405594 }
5595+
55415596}
0 commit comments