From 661482ec8fe1f8a1900073acab86225d4fe15592 Mon Sep 17 00:00:00 2001 From: Sergey Vasiliev Date: Fri, 16 Mar 2007 10:36:27 +0300 Subject: [PATCH] added generate spring elements actions --- .../xml/impl/DomElementsNavigationManagerImpl.java | 11 +++++++--- .../generate/DefaultGenerateElementProvider.java | 24 ++++++++++++++-------- .../generate/GenerateDomElementProvider.java | 10 +++++---- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/dom/impl/src/com/intellij/util/xml/impl/DomElementsNavigationManagerImpl.java b/dom/impl/src/com/intellij/util/xml/impl/DomElementsNavigationManagerImpl.java index 383bff8fc7..ad54ff1d20 100644 --- a/dom/impl/src/com/intellij/util/xml/impl/DomElementsNavigationManagerImpl.java +++ b/dom/impl/src/com/intellij/util/xml/impl/DomElementsNavigationManagerImpl.java @@ -8,6 +8,8 @@ import com.intellij.openapi.fileEditor.OpenFileDescriptor; import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.xml.XmlAttribute; +import com.intellij.psi.xml.XmlElement; import com.intellij.util.xml.DomElement; import com.intellij.util.xml.DomElementNavigationProvider; import com.intellij.util.xml.DomElementsNavigationManager; @@ -55,10 +57,13 @@ public class DomElementsNavigationManagerImpl extends DomElementsNavigationManag } public void navigate(DomElement domElement, boolean requestFocus) { - VirtualFile file = domElement.getRoot().getFile().getVirtualFile(); - final OpenFileDescriptor fileDescriptor = domElement.getXmlTag() != null ? - new OpenFileDescriptor(myProject, file, domElement.getXmlTag().getTextOffset()) : + if (file == null) return; + + XmlElement xmlElement = domElement.getXmlElement(); + if (xmlElement instanceof XmlAttribute) xmlElement = ((XmlAttribute)xmlElement).getValueElement(); + final OpenFileDescriptor fileDescriptor = xmlElement != null ? + new OpenFileDescriptor(myProject, file, xmlElement.getTextOffset()) : new OpenFileDescriptor(myProject, file); FileEditorManagerEx.getInstanceEx(myProject).openTextEditor(fileDescriptor, requestFocus); diff --git a/dom/openapi/src/com/intellij/util/xml/ui/actions/generate/DefaultGenerateElementProvider.java b/dom/openapi/src/com/intellij/util/xml/ui/actions/generate/DefaultGenerateElementProvider.java index 5a80a21699..699414106b 100644 --- a/dom/openapi/src/com/intellij/util/xml/ui/actions/generate/DefaultGenerateElementProvider.java +++ b/dom/openapi/src/com/intellij/util/xml/ui/actions/generate/DefaultGenerateElementProvider.java @@ -6,34 +6,40 @@ import com.intellij.psi.PsiFile; import com.intellij.util.ReflectionUtil; import com.intellij.util.xml.DomElement; import com.intellij.util.xml.reflect.DomCollectionChildDescription; +import org.jetbrains.annotations.Nullable; import java.util.List; /** * User: Sergey.Vasiliev */ -public abstract class DefaultGenerateElementProvider extends GenerateDomElementProvider { +public abstract class DefaultGenerateElementProvider extends GenerateDomElementProvider { private Class myChildElementClass; - public DefaultGenerateElementProvider(final String name, Class childElementClass) { - super(name); + public DefaultGenerateElementProvider(final String name, Class childElementClass) { + super(name); myChildElementClass = childElementClass; } - public DomElement generate(final Project project, final Editor editor, final PsiFile file) { + @Nullable + public T generate(final Project project, final Editor editor, final PsiFile file) { return generate(getParentDomElement(project, editor, file)); } + @Nullable protected abstract DomElement getParentDomElement(final Project project, final Editor editor, final PsiFile file); - public DomElement generate(final DomElement parent) { - final List list = parent.getGenericInfo().getCollectionChildrenDescriptions(); + @Nullable + public T generate(@Nullable final DomElement parent) { + if (parent != null) { + final List list = parent.getGenericInfo().getCollectionChildrenDescriptions(); - for (DomCollectionChildDescription childDescription : list) { - if (ReflectionUtil.getRawType(childDescription.getType()).isAssignableFrom(myChildElementClass)) { - return childDescription.addValue(parent, myChildElementClass); + for (DomCollectionChildDescription childDescription : list) { + if (ReflectionUtil.getRawType(childDescription.getType()).isAssignableFrom(myChildElementClass)) { + return (T)childDescription.addValue(parent, myChildElementClass); + } } } diff --git a/dom/openapi/src/com/intellij/util/xml/ui/actions/generate/GenerateDomElementProvider.java b/dom/openapi/src/com/intellij/util/xml/ui/actions/generate/GenerateDomElementProvider.java index 0f2f9c0977..dffe3a4b33 100644 --- a/dom/openapi/src/com/intellij/util/xml/ui/actions/generate/GenerateDomElementProvider.java +++ b/dom/openapi/src/com/intellij/util/xml/ui/actions/generate/GenerateDomElementProvider.java @@ -1,12 +1,13 @@ package com.intellij.util.xml.ui.actions.generate; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiFile; import com.intellij.util.xml.DomElement; import com.intellij.util.xml.DomElementNavigationProvider; import com.intellij.util.xml.DomElementsNavigationManager; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.Nullable; /** * User: Sergey.Vasiliev @@ -18,6 +19,7 @@ public abstract class GenerateDomElementProvider { myDescription = description; } + @Nullable public abstract T generate(final Project project, final Editor editor, final PsiFile file); public void navigate(final DomElement element) { -- 2.11.4.GIT