Vim Syntastic Java Unaware of Current Project Classes - java

Using Vim Syntastic with an android project. (e.g. com.myproject.project) It's not aware of classes declared within my project but outside of the current file. e.g. the following flags errors:
import com.myproject.project.SomeClass;
...
SomeClass someclass = new SomeClass();

Saw this post Configure syntastic to work fine with Android projects which solve the problem:
Method 1:
Inside vim editor
:SyntasticJavacEditClasspath
Then add the following to the buffer window
/path-to-your-app/bin/classes
/path-to-your-android-sdk/platforms/android-19/*.jar
Method 2:
Add the following to the .vimrc:
let g:syntastic_java_javac_classpath = "/<path-to-your-app>/bin/classes:/<path-to-your-android-sdk>/platforms/android-19/*.jar"

Here is a summary of the various methods which worked for me in linux vim7.4 and Syntastic3.7.0-224 with credit to each.
Method 1 - manual creation of .syntastic_javac_config
1. Edit .vimrc and use this syntax:
let g:syntastic_java_javac_config_file_enabled = 1
2. Where you edit your vim files, add this to a file named .syntastic_javac_config
let g:syntastic_java_javac_classpath = '/home/davis/progs/princeton-algos/week1/libs/algs4.jar'
Method 2 - advantage no matter where you edit the class path is known.
1. Edit .vimrc and use this syntax:
let g:syntastic_java_javac_classpath = "/home/davis/progs/princeton-algos/week1/libs/algs4.jar"
This adds the jar and
Method 3 - Automatic generation of .syntastic_javac_config file
1. Edit .vimrc and use this syntax:
let g:syntastic_java_javac_config_file_enabled = 1
2. Edit a java file with vim
3. :SyntasticJavacEditClasspath
When the edit window opens, add the class path without quotes and a newline after each entry the class path. In my case, this is the entry
for the setting includes the current folder as well:
/home/davis/progs/princeton-algos/week1/libs/algs4.jar
.
4 :wq the edit setting window
5. Now the class path is set for syntastic when editing files from that location. If you edit from a new directory, you will need to repeat the process.
Besides the comments above, this post also helped.

Related

Groovy script without default imports

Problem
With Groovy's default imports any script has access to java.{lang,util,io,net}.*, groovy.{lang,util}.*, java.math.BigInteger, and java.math.BigDecimal without importing anything.
What if I want none of that?
Is it possible to create a GroovyShell that would not have any default import?
Example demonstrating the issue
def importCustomizer = new ImportCustomizer()
// importCustomizer.clearImports() <-- I wish that would exist
def configuration = new CompilerConfiguration()
configuration.addCompilationCustomizers(importCustomizer)
def binding = new Binding("Date", "today")
def shell = new GroovyShell(binding, configuration)
println shell.evaluate("Date")
It prints class java.util.Date.
I'd like to get today instead, using Date from the binding.
(It's just an example, inspired by this recent question).
What I have tried so far
With CompilerConfiguration and ImportCustomizer, I can only add more imports, I don't know how to start from a clean slate.
I've also seen this answer (for which I just fixed the dead link), which pointed me to where those default imports are defined, but I don't see a way to remove imports, again it's only about adding more.
It looks like I have to hook "Semantic Analysis" phase:
This includes resolving classes, static imports and scope of variables.
Using groovyConsole confirms this: if I type x=Date in there, then use "Script" menu → "Inspect AST", the tool shows:
after "Conversion" I still have x=Date
after "Semantic Analysis" I see x = java.util.Date
And at that phase the ResolveVisitor does its thing (using default imports) and I have not found a way to get around that.

Netbeans SVN commit with keywords in header [duplicate]

My requirement is simple. At the beginning of each file there should be a block comment like this:
/*
* This file was last modified by {username} at {date} and has revision number {revisionnumber}
*/
I want to populate the {username}, {date} and {revisionnumber} with the appropriate content from SVN.
How can I achieve this with NetBeans and Subversion? I have searched a lot but I can't find exactly what I need.
I looked at this question and got some useful information. It is not exactly duplicate because I am working with NetBeans but the idea is the same. This is my header:
/*
* $LastChangedDate$
* $LastChangedRevision$
*/
Then I go to Team > Subversion > Svn properties and add svn:keywords as property name and LastChangedDate LastChangedRevision as property value.
And when I commit from NetBeans it looks like this:
/*
* $LastChangedDate: 2012-02-13 17:38:57 +0200 (Пн, 13 II 2012) $
* $LastChangedRevision: 27 $
*/
Thanks all for the support! I will accept my answer because other answers do not include the NetBeans information. Nevertheless I give +1 to the other answers.
As this data only exists after the file was committed it should be set by SVN itself, not a client program. (And client-side processing tends to get disabled or not configured at all.) This means there is no simple template/substitute like you want, because then after the first replacement the template variables would be lost.
You can find information abut SVN's keyword substitution here. Then things like $Rev$ can be replaced by $Rev: 12 $.
You can do this with The SubWCRev Program.
SubWCRev is Windows console program which can be used to read the
status of a Subversion working copy and optionally perform keyword
substitution in a template file. This is often used as part of the
build process as a means of incorporating working copy information
into the object you are building. Typically it might be used to
include the revision number in an “About” box.
This is typically done during the build process.
If you use Linux, you can find a Linux binary here. If you wish, you could also write your own using the output of svn log.
I followed Petar Minchev's suggestions, only I put the $LastChangedRevision$ tag not in a comment block but embedded it in a string. Now it is available to programmatically display the revision number in a Help -> About dialog.
String build = "$LastChangedRevision$";
I can later display the revision value in the about dialog using a String that has all of the fluff trimmed off.
String version = build.replace("$LastChangedRevision:", "").replace("$", "").trim();
I recommend a slightly different approach.
Put the following header at the top of your source files.
/*
* This file was last modified by {username} at {date} and has revision number {revisionnumber}
*/
Then add a shell script like this
post update, checkout script
USERNAME=# // use svnversion to get username
DATE=# // use svnversion to get revisio nnumber
sed -e "s#{username}#${USERNAME}#" -e "s#{date}#${DATE}#" ${SOURCE_CONTROL_FILE} > ${SOURCE_FILE}
pre commit script
cat standard_header.txt > ${SOURCE_CONTROL_FILE}
tail --lines $((${LENGTH}-4)) ${SOURCE_FILE} >> ${SOURCE_CONTROL_FILE}

