by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Eric Peters
@er1c
val PROPERTY = 0x00001000
val LAZY = 0x00002000
val OBJECT = 0x00004000
val IMPLICIT = 0x00008000
Eric Peters
@er1c
woof, big learning curve day, I figure out what I needed for the modifiers
Eric Peters
@er1c
I kind of get the difference between getElementType and getCommonType but is there a better explanation? What was the 2.5.1 behavior/equivalent?
I'm speculating that it shouldn't be used, and the variables should have the type now?
maybe just UnionType
jimshowalter
@jimshowalter
We have a project that's using an older version of javaparser (3.5.9). I want to upgrade it to the latest, which normally just involves reading release notes sequentially and updating code as needed. But I can't find the release notes! I found https://github.com/javaparser/javaparser/releases, which seems to be autogenerated, and doesn't have any useful documentation. Where should I be looking?
jimshowalter
@jimshowalter
To be more-specific, it's javaparser-core.
jimshowalter
@jimshowalter
Finally found it: https://github.com/javaparser/javaparser/blob/master/changelog.md. It would be helpful for the main javaparser page to link to the changelog.
Eric Peters
@er1c
@jimshowalter create a PR that does sound useful!
Eric Peters
@er1c
@matozoid down to 25 compile errors!
Danny van Bruggen
@matozoid
@er1c many changes get a short mention in that changelog, so if you're lost you can try searching it.
Eric Peters
@er1c
7 errors :)
trying to figure out what to do with Parameters to determine if the type is an array since getId is gone
Danny van Bruggen
@matozoid
Modifiers have been redesigned a few times - I don't think you should need the metamodel!
Eric Peters
@er1c
I didn't need metamodel
Danny van Bruggen
@matozoid
Array types are made by wrapping a type inside an ArrayType for every []
Eric Peters
@er1c
object ScalaModifier {
  object Keyword {
    val LAZY = Modifier.Keyword.valueOf("lazy")
    val OBJECT = Modifier.Keyword.valueOf("object")
    val IMPLICIT = Modifier.Keyword.valueOf("implicit")

    val VAL = Modifier.Keyword.valueOf("val")
    val VAR = Modifier.Keyword.valueOf("var")

    // Dummy Keywords used to keep state
    val PROPERTY = Modifier.Keyword.valueOf("@@property@@")

    val DummyKeywords: Seq[Modifier.Keyword] = Seq(PROPERTY)
  }
}
created what I needed that way
I'm guessing "Array[" * v.getId.getArrayCount + n.getElementType.accept(this, arg) + "]" * v.getId.getArrayCount + is just n.getElementType.accept(this, arg)

```object ScalaModifier {
object Keyword {
val LAZY = Modifier.Keyword.valueOf("lazy")
val OBJECT = Modifier.Keyword.valueOf("object")
val IMPLICIT = Modifier.Keyword.valueOf("implicit")

val VAL = Modifier.Keyword.valueOf("val")
val VAR = Modifier.Keyword.valueOf("var")

// Dummy Keywords used to keep state
val PROPERTY = Modifier.Keyword.valueOf("@@property@@")

val DummyKeywords: Seq[Modifier.Keyword] = Seq(PROPERTY)

}
}```

considering there are so many .getFoo() that return Optional it would be kind of nice to have constructors that also take the Optional values
Eric Peters
@er1c
public interface GenericVisitor<R, A> {
what's the R suppose to be? just Node?
Eric Peters
@er1c
3.16.1 compiling! Still alot of unimplemented stuff though :) figured out the generic visitor issue
Eric Peters
@er1c
Is the a reason GenericVisitor doesn't have ReferenceType as one of the signatures?
Danny van Bruggen
@matozoid
ReferenceType used to be a stand-alone class that wrapped the type that is a reference, but it is now the superclass of the types that are reference types. Only the leaf types are in the visitors.
AbdelkaderElMehdi
@AbdelkaderElMehdi
Hello, i'm new to JavaParser !
I'm developping a maven plugin that scans the code to know which Spring Rest-Endpoint trigger an external http request to other micro-services, we are using a custom class that makes http request called Accessible, the goal is the to be able to draw a complete graph of dependencies between multiple endpoints of microservices,
The problem that i have now, is the to know to trace the function calls flow, from the method of the controller to the Accessible-call to make an external http request, the program flow might go trough multiple function calls successively
Is there a way to do that with java parser, or i will have to manually construct a function call graph ?
Thank you all !
Lucas Gontijo
@Lucasgontijo0
You want to combine the AST from all the files right?
I found a similar question on Github, take a look: javaparser/javaparser#1239
AbdelkaderElMehdi
@AbdelkaderElMehdi
Yes, if it's in some sort, a "find usage" like in IDE's
I'll take a look
Thank you !!
Eric Peters
@er1c
@matozoid ahh thanks, I see that now!
Eric Peters
@er1c
scala> com.mysema.scalagen.ScalaModifier
java.lang.IllegalArgumentException: No enum constant com.github.javaparser.ast.Modifier.Keyword.lazy
  at java.lang.Enum.valueOf(Enum.java:238)
  at com.github.javaparser.ast.Modifier$Keyword.valueOf(Modifier.java:92)
