src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.meta/src/jdk/vm/ci/meta/MetaUtil.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File open Cdiff src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.meta/src/jdk/vm/ci/meta/MetaUtil.java

src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.meta/src/jdk/vm/ci/meta/MetaUtil.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 36,52 **** * of the enclosing class/classes of {@code clazz} (if any). This option is ignored * if {@code clazz} denotes an anonymous or local class. * @return the simple name */ public static String getSimpleName(Class<?> clazz, boolean withEnclosingClass) { ! final String simpleName = clazz.getSimpleName(); if (simpleName.length() != 0) { if (withEnclosingClass) { String prefix = ""; Class<?> enclosingClass = clazz; while ((enclosingClass = enclosingClass.getEnclosingClass()) != null) { ! prefix = enclosingClass.getSimpleName() + "." + prefix; } return prefix + simpleName; } return simpleName; } --- 36,52 ---- * of the enclosing class/classes of {@code clazz} (if any). This option is ignored * if {@code clazz} denotes an anonymous or local class. * @return the simple name */ public static String getSimpleName(Class<?> clazz, boolean withEnclosingClass) { ! final String simpleName = safeSimpleName(clazz); if (simpleName.length() != 0) { if (withEnclosingClass) { String prefix = ""; Class<?> enclosingClass = clazz; while ((enclosingClass = enclosingClass.getEnclosingClass()) != null) { ! prefix = safeSimpleName(enclosingClass) + "." + prefix; } return prefix + simpleName; } return simpleName; }
*** 61,70 **** --- 61,93 ---- return name; } return name.substring(index + 1); } + private static String safeSimpleName(Class<?> clazz) { + try { + return clazz.getSimpleName(); + } catch (InternalError e) { + // Scala inner class names do not always start with '$', + // causing Class.getSimpleName to throw an InternalError + Class<?> enclosingClass = clazz.getEnclosingClass(); + String fqn = clazz.getName(); + if (enclosingClass == null) { + // Should never happen given logic in + // Class.getSimpleName but best be safe + return fqn; + } + String enclosingFQN = enclosingClass.getName(); + int length = fqn.length(); + if (enclosingFQN.length() >= length) { + // Should also never happen + return fqn; + } + return fqn.substring(enclosingFQN.length()); + } + } + /** * Converts a type name in internal form to an external form. * * @param name the internal name to convert * @param qualified whether the returned name should be qualified with the package name
src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.meta/src/jdk/vm/ci/meta/MetaUtil.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File