use of org.jetbrains.android.dom.layout.LayoutDomFileDescription in project android by JetBrains.
the class AndroidXmlFormattingModelBuilder method getContextSpecificSettings.
@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;
}
use of org.jetbrains.android.dom.layout.LayoutDomFileDescription in project android by JetBrains.
the class AndroidMissingOnClickHandlerInspection method checkFile.
@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()]);
}
use of org.jetbrains.android.dom.layout.LayoutDomFileDescription in project android by JetBrains.
the class RtlSupportProcessor method performRefactoringForLayoutFile.
private void performRefactoringForLayoutFile(@NotNull final RtlRefactoringUsageInfo usageInfo) {
final PsiElement element = usageInfo.getElement();
assert element != null;
final XmlAttribute attribute = (XmlAttribute) element;
final int minSdk = usageInfo.getAndroidManifestMinSdkVersion();
if (!usageInfo.isCreateV17()) {
updateAttributeForElement(attribute, minSdk);
} else {
// We need first to create the v17 layout file, so first get our initial layout file
final PsiFile psiFile = element.getContainingFile();
final VirtualFile layoutFile = psiFile.getVirtualFile();
assert layoutFile != null;
final VirtualFile layoutDir = layoutFile.getParent();
assert layoutDir != null;
final VirtualFile layoutV17Dir = getLayoutV17(layoutDir, true);
assert layoutV17Dir != null;
final String layoutFileName = layoutFile.getName();
// Create the v17 file if needed (should be done only once)
if (layoutV17Dir.findChild(layoutFileName) == null) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
try {
layoutFile.copy(this, layoutV17Dir, layoutFileName);
} catch (IOException e) {
LOG.error("Cannot copy layout file " + quote(layoutFileName) + " from " + quote(layoutDir.getName()) + " directory to " + quote(layoutV17Dir.getName()) + " directory");
}
}
});
}
final VirtualFile layoutV17File = layoutV17Dir.findChild(layoutFileName);
assert layoutV17File != null;
final XmlFile xmlV17File = (XmlFile) PsiManager.getInstance(myProject).findFile(layoutV17File);
assert xmlV17File != null;
LOG.info("Processing refactoring for attribute: " + attribute.getName() + " into file: " + layoutV17File.getPath());
if (DomManager.getDomManager(myProject).getDomFileDescription((XmlFile) xmlV17File) instanceof LayoutDomFileDescription) {
xmlV17File.accept(new XmlRecursiveElementVisitor() {
@Override
public void visitXmlTag(XmlTag tag) {
super.visitXmlTag(tag);
final XmlAttribute attribute = tag.getAttribute(((XmlAttribute) element).getName());
if (attribute == null) {
return;
}
updateAttributeForElement(attribute, minSdk);
}
});
}
layoutV17File.refresh(true, /* asynchronous */
false);
}
}
use of org.jetbrains.android.dom.layout.LayoutDomFileDescription in project android by JetBrains.
the class AndroidMissingOnClickHandlerInspection method findRelatedActivities.
@NotNull
private static Collection<PsiClass> findRelatedActivities(@NotNull XmlFile file, @NotNull AndroidFacet facet, @NotNull DomFileDescription<?> description) {
if (description instanceof LayoutDomFileDescription) {
final Computable<List<GotoRelatedItem>> computable = AndroidGotoRelatedProvider.getLazyItemsForXmlFile(file, facet);
if (computable == null) {
return Collections.emptyList();
}
final List<GotoRelatedItem> items = computable.compute();
if (items.isEmpty()) {
return Collections.emptyList();
}
final PsiClass activityClass = findActivityClass(facet.getModule());
if (activityClass == null) {
return Collections.emptyList();
}
final List<PsiClass> result = new ArrayList<PsiClass>();
for (GotoRelatedItem item : items) {
final PsiElement element = item.getElement();
if (element instanceof PsiClass) {
final PsiClass aClass = (PsiClass) element;
if (aClass.isInheritor(activityClass, true)) {
result.add(aClass);
}
}
}
return result;
} else {
return findRelatedActivitiesForMenu(file, facet);
}
}
Aggregations