Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jamie Mansfield
asm
Commits
2db91a42
Unverified
Commit
2db91a42
authored
Aug 19, 2018
by
Jamie Mansfield
Browse files
Actually remap inner class names
parent
63253d4a
Pipeline
#2604
passed with stage
in 7 minutes
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
asm-commons/src/main/java/org/objectweb/asm/commons/ClassRemapper.java
View file @
2db91a42
...
...
@@ -168,7 +168,7 @@ public class ClassRemapper extends ClassVisitor {
super
.
visitInnerClass
(
remapper
.
mapType
(
name
),
outerName
==
null
?
null
:
remapper
.
mapType
(
outerName
),
innerName
,
innerName
==
null
?
null
:
remapper
.
mapInnerClassName
(
name
,
outerName
,
innerName
)
,
access
);
}
...
...
asm-commons/src/main/java/org/objectweb/asm/commons/Remapper.java
View file @
2db91a42
...
...
@@ -214,6 +214,26 @@ public abstract class Remapper {
return
new
SignatureRemapper
(
signatureVisitor
,
this
);
}
/**
* Maps an inner class name to its new name. The default implementation of this method provides a
* strategy that will work for inner classes produced by Java, but not necessarily other
* languages. Subclasses can override.
*
* @param name the fully-qualified internal name of the inner class.
* @param ownerName the internal name of the owner class of the inner class.
* @param innerName the internal name of the inner class.
* @return the new inner name of the inner class.
*/
public
String
mapInnerClassName
(
final
String
name
,
final
String
ownerName
,
final
String
innerName
)
{
final
String
remappedInnerName
=
this
.
mapType
(
name
);
if
(
remappedInnerName
.
contains
(
"$"
))
{
return
remappedInnerName
.
substring
(
remappedInnerName
.
lastIndexOf
(
'$'
)
+
1
);
}
else
{
return
innerName
;
}
}
/**
* Maps a method name to its new name. The default implementation of this method returns the given
* name, unchanged. Subclasses can override.
...
...
asm-commons/src/test/java/org/objectweb/asm/commons/ClassRemapperTest.java
View file @
2db91a42
...
...
@@ -58,6 +58,26 @@ public class ClassRemapperTest extends AsmTest {
assertEquals
(
"new/pkg/C"
,
classNode
.
name
);
}
@Test
public
void
testRenameInnerClass
()
{
final
ClassNode
node
=
new
ClassNode
();
final
ClassRemapper
remapper
=
new
ClassRemapper
(
node
,
new
Remapper
()
{
@Override
public
String
map
(
final
String
internalName
)
{
if
(
"a"
.
equals
(
internalName
))
return
"pkg/Demo"
;
if
(
"a$g"
.
equals
(
internalName
))
return
"pkg/Demo$Container"
;
return
internalName
;
}
});
remapper
.
visit
(
Opcodes
.
V1_5
,
Opcodes
.
ACC_PUBLIC
,
"a"
,
null
,
"java/lang/Object"
,
null
);
remapper
.
visitInnerClass
(
"a$g"
,
"a"
,
"g"
,
Opcodes
.
ACC_PUBLIC
);
assertEquals
(
"pkg/Demo"
,
node
.
innerClasses
.
get
(
0
).
outerName
);
assertEquals
(
"Container"
,
node
.
innerClasses
.
get
(
0
).
innerName
);
}
@Test
public
void
testRenameModuleHashes
()
{
ClassNode
classNode
=
new
ClassNode
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment