region navigation

I'd like to know if you have considered a region navigation dialog, much
like ctrl+f12.

It should handle multiple region with the same name, probably decorated
with class/method name plus a unique number ...

Thanks
Federico

2 comments
Comment actions Permalink

No. Can you give a sample use-case when such navigation is needed?

--
Andrey Simanovsky
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"



"federico" <f.spinazzi@masterhouse.it> wrote in message
news:cd5reb$h42$1@is.intellij.net...

I'd like to know if you have considered a region navigation dialog, much
like ctrl+f12.

>

It should handle multiple region with the same name, probably decorated
with class/method name plus a unique number ...

>

Thanks
Federico

>


0
Comment actions Permalink

Andrey Simanovsky (JetBrains) wrote:

No. Can you give a sample use-case when such navigation is needed?

I think that it can better support those cases when there are coding
conventions using regions heavily and
- you need to put new code into it
- you want to review the source code
- you want to adhere to such conventions

I'm attaching a sample file
Thank you very much
Federico
#region Licence

/*

  • Copyright 2002-2004 the original author or authors.

*

  • Licensed under the Apache License, Version 2.0 (the "License");

  • you may not use this file except in compliance with the License.

  • You may obtain a copy of the License at

*

*

  • Unless required by applicable law or agreed to in writing, software

  • distributed under the License is distributed on an "AS IS" BASIS,

  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

  • See the License for the specific language governing permissions and

  • limitations under the License.

*/

#endregion

#region Imports

using System;
using System.Reflection;
using System.Xml;
using System.Text;
using System.Collections;
using System.Collections.Specialized;

using Spring.Util;
using Spring.Core.IO;
using Spring.Objects.Factory.Config;
using Spring.Objects.Factory.Support;

using log4net;
using Iesi.Collections;

#endregion

