36

In my Eclipse project are a handful of generated .java files that I need to use for SQLJ and I can't move to a separate project (due to Administrative Overhead). These files are also regularly regenerated so editing them is unfortunately out.

Unfortunately these files generate a few hundred java compiler warnings which drown out the useful warnings I get on files that I actually can edit.

Is there any way in Eclipse to say Ignore all the warnings of a file-by-file basis? Or can I block out a specific sub-directory?

kutuzof
  • 660
  • 1
  • 7
  • 22

5 Answers5

26

Ensure the files are under the gen folder, the typical home for all generated .java files. Then in the project properties, under Java Build Path, set Ignore optional compile problems for that folder to Yes.

If your project structure requires your files be in a folder other than gen, add that folder to the Java Build Path so that you can enable ignoring optional compile problems for it.

Edward Brey
  • 40,302
  • 20
  • 199
  • 253
  • Very useful. This seems to be what the OP asked for, and I needed the same. – StellarVortex Jun 20 '14 at 20:10
  • 2
    this is the answer to the question – mvera Jul 08 '14 at 22:43
  • I believe this is the answer to the OP's question as well. To use this approach with a Maven project, I send all generated files to src/main/gen and use Edwards solution. – bigleftie Jul 27 '14 at 05:15
  • This should be the accepted answers as it can be a best practice (as an example, Android currently uses gen source directory) – usr-local-ΕΨΗΕΛΩΝ Oct 17 '14 at 12:42
  • 1
    I don't have said option under Java Build Path. What version of Eclipse are we talking about? – Florian F Jan 29 '15 at 13:42
  • @FlorianF Eclicpse 4.2.1, Android Developer Tools 23.0.2.1259578. Make sure you are on the **Source** tab. If you expand **Android/gen** you should see an **Ignore optional compile problems** node in the tree, which you can select, and then click **Toggle**. – Edward Brey Jan 29 '15 at 13:50
  • I see. I am using MyEclipse which is based on Eclipse 3.7. Maybe that's why. Time to upgrade. – Florian F Jan 29 '15 at 13:55
19

The "problems" view in eclipse can be filtered; I always have it set to "on selected element and its children only". Granted, this is more of a work-around, but it lessens the impact of having the files in the same project. (Note that even if you must have them in the same project, you can keep them in a separate source folder).

Edit: To configure the filters, find the icon with a downward arrow with tooltip "View Menu" on the top right of the problems view. Click it, and then click "configure contents".

meriton
  • 68,356
  • 14
  • 108
  • 175
  • 1
    I've tried filtering the problems view to a working set. The "selected elements and its children only" is pretty sweet actually! – kutuzof Sep 09 '10 at 20:38
  • Please clarify how to filter the problems view. It's not obvious. – wberry Apr 06 '12 at 16:08
  • 1
    Cute but insufficient. You can't hide both warnings containing "Dead code" and "raw type". You can't show all warnings except in folder X. – Florian F Jan 29 '15 at 13:30
12

@SuppressWarning annotation?

Per, Stephen's comment, you can find the "Per project compiler settings option here"

Project->Properties->Java Compiler->Errors/Warnings

Enable project specific settings

alt text

Pang
  • 9,564
  • 146
  • 81
  • 122
bdhar
  • 21,619
  • 17
  • 70
  • 86
  • Good too. The problem is that the SQLJ files are in the same project and many of the warnings are useful to have for other files. I need a file specific settings... – kutuzof Sep 05 '10 at 05:07
  • The Javadoc for `@SuppressWarning` isn't very helpful to understand how to use it. It lacks examples. – dolmen May 03 '13 at 12:23
  • The Eclipse documentation about `@SuppressWarning` is more detailed. See my own answer. – dolmen May 03 '13 at 12:30
2

One way to do this is to add @SuppressWarning(...) annotations to the source code.

Another way would be to move the troublesome code to a separate Eclipse project and use per-project compiler settings.

EDIT

Surely, you can partition your code into multiple projects with the appropriate inter-project dependencies?

If not, I'd say you are out of realistic options. (But if you want some unrealistic ones, you could post-process the generated code to add the annotations, hack the Eclipse Java compiler to implement per-file suppression, hack the Eclipse "Problems" view to implement per-file/directory filtering of errors, etc, etc.)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • +1 "per-project compiler settings." New thing learnt!! – bdhar Sep 02 '10 at 07:56
  • Yea that is is good. The problem is that the SQLJ files are regularly newly generated (Whenever someone changes the SQL). So all the @SuppressWarning(all) disappear then. – kutuzof Sep 05 '10 at 05:06
1

If you want to hide warnings on a class or on a method, see the Eclipse documentation on the @SuppressWarnings annotation or Java documentation

Example:

@SuppressWarnings("unused")
public void foo() {
    String s;
}
pamcevoy
  • 1,136
  • 11
  • 15
dolmen
  • 8,126
  • 5
  • 40
  • 42
  • 1
    This doesn't work because the files are regularly generated. So each time I'd have to add the @SuppressWarning by hand to tens of files. – kutuzof Dec 15 '14 at 13:08