本文整理汇总了Java中com.android.tools.lint.detector.api.LintUtils.getBaseName方法的典型用法代码示例。如果您正苦于以下问题:Java LintUtils.getBaseName方法的具体用法?Java LintUtils.getBaseName怎么用?Java LintUtils.getBaseName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.tools.lint.detector.api.LintUtils
的用法示例。
在下文中一共展示了LintUtils.getBaseName方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beforeCheckFile
import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
@Override
public void beforeCheckFile(@NonNull Context context) {
if (mPrefix != null && context instanceof XmlContext) {
XmlContext xmlContext = (XmlContext) context;
ResourceFolderType folderType = xmlContext.getResourceFolderType();
if (folderType != null && folderType != ResourceFolderType.VALUES) {
String name = LintUtils.getBaseName(context.file.getName());
if (!name.startsWith(mPrefix)) {
// Attempt to report the error on the root tag of the associated
// document to make suppressing the error with a tools:suppress
// attribute etc possible
if (xmlContext.document != null) {
Element root = xmlContext.document.getDocumentElement();
if (root != null) {
xmlContext.report(ISSUE, root, xmlContext.getLocation(root),
getErrorMessage(name));
return;
}
}
context.report(ISSUE, Location.create(context.file),
getErrorMessage(name));
}
}
}
}
示例2: checkBinaryResource
import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
@Override
public void checkBinaryResource(@NonNull ResourceContext context) {
if (mPrefix != null) {
ResourceFolderType folderType = context.getResourceFolderType();
if (folderType != null && folderType != ResourceFolderType.VALUES) {
String name = LintUtils.getBaseName(context.file.getName());
if (!name.startsWith(mPrefix)) {
Location location = Location.create(context.file);
context.report(ISSUE, location, getErrorMessage(name));
}
}
}
}
示例3: getResourceName
import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
/** Looks up the resource name for the given refactored element. Uses the same
* instanceof chain checkups as is done in {@link #canProcessElement} */
@Nullable
private static String getResourceName(PsiElement originalElement) {
PsiElement element = LazyValueResourceElementWrapper.computeLazyElement(originalElement);
if (element == null) {
return null;
}
if (element instanceof PsiFile) {
PsiFile file = (PsiFile)element;
LocalResourceManager manager = LocalResourceManager.getInstance(element);
if (manager != null) {
String type = manager.getFileResourceType(file);
if (type != null) {
String name = file.getName();
return AndroidCommonUtils.getResourceName(type, name);
}
}
return LintUtils.getBaseName(file.getName());
}
else if (element instanceof PsiField) {
PsiField field = (PsiField)element;
return field.getName();
}
else if (element instanceof XmlAttributeValue) {
if (AndroidResourceUtil.isIdDeclaration((XmlAttributeValue)element)) {
return AndroidResourceUtil.getResourceNameByReferenceText(((XmlAttributeValue)element).getValue());
}
XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
if (tag != null) {
DomElement domElement = DomManager.getDomManager(tag.getProject()).getDomElement(tag);
if (domElement instanceof ResourceElement) {
return ((ResourceElement)domElement).getName().getValue();
}
}
}
return null;
}
示例4: getResourceName
import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
/**
* Returns the resource name of the given file.
* <p>
* For example, {@code getResourceName(</res/layout-land/foo.xml, false) = "foo"}.
*
* @param file the file to compute a resource name for
* @return the resource name
*/
@NotNull
public static String getResourceName(@NotNull PsiFile file) {
// See getResourceName(VirtualFile)
// We're replicating that code here rather than just calling
// getResourceName(file.getVirtualFile());
// since file.getVirtualFile can return null
return LintUtils.getBaseName(file.getName());
}
示例5: removeFile
import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
private void removeFile(@Nullable PsiResourceFile resourceFile) {
if (resourceFile == null) {
// No resources for this file
return;
}
for (Map.Entry<PsiFile, PsiResourceFile> entry : myResourceFiles.entrySet()) {
PsiResourceFile file = entry.getValue();
if (resourceFile == file) {
PsiFile psiFile = entry.getKey();
myResourceFiles.remove(psiFile);
break;
}
}
myGeneration++;
invalidateItemCaches();
ResourceFolderType folderType = resourceFile.getFolderType();
if (folderType == VALUES || folderType == LAYOUT || folderType == MENU) {
removeItemsFromFile(resourceFile);
} else if (folderType != null) {
// Remove the file item
List<ResourceType> resourceTypes = FolderTypeRelationship.getRelatedResourceTypes(folderType);
for (ResourceType type : resourceTypes) {
if (type != ResourceType.ID) {
String name = LintUtils.getBaseName(resourceFile.getName());
boolean removeFromFile = false; // no need since we're discarding the file
removeItems(resourceFile, type, name, removeFromFile);
}
}
} // else: not a resource folder
}
示例6: suggestName
import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
@NotNull
private String suggestName(EditorFixture editor) {
String currentFileName = editor.getCurrentFileName();
assertNotNull(currentFileName);
String prefix = this.getClass().getSimpleName() + "-" + getTestName();
String pngFileName = LintUtils.getBaseName(currentFileName) + DOT_PNG;
return THUMBNAIL_FOLDER + "/" + prefix + "-" + pngFileName;
}
示例7: visitSetContentView
import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
private void visitSetContentView(JavaContext context, MethodInvocation node) {
if (node.astArguments().size() != 1) return;
String argument = node.astArguments().first().toString();
String layoutName = argument.substring(9); //strip 'R.layout.'
String className = LintUtils.getBaseName(context.file.getName());
String expectedLayoutName = camelToUnderscore(className);
if (!expectedLayoutName.equals(layoutName)) {
context.report(ISSUE, context.getLocation(node),
String.format("Class '%s' should reference '%s' instead of '%s'.", className,
expectedLayoutName, layoutName));
}
}