namespace Spring.Objects.Factory.Xml
{

/// /// Default implementation of the /// interface. /// /// ///

/// Parses object definitions according to the "spring-objects" DTD. ///

/// /// Rod Johnson /// Juergen Hoeller /// Rick Evans (.NET) public class DefaultXmlObjectDefinitionParser : IXmlObjectDefinitionParser { #region Constants /// /// The string of characters that delimit object names. /// public const string ObjectNameDelimeters = ",; "; /// /// The shared ILog instance for this class (and derived classes). /// protected static readonly ILog logger = LogManager.GetLogger (typeof (DefaultXmlObjectDefinitionParser)); #endregion #region Constructor (s) / Destructor /// /// Creates a new instance of the DefaultXmlObjectDefinitionParser class. /// public DefaultXmlObjectDefinitionParser () { } #endregion #region Properties /// /// The /// that is being (or is to be) populated with object definitions. /// protected IObjectDefinitionRegistry ObjectFactory { get { return _objectFactory; } } /// /// Are objects to be lazily initalised (Singletons only)? /// protected string DefaultLazyInit { get { return _defaultLazyInit; } } /// /// Is the default dependency check on? /// protected string DefaultDependencyCheck { get { return _defaultDependencyCheck; } } /// /// Resolve string type names to instances? /// protected bool ResolveTypes { get { return _resolveTypes; } } /// /// Is autowiring to be performed? /// protected string DefaultAutowire { get { return _defaultAutowire; } } #endregion #region Methods /// /// Parse object definitions from the given DOM node, and register them with the /// given object registry. /// /// /// The object registry to register the object definition (s) with. /// /// /// The DOM document containing object definitions. /// /// /// Descriptor of the original XML resource (useful for displaying parse errors). /// /// /// Resolve string type names to instances? /// /// /// In case of (parsing) errors. /// public virtual void RegisterObjectDefinitions ( IObjectDefinitionRegistry objectRegistry, XmlDocument doc, IResource resource, bool resolveTypes) { RegisterObjectDefinitions ( objectRegistry, doc.DocumentElement, resource, resolveTypes); } /// /// Parse object definitions from the given DOM node, and register them with the /// given object registry. /// /// /// The object registry to register the object definition (s) with. /// /// /// The DOM element containing object definitions (usually the root). /// /// /// Descriptor of the original XML resource (useful for displaying parse errors). /// /// /// Resolve string type names to instances? /// /// /// In case of (parsing) errors. /// ]]>
public virtual void RegisterObjectDefinitions (
IObjectDefinitionRegistry objectRegistry,
XmlElement root,
IResource resource,
bool resolveTypes)
{
_objectFactory = objectRegistry;
_resolveTypes = resolveTypes;
_resource = resource;

#region Instrumentation
if (logger.IsDebugEnabled)
{
logger.Debug ("Loading object definitions...");
}
#endregion

_defaultLazyInit = root.GetAttribute (ObjectsDtd.DefaultLazyInitAttribute);

#region Instrumentation
if (logger.IsDebugEnabled)
{
logger.Debug (
string.Format (
System.Globalization.CultureInfo.CurrentUICulture,
"Default lazy init '{0}'.",
DefaultLazyInit));
}
#endregion

_defaultDependencyCheck = root.GetAttribute (ObjectsDtd.DefaultDependencyCheckAttribute);

#region Instrumentation
if (logger.IsDebugEnabled)
{
logger.Debug (
string.Format (
System.Globalization.CultureInfo.CurrentUICulture,
"Default dependency check '{0}'.",
DefaultDependencyCheck));
}
#endregion

_defaultAutowire = root.GetAttribute (ObjectsDtd.DefaultAutowireAttribute);

#region Instrumentation
if (logger.IsDebugEnabled)
{
logger.Debug (
string.Format (
System.Globalization.CultureInfo.CurrentUICulture,
"Default autowire '{0}'.",
DefaultAutowire));
}
#endregion

int objectDefinitionCounter = 0;
foreach (XmlNode node in root.SelectNodes (ObjectsDtd.ObjectElement))
{
++objectDefinitionCounter;
LoadObjectDefinition ((XmlElement) node);
}

#region Instrumentation
if (logger.IsDebugEnabled)
{
logger.Debug (
string.Format (
System.Globalization.CultureInfo.CurrentUICulture,
"Found {0} <> elements defining objects.", objectDefinitionCounter, ObjectsDtd.ObjectElement)); } #endregion } /// <summary> /// Parse an object definition. /// </summary> /// <remarks> /// <p> /// Object elements specify their canonical name as id attribute /// and their aliases as a delimited name attribute. /// If no id specified, use the first name in the name attribute as /// canonical name, registering all others as aliases. /// </p> /// </remarks> protected void LoadObjectDefinition (XmlElement ele) { string id = ele.GetAttribute (ObjectsDtd.IdAttribute); string nameAttr = ele.GetAttribute (ObjectsDtd.NameAttribute); StringCollection aliases = new StringCollection (); if (nameAttr != null && nameAttr.Length > 0) { string [] names = StringUtils.Split ( nameAttr, ObjectNameDelimeters, true, true); foreach (string name in names) { aliases.Add (name); } } // if we ain't got an id, assign any existing (first) alias if (id == null || string.Empty.Equals (id) && aliases.Count > 0) { string firstAlias = aliases ; aliases.RemoveAt (0); id = firstAlias; #region Instrumentation if (logger.IsDebugEnabled) { StringBuilder buffer = new StringBuilder (); foreach (string alias in aliases) { buffer.Append (alias).Append (","); } logger.Debug ( string.Format ( System.Globalization.CultureInfo.CurrentUICulture, "No XML 'id' specified - using '' as ID and as aliases.",
id,
buffer.ToString ()));
}
#endregion
}
AbstractObjectDefinition objectDefinition
= ParseObjectDefinition (ele, id);
if (id == null || string.Empty.Equals (id))
{
if (objectDefinition is RootObjectDefinition)
{
id = ((RootObjectDefinition) objectDefinition).ObjectClassName;

#region Instrumentation
if (logger.IsDebugEnabled)
{
logger.Debug (
string.Format (
System.Globalization.CultureInfo.CurrentUICulture,
"Neither XML 'id' nor 'name' specified - using object class name as ID.",
id));
}
#endregion
}
else
{
throw new ObjectDefinitionStoreException (
_resource.Description,
string.Empty,
"Child object definition has neither 'id' nor 'name'");
}
}

