question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting full name of property/type

See original GitHub issue

I’m currently using the findReferences() method as part of a refactoring tool I’m creating to remove namespaces from a large project.

This method correctly finds all of the project references however it only returns the part being searched and does not include the namespaces to the left so I am unable to rewrite them. Grabbing all the names to the left where they exist has proven to be far more difficult than I expected.

For example, the findReferences() return “something” rather than “foo.bar.something”.

After trying various combinations of getParent, getAncestors and getPreviousSiblings I’ve been unable to get something that reliably pulls everything from the left (leaving any class properties on the right.)

I tried something like this with very limited success.

        var node=element.getNode();
        
        if (TypeGuards.isTypeReferenceNode(node) || TypeGuards.isPropertyAccessExpression(node)){
            //property with no left namespace, leave alone.  broken DOESN'T seem to pick up all single names
            console.log("nochange: ", node.getKindName(), node.getText());            
        } else {
            var ancestor = node.getFirstAncestorByKind(ts.SyntaxKind.TypeReference);
            if (ancestor){
                    //appears to work.
                    ancestor.replaceWithText(getNewQualifiedname(ancestor.getText()))                   
            } else {
                var ancestor2 = node.getFirstAncestorByKind(ts.SyntaxKind.PropertyAccessExpression);
                if (ancestor2){
                        //not much success here.
                        ancestor2.replaceWithText(getNewQualifiedname(ancestor2.getText()))
                }
            }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
dsherretcommented, Oct 28, 2017

Nice, I’m glad it’s mostly working out! Let me know what you find about the special character being introduced when you get a chance. I will maybe spend some time on it this weekend to try to reproduce it.

By the way, I created a web-based AST viewer that you can use to help understand the tree. It’s very basic for now, but shows the relationship between the nodes (it took me about 6 hours to do). I’ll work on improving it more in the future: https://dsherret.github.io/ts-ast-viewer/

0reactions
dsherretcommented, Nov 13, 2017

I don’t believe there’s anything still outstanding in this issue so I’m closing it. Please reopen it if that’s not correct.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type.FullName Property (System) - Microsoft Learn
The BaseType property obtains the Type object that represents the base type of Derived<T> , and its FullName property returns null . To...
Read more >
Display full name of all properties of an object - Stack Overflow
A good approach will be to pass the path with every call for DisplayProperties . Change the method signature: public static void ...
Read more >
Get Property Names using Reflection [C#] - C# Examples
To get names of properties for a specific type use method Type.GetProperties. Method returns array of PropertyInfo objects and the property names are ......
Read more >
PropertyInfo - John Nelson's Blog
//get the PropertyInfo array for all properties ... Format( "Property Type FullName: {0}" , property.PropertyType.FullName));. sb.AppendLine(String.
Read more >
System.Reflection.PropertyInfo - Type
The Type is String, Boolean, Int32, and so on. To get the PropertyType property, first get the class Type. From the Type, get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found