From 7376388a949f82cc32a147c2f1d9603f656e443e Mon Sep 17 00:00:00 2001 From: Thomas Corbat Date: Tue, 30 May 2017 09:29:48 +0200 Subject: [PATCH] Bug 517405 - Marker refresh causes editor to open Changed isApplicable to not retrieve the TU from the editor if it is not open. Applying the quick fix will still open the editor. Change-Id: Ib328ffa2054145eda8b2e72fe646fca2e7fc7905 Signed-off-by: Thomas Corbat --- .../quickfix/CaseBreakQuickFixFallthroughAttribute.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixFallthroughAttribute.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixFallthroughAttribute.java index 84e373fc9df..f72294bfc84 100644 --- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixFallthroughAttribute.java +++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixFallthroughAttribute.java @@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNodeFactory; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.parser.StandardAttributes; +import org.eclipse.cdt.internal.corext.util.CModelUtil; import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.text.BadLocationException; @@ -31,8 +32,8 @@ public class CaseBreakQuickFixFallthroughAttribute extends AbstractCaseBreakQuic RootProblemPreference map = (RootProblemPreference) problem.getPreference(); boolean enabled = (boolean) map.getChildValue(CaseBreakChecker.PARAM_ENABLE_FALLTHROUGH_QUICKFIX); boolean last_case_enabled = (boolean) map.getChildValue(CaseBreakChecker.PARAM_LAST_CASE); - ITranslationUnit tu = getTranslationUnitViaEditor(marker); - return enabled && tu.isCXXLanguage() && (!last_case_enabled || validPositionForFallthrough(marker)); + ITranslationUnit tu = getTranslationUnitViaWorkspace(marker); + return enabled && tu != null && tu.isCXXLanguage() && (!last_case_enabled || validPositionForFallthrough(tu, marker)); } @Override @@ -53,9 +54,9 @@ public class CaseBreakQuickFixFallthroughAttribute extends AbstractCaseBreakQuic } } - private boolean validPositionForFallthrough(IMarker marker) { + private boolean validPositionForFallthrough(ITranslationUnit tu, IMarker marker) { try { - IASTTranslationUnit ast = getTranslationUnitViaEditor(marker).getAST(null, ITranslationUnit.AST_SKIP_INDEXED_HEADERS); + IASTTranslationUnit ast = CModelUtil.toWorkingCopy(tu).getAST(null, ITranslationUnit.AST_SKIP_INDEXED_HEADERS); IASTStatement beforeCaseEnd = getStmtBeforeCaseEnd(marker, ast); if (getNextStatement(beforeCaseEnd) == null) return false;