#region Instrumentation
if (logger.IsDebugEnabled)
{
logger.Debug (
string.Format (
System.Globalization.CultureInfo.CurrentUICulture,
"Registering object definition with id '{0}'.",
id));
}
#endregion

_objectFactory.RegisterObjectDefinition (id, objectDefinition);
foreach (string alias in aliases) {
_objectFactory.RegisterAlias (id, alias);
}
}

/// /// Parse a standard object definition. /// /// /// The element containing the object definition. /// /// /// The name of the object (definition). /// /// /// The object (definition). /// ]]>
protected AbstractObjectDefinition ParseObjectDefinition (
XmlElement ele, string objectName)
{
string className = null;
try
{
if (ele.HasAttribute (ObjectsDtd.ClassAttribute))
{
className = ele.GetAttribute (ObjectsDtd.ClassAttribute);
}
string parent = null;
if (ele.HasAttribute (ObjectsDtd.ParentAttribute))
{
parent = ele.GetAttribute (ObjectsDtd.ParentAttribute);
}
if (className == null && parent == null)
{
throw new ObjectDefinitionStoreException (
_resource.Description,
objectName,
string.Format (
System.Globalization.CultureInfo.CurrentUICulture,
"Either '{0}' or '' is required.",
ObjectsDtd.ClassAttribute,
ObjectsDtd.ParentAttribute));
}
AbstractObjectDefinition bd = null;
MutablePropertyValues pvs
= GetPropertyValueSubElements (objectName, ele);
if (className != null)
{
ConstructorArgumentValues cargs
= GetConstructorArgSubElements (objectName, ele);
RootObjectDefinition rbd = null;
if (ResolveTypes)
{
Type type = ResolveType(className);
rbd = new RootObjectDefinition(type, cargs, pvs);
}
else
{
rbd = new RootObjectDefinition(className, cargs, pvs);
}
if (ele.HasAttribute (ObjectsDtd.DependsOnAttribute))
{
string dependsOn = ele.GetAttribute (ObjectsDtd.DependsOnAttribute);
rbd.DependsOn = StringUtils.Split (dependsOn, ObjectNameDelimeters, true, true);
}
string dependencyCheck = ele.GetAttribute (ObjectsDtd.DependencyCheckAttribute);
if (ObjectsDtd.DefaultValue.Equals (dependencyCheck))
{
dependencyCheck = _defaultDependencyCheck;
}
rbd.DependencyCheck = GetDependencyCheck (dependencyCheck);
string autowire = ele.GetAttribute (ObjectsDtd.AutowireAttribute);
if (ObjectsDtd.DefaultValue.Equals (autowire))
{
autowire = _defaultAutowire;
}
rbd.AutowireMode = GetAutowireMode(autowire);
string initMethodName = ele.GetAttribute(ObjectsDtd.InitMethodAttribute);
if (!initMethodName.Equals(string.Empty))
{
rbd.InitMethodName = initMethodName;
}
string destroyMethodName = ele.GetAttribute(ObjectsDtd.DestroyMethodAttribute);
if (!destroyMethodName.Equals(string.Empty))
{
rbd.DestroyMethodName = destroyMethodName;
}

bd = rbd;
}
else
{
bd = new ChildObjectDefinition(parent, pvs);
}

if (ele.HasAttribute(ObjectsDtd.SingletonAttribute))
{
bd.IsSingleton = ObjectsDtd.TrueValue.Equals (ele.GetAttribute(ObjectsDtd.SingletonAttribute));
}

string lazyInit = ele.GetAttribute(ObjectsDtd.LazyInitAttribute);
if (ObjectsDtd.DefaultValue.Equals(lazyInit) && bd.IsSingleton)
{
// just apply default to singletons, as lazy-init has no meaning for prototypes
lazyInit = _defaultLazyInit;
}
bd.LazyInit = ObjectsDtd.TrueValue.Equals(lazyInit);
bd.ResourceDescription = _resource.Description;
return bd;
}
catch (TypeLoadException ex)
{
throw new ObjectDefinitionStoreException (
_resource.Description,
objectName,
string.Format (
System.Globalization.CultureInfo.CurrentUICulture,
"Object class not found.",
className),
ex);
}
catch (ApplicationException err)
{
throw new ObjectDefinitionStoreException (
_resource.Description,
objectName,
string.Format (
System.Globalization.CultureInfo.CurrentUICulture,
"Class that object class depends on not found.",
className),
err);
}
}

/// /// Try to convert a string definig a type to a System.Type /// /// /// Type ResolveType (string partialOrFullClassName) { Type type = Type.GetType (partialOrFullClassName); if (type != null) return type; string[] splitted = partialOrFullClassName.Split (new char[] {','}); if (splitted.Length > 1) { Assembly assembly = LoadAssembly (partialOrFullClassName); return assembly.GetType (splitted[0]); } throw new ObjectDefinitionException (partialOrFullClassName); } private Assembly LoadAssembly (string className) { string assemblyName = className.Substring (className.IndexOf (',') + 1).Trim (); Assembly assembly = assembly = Assembly.LoadWithPartialName (assemblyName); return assembly; } /// /// Parse constructor argument subelements of the given object element. /// /// /// /// protected internal virtual ConstructorArgumentValues GetConstructorArgSubElements ( string objectName, XmlElement objectEle) { XmlNodeList nl = objectEle.ChildNodes; ConstructorArgumentValues cargs = new ConstructorArgumentValues (); for (int i = 0; i < nl.Count; ++i) { XmlNode node = nl.Item(i); if (node is XmlElement && ObjectsDtd.ConstructorArgElement.Equals (node.Name)) { ParseConstructorArgElement (objectName, cargs, (XmlElement) node); } } return cargs; } /// /// Parse property value subelements of the given object element. /// /// /// The name of the object (definition) associated with the property element (s) /// /// /// The element containing the top level object definition. /// /// The property (s) associated with the object (definition). protected internal virtual MutablePropertyValues GetPropertyValueSubElements ( string objectName, XmlElement objectEle) { XmlNodeList nl = objectEle.ChildNodes; MutablePropertyValues pvs = new MutablePropertyValues (); for (int i = 0; i < nl.Count; ++i) { XmlNode node = nl.Item (i); if (node is XmlElement && ObjectsDtd.PropertyElement.Equals (node.Name)) { ParsePropertyElement(objectName, pvs, (XmlElement) node); } } return pvs; } /// /// Parse a constructor-arg element. /// /// /// The name of the object (definition) associated with the ctor arg. /// /// /// The list of ctor args associated with the object (definition). /// /// /// The name of the element containing the ctor arg definition. /// protected internal virtual void ParseConstructorArgElement ( string objectName, ConstructorArgumentValues cargs, XmlElement ele) { object val = GetPropertyValue(ele, objectName); string indexAttr = ele.GetAttribute (ObjectsDtd.IndexAttribute); string typeAttr = ele.GetAttribute (ObjectsDtd.TypeAttribute); if (!string.Empty.Equals (indexAttr)) { try { int index = int.Parse (indexAttr); if (index < 0) { throw new ObjectDefinitionStoreException ( _resource.Description, objectName, "'index' cannot be lower than 0"); } if (!string.Empty.Equals(typeAttr)) { cargs.AddIndexedArgumentValue (index, val, typeAttr); } else { cargs.AddIndexedArgumentValue (index, val); } } catch (FormatException) { throw new ObjectDefinitionStoreException ( _resource.Description, objectName, "Attribute 'index' of tag 'constructor-arg' must be an integer"); } } else { if (!string.Empty.Equals (typeAttr)) { cargs.AddGenericArgumentValue (val, typeAttr); } else { cargs.AddGenericArgumentValue(val); } } } /// /// Parse a property element. /// /// /// The name of the object (definition) associated with the property. /// /// /// The list of properties associated with the object (definition). /// /// /// The name of the element containing the property definition. /// protected void ParsePropertyElement ( string objectName, MutablePropertyValues pvs, XmlElement ele) { string propertyName = ele.GetAttribute (ObjectsDtd.NameAttribute); if (string.Empty.Equals (propertyName)) { throw new ObjectDefinitionStoreException ( _resource.Description, objectName, "Tag 'property' must have a 'name' attribute"); } object val = GetPropertyValue (ele, objectName); pvs.AddPropertyValue (new PropertyValue (propertyName, val)); } /// /// Get the value of a property element (may be a list). /// The property element. /// /// The name of the object associated with the property. /// ]]>
protected internal virtual object GetPropertyValue (
XmlElement ele, string objectName)
{
// should only have one element child: value, ref, collection
XmlNodeList nl = ele.ChildNodes;
XmlElement valueRefOrCollectionElement = null;
for (int i = 0; i < nl.Count; ++i)
{
if (nl.Item is XmlElement)
{
XmlElement candidateEle = (XmlElement) nl.Item (i);
if (ObjectsDtd.DescriptionElement.Equals (candidateEle.Name))
{
// keep going: we don't use this value for now
}
else
{
// child element is what we're looking for
valueRefOrCollectionElement = candidateEle;
}
}
}
if (valueRefOrCollectionElement == null)
{
throw new ObjectDefinitionStoreException (
_resource.Description,
objectName,
" element must have a subelement like 'value' or 'ref'."); } return ParsePropertySubElement (valueRefOrCollectionElement, objectName); } /// /// Parse a value, ref or collection subelement of a property element. /// /// /// Subelement of property element; we don't know which yet. /// /// /// The name of the object (definition) associated with the top level property. /// protected internal virtual object ParsePropertySubElement ( XmlElement ele, string objectName) { if (ele.Name.Equals(ObjectsDtd.ObjectElement)) { return ParseObjectDefinition (ele, "(inner object definition)"); } else if (ele.Name.Equals(ObjectsDtd.RefElement)) { // a generic reference to any name of any object string objectRef = ele.GetAttribute (ObjectsDtd.ObjectRefAttribute); if (string.Empty.Equals(objectRef)) { // a reference to the id of another object in the same XML file objectRef = ele.GetAttribute(ObjectsDtd.LocalRefAttribute); if (string.Empty.Equals(objectRef)) { throw new ObjectDefinitionStoreException ( _resource.Description, objectName, "Either 'object' or 'local' is required for a reference"); } } return new RuntimeObjectReference(objectRef); } else if (ele.Name.Equals(ObjectsDtd.IdRefElement)) { // a generic reference to any name of any object string objectRef = ele.GetAttribute (ObjectsDtd.ObjectRefAttribute); if (string.Empty.Equals (objectRef)) { // a reference to the id of another object in the same XML file objectRef = ele.GetAttribute (ObjectsDtd.LocalRefAttribute); if (string.Empty.Equals (objectRef)) { throw new ObjectDefinitionStoreException ( _resource.Description, objectName, "Either 'object' or 'local' is required for an idref"); } } return objectRef; } else if (ele.Name.Equals (ObjectsDtd.ListElement)) { return GetList (ele, objectName); } else if (ele.Name.Equals (ObjectsDtd.SetElement)) { return GetSet (ele, objectName); } else if (ele.Name.Equals (ObjectsDtd.MapElement)) { return GetMap (ele, objectName); } else if (ele.Name.Equals (ObjectsDtd.PropsElement)) { return GetProps (ele, objectName); } else if (ele.Name.Equals (ObjectsDtd.ValueElement)) { // it's a literal value return GetTextValue (ele, objectName); } else if (ele.Name.Equals (ObjectsDtd.NullElement)) { // it's a distinguished null value return null; } throw new ObjectDefinitionStoreException ( _resource.Description, objectName, "Unknown subelement of : "); } /// /// Gets a list definition. /// /// /// The element describing the list definition. /// /// /// The name of the object (definition) associated with the list definition. /// /// The list definition. protected internal virtual IList GetList ( XmlElement collectionEle, string objectName) { ManagedList l = new ManagedList(); foreach (XmlNode node in collectionEle.ChildNodes) { if (node is XmlElement) { XmlElement ele = (XmlElement) node; l.Add (ParsePropertySubElement (ele, objectName)); } } return l; } /// /// Gets a set definition. /// /// /// The element describing the set definition. /// /// /// The name of the object (definition) associated with the set definition. /// /// The set definition. protected Set GetSet (XmlElement collectionEle, string objectName) { ManagedSet s = new ManagedSet (); foreach (XmlNode node in collectionEle.ChildNodes) { if (node is XmlElement) { XmlElement ele = (XmlElement) node; object element = ParsePropertySubElement (ele, objectName); s.Add (element); } } return s; } /// /// Gets a map definition. /// /// /// The element describing the map definition. /// /// /// The name of the object (definition) associated with the map definition. /// /// The map definition.]]>
protected IDictionary GetMap (XmlElement mapEle, string objectName)
{
ManagedMap m = new ManagedMap();
IList l = GetChildElementsByTagName (mapEle, ObjectsDtd.EntryElement);
foreach (XmlElement entryEle in l)
{
string key = entryEle.GetAttribute (ObjectsDtd.KeyAttribute);
// TODO: make more robust
XmlNodeList subEles = entryEle.GetElementsByTagName ("*");
m = ParsePropertySubElement ((XmlElement) subEles.Item (0), objectName);
}
return m;
}

