当前位置: 首页>>代码示例>>Java>>正文


Java LintUtils.getBaseName方法代码示例

本文整理汇总了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));
            }
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:ResourcePrefixDetector.java

示例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));
            }
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:ResourcePrefixDetector.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:41,代码来源:AndroidResourceRenameResourceProcessor.java

示例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());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:ResourceHelper.java

示例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
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:ResourceFolderRepository.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:LayoutPreviewTest.java

示例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));
  }
}
 
开发者ID:a11n,项目名称:CustomLintRulesWorkshop,代码行数:16,代码来源:LayoutNamesDetector.java


注:本文中的com.android.tools.lint.detector.api.LintUtils.getBaseName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。