1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 08:46:02 +02:00

Bug 495095 - Get the parameter guessing test suite to actually exercise the parameter guessing code

Change-Id: Ic0c2031f5d2f8854fcd304bbce8cba44222a0070
This commit is contained in:
Nathan Ridge 2016-06-01 03:28:15 -04:00
parent 95eee92c4c
commit bb8f775f99
2 changed files with 29 additions and 23 deletions

View file

@ -39,6 +39,7 @@ import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.CUIPlugin;
@ -240,13 +241,14 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
}
}
private Map<String, String[][]> toMap(Object[] results, CompareType compareType) {
private Map<String, String[][]> toMap(Object[] results, CompareType compareType) throws CModelException {
Map<String, String[][]> resultsMap = new HashMap<>();
for (Object result : results) {
switch (compareType) {
case REPLACEMENT:
if (result instanceof ParameterGuessingProposal) {
ParameterGuessingProposal proposal = (ParameterGuessingProposal) result;
proposal.generateParameterGuesses();
String pName = proposal.getReplacementString();
ICompletionProposal[][] pProposals = proposal
.getParametersGuesses();

View file

@ -176,27 +176,7 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
super.apply(document, trigger, offset);
if (fGuessArguments) {
IStatus status = ASTProvider.getASTProvider().runOnAST(fTranslationUnit, ASTProvider.WAIT_ACTIVE_ONLY,
new NullProgressMonitor(), new ASTRunnable() {
@Override
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit astRoot) throws CoreException {
if (astRoot == null)
return Status.CANCEL_STATUS;
// Initialize necessary fields.
fParametersNames = getFunctionParametersNames(fFunctionParameters);
fParametersTypes = getFunctionParametersTypes(fFunctionParameters);
try {
guessParameters();
} catch (Exception e) {
CUIPlugin.log(e);
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
});
if (Status.CANCEL_STATUS == status)
return;
generateParameterGuesses();
}
int baseOffset = getReplacementOffset();
@ -275,8 +255,32 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
return new Point(fSelectedRegion.getOffset(), fSelectedRegion.getLength());
}
public void generateParameterGuesses() {
IStatus status = ASTProvider.getASTProvider().runOnAST(fTranslationUnit, ASTProvider.WAIT_ACTIVE_ONLY,
new NullProgressMonitor(), new ASTRunnable() {
@Override
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit astRoot) throws CoreException {
if (astRoot == null)
return Status.CANCEL_STATUS;
try {
guessParameters(astRoot);
} catch (Exception e) {
CUIPlugin.log(e);
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
});
if (Status.CANCEL_STATUS == status)
return;
}
void guessParameters(IASTTranslationUnit ast) throws CModelException {
// Initialize necessary fields.
fParametersNames = getFunctionParametersNames(fFunctionParameters);
fParametersTypes = getFunctionParametersTypes(fFunctionParameters);
private void guessParameters() throws CModelException {
int count = fParametersNames.length;
fPositions = new Position[count];
fChoices = new ICompletionProposal[count][];