use of com.intellij.util.xml.DomManager in project intellij-community by JetBrains.
the class AntSupport method getAntDomProject.
//
// Managing ant files dependencies via the <import> task.
//
@Nullable
public static AntDomProject getAntDomProject(PsiFile psiFile) {
if (psiFile instanceof XmlFile) {
final DomManager domManager = DomManager.getDomManager(psiFile.getProject());
final DomFileElement<AntDomProject> fileElement = domManager.getFileElement((XmlFile) psiFile, AntDomProject.class);
return fileElement != null ? fileElement.getRootElement() : null;
}
return null;
}
use of com.intellij.util.xml.DomManager in project intellij-community by JetBrains.
the class AntSupport method getAntDomProjectForceAntFile.
@Nullable
public static AntDomProject getAntDomProjectForceAntFile(PsiFile psiFile) {
if (psiFile instanceof XmlFile) {
final DomManager domManager = DomManager.getDomManager(psiFile.getProject());
DomFileElement<AntDomProject> fileElement = domManager.getFileElement((XmlFile) psiFile, AntDomProject.class);
if (fileElement == null) {
ForcedAntFileAttribute.forceAntFile(psiFile.getVirtualFile(), true);
fileElement = domManager.getFileElement((XmlFile) psiFile, AntDomProject.class);
}
return fileElement != null ? fileElement.getRootElement() : null;
}
return null;
}
use of com.intellij.util.xml.DomManager in project intellij-community by JetBrains.
the class MavenGroovyPomScriptMemberContributor method processDynamicElements.
@Override
public void processDynamicElements(@NotNull PsiType qualifierType, PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) {
PsiElement pomElement = aClass.getContainingFile().getContext();
if (pomElement == null)
return;
PsiFile pomFile = pomElement.getContainingFile();
if (!(pomFile instanceof XmlFile))
return;
DomManager domManager = DomManager.getDomManager(pomElement.getProject());
if (!(domManager.getDomFileDescription((XmlFile) pomFile) instanceof MavenDomProjectModelDescription)) {
return;
}
DynamicMemberUtils.process(processor, false, place, CLASS_SOURCE);
}
use of com.intellij.util.xml.DomManager in project intellij-community by JetBrains.
the class MockDomElementsEditor method createMockElement.
private <T extends DomElement> T createMockElement(final Class<T> aClass, final Module module) {
final Project project = module.getProject();
ApplicationManager.getApplication().invokeLater(() -> {
if (myFileEditor.isInitialised()) {
myContents.reset();
}
});
final DomManager domManager = DomManager.getDomManager(project);
final T mockElement = domManager.createMockElement(aClass, module, true);
if (myFileEditor != null) {
myFileEditor.addWatchedElement(mockElement);
}
return mockElement;
}
use of com.intellij.util.xml.DomManager in project intellij-community by JetBrains.
the class MockDomElementsEditor method initFileEditor.
protected final DomFileEditor initFileEditor(final Project project, final VirtualFile virtualFile, final String name, final Factory<? extends BasicDomElementComponent> component) {
myFileEditor = new DomFileEditor<BasicDomElementComponent>(project, virtualFile, name, component) {
@Override
public JComponent getPreferredFocusedComponent() {
return null;
}
@Override
@NotNull
protected JComponent createCustomComponent() {
final JComponent customComponent = super.createCustomComponent();
myContents = getDomComponent();
return customComponent;
}
@Override
public void reset() {
for (final Map.Entry<EditedElementDescription<? extends DomElement>, DomElement> entry : myDomElements.entrySet()) {
final DomElement newValue = entry.getKey().find();
final DomElement oldValue = entry.getValue();
if (newValue != null && !newValue.equals(oldValue) || newValue == null && !oldValue.getManager().isMockElement(oldValue)) {
((StableElement) oldValue).revalidate();
}
}
super.reset();
}
@Override
public void commit() {
super.commit();
final List<EditedElementDescription> descriptions = new ArrayList<>();
final Set<PsiFile> changedFiles = new HashSet<>();
for (final Map.Entry<EditedElementDescription<? extends DomElement>, DomElement> entry : myDomElements.entrySet()) {
final EditedElementDescription description = entry.getKey();
final DomElement editedElement = entry.getValue();
if (description.find() == null && editedElement.getXmlTag() != null) {
descriptions.add(description);
final XmlFile xmlFile = description.getEditedFile();
if (xmlFile != null) {
changedFiles.add(xmlFile);
}
}
}
new WriteCommandAction(project, PsiUtilCore.toPsiFileArray(changedFiles)) {
@Override
protected void run(@NotNull Result result) throws Throwable {
for (EditedElementDescription description : descriptions) {
final DomElement editedElement = myDomElements.get(description);
DomElement element = description.addElement();
element.copyFrom(editedElement);
description.initialize(element);
removeWatchedElement(editedElement);
((StableElement) editedElement).invalidate();
}
}
}.execute();
}
};
final DomManager domManager = DomManager.getDomManager(project);
for (final DomElement element : myDomElements.values()) {
if (domManager.isMockElement(element)) {
myFileEditor.addWatchedElement(element);
}
}
return myFileEditor;
}
Aggregations