Skip to content

snippets: Add java snippets

Ghost User requested to merge (removed):java-snippets into master

Basic snippets to code in java

Captura_del_escritorio_de_30-05-18_00_54_11{}

That snippets will cover the defaults. but in next iterations we can go further


You will see a filter called descend_path, which removes first leading node in path. In maven source are on:

  • ${project.path}/src/main/java
  • ${project.path}/src/main/test

and packages come after its path.

so org.gnome.examples.button.Hello class will have this path:

${project.path}/src/main/java/org/gnome/examples/button/Hello.java

I can remove project path (added a relative_dirname for that) from file path but cannot remove src/main/java with an agnostic plugin. So I remove it calling 3 times that filter.

src/main/java might not be the path for source, is just the default. We need something like snippet filters by language. In this case need to ask maven for the property project.build.sourceDirectory:

$ mvn help:evaluate -Dexpression=basedir | grep -v '^\[INFO\]'
/home/alberto/projects/java/pressme

$ mvn help:evaluate -Dexpression=project.build.sourceDirectory | grep -v '^\[INFO\]'
/home/alberto/projects/java/pressme/src/main/java

The grep part is needed, maven cannot suppress its own log (for real)

One can check project.build.testDirectory (src/test/java) or several other properties, but didn't see a way to provide filters based on BuildSystem. They could be called be something like mvn_remove_source_dir_filter

Edited by Ghost User

Merge request reports