mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 539145 - Avoid opening an editor during CaseBreakQuickFixFallthroughAttribute.isApplicable()
Change-Id: I82c5b345cfb017680d06f3caeff0c9839780ee68
This commit is contained in:
parent
87cd426861
commit
acca2b3b6e
2 changed files with 9 additions and 11 deletions
|
@ -27,8 +27,6 @@ import org.eclipse.core.resources.IMarker;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.jface.text.BadLocationException;
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
import org.eclipse.jface.text.IDocument;
|
|
||||||
import org.eclipse.jface.text.IRegion;
|
|
||||||
import org.eclipse.ltk.core.refactoring.Change;
|
import org.eclipse.ltk.core.refactoring.Change;
|
||||||
|
|
||||||
abstract public class AbstractCaseBreakQuickFix extends AbstractAstRewriteQuickFix {
|
abstract public class AbstractCaseBreakQuickFix extends AbstractAstRewriteQuickFix {
|
||||||
|
@ -57,20 +55,18 @@ abstract public class AbstractCaseBreakQuickFix extends AbstractAstRewriteQuickF
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IASTStatement getStmtBeforeCaseEnd(IMarker marker, IASTTranslationUnit ast) throws BadLocationException {
|
protected IASTStatement getStmtBeforeCaseEnd(IMarker marker, IASTTranslationUnit ast) throws BadLocationException {
|
||||||
int line = marker.getAttribute(IMarker.LINE_NUMBER, 0) - 1;
|
int offset = marker.getAttribute(IMarker.CHAR_START, 0);
|
||||||
if (line < 0)
|
int endOffset = marker.getAttribute(IMarker.CHAR_END, 0);
|
||||||
|
if (offset < 0 || endOffset < offset)
|
||||||
return null;
|
return null;
|
||||||
IDocument doc = getDocument();
|
int length = endOffset - offset;
|
||||||
if (doc == null)
|
|
||||||
doc = openDocument(marker);
|
|
||||||
IRegion lineInformation = doc.getLineInformation(line);
|
|
||||||
IASTNodeSelector nodeSelector = ast.getNodeSelector(null);
|
IASTNodeSelector nodeSelector = ast.getNodeSelector(null);
|
||||||
IASTNode containedNode = nodeSelector.findFirstContainedNode(lineInformation.getOffset(), lineInformation.getLength());
|
IASTNode containedNode = nodeSelector.findFirstContainedNode(offset, length);
|
||||||
IASTNode beforeCaseEndNode = null;
|
IASTNode beforeCaseEndNode = null;
|
||||||
if (containedNode != null) {
|
if (containedNode != null) {
|
||||||
beforeCaseEndNode = CxxAstUtils.getEnclosingStatement(containedNode);
|
beforeCaseEndNode = CxxAstUtils.getEnclosingStatement(containedNode);
|
||||||
} else {
|
} else {
|
||||||
beforeCaseEndNode = nodeSelector.findEnclosingNode(lineInformation.getOffset(), lineInformation.getLength());
|
beforeCaseEndNode = nodeSelector.findEnclosingNode(offset, length);
|
||||||
}
|
}
|
||||||
if (beforeCaseEndNode instanceof IASTCompoundStatement) {
|
if (beforeCaseEndNode instanceof IASTCompoundStatement) {
|
||||||
while (beforeCaseEndNode != null) {
|
while (beforeCaseEndNode != null) {
|
||||||
|
|
|
@ -219,7 +219,9 @@ public class CaseBreakChecker extends AbstractIndexAstChecker implements IChecke
|
||||||
IASTFileLocation astLocation = astNode.getFileLocation();
|
IASTFileLocation astLocation = astNode.getFileLocation();
|
||||||
int line = astLocation.getEndingLineNumber();
|
int line = astLocation.getEndingLineNumber();
|
||||||
IProblemLocationFactory locFactory = getRuntime().getProblemLocationFactory();
|
IProblemLocationFactory locFactory = getRuntime().getProblemLocationFactory();
|
||||||
return locFactory.createProblemLocation(getFile(), -1, -1, line);
|
int offset = astLocation.getNodeOffset();
|
||||||
|
return locFactory.createProblemLocation(getFile(), offset,
|
||||||
|
offset + astLocation.getNodeLength(), line);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue