1

I want to define and trigger some customized Java compilation errors in Eclipse. Basically I want that some system calls in some methods trigger a compilation error.

In this discussion an Annotaion based solution is proposed but it is not suitable in my case because I cannot predict when the copilation errors will happen. All I want is that when a developer makes a System Call for example a compilation error will be triggered.

Community
  • 1
  • 1
Mehdi
  • 1,494
  • 5
  • 33
  • 53

4 Answers4

1

Not exactly what you look for, but consider using a custom Checkstyle definition. Here is a sample from the checkstyle documentation that marks calls to System.out.println as invalid:

<module name="Regexp">
    <!-- . matches any character, so we need to escape it and use \. to match dots. -->
    <property name="format" value="System\.out\.println"/>
    <property name="illegalPattern" value="true"/>
</module>
Arne
  • 2,106
  • 12
  • 9
0

The only way to accomplish something like that would be to write a plug-in for Eclipse that analyzes code during builds. But the details of doing so is really out of the scope of a StackOverflow question.

E-Riz
  • 31,431
  • 9
  • 97
  • 134
0

You need to create your Builder implementation and register it with the Java Project.

You could start here.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436
0

If you want to prevent developpers from using java.lang.System for example, a nice trick is to create a custom class java.lang.System in your projet, so every call to any methods of java.lang.System (the real one) will occure a compilation problem.

If you use maven, you can also create the class in a seperate maven project with scope provided to not be packaged with the real application.

waliddah
  • 1
  • 1