8183148: cleanup ModuleSymbol.getSimpleName
authorvromero
Wed, 28 Jun 2017 14:46:18 -0700
changeset 45752 32eb45c44fc8
parent 45751 61f96770ee3a
child 45753 567c159ce16f
8183148: cleanup ModuleSymbol.getSimpleName Reviewed-by: jjg
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Convert.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Wed Jun 28 11:27:31 2017 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Wed Jun 28 14:46:18 2017 -0700
@@ -951,13 +951,7 @@
 
         @Override @DefinedBy(Api.LANGUAGE_MODEL)
         public Name getSimpleName() {
-            Name fullName = getQualifiedName();
-            int lastPeriod = fullName.lastIndexOf((byte)'.');
-            if (lastPeriod == -1) {
-                return fullName;
-            } else {
-                return fullName.subName(lastPeriod + 1, fullName.length());
-            }
+            return Convert.shortName(name);
         }
 
         @Override @DefinedBy(Api.LANGUAGE_MODEL)
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Convert.java	Wed Jun 28 11:27:31 2017 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Convert.java	Wed Jun 28 14:46:18 2017 -0700
@@ -303,15 +303,26 @@
 
 /* Conversion routines for qualified name splitting
  */
-    /** Return the last part of a class name.
+    /** Return the last part of a qualified name.
+     *  @param name the qualified name
+     *  @return the last part of the qualified name
      */
-    public static Name shortName(Name classname) {
-        return classname.subName(
-            classname.lastIndexOf((byte)'.') + 1, classname.getByteLength());
+    public static Name shortName(Name name) {
+        int start = name.lastIndexOf((byte)'.') + 1;
+        int end = name.getByteLength();
+        if (start == 0 && end == name.length()) {
+            return name;
+        }
+        return name.subName(
+            name.lastIndexOf((byte)'.') + 1, name.getByteLength());
     }
 
-    public static String shortName(String classname) {
-        return classname.substring(classname.lastIndexOf('.') + 1);
+    /** Return the last part of a qualified name from its string representation
+     *  @param name the string representation of the qualified name
+     *  @return the last part of the qualified name
+     */
+    public static String shortName(String name) {
+        return name.substring(name.lastIndexOf('.') + 1);
     }
 
     /** Return the package name of a class name, excluding the trailing '.',