本文整理汇总了Java中org.jetbrains.android.util.AndroidUtils.loadDomElement方法的典型用法代码示例。如果您正苦于以下问题:Java AndroidUtils.loadDomElement方法的具体用法?Java AndroidUtils.loadDomElement怎么用?Java AndroidUtils.loadDomElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jetbrains.android.util.AndroidUtils
的用法示例。
在下文中一共展示了AndroidUtils.loadDomElement方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getManifest
import org.jetbrains.android.util.AndroidUtils; //导入方法依赖的package包/类
@Nullable
public Manifest getManifest(File file) {
if (!file.exists()) {
return null;
}
Manifest manifest = manifestFileMap.get(file);
// Note: The manifest may be invalid if the underlying VirtualFile is invalidated.
// Once invalid, it cannot become valid again, and must be reloaded.
if (manifest != null && manifest.isValid()) {
return manifest;
}
final VirtualFile virtualFile;
if (ApplicationManager.getApplication().isDispatchThread()) {
virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
} else {
virtualFile = LocalFileSystem.getInstance().findFileByIoFile(file);
}
if (virtualFile == null) {
LOG.error("Could not find manifest: " + file);
return null;
}
manifest = AndroidUtils.loadDomElement(project, virtualFile, Manifest.class);
manifestFileMap.put(file, manifest);
return manifest;
}
示例2: registerComponent
import org.jetbrains.android.util.AndroidUtils; //导入方法依赖的package包/类
protected static void registerComponent(String templateName,
PsiClass aClass,
PsiPackage aPackage,
AndroidFacet facet,
String label,
boolean startupActivity) {
final VirtualFile manifestFile = AndroidRootUtil.getManifestFile(facet);
if (manifestFile == null ||
!ReadonlyStatusHandler.ensureFilesWritable(facet.getModule().getProject(), manifestFile)) {
return;
}
final Manifest manifest = AndroidUtils.loadDomElement(facet.getModule(), manifestFile, Manifest.class);
if (manifest == null) {
return;
}
String packageName = manifest.getPackage().getValue();
if (packageName == null || packageName.length() == 0) {
manifest.getPackage().setValue(aPackage.getQualifiedName());
}
Application application = manifest.getApplication();
if (application == null) return;
ApplicationComponent component = addToManifest(templateName, aClass, application, startupActivity);
if (component != null && label.length() > 0) {
component.getLabel().setValue(ResourceValue.literal(label));
}
}
示例3: getRootDomElements
import org.jetbrains.android.util.AndroidUtils; //导入方法依赖的package包/类
private <T extends DomElement> List<Pair<T, VirtualFile>> getRootDomElements(@NotNull Class<T> elementType,
@Nullable Set<VirtualFile> files) {
final List<Pair<T, VirtualFile>> result = new ArrayList<Pair<T, VirtualFile>>();
for (VirtualFile file : getAllValueResourceFiles()) {
if ((files == null || files.contains(file)) && file.isValid()) {
final T element = AndroidUtils.loadDomElement(myProject, file, elementType);
if (element != null) {
result.add(Pair.create(element, file));
}
}
}
return result;
}
示例4: checkIfResourceAlreadyExists
import org.jetbrains.android.util.AndroidUtils; //导入方法依赖的package包/类
@Nullable
public static ValidationInfo checkIfResourceAlreadyExists(@NotNull Module selectedModule,
@NotNull String resourceName,
@NotNull ResourceType resourceType,
@NotNull List<String> dirNames,
@NotNull String fileName) {
if (resourceName.length() == 0 ||
dirNames.size() == 0 ||
fileName.length() == 0) {
return null;
}
final AndroidFacet facet = AndroidFacet.getInstance(selectedModule);
final VirtualFile resourceDir = facet != null ? facet.getPrimaryResourceDir() : null;
if (resourceDir == null) {
return null;
}
for (String directoryName : dirNames) {
final VirtualFile resourceSubdir = resourceDir.findChild(directoryName);
if (resourceSubdir == null) {
continue;
}
final VirtualFile resFile = resourceSubdir.findChild(fileName);
if (resFile == null) {
continue;
}
if (resFile.getFileType() != StdFileTypes.XML) {
return new ValidationInfo("File " + FileUtil.toSystemDependentName(resFile.getPath()) + " is not XML file");
}
final Resources resources = AndroidUtils.loadDomElement(selectedModule, resFile, Resources.class);
if (resources == null) {
return new ValidationInfo(AndroidBundle.message("not.resource.file.error", FileUtil.toSystemDependentName(resFile.getPath())));
}
for (ResourceElement element : AndroidResourceUtil.getValueResourcesFromElement(resourceType.getName(), resources)) {
if (resourceName.equals(element.getName().getValue())) {
return new ValidationInfo("resource '" + resourceName + "' already exists in " + FileUtil.toSystemDependentName(
resFile.getPath()));
}
}
}
return null;
}
示例5: computePackageName
import org.jetbrains.android.util.AndroidUtils; //导入方法依赖的package包/类
@Nullable
private String computePackageName(@NotNull final AndroidFacet facet) {
if (facet.getProperties().USE_CUSTOM_MANIFEST_PACKAGE) {
return facet.getProperties().CUSTOM_MANIFEST_PACKAGE;
}
else if (facet.getProperties().USE_CUSTOM_COMPILER_MANIFEST) {
// Ensure the local file system is up to date to enable accurate calculation of the package name.
LocalFileSystem.getInstance().refresh(false);
File manifestCopy = null;
final Manifest manifest;
final String manifestLocalPath;
try {
final Pair<File, String> pair = AndroidRunConfigurationBase.getCopyOfCompilerManifestFile(facet, getProcessHandler());
manifestCopy = pair != null ? pair.getFirst() : null;
VirtualFile manifestVFile = manifestCopy != null ? LocalFileSystem.getInstance().refreshAndFindFileByIoFile(manifestCopy) : null;
if (manifestVFile != null) {
manifestVFile.refresh(false, false);
manifest = AndroidUtils.loadDomElement(facet.getModule(), manifestVFile, Manifest.class);
}
else {
manifest = null;
}
manifestLocalPath = pair != null ? pair.getSecond() : null;
final Module module = facet.getModule();
final String moduleName = module.getName();
if (manifest == null) {
message("Cannot find " + SdkConstants.FN_ANDROID_MANIFEST_XML + " file for module " + moduleName, STDERR);
return null;
}
return ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
final GenericAttributeValue<String> packageAttrValue = manifest.getPackage();
final String aPackage = packageAttrValue.getValue();
if (aPackage == null || aPackage.isEmpty()) {
message("[" + moduleName + "] Main package is not specified in file " + manifestLocalPath, STDERR);
//noinspection ConstantConditions
return null;
}
return aPackage;
}
});
}
finally {
if (manifestCopy != null) {
FileUtil.delete(manifestCopy.getParentFile());
}
}
}
else {
String pkg = AndroidModuleInfo.get(facet).getPackage();
if (pkg == null || pkg.isEmpty()) {
message("[" + facet.getModule().getName() + "] Unable to obtain main package from manifest.", STDERR);
}
return pkg;
}
}
示例6: computeDefaultActivity
import org.jetbrains.android.util.AndroidUtils; //导入方法依赖的package包/类
@Nullable
@VisibleForTesting
static String computeDefaultActivity(@NotNull final AndroidFacet facet, @Nullable final ProcessHandler processHandler) {
if (!facet.getProperties().USE_CUSTOM_COMPILER_MANIFEST) {
final boolean useMergedManifest = facet.isGradleProject() || facet.getProperties().ENABLE_MANIFEST_MERGING;
final ManifestInfo manifestInfo = ManifestInfo.get(facet.getModule(), useMergedManifest);
return ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
return AndroidUtils.getDefaultLauncherActivityName(manifestInfo.getActivities(), manifestInfo.getActivityAliases());
}
});
}
File manifestCopy = null;
try {
final Pair<File, String> pair = getCopyOfCompilerManifestFile(facet, processHandler);
manifestCopy = pair != null ? pair.getFirst() : null;
VirtualFile manifestVFile = manifestCopy != null ? LocalFileSystem.getInstance().findFileByIoFile(manifestCopy) : null;
final Manifest manifest =
manifestVFile == null ? null : AndroidUtils.loadDomElement(facet.getModule(), manifestVFile, Manifest.class);
return ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Nullable
@Override
public String compute() {
if (manifest == null) {
if (processHandler != null) {
processHandler.notifyTextAvailable("Cannot find " + SdkConstants.FN_ANDROID_MANIFEST_XML + " file\n", STDERR);
}
return null;
}
return AndroidUtils.getDefaultLauncherActivityName(manifest);
}
});
}
finally {
if (manifestCopy != null) {
FileUtil.delete(manifestCopy.getParentFile());
}
}
}