mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +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:
parent
95eee92c4c
commit
bb8f775f99
2 changed files with 29 additions and 23 deletions
|
@ -39,6 +39,7 @@ import org.eclipse.ui.texteditor.AbstractTextEditor;
|
||||||
import org.eclipse.ui.texteditor.ITextEditor;
|
import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
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.model.ICProject;
|
||||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
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<>();
|
Map<String, String[][]> resultsMap = new HashMap<>();
|
||||||
for (Object result : results) {
|
for (Object result : results) {
|
||||||
switch (compareType) {
|
switch (compareType) {
|
||||||
case REPLACEMENT:
|
case REPLACEMENT:
|
||||||
if (result instanceof ParameterGuessingProposal) {
|
if (result instanceof ParameterGuessingProposal) {
|
||||||
ParameterGuessingProposal proposal = (ParameterGuessingProposal) result;
|
ParameterGuessingProposal proposal = (ParameterGuessingProposal) result;
|
||||||
|
proposal.generateParameterGuesses();
|
||||||
String pName = proposal.getReplacementString();
|
String pName = proposal.getReplacementString();
|
||||||
ICompletionProposal[][] pProposals = proposal
|
ICompletionProposal[][] pProposals = proposal
|
||||||
.getParametersGuesses();
|
.getParametersGuesses();
|
||||||
|
|
|
@ -176,27 +176,7 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
|
||||||
super.apply(document, trigger, offset);
|
super.apply(document, trigger, offset);
|
||||||
|
|
||||||
if (fGuessArguments) {
|
if (fGuessArguments) {
|
||||||
IStatus status = ASTProvider.getASTProvider().runOnAST(fTranslationUnit, ASTProvider.WAIT_ACTIVE_ONLY,
|
generateParameterGuesses();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int baseOffset = getReplacementOffset();
|
int baseOffset = getReplacementOffset();
|
||||||
|
@ -275,8 +255,32 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
|
||||||
|
|
||||||
return new Point(fSelectedRegion.getOffset(), fSelectedRegion.getLength());
|
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;
|
int count = fParametersNames.length;
|
||||||
fPositions = new Position[count];
|
fPositions = new Position[count];
|
||||||
fChoices = new ICompletionProposal[count][];
|
fChoices = new ICompletionProposal[count][];
|
||||||
|
|
Loading…
Add table
Reference in a new issue