@Test public void testGetMessage() { assertEquals("Error: My error message", MergingException.withMessage("My error message").build().getMessage()); assertEquals("Error: My error message", MergingException.wrapException(new Exception()).withMessage( "Error: My error message").build().getMessage()); assertEquals("Error: My error message", MergingException.withMessage("Error: My error message").build().getMessage()); assertEquals("/some/random/path: Error: My error message", MergingException.wrapException(new Exception("My error message")).withFile(file) .build().getMessage()); MergingException.Builder builder2 = MergingException .wrapException(new Exception("My error message")).withFile(file) .withPosition(new SourcePosition(49, -1, -1)); assertEquals("/some/random/path:50: Error: My error message", builder2.build() .getMessage()); MergingException.Builder builder1 = MergingException .wrapException(new Exception("My error message")).withFile(file) .withPosition(new SourcePosition(49, 3, -1)); assertEquals("/some/random/path:50:4: Error: My error message", builder1.build() .getMessage()); MergingException.Builder builder = MergingException .wrapException(new Exception("My error message")).withFile(file) .withPosition(new SourcePosition(49, 3, -1)); assertEquals("/some/random/path:50:4: Error: My error message", builder.build() .getLocalizedMessage()); assertEquals("/some/random/path: Error: My error message", MergingException.withMessage("/some/random/path: My error message").withFile(file) .build().getMessage()); assertEquals("/some/random/path: Error: My error message", MergingException.withMessage("/some/random/path My error message").withFile(file) .build().getMessage()); assertEquals("/some/random/path: Error: ", MergingException.withMessage("/some/random/path").withFile(file).build() .getMessage()); assertEquals("/some/random/path: Error: ", MergingException.withMessage("/some/random/path").withFile(file).build().getMessage()); assertEquals("/some/random/path: Error: ", MergingException.withMessage("/some/random/path:").withFile(file).build().getMessage()); assertEquals("/some/random/path: Error: ", MergingException.withMessage("/some/random/path: ").withFile(file).build().getMessage()); }
@NonNull @Override public String getMessage() { List<String> messages = Lists.newArrayListWithCapacity(mMessages.size()); for (Message message : mMessages) { StringBuilder sb = new StringBuilder(); List<SourceFilePosition> sourceFilePositions = message.getSourceFilePositions(); if (sourceFilePositions.size() > 1 || !sourceFilePositions.get(0) .equals(SourceFilePosition.UNKNOWN)) { sb.append(Joiner.on('\t').join(sourceFilePositions)); } String text = message.getText(); if (sb.length() > 0) { sb.append(':').append(' '); if (!text.startsWith("Error: ")) { sb.append("Error: "); } } else if (!text.contains("Error: ")) { sb.append("Error: "); } if (sourceFilePositions.size() == 1) { File file = sourceFilePositions.get(0).getFile().getSourceFile(); if (file != null) { String path = file.getAbsolutePath(); if (text.startsWith(path)) { int stripStart = path.length(); if (text.length() > stripStart && text.charAt(stripStart) == ':') { stripStart++; } if (text.length() > stripStart && text.charAt(stripStart) == ' ') { stripStart++; } text = text.substring(stripStart); } } } sb.append(text); messages.add(sb.toString()); } return Joiner.on('\n').join(messages); }
MergingException extends Exception { @NonNull @Override public String getMessage() { List<String> messages = Lists.newArrayListWithCapacity(mMessages.size()); for (Message message : mMessages) { StringBuilder sb = new StringBuilder(); List<SourceFilePosition> sourceFilePositions = message.getSourceFilePositions(); if (sourceFilePositions.size() > 1 || !sourceFilePositions.get(0) .equals(SourceFilePosition.UNKNOWN)) { sb.append(Joiner.on('\t').join(sourceFilePositions)); } String text = message.getText(); if (sb.length() > 0) { sb.append(':').append(' '); if (!text.startsWith("Error: ")) { sb.append("Error: "); } } else if (!text.contains("Error: ")) { sb.append("Error: "); } if (sourceFilePositions.size() == 1) { File file = sourceFilePositions.get(0).getFile().getSourceFile(); if (file != null) { String path = file.getAbsolutePath(); if (text.startsWith(path)) { int stripStart = path.length(); if (text.length() > stripStart && text.charAt(stripStart) == ':') { stripStart++; } if (text.length() > stripStart && text.charAt(stripStart) == ' ') { stripStart++; } text = text.substring(stripStart); } } } sb.append(text); messages.add(sb.toString()); } return Joiner.on('\n').join(messages); } }
MergingException extends Exception { @NonNull @Override public String getMessage() { List<String> messages = Lists.newArrayListWithCapacity(mMessages.size()); for (Message message : mMessages) { StringBuilder sb = new StringBuilder(); List<SourceFilePosition> sourceFilePositions = message.getSourceFilePositions(); if (sourceFilePositions.size() > 1 || !sourceFilePositions.get(0) .equals(SourceFilePosition.UNKNOWN)) { sb.append(Joiner.on('\t').join(sourceFilePositions)); } String text = message.getText(); if (sb.length() > 0) { sb.append(':').append(' '); if (!text.startsWith("Error: ")) { sb.append("Error: "); } } else if (!text.contains("Error: ")) { sb.append("Error: "); } if (sourceFilePositions.size() == 1) { File file = sourceFilePositions.get(0).getFile().getSourceFile(); if (file != null) { String path = file.getAbsolutePath(); if (text.startsWith(path)) { int stripStart = path.length(); if (text.length() > stripStart && text.charAt(stripStart) == ':') { stripStart++; } if (text.length() > stripStart && text.charAt(stripStart) == ' ') { stripStart++; } text = text.substring(stripStart); } } } sb.append(text); messages.add(sb.toString()); } return Joiner.on('\n').join(messages); } protected  MergingException(@Nullable Throwable cause, @NonNull Message... messages); }
MergingException extends Exception { @NonNull @Override public String getMessage() { List<String> messages = Lists.newArrayListWithCapacity(mMessages.size()); for (Message message : mMessages) { StringBuilder sb = new StringBuilder(); List<SourceFilePosition> sourceFilePositions = message.getSourceFilePositions(); if (sourceFilePositions.size() > 1 || !sourceFilePositions.get(0) .equals(SourceFilePosition.UNKNOWN)) { sb.append(Joiner.on('\t').join(sourceFilePositions)); } String text = message.getText(); if (sb.length() > 0) { sb.append(':').append(' '); if (!text.startsWith("Error: ")) { sb.append("Error: "); } } else if (!text.contains("Error: ")) { sb.append("Error: "); } if (sourceFilePositions.size() == 1) { File file = sourceFilePositions.get(0).getFile().getSourceFile(); if (file != null) { String path = file.getAbsolutePath(); if (text.startsWith(path)) { int stripStart = path.length(); if (text.length() > stripStart && text.charAt(stripStart) == ':') { stripStart++; } if (text.length() > stripStart && text.charAt(stripStart) == ' ') { stripStart++; } text = text.substring(stripStart); } } } sb.append(text); messages.add(sb.toString()); } return Joiner.on('\n').join(messages); } protected  MergingException(@Nullable Throwable cause, @NonNull Message... messages); static Builder wrapException(@NonNull Throwable cause); static Builder withMessage(@NonNull String message, Object... args); static void throwIfNonEmpty(Collection<Message> messages); @NonNull List<Message> getMessages(); @NonNull @Override String getMessage(); @Override String toString(); }
MergingException extends Exception { @NonNull @Override public String getMessage() { List<String> messages = Lists.newArrayListWithCapacity(mMessages.size()); for (Message message : mMessages) { StringBuilder sb = new StringBuilder(); List<SourceFilePosition> sourceFilePositions = message.getSourceFilePositions(); if (sourceFilePositions.size() > 1 || !sourceFilePositions.get(0) .equals(SourceFilePosition.UNKNOWN)) { sb.append(Joiner.on('\t').join(sourceFilePositions)); } String text = message.getText(); if (sb.length() > 0) { sb.append(':').append(' '); if (!text.startsWith("Error: ")) { sb.append("Error: "); } } else if (!text.contains("Error: ")) { sb.append("Error: "); } if (sourceFilePositions.size() == 1) { File file = sourceFilePositions.get(0).getFile().getSourceFile(); if (file != null) { String path = file.getAbsolutePath(); if (text.startsWith(path)) { int stripStart = path.length(); if (text.length() > stripStart && text.charAt(stripStart) == ':') { stripStart++; } if (text.length() > stripStart && text.charAt(stripStart) == ' ') { stripStart++; } text = text.substring(stripStart); } } } sb.append(text); messages.add(sb.toString()); } return Joiner.on('\n').join(messages); } protected  MergingException(@Nullable Throwable cause, @NonNull Message... messages); static Builder wrapException(@NonNull Throwable cause); static Builder withMessage(@NonNull String message, Object... args); static void throwIfNonEmpty(Collection<Message> messages); @NonNull List<Message> getMessages(); @NonNull @Override String getMessage(); @Override String toString(); static final String MULTIPLE_ERRORS; }