Axaptapedia is now maintained by AgileCadence For more information please click here.

Editor scripts OpenOverriddenMethodDef

From Axaptapedia
Jump to: navigation, search

Purpose[edit]

Navigate to the definition of a method that overrides the currently open method in a descendent class

Description[edit]

  • This is a nice script that will be very helpful to AX developers often exploring the class heirarchy when debugging, etc. You will need to navigate to the AOT less, which, generally, speeds up things
  • In case there is more than one overridden method found, a listview with the possible choices is shown, where the developer can select the needed class.
  • 2 versions of the code are provided, one of which uses cross references information, and the other - Dictionary class. The xRef version is generally faster.

Dynamics AX versions[edit]

Has been tested on Dynamics AX 3.0 SP3, Dynamics AX 4.0 SP1 and Dynamics AX 2009

Code[edit]

Simply create a new method in class EditorScripts and paste the following code into it. (Check out the other 2 verions here: Talk:Editor_scripts_OpenOverriddenMethodDef) <xpp> /// <summary> /// Editor_Scripts_OpenOverriddenMethodDef_ikash, 2008-08-12 /// Navigate to the definition of a method that overrides the currently open method in a descendent class /// </summary> /// <param name="e">Currenty open editor</param> public void addIns_OpenOverriddenMethodDef(Editor e) {

   #define.AOTDelimiter('\\')
   #AOT
   TreeNode        treeNode = TreeNode::findNode(e.path());
   TreeNode        treeNodeParent;
   ClassId         classIdParent;
   TreeNodeName    methodName = treeNode.treeNodeName();
   Map             descendents;
   MapEnumerator   descendentsEnumerator;
   Counter         descendentsCount;
   xRefTypeHierarchy xRefTypeHierarchy_find(Types _baseType, int _id)
   {
       xRefTypeHierarchy xRefTypeHierarchy;
       select firstonly xRefTypeHierarchy
           index BaseTypeIdIdx
           where xRefTypeHierarchy.BaseType == _baseType &&
                 xRefTypeHierarchy.Id == _id;
       return xRefTypeHierarchy;
   }
   xRefTypeHierarchy xRefTypeHierarchy_findOrCreate(Types _baseType, int _id)
   {
       xRefTypeHierarchy xRefTypeHierarchy = xRefTypeHierarchy_find(_baseType, _id);
       if (!xRefTypeHierarchy)
       {
           new xRefUpdateTypeHierarchy().run();
           xRefTypeHierarchy = xRefTypeHierarchy_find(_baseType, _id);
       }
       return xRefTypeHierarchy;
   }
   void findDescendents(ClassId _parentId)
   {
       xRefTypeHierarchy   typeHierarchy;
       TreeNode            descendent;
       ;
       if (!xRefTypeHierarchy_findOrCreate(Types::Class, _parentId).Children)
           return;
       while select typeHierarchy
           where typeHierarchy.Parent == _parentId &&
                 typeHierarchy.BaseType == Types::Class
       {
           descendentsCount++;
           descendent = TreeNode::findNode(#ClassesPath + #AOTDelimiter + typeHierarchy.Name + #AOTDelimiter + methodName);
           if (descendent)
               descendents.insert(descendent.treeNodePath(), descendent.AOTparent().treeNodeName());
           if (typeHierarchy.Children && typeHierarchy.Id)
               findDescendents(typeHierarchy.Id);
       }
   }
   ;
   if (subStr(treeNode.treeNodePath(), 1, strLen(#ClassesPath)) == #ClassesPath)
   {
       treeNodeParent = TreeNode::findNode(xUtilElements::getNodePathRough(xUtilElements::parentElement(xUtilElements::findTreeNode(treeNode))));
       classIdParent = className2Id(treeNodeParent.treeNodeName());
       descendents = new Map(Types::String, Types::String);
       findDescendents(classIdParent);
       switch (descendents.elements())
       {
           case 0:
               info(strFmt(@"The method '%1' is not overridden in any of the %2 descendent classes", methodName, descendentsCount));
               break;
           case 1:
               descendentsEnumerator = descendents.getEnumerator();
               if (descendentsEnumerator.moveNext())
                   treeNode = TreeNode::findNode(descendentsEnumerator.currentKey());
               break;
           default:
               treeNode = TreeNode::findNode(pickList(descendents, "@SYS24724", @"Pick required class to go to method definition"));
       }
       if (treeNode && SysTreeNode::hasSource(treeNode))
           treeNode.AOTedit();
   }

} </xpp>

Used in[edit]

Editor scripts

Externdal Links[edit]

Original blog post about this script