@@ -53,7 +53,7 @@ public String mangleScriptName(final SourceFile sourceFile) {
5353 }
5454
5555 public String mangleScriptBodyMethod (final int methodsAmount ) {
56- return "script- body" + (methodsAmount == 0 ? "" : ('- ' + Integer .toString (methodsAmount )));
56+ return "$ body" + (methodsAmount == 0 ? "" : ('$ ' + Integer .toString (methodsAmount )));
5757 }
5858
5959 public String mangleSourceFileName (final HighLevelDefinition definition ) {
@@ -116,40 +116,41 @@ public int hashCode() {
116116 return builder .toString ();
117117 }
118118
119- public String mangleGeneratedLambdaName ( final String interfaceName ) {
119+ public String mangleLambdaMethod ( final String parentMethodName , final String interfaceName ) {
120120 final class LambdaId {
121- final String target ;
121+ final String interfaceName ;
122+ final String method ;
122123
123- LambdaId (final String target ) {
124- this .target = target ;
124+ LambdaId (final String interfaceName , final String method ) {
125+ this .interfaceName = interfaceName ;
126+ this .method = method ;
125127 }
126128
127129 @ Override
128130 public boolean equals (final Object o ) {
129- return this == o || o instanceof LambdaId && this .target .equals (((LambdaId ) o ).target );
131+ return this == o || o instanceof LambdaId && this .interfaceName .equals (((LambdaId ) o ).interfaceName ) && this . method . equals ((( LambdaId ) o ). method );
130132 }
131133
132134 @ Override
133135 public int hashCode () {
134- return 17 * this .target .hashCode ();
136+ return 17 * ( this .interfaceName .hashCode () + 31 * this . method . hashCode () );
135137 }
136138 }
137139
138- final String interfaceTarget = interfaceName .replace ('/' , '_' ).replace ('.' , '_' );
139- // TODO("Rework package structure")
140- return "zsynthetic/$Lambda$" + interfaceTarget + '$' + this .mangleCounters .get (new LambdaId (interfaceTarget ));
141- }
142-
143- public String mangleGeneratedLambdaName (final FunctionHeader header ) {
144- return this .mangleGeneratedLambdaName ("$Generated" + EXP_TAR_MANGLE_FUNCTION_ID + this .encodeLengthNameFormat (this .mangleFunctionHeader (header )));
145- }
146-
147- public String mangleCapturedParameter (final int parameterId , final boolean isThis ) {
148- if (isThis ) {
149- return "$this" ;
140+ final String sanitizedMethodName ;
141+ if (parentMethodName == null ) {
142+ sanitizedMethodName = "$null" ;
143+ } else if ("<init>" .equals (parentMethodName ) || "<clinit>" .equals (parentMethodName )) {
144+ sanitizedMethodName = "$_" + parentMethodName .substring (1 , parentMethodName .length () - 1 ) + '_' ;
150145 } else {
151- return "$" + parameterId ;
146+ sanitizedMethodName = parentMethodName ;
152147 }
148+ final String interfaceTarget = interfaceName .replace ('/' , '.' );
149+ final int lastDot = interfaceTarget .lastIndexOf ('.' );
150+ final String canonicalInterfaceTarget = lastDot == -1 ? interfaceTarget : interfaceTarget .substring (lastDot + 1 );
151+ final LambdaId id = new LambdaId (canonicalInterfaceTarget , sanitizedMethodName );
152+
153+ return "$lambda$" + sanitizedMethodName + '$' + canonicalInterfaceTarget + '$' + this .mangleCounters .get (id );
153154 }
154155
155156 private String mangleScriptName (final String rawName ) {
0 commit comments