EclipseCodeFormatter
EclipseCodeFormatter copied to clipboard
Only format if no compile errors
trafficstars
If you invoke the formatter on a file with compile errors (f.e. missing paranthesis) the code is messed up. How about checking for compile errors before formatting?
private boolean hasErrors(PsiFile psiFile) {
final AtomicBoolean hasErrors = new AtomicBoolean(false);
psiFile.accept(new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitElement(PsiElement element) {
super.visitElement(element);
//FIXME does PsiErrorElementUtil.hasErrors() the same?
if (!element.isValid() || !(element instanceof PsiErrorElement)) {
//contains compile-errors, which may lead to strange results in formatting
hasErrors.set(true);
}
}
});
return hasErrors.get();
}
I provided code for the save-actions plugin, which does the check - https://github.com/dubreuia/intellij-plugin-save-actions/pull/77. But the issues occures even without the save-actions plugin
Hmm, I never noticed that, for me it would just not format anything if there was some ugly syntax error.
@krasa Add this feature will be better, isn't it? SEE: dubreuia/intellij-plugin-save-actions#76.