private static String toParamString(final Object[] args) { Class<?> paramTypes[] = new Class<?>[args.length]; for (int i = 0; i < args.length; i++) { paramTypes[i] = args[i].getClass(); } return Converter.toShortString(paramTypes); }
/** * To short string. * * @param array the array * * @return the string */ public static String toShortString(Object[] array) { try { StringBuffer sbuf = new StringBuffer(toShortString(array[0])); for (int i = 1; i < array.length; i++) { sbuf.append(", "); sbuf.append(toShortString(array[i])); } return sbuf.toString(); } catch (RuntimeException e) { return ""; } }
/** * Gets the args as string. * * @return the args as string */ public String getArgsAsString() { return Converter.toShortString(JoinPointHelper.getArgsAsString(this.args)); }
private static void assertEqualsSize(Collection<?> c1, Collection<?> c2) throws AssertionError { if (c1.size() > c2.size()) { for (Object element : c1) { if (!c2.contains(element)) { logMissingElement(element, c2); throw new AssertionError("\"" + Converter.toShortString(element) + "\" is missing in one collection (size: " + c1.size() + " / " + c2.size() + " elements)"); } } } }
private static Method findMethod(final Class<?> cl, final String name, final Class<?>... parameterTypes) throws NoSuchMethodException { Method[] methods = cl.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { if (name.equals(methods[i].getName()) && matchesParameters(methods[i], parameterTypes)) { return methods[i]; } } throw new NoSuchMethodException( cl.getName() + "." + name + "(" + Converter.toShortString(parameterTypes) + ")"); }
/** * Deserializes the given byte array and returns it as object. * * @param bytes * the byte array * @return the deserialized object * @throws ClassNotFoundException * if byte array can't be deserialized */ public static Serializable deserialize(final byte[] bytes) throws ClassNotFoundException { ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes); try { ObjectInputStream oistream = new ObjectInputStream(byteStream); Object object = oistream.readObject(); IOUtils.closeQuietly(oistream); return (Serializable) object; } catch (IOException canthappen) { throw new IllegalArgumentException(toShortString(bytes) + " can't be deserialized", canthappen); } }
/** * Gets the arg as short string. * * @param obj * the obj * @return the arg as short string * @since 1.4.1 */ @NullArgsAllowed public static String getArgAsShortString(final Object obj) { if (obj == null) { return "(null)"; } String shortString = Converter.toShortString(obj); if (obj instanceof String) { return "\"" + shortString + "\""; } return shortString; }
private static void assertEqualSizedMaps(final Map<?, ?> m2, Map<Object, Object> m1) throws AssertionError { for (Entry<Object, Object> entry : m1.entrySet()) { Object value2 = m2.get(entry.getKey()); if (entry.getValue() == null) { if (value2 != null) { LOG.debug("Key \"{}\" has different values: null <--> {}.", entry.getKey(), Converter.toString(value2)); throw new AssertionError("key \"" + entry.getKey() + "\" has different values: null <--> " + Converter.toShortString(value2)); } } else if (value2 == null) { LOG.debug("{{}}\" is missing in {}.", entry, Converter.toString(m2)); throw new AssertionError("{" + entry + "} is missing in " + Converter.toShortString(m2)); } else if (!(value2.equals(entry.getValue()))) { LOG.debug("Key \"{}\" has different values: {} <--> {}.", entry.getKey(), Converter.toString(entry.getValue()), Converter.toString(value2)); throw new AssertionError("key \"" + entry.getKey() + "\" has different values: " + Converter.toShortString(entry.getValue()) + " <--> " + Converter.toShortString(value2)); } } }
/** * To short string. * * @return the string * @see org.aspectj.lang.Signature#toShortString() */ @Override public String toShortString() { return this.getDeclaringType().getSimpleName() + "(" + Converter.toShortString(this.getParameterTypes()) + ")"; }
/** * Logs the trace with a start sign ("<"). * * @param joinpoint * the joinpoint * @param result * the result */ public static void end(final JoinPoint joinpoint, final Object result) { if (LOG.isDebugEnabled()) { int level = getIndentLevel(); trace(level, "< ", joinpoint, " = " + Converter.toShortString(result)); } }
private static void assertEquals(final byte[] a1, final byte[] a2, final int i) { if (a1[i] != a2[i]) { if (LOG.isTraceEnabled()) { LOG.trace("{}. element differs ({} != {}).", i + 1, Converter.toLongString(a1[i]), Converter.toLongString(a2[i])); } else if (LOG.isDebugEnabled()) { LOG.debug("{}. element differs ({} != {}).", i + 1, Converter.toString(a1[i]), Converter.toString(a2[i])); } throw new AssertionError((i + 1) + ". element differs (" + Converter.toShortString(a1[i]) + " != " + Converter.toShortString(a2[i]) + ")"); } }
/** * To string. * * @return the string * * @see java.lang.Object#toString() */ @Override public String toString() { return this.getDeclaringTypeName() + "(" + Converter.toShortString(this.getParameterTypes()) + ")"; }
/** * To string. * * @return the string * @see java.lang.Object#toString() */ @Override public String toString() { return this.getDeclaringTypeName() + "(" + Converter.toShortString(this.getParameterTypes()) + ")"; }
/** * To short string. * * @return the string * * @see org.aspectj.lang.Signature#toShortString() */ @Override public String toShortString() { return this.getName() + "(" + Converter.toShortString(this.getParameterTypes()) + ")"; }
/** * Write return message. * * @param stmt * the stmt */ protected void writeReturnMessage(final DrawStatement stmt) { writeLine(this.placeholders.get(stmt.getTarget()) + " --> -" + this.placeholders.get(stmt.getSender()) + ": " + Converter.toShortString(stmt.getArgs()[0])); }
/** * Check for each class in the given package if the clone method is * implemented correct. * * @param packageName * the package name e.g. "patterntesting.runtime" * @param excluded * pattern for classes which should be excluded from the check * @see #assertCloningOfPackage(String) * @since 1.6 */ public static void assertCloningOfPackage(final String packageName, final Pattern... excluded) { Collection<Class<? extends Cloneable>> classes = getCloneableClasses(packageName); if (LOG.isDebugEnabled()) { LOG.debug("Pattern {} will be excluded from check.", Converter.toShortString(excluded)); } removeClasses(classes, excluded); assertCloning(classes); }
/** * The difference to Signature.toString() is that in case of a methode * or constructor the return type is not part of result. * * @param sig the sig * * @return the given signature as string */ public static String getAsString(Signature sig) { try { CodeSignature codeSig = (CodeSignature) sig; String name = getAsString(sig.getDeclaringTypeName(), sig); Class<?>[] params = codeSig.getParameterTypes(); return name + "(" + Converter.toShortString(params) + ")"; } catch (Exception e) { log.debug("can't get '" + sig + "' as String", e); return sig.toString(); } }
/** * The difference to Signature.toString() is that in case of a methode or * constructor the return type is not part of result. * * @param sig * the sig * * @return the given signature as string */ public static String getAsString(final Signature sig) { if (sig instanceof CodeSignature) { try { CodeSignature codeSig = (CodeSignature) sig; String name = getAsString(sig.getDeclaringTypeName(), sig); Class<?>[] params = codeSig.getParameterTypes(); return name + "(" + Converter.toShortString(params) + ")"; } catch (RuntimeException e) { LOG.debug("Cannot get '" + sig + "' as short string:", e); } } return sig.toString(); }
/** * To string. * * @return the string * * @see java.lang.Object#toString() */ @Override public String toString() { return this.getReturnType() + " " + this.getDeclaringTypeName() + "." + this.getName() + "(" + Converter.toShortString(this.getParameterTypes()) + ")"; }
@Override protected void writeReturnMessage(final DrawStatement stmt) { if (stmt.hasMessageToLeft()) { writeLine("step();"); } writeLine("\n# <-- " + stmt.getJpInfo()); writeLine("return_message(" + stmt.getTarget() + "," + stmt.getSender() + ",\"" + toEscapedString(Converter.toShortString(stmt.getArgs()[0])) + "\");"); writeLine("inactive(" + stmt.getTarget() + ");"); }