Skip to content

Commit

Permalink
Add null guards and more error logging to force on-save handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gohla committed Mar 14, 2014
1 parent ab61ad5 commit e0de767
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Expand Up @@ -14,7 +14,12 @@ public class AntForceOnSave {
public static void main(String[] args) {
for(String arg : args) {
try {
System.out.println("Forcing on-save handler for: " + arg);
FileState fileState = FileState.getFile(new Path(arg), null);
if(fileState == null) {
Environment.logException("Could not call on-save handler. File state could not be retrieved.");
continue;
}
IStrategoTerm ast = fileState.getAnalyzedAst();
OnSaveService onSave = fileState.getDescriptor().createService(OnSaveService.class, fileState.getParseController());
onSave.invokeOnSave(ast);
Expand Down
Expand Up @@ -60,8 +60,9 @@ protected FileState(Descriptor descriptor) {
*/
public static FileState getFile(IPath path, IDocument document)
throws FileNotFoundException, BadDescriptorException, ModelException {

Language language = LanguageRegistry.findLanguage(path, document);
if(language == null)
return null;
Descriptor descriptor = Environment.getDescriptor(language);
IResource resource = EditorIOAgent.getResource(path.toFile());
if (descriptor == null) return null;
Expand Down

0 comments on commit e0de767

Please sign in to comment.