1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.databinding.tool.processing; 18 19import android.databinding.tool.store.Location; 20import android.databinding.tool.util.StringUtils; 21 22import java.util.List; 23 24public class ScopedErrorReport { 25 26 private final String mFilePath; 27 28 private final List<Location> mLocations; 29 30 /** 31 * Only created by Scope 32 */ 33 ScopedErrorReport(String filePath, List<Location> locations) { 34 mFilePath = filePath; 35 mLocations = locations; 36 } 37 38 public String getFilePath() { 39 return mFilePath; 40 } 41 42 public List<Location> getLocations() { 43 return mLocations; 44 } 45 46 public boolean isValid() { 47 return StringUtils.isNotBlank(mFilePath); 48 } 49 50 public String toUserReadableString() { 51 StringBuilder sb = new StringBuilder(); 52 if (mFilePath != null) { 53 sb.append("File:"); 54 sb.append(mFilePath); 55 } 56 if (mLocations != null && mLocations.size() > 0) { 57 if (mLocations.size() > 1) { 58 sb.append("Locations:"); 59 for (Location location : mLocations) { 60 sb.append("\n ").append(location.toUserReadableString()); 61 } 62 } else { 63 sb.append("\n Location: ").append(mLocations.get(0).toUserReadableString()); 64 } 65 } 66 return sb.toString(); 67 } 68} 69