本文整理汇总了Java中org.jetbrains.android.facet.AndroidFacet类的典型用法代码示例。如果您正苦于以下问题:Java AndroidFacet类的具体用法?Java AndroidFacet怎么用?Java AndroidFacet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AndroidFacet类属于org.jetbrains.android.facet包,在下文中一共展示了AndroidFacet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: forkResourceValue
import org.jetbrains.android.facet.AndroidFacet; //导入依赖的package包/类
protected static void forkResourceValue(@NotNull Project project, @NotNull XmlTag tag, @NotNull PsiFile file,
@NotNull AndroidFacet facet, @Nullable PsiDirectory dir) {
PsiDirectory resFolder = findRes(file);
if (resFolder == null) {
return; // shouldn't happen; we checked in isAvailable
}
String name = tag.getAttributeValue(ATTR_NAME);
ResourceType type = AndroidResourceUtil.getResourceForResourceTag(tag);
if (name == null || type == null) {
return; // shouldn't happen; we checked in isAvailable
}
if (dir == null) {
dir = selectFolderDir(project, resFolder.getVirtualFile(), ResourceFolderType.VALUES);
}
if (dir != null) {
String value = PsiResourceItem.getTextContent(tag).trim();
createValueResource(file, facet, dir, name, value, type, tag.getText());
}
}
示例2: isAvailableOnElementInEditorAndFile
import org.jetbrains.android.facet.AndroidFacet; //导入依赖的package包/类
@Override
protected boolean isAvailableOnElementInEditorAndFile(@NotNull PsiElement element, @NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext context) {
final XmlTag[] tags = getXmlTagsFromExternalContext(context);
if (tags.length > 0) {
return AndroidFacet.getInstance(tags[0]) != null && isEnabledForTags(tags);
}
final TextRange range = getNonEmptySelectionRange(editor);
if (range != null) {
final Pair<PsiElement, PsiElement> psiRange = getExtractableRange(
file, range.getStartOffset(), range.getEndOffset());
return psiRange != null && isEnabledForPsiRange(psiRange.getFirst(), psiRange.getSecond());
}
if (element == null ||
AndroidFacet.getInstance(element) == null ||
PsiTreeUtil.getParentOfType(element, XmlText.class) != null) {
return false;
}
final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
return tag != null && isEnabledForTags(new XmlTag[]{tag});
}
示例3: getAndroidLibraryDependencies
import org.jetbrains.android.facet.AndroidFacet; //导入依赖的package包/类
@NotNull
public static List<AndroidFacet> getAndroidLibraryDependencies(@NotNull Module module) {
final List<AndroidFacet> depFacets = new ArrayList<AndroidFacet>();
for (OrderEntry orderEntry : ModuleRootManager.getInstance(module).getOrderEntries()) {
if (orderEntry instanceof ModuleOrderEntry) {
final ModuleOrderEntry moduleOrderEntry = (ModuleOrderEntry)orderEntry;
if (moduleOrderEntry.getScope() == DependencyScope.COMPILE) {
final Module depModule = moduleOrderEntry.getModule();
if (depModule != null) {
final AndroidFacet depFacet = AndroidFacet.getInstance(depModule);
if (depFacet != null && depFacet.isLibraryProject()) {
depFacets.add(depFacet);
}
}
}
}
}
return depFacets;
}
示例4: updateLibraryProperty
import org.jetbrains.android.facet.AndroidFacet; //导入依赖的package包/类
public static void updateLibraryProperty(@NotNull AndroidFacet facet,
@NotNull final PropertiesFile propertiesFile,
@NotNull List<Runnable> changes) {
final IProperty property = propertiesFile.findPropertyByKey(AndroidUtils.ANDROID_LIBRARY_PROPERTY);
if (property != null) {
final String value = Boolean.toString(facet.isLibraryProject());
if (!value.equals(property.getValue())) {
changes.add(new Runnable() {
@Override
public void run() {
property.setValue(value);
}
});
}
}
else if (facet.isLibraryProject()) {
changes.add(new Runnable() {
示例5: findIdFields
import org.jetbrains.android.facet.AndroidFacet; //导入依赖的package包/类
@NotNull
public static PsiField[] findIdFields(@NotNull XmlAttribute attribute) {
final XmlAttributeValue value = attribute.getValueElement();
if (value != null && isIdDeclaration(value)) {
final String id = getResourceNameByReferenceText(attribute.getValue());
if (id != null) {
final AndroidFacet facet = AndroidFacet.getInstance(attribute);
if (facet != null) {
return findResourceFields(facet, ResourceType.ID.getName(), id, false);
}
}
}
return PsiField.EMPTY_ARRAY;
}
示例6: getLayoutUsageDataFromContext
import org.jetbrains.android.facet.AndroidFacet; //导入依赖的package包/类
@Nullable
private static LayoutUsageData getLayoutUsageDataFromContext(Editor editor) {
if (editor == null) {
return null;
}
final PsiElement element = PsiUtilBase.getElementAtCaret(editor);
if (!(element instanceof XmlToken) ||
AndroidFacet.getInstance(element) == null) {
return null;
}
final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
return tag != null
? AndroidInlineUtil.getLayoutUsageData(tag)
: null;
}
示例7: getCopyOfCompilerManifestFile
import org.jetbrains.android.facet.AndroidFacet; //导入依赖的package包/类
@Nullable
protected static Pair<File, String> getCopyOfCompilerManifestFile(@NotNull AndroidFacet facet, @Nullable ProcessHandler processHandler) {
final VirtualFile manifestFile = AndroidRootUtil.getCustomManifestFileForCompiler(facet);
if (manifestFile == null) {
return null;
}
File tmpDir = null;
try {
tmpDir = FileUtil.createTempDirectory("android_manifest_file_for_execution", "tmp");
final File manifestCopy = new File(tmpDir, manifestFile.getName());
FileUtil.copy(new File(manifestFile.getPath()), manifestCopy);
//noinspection ConstantConditions
return Pair.create(manifestCopy, PathUtil.getLocalPath(manifestFile));
}
catch (IOException e) {
if (processHandler != null) {
processHandler.notifyTextAvailable("I/O error: " + e.getMessage(), ProcessOutputTypes.STDERR);
}
LOG.info(e);
if (tmpDir != null) {
FileUtil.delete(tmpDir);
}
return null;
}
}
示例8: checkFile
import org.jetbrains.android.facet.AndroidFacet; //导入依赖的package包/类
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
if (!(file instanceof XmlFile)) {
return ProblemDescriptor.EMPTY_ARRAY;
}
AndroidFacet facet = AndroidFacet.getInstance(file);
if (facet == null) {
return ProblemDescriptor.EMPTY_ARRAY;
}
if (AndroidUnknownAttributeInspection.isMyFile(facet, (XmlFile)file)) {
MyVisitor visitor = new MyVisitor(manager, isOnTheFly);
file.accept(visitor);
return visitor.myResult.toArray(new ProblemDescriptor[visitor.myResult.size()]);
}
return ProblemDescriptor.EMPTY_ARRAY;
}
示例9: getResourceSourceSetsWithTargetDirectory
import org.jetbrains.android.facet.AndroidFacet; //导入依赖的package包/类
/**
* If we have a resource module and a target directory, then we can get the res dir from the
* module, and use the target directory for everything else.
*/
@Test
public void getResourceSourceSetsWithTargetDirectory() {
AndroidFacet facet = mockResourceFacet();
File resourceFile = VfsUtilCore.virtualToIoFile(resource);
File targetFile = VfsUtilCore.virtualToIoFile(target);
List<AndroidSourceSet> sourceSets = AndroidSourceSet.getSourceSets(facet, target);
assertThat(sourceSets).hasSize(1);
AndroidSourceSet sourceSet = sourceSets.get(0);
AndroidProjectPaths paths = sourceSet.getPaths();
assertThat(sourceSet.getName()).isEqualTo("com.google.target");
assertThat(paths.getModuleRoot()).isEqualTo(resourceFile);
assertThat(paths.getSrcDirectory(null)).isEqualTo(targetFile);
assertThat(paths.getTestDirectory(null)).isEqualTo(targetFile);
assertThat(paths.getResDirectory()).isEqualTo(new File(resourceFile, "res"));
assertThat(paths.getAidlDirectory(null)).isEqualTo(targetFile);
assertThat(paths.getManifestDirectory()).isEqualTo(targetFile);
}
示例10: doGetInnerClasses
import org.jetbrains.android.facet.AndroidFacet; //导入依赖的package包/类
private PsiClass[] doGetInnerClasses() {
if (DumbService.isDumb(getProject())) {
LOG.debug("R_CLASS_AUGMENT: empty because of dumb mode");
return new PsiClass[0];
}
final AndroidFacet facet = AndroidFacet.getInstance(myModule);
if (facet == null) {
LOG.debug("R_CLASS_AUGMENT: empty because no facet");
return new PsiClass[0];
}
final Set<ResourceType> types =
ResourceReferenceConverter.getResourceTypesInCurrentModule(facet);
final List<PsiClass> result = new ArrayList<>();
for (ResourceType type : types) {
result.add(new ResourceTypeClass(facet, type.getName(), this));
}
LOG.debug("R_CLASS_AUGMENT: " + result.size() + " classes added");
return result.toArray(new PsiClass[result.size()]);
}
示例11: checkFile
import org.jetbrains.android.facet.AndroidFacet; //导入依赖的package包/类
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
if (!(file instanceof XmlFile)) {
return ProblemDescriptor.EMPTY_ARRAY;
}
final AndroidFacet facet = AndroidFacet.getInstance(file);
if (facet == null) {
return ProblemDescriptor.EMPTY_ARRAY;
}
final DomFileDescription<?> description = DomManager.getDomManager(file.getProject()).getDomFileDescription((XmlFile)file);
if (!(description instanceof LayoutDomFileDescription) &&
!(description instanceof MenuDomFileDescription)) {
return ProblemDescriptor.EMPTY_ARRAY;
}
final Collection<PsiClass> activities = findRelatedActivities((XmlFile)file, facet, description);
final MyVisitor visitor = new MyVisitor(manager, isOnTheFly, activities);
file.accept(visitor);
return visitor.myResult.toArray(new ProblemDescriptor[visitor.myResult.size()]);
}
示例12: getHighestApi
import org.jetbrains.android.facet.AndroidFacet; //导入依赖的package包/类
private static int getHighestApi(PsiElement element) {
int max = SdkVersionInfo.HIGHEST_KNOWN_STABLE_API;
AndroidFacet instance = AndroidFacet.getInstance(element);
if (instance != null) {
AndroidSdkData sdkData = instance.getSdkData();
if (sdkData != null) {
for (IAndroidTarget target : sdkData.getTargets()) {
if (target.isPlatform()) {
AndroidVersion version = target.getVersion();
if (version.getApiLevel() > max && !version.isPreview()) {
max = version.getApiLevel();
}
}
}
}
}
return max;
}
示例13: findAttributeDefinitionGlobally
import org.jetbrains.android.facet.AndroidFacet; //导入依赖的package包/类
@Nullable
private static AttributeDefinition findAttributeDefinitionGlobally(@NotNull AndroidFacet facet,
@NotNull String namespace,
@NotNull String localName) {
ResourceManager resourceManager;
if (ANDROID_URI.equals(namespace) || TOOLS_URI.equals(namespace)) {
resourceManager = facet.getSystemResourceManager();
}
else if (namespace.equals(AUTO_URI) || namespace.startsWith(URI_PREFIX)) {
resourceManager = facet.getLocalResourceManager();
}
else {
resourceManager = facet.getSystemResourceManager();
}
if (resourceManager != null) {
final AttributeDefinitions attrDefs = resourceManager.getAttributeDefinitions();
if (attrDefs != null) {
return attrDefs.getAttrDefByName(localName);
}
}
return null;
}
示例14: getContextSpecificSettings
import org.jetbrains.android.facet.AndroidFacet; //导入依赖的package包/类
@Nullable
private static ContextSpecificSettingsProviders.Provider getContextSpecificSettings(PsiElement context) {
final PsiFile file = context.getContainingFile();
if (!(file instanceof XmlFile) ||
AndroidFacet.getInstance(file) == null) {
return null;
}
final DomFileDescription<?> description = DomManager.getDomManager(
context.getProject()).getDomFileDescription((XmlFile)file);
if (description instanceof LayoutDomFileDescription) {
return ContextSpecificSettingsProviders.LAYOUT;
}
else if (description instanceof ManifestDomFileDescription) {
return ContextSpecificSettingsProviders.MANIFEST;
}
else if (description instanceof ResourcesDomFileDescription ||
description instanceof DrawableStateListDomFileDescription ||
description instanceof ColorDomFileDescription) {
return ContextSpecificSettingsProviders.VALUE_RESOURCE_FILE;
}
else if (description instanceof AndroidResourceDomFileDescription) {
return ContextSpecificSettingsProviders.OTHER;
}
return null;
}
示例15: isAvailable
import org.jetbrains.android.facet.AndroidFacet; //导入依赖的package包/类
public boolean isAvailable(@Nullable XmlTag tag, PsiFile file) {
if (file instanceof XmlFile && file.isValid() && AndroidFacet.getInstance(file) != null) {
ResourceFolderType folderType = ResourceHelper.getFolderType(file);
if (folderType == null) {
return false;
} else if (folderType != ResourceFolderType.VALUES) {
return true;
} else {
// In value files, you can invoke this action if the caret is on or inside an element (other than the
// root <resources> tag). Only accept the element if it has a known type with a known name.
if (tag != null && tag.getAttributeValue(ATTR_NAME) != null) {
return AndroidResourceUtil.getResourceForResourceTag(tag) != null;
}
}
}
return false;
}