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.
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>
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.
You need to create your Builder
implementation and register it with the Java Project.
You could start here .
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.