Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Default Let eclipse warn about a semicolon after an if statement and string == string?

    Is there any way eclipse can warn me about statements like

    Java Code:
    if (foo.equals(bar));
    {
     // this will always be executed
    
    }
    or
    Java Code:
    if (username == "Foo bar fighter")  // probably never true
    ?

  2. #2
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Default

    Is my question stupid or unclear or impossible?

  3. #3
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    Eclipse preferences, somewhere in Java.compiler, lets you set up warnings, and you can also specify formatter settings that will force your code into a style that exposes those sorts of errors. For example, you might be able to expose the first one by requiring all if statements to use {}.

    Having said that, it won't stop you from doing things that are strange but valid. The second falls in that category, afaik.

    If it was easy, no one would pay you to do it ;-)

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Since those things are errors, why you just want to see them as warnings. I think Eclipse clearly state those things as errors. Seems to me this is annoying thing our thread starter wants to do.

  5. #5
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    I've never tried the first one, but I *think* it might be a valid statement. The second is a fragment, but the idea is valid.

    I think ff wants the compiler to warn him/her about slip ups that end up compiling but that don't make sense. That's why I said it's not easy, the compiler can't do all the work for us...

  6. #6
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by Steve11235 View Post
    I've never tried the first one, but I *think* it might be a valid statement. The second is a fragment, but the idea is valid.

    I think ff wants the compiler to warn him/her about slip ups that end up compiling but that don't make sense. That's why I said it's not easy, the compiler can't do all the work for us...
    Yes, this is exactly my point; both compile but don't make sense.

    I thought there might be a simple plugin which allows me to write some code which checks my source code; I could just simply match some kind of /if.*;/ regular expression to find the first one.

Similar Threads

  1. Sql string with callable statement..
    By nathan in forum JDBC
    Replies: 1
    Last Post: 09-24-2008, 02:41 AM
  2. string vs string builder??
    By j2vdk in forum New To Java
    Replies: 6
    Last Post: 09-08-2008, 10:38 AM
  3. Replies: 0
    Last Post: 11-20-2007, 05:59 PM
  4. Replies: 1
    Last Post: 08-07-2007, 08:29 AM
  5. Replies: 1
    Last Post: 08-03-2007, 11:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •