Custom compiler errors through Compilation Participants

前提是你 提交于 2019-12-24 12:39:19

问题


I am working on an Eclipse plugin and would like to make some of his suggestions to be compiler errors if not handled and so I tried to create a Compilation Participant that creates a compilation error no matter what but the project still compiles and it doesnt seem to work. My code:

public class compilerNotificator extends CompilationParticipant{
    @Override
    public int aboutToBuild(@SuppressWarnings("unused") final IJavaProject project){
        return 0;
    }
    @Override
    public boolean isActive(@SuppressWarnings("unused") final IJavaProject project){
        return true;
    }
    @Override
    public void reconcile(final ReconcileContext context){
        final CategorizedProblem[] problems = new CategorizedProblem[1];
        problems[0] = new CategorizedProblem() {

            @Override
            public void setSourceStart(final int sourceStart) {
                // TODO Auto-generated method stub

            }

            @Override
            public void setSourceLineNumber(final int lineNumber) {
                // TODO Auto-generated method stub

            }

            @Override
            public void setSourceEnd(final int sourceEnd) {
                // TODO Auto-generated method stub

            }

            @Override
            public boolean isWarning() {
                // TODO Auto-generated method stub
                return true;
            }

            @Override
            public boolean isError() {
                // TODO Auto-generated method stub
                return true;
            }

            @Override
            public int getSourceStart() {
                // TODO Auto-generated method stub
                return 3;
            }

            @Override
            public int getSourceLineNumber() {
                // TODO Auto-generated method stub
                return 10;
            }

            @Override
            public int getSourceEnd() {
                // TODO Auto-generated method stub
                return 34;
            }

            @Override
            public char[] getOriginatingFileName() {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public String getMessage() {
                // TODO Auto-generated method stub
                return "This is some fucked up shit";
            }

            @Override
            public int getID() {
                // TODO Auto-generated method stub
                return 1000129;
            }

            @Override
            public String[] getArguments() {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public String getMarkerType() {
                // TODO Auto-generated method stub
                return "Bad";
            }

            @Override
            public int getCategoryID() {
                // TODO Auto-generated method stub
                return 5;
            }
        };
        context.putProblems("test", problems);
    }
}

The anonymous class is just for testing purposes and has no meaning but it is supposed to be the one that triggers the Error and its not...

Right now the above code sits in the code for the plugin preferences page(in Windows -> Preferences). Thanks!

By the way, I already tried changing the return value of aboutToBuild to IProblem.AnnotaionCircularRef (something like that) but I got the same result.


回答1:


Solved.

You need to add an extension point to plugin.xml like so:

<extension point="org.eclipse.jdt.core.compilationParticipant">
<compilationParticipant 
class="Path.To.Package.MyCompilationParticipant"
id="Path.To.Package.MyCompilationParticipant">
</compilationParticipant>
</extension>


来源:https://stackoverflow.com/questions/24195142/custom-compiler-errors-through-compilation-participants

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