use of com.intellij.util.xml.DomManager in project android by JetBrains.
the class AndroidApplicationPackageRenameProcessor method processAllClassAttrValues.
private static void processAllClassAttrValues(@NotNull XmlFile file, @NotNull final Processor<Pair<GenericAttributeValue, PsiClass>> processor) {
final DomManager domManager = DomManager.getDomManager(file.getProject());
file.accept(new XmlRecursiveElementVisitor() {
@Override
public void visitXmlAttribute(XmlAttribute attribute) {
final GenericAttributeValue domAttrValue = domManager.getDomElement(attribute);
if (domAttrValue != null) {
final Object value = domAttrValue.getValue();
if (value instanceof PsiClass) {
processor.process(Pair.create(domAttrValue, (PsiClass) value));
}
}
}
});
}
use of com.intellij.util.xml.DomManager in project android by JetBrains.
the class AndroidDomElementDescriptorProvider method getDomElementAndBaseClassQName.
@Nullable
public static Pair<AndroidDomElement, String> getDomElementAndBaseClassQName(@NotNull XmlTag tag) {
final PsiFile file = tag.getContainingFile();
if (!(file instanceof XmlFile))
return null;
Project project = file.getProject();
if (project.isDefault())
return null;
final DomManager domManager = DomManager.getDomManager(project);
if (domManager.getFileElement((XmlFile) file, AndroidDomElement.class) == null)
return null;
final DomElement domElement = domManager.getDomElement(tag);
if (!(domElement instanceof AndroidDomElement)) {
return null;
}
String className = null;
if (domElement instanceof LayoutViewElement) {
className = AndroidUtils.VIEW_CLASS_NAME;
} else if (domElement instanceof XmlResourceElement) {
className = SdkConstants.CLASS_PREFERENCE;
}
return Pair.create((AndroidDomElement) domElement, className);
}
use of com.intellij.util.xml.DomManager in project android by JetBrains.
the class DataBindingCompletionUtil method fillAliases.
/**
* Add completion suggestions for classes included via {@code <import>}s.
* @param resultSet the set to add the suggestions to.
*/
private static void fillAliases(@NotNull CompletionResultSet resultSet, @NotNull String packagePrefix, @NotNull PsiElement originalPosition, @NotNull Module module, @NotNull PsiElement originalParent) {
PsiFile containingFile = getRealContainingFile(originalParent.getContainingFile());
if (containingFile instanceof XmlFile) {
final Project project = module.getProject();
DomManager domManager = DomManager.getDomManager(project);
XmlTag tag = PsiTreeUtil.getParentOfType(originalPosition, XmlTag.class, false, PsiFile.class);
if (domManager.getDomElement(tag) instanceof Import) {
// No referencing aliases in import tags.
return;
}
DomFileElement<Layout> file = domManager.getFileElement((XmlFile) containingFile, Layout.class);
if (file != null) {
JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
for (Data data : file.getRootElement().getDatas()) {
for (Import anImport : data.getImports()) {
String alias = AndroidLayoutUtil.getAlias(anImport);
if (packagePrefix.isEmpty()) {
XmlAttributeValue type = anImport.getType().getXmlAttributeValue();
if (type != null && alias != null) {
String typeValue = type.getValue().replace('$', '.');
PsiClass aClass = facade.findClass(typeValue, module.getModuleWithDependenciesAndLibrariesScope(false));
if (aClass != null) {
resultSet.addElement(getClassReferenceElement(alias, aClass));
}
}
} else {
int i = packagePrefix.indexOf('.');
String possibleAlias = i < 0 ? packagePrefix : packagePrefix.substring(0, i);
if (possibleAlias.equals(alias)) {
String type = anImport.getType().getStringValue();
if (type != null) {
String fqcn = packagePrefix.equals(alias) ? type : type + packagePrefix.substring(alias.length());
PsiClass aClass = facade.findClass(fqcn, module.getModuleWithDependenciesAndLibrariesScope(false));
if (aClass != null) {
for (PsiClass innerClass : aClass.getInnerClasses()) {
String name = innerClass.getQualifiedName();
if (name != null) {
resultSet.addElement(getClassReferenceElement(name.substring(type.length() + 1), innerClass));
}
}
break;
}
}
}
}
}
}
}
}
}
use of com.intellij.util.xml.DomManager in project android by JetBrains.
the class AndroidExtractAsIncludeAction method isEnabledForTags.
@Override
protected boolean isEnabledForTags(@NotNull XmlTag[] tags) {
if (tags.length == 0) {
return false;
}
final DomManager domManager = DomManager.getDomManager(tags[0].getProject());
boolean containsViewElement = false;
for (XmlTag tag : tags) {
final DomElement domElement = domManager.getDomElement(tag);
if (!isSuitableDomElement(domElement)) {
return false;
}
if (domElement instanceof LayoutViewElement) {
containsViewElement = true;
}
}
if (!containsViewElement) {
return false;
}
final PsiElement parent = tags[0].getParent();
if (!(parent instanceof XmlTag) || parent.getContainingFile() == null) {
return false;
}
for (int i = 1; i < tags.length; i++) {
if (tags[i].getParent() != parent) {
return false;
}
}
return true;
}
use of com.intellij.util.xml.DomManager in project intellij-community by JetBrains.
the class AntSupport method getAntLib.
@Nullable
public static AntDomAntlib getAntLib(PsiFile psiFile) {
if (psiFile instanceof XmlFile) {
final DomManager domManager = DomManager.getDomManager(psiFile.getProject());
final DomFileElement<AntDomAntlib> fileElement = domManager.getFileElement((XmlFile) psiFile, AntDomAntlib.class);
return fileElement != null ? fileElement.getRootElement() : null;
}
return null;
}
Aggregations