Some of our code written a while have unnecessary semi-colon. I wonder whats the easiest way to remove them. For example, the last semi-colon in the following
if(i == 2)
{
System.out.println("if statement");
}
else
{
System.out.println("else statement");
};
You can find them easily enough by going into the Java Compiler / Error and Warnings preferences, then under "Potential Programming Problems" change "Empty Statements" to warning or error. Then it'll just be a matter of going through them. There may be a way of automating it, but I wouldn't bother unless there are loads :)
It is probably too late for you but, you can Analyze your code with Intellij IDEA using the Inspection "Unnecessary semi-colon" then after it has found them all you can apply the Fix.
http://www.jetbrains.com/idea/documentation/inspections.jsp
Eclipse can also do this too but it suffers from a bug that doesn't allow you to apply the Quick Fix in bulk.
As the above said, by typing ctrl + f and searching for }; and replacing it with } would work great, but could break the code.
They are not necessary to be removed, as it is just the equivalent of:
if(true){
//...
}
/*Empty Line*/;
It won't effect the code in any way, but is best to remove them just for preference.
It may be too late for you but this could help others:
CTRL + F
write what you want to delete in your case ; and then:
CTRL + ALT + SHIFT + J
This will select all the matches for your search in that file.
Then you just have to delete DELETE
Related
I have the following code for logging all the errors after every command I run in cmd with my tool. (It runs p4 integrate commands, about 1000-1500/task)
if (errorArrayList.size() > 0) {
LoggerSingleton.I.writeDebugInfoTimeStampedLog("[INFO-CMD] CommandExecuter.java -> runAndGetResults: errors happened while running the following command: [ " + commandResultBean.getCommand() + " ]");
for (int i = 0; i < errorArrayList.size(); i++) {
LoggerSingleton.I.writeDebugErrorTimeStampedLog(errorArrayList.get(i));
commandResultBean.addToCLI_Error(errorArrayList.get(i));
}
LoggerSingleton.I.writeDebugInfoTimeStampedLog("[INFO-CMD] CommandExecuter.java -> runAndGetResults: Listing errors of command [" + commandResultBean.getCommand() + "] finished");
}
The feature that I'm working on right now is check the error I get, and if that's on a predefined error list (list of errors that doesn't matter, and in fact not real errors, for example "all revision(s) already integrated") do nothing else, but when it's a "real" error, write it to an other log file too (Because these debug logs way too long for the users of the tool, it's made for the developers more likely).
The question is, what is the best way for this?
I want to avoid big deceleration. I have many commands, but the number of errors less then the commands, but that is not unusual at all that I get 700-800 "irrelevant" errors in one task.
I will use another class to make the I/O part, and that is not a problem to extend the running time in case we catch a "real" error.
The list is constant, it is okay if it can be modified only by coding.
At the moment I don't know what type to use (2-3 single Strings, List, Array ...). What type should I use? I never used enums in Java before, in this one should I?
I guess a for or foreach and errorArrayList.get(i).contains(<myVariable>)in a method is the only option for the checking.
If I'm wrong, there is a better way to do this?
EDIT
If I have an ArrayList<String>called knownErrors with the irrelevant errors (can define only parts of it), and I use the following code will better performance than a method wrote above? Also, can I use it if I have only parts of the String? How?
if (errorArrayList.removeAll(knownErrors) {
//do the logging and stuff
}
ArrayList itself has a method removeAll(Collection c) which removes all the elements which are matching with input collection elements. Below program show it evidently. So if you have the known error to be skipped in arraylist and pass it to removeall method it will remove the known errors and errorArrayList will have only new errors.
According to the standard coding practice "Left curly braces should be located at the end of lines of code". e.g.,
/* Not a good coding practice*/
} else
{
}
/* Good coding practice */
} else {
}
Actually I ran Sonar on my Java project and because of the above mentioned Rule, I got more than 6000 errors. Is there any shortcut in eclipse or any other way to fix these errors(at a time)?
Open the java files(where errors occured) and use "Ctrl+Shift+F" key to format. Then code will be formatted according "Formatter" settings
I'm trying to see what's going on in a chain of recursive calls. Is there some way to set a breakpoint in the middle of a single line to see when the function is being called from each statement?
Example: fibonacci(term - 2) + (want to put a breakpoint here) fibonacci(term - 1)
I don't think it is possible for some of the major IDE's like (Eclipse, Netbeans).
However, you can actually update your codes to such that you can evaluate them :
result1 = fibonacci(term - 2);
result2 = fibonacci(term - 1);
sum = result1 + result2;
The above code might not give you an elegant way of presenting your codes but can actually help you solve your problem.
You can't do this, but in some IDE's (Eclipse, IntelliJ) you can evaluate an expression that you highlight during debugging.
This could be useful if you wanted to see what fibonaci(term-2), for example, produced.
I have looked around and could not seem to find a solution to this. I'm not sure what is wrong with my code here. Link to my code http://pastebin.com/8z7rjVVK
Error received while compiling:
===== COMPILING - PLEASE WAIT... =====
src\server\model\players\packets\ClickingButtons.java:1313: error: reached end o
f file while parsing
}
^
1 error
=============== DONE ===================
Press any key to continue . . .
Sorry, I know there are other questions regarding the same error, but I can't seem to fix this. Thanks. This is Java.
The problem (or at least one of them) is that you have an if statement inside a switch block. It's almost at the end of the code:
if (c.isAutoButton(actionButtonId))
c.assignAutocast(actionButtonId);
You can't have code directly as a "child" of a switch statement, it must be placed inside a case block.
From the look of it, you define the switch statement and open it with a {, but then you never close it off.
switch (actionButtonId) {
case 118098:
So I added an extra } close bracket at the end of the whole class and the only errors I'm left with are ones for the missing classes. (I don't have your server directory classes)
I would advise using an IDE (like eclipse) or rewriting this class to use an individual method for each case.
Also, using { } for if-else statements will help avoid this type of issue in the future.
EDIT: Final Solution
Once you've got the final close bracket in place, you also needed to move the if statement above the break key word.
The following if statement (around line 1285) became unreachable once the final close bracket was in place
break;
if (c.isAutoButton(actionButtonId))
c.assignAutocast(actionButtonId);
I download the last Java build b96- Feature Complete for testing the new JDK features
but I can't figure out which syntax using for testing closures!
Can I test it?
Which syntax has been approved in the final release?
I can't be certain, but I think this syntax:
// function expressions
#(int i, String s) {
System.println.out(s);
return i + s.length();
}
// function expressions
#(int i, String s) (i + s.length())
// function types
#int(int, String)
Is going to make it through as per http://docs.google.com/Doc?id=ddhp95vd_0f7mcns
To answer your question, no final syntax has been approved and, despite M8 being listed as the feature-complete milestone, it doesn't have all the proposed features. You can read here about the feature in its current form, but much discussion is going on now and it has quite a ways to go. Additionally, the syntax is going to be revisited and likely changed (at least some) later, once more pressing issues are worked out.
Also, project-lambda code is being worked on in a fork of the main line JDK7 (I believe), so I don't think any of it would be in the build you downloaded.