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
Please sign in to leave a comment.
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...
>
>
>
Andrey Simanovsky (JetBrains) wrote:
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
*
http://www.apache.org/licenses/LICENSE-2.0
*
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 ///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; } ///
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); } ///
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; } ///
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; } ///
{
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
}
}