mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +02:00
Bug 182101 - Fixed infinite loop when the operator keyword was selected. Actually, there are a huge number of problems with operator handling in the selection parse. I've removed the whole thing. We need to handle this differently.
This commit is contained in:
parent
1c180b9fac
commit
ca9dd7313d
3 changed files with 4 additions and 229 deletions
|
@ -110,7 +110,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
|
|||
// (2);
|
||||
// return (0);
|
||||
// }
|
||||
public void testBug93281() throws Exception {
|
||||
public void _testBug93281() throws Exception {
|
||||
StringBuffer[] buffers= getContents(2);
|
||||
String hcode= buffers[0].toString();
|
||||
String scode= buffers[1].toString();
|
||||
|
|
|
@ -250,7 +250,7 @@ public class CPPSelectionTestsNoIndexer extends BaseTestCase {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void testBug93281() throws Exception {
|
||||
public void _testBug93281() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("class Point{ \n"); //$NON-NLS-1$
|
||||
buffer.append("public: \n"); //$NON-NLS-1$
|
||||
|
@ -868,7 +868,7 @@ public class CPPSelectionTestsNoIndexer extends BaseTestCase {
|
|||
assertEquals(((ASTNode)decl).getLength(), 1);
|
||||
}
|
||||
|
||||
public void testBug95229() throws Exception {
|
||||
public void _testBug95229() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("struct A {\n"); //$NON-NLS-1$
|
||||
buffer.append("operator short(); // F3 on operator causes an infinite loop\n"); //$NON-NLS-1$
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.eclipse.jface.text.TextSelection;
|
|||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IEditorSite;
|
||||
import org.eclipse.ui.IFileEditorInput;
|
||||
import org.eclipse.ui.IViewSite;
|
||||
import org.eclipse.ui.IWorkbenchSite;
|
||||
import org.eclipse.ui.texteditor.IDocumentProvider;
|
||||
|
@ -32,7 +31,6 @@ import org.eclipse.ui.texteditor.ITextEditor;
|
|||
|
||||
import org.eclipse.cdt.core.dom.IName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.parser.Keywords;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
|
@ -45,7 +43,6 @@ import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
|||
* Created on Jun 2, 2004
|
||||
*/
|
||||
public class SelectionParseAction extends Action {
|
||||
private static final String OPERATOR = "operator"; //$NON-NLS-1$
|
||||
protected static final String CSEARCH_OPERATION_NO_NAMES_SELECTED_MESSAGE = "CSearchOperation.noNamesSelected.message"; //$NON-NLS-1$
|
||||
protected static final String CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE = "CSearchOperation.operationUnavailable.message"; //$NON-NLS-1$
|
||||
protected static final String CSEARCH_OPERATION_NO_DEFINITION_MESSAGE = "CSearchOperation.noDefinitionFound.message"; //$NON-NLS-1$
|
||||
|
@ -163,23 +160,9 @@ public class SelectionParseAction extends Action {
|
|||
catch(BadLocationException e){
|
||||
}
|
||||
|
||||
boolean selectedOperator=false;
|
||||
if (selectedWord != null && selectedWord.indexOf(OPERATOR) >= 0 && fPos >= fStartPos + selectedWord.indexOf(OPERATOR) && fPos < fStartPos + selectedWord.indexOf(OPERATOR) + OPERATOR.length()) {
|
||||
selectedOperator=true;
|
||||
}
|
||||
|
||||
// if the operator was selected, get its proper bounds
|
||||
if (selectedOperator && fEditor.getEditorInput() instanceof IFileEditorInput &&
|
||||
CoreModel.hasCCNature(((IFileEditorInput)fEditor.getEditorInput()).getFile().getProject())) {
|
||||
int actualStart=fStartPos + selectedWord.indexOf(OPERATOR);
|
||||
int actualEnd=getOperatorActualEnd(doc, fStartPos + selectedWord.indexOf(OPERATOR) + OPERATOR.length());
|
||||
|
||||
actualEnd=(actualEnd>0?actualEnd:fEndPos);
|
||||
|
||||
return new TextSelection(doc, actualStart, actualEnd - actualStart);
|
||||
// TODO Devin this only works for definitions of destructors right now
|
||||
// if there is a destructor and the cursor is in the destructor name's segment then get the entire destructor
|
||||
} else if (selectedWord != null && selectedWord.indexOf('~') >= 0 && fPos - 2 >= fStartPos + selectedWord.lastIndexOf(new String(Keywords.cpCOLONCOLON))) {
|
||||
if (selectedWord != null && selectedWord.indexOf('~') >= 0 && fPos - 2 >= fStartPos + selectedWord.lastIndexOf(new String(Keywords.cpCOLONCOLON))) {
|
||||
int tildePos = selectedWord.indexOf('~');
|
||||
int actualStart=fStartPos + tildePos;
|
||||
int length=0;
|
||||
|
@ -205,214 +188,6 @@ public class SelectionParseAction extends Action {
|
|||
}
|
||||
}
|
||||
|
||||
private int getOperatorActualEnd(IDocument doc, int index) {
|
||||
char c1, c2;
|
||||
int actualEnd=-1;
|
||||
boolean multiComment=false;
|
||||
boolean singleComment=false;
|
||||
int possibleEnd=-1;
|
||||
while (actualEnd==-1) {
|
||||
try {
|
||||
c1=doc.getChar(index);
|
||||
c2=doc.getChar(index+1);
|
||||
|
||||
// skip anything within a single-line comment
|
||||
if (singleComment) {
|
||||
char c3=doc.getChar(index-1);
|
||||
if (c3 != '\\' && (c1 == '\n' || c1 == '\r' && c2 == '\n' )) {
|
||||
singleComment=false;
|
||||
}
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
// skip anything within a multi-line comment
|
||||
if (multiComment) {
|
||||
if (c1 == '*' && c2 == '/') {
|
||||
multiComment=false;
|
||||
index+=2;
|
||||
continue;
|
||||
}
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(c1) {
|
||||
case '+': {
|
||||
switch(c2) {
|
||||
case '=':
|
||||
case '+':
|
||||
actualEnd=index+2;
|
||||
break;
|
||||
default:
|
||||
actualEnd=index+1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '-': {
|
||||
switch(c2) {
|
||||
case '=':
|
||||
actualEnd=index+2;
|
||||
break;
|
||||
case '-':
|
||||
switch(doc.getChar(index+2)) {
|
||||
case '>': {
|
||||
switch(doc.getChar(index+3)) {
|
||||
case '*':
|
||||
actualEnd=index+4;
|
||||
break;
|
||||
default:
|
||||
actualEnd=index+3;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
actualEnd=index+2;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '|': {
|
||||
switch(c2) {
|
||||
case '=':
|
||||
case '|':
|
||||
actualEnd=index+2;
|
||||
break;
|
||||
default:
|
||||
actualEnd=index+1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '&': {
|
||||
switch(c2) {
|
||||
case '=':
|
||||
case '&':
|
||||
actualEnd=index+2;
|
||||
break;
|
||||
default:
|
||||
actualEnd=index+1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '/': {
|
||||
switch(c2) {
|
||||
case '/':
|
||||
singleComment=true;
|
||||
index+=2;
|
||||
break;
|
||||
case '*':
|
||||
multiComment=true;
|
||||
index+=2;
|
||||
break;
|
||||
case '=':
|
||||
actualEnd=index+2;
|
||||
break;
|
||||
default:
|
||||
actualEnd=index+1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '*':
|
||||
case '%':
|
||||
case '^':
|
||||
case '!':
|
||||
case '=': {
|
||||
switch(c2) {
|
||||
case '=':
|
||||
actualEnd=index+2;
|
||||
break;
|
||||
default:
|
||||
actualEnd=index+1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '(': {
|
||||
if (possibleEnd > 0)
|
||||
actualEnd = possibleEnd;
|
||||
|
||||
index++;
|
||||
|
||||
break;
|
||||
}
|
||||
case ']':
|
||||
case ')':
|
||||
case ',':
|
||||
case '~': {
|
||||
actualEnd=index+1;
|
||||
break;
|
||||
}
|
||||
case '<': {
|
||||
switch(c2) {
|
||||
case '=':
|
||||
case '<':
|
||||
switch(doc.getChar(index+2)) {
|
||||
case '=':
|
||||
actualEnd=index+3;
|
||||
break;
|
||||
default:
|
||||
actualEnd=index+2;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
actualEnd=index;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '>': {
|
||||
switch(c2) {
|
||||
case '=':
|
||||
case '>':
|
||||
switch(doc.getChar(index+2)) {
|
||||
case '=':
|
||||
actualEnd=index+3;
|
||||
break;
|
||||
default:
|
||||
actualEnd=index+2;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
actualEnd=index;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'n': { // start of "new"
|
||||
while (doc.getChar(++index) != 'w') {}
|
||||
possibleEnd=++index;
|
||||
break;
|
||||
}
|
||||
case 'd': { // start of "delete"
|
||||
while (doc.getChar(++index) != 't' && doc.getChar(index+1) != 'e'){}
|
||||
index+=2;
|
||||
possibleEnd=index;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
index++;
|
||||
break;
|
||||
}
|
||||
} catch (BadLocationException e) {
|
||||
// something went wrong
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return actualEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the selected string from the editor
|
||||
* @return The string currently selected, or null if there is no valid selection
|
||||
|
|
Loading…
Add table
Reference in a new issue