Eclipse - spell checking inside String Quotes "" - java

When using Eclipse spell check inside comments is enabled, but when entering for example :
String myString = "why isnt this getttting cheackedd";
Eclipse isn't checking spelling inside quotes,
is there a option to set this enable ? or do i have to download a plugin for this matter ?
thanks

You need to disable
"Ignore Java String literals" under eclipse
Preferences->General->Editors->Text Editors->Spelling.

Related

Using SonarLint with VSCode. How can I change the regex rule S116 for Jave uses?

I am using Sonarlint with VSCode on a Java project on Windows 10. My project has a variable naming convention such that we use underscores as long as it isn't the first character. These variables are triggering Java Rule S116 "Field names should comply with a naming convention". The doc on this rule says that the default regex it uses is '^[a-z][a-zA-Z0-9]*$' It also says:
Parameters
Following parameter values can be set in the
SonarLint:Rules user settings. In connected mode, server side
configuration overrides local settings.
format Regular expression used to check the field names against.
(Default value: ^[a-z][a-zA-Z0-9]*$)
This strongly implies that the value of the regex can be changed by the user and that it can be done with local configuration. But I can't figure out from this information what exactly do I do to change the value. Any ideas?
In the settings GUI find the setting for this extension and change it to
^[a-z][a-zA-Z0-9_]*$
There wasn't a place in the setting GUI for this, but it can be set in the user (not workspace) settings.json file, by adding this entry:
"sonarlint.rules": {
"java:S116": {
"parameters": {
"format": "^[a-z][a-zA-Z0-9_]*$"
}
}|
}

Automatic `log.info` completion in IntelliJ IDEA?

I am using Java and I log things like:
log.info("createArticle userId={} articleId={} title={} content={}", userId, articleId, title, content);
As you can see, when inputting this line into my IDE, I have to manually write down those characters like "userId={} ". Ideally, I hope I can simply type the userId, and Intellij IDEA will automatically help me fill out both "userId={} " (in the format string) and , userId (in the arguments list).
Question: How can I do that in IntelliJ IDEA? Or, is there any other ways to type such logging lines faster?
Thanks for any suggestions!
It is possible to implement it with Live Templates and groovyScript for one of the variables: take the second segment, split it by comma, concat in something like part=${part}:
groovyScript("_1.split(',').collect { it.trim() + '={}' }.join(' ')", B)
See video

How to prepend String on each line by jline3?

I want app to print on each line its name like (shell > ):
shell > --param1 value1 --param2 value2
Is it possible to implement it by jline3?
You can do this using jline3-terminal.
It has support for 'jansi' and 'jna'. Both work near same, but jansi is a bit light weight than jna. Whereas jna is more generic.
You can follow documentation here and the also the terminal documentation here.
Prefer maven project to start with and go ahead with documentation.
Let me know for anything else.
See JLine readLine() javadoc. Add command prompt (shell >) to your CLI app call readLine method as
lineReader.readLine("shell > ", null, null);
If you want to add buffer also the default value for user to edit call readLine method as
lineReader.readLine("shell > ", null, "--param1 value1 --param2 value2");

Get highlighted variable -Eclipse

I am implementing an Eclipse plugin for C programmers.
I can't find a way to get the variable that the user already highlited.(The user will highlight a variable in the editor and I need to know which variable it is/variable's name/location of this variable in the editor, like line number..)
Can anyone help to achieve that ?
Well after searching in some links, I achvieved that by using the ISelectionProvider and ITextSelection Interfaces. Here a code to get the name of the highlighted variable :
ISelectionProvider selProvider = textEditor.getSelectionProvider();
ITextSelection txtSel = (ITextSelection) selProvider.getSelection();
String varName = txtSel.getText();

Using Gradle to generate JavaDoc with newline characters in the "header"

UPDATE: Made a posting on the Gradle forum. Please star this issue so that it gets more attention http://gsfn.us/t/4jedo
I'm in the process of transitioning from a primarily Ant build environment into a Gradle one. One sticking point is injecting Google Analytics and Adsense code into the JavaDoc. This is done by putting java script code into the header or bottom panels. For an example of what I'm currently doing, look at this question CDATA.
The problem with Gradle is that it can't handle newline characters in the string which is to be inserted. If you filter out those characters you break the script. Here is a code sniplet:
task alljavadoc(type: Javadoc) {
source = javadocProjects.collect { project(it).sourceSets.main.allJava }
classpath = files(javadocProjects.collect { project(it).sourceSets.main.compileClasspath })
destinationDir = file("${buildDir}/docs/javadoc")
configure(options) {
header = "this is\na test which should fail"
}
}
The critical part is "header =". If you remove the '\n' character it will work just fine. Otherwise the call to javadoc, which Gradle makes, will fail with the following error:
Successfully started process 'command '/opt/jdk/jdk1.7.0_21/bin/javadoc''
javadoc: error - Illegal package name: ""
javadoc: warning - No source files for package a
javadoc: warning - No source files for package test
javadoc: warning - No source files for package which
javadoc: warning - No source files for package should
javadoc: warning - No source files for package fail
The actual java script that I wish to include is below. Note that I can't hack it by removing new line characters since that will break the script.
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- banner -->
<ins class="adsbygoogle"
style="display:inline-block;width:468px;height:60px"
data-ad-client="ca-pub-xxxxxxxxxxxxxxxxx"
data-ad-slot="xxxxxxxxx"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
As a sanity check I also passed in a string with new line characters directly to javadoc (manual) on the command line and it works just fine.
javadoc foo.java -header "This is a test
and so is this"
The output HTML:
<div class="aboutLanguage"><em>This is a test
and so is this</em></div>
</div>
I have an explanation, but i don't have a solution except for creating a new feature request in Gradle JIRA.
To generate a javadoc Gradle first generates the so-called argfile at build\tmp\javadocTaskName\javadoc.options that contains all individual options and than executes javadoc #full\path\to\build\tmp\javadocTaskName\javadoc.options command.
It is actually quite useful as you can debug the contents of that file by simply invoking javadoc #javadoc.options yourself from the command line.
It is possible to define multi-line values in the argfile by using the \ character at the end of each line inside the multi-line value.
The example header = "this is\na test which should fail" results in
-header 'this is
a test which should fail'
but we need to get
-header 'this is\
a test which should fail'
to tell javadoc that the value continues on the next line.
Now the problem is how to output that \ on each line.
The obvious attempt at header = "this is\\\na test which should fail" does not work, it will result in
-header 'this is\\
a test which should fail'
And even Groovy multi-line or slashy strings will not work and will result in similar double back slashes.
Because Gradle just replaces all single backslashes in the option values. The JavadocOptionFileWriterContext.writeValue(String) method is the culprit, the replaceAll("\\\\", "\\\\\\\\") line in particular (a regex that matches single backslash and replaces it with double backslash ).
This escaping is required for backslashes inside a line, but it should not escape a single backslash followed by the new line character. My regex-fu is not strong enough to write such a pattern, but it is surely possible.
Or even better, the escaping mechanism inside that method should replace newline characters with a single backslash followed by the newline to hide all this stuff and allow users to declare multi-line javadoc options without the need to think or even know that feature.
I would appreciate if somebody can create an issue in Gradle tracker as i can't do so from my current location. This sentence should be replaced with the link to the issue so that people with similar problem can vote and track its progress.
I tried to implement it in Gradle but I couldn't get it to work reliably on windows. If the options file has this:
-header 'this is\
a test which should fail'
It works nicely on linux/mac but fails on windows (tried on win7/java7 and some other windows+java6). I've tried with vanilla javadoc executable (without Gradle).
I'll get the fix into Gradle and it will work out of the box for linux/mac but not quite for windows. If you want to help out with windows support catch us at http://issues.gradle.org/browse/GRADLE-3099

Categories