1 /* 2 * Copyright (C) 2011 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 17 package com.android.tools.lint.detector.api; 18 19 import com.android.annotations.NonNull; 20 import com.android.annotations.Nullable; 21 import com.google.common.annotations.Beta; 22 23 /** 24 * A category is a container for related issues. 25 * <p/> 26 * <b>NOTE: This is not a public or final API; if you rely on this be prepared 27 * to adjust your code for the next tools release.</b> 28 */ 29 @Beta 30 public final class Category implements Comparable<Category> { 31 private final String mName; 32 private final String mExplanation; 33 private final int mPriority; 34 private final Category mParent; 35 36 /** 37 * Creates a new {@link Category}. 38 * 39 * @param parent the name of a parent category, or null 40 * @param name the name of the category 41 * @param explanation an optional explanation of the category 42 * @param priority a sorting priority, with higher being more important 43 */ Category( @ullable Category parent, @NonNull String name, @Nullable String explanation, int priority)44 private Category( 45 @Nullable Category parent, 46 @NonNull String name, 47 @Nullable String explanation, 48 int priority) { 49 mParent = parent; 50 mName = name; 51 mExplanation = explanation; 52 mPriority = priority; 53 } 54 55 /** 56 * Creates a new top level {@link Category} with the given sorting priority. 57 * 58 * @param name the name of the category 59 * @param priority a sorting priority, with higher being more important 60 * @return a new category 61 */ 62 @NonNull create(@onNull String name, int priority)63 public static Category create(@NonNull String name, int priority) { 64 return new Category(null, name, null, priority); 65 } 66 67 /** 68 * Creates a new top level {@link Category} with the given sorting priority. 69 * 70 * @param parent the name of a parent category, or null 71 * @param name the name of the category 72 * @param explanation an optional explanation of the category 73 * @param priority a sorting priority, with higher being more important 74 * @return a new category 75 */ 76 @NonNull create( @ullable Category parent, @NonNull String name, @Nullable String explanation, int priority)77 public static Category create( 78 @Nullable Category parent, 79 @NonNull String name, 80 @Nullable String explanation, 81 int priority) { 82 return new Category(parent, name, null, priority); 83 } 84 85 /** 86 * Returns the parent category, or null if this is a top level category 87 * 88 * @return the parent category, or null if this is a top level category 89 */ getParent()90 public Category getParent() { 91 return mParent; 92 } 93 94 /** 95 * Returns the name of this category 96 * 97 * @return the name of this category 98 */ getName()99 public String getName() { 100 return mName; 101 } 102 103 /** 104 * Returns an explanation for this category, or null 105 * 106 * @return an explanation for this category, or null 107 */ getExplanation()108 public String getExplanation() { 109 return mExplanation; 110 } 111 112 /** 113 * Returns a full name for this category. For a top level category, this is just 114 * the {@link #getName()} value, but for nested categories it will include the parent 115 * names as well. 116 * 117 * @return a full name for this category 118 */ getFullName()119 public String getFullName() { 120 if (mParent != null) { 121 return mParent.getFullName() + ':' + mName; 122 } else { 123 return mName; 124 } 125 } 126 127 @Override compareTo(@onNull Category other)128 public int compareTo(@NonNull Category other) { 129 if (other.mPriority == mPriority) { 130 if (mParent == other) { 131 return 1; 132 } else if (other.mParent == this) { 133 return -1; 134 } 135 } 136 return other.mPriority - mPriority; 137 } 138 139 /** Issues related to running lint itself */ 140 public static final Category LINT = Category.create("Lint", 110); 141 142 /** Issues related to correctness */ 143 public static final Category CORRECTNESS = Category.create("Correctness", 100); 144 145 /** Issues related to security */ 146 public static final Category SECURITY = Category.create("Security", 90); 147 148 /** Issues related to performance */ 149 public static final Category PERFORMANCE = Category.create("Performance", 80); 150 151 /** Issues related to usability */ 152 public static final Category USABILITY = Category.create("Usability", 70); 153 154 /** Issues related to accessibility */ 155 public static final Category A11Y = Category.create("Accessibility", 60); 156 157 /** Issues related to internationalization */ 158 public static final Category I18N = Category.create("Internationalization", 50); 159 160 // Sub categories 161 162 /** Issues related to icons */ 163 public static final Category ICONS = Category.create(USABILITY, "Icons", null, 73); 164 165 /** Issues related to typography */ 166 public static final Category TYPOGRAPHY = Category.create(USABILITY, "Typography", null, 76); 167 168 /** Issues related to messages/strings */ 169 public static final Category MESSAGES = Category.create(CORRECTNESS, "Messages", null, 95); 170 } 171