Is there an action to take over code snippets from JavaDoc?

已回答

Hi all!

I know of live templates but I don't want to create templates for this. Instead, I want to insert code snippets which are part of the JavaDoc of e.g. a method into my code.

Do you know of any builtin functionality in this direction? This could become even more interesting when the following Java feature becomes live: https://openjdk.java.net/jeps/413.

0

Could you please clarify with an example how should this work? Thank you.

0

Sure. Have e.g. a look at the JDK lib method java.nio.file.Files#newByteChannel. The method comment contains some example code. When I use this method in the code and I hit some magical key combination, the example is inserted into my code, like this:

Path path = ...

// open file for reading
ReadableByteChannel rbc = Files.newByteChannel(path, EnumSet.of(READ)));

// open file for writing to the end of an existing file, creating
// the file if it doesn't already exist
WritableByteChannel wbc = Files.newByteChannel(path, EnumSet.of(CREATE,APPEND));

// create file with initial permissions, opening it for both reading and writing
FileAttribute<Set<PosixFilePermission>> perms = ...
SeekableByteChannel sbc =
Files.newByteChannel(path, EnumSet.of(CREATE_NEW,READ,WRITE), perms);

Then I could pick the code snippet that I want to use and remove the rest.

This might not be the best example but I hope you get the point.

0

Thank you for clarifications! There is no such functionality exists. It possibly could be useful for someone. Please feel free to file such a request for people to vote on it. I think, it could also be implemented as a nice IDE plugin.

0

Thanks for the answer. Then I know what options I have.

Have a nice day!

0

请先登录再写评论。