Including a Java code snippet by method name, not line number
up vote
2
down vote
favorite
I am currently writing documents that contain large amounts of references to source code, in which I would typically include a complete method at a time.
/*
...
*/
public class MyClass {
public MyClass(String... someArguments) {
/*
...
*/
}
@Override
public String toString() {
return "Some information on this specific instance.";
}
}
Currently, I would do this for example as follows:
lstinputlisting[firstnumber=13,firstline=13,lastline=16]{./path/MyClass.java}}
This source code is kept in separate files that are being edited in parallel, resulting in the methods I want to include moving or changing its line count. The method itself might be rewritten to include additional lines, annotations, etc.
A simple addition at the beginning of the document (such as an additional import) results in all references to these lines needing to be updated.
Ideally I would like to do something like this:
importmethod{toString()}{./path/MyClass.java}
or possibly with other options/syntax:
importmethod[annotations=true]{MyClass > toString()}{./path/MyClass.java}
That would always look for the complete section of this method including annotations, JavaDoc comments, etc. as long as the method signature does not change.
Does this already exist in some package or could this be achieved with a macro?
listings java
add a comment |
up vote
2
down vote
favorite
I am currently writing documents that contain large amounts of references to source code, in which I would typically include a complete method at a time.
/*
...
*/
public class MyClass {
public MyClass(String... someArguments) {
/*
...
*/
}
@Override
public String toString() {
return "Some information on this specific instance.";
}
}
Currently, I would do this for example as follows:
lstinputlisting[firstnumber=13,firstline=13,lastline=16]{./path/MyClass.java}}
This source code is kept in separate files that are being edited in parallel, resulting in the methods I want to include moving or changing its line count. The method itself might be rewritten to include additional lines, annotations, etc.
A simple addition at the beginning of the document (such as an additional import) results in all references to these lines needing to be updated.
Ideally I would like to do something like this:
importmethod{toString()}{./path/MyClass.java}
or possibly with other options/syntax:
importmethod[annotations=true]{MyClass > toString()}{./path/MyClass.java}
That would always look for the complete section of this method including annotations, JavaDoc comments, etc. as long as the method signature does not change.
Does this already exist in some package or could this be achieved with a macro?
listings java
1
You could use text markers, see 5.7 Arbitrary linerange markers in the listings documentation.
– Ulrike Fischer
Dec 4 at 12:11
Thanks, I was always looking at an outdated version of the reference, this made me search for the current version of the documentation.
– Z42
Dec 4 at 20:18
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am currently writing documents that contain large amounts of references to source code, in which I would typically include a complete method at a time.
/*
...
*/
public class MyClass {
public MyClass(String... someArguments) {
/*
...
*/
}
@Override
public String toString() {
return "Some information on this specific instance.";
}
}
Currently, I would do this for example as follows:
lstinputlisting[firstnumber=13,firstline=13,lastline=16]{./path/MyClass.java}}
This source code is kept in separate files that are being edited in parallel, resulting in the methods I want to include moving or changing its line count. The method itself might be rewritten to include additional lines, annotations, etc.
A simple addition at the beginning of the document (such as an additional import) results in all references to these lines needing to be updated.
Ideally I would like to do something like this:
importmethod{toString()}{./path/MyClass.java}
or possibly with other options/syntax:
importmethod[annotations=true]{MyClass > toString()}{./path/MyClass.java}
That would always look for the complete section of this method including annotations, JavaDoc comments, etc. as long as the method signature does not change.
Does this already exist in some package or could this be achieved with a macro?
listings java
I am currently writing documents that contain large amounts of references to source code, in which I would typically include a complete method at a time.
/*
...
*/
public class MyClass {
public MyClass(String... someArguments) {
/*
...
*/
}
@Override
public String toString() {
return "Some information on this specific instance.";
}
}
Currently, I would do this for example as follows:
lstinputlisting[firstnumber=13,firstline=13,lastline=16]{./path/MyClass.java}}
This source code is kept in separate files that are being edited in parallel, resulting in the methods I want to include moving or changing its line count. The method itself might be rewritten to include additional lines, annotations, etc.
A simple addition at the beginning of the document (such as an additional import) results in all references to these lines needing to be updated.
Ideally I would like to do something like this:
importmethod{toString()}{./path/MyClass.java}
or possibly with other options/syntax:
importmethod[annotations=true]{MyClass > toString()}{./path/MyClass.java}
That would always look for the complete section of this method including annotations, JavaDoc comments, etc. as long as the method signature does not change.
Does this already exist in some package or could this be achieved with a macro?
listings java
listings java
asked Dec 4 at 10:42
Z42
112
112
1
You could use text markers, see 5.7 Arbitrary linerange markers in the listings documentation.
– Ulrike Fischer
Dec 4 at 12:11
Thanks, I was always looking at an outdated version of the reference, this made me search for the current version of the documentation.
– Z42
Dec 4 at 20:18
add a comment |
1
You could use text markers, see 5.7 Arbitrary linerange markers in the listings documentation.
– Ulrike Fischer
Dec 4 at 12:11
Thanks, I was always looking at an outdated version of the reference, this made me search for the current version of the documentation.
– Z42
Dec 4 at 20:18
1
1
You could use text markers, see 5.7 Arbitrary linerange markers in the listings documentation.
– Ulrike Fischer
Dec 4 at 12:11
You could use text markers, see 5.7 Arbitrary linerange markers in the listings documentation.
– Ulrike Fischer
Dec 4 at 12:11
Thanks, I was always looking at an outdated version of the reference, this made me search for the current version of the documentation.
– Z42
Dec 4 at 20:18
Thanks, I was always looking at an outdated version of the reference, this made me search for the current version of the documentation.
– Z42
Dec 4 at 20:18
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f463121%2fincluding-a-java-code-snippet-by-method-name-not-line-number%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You could use text markers, see 5.7 Arbitrary linerange markers in the listings documentation.
– Ulrike Fischer
Dec 4 at 12:11
Thanks, I was always looking at an outdated version of the reference, this made me search for the current version of the documentation.
– Z42
Dec 4 at 20:18