mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-13 19:25:38 +02:00
Fix for 189119: [Parameter Hints] failure to highlight current parameter
This commit is contained in:
parent
6a7ab9f69b
commit
7f4dce4f49
1 changed files with 64 additions and 26 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2005 QNX Software Systems and others.
|
* Copyright (c) 2000, 2007 QNX Software Systems and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -7,9 +7,13 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - Initial API and implementation
|
* QNX Software Systems - Initial API and implementation
|
||||||
|
* Anton Leherbauer (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.text;
|
package org.eclipse.cdt.internal.ui.text;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.custom.StyleRange;
|
import org.eclipse.swt.custom.StyleRange;
|
||||||
|
|
||||||
|
@ -190,31 +194,14 @@ public class CParameterListValidator implements IContextInformationValidator, IC
|
||||||
//Don't presume what has been done to the string, rather use as is
|
//Don't presume what has been done to the string, rather use as is
|
||||||
String s= fInformation.getInformationDisplayString();
|
String s= fInformation.getInformationDisplayString();
|
||||||
|
|
||||||
//@@@ This is obviously going to have problems with functions such
|
int[] commas= computeCommaPositions(s);
|
||||||
//int myfunction(int (*function_argument)(void * extra, int param), void * extra)
|
if (commas.length - 2 < fCurrentParameter) {
|
||||||
//int myfunction(/*A comment, indeed */int a);
|
|
||||||
int start= 0;
|
|
||||||
int occurrences= 0;
|
|
||||||
while (occurrences < fCurrentParameter) {
|
|
||||||
int found= s.indexOf(',', start);
|
|
||||||
if (found == -1)
|
|
||||||
break;
|
|
||||||
start= found + 1;
|
|
||||||
++ occurrences;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (occurrences < fCurrentParameter) {
|
|
||||||
presentation.addStyleRange(new StyleRange(0, s.length(), null, null, SWT.NORMAL));
|
presentation.addStyleRange(new StyleRange(0, s.length(), null, null, SWT.NORMAL));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start == -1)
|
int start= commas[fCurrentParameter] + 1;
|
||||||
start= 0;
|
int end= commas[fCurrentParameter + 1];
|
||||||
|
|
||||||
int end= s.indexOf(',', start);
|
|
||||||
if (end == -1)
|
|
||||||
end= s.length();
|
|
||||||
|
|
||||||
if (start > 0)
|
if (start > 0)
|
||||||
presentation.addStyleRange(new StyleRange(0, start, null, null, SWT.NORMAL));
|
presentation.addStyleRange(new StyleRange(0, start, null, null, SWT.NORMAL));
|
||||||
|
|
||||||
|
@ -226,5 +213,56 @@ public class CParameterListValidator implements IContextInformationValidator, IC
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int[] computeCommaPositions(String code) {
|
||||||
|
final int length= code.length();
|
||||||
|
int pos= 0;
|
||||||
|
List positions= new ArrayList();
|
||||||
|
positions.add(new Integer(-1));
|
||||||
|
while (pos < length && pos != -1) {
|
||||||
|
char ch= code.charAt(pos);
|
||||||
|
switch (ch) {
|
||||||
|
case ',':
|
||||||
|
positions.add(new Integer(pos));
|
||||||
|
break;
|
||||||
|
case '(':
|
||||||
|
pos= indexOfClosingPeer(code, '(', ')', pos);
|
||||||
|
break;
|
||||||
|
case '<':
|
||||||
|
pos= indexOfClosingPeer(code, '<', '>', pos);
|
||||||
|
break;
|
||||||
|
case '[':
|
||||||
|
pos= indexOfClosingPeer(code, '[', ']', pos);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (pos != -1)
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
positions.add(new Integer(length));
|
||||||
|
|
||||||
|
int[] fields= new int[positions.size()];
|
||||||
|
for (int i= 0; i < fields.length; i++)
|
||||||
|
fields[i]= ((Integer) positions.get(i)).intValue();
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int indexOfClosingPeer(String code, char left, char right, int pos) {
|
||||||
|
int level= 0;
|
||||||
|
final int length= code.length();
|
||||||
|
while (pos < length) {
|
||||||
|
char ch= code.charAt(pos);
|
||||||
|
if (ch == left) {
|
||||||
|
++level;
|
||||||
|
} else if (ch == right) {
|
||||||
|
if (--level == 0) {
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++pos;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue