Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
ovesh
@ovesh

Hello!

I have a question about chained method calls.
Given a chained invocation (builder pattern):

return new ThingBuilder().withA(a).withB(b).build();

How can I use JavaParser to add another chained invocation to end up with code like this:

return new ThingBuilder().withA(a).withB(b).withC(c).build();

Inserting it anywhere in the chain (before build()) is fine.

15 replies
mdproctor
@mdproctor
does anyone know of a Language Server Protocol impl, that can be driven from a JavaCC grammar?
3 replies
Yevgen Muntyan
@muntyan

Good morning. I am using LexicalPreservingPrinter to do some code modifications, and it works well, but I can't figure out how to insert whitespace where I need it. My goal is to replace code like

    function(new RuntimeException("abc"),
        anArgument,
        anotherArgument);

with

    new RuntimeException("abc",
        anArgument,
        anotherArgument);

But I can't get the newlines in the replacement, I can only get

    new RuntimeException("abc", anArgument, anotherArgument);

Is it possible to do what I want?

12 replies
Roger Howell
@MysterAitch
v3.17.0 released -- it'll be available as soon as bintray/sonatype/maven central do their thing!
Big shout out to @jlerbsc for another bumper release of bug fixes! 🥳🥳
Nicholas Smith
@SmiddyPence

I would like to translate the book "JavaParser: Visited" into Brazilian Portuguese, has anyone translated this book? do you know if it is allowed? who would i have to talk to? thank you.

Sure, no problem.

Devan-Kerman
@Devan-Kerman

hey, given a FieldDeclaration, how would I replace the initiailizer, so for example

public class Foo {
       public int a = Something.compute(3, 5);
}

to

public class Foo {
       public int a = Impl.init();
}

I have the FieldDeclaration instance already

Roger Howell
@MysterAitch
Iirc the field declaration has a list of variable initialisations -- that's where you can access the right hand side of the assignment operators
(it's a list because you can have int x, b, abc;)
Devan-Kerman
@Devan-Kerman
yea I think I got it
for (VariableDeclarator variable : n.getVariables()) {
variable.setInitializer("Impl.init()");
}
very nice api, thank you
Roger Howell
@MysterAitch
Brill! Glad you've got it! :)
For reference, in case you've not seen it, this article might be helpful :) https://javaparser.org/inspecting-an-ast/
MarcosCosmos
@MarcosCosmos
Hey has anyone got a generic method/solution for getting the position/range in the source for attributes, or at the least, their tokens?
48 replies
mdproctor
@mdproctor
We are back to developing our java language extensions. One problem we have, is backwards compatibility - we want to make this optional. In short how we handle newlines, we would like to make configurable on a property. Does JavaCC have anything to enable that?
23 replies
Roger Howell
@MysterAitch
Could I ask for some sets of eyes on #2886 please? Specifically, will these changes in Java need to be acted upon in javaparser? It's not a language change, but I don't understand nests and some of the other things it talks about... equally, it could end up being something that is handled transparently for us by javassist...

Assuming that hidden classes (#2886) don't affect anything (I don't think it does, but I don't entirely understand the JEP), we can then formally tick javaparser off as supporting java 15... which would be rather nice! :D

After that, it's just records to go for java 16 support :)

Danny van Bruggen
@matozoid
Looks like some way to support people who want to write code that generates classes at runtime, so it is user code, running on the JVM, that is generating byte code to run on the same JVM, which can then be used only with reflection. Symbol solving is all about static, compile-time analysis, so this JEP would only be of interest if JP also had a JVM implementation :-)
Don't forget about javaparser/javaparser#2512 which has half the record syntax already! Feel free to take over from me.
The private project I'm working on has a dependency on JP since a few days ago, so I now have a stake in the project again :-#
fahd
@debbicce_gitlab
is there a javaparser jar file that I can add to my project configurations in Eclipse?
3 replies
Denis
@dencns
Using Gradle & Eclipse. Tried running this https://javaparser.org/inspecting-an-ast/, but I get the following error: Caused by: java.lang.NoClassDefFoundError: com/github/javaparser/ast/Node. Any tips to fix it? In the end I just want to change it to see the AST of a simple print of helloworld.
5 replies
Denis
@dencns
Tested it within intellij. it works there.
Luke McMahon
@ll16l4m_gitlab
Hi, is there a way to findAll for specific logical operators? For example, if I wanted to findAll(&&)?
3 replies
mdproctor
@mdproctor
@ftomasse_twitter I've just been told you are well connected to a JavaCC committer? I might be great if we could get an introduction, as we want to ask about LSP. One reason why we were interested in JavaCC21, is LSP. But if there was a way to get that into JavaCC itself, we have less of a need for JavaCC21.
Federico Tomassetti
@ftomassetti
I would strongely discourage to look into JavaCC21 as you would be strongely dependant on the person that behave the worst among all the persons I encountered online. So I would consider it risky for the future of the project and not ideal on the personal level
That said, I have talked the other day with Francis Andre', and I would be happy to write an introduction. Could you share your email with me, so I will put you in CC?
tagging @mdproctor
Federico Tomassetti
@ftomassetti
Screenshot 2020-12-03 at 11.52.46.png
@mdproctor this is just for you to get an idea of the kind of interactions you can expect, totally unprovoked
Danny van Bruggen
@matozoid
Yeah, sadly he already met the guy in the latest email torrent :-#
Federico Tomassetti
@ftomassetti
Sorry to hear that. Meeting this person made me much more careful. I have a ton of interactions every day and I was completely caught by surprise by the behavior of this guy
Betty-Wong
@Betty-Wong
Let me get this straight. You're saying that I should make the technical decision to use JavaCC21, or actually, not use it, I guess, because you have a beef with the main developer? Is there some other reason, like something that has some technical grounds?
Federico Tomassetti
@ftomassetti
@Betty-Wong of course you should do what you think it is best for you. However, I think it is useful to share experiences that were problematic. We are not reporting an heated discussion or a disagreement. We are talking about a person who insulted in very disturbing ways several persons, unprovoked. He involved people totally external to the conversation and forked projects out of spite for the persons he was attacking. I think this could have an impact on the future of the projects, because I can suppose that building a team of contributors and a community with this behavior may prove difficult and this can reflect on the project
If you do not find this relevant to you, you should obviously feel free to ignore we reporting our experiences
I can say that it was a really surprising experience for me. I interact with a ton of people every single day and I have never been attacked in such a way. I can guarantee you that it has been very unpleasant, and I wish something had warned me before I interacted with this person, for this reason I thought useful and fair to share my experience
Betty-Wong
@Betty-Wong

@Betty-Wong However, I think it is useful to share experiences that were problematic.

Well, "problematic" for you. But why should I consider your personal interaction with somebody "problematic" for me? The whole thing is very novel to me. I use a lot of different open source tools in my work and the truth is that I almost never have any idea at all of the personalities of the various people who created those things. I honestly just never gave it much thought. To me, it is a very strange idea that I should decide on the tool stack to use in a project because of an opinion about a person I don't know, expressed by another person whom I also don't know. That, of course, is why I asked you whether you had any technical grounds for telling people not to even consider using JavaCC21. That's the question I'm interested in but you didn't answer it.

Federico Tomassetti
@ftomassetti
I did not answer it because I did not make a technical analysis of that project for the reasons I explained. I understand you have a different point of view and I respect it
Danny van Bruggen
@matozoid
Hi @Betty-Wong - I'm curious what kind of project you're thinking to develop. Anything cool?
mdproctor
@mdproctor
@ftomassetti just looking at your reply. made me laugh. He seemed talented and with some passion, so I thought maybe I could help him, and I tried to coach him, just basically saying "be nice to people" and that maybe he's perceiving ill intent, when there isn't, and saying these types of conversations are not productive for any one ( he was abusing @matozoid at the time in am email to me). He then unloaded on me too. I just did one line reply, that this isn't a productive conversation, and to not include me in any further conversation unless it's purely technical. He then sent another long email, I read one line and ignored the rest. I replied saying I didn't read it, so he then sent another long email. I didn't read it and didn't reply.
Roger Howell
@MysterAitch

I use a lot of different open source tools in my work and the truth is that I almost never have any idea at all of the personalities of the various people who created those things.

Ditto. For the most part, the vast vast vast majority of people involved in open source are friendly -- OR, at the absolute least, civil. Being noticably offensive is (thankfully) the extremely rare exception within successful projects.

I think Linus Torvalds with the Linux kernel project is the only exception I can recall and that's only front of mind because it was in the headlines a short while back that he'd been forced to tone it down.

I wholly agree with you that the personality of the creators/maintainers of a project should normally not be noticeable.

... Which makes it extremely remarkable and a bit of a novelty when such offensive individuals make it onto the radar.

It is disappointing and shameful when someone is notable because of the way they interact rather than their technical ability.


Imagine, hypothetically, a project you use that is, on a technical consideration, extremely appealing... BUT it is extremely noticable that the maintainer is particularly hostile and offensive in reply to even the slightest bit of disagreement or (perceived) provocation.

Imagine if it then escalated to the point where absolutely foul language and hateful abusive emails are being sent, despite repeated requests to tone it down and pleas to keep it friendly/civil.

Imagine if it then escalated to the point that this individual actually goes ahead and registers domain names out of spite and continues the barrage of personal threats/insults.

For what reason would anybody continue to engage with somebody who is consistently like this and is consistently hard work to communicate with (e.g. one line email being returned with multiple essays, the content of which is often vile and offensive personal attacks)??

Most of us join open source communities (and then STAY) for the community. We do it for fun and gratification. There is (typically) no monetary reward. If it's not fun, don't do it. If you're snowed under at work or with family or whatever "real world" obligations and commitments you have -- whatever pays the bills and makes you happy absolutely MUST take priority. That is ever more relevant given the current global pandemic.

THAT is the reason several of us have such strong opinions about the project, despite being able to appreciate its progress on a technical level.


(I am inclined to think of this being analogous to boycotting a clothing company because of the vile views of it's owners re: oppressing LGBT rights or promoting child labour or bullying or some other horrid and offensive behaviour ---- even if the quality of the clothing (software) is technically amazing, I'm not going to shop there (use the software)... and if I feel particularly strongly I'll spread the word and encourage others to boycott that particular range of products (software) irrespective of how technically awesome it is)

Sorry.. struggling to sleep and got a bit carried away with that reply!!
Federico Tomassetti
@ftomassetti
Thank you @mdproctor and Roger for your replies. Well thought and useful
Roger Howell
@MysterAitch
.... On a very different topic, does anyone have experience with @Nullable annotations? Specifically I'm curious about whether it's possible to create a custom annotation that "extends" another (thus creating a single place that it can be swapped out/changed), but general thoughts/comments/experiences would be welcomed :)
Roger Howell
@MysterAitch
I saw a few comments recently about IDE support being generally in place for annotations with that name even if they're not one of the "standard" few provided by tools, and it got me thinking! :)
Danny van Bruggen
@matozoid
Only a side note there: JP is a library that really LOVES Optional. I introduced that a few years back, and I often wondered if it was a good decision. I think, by now, that I would prefer to replace all Optionals with some kind of annotation. The only drawback is that you can't do fancy map/ifpresent stuff anymore.
But, to show the good side too: introducing consistent Optional usage and parameter null-checks did completely, 100% stamp out all null-pointer related issues. And there were a lot!
Roger Howell
@MysterAitch
Yep - there are places where optional isn't (yet) used, and the annotation would be one way to report where it hasn't yet happened and verify that we've not missed any / accidentally re-introduced any