1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php 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 package com.android.ide.common.resources; 17 18 import java.util.ArrayList; 19 import java.util.List; 20 21 /** 22 * A {@link ScanningContext} keeps track of state during a resource file scan, 23 * such as any parsing errors encountered, whether Android ids have changed, and 24 * so on. 25 */ 26 public class ScanningContext { 27 private final ResourceRepository mRepository; 28 private boolean mNeedsFullAapt; 29 private List<String> mErrors = null; 30 31 /** 32 * Constructs a new {@link ScanningContext} 33 * 34 * @param repository the associated resource repository 35 */ 36 public ScanningContext(ResourceRepository repository) { 37 super(); 38 mRepository = repository; 39 } 40 41 /** 42 * Returns a list of errors encountered during scanning 43 * 44 * @return a list of errors encountered during scanning (or null) 45 */ 46 public List<String> getErrors() { 47 return mErrors; 48 } 49 50 /** 51 * Adds the given error to the scanning context. The error should use the 52 * same syntax as real aapt error messages such that the aapt parser can 53 * properly detect the filename, line number, etc. 54 * 55 * @param error the error message, including file name and line number at 56 * the beginning 57 */ 58 public void addError(String error) { 59 if (mErrors == null) { 60 mErrors = new ArrayList<String>(); 61 } 62 mErrors.add(error); 63 } 64 65 /** 66 * Returns the repository associated with this scanning context 67 * 68 * @return the associated repository, never null 69 */ 70 public ResourceRepository getRepository() { 71 return mRepository; 72 } 73 74 /** 75 * Marks that a full aapt compilation of the resources is necessary because it has 76 * detected a change that cannot be incrementally handled. 77 */ 78 protected void requestFullAapt() { 79 mNeedsFullAapt = true; 80 } 81 82 /** 83 * Returns whether this repository has been marked as "dirty"; if one or 84 * more of the constituent files have declared that the resource item names 85 * that they provide have changed. 86 * 87 * @return true if a full aapt compilation is required 88 */ 89 public boolean needsFullAapt() { 90 return mNeedsFullAapt; 91 } 92 } 93