looks like I get a runtime error here...damnit
@matozoid is there any way for me to create my own keywords? or is this the DataKey you mentioned?
Eric Peters
@er1c
think I have what I need with the DataKey
Danny van Bruggen
@matozoid
Good
Lucas Gontijo
@Lucasgontijo0
@AbdelkaderElMehdi progress?
AbdelkaderElMehdi
@AbdelkaderElMehdi

@Lucasgontijo0 Hello,
I was able to construct the method call tree manually, by creating indexing all methods in a list and linking everything with a recursive function, it works but i think i'll go for your solution since it might bug if there's overloading of functions ...
beside this, i have a new question that concern the symbol resolving too :

Accessor a = new Accessor( a, b, c);
a.getApiResponseOf(...);

a= new Accessor(d,e,f);
a.getApiResponseOf(...);

I want to get the information about each pair of constructor and method call of getApiResponseOf(...);
I need some MetaData present in the parameters passed to the constructor and also another data in the call function itself,
The problem that i encounter here, is that i don't know how to construct the specific pair, so we can't use the Accessor with a,b,c with the second method call,

Do you have any clues ?
Thank you all !

Eric Peters
@er1c
    case b: BlockStmt => if (b.getStatements != null && b.getStatements.size == 1) {
        val foo: Node = b.getStatements.get(0)
        if (foo.isInstanceOf[NameExpr]) {
          throw new IllegalArgumentException(s"wtf foo: $b")
Trying to figure out if I did this to myself, there isn't any way a NameExpr should be a Statement, right?
Eric Peters
@er1c
spoiler: it was my bug :)
Maarten Coene
@maartenc
Hi, I've created 2 PR's yesterday... any change this could be merged soon? (I don't want to pressurize you, it's just to know if we'll need to patch the library ourselfs, or if I can still wait for a couple of days and use an 'official' snapshot build of this library).
Shashank
@shankyty
Hi @all,
Is it possible using java parser to list all static method to be invoked by a method in class?
1 reply
mindajalaj
@mindajalaj
Hi @all, how to use lexicalPreservingprinter along with source root ? Sharing the code snippet below, i have used parserConfiguration.setLexicalPreservationEnabled(true);statement but it does not looks like working, i am not sure how to use sourceRoot.setPrinter() with LexicalPreservingPrinter class
mindajalaj
@mindajalaj
CombinedTypeSolver typeSolver = new CombinedTypeSolver(
                                            new ReflectionTypeSolver(), new JavaParserTypeSolver(codeDir));

        ParserConfiguration parserConfiguration = new ParserConfiguration()
                                                    .setSymbolResolver(new JavaSymbolSolver(typeSolver));

        parserConfiguration.setLexicalPreservationEnabled(true);
        // Parse all source files
        SourceRoot sourceRoot = new SourceRoot(codeDir.toPath());
        sourceRoot.setParserConfiguration(parserConfiguration);

        List<ParseResult<CompilationUnit>> parseResults;

        try {
            parseResults = sourceRoot.tryToParse("");
            // Now get all compilation units
            compilations = parseResults.stream()
                                .filter(ParseResult::isSuccessful)
                                .map(r -> r.getResult().get())
                                .collect(Collectors.toList());

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        for (int i =0; i < compilations.size(); i++) {    
            CompilationUnit cuu = compilations.get(i);
            LexicalPreservingPrinter.setup(cuu);    
        }

        modifyCode(compilations);

//  sourceRoot.setPrinter(new PrettyPrinter(new PrettyPrinterConfiguration().setEndOfLineCharacter("\n"))::print);
        sourceRoot.saveAll();
hsnysf
@hsnysf
hi
good morning/evening