Re: [tasklist] compiler/JavacError

Tor Norbye <[email protected]>
Newsgroups gmane.comp.java.netbeans.modules.tasklist.devel
Organization Sun Microsystems, Inc
Message-ID <1051461750.732.6035.camel@proto>
On Sat, 2003-04-26 at 00:57, Tim Lebedkov wrote:
> Hi Tor,
> 
> compiler/JavacError class can parse all Javac messages.
> Maybe you want to reuse it in the suggestion module.

The suggestion module (or more specifically, tasklist/javaparser)
doesn't have to parse messages because they are provided 
directly by the java module (using the new ParserMessage class,
org.netbeans.modules.java.ParserMessage).  

Or are you thinking that the scan for symbols etc. could
be improved by using JavacError? If so, please explain what
you think should be done. 

> How we can organize the cooperation between "suggestions" and "compiler"?
> I want to have a "Fix" action for the nodes in the "Build Messages" view.

I agree, it would be very desirable to have the compiler module
list suggestions just like the suggestions view provides.

Most of the code in tasklist/javaparser does exactly what you
need: looks at error messages, and creates corresponding suggestions
for them:

    /** Check the given error message to see if we can help resolve
     * it, and register "solutions" into the given tasks list.
     * @param manager The suggestion manager to use
     * @param tasks List of Suggestions. May be empty. This method will
     *   add to it any suggestions that it thinks will help fix the error.
     *   For example, if the error is "No such class: List", it may add
     *   two suggestions:  "import java.awt.List" and "import java.util.List"
     * @param doc The document for the file containing the error. Used by the
     *   SuggestionPerformers to modify the document when the user wants
     *   to apply a fix suggestion.
     *   TODO: get rid of this parameter (such that it's computed/located/
     *   opened automatically by the SuggestionPerformers when you perform
     *   the fix.
     * @param dobj The data object for the file containing the error
     * @param summary The compiler error message as provided by javac
     * @param lineNumber The line number of the error message
     * @param column The column provided for the error, if any
     */
    public void handleError(SuggestionManager manager, List tasks,
                            final Document doc, final DataObject dobj,
                            String summary,
                            Line line,
                            int lineNumber,
                            int column) {


So, all you have to do is obtain a reference to an ErrorSuggester,
create an empty list (new ArrayList()), then call the above method
and additional suggestions will be added into your list, which you
can then append to your compiler output list.   Yes, this won't
be completely independent from the suggestions framework, but
I think that's okay; specifically, it needs the "FixAction" support
in the suggestions module in order for the suggestion fixing
(confirmation dialog etc.) to work.  But if you call handleError
it will be independent of everything else (e.g. it will create
error suggestions even if the javaparser suggestion type is turned
off in the suggestions module.)

So the only "unsolved" part here is how you obtain the ErrorSuggester.
The easy solution is just to create your own instance - 
new ErrorSuggester().  However, that's a bit wasteful since ErrorSuggester
does keep a fair bit of state (to do case-insensitive searching of
the code completion database).   So instead we could provide
a default instance and a getDefault() method which initializes and/or
accesses it.

-- Tor
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.