Merge "Revert "Modify how simple name is computed"" into ub-jack
diff --git a/jack-tests/tests/com/android/jack/AllTests.java b/jack-tests/tests/com/android/jack/AllTests.java
index 7842b68..fecbacc 100644
--- a/jack-tests/tests/com/android/jack/AllTests.java
+++ b/jack-tests/tests/com/android/jack/AllTests.java
@@ -52,7 +52,6 @@
 import com.android.jack.optimizations.uselesscopy.UselessVariableCopyTest;
 import com.android.jack.order.OrderTests;
 import com.android.jack.preprocessor.PreProcessorTests;
-import com.android.jack.reflect.ReflectTests;
 import com.android.jack.resource.ResourceTests;
 import com.android.jack.returnstatement.ReturnstatementTests;
 import com.android.jack.shrob.ShrobAllTests;
@@ -125,7 +124,6 @@
     OpcodesTests.class,
     ParserTest.class,
     PreProcessorTests.class,
-    ReflectTests.class,
     ReturnstatementTests.class,
     ResourceTests.class,
     ReachingDefsTests.class,
diff --git a/jack-tests/tests/com/android/jack/reflect/ReflectTests.java b/jack-tests/tests/com/android/jack/reflect/ReflectTests.java
deleted file mode 100644
index 1e36055..0000000
--- a/jack-tests/tests/com/android/jack/reflect/ReflectTests.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.jack.reflect;
-
-import com.android.jack.test.helper.RuntimeTestHelper;
-import com.android.jack.test.runtime.RuntimeTest;
-import com.android.jack.test.runtime.RuntimeTestInfo;
-import com.android.jack.test.toolchain.AbstractTestTools;
-import com.android.jack.unary.UnaryTests;
-
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class ReflectTests extends RuntimeTest {
-
-  private static RuntimeTestInfo TEST001_WITH_SHRINK_SCHEDULABLE = new RuntimeTestInfo(
-      AbstractTestTools.getTestRootDir("com.android.jack.reflect.test001"),
-      "com.android.jack.reflect.test001.dx.Tests");
-
-  private static RuntimeTestInfo TEST001_WITHOUT_SHRINK_SCHEDULABLE = new RuntimeTestInfo(
-      AbstractTestTools.getTestRootDir("com.android.jack.reflect.test001"),
-      "com.android.jack.reflect.test001.dx.Tests");
-
-  @BeforeClass
-  public static void setUpClass() {
-    UnaryTests.class.getClassLoader().setDefaultAssertionStatus(true);
-    TEST001_WITH_SHRINK_SCHEDULABLE.addProguardFlagsFileName("proguard.flags");
-  }
-
-  @Test
-  public void simpleName001() throws Exception {
-    new RuntimeTestHelper(TEST001_WITHOUT_SHRINK_SCHEDULABLE).compileAndRunTest();
-  }
-
-
-  @Test
-  public void simpleName002() throws Exception {
-    new RuntimeTestHelper(TEST001_WITH_SHRINK_SCHEDULABLE).compileAndRunTest();
-  }
-
-  @Override
-  protected void fillRtTestInfos() {
-    rtTestInfos.add(TEST001_WITH_SHRINK_SCHEDULABLE);
-    rtTestInfos.add(TEST001_WITHOUT_SHRINK_SCHEDULABLE);
-  }
-}
diff --git a/jack-tests/tests/com/android/jack/reflect/test001/dx/Tests.java b/jack-tests/tests/com/android/jack/reflect/test001/dx/Tests.java
deleted file mode 100644
index 4649902..0000000
--- a/jack-tests/tests/com/android/jack/reflect/test001/dx/Tests.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.jack.reflect.test001.dx;
-
-import com.android.jack.reflect.test001.jack.Reflect001;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class Tests {
-
-  @Test
-  public void simpleName001() {
-    Assert.assertEquals("C",  new Reflect001().getSimpleNameInner1());
-    Assert.assertEquals("C",  new Reflect001().getSimpleNameInner2());
-    Assert.assertEquals("$A$B$C",  new Reflect001().getSimpleNameInner3());
-    Assert.assertEquals("$A$B$C",  new Reflect001().getSimpleNameInner4());
-    Assert.assertEquals("$1I",  new Reflect001().getSimpleNameInner5());
-    Assert.assertEquals("$1I",  new Reflect001().getSimpleNameInner6());
-  }
-
-  @Test
-  public void simpleName002() {
-    Assert.assertEquals("$1I",  new Reflect001().getSimpleNameLocal1());
-    Assert.assertEquals("",  new Reflect001().getSimpleNameLocal2());
-    Assert.assertEquals("I",  new Reflect001().getSimpleNameLocal3());
-    Assert.assertEquals("",  new Reflect001().getSimpleNameLocal4());
-  }
-
-  @Test
-  public void isAnonymous001() {
-    Assert.assertFalse(new Reflect001().isAnonymousInner1());
-    Assert.assertFalse(new Reflect001().isAnonymousInner2());
-    Assert.assertFalse(new Reflect001().isAnonymousInner3());
-    Assert.assertFalse(new Reflect001().isAnonymousInner4());
-    Assert.assertTrue(new Reflect001().isAnonymousInner5());
-  }
-
-  @Test
-  public void isAnonymous002() {
-    Assert.assertFalse(new Reflect001().isAnonymousLocal1());
-    Assert.assertTrue(new Reflect001().isAnonymousLocal2());
-    Assert.assertFalse(new Reflect001().isAnonymousLocal3());
-    Assert.assertTrue(new Reflect001().isAnonymousLocal4());
-  }
-}
diff --git a/jack-tests/tests/com/android/jack/reflect/test001/jack/Reflect001.java b/jack-tests/tests/com/android/jack/reflect/test001/jack/Reflect001.java
deleted file mode 100644
index 2c29cb8..0000000
--- a/jack-tests/tests/com/android/jack/reflect/test001/jack/Reflect001.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.jack.reflect.test001.jack;
-
-public class Reflect001 {
-
-  private class $1I{}
-
-  private interface I{}
-
-  private class $A$B$C {}
-
-  private class C{}
-
-  public String getSimpleNameInner1() {
-    return C.class.getSimpleName();
-  }
-
-  public String getSimpleNameInner2() {
-    return new C().getClass().getSimpleName();
-  }
-
-  public String getSimpleNameInner3() {
-    return $A$B$C.class.getSimpleName();
-  }
-
-  public String getSimpleNameInner4() {
-    return new $A$B$C().getClass().getSimpleName();
-  }
-
-  public String getSimpleNameInner5() {
-    return $1I.class.getSimpleName();
-  }
-
-  public String getSimpleNameInner6() {
-    return new $1I().getClass().getSimpleName();
-  }
-
-  public boolean isAnonymousInner1() {
-    return C.class.isAnonymousClass();
-  }
-
-  public boolean isAnonymousInner2() {
-    return new C().getClass().isAnonymousClass();
-  }
-
-  public boolean isAnonymousInner3() {
-    return $A$B$C.class.isAnonymousClass();
-  }
-
-  public boolean isAnonymousInner4() {
-    return new $A$B$C().getClass().isAnonymousClass();
-  }
-
-  public boolean isAnonymousInner5() {
-    return new I(){}.getClass().isAnonymousClass();
-  }
-
-
-  public String getSimpleNameLocal1() {
-    class $1I{}
-
-    return $1I.class.getSimpleName();
-  }
-
-  public String getSimpleNameLocal2() {
-    class $1I{}
-
-    $1I i = new $1I(){};
-    return i.getClass().getSimpleName();
-  }
-
-  public String getSimpleNameLocal3() {
-    class I{}
-
-    return I.class.getSimpleName();
-  }
-
-  public String getSimpleNameLocal4() {
-    class I{}
-
-    I i = new I(){};
-    return i.getClass().getSimpleName();
-  }
-
-  public boolean isAnonymousLocal1() {
-    class $1I{}
-
-    return $1I.class.isAnonymousClass();
-  }
-
-  public boolean isAnonymousLocal2() {
-    class $1I{}
-
-    $1I i = new $1I(){};
-    return i.getClass().isAnonymousClass();
-  }
-
-  public boolean isAnonymousLocal3() {
-    class I{}
-
-    return I.class.isAnonymousClass();
-  }
-
-  public boolean isAnonymousLocal4() {
-    class I{}
-
-    I i = new I(){};
-    return i.getClass().isAnonymousClass();
-  }
-}
diff --git a/jack-tests/tests/com/android/jack/reflect/test001/proguard.flags b/jack-tests/tests/com/android/jack/reflect/test001/proguard.flags
deleted file mode 100644
index 96c3c88..0000000
--- a/jack-tests/tests/com/android/jack/reflect/test001/proguard.flags
+++ /dev/null
@@ -1,2 +0,0 @@
--keep class * {*; }
--keepattributes *
\ No newline at end of file
diff --git a/jack/src/com/android/jack/ir/naming/TypeName.java b/jack/src/com/android/jack/ir/naming/TypeName.java
index c6d1ebd..9fe86cd 100644
--- a/jack/src/com/android/jack/ir/naming/TypeName.java
+++ b/jack/src/com/android/jack/ir/naming/TypeName.java
@@ -18,7 +18,6 @@
 
 import com.android.jack.ir.ast.JArrayType;
 import com.android.jack.ir.ast.JClassOrInterface;
