mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Added handling of situations when the AST in not available.
This commit is contained in:
parent
48799b684f
commit
51ac942b6c
5 changed files with 27 additions and 2 deletions
|
@ -22,6 +22,7 @@ import org.eclipse.jface.text.ITextSelection;
|
|||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.text.edits.MalformedTreeException;
|
||||
|
@ -48,7 +49,7 @@ import org.eclipse.cdt.internal.ui.refactoring.includes.IElementSelector;
|
|||
import org.eclipse.cdt.internal.ui.refactoring.includes.IncludeCreator;
|
||||
|
||||
/**
|
||||
* Organizes the include directives and forward declarations of a source or header file.
|
||||
* Adds an '#include' statement and, optionally, a 'using' declaration necessary to resolve a name.
|
||||
*/
|
||||
public class AddIncludeAction extends TextEditorAction {
|
||||
private IElementSelector fAmbiguityResolver;
|
||||
|
@ -103,6 +104,11 @@ public class AddIncludeAction extends TextEditorAction {
|
|||
SharedASTJob job = new SharedASTJob(CEditorMessages.AddInclude_action, tu) {
|
||||
@Override
|
||||
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException {
|
||||
if (ast == null) {
|
||||
return CUIPlugin.createErrorStatus(
|
||||
NLS.bind(CEditorMessages.AddInclude_ast_not_available, tu.getPath().toOSString()));
|
||||
}
|
||||
|
||||
IIndex index= CCorePlugin.getIndexManager().getIndex(tu.getCProject(),
|
||||
IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_EXTENSION_FRAGMENTS_ADD_IMPORT);
|
||||
try {
|
||||
|
|
|
@ -35,11 +35,13 @@ public final class CEditorMessages extends NLS {
|
|||
public static String AddInclude_label;
|
||||
public static String AddInclude_description;
|
||||
public static String AddInclude_action;
|
||||
public static String AddInclude_ast_not_available;
|
||||
public static String AddInclude_error_title;
|
||||
public static String AddInclude_insertion_failed;
|
||||
public static String OrganizeIncludes_label;
|
||||
public static String OrganizeIncludes_description;
|
||||
public static String OrganizeIncludes_action;
|
||||
public static String OrganizeIncludes_ast_not_available;
|
||||
public static String OrganizeIncludes_error_title;
|
||||
public static String OrganizeIncludes_insertion_failed;
|
||||
public static String OrganizeIncludes_help_provider_error;
|
||||
|
|
|
@ -19,12 +19,14 @@
|
|||
AddInclude_label=Add Include
|
||||
AddInclude_description=Add include statement for selected name
|
||||
AddInclude_action=Adding include statement
|
||||
AddInclude_ast_not_available=Unable to parse ''{0}''
|
||||
AddInclude_error_title=Error Adding Include Statement
|
||||
AddInclude_insertion_failed=Adding include statement failed
|
||||
|
||||
OrganizeIncludes_label=Organize Includes
|
||||
OrganizeIncludes_description=Organize includes for current file
|
||||
OrganizeIncludes_action=Organizing includes
|
||||
OrganizeIncludes_ast_not_available=Unable to parse ''{0}''
|
||||
OrganizeIncludes_error_title=Error Organizing Includes
|
||||
OrganizeIncludes_insertion_failed=Adding include statements failed
|
||||
OrganizeIncludes_help_provider_error=Help provider error
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.eclipse.core.runtime.Status;
|
|||
import org.eclipse.jface.dialogs.ErrorDialog;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
import org.eclipse.text.edits.MalformedTreeException;
|
||||
import org.eclipse.text.edits.MultiTextEdit;
|
||||
import org.eclipse.text.undo.DocumentUndoManagerRegistry;
|
||||
|
@ -70,6 +71,11 @@ public class OrganizeIncludesAction extends TextEditorAction {
|
|||
SharedASTJob job = new SharedASTJob(CEditorMessages.OrganizeIncludes_action, tu) {
|
||||
@Override
|
||||
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException {
|
||||
if (ast == null) {
|
||||
return CUIPlugin.createErrorStatus(
|
||||
NLS.bind(CEditorMessages.OrganizeIncludes_ast_not_available, tu.getPath().toOSString()));
|
||||
}
|
||||
|
||||
IIndex index= CCorePlugin.getIndexManager().getIndex(tu.getCProject(),
|
||||
IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_EXTENSION_FRAGMENTS_ADD_IMPORT);
|
||||
try {
|
||||
|
|
|
@ -342,7 +342,16 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
/**
|
||||
* Creates an error status.
|
||||
*
|
||||
* @since 5.7
|
||||
* @noreference This method is not intended to be referenced by clients.
|
||||
*/
|
||||
public static Status createErrorStatus(String message) {
|
||||
return createErrorStatus(message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error status.
|
||||
*
|
||||
* @noreference This method is not intended to be referenced by clients.
|
||||
*/
|
||||
public static Status createErrorStatus(String message, Throwable e) {
|
||||
return new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, e);
|
||||
|
|
Loading…
Add table
Reference in a new issue