/// /// Don&t use the horrible DOM API to get child elements: get an element&s /// children with a given element name. /// protected IList GetChildElementsByTagName ( XmlElement mapEle, string elementName) { IList nodes = new ArrayList (); foreach (XmlNode node in mapEle.ChildNodes) { if (node is XmlElement && elementName.Equals (node.Name)) { nodes.Add (node); } } return nodes; } /// /// Gets a property mapping definition. /// /// /// The element describing the property mapping definition. /// /// /// The name of the object (definition) associated with the property mapping /// definition. /// /// The property mapping definition.]]>
protected IDictionary GetProps (
XmlElement propsEle, string objectName)
{
IDictionary props = new Hashtable ();
XmlNodeList nl = propsEle.GetElementsByTagName (ObjectsDtd.PropElement);
foreach (XmlElement propEle in nl)
{
string key = propEle.GetAttribute (ObjectsDtd.KeyAttribute);
// trim the text value to avoid unwanted whitespace caused by typical XML formatting
string value = GetTextValue (propEle, objectName).Trim ();
props = value;
}
return props;
}

/// /// Make the horrible DOM API slightly more bearable: get the text value /// we know this element contains /// protected string GetTextValue ( XmlElement ele, string objectName) { XmlNodeList nl = ele.ChildNodes; if (nl.Item (0) == null) { // treat empty value as the empty string instance return string.Empty; } if (nl.Count != 1 || !(nl.Item (0) is XmlText)) { throw new ObjectDefinitionStoreException ( _resource.Description, objectName, "Unexpected element or type mismatch: expected single node of " + nl.Item(0).GetType() + " to be of type Text: " + "found " + ele, null); } return ((XmlText) nl.Item (0)).Data; } /// /// Strips the dependency check value out of the supplied string.. /// /// /// The string containing the dependency check value. /// /// The dependency check value. protected DependencyCheckingMode GetDependencyCheck (string att) { DependencyCheckingMode code = DependencyCheckingMode.None; if (att != null && att.Trim ().Length > 0) { try { code = (DependencyCheckingMode) Enum.Parse ( typeof (DependencyCheckingMode), att, true); } catch (ArgumentException ex) { #region Instrumentation if (logger.IsDebugEnabled) { logger.Debug ("Error while parsing dependency checking mode.", ex); } #endregion } } return code; } /// /// Strips the autowiring mode out of the supplied string.. /// /// /// The string containing the autowiring mode definition. /// /// The autowiring mode. protected AutoWiringMode GetAutowireMode (string att) { AutoWiringMode mode = AutoWiringMode.No; if (att != null && att.Trim ().Length >]]> 0)
{
try
{
mode = (AutoWiringMode) Enum.Parse (
typeof (AutoWiringMode), att, true);
}
catch (ArgumentException ex)
{
#region Instrumentation
if (logger.IsDebugEnabled)
{
logger.Debug ("Error while parsing autowire mode.", ex);
}
#endregion
}
}
return mode;
}
#endregion

#region Fields
private IObjectDefinitionRegistry _objectFactory;
private IResource _resource;
private string _defaultLazyInit;
private string _defaultDependencyCheck;
private string _defaultAutowire;
private bool _resolveTypes;
#endregion
}
}

0

Please sign in to leave a comment.