How can I disable compiler warnings in Eclipse on a file specific basis? [duplicate]

守給你的承諾、 提交于 2019-11-27 08:36:01

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".

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.

bdhar

@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

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.)

dolmen

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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!