Function list with Java problems
-
I’ve found several problems using function list for Java.
-
closing bracket “}” must not be the last character
there must be at least one chcracter beyond. Can be space or newline.public class MyClass {
void method() {
}
} -
comments don’t work at all
If there is comment inside my class the function list produces no output at all.public class MyClass {
// this comment must not be here
/* this also breaks the functionlist */
void method() {
// even this comment is wrong
}
} -
nested classes not recognized
No support for nested classes. I would really appreciate if ClassRange would be recursivepublic class OuterClass {
private class InnerClass { // this class is not in functionlist
void innerMethod() { // this method is placed in OuterClass
}
}
void outerMethod() {
}
} -
template classes extending other templates
I created my custom Collection. The implemented interface destroyed the function list.public class MyCollection<T> implements Collection<T> {
void overrideCollectionMethods() {
}
} -
templates limiting the template type
My collection was used for certain types only. This was also not recognized.public class MyCollection<T extends MyInterface> {
void someMethod() {
}
}
-
-
- Known issue, is being worked on;
- Known issue, is being worked on;
- Correct, nested classes are not supported; It’s implementation raises a whole new set of questions/challenges; Won’t implement in near future;
- I’ll look into this;
- I’ll look into this (as related to no.4).
-
-
interface (abstract classes) methods are not recognized
regex for method recognition requires method implementation {…}. Abstract methods are not recognized.public interface MyInterface {
public void method();
}
-
-
I did some investigation on templates and I ended up with this FunctionList. Please check it out.
Comment is commented out (ad 2.).<parser id ="java" displayName="Java" c_ommentExpr="(?s:/\*.*?\*/)|(?m-s://.*$)" > <classRange mainExpr ="^[\t\x20]*((public|protected|private|static|final|abstract|synchronized|@(\w)+)\s+)*(class|enum|interface|@interface)\s+(?'D'\s*\w+(\s*<(?'G'\s*(((\w+\.)*(?&D))|((\?|\w+)(\s+(extends|super)\s+(?&D))?)))(\s*,(?&G))*\s*>)?)(\s+extends\s+(?&D))?(\s+implements\s+(?&D)(\s*,(?&D))*)?\s*\{" openSymbole ="\{" closeSymbole="\}" > <className> <nameExpr expr="(class|enum|interface|@interface)\s+\w+" /> </className> <function mainExpr="^[\t\x20]*((public|protected|private|static|final|abstract|synchronized|@(\w)+)\s+)*(\s*<(?&G)\s*>)?(?'D'\s*(\w+\.)*\w+(\s*<(?'G'\s*((?&D)|((\?|\w+)(\s+(extends|super)\s+(?&D))?)))(\s*,(?&G))*\s*>)?(\[\s*\])*)\s+(?!(if|while|for|switch|catch|synchronized|this|super)\b)\w+\(((?'A'(?&D)\s+\w+)(\s*,(?&A))*)?\)(\s+throws\s+\w+)?\s*(\{|;)" > <functionName> <funcNameExpr expr="\w+(\s*<.*>)?\s*\(" /> <funcNameExpr expr="\w+" /> </functionName> </function> </classRange> </parser> -
A= Argument?
D= Declarator?
G= Generic? -
@Petr-Skýpala Based on your post I adapted the parser to:
<parser displayName="Java" id ="java_syntax" > <classRange mainExpr ="(?x) # Utilize inline comments (see `RegEx - Pattern Modifiers`) ^[\t\x20]* # leading whitespace (?: (?-i:abstract|final|private|protected|public|static|synchronized|@\w+) \s+ )* (?-i:class|enum|@?interface) \s+ (?'DECLARATOR' (?'VALID_ID' # valid identifier, use as subroutine \b(?!(?-i: a(?:bstract|ssert)|b(?:oolean|reak|yte)|c(?:ase|atch|har|lass|on(?:st|tinue))| d(?:efault|o(?:uble)?)|e(?:lse|num|xtends)|f(?:inal(?:ly)?|loat|or)| goto|i(?:f|mp(?:lements|ort)|nstanceof|nt(?:erface)?)| long|n(?:ative|ew)|p(?:ackage|rivate|rotected|ublic)|return| s(?:hort|tatic|trictfp|uper|witch|ynchronized)|th(?:is|rows?)|tr(?:ansient|y)| vo(?:id|latile)|while )\b) # keywords, not to be used as identifier [A-Za-z_]\w* # valid character combination for identifiers ) (?: \s*\x3C # start-of-template indicator (?'GENERIC' # ...match first generic, use as subroutine \s* (?: (?: # optional parent type name(s) (?&VALID_ID) # ...parent type name \. # ...parent-sibling separator )* (?&DECLARATOR) | (?: \? # .. | \w+ # .. name ) (?: # optional type extension \s+(?-i:extends|super) \s+(?&DECLARATOR) )? ) ) (?: # ...match consecutive generic objects, they are \s*, # separated by a comma (?&GENERIC) )* \s*\x3E # ...end-of-template indicator )? ) (?: # optional object extension \s+(?-i:extends) \s+(?&DECLARATOR) )? (?: # optional object implementation \s+(?-i:implements) \s+(?&DECLARATOR) # ...match first object (?: # ...match consecutive objects, they are \s*, # separated by a comma \s*(?&DECLARATOR) )* )? \s*\{ # whatever, up till start-of-body indicator " openSymbole ="\{" closeSymbole="\}" > <className> <nameExpr expr="(?-i:class|enum|@?interface)\s+\K\w+(?:\s*\x3C.*?\x3E)?" /> </className> <function mainExpr="(?x) # Utilize inline comments (see `RegEx - Pattern Modifiers`) ^[\t\x20]* # leading whitespace (?: (?-i:abstract|final|native|private|protected|public|static|synchronized|@\w+) \s+ )* (?: \s*\x3C # start-of-template indicator \s*(?&GENERIC) \s*\x3E # end-of-template indicator )? \s* (?'DECLARATOR' (?: # optional parent type name(s) [A-Za-z_]\w* # ...parent type name \. # ...parent-sibling separator )* [A-Za-z_]\w* # type name (?: # optional template type \s*\x3C # ...start-of-template indicator (?'GENERIC' # ...match first generic object, use as subroutine \s* (?: (?&DECLARATOR) | (?: \? # .. | \w+ # .. name ) (?: # optional type extension \s+(?-i:extends|super) \s+(?&DECLARATOR) )? ) ) (?: # ...match consecutive generic objects, they are \s*, # separated by a comma (?&GENERIC) )* \s*\x3E # ...end-of-template indicator )? (?: # optional compound type \s*\[ # ...start-of-compound indicator \s*\] # ...end-of-compound indicator )* ) \s+ (?'VALID_ID' # valid identifier, use as subroutine \b(?!(?-i: a(?:bstract|ssert)|b(?:oolean|reak|yte)|c(?:ase|atch|har|lass|on(?:st|tinue))| d(?:efault|o(?:uble)?)|e(?:lse|num|xtends)|f(?:inal(?:ly)?|loat|or)| goto|i(?:f|mp(?:lements|ort)|nstanceof|nt(?:erface)?)| long|n(?:ative|ew)|p(?:ackage|rivate|rotected|ublic)|return| s(?:hort|tatic|trictfp|uper|witch|ynchronized)|th(?:is|rows?)|tr(?:ansient|y)| vo(?:id|latile)|while )\b) # keywords, not to be used as identifier [A-Za-z_]\w* # valid character combination for identifiers ) \s* \( # start-of-arguments indicator (?: # optional arguments (?'ARG' # ...match first argument, use as subroutine \s* (?-i:final\s+)? (?&DECLARATOR) \s+(?&VALID_ID) # argument name ) (?: # ...consecutive arguments are \s*, # separated by commas (?&ARG) )* )? \) # end-of-arguments indicator (?: # optional exceptions \s*(?-i:throws) \s+(?&VALID_ID) # ...first exception name (?: # ...consecutive exception names are \s*, # separated by commas \s*(?&VALID_ID) )* )? \s* (?: # function declaration ends with ... \{ # ...a start-of-function-body indicator or | ; # ...an end-of-declaration indicator ) " > <functionName> <funcNameExpr expr="\w+(?=\s*\()" /> </functionName> </function> </classRange> </parser>Could you please test/verify it.
Thanx! -
Hi MAPJe71,
Ah, Indeed ! I’ve never thought yet, about using the
(?x)modifier in regexes of the functionList.xml file, but you’re quite right : this improve readability of text and, surely, helps in achieving overall exact regexes :-))Cheers,
guy038
-
Great job. You’re a genius. Making the regex multiline and commentes is real blessing.
I’ve added several whitespaces \s where i missed them.
I’ve added bounded templates <T extends A & B>
I’ve added multiple inheritance - interface can extend multiple interfaces
I’ve generalized the DECLARATOR and GENERIC groups a bit.The result is far from perfect, but it completely satisfies my needs. I don’t mind if it recognizes multiple inheritance. We can leave some work for compiler too. I hope this class-function template will help with other languages.
<parser displayName="Java" id ="java" > <classRange mainExpr ="(?x) # Utilize inline comments (see `RegEx - Pattern Modifiers`) ^[\t\x20]* # leading whitespace (?: (?-i: abstract |final |native |p(?:rivate|rotected|ublic) |s(?:tatic|trictfp|ynchronized) |transient |volatile |@[A-Za-z_]\w* # qualified identifier (?: \. [A-Za-z_]\w* )* ) \s+ )* (?-i:class|enum|@?interface) \s+ (?'DECLARATOR' (?'VALID_ID' # valid identifier, use as subroutine \b(?!(?-i: a(?:bstract|ssert) |b(?:oolean|reak|yte) |c(?:ase|atch|har|lass|on(?:st|tinue)) |d(?:efault|o(?:uble)?) |e(?:lse|num|xtends) |f(?:inal(?:ly)?|loat|or) |goto |i(?:f|mp(?:lements|ort)|nstanceof|nt(?:erface)?) |long |n(?:ative|ew) |p(?:ackage|rivate|rotected|ublic) |return |s(?:hort|tatic|trictfp|uper|witch|ynchronized) |th(?:is|rows?) |tr(?:ansient|y) |vo(?:id|latile) |while )\b) # keywords, not to be used as identifier [A-Za-z_]\w* # valid character combination for identifiers ) (?: \s*\x3C # start-of-template indicator (?'GENERIC' # ...match first generic, use as subroutine \s* (?: (?&DECLARATOR) # use named generic | \? # or unknown ) (?: # optional type extension \s+(?-i:extends|super) \s+(?&DECLARATOR) (?: # multiple bounds \s+\x26 # ...are ampersand separated \s+(?&DECLARATOR) )* )? (?: # match consecutive generics objects \s*, # ...comma separated (?&GENERIC) )? ) \s*\x3E # ...end-of-template indicator )? (?: # package and|or nested classes \. # ...are dot separated (?&DECLARATOR) )? ) (?: # optional object extension \s+(?-i:extends) \s+(?&DECLARATOR) (?: # ...match consecutive objects, they are \s*, # separated by a comma \s*(?&DECLARATOR) )* )? (?: # optional object implementation \s+(?-i:implements) \s+(?&DECLARATOR) # ...match first object (?: # ...match consecutive objects, they are \s*, # separated by a comma \s*(?&DECLARATOR) )* )? \s*\{ # whatever, up till start-of-body indicator " openSymbole ="\{" closeSymbole="\}" > <className> <nameExpr expr="(?-i:class|enum|@?interface)\s+\K\w+(?:\s*\x3C.*?\x3E)?" /> </className> <function mainExpr="(?x) # Utilize inline comments (see `RegEx - Pattern Modifiers`) ^[\t\x20]* # leading whitespace (?: (?-i: abstract |final |native |p(?:rivate|rotected|ublic) |s(?:tatic|trictfp|ynchronized) |transient |volatile |@[A-Za-z_]\w* # qualified identifier (?: \. # ... dot separated [A-Za-z_]\w* )* ) \s+ )* (?: \s*\x3C # start-of-template indicator (?&GENERIC) \s*\x3E # end-of-template indicator )? \s* (?'DECLARATOR' [A-Za-z_]\w* # type name (?: # optional parent type name(s) \. # ...parent-sibling separator [A-Za-z_]\w* # ...parent type name )* (?: \s*\x3C # start-of-template indicator (?'GENERIC' # ...match first generic, use as subroutine \s* (?: (?&DECLARATOR) # use named generic | \? # or unknown ) (?: # optional type extension \s+(?-i:extends|super) \s+(?&DECLARATOR) (?: # multiple bounds \s+\x26 # ...are ampersand separated \s+(?&DECLARATOR) )* )? (?: # match consecutive generics objects \s*, # ...comma separated (?&GENERIC) )? ) \s*\x3E # ...end-of-template indicator )? (?: # package and|or nested classes \. # ... are dot separated (?&DECLARATOR) )? (?: # optional compound type \s*\[ # ...start-of-compound indicator \s*\] # ...end-of-compound indicator )* ) \s+ (?'VALID_ID' # valid identifier, use as subroutine \b(?!(?-i: a(?:bstract|ssert) |b(?:oolean|reak|yte) |c(?:ase|atch|har|lass|on(?:st|tinue)) |d(?:efault|o(?:uble)?) |e(?:lse|num|xtends) |f(?:inal(?:ly)?|loat|or) |goto |i(?:f|mp(?:lements|ort)|nstanceof|nt(?:erface)?) |long |n(?:ative|ew) |p(?:ackage|rivate|rotected|ublic) |return |s(?:hort|tatic|trictfp|uper|witch|ynchronized) |th(?:is|rows?) |tr(?:ansient|y) |vo(?:id|latile) |while )\b) # keywords, not to be used as identifier [A-Za-z_]\w* # valid character combination for identifiers ) \s*\( # start-of-arguments indicator (?'ARG' # ...match first argument, use as subroutine \s*(?-i:final\s+)? (?&DECLARATOR) \s+(?&VALID_ID) # argument name (?: # ...consecutive arguments are \s*, # separated by commas (?&ARG) )? )? \) # end-of-arguments indicator (?: # optional exceptions \s*(?-i:throws) \s+(?&VALID_ID) # ...first exception name (?: # ...consecutive exception names are \s*, # separated by commas \s*(?&VALID_ID) )* )? \s*(?: # function declaration ends with ... \{ # ...a start-of-function-body indicator or | ; # ...an end-of-declaration indicator ) " > <functionName> <funcNameExpr expr="\w+(?=\s*\()" /> </functionName> </function> </classRange> </parser> -
M MAPJe71 referenced this topic on
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login