简体   繁体   中英

Is it possible to call quickfix solutions(eclipse) for specific(error/s)?

I have a program which scans a Java file for errors. I call the compiler from Eclipse and run a scan on the Java file and get the line numbers, start position and end positon as output. I have written a program to extract the error from the file.

What I want to do is to have access to the quickfix component in eclipse, have a list of possible fixes for the problem, and print that list to the console.

Below is a portion of the program of how I called the compiler and got the details printed on the console:

Iterable fileObjects = fileManager.getJavaFileObjectsFromStrings(
        Arrays.asList(fileToCompile));  
CompilationTask task = compiler.getTask(null, fileManager, listener, null,
        null, fileObjects); 
Boolean result = task.call();
if(result == true) {
    System.out.println("Compilation has succeeded");
}
myerrors = listener.getlistofErrors();
for (CaptureErrors e : myerrors) {
    System.out.println("Code: " + e.getCode());
    System.out.println("Kind: " + e.getKind());
    System.out.println("Line Number: " + e.getLinenumber());
//  System.out.println("Message: "+ e.getMessage(Locale.ENGLISH));
//  System.out.println("Source: " + diagnostic.getSource());
    System.out.println("End position"+ e.getEndposition());
    System.out.println("Position: "+ e.getPosition());
    System.out.println("\n");
}

class MyDiagnosticListener implements DiagnosticListener {
    List<CaptureErrors> errors = new ArrayList<CaptureErrors>();
    public void report(Diagnostic diagnostic) {
        CaptureErrors single_error = new CaptureErrors(diagnostic.getCode(),
                diagnostic.getKind(), diagnostic.getLineNumber(),
                diagnostic.getMessage(Locale.ENGLISH), diagnostic.getPosition(),
                diagnostic.getEndPosition());
        errors.add(single_error);  
    }

    public List<CaptureErrors> getlistofErrors() {
        return errors;
    }
}

I also have a program to go to the line numbers and extract the text(error) at specific positions.

How can I call eclipse quickfix solutions for the specific errors that I find?

Yes, it is possible. The exact details are a bit larger than can easily be encompassed in even a StackOverflow answer.

Eclipse is extended through the use of plug-ins. A "Hello World" plugin is detailed here , and after you get through the initial learning curve, you can download other plugins to get a feel for how eclipse works internally.

I imagine that you would do well to examine the current code highlighting capabilities of eclipse and read the source code for those plugins as a guide, but only after you get some idea of how plugin development works.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM