Search in sources :

Example 1 with Message

use of com.android.common.ide.common.blame.Message in project buck by facebook.

the class MergingException method getMessage.

/**
     * Computes the error message to display for this error
     */
@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(' ');
            // string to the left of a colon.)
            if (!text.startsWith("Error: ")) {
                sb.append("Error: ");
            }
        } else if (!text.contains("Error: ")) {
            sb.append("Error: ");
        }
        //    /my/full/path: /my/full/path (Permission denied)
        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);
}
Also used : SourceFilePosition(com.android.common.ide.common.blame.SourceFilePosition) Message(com.android.common.ide.common.blame.Message) File(java.io.File) SourceFile(com.android.common.ide.common.blame.SourceFile) NonNull(com.android.annotations.NonNull)

Aggregations

NonNull (com.android.annotations.NonNull)1 Message (com.android.common.ide.common.blame.Message)1 SourceFile (com.android.common.ide.common.blame.SourceFile)1 SourceFilePosition (com.android.common.ide.common.blame.SourceFilePosition)1 File (java.io.File)1