Git Product home page Git Product logo

Comments (4)

chriswhocodes avatar chriswhocodes commented on July 28, 2024

Turns out regex is the wrong tool for the job once you go past simple method signatures and get into heavy generics.
Looks like a full parser like ANTLR is needed.

http://stackoverflow.com/questions/3007139/regex-to-match-a-java-method-signature

http://stackoverflow.com/questions/5744549/java-regex-for-a-method-signature-with-a-collectiongenerictype-return-type

Will investigate further to decide correct fix.

from jitwatch.

nicoulaj avatar nicoulaj commented on July 28, 2024

If this can help, parboiled provides a Java parser in its examples section: https://github.com/sirthias/parboiled/tree/master/examples-java/src/main/java/org/parboiled/examples/java/

from jitwatch.

chriswhocodes avatar chriswhocodes commented on July 28, 2024

Thanks :)

Thinking about this more, JITWatch knows the declared method on the Class e.g.

public static java.lang.Object[] java.util.Arrays.copyOf(java.lang.Object[],int,java.lang.Class)

and is trying to create a regex that will match this in the Java source file (a big String) by adding wildcards for things it cannot know (variable names, if types are fully qualified, etc.)

Currently it comes up with:

^(.*)public static ([0-9a-zA-Z_\.]*)Object\[\] copyOf( )*\(( )*([0-9a-zA-Z_\.]*)Object\[\]( )+([0-9a-zA-Z_]+),( )*int( )+([0-9a-zA-Z_]+),( )*([0-9a-zA-Z_\.]*)Class( )+([0-9a-zA-Z_]+)( )*\)(.*)$

Which will match with the type-erased signature but not with the generics syntactic sugar.

Given that generics can substitute the type names with E,T,U, ... I think the best solution might be to try a first pass search with the regex and then attempt a "best fit" search if that fails.

from jitwatch.

chriswhocodes avatar chriswhocodes commented on July 28, 2024

Added best match fallback algorithm where regex fails to match source code method signatures with generics.

from jitwatch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.