Board index » jbuilder » How to find out if a source-file is buildable

How to find out if a source-file is buildable


2004-09-08 03:18:04 PM
jbuilder20
Using JOT we can parse and generate source-code to source-files. In some situations JOT refuses to parse a source-file because of errors in the file, but sometimes a file with errors can be parsed.
Is there a way that we can ask (JOT) if a certain file is buildable? How does JBuilder do this for, for example, error highlighting? (I don't want to use the IEditorPane.getErrorHighlights method because this requires me to open the file before I can find out if the file has errors.)
Please help.
 
 

Re:How to find out if a source-file is buildable

Maybe there is some way to do this with JOT, however I would use SourceInfo.
It is a lot closer to the compiler parser and more lightweight.
public static boolean hasErrors(JavaFileNode node) {
return node.getSourceInfo().hasErrors();
}
"Bennie" < XXXX@XXXXX.COM >wrote in message
Quote

Using JOT we can parse and generate source-code to source-files. In some
situations JOT refuses to parse a source-file because of errors in the
file, but sometimes a file with errors can be parsed.

Is there a way that we can ask (JOT) if a certain file is buildable? How
does JBuilder do this for, for example, error highlighting? (I don't want
to use the IEditorPane.getErrorHighlights method because this requires me
to open the file before I can find out if the file has errors.)

Please help.
 

Re:How to find out if a source-file is buildable

Thanks for your response!
Quote
It is a lot closer to the compiler parser and more lightweight.

public static boolean hasErrors(JavaFileNode node) {
return node.getSourceInfo().hasErrors();
}
Unfortunately, it does not seem to detect all errors:
it detects:
public method()
{
// this is something that is not declared, never and nowhere
abcd
}
but does not detect:
public method()
{
// the method 'append' is declared, but
// this 'abcd' is something that is not declared, never and nowhere
append(abcd);
}
(however error highlighting DOES show it as an error..)
Please help..
 

{smallsort}

Re:How to find out if a source-file is buildable

Try this then:
public static boolean hasErrors(JavaFileNode node) {
SourceInfo sourceInfo = node.getSourceInfo();
sourceInfo.attributeAll();
return sourceInfo.hasErrors();
}
"Bennie" < XXXX@XXXXX.COM >wrote in message
Quote

Thanks for your response!

Unfortunately, it does not seem to detect all errors:

it detects:

public method()
{
// this is something that is not declared, never and nowhere
abcd
}

but does not detect:

public method()
{
// the method 'append' is declared, but
// this 'abcd' is something that is not declared, never and nowhere

append(abcd);
}

(however error highlighting DOES show it as an error..)

Please help..

 

Re:How to find out if a source-file is buildable

OK! Thanks! This already works much better, now it detects the mentioned errors too.
But unfortunately when I do not alter a file with errors, and I call 'hasErrors' several times, it sometimes occurs that I get a 'false' returned which indicates that there are no errors. This is strange because the underlying source-file has not been changed and former calls returned true...
Note that I want to use this functionality for switching from one tabpage to another tabpage (from one view on a souce-file to another view on the source-file). With this functionality I should be able to check if the user is allowed to switch to the destination tabpage. Now I can switch to the destination tab sometimes, whereas there are still some errors...
Is there something else I can do, additional calls? Thanks in advance!