I created a project, it asked me to select JDK version and finish.
I couldn't find system namespace in autocomplete.
I typed it manually but IDEA told me that system doesn't exist.
It's System (with a cap)
Some very useful shortcuts:
soutm (+TAB) ==> System.out.println("Class.And.Method.Name")
soutv (+TAB) ==> System.out.println("Last variable used = " + value);
sout (+TAB) ==> System.out.println();
I really love IntelliJ. Glad I moved to it from Eclipse a couple of years ago ;)
Just type sout.
public class Main {
public static void main(String[] args) {
int data = 1;
System.out.println(); ===>sout
System.out.println("Main.main"); ===>soutm
System.out.println("args = [" + args + "]"); ===>soutp
System.out.println("data = " + data); ===>soutv
}
}
sout - just print System.out.println()
soutm - added Class name & method name
soutp - added parameter
soutv - added last variable name
We can change the auto complete settings to to ignore case. Go to:
File -> Settings... -> IDE Settings -> Editor -> Code Completion
and change 'Case sensitive completion' to 'None'.
I came from eclipse and was using the syso shortcut, so I have just added it to my live template. Here is a templete:
System.out.println($END$);
Here is a screenshot:
Don't forget to add Java as applicable context (at the bottom of the window).
Now it will appear as a hint while you typing syso here is a screenshot:
Hope it helps
This can also happen because user has not created any main function or trying to test this directly in class without any function
Related
psvm + tab would make:
public static void main(String[] args) {
}
And now I want to have cml for:
CommandLineRunner runner () {
return args -> {
};
}
How to add it in IDEA?
Checkout IntelliJ IDEA Live Templates documentation
Basically you can create abbreviations like that :
go to File -> Settings... -> Editor -> Live Templates
Add a live template with the + sign
define at least abbreviation and text template
define the appropriate JAVA context
That's it.
I have this sonar error Major:
Found 'UR'-anomaly for variable 'language' (lines '83'-'85')
in this function:
public void saveAll(List<Language> languages){
//Found 'UR'-anomaly for variable 'country' (lines '83'-'85').
//Code Smell Major Open Not assigned 20min effort Comment
for (Language language: languages) {
save(language);
}
}
how to fix this major error please, thanks for advance
Edit:
Found even more information it this other SO post. While that is more PMD centric, the background information can be of interest to you.
Java for each loop being flagged as UR anomaly by PMD.
This is a rule from PMD it seems. Definition:
The dataflow analysis tracks local definitions, undefinitions and
references to variables on different paths on the data flow. From
those informations there can be found various problems. 1. UR -
Anomaly: There is a reference to a variable that was not defined
before. This is a bug and leads to an error. 2. DU - Anomaly: A
recently defined variable is undefined. These anomalies may appear in
normal source text. 3. DD - Anomaly: A recently defined variable is
redefined. This is ominous but don't have to be a bug.
There is an open bug report for this:
https://sourceforge.net/p/pmd/bugs/1190/
In the example they report it for Arrays, but somebody commented that it happens for them also for collections.
Example:
public static void main(final String[] args) {
for (final String string : args) {
string.getBytes(); //UR Anomaly
}
for (int i = 0; i < args.length; i++) {
args[i].getBytes();
}
}
In our sonar setup we don't use this rule. Based on the available information you may wish not to use it in yours.
Quick Intellij plugin Development question.
Can somebody show me a snippet of code on how to display a warning at a specific line?
I want to display a yellow bulb and be able to alt enter.
I don't know if the yellow bulb is part of a warning or just a hint but i would very much appreciate if somebody would show me how to do it.
I tried to find it on idea plugin development but didn't have any luck
private List<PsiFile> psiFiles = new ArrayList<PsiFile>();
public void actionPerformed(AnActionEvent e) {
PsiManager psiManager=PsiManager.getInstance(e.getProject());
Project project = e.getProject();
VirtualFile srcFile;
if(e.getProject().getBaseDir().findChild("src") == null)
return;
else
{
srcFile = e.getProject().getBaseDir().findChild("src");
}
//using the buildFilesList i get all the .java files
buildFilesList(psiManager,srcFile);
for(PsiFile file : psiFiles)
//here i would want for a psiFile a warning to be displayed at a specific line
System.out.println(file);
}
What you need to write is an inspection. You don't need to enumerate the files in the project; IntelliJ IDEA will take care of calling your API at the correct moment. You can find a simple example of a plugin that implements an inspection here.
I noticed that when I hover my mouse over a local variable when my debugger is stopped inside a lambda it will report Cannot find local variable 'variable_name' even if it's visible inside the lambda and it's used.
Example code
public class Main {
public static void main(String[] args) {
String a = "hello_world";
m1(a);
}
private static void m1(String a) {
AccessController.doPrivileged((PrivilegedAction<String>) () -> {
System.out.println("blala " + a);
return "abc";
});
}
}
Try with a breakpoint in System.out.println("blala " + a); and after return "abc" and it always report the same error.
I used AccessController.doPrivileged because it's what I used in my original code and of course i'm using Java 8.
It says the same thing in Watchers and Evaluate Expression.
I tried using the "anonymous class" version and the debugger sees the value of a correctly
private static void m1(String a) {
AccessController.doPrivileged(new PrivilegedAction<String>() {
#Override
public String run() {
System.out.println("blala " + a);
return "abc";
}
});
}
I'm missing something about lambda expressions or it's an IntellIJ IDEA 14 bug?
I don't want to report the bug right now because I already reported a bug that was caused by my code instead of IntellIJ IDEA, so I want to be sure before do something (and because I don't use Java 8 so often, so I could be wrong).
This appears to be a know issue. According to JetBrains the root causes of this behavior is with the JDK. For more info see: IDEA-126257
I can confirm what is written in IDEA bug report linked by Mike Rylander: this is a JDK bug and update to version 8u60_25 of the JDK solves it.
I'm using MvvmCross.
In the library I see usage of Mvx.Trace method, but no output to the console/output window.
How to use it?
p.s. I have set the compiler constant Trace = true
Thanks.
MvvmCross DebugTrace is all routed via a singleton implementation of IMvxTrace
Each platform provides different implementations of this:
the Windows platforms use Debug trace (because Trace itself is not available on all the Windows platforms)
Android uses a dual log of both Debug and the Android log
iOS uses a dual log of both Debug and the iOS Console
This worked well in earlier versions of MvvmCross, especially where people linked directly to the MvvmCross source code and so could bind directly to either the debug or release MvvmCross binaries.
However... because people are now increasingly using the release Binaries from Nuget - in which Debug is of course compiled out, then this often leaves people asking "How to use it?"
The easiest way is for you to override the initialisation of IMvxTrace in your Setup class.
This is easy to do - e.g.:
protected override IMvxTrace CreateDebugTrace() { return new MyDebugTrace(); }
where MyDebugTrace is something like:
public class MyDebugTrace : IMvxTrace
{
public void Trace(MvxTraceLevel level, string tag, Func<string> message)
{
Debug.WriteLine(tag + ":" + level + ":" + message());
}
public void Trace(MvxTraceLevel level, string tag, string message)
{
Debug.WriteLine(tag + ":" + level + ":" + message);
}
public void Trace(MvxTraceLevel level, string tag, string message, params object[] args)
{
try
{
Debug.WriteLine(string.Format(tag + ":" + level + ":" + message, args));
}
catch (FormatException)
{
Trace(MvxTraceLevel.Error, tag, "Exception during trace of {0} {1} {2}", level, message);
}
}
}
If you wanted to include different implementations for debug/release; if you wanted to switch this on/off at runtime; if you wanted to filter on MvxTraceLevel or tag; or if you wanted to use some third party logging engine then this should also be easy to do using simple C# on each platform.
Just hitting an issue on iOS with the current solution provided by Stuart.
Running a debug session in VS with the MvxTrace using Debug.WriteLine can be extremely slow depending on how verbose is your app logging. Same for Trace.WriteLinte.
Use Console.WriteLine instead (as MvvmCross MvxDebugTrace does) which is not impacted.
See this Xamarin bug item for "more" details: https://bugzilla.xamarin.com/show_bug.cgi?id=13538#c4