-import com.android.jack.ir.ast.JDefinedClassOrInterface;
 import com.android.jack.ir.ast.JType;
 import com.android.jack.ir.formatter.BinaryQualifiedNameFormatter;
 import com.android.jack.ir.formatter.BinarySignatureFormatter;
@@ -114,31 +113,19 @@
 
   @Nonnull
   private static String getSimpleName(@Nonnull JType type) {
-    if (type instanceof JDefinedClassOrInterface) {
-      JDefinedClassOrInterface clOrI = (JDefinedClassOrInterface) type;
-      if (clOrI.isAnonymous()) {
-        return "";
-      } else {
-        String simpleName = type.getName();
-        JClassOrInterface enclosingType = clOrI.getEnclosingType();
+    String typeName = type.getName();
+    int simpleNameBeginIndex = typeName.lastIndexOf("$");
 
-        if (enclosingType != null) {
-          // Remove enclosing type name from simpleName
-          int simpleNameBeginIndex = enclosingType.getName().length() + 1;
-          assert simpleName.charAt(simpleNameBeginIndex - 1) == '$';
-
-          // Simple name of Foo$1Bar is Bar, it happens when there is another class named Foo$Bar
-          while (Character.isDigit(simpleName.charAt(simpleNameBeginIndex))) {
-            simpleNameBeginIndex++;
-          }
-
-          simpleName = simpleName.substring(simpleNameBeginIndex);
-        }
-
-        return simpleName;
-      }
+    if (simpleNameBeginIndex == -1) {
+      return typeName;
     } else {
-      throw new AssertionError();
+      int length = typeName.length();
+      simpleNameBeginIndex++;
+      while (simpleNameBeginIndex < length
+          && Character.isDigit(typeName.charAt(simpleNameBeginIndex))) {
+        simpleNameBeginIndex++;
+      }
+      return typeName.substring(simpleNameBeginIndex);
     }
   }
 }