method renaming code in java eclipse for code refactoring

Is there any code could get for renaming method in java eclipse plugin for code re-factoring?
For instance, if want to change method name at one place , it may get changed at all other places.
visit http://pdplab.it.uom.gr/teaching/sunjava/eclipse-java.html
The starting point corresponding to Refactor >> Rename is org.eclipse.jdt.ui.actions.RenameAction. Start by looking at the package org.eclipse.jdt.core.refactoring.descriptors and the class org.eclipse.ltk.core.refactoring.Refactoring:
RefactoringContribution contribution =
RefactoringCore.getRefactoringContribution(IJavaRefactorings.RENAME_METHOD);
RenameJavaElementDescriptor descriptor =
(RenameJavaElementDescriptor) contribution.createDescriptor()

How to show arguments of java function in vim + eclim?

I have configured vim + eclim OK. Now I can use Ctrl+X and Ctrl+U complete functions. But there is no arguments hint. For example,
FileInputStream fins = new FileInputStream(/* what arguments can be used here? eclipse will show those but eclim not */);
how to show arguments hint in vim + eclim?
Resurrecting this old question, since I stumbled on this.
You can use eclim to lookup the java docs of the class and look through the list of constructors that way using the :JavaDocSearch command.
Because the command uses a browser to render the javadocs, you'll need to add to your .vimrc:
let g:EclimBrowser = 'browser-executable-name'
Replacing browser-executable-name with your console-based browser of choice. Example: lynx, links, w3m
Then navigate over FileInputStream with your cursor and run the command :JavaDocSearch and it will pop up the java doc for the class.
Or enter the class name manually: :JavaDocSearch java.io.FileInputStream
You can use the YouCompleteMe (YCM) plugin with options
let g:ycm_add_preview_to_completeopt = 1
let g:ycm_autoclose_preview_window_after_insertion = 1
Note that this does not work for your Constructor invocations. But at least prototypes for method calls will be shown.
Also, if you don't like the auto-popup of YCM, it can be switched off.

Installing libfprint and wrapping with Jlibfprint

I developed a fingerprint application which captures a finger and saved it to the file system. Now I am try to find the minutiae using the libfprint
I am also using Jlibfprint to wrap the app for java part. In the ReadMe file there is some instructions for calling a function
int fpi_img_compare_print_data(struct fp_print_data *enrolled_print,
struct fp_print_data *new_print)
Instructions is:
1. To give the ability to compare two fingerprint data in Jlibfprint
you probabily need to patch the library in this way:
- in libfprint find the file img.c and open it
- find the function
int fpi_img_compare_print_data(struct fp_print_data *enrolled_print,
struct fp_print_data *new_print)
- add the attribute "API_EXPORTED" before the definition of the function:
API_EXPORTED int fpi_img_compare_print_data(struct fp_print_data *enrolled_print,
struct fp_print_data *new_print)
2. Open the jlibfprint_jni/Makefile file, search for the ADD_INCLUDE variable (near line 53),
and specify the JDK include library and the path of the source files of the libfprint
you have just patched. Please take care to add also this subfolder: libfprint/nbis/include.
After completing all instructions when I try to use the function I get function was out of scope error.
I think I am doing something wrong here :
specify the path of the source files of the libfprint
you have just patched.
Any suggestions? Thanks in advance.
This is the inner interface, if you wanna use you must find the related object file in your build path, besides, you should add the function declaration in you .h file.

Categories