1

I recently discovered that ZeroBrane Studio 1.90 comes with a lexer for Java, which makes it nicely syntax color Java files. However, it seems that ZB cannot list Java functions in the Outline pane, like it does for Lua and C/C++. Digging a little bit, it seems that there is no specification file for Java that (IIUC) describes syntax and keywords and what a function definition looks like in Java etc.

I tried to roll my own with the spec file for C/C++ as template, and the tiny bit of documentation from here https://studio.zerobrane.com/doc-plugin#registering-a-specification, but I could not get my mind around it. The only thing I achieved was for the syntax coloring to disappear, so I had to delete the java-lua file in the spec/ folder.

Is there any such spec file for Java available? I have googled a lot for such a thing, but to no avail. Or does anyone have a link to documentation for these things?

Any help would be appreciated. Thanks

Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56
OppfinnarJocke
  • 1,038
  • 2
  • 9
  • 21

1 Answers1

1

Something like this may work (just add it to your configuration file):

if not CMarkSymbols then dofile "spec/cbase.lua" end
local function javalex(self, editor)
  if editor.spec.lexer == "lexlpeg.java" then editor.spec.marksymbols = CMarkSymbols end
end
package { onEditorNew =  javalex, onEditorLoad = javalex }

This piggybacks on the function parser for C files, but since function definitions are similar for Java files, it should work for most of the cases. You can also check what's done in CMarkSymbols and write a similar function that does what you need for Java. I tested on simple Java files and it lists the functions/methods for me. You can also play with it and add classes and indentations for functions (similar to how it's done for Lua functions inside other functions).

Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56
  • Thanks!! This does indeed work, except that it misses the public static void main(String[] args), but at least now I have something to work from. Great. Thanks. A note to others and my future self: this code snippet goes into the user.lua file in the cfg folder. Initially I put it into a java.lua file that I placed in the spec folder, but that didn't work. – OppfinnarJocke Feb 15 '22 at 21:01
  • Right; create a separate function/file and make any adjustment you may need. I think `[]` are explicitly filtered out (because they are not valid in C), so you may want to re-enable them. – Paul Kulchenko Feb 15 '22 at 22:47