Created
March 15, 2019 16:49
-
-
Save zabetak/fcb0b842772cad7cd2e2083926853028 to your computer and use it in GitHub Desktop.
Obtain a rough equivalent of Class#getName for all subtypes of a java Type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using IntelliJ select the desired type (e.g., java.lang.Number) and open subtypes hierarchy. | |
# Using the toolbar in the Hierarchy window click the button to export the hierarchy into a file. | |
# The exported file (let's call it init.txt) should look like below: | |
Number (java.lang) | |
Float (java.lang) | |
MutableInt (org.apache.commons.lang3.mutable) | |
MutableInt (org.apache.commons.lang3.mutable) | |
BigFraction (org.apache.commons.math3.fraction) | |
BigFraction (org.apache.commons.math3.fraction) | |
BigFraction (org.apache.commons.math3.fraction) | |
Integer (java.lang) | |
MyInteger in MyClass (org.some.package) | |
# The first step is to treat inner classes which appear as type MyInteger in MyClass to look like MyClass$MyInteger | |
sed 's/\([[:alnum:]]\+\)$\([[:alnum:]]\+\)/\2$\1/' init.txt > step1.txt | |
# The second step is to remove whitespaces to have all classes at the same level | |
sed 's/\s\+//g' step1.txt > step2.txt | |
# The third step is to bring package name in front of class name and remove parentheses | |
sed 's/\(.\+\)(\(.\+\))/\2.\1/' step2.txt > step3.txt | |
# The previous can be done using piped sed expressions as follows | |
sed 's/\([[:alnum:]]\+\)$\([[:alnum:]]\+\)/\2$\1/' init.txt | sed 's/\s\+//g' | sed 's/\(.\+\)(\(.\+\))/\2.\1/' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment