What APIs would I use

Hi,
I want to go through a code base and systematically find 1) where each token is defined and 2) where each token is used. (find useages with various options). There are a number of ways to do this but why reinvent the wheel when  IntelliJ already does this. Since the Intellij source is the code base I am targeting it makes sense to use the IntelliJ API .   Can you give me an idea of whqat API I would use to do 1 and 2 above?

Thank you.

11 comments
Comment actions Permalink

Do you have a more specific task in mind? What you describe is certainly possible with the IntelliJ IDEA APIs, but invoking resolve and find usages on every reference in a project would take a very large amount of time.

0
Comment actions Permalink

Do you have a more specific task in mind? What you describe is certainly possible with the IntelliJ IDEA APIs, but invoking resolve and find usages on every reference in a project would take a very large amount of time.






It's OK about the time, even if it takes days. This is just something to help the Intellij community. I could use ANTLR and start parsing files and tokenizsing or tapping into the bytecode etc but it seems like a gigantic waste of  effort since in the end I would have written something just equivalent to what is already been written by Jetbrains anyway.


But to answer your question, yes, I am aware that it will take a long time. It only needs to be done once, so it can take as long as it takes.


Message was edited by: java developer

0
Comment actions Permalink

Hey Dmitry if you don't like the idea then can you just tell me what APIs I use to determine this same information for one class? Thanks!

0
Comment actions Permalink

OK you tell me how I have to ask this question to get an answer. It's discouraging when you take the time to reply to the  question only to  question  WHY I want this very very basic information  . I want it because I want it, that's why. I know this is SOOO basic - what API woudl I use to get 1) defintiion and 2) used by infromation for any given token it can't be  that you dont' know. So just tell me instead of wondering aloud in a public forum about the  sagacity of my want to acquire this specific infomation. What do you care why I want to know this and why was that the content of your "qanswer" rather than just the answer I was looking for? Can you tell me that?  

0
Comment actions Permalink

I'm sorry but I don't spend 100% of my time in the office and answering user's questions. Sometimes I go to conferences, take vacations, sick leave etc. And since the APIs you're interested in are so basic and commonly used, it's absolutely not hard to find them by yourself.

PsiElement.getReference().resolve() gets you the the declaration of any PSI element, and ReferencesSearch.search() gives you the information on its usages.

0
Comment actions Permalink

OK Dmitry, you win. Errr.. what was it you won  exactly?

I dont' want to make you do anything you don't like. People like what they're good at and trying to force them outside their comfort zone is not anyone else's business except theirs if they chose to do so on their own initiative.

How hard was it to just answer my question as it was asked? Apparently not too. I really don't  know how to figure it out ti would have taken me foreverr b/c I'm a  newbie. For you I figured  you knew the answer in your head and wouldn't  even have to spend time looking it up. So I asked.


How many posts do we get here a day? Do we have an active vibrant mailing list? IMHO Intellij is the greatest IDE out there by a large measure. I could ride for free in an IDE that to outsiders is indistinguishable from IntelliJ, but I choose to pay and so do a lot of other people. That says it all.


So if it's so great, why isn't it the favorite deployment target of university researchers who are doing their masters and PhD work in some aspect of code tooling ro software research  etc etc etc? Why does Eclipse have that distinction? Why does Eclipse have more market share? At least part of that is the  plugin ecostructure. Then there's the books and researchers and the academic papers and on and on and on. It's a big, self-reinforcing virtuous circle- for Eclipse. It should  not be that way.


I'm not the one who's going to allocate resources and change internal attitudes towards "annoying newbies who want someone to spoonfeed them everything" but someone or something has to. This mailing list is barely alive  and  too many people  all act like they just have  better things to do, which hey maybe they do. But if they do then why is it not that  way on other mailing lists where presumably people are also busy and newbies are also lame and people also have lives filled with better things to do?


I am telling it like it is. I have seen really enthusiastic people just disappear from here. Reading the exchanges I get the idea they found their enthusiam to be unreciprocated or met with actual disdain for some reason . There are good and healthy communities and there are other kinds. The kinds dominated by knowledge horders. The kinds where the level of unresponsiveness is deafening. The kinds filled with passive aggressive crap. The whole 'figure it out yourself" is  antisocial, whether you think the newbie is probably an idiot not worth wasting your time on or not.  Maybe it's a cultural thing, I am sure I don't  know.  What I do know is Intellij is nowhere near as popular as it deserves to be, that I  experience the "community" as  weak and barren and that the numbers bear me out in all I've said and it should not be this way.


Giving people info which you think is too bassic to even have to articulate   but they find helpful takes a certain personality type with a certain view of the world and  people in it. I am not telling to behave differently. I am saying  InteliJ is a ship sailing in the same seas as  every other IDE and the same good fish who  build a commuity are swimming by IntelliJ in the same number as any other  IDE..  If we haven't caught our share of  those  fish then we're not building the right nets.


I  don't  want to see Intellij starved of resources and disappear from the earth. That would be a personal disaster for me; that would hurt me and make my life less good. As far as I know everyone's gotta eat. If IntelliJ doesn't grow its  paying base but the demands keep increasing and at  the same time the  technologies to be supported keep expanding and the work load keeps increasing,  then ultimately the devs can't keep up.  I call that death through painful expansion. You are a pay IDE in a world of mega-behemouths who treat their IDEs like loss leaders for their global brand. That's a tough row to hoe and quite frankly can you really continue to pull it off without a community of devs-you-dont'-have-to-pay  taking your product in innovative directions that maybe surprise even you?


Thanks for the info.

Message was edited by: java developer

0
Comment actions Permalink

There are good and healthy communities and there are other kinds. The kinds dominated by knowledge horders. The kinds where the level of unresponsiveness is deafening. The kinds filled with passive aggressive crap.


I don't know where you've been hanging out, but this community is not like that at all. It's true that there is not enough documentation but this is a topic that has been discussed endlessly here - search the forum for more. I'm not sure what you found so offensive about Dmitry's initial response - he simply asked for more information about what you're trying to achieve so he could advise you better. You didn't answer his question. I'm sure he would have been willing to help you if you had done so - he's done that for me many times, even when I'm asking quite stupid questions.

0
Comment actions Permalink

This is the internet. What can you do?

It is easy to take things the wrong way, especially when you are asking your first question and are very excited about it.

That said Dmitry's first response seemed very polite.

That reminds me - I applied for the job posting for JetBrains Boston, MA office, and they never replied to me....maybe I should make an angry post ;)

0
Comment actions Permalink

I'll get the popcorn :)

0
Comment actions Permalink

No popcorn needed for anything here . I consciously waited to make sure that other, newer questions were being actively answered by Dmitry before I complained about being not answered.   Answering a question  with any form of "why do you want to know that?"    instead of the  answer the person actually asked for- an answer is actually shorter and easier to both forma dn type-  is bad form IMHO.



What exactly did I do wrong? I asked a directed, specific question on a  very specific part of the API which had a very specific answer.  didn't ask a "I want to do X and I dont' know anything about how to do it " type question.  I wasn't  wasting anyone's time.  That's good question asking. Still I get "hmmmm... why do you want to know about that?". I want to know about it b./c I want to now about it. Is that OK ?  I actually  answered his first "answer" rather cheerfully. Then the question got dropped while other questions got answered. So I went meta and asked  him how exactly I  should ask the question in order to get an answer. Everyone has their own narrative and I'm, not going to defend mine any further.



As far as  anything else goes,  I said everything I have to say, so take it for what's it's worth. If anyone thinks I'm a bad guy that's cool. I fully understand that complaining about the gatekeeper on  his own turf with an audience composed srtictly of people who will need something from said gatekeeper and who have every motivation to stay in his good graces is totally a losing move. It's going  to net you nothing but a lot of (very) publicly voiced disdain and dismisal all around. I didn't just fall off the pumpkin wagon yesterday I get that. I got that before I posted. But is what I said true? Is it?  


To whatever extent my complaint made people  thnk about things   then it's a net good. So now I have a reputation as an unreasonable self-centered newbie-hot-head-jerk  who expects all resources to be directed toawrds him alone. That's the price you pay sometimes.  First off, it's not true, it does not describe me accurately. Secondly, I'll do that. I'm not going to be a slave to some idea of never stepping on anyone's toes or to some convoluted political calculus of maintaining your  reputation in an online forum.  I'd rather take a swing at making things  better. Everyone pussyfoots around and does nothing about real problems because they are afraid of their reputation and making enemies. They're so afraid they dont' even see the problems. That's bad for everyone. Yeah, I'm not going to be applying to Jetbrains anytime soon or asking anymore questions here. That's the price you pay for trying  to motivate people to make changes.    

0
Comment actions Permalink

I'll explain why I asked my original question. When people ask a plugin development question here, I assume that they are working on a plugin that will eventually be published and available to IntelliJ IDEA users. Because of that, I always try to understand what problem they are trying to solve, in order to recommend a solution that would have optimum performance and align well with how the APIs are intended to be used. Otherwise, our users installing their plugins would suffer from performance problems and possibly blame IntelliJ IDEA for those.

Whatever the problem you're trying to solve (and you never explained it), calling Find Usages on all references in a certain context (especially on all references in a project) is most likely a very inefficient way of solving it. Because of that, I tried to see if I could recommend you a better approach.

0

Please sign in to leave a comment.