< prev index next >

src/java.base/share/classes/java/lang/reflect/Executable.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2012, 2017, 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. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2012, 2018, 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. Oracle designates this
*** 24,36 **** --- 24,39 ---- */ package java.lang.reflect; import java.lang.annotation.*; + import java.util.Arrays; import java.util.Map; import java.util.Objects; import java.util.StringJoiner; + import java.util.stream.Stream; + import java.util.stream.Collectors; import jdk.internal.misc.SharedSecrets; import sun.reflect.annotation.AnnotationParser; import sun.reflect.annotation.AnnotationSupport; import sun.reflect.annotation.TypeAnnotationParser;
*** 107,129 **** StringBuilder sb = new StringBuilder(); printModifiersIfNonzero(sb, modifierMask, isDefault); specificToStringHeader(sb); sb.append('('); ! StringJoiner sj = new StringJoiner(","); ! for (Class<?> parameterType : parameterTypes) { ! sj.add(parameterType.getTypeName()); ! } ! sb.append(sj.toString()); sb.append(')'); if (exceptionTypes.length > 0) { ! StringJoiner joiner = new StringJoiner(",", " throws ", ""); ! for (Class<?> exceptionType : exceptionTypes) { ! joiner.add(exceptionType.getTypeName()); ! } ! sb.append(joiner.toString()); } return sb.toString(); } catch (Exception e) { return "<" + e + ">"; } --- 110,128 ---- StringBuilder sb = new StringBuilder(); printModifiersIfNonzero(sb, modifierMask, isDefault); specificToStringHeader(sb); sb.append('('); ! ! sb.append(Stream.of(parameterTypes).map(p -> p.getTypeName()). ! collect(Collectors.joining(","))); ! sb.append(')'); if (exceptionTypes.length > 0) { ! sb.append(Stream.of(exceptionTypes).map(e -> e.getTypeName()). ! collect(Collectors.joining(",", " throws ", ""))); } return sb.toString(); } catch (Exception e) { return "<" + e + ">"; }
*** 133,155 **** * Generate toString header information specific to a method or * constructor. */ abstract void specificToStringHeader(StringBuilder sb); String sharedToGenericString(int modifierMask, boolean isDefault) { try { StringBuilder sb = new StringBuilder(); printModifiersIfNonzero(sb, modifierMask, isDefault); TypeVariable<?>[] typeparms = getTypeParameters(); if (typeparms.length > 0) { ! StringJoiner sj = new StringJoiner(",", "<", "> "); ! for(TypeVariable<?> typeparm: typeparms) { ! sj.add(typeparm.getTypeName()); ! } ! sb.append(sj.toString()); } specificToGenericStringHeader(sb); sb.append('('); --- 132,162 ---- * Generate toString header information specific to a method or * constructor. */ abstract void specificToStringHeader(StringBuilder sb); + String typeVarBounds(TypeVariable<?> typeVar) { + Type[] bounds = typeVar.getBounds(); + if (bounds.length == 1 && bounds[0].equals(Object.class)) { + return typeVar.getName(); + } else { + return typeVar.getName() + " extends " + + Stream.of(bounds).map(e -> e.getTypeName()). + collect(Collectors.joining(" & ")); + } + } + String sharedToGenericString(int modifierMask, boolean isDefault) { try { StringBuilder sb = new StringBuilder(); printModifiersIfNonzero(sb, modifierMask, isDefault); TypeVariable<?>[] typeparms = getTypeParameters(); if (typeparms.length > 0) { ! sb.append(Stream.of(typeparms).map(t -> typeVarBounds(t)). ! collect(Collectors.joining(",", "<", "> "))); } specificToGenericStringHeader(sb); sb.append('(');
< prev index next >