mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +02:00
Cosmetics.
Change-Id: I379de81844c6beed828ec2d27cef110a10987d17
This commit is contained in:
parent
62dc7c36ea
commit
3e27134c47
9 changed files with 128 additions and 111 deletions
|
@ -399,8 +399,9 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
fActiveCode= true;
|
fActiveCode= true;
|
||||||
while (t != null && t.getType() != IToken.tINACTIVE_CODE_END)
|
while (t != null && t.getType() != IToken.tINACTIVE_CODE_END) {
|
||||||
t= t.getNext();
|
t= t.getNext();
|
||||||
|
}
|
||||||
|
|
||||||
if (t != null) {
|
if (t != null) {
|
||||||
nextToken= t.getNext();
|
nextToken= t.getNext();
|
||||||
|
@ -524,7 +525,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
|
|
||||||
protected final boolean isOnSameLine(int offset1, int offset2) {
|
protected final boolean isOnSameLine(int offset1, int offset2) {
|
||||||
ILocationResolver lr= getTranslationUnit().getAdapter(ILocationResolver.class);
|
ILocationResolver lr= getTranslationUnit().getAdapter(ILocationResolver.class);
|
||||||
IASTFileLocation floc= lr.getMappedFileLocation(offset1, offset2-offset1+1);
|
IASTFileLocation floc= lr.getMappedFileLocation(offset1, offset2 - offset1 + 1);
|
||||||
return floc.getFileName().equals(lr.getContainingFilePath(offset1)) &&
|
return floc.getFileName().equals(lr.getContainingFilePath(offset1)) &&
|
||||||
floc.getStartingLineNumber() == floc.getEndingLineNumber();
|
floc.getStartingLineNumber() == floc.getEndingLineNumber();
|
||||||
}
|
}
|
||||||
|
@ -541,12 +542,12 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
|
|
||||||
protected final <T extends IASTNode> T setRange(T n, IASTNode from, int endOffset) {
|
protected final <T extends IASTNode> T setRange(T n, IASTNode from, int endOffset) {
|
||||||
final int offset = ((ASTNode) from).getOffset();
|
final int offset = ((ASTNode) from).getOffset();
|
||||||
((ASTNode) n).setOffsetAndLength(offset, endOffset-offset);
|
((ASTNode) n).setOffsetAndLength(offset, endOffset - offset);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final <T extends IASTNode> T setRange(T n, int offset, int endOffset) {
|
protected final <T extends IASTNode> T setRange(T n, int offset, int endOffset) {
|
||||||
((ASTNode) n).setOffsetAndLength(offset, endOffset-offset);
|
((ASTNode) n).setOffsetAndLength(offset, endOffset - offset);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -557,7 +558,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
|
|
||||||
protected final <T extends IASTNode> T adjustEndOffset(T n, final int endOffset) {
|
protected final <T extends IASTNode> T adjustEndOffset(T n, final int endOffset) {
|
||||||
final ASTNode node = (ASTNode) n;
|
final ASTNode node = (ASTNode) n;
|
||||||
node.setLength(endOffset-node.getOffset());
|
node.setLength(endOffset - node.getOffset());
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,9 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.ui.tests.text.contentassist2;
|
package org.eclipse.cdt.ui.tests.text.contentassist2;
|
||||||
|
|
||||||
|
import static org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_METHOD_DECLARATION_PARAMETERS;
|
||||||
|
import static org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_TEMPLATE_PARAMETERS;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -36,7 +39,6 @@ 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.formatter.DefaultCodeFormatterConstants;
|
|
||||||
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;
|
||||||
|
@ -56,9 +58,7 @@ import org.eclipse.cdt.internal.ui.text.contentassist.ParameterGuessingProposal;
|
||||||
import org.eclipse.cdt.internal.ui.text.contentassist.RelevanceConstants;
|
import org.eclipse.cdt.internal.ui.text.contentassist.RelevanceConstants;
|
||||||
|
|
||||||
public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
||||||
public static enum CompareType {
|
public static enum CompareType { ID, DISPLAY, REPLACEMENT, CONTEXT, INFORMATION }
|
||||||
ID, DISPLAY, REPLACEMENT, CONTEXT, INFORMATION
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ContentAssistResult {
|
private class ContentAssistResult {
|
||||||
long startTime;
|
long startTime;
|
||||||
|
@ -102,7 +102,7 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup the project's content.
|
* Sets up the project's content.
|
||||||
* @param project
|
* @param project
|
||||||
* @return the file to be opened in the editor
|
* @return the file to be opened in the editor
|
||||||
*/
|
*/
|
||||||
|
@ -123,9 +123,8 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
||||||
return CUIPlugin.getDefault().getPreferenceStore();
|
return CUIPlugin.getDefault().getPreferenceStore();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ContentAssistResult invokeContentAssist(int offset, int length,
|
private ContentAssistResult invokeContentAssist(int offset, int length, boolean isCompletion,
|
||||||
boolean isCompletion, boolean isTemplate, boolean filterResults)
|
boolean isTemplate, boolean filterResults) throws Exception {
|
||||||
throws Exception {
|
|
||||||
if (CTestPlugin.getDefault().isDebugging()) {
|
if (CTestPlugin.getDefault().isDebugging()) {
|
||||||
System.out.println("\n\n\n\n\nTesting " + this.getClass().getName());
|
System.out.println("\n\n\n\n\nTesting " + this.getClass().getName());
|
||||||
}
|
}
|
||||||
|
@ -158,9 +157,8 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
||||||
return new ContentAssistResult(startTime, endTime, results);
|
return new ContentAssistResult(startTime, endTime, results);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertContentAssistResults(int offset, int length,
|
protected void assertContentAssistResults(int offset, int length, String[] expected, boolean isCompletion,
|
||||||
String[] expected, boolean isCompletion, boolean isTemplate,
|
boolean isTemplate, boolean filterResults, CompareType compareType) throws Exception {
|
||||||
boolean filterResults, CompareType compareType) throws Exception {
|
|
||||||
ContentAssistResult r = invokeContentAssist(offset, length, isCompletion, isTemplate, filterResults);
|
ContentAssistResult r = invokeContentAssist(offset, length, isCompletion, isTemplate, filterResults);
|
||||||
|
|
||||||
String[] resultStrings= toStringArray(r.results, compareType);
|
String[] resultStrings= toStringArray(r.results, compareType);
|
||||||
|
@ -204,7 +202,7 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
||||||
|
|
||||||
protected void assertContentAssistResults(int offset, int length, Map<String, String[][]> expected,
|
protected void assertContentAssistResults(int offset, int length, Map<String, String[][]> expected,
|
||||||
boolean isCompletion, boolean isTemplate, boolean filterResults, CompareType compareType)
|
boolean isCompletion, boolean isTemplate, boolean filterResults, CompareType compareType)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
ContentAssistResult r = invokeContentAssist(offset, length, isCompletion, isTemplate, filterResults);
|
ContentAssistResult r = invokeContentAssist(offset, length, isCompletion, isTemplate, filterResults);
|
||||||
Map<String, String[][]> resultMap = toMap(r.results, compareType);
|
Map<String, String[][]> resultMap = toMap(r.results, compareType);
|
||||||
|
|
||||||
|
@ -242,8 +240,7 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String[][]> toMap(Object[] results,
|
private Map<String, String[][]> toMap(Object[] results, CompareType compareType) {
|
||||||
CompareType compareType) {
|
|
||||||
Map<String, String[][]> resultsMap = new HashMap<>();
|
Map<String, String[][]> resultsMap = new HashMap<>();
|
||||||
for (Object result : results) {
|
for (Object result : results) {
|
||||||
switch (compareType) {
|
switch (compareType) {
|
||||||
|
@ -273,16 +270,19 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
||||||
return resultsMap;
|
return resultsMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertContentAssistResults(int offset, int length, String[] expected, boolean isCompletion, boolean isTemplate, CompareType compareType) throws Exception {
|
protected void assertContentAssistResults(int offset, int length, String[] expected, boolean isCompletion,
|
||||||
|
boolean isTemplate, CompareType compareType) throws Exception {
|
||||||
assertContentAssistResults(offset, length, expected, isCompletion, isTemplate, true, compareType);
|
assertContentAssistResults(offset, length, expected, isCompletion, isTemplate, true, compareType);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertContentAssistResults(int offset, String[] expected, boolean isCompletion, CompareType compareType) throws Exception {
|
protected void assertContentAssistResults(int offset, String[] expected, boolean isCompletion,
|
||||||
|
CompareType compareType) throws Exception {
|
||||||
assertContentAssistResults(offset, 0, expected, isCompletion, false, compareType);
|
assertContentAssistResults(offset, 0, expected, isCompletion, false, compareType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter out template and keyword proposals.
|
* Filter out template and keyword proposals.
|
||||||
|
*
|
||||||
* @param results
|
* @param results
|
||||||
* @param isCodeCompletion completion is in code, not preprocessor, etc.
|
* @param isCodeCompletion completion is in code, not preprocessor, etc.
|
||||||
* @return filtered proposals
|
* @return filtered proposals
|
||||||
|
@ -386,14 +386,14 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the content of the editor buffer
|
* Returns the content of the editor buffer
|
||||||
*/
|
*/
|
||||||
protected String getBuffer() {
|
protected String getBuffer() {
|
||||||
return getDocument().get();
|
return getDocument().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the editor document
|
* Returns the editor document
|
||||||
*/
|
*/
|
||||||
protected IDocument getDocument() {
|
protected IDocument getDocument() {
|
||||||
return EditorTestHelper.getDocument(fEditor);
|
return EditorTestHelper.getDocument(fEditor);
|
||||||
|
@ -401,11 +401,10 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
||||||
|
|
||||||
protected void setCommaAfterFunctionParameter(String value) {
|
protected void setCommaAfterFunctionParameter(String value) {
|
||||||
fCProject.setOption(
|
fCProject.setOption(
|
||||||
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_METHOD_DECLARATION_PARAMETERS, value);
|
FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_METHOD_DECLARATION_PARAMETERS, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setCommaAfterTemplateParameter(String value) {
|
protected void setCommaAfterTemplateParameter(String value) {
|
||||||
fCProject.setOption(
|
fCProject.setOption(FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_TEMPLATE_PARAMETERS, value);
|
||||||
DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_TEMPLATE_PARAMETERS, value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,13 +13,13 @@ package org.eclipse.cdt.ui.tests.text.contentassist2;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
|
||||||
public class CParameterGuessingTests extends AbstractContentAssistTest {
|
public class CParameterGuessingTests extends AbstractContentAssistTest {
|
||||||
private static final String HEADER_FILE_NAME = "PGTest_C.h";
|
private static final String HEADER_FILE_NAME = "PGTest_C.h";
|
||||||
private static final String SOURCE_FILE_NAME = "PGTest_C.c";
|
private static final String SOURCE_FILE_NAME = "PGTest_C.c";
|
||||||
|
@ -52,8 +52,8 @@ public class CParameterGuessingTests extends AbstractContentAssistTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertParametersGuesses(Map<String, String[][]> expected) throws Exception {
|
protected void assertParametersGuesses(Map<String, String[][]> expected) throws Exception {
|
||||||
assertContentAssistResults(getBuffer().length() - 1, 0, expected, true,
|
assertContentAssistResults(getBuffer().length() - 1, 0, expected, true, false, false,
|
||||||
false, false, CompareType.REPLACEMENT);
|
CompareType.REPLACEMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// void foo(){
|
// void foo(){
|
||||||
|
|
|
@ -19,11 +19,11 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.FileLocator;
|
import org.eclipse.core.runtime.FileLocator;
|
||||||
import org.eclipse.core.runtime.IConfigurationElement;
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
import org.eclipse.core.runtime.IExtension;
|
import org.eclipse.core.runtime.IExtension;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
|
||||||
import org.eclipse.jface.action.LegacyActionTools;
|
import org.eclipse.jface.action.LegacyActionTools;
|
||||||
import org.eclipse.jface.resource.ImageDescriptor;
|
import org.eclipse.jface.resource.ImageDescriptor;
|
||||||
import org.eclipse.jface.text.contentassist.ICompletionProposal;
|
import org.eclipse.jface.text.contentassist.ICompletionProposal;
|
||||||
|
@ -252,7 +252,8 @@ public final class CompletionProposalCategory {
|
||||||
* @return the list of computed completion proposals (element type:
|
* @return the list of computed completion proposals (element type:
|
||||||
* {@link org.eclipse.jface.text.contentassist.ICompletionProposal})
|
* {@link org.eclipse.jface.text.contentassist.ICompletionProposal})
|
||||||
*/
|
*/
|
||||||
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, String partition, SubProgressMonitor monitor) {
|
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context,
|
||||||
|
String partition, IProgressMonitor monitor) {
|
||||||
fLastError= null;
|
fLastError= null;
|
||||||
List<ICompletionProposal> result= new ArrayList<>();
|
List<ICompletionProposal> result= new ArrayList<>();
|
||||||
List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<>(fRegistry.getProposalComputerDescriptors(partition));
|
List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<>(fRegistry.getProposalComputerDescriptors(partition));
|
||||||
|
@ -276,10 +277,12 @@ public final class CompletionProposalCategory {
|
||||||
* @return the list of computed context information objects (element type:
|
* @return the list of computed context information objects (element type:
|
||||||
* {@link org.eclipse.jface.text.contentassist.IContextInformation})
|
* {@link org.eclipse.jface.text.contentassist.IContextInformation})
|
||||||
*/
|
*/
|
||||||
public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, String partition, SubProgressMonitor monitor) {
|
public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context,
|
||||||
|
String partition, IProgressMonitor monitor) {
|
||||||
fLastError= null;
|
fLastError= null;
|
||||||
List<IContextInformation> result= new ArrayList<>();
|
List<IContextInformation> result= new ArrayList<>();
|
||||||
List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<>(fRegistry.getProposalComputerDescriptors(partition));
|
List<CompletionProposalComputerDescriptor> descriptors=
|
||||||
|
new ArrayList<>(fRegistry.getProposalComputerDescriptors(partition));
|
||||||
for (CompletionProposalComputerDescriptor desc : descriptors) {
|
for (CompletionProposalComputerDescriptor desc : descriptors) {
|
||||||
if (desc.getCategory() == this)
|
if (desc.getCategory() == this)
|
||||||
result.addAll(desc.computeContextInformation(context, monitor));
|
result.addAll(desc.computeContextInformation(context, monitor));
|
||||||
|
|
|
@ -23,7 +23,7 @@ import org.eclipse.core.runtime.Assert;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
import org.eclipse.core.runtime.SubMonitor;
|
||||||
import org.eclipse.jface.action.LegacyActionTools;
|
import org.eclipse.jface.action.LegacyActionTools;
|
||||||
import org.eclipse.jface.bindings.TriggerSequence;
|
import org.eclipse.jface.bindings.TriggerSequence;
|
||||||
import org.eclipse.jface.bindings.keys.KeySequence;
|
import org.eclipse.jface.bindings.keys.KeySequence;
|
||||||
|
@ -251,11 +251,13 @@ public class ContentAssistProcessor implements IContentAssistProcessor {
|
||||||
fNumberOfComputedResults= 0;
|
fNumberOfComputedResults= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ICompletionProposal> collectProposals(ITextViewer viewer, int offset, IProgressMonitor monitor, ContentAssistInvocationContext context) {
|
private List<ICompletionProposal> collectProposals(ITextViewer viewer, int offset,
|
||||||
|
IProgressMonitor monitor, ContentAssistInvocationContext context) {
|
||||||
List<ICompletionProposal> proposals= new ArrayList<>();
|
List<ICompletionProposal> proposals= new ArrayList<>();
|
||||||
List<CompletionProposalCategory> providers= getCategories();
|
List<CompletionProposalCategory> providers= getCategories();
|
||||||
|
SubMonitor progress = SubMonitor.convert(monitor, providers.size());
|
||||||
for (CompletionProposalCategory cat : providers) {
|
for (CompletionProposalCategory cat : providers) {
|
||||||
List<ICompletionProposal> computed= cat.computeCompletionProposals(context, fPartition, new SubProgressMonitor(monitor, 1));
|
List<ICompletionProposal> computed= cat.computeCompletionProposals(context, fPartition, progress.split(1));
|
||||||
proposals.addAll(computed);
|
proposals.addAll(computed);
|
||||||
if (fErrorMessage == null)
|
if (fErrorMessage == null)
|
||||||
fErrorMessage= cat.getErrorMessage();
|
fErrorMessage= cat.getErrorMessage();
|
||||||
|
@ -298,14 +300,17 @@ public class ContentAssistProcessor implements IContentAssistProcessor {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<IContextInformation> collectContextInformation(ITextViewer viewer, int offset, IProgressMonitor monitor) {
|
private List<IContextInformation> collectContextInformation(ITextViewer viewer, int offset,
|
||||||
|
IProgressMonitor monitor) {
|
||||||
List<IContextInformation> proposals= new ArrayList<>();
|
List<IContextInformation> proposals= new ArrayList<>();
|
||||||
ContentAssistInvocationContext context= createContext(viewer, offset, false);
|
ContentAssistInvocationContext context= createContext(viewer, offset, false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<CompletionProposalCategory> providers= getCategories();
|
List<CompletionProposalCategory> providers= getCategories();
|
||||||
|
SubMonitor progress = SubMonitor.convert(monitor, providers.size());
|
||||||
for (CompletionProposalCategory cat : providers) {
|
for (CompletionProposalCategory cat : providers) {
|
||||||
List<IContextInformation> computed= cat.computeContextInformation(context, fPartition, new SubProgressMonitor(monitor, 1));
|
List<IContextInformation> computed=
|
||||||
|
cat.computeContextInformation(context, fPartition, progress.split(1));
|
||||||
proposals.addAll(computed);
|
proposals.addAll(computed);
|
||||||
if (fErrorMessage == null)
|
if (fErrorMessage == null)
|
||||||
fErrorMessage= cat.getErrorMessage();
|
fErrorMessage= cat.getErrorMessage();
|
||||||
|
@ -326,7 +331,8 @@ public class ContentAssistProcessor implements IContentAssistProcessor {
|
||||||
* @return the list of filtered and sorted proposals, ready for
|
* @return the list of filtered and sorted proposals, ready for
|
||||||
* display (element type: {@link IContextInformation})
|
* display (element type: {@link IContextInformation})
|
||||||
*/
|
*/
|
||||||
protected List<IContextInformation> filterAndSortContextInformation(List<IContextInformation> contexts, IProgressMonitor monitor) {
|
protected List<IContextInformation> filterAndSortContextInformation(List<IContextInformation> contexts,
|
||||||
|
IProgressMonitor monitor) {
|
||||||
return contexts;
|
return contexts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
private static final String TYPENAME = "typename"; //$NON-NLS-1$;
|
private static final String TYPENAME = "typename"; //$NON-NLS-1$;
|
||||||
private static final String ELLIPSIS = "..."; //$NON-NLS-1$;
|
private static final String ELLIPSIS = "..."; //$NON-NLS-1$;
|
||||||
private String fPrefix;
|
private String fPrefix;
|
||||||
private ArrayList<IBinding> fAvailableElements;
|
private List<IBinding> fAvailableElements;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor is required (executable extension).
|
* Default constructor is required (executable extension).
|
||||||
|
@ -121,8 +121,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<ICompletionProposal> computeCompletionProposals(
|
protected List<ICompletionProposal> computeCompletionProposals(CContentAssistInvocationContext context,
|
||||||
CContentAssistInvocationContext context,
|
|
||||||
IASTCompletionNode completionNode, String prefix) {
|
IASTCompletionNode completionNode, String prefix) {
|
||||||
fPrefix = prefix;
|
fPrefix = prefix;
|
||||||
initializeDefinedElements(context);
|
initializeDefinedElements(context);
|
||||||
|
@ -130,7 +129,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
|
|
||||||
if (inPreprocessorDirective(context)) {
|
if (inPreprocessorDirective(context)) {
|
||||||
if (!inPreprocessorKeyword(context)) {
|
if (!inPreprocessorKeyword(context)) {
|
||||||
// add only macros
|
// Add only macros.
|
||||||
if (prefix.length() == 0) {
|
if (prefix.length() == 0) {
|
||||||
try {
|
try {
|
||||||
prefix= context.computeIdentifierPrefix().toString();
|
prefix= context.computeIdentifierPrefix().toString();
|
||||||
|
@ -146,7 +145,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
|
|
||||||
for (IASTName name : names) {
|
for (IASTName name : names) {
|
||||||
if (name.getTranslationUnit() == null)
|
if (name.getTranslationUnit() == null)
|
||||||
// The node isn't properly hooked up, must have backtracked out of this node
|
// The node isn't properly hooked up, must have backtracked out of this node.
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
IASTCompletionContext astContext = name.getCompletionContext();
|
IASTCompletionContext astContext = name.getCompletionContext();
|
||||||
|
@ -154,7 +153,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
continue;
|
continue;
|
||||||
} else if (astContext instanceof IASTIdExpression
|
} else if (astContext instanceof IASTIdExpression
|
||||||
|| astContext instanceof IASTNamedTypeSpecifier) {
|
|| astContext instanceof IASTNamedTypeSpecifier) {
|
||||||
// handle macros only if there is a prefix
|
// Handle macros only if there is a prefix.
|
||||||
handleMacros = prefix.length() > 0;
|
handleMacros = prefix.length() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,12 +191,12 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
if (ICPartitions.C_PREPROCESSOR.equals(partition.getType())) {
|
if (ICPartitions.C_PREPROCESSOR.equals(partition.getType())) {
|
||||||
String ppPrefix= doc.get(partition.getOffset(), offset - partition.getOffset());
|
String ppPrefix= doc.get(partition.getOffset(), offset - partition.getOffset());
|
||||||
if (ppPrefix.matches("\\s*#\\s*\\w*")) { //$NON-NLS-1$
|
if (ppPrefix.matches("\\s*#\\s*\\w*")) { //$NON-NLS-1$
|
||||||
// we are inside the directive keyword
|
// We are inside the directive keyword.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (BadLocationException exc) {
|
} catch (BadLocationException e) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -205,7 +204,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
/**
|
/**
|
||||||
* Check if the invocation offset is inside a preprocessor directive.
|
* Check if the invocation offset is inside a preprocessor directive.
|
||||||
*
|
*
|
||||||
* @param context the content asist invocation context
|
* @param context the content assist invocation context
|
||||||
* @return <code>true</code> if invocation offset is inside a preprocessor directive
|
* @return <code>true</code> if invocation offset is inside a preprocessor directive
|
||||||
*/
|
*/
|
||||||
private boolean inPreprocessorDirective(CContentAssistInvocationContext context) {
|
private boolean inPreprocessorDirective(CContentAssistInvocationContext context) {
|
||||||
|
@ -239,7 +238,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
char[] prefixChars= prefix.toCharArray();
|
char[] prefixChars= prefix.toCharArray();
|
||||||
final boolean matchPrefix= !context.isContextInformationStyle();
|
final boolean matchPrefix= !context.isContextInformationStyle();
|
||||||
if (matchPrefix) {
|
if (matchPrefix) {
|
||||||
IContentAssistMatcher matcher = ContentAssistMatcherFactory.getInstance().createMatcher(prefixChars);
|
IContentAssistMatcher matcher =
|
||||||
|
ContentAssistMatcherFactory.getInstance().createMatcher(prefixChars);
|
||||||
for (int i = 0; i < macros.length; ++i) {
|
for (int i = 0; i < macros.length; ++i) {
|
||||||
final char[] macroName= macros[i].getName().toCharArray();
|
final char[] macroName= macros[i].getName().toCharArray();
|
||||||
if (matcher.match(macroName)) {
|
if (matcher.match(macroName)) {
|
||||||
|
@ -304,8 +304,9 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argString.length() > 0) {
|
if (!argString.isEmpty()) {
|
||||||
CProposalContextInformation info = new CProposalContextInformation(image, descString, argString);
|
CProposalContextInformation info =
|
||||||
|
new CProposalContextInformation(image, descString, argString);
|
||||||
info.setContextInformationPosition(context.getContextInformationOffset());
|
info.setContextInformationPosition(context.getContextInformationOffset());
|
||||||
proposal.setContextInformation(info);
|
proposal.setContextInformation(info);
|
||||||
}
|
}
|
||||||
|
@ -366,8 +367,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
return name.length == 0 || name[0] == '{';
|
return name.length == 0 || name[0] == '{';
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addProposalForClassTemplate(ICPPClassTemplate templateType, CContentAssistInvocationContext context,
|
private void addProposalForClassTemplate(ICPPClassTemplate templateType,
|
||||||
int baseRelevance, List<ICompletionProposal> proposals) {
|
CContentAssistInvocationContext context, int baseRelevance, List<ICompletionProposal> proposals) {
|
||||||
int relevance = getClassTypeRelevance(templateType);
|
int relevance = getClassTypeRelevance(templateType);
|
||||||
StringBuilder representation = new StringBuilder(templateType.getName());
|
StringBuilder representation = new StringBuilder(templateType.getName());
|
||||||
boolean inUsingDeclaration = context.isInUsingDirective();
|
boolean inUsingDeclaration = context.isInUsingDirective();
|
||||||
|
@ -384,8 +385,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
baseRelevance + relevance, context);
|
baseRelevance + relevance, context);
|
||||||
|
|
||||||
if (!inUsingDeclaration) {
|
if (!inUsingDeclaration) {
|
||||||
CProposalContextInformation info =
|
CProposalContextInformation info = new CProposalContextInformation(
|
||||||
new CProposalContextInformation(getImage(templateType), displayString, templateParameterRepresentation);
|
getImage(templateType), displayString, templateParameterRepresentation);
|
||||||
info.setContextInformationPosition(context.getContextInformationOffset());
|
info.setContextInformationPosition(context.getContextInformationOffset());
|
||||||
proposal.setContextInformation(info);
|
proposal.setContextInformation(info);
|
||||||
if (!context.isContextInformationStyle()) {
|
if (!context.isContextInformationStyle()) {
|
||||||
|
@ -418,8 +419,10 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
} else if (parameter instanceof ICPPTemplateTypeParameter) {
|
} else if (parameter instanceof ICPPTemplateTypeParameter) {
|
||||||
representation.append(TYPENAME);
|
representation.append(TYPENAME);
|
||||||
} else if (parameter instanceof ICPPTemplateTemplateParameter) {
|
} else if (parameter instanceof ICPPTemplateTemplateParameter) {
|
||||||
String templateParameterParameters = buildTemplateParameters((ICPPTemplateTemplateParameter) parameter, context);
|
String templateParameterParameters =
|
||||||
representation.append(MessageFormat.format(TEMPLATE_PARAMETER_PATTERN, templateParameterParameters));
|
buildTemplateParameters((ICPPTemplateTemplateParameter) parameter, context);
|
||||||
|
representation.append(
|
||||||
|
MessageFormat.format(TEMPLATE_PARAMETER_PATTERN, templateParameterParameters));
|
||||||
representation.append(templateParameterParameters);
|
representation.append(templateParameterParameters);
|
||||||
}
|
}
|
||||||
if (parameter.isParameterPack()) {
|
if (parameter.isParameterPack()) {
|
||||||
|
@ -428,11 +431,13 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
representation.append(' ');
|
representation.append(' ');
|
||||||
representation.append(parameter.getName());
|
representation.append(parameter.getName());
|
||||||
if (addDefaultArguments && defaultValue != null) {
|
if (addDefaultArguments && defaultValue != null) {
|
||||||
String defaultArgumentRepresentation = MessageFormat.format(DEFAULT_ARGUMENT_PATTERN, defaultValue);
|
String defaultArgumentRepresentation =
|
||||||
|
MessageFormat.format(DEFAULT_ARGUMENT_PATTERN, defaultValue);
|
||||||
for (int parameterIndex = 0; parameterIndex < i; parameterIndex++) {
|
for (int parameterIndex = 0; parameterIndex < i; parameterIndex++) {
|
||||||
String templateArgumentID = HASH + parameterIndex;
|
String templateArgumentID = HASH + parameterIndex;
|
||||||
String templateArgumentValue = parameters[parameterIndex].getName();
|
String templateArgumentValue = parameters[parameterIndex].getName();
|
||||||
defaultArgumentRepresentation = defaultArgumentRepresentation.replaceAll(templateArgumentID, templateArgumentValue);
|
defaultArgumentRepresentation =
|
||||||
|
defaultArgumentRepresentation.replaceAll(templateArgumentID, templateArgumentValue);
|
||||||
}
|
}
|
||||||
representation.append(defaultArgumentRepresentation);
|
representation.append(defaultArgumentRepresentation);
|
||||||
}
|
}
|
||||||
|
@ -493,8 +498,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
|
|
||||||
repStringBuff.append('(');
|
repStringBuff.append('(');
|
||||||
|
|
||||||
StringBuilder dispargs = new StringBuilder(); // for the dispargString
|
StringBuilder dispArgs = new StringBuilder(); // for the dispargString
|
||||||
StringBuilder idargs = new StringBuilder(); // for the idargString
|
StringBuilder idArgs = new StringBuilder(); // for the idargString
|
||||||
boolean hasArgs = true;
|
boolean hasArgs = true;
|
||||||
String returnTypeStr = null;
|
String returnTypeStr = null;
|
||||||
IParameter[] params = function.getParameters();
|
IParameter[] params = function.getParameters();
|
||||||
|
@ -507,35 +512,36 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
}
|
}
|
||||||
IType paramType = param.getType();
|
IType paramType = param.getType();
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
dispargs.append(parameterDelimiter);
|
dispArgs.append(parameterDelimiter);
|
||||||
idargs.append(parameterDelimiter);
|
idArgs.append(parameterDelimiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
dispargs.append(ASTTypeUtil.getType(paramType, false));
|
dispArgs.append(ASTTypeUtil.getType(paramType, false));
|
||||||
idargs.append(ASTTypeUtil.getType(paramType, false));
|
idArgs.append(ASTTypeUtil.getType(paramType, false));
|
||||||
String paramName = param.getName();
|
String paramName = param.getName();
|
||||||
if (paramName != null && paramName.length() > 0) {
|
if (paramName != null && paramName.length() > 0) {
|
||||||
dispargs.append(' ');
|
dispArgs.append(' ');
|
||||||
dispargs.append(paramName);
|
dispArgs.append(paramName);
|
||||||
}
|
}
|
||||||
if (param instanceof ICPPParameter) {
|
if (param instanceof ICPPParameter) {
|
||||||
ICPPParameter cppParam = (ICPPParameter) param;
|
ICPPParameter cppParam = (ICPPParameter) param;
|
||||||
if (cppParam.hasDefaultValue() && isDisplayDefaultArguments()) {
|
if (cppParam.hasDefaultValue() && isDisplayDefaultArguments()) {
|
||||||
dispargs.append(MessageFormat.format(DEFAULT_ARGUMENT_PATTERN, cppParam.getDefaultValue()));
|
dispArgs.append(
|
||||||
|
MessageFormat.format(DEFAULT_ARGUMENT_PATTERN, cppParam.getDefaultValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (function.takesVarArgs()) {
|
if (function.takesVarArgs()) {
|
||||||
if (params.length > 0) {
|
if (params.length != 0) {
|
||||||
dispargs.append(parameterDelimiter);
|
dispArgs.append(parameterDelimiter);
|
||||||
idargs.append(parameterDelimiter);
|
idArgs.append(parameterDelimiter);
|
||||||
}
|
}
|
||||||
dispargs.append("..."); //$NON-NLS-1$
|
dispArgs.append("..."); //$NON-NLS-1$
|
||||||
idargs.append("..."); //$NON-NLS-1$
|
idArgs.append("..."); //$NON-NLS-1$
|
||||||
} else if (params.length == 0) { // force the void in
|
} else if (params.length == 0) { // force the void in
|
||||||
dispargs.append("void"); //$NON-NLS-1$
|
dispArgs.append("void"); //$NON-NLS-1$
|
||||||
idargs.append("void"); //$NON-NLS-1$
|
idArgs.append("void"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IFunctionType functionType = function.getType();
|
IFunctionType functionType = function.getType();
|
||||||
|
@ -547,20 +553,20 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
|
|
||||||
hasArgs = ASTTypeUtil.functionTakesParameters(function);
|
hasArgs = ASTTypeUtil.functionTakesParameters(function);
|
||||||
|
|
||||||
String dispargString = dispargs.toString();
|
String dispArgString = dispArgs.toString();
|
||||||
String idargString = idargs.toString();
|
String idArgString = idArgs.toString();
|
||||||
String contextDispargString = hasArgs ? dispargString : null;
|
String contextDispargString = hasArgs ? dispArgString : null;
|
||||||
StringBuilder dispStringBuff = new StringBuilder(repStringBuff);
|
StringBuilder dispStringBuff = new StringBuilder(repStringBuff);
|
||||||
dispStringBuff.append(dispargString);
|
dispStringBuff.append(dispArgString);
|
||||||
dispStringBuff.append(')');
|
dispStringBuff.append(')');
|
||||||
if (returnTypeStr != null && returnTypeStr.length() > 0) {
|
if (returnTypeStr != null && !returnTypeStr.isEmpty()) {
|
||||||
dispStringBuff.append(" : "); //$NON-NLS-1$
|
dispStringBuff.append(" : "); //$NON-NLS-1$
|
||||||
dispStringBuff.append(returnTypeStr);
|
dispStringBuff.append(returnTypeStr);
|
||||||
}
|
}
|
||||||
String dispString = dispStringBuff.toString();
|
String dispString = dispStringBuff.toString();
|
||||||
|
|
||||||
StringBuilder idStringBuff = new StringBuilder(repStringBuff);
|
StringBuilder idStringBuff = new StringBuilder(repStringBuff);
|
||||||
idStringBuff.append(idargString);
|
idStringBuff.append(idArgString);
|
||||||
idStringBuff.append(')');
|
idStringBuff.append(')');
|
||||||
String idString = idStringBuff.toString();
|
String idString = idStringBuff.toString();
|
||||||
|
|
||||||
|
@ -584,7 +590,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
CCompletionProposal proposal = createProposal(repString, dispString, idString,
|
CCompletionProposal proposal = createProposal(repString, dispString, idString,
|
||||||
context.getCompletionNode().getLength(), image, baseRelevance + relevance, context);
|
context.getCompletionNode().getLength(), image, baseRelevance + relevance, context);
|
||||||
if (!context.isContextInformationStyle()) {
|
if (!context.isContextInformationStyle()) {
|
||||||
int cursorPosition = (!inUsingDeclaration && hasArgs) ? (repString.length() - 1) : repString.length();
|
int cursorPosition = !inUsingDeclaration && hasArgs ?
|
||||||
|
repString.length() - 1 : repString.length();
|
||||||
proposal.setCursorPosition(cursorPosition);
|
proposal.setCursorPosition(cursorPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,18 +603,21 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The ParameterGuessingProposal will be active if the function accepts parameters and the content assist is
|
* The ParameterGuessingProposal will be active if the function accepts parameters and the content
|
||||||
* invoked before typing any parameters. Otherwise, the normal Parameter Hint Proposal will be added.
|
* assist is invoked before typing any parameters. Otherwise, the normal parameter hint proposal will
|
||||||
|
* be added.
|
||||||
*/
|
*/
|
||||||
if (function.getParameters() != null && function.getParameters().length > 0 && isBeforeParameters(context)) {
|
if (function.getParameters() != null && function.getParameters().length != 0
|
||||||
proposals.add(ParameterGuessingProposal.createProposal(context, fAvailableElements, proposal, function, fPrefix));
|
&& isBeforeParameters(context)) {
|
||||||
|
proposals.add(ParameterGuessingProposal.createProposal(context, fAvailableElements, proposal,
|
||||||
|
function, fPrefix));
|
||||||
} else {
|
} else {
|
||||||
proposals.add(proposal);
|
proposals.add(proposal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the invocation is at the function name or before typing any parameters
|
* Returns true if the invocation is at the function name or before typing any parameters.
|
||||||
*/
|
*/
|
||||||
private boolean isBeforeParameters(CContentAssistInvocationContext context) {
|
private boolean isBeforeParameters(CContentAssistInvocationContext context) {
|
||||||
/*
|
/*
|
||||||
|
@ -637,7 +647,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the list of defined elements at the start of the current statement.
|
* Initializes the list of variables accessible at the start of the current statement.
|
||||||
*/
|
*/
|
||||||
private void initializeDefinedElements(CContentAssistInvocationContext context) {
|
private void initializeDefinedElements(CContentAssistInvocationContext context) {
|
||||||
/*
|
/*
|
||||||
|
@ -804,8 +814,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
CContentAssistInvocationContext cContext, int baseRelevance,
|
CContentAssistInvocationContext cContext, int baseRelevance,
|
||||||
List<ICompletionProposal> proposals) {
|
List<ICompletionProposal> proposals) {
|
||||||
if (astContext instanceof ICPPASTQualifiedName) {
|
if (astContext instanceof ICPPASTQualifiedName) {
|
||||||
IASTCompletionContext parent = ((ICPPASTQualifiedName) astContext)
|
IASTCompletionContext parent = ((ICPPASTQualifiedName) astContext).getCompletionContext();
|
||||||
.getCompletionContext();
|
|
||||||
handleNamespace(namespace, parent, cContext, baseRelevance, proposals);
|
handleNamespace(namespace, parent, cContext, baseRelevance, proposals);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -904,7 +913,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
imageDescriptor = CElementImageProvider.getFunctionImageDescriptor();
|
imageDescriptor = CElementImageProvider.getFunctionImageDescriptor();
|
||||||
} else if (binding instanceof ICPPUsingDeclaration) {
|
} else if (binding instanceof ICPPUsingDeclaration) {
|
||||||
IBinding[] delegates = ((ICPPUsingDeclaration) binding).getDelegates();
|
IBinding[] delegates = ((ICPPUsingDeclaration) binding).getDelegates();
|
||||||
if (delegates.length > 0)
|
if (delegates.length != 0)
|
||||||
return getImage(delegates[0]);
|
return getImage(delegates[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ public abstract class Lazy<E> {
|
||||||
* @return The value of this object.
|
* @return The value of this object.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public E value() {
|
public final E value() {
|
||||||
if (value == NOT_INITIALIZED) {
|
if (value == NOT_INITIALIZED) {
|
||||||
value = calculateValue();
|
value = calculateValue();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.ui.text.contentassist;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.jface.text.BadLocationException;
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
import org.eclipse.jface.text.BadPositionCategoryException;
|
import org.eclipse.jface.text.BadPositionCategoryException;
|
||||||
|
@ -56,18 +57,18 @@ import org.eclipse.cdt.internal.ui.editor.EditorHighlightingSynchronizer;
|
||||||
* with a list of suggestions for each parameter.
|
* with a list of suggestions for each parameter.
|
||||||
*/
|
*/
|
||||||
public class ParameterGuessingProposal extends FunctionCompletionProposal {
|
public class ParameterGuessingProposal extends FunctionCompletionProposal {
|
||||||
private ICompletionProposal[][] fChoices; // initialized by guessParameters()
|
private ICompletionProposal[][] fChoices; // Initialized by guessParameters()
|
||||||
private Position[] fPositions; // initialized by guessParameters()
|
private Position[] fPositions; // Initialized by guessParameters()
|
||||||
private IRegion fSelectedRegion; // initialized by apply()
|
private IRegion fSelectedRegion; // Initialized by apply()
|
||||||
private IPositionUpdater fUpdater;
|
private IPositionUpdater fUpdater;
|
||||||
private String fFullPrefix; // The string from the start of the statement to the invocation offset.
|
private String fFullPrefix; // The string from the start of the statement to the invocation offset.
|
||||||
private CEditor fCEditor;
|
private CEditor fCEditor;
|
||||||
private char[][] fParametersNames;
|
private char[][] fParametersNames;
|
||||||
private IType[] fParametersTypes;
|
private IType[] fParametersTypes;
|
||||||
private ArrayList<IBinding> fAssignableElements;
|
private List<IBinding> fAssignableElements;
|
||||||
|
|
||||||
public static ParameterGuessingProposal createProposal(CContentAssistInvocationContext context,
|
public static ParameterGuessingProposal createProposal(CContentAssistInvocationContext context,
|
||||||
ArrayList<IBinding> availableElements, CCompletionProposal proposal, IFunction function,
|
List<IBinding> availableElements, CCompletionProposal proposal, IFunction function,
|
||||||
String prefix) {
|
String prefix) {
|
||||||
String replacement = getParametersList(function);
|
String replacement = getParametersList(function);
|
||||||
String fullPrefix = function.getName() + "("; //$NON-NLS-1$
|
String fullPrefix = function.getName() + "("; //$NON-NLS-1$
|
||||||
|
@ -92,7 +93,7 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
|
||||||
} catch (BadLocationException e1) {
|
} catch (BadLocationException e1) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// remove ')' from the replacement string if it is auto appended.
|
// Remove ')' from the replacement string if it is auto appended.
|
||||||
if (document.getChar(invocationOffset) == ')')
|
if (document.getChar(invocationOffset) == ')')
|
||||||
replacement = replacement.substring(0, replacement.length() - 1);
|
replacement = replacement.substring(0, replacement.length() - 1);
|
||||||
} catch (BadLocationException e) {
|
} catch (BadLocationException e) {
|
||||||
|
@ -133,7 +134,8 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
|
||||||
|
|
||||||
public ParameterGuessingProposal(String replacementString, int replacementOffset, int replacementLength,
|
public ParameterGuessingProposal(String replacementString, int replacementOffset, int replacementLength,
|
||||||
Image image, String displayString, String idString, int relevance, ITextViewer viewer,
|
Image image, String displayString, String idString, int relevance, ITextViewer viewer,
|
||||||
IFunction function, int invocationOffset, int parseOffset, ITranslationUnit tu, IDocument document) {
|
IFunction function, int invocationOffset, int parseOffset, ITranslationUnit tu,
|
||||||
|
IDocument document) {
|
||||||
super(replacementString, replacementOffset, replacementLength, image, displayString, idString,
|
super(replacementString, replacementOffset, replacementLength, image, displayString, idString,
|
||||||
relevance, viewer, function, invocationOffset, parseOffset, tu, document);
|
relevance, viewer, function, invocationOffset, parseOffset, tu, document);
|
||||||
}
|
}
|
||||||
|
@ -145,9 +147,6 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
|
||||||
return invocationOffset - parseOffset != 0;
|
return invocationOffset - parseOffset != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getPrefixCompletionText(IDocument document, int completionOffset) {
|
public CharSequence getPrefixCompletionText(IDocument document, int completionOffset) {
|
||||||
if (isInsideBracket(fInvocationOffset, fParseOffset)) {
|
if (isInsideBracket(fInvocationOffset, fParseOffset)) {
|
||||||
|
@ -163,7 +162,7 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
|
||||||
public void apply(final IDocument document, char trigger, int offset) {
|
public void apply(final IDocument document, char trigger, int offset) {
|
||||||
super.apply(document, trigger, offset);
|
super.apply(document, trigger, offset);
|
||||||
|
|
||||||
// Initialize necessary fields
|
// Initialize necessary fields.
|
||||||
fParametersNames = getFunctionParametersNames(fFunctionParameters);
|
fParametersNames = getFunctionParametersNames(fFunctionParameters);
|
||||||
fParametersTypes = getFunctionParametersTypes(fFunctionParameters);
|
fParametersTypes = getFunctionParametersTypes(fFunctionParameters);
|
||||||
|
|
||||||
|
@ -204,7 +203,7 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
|
||||||
|
|
||||||
LinkedModeUI ui = new EditorLinkedModeUI(model, fTextViewer);
|
LinkedModeUI ui = new EditorLinkedModeUI(model, fTextViewer);
|
||||||
ui.setExitPosition(fTextViewer, baseOffset + replacement.length(), 0, Integer.MAX_VALUE);
|
ui.setExitPosition(fTextViewer, baseOffset + replacement.length(), 0, Integer.MAX_VALUE);
|
||||||
// exit character can be either ')' or ';'
|
// Exit character can be either ')' or ';'
|
||||||
final char exitChar = replacement.charAt(replacement.length() - 1);
|
final char exitChar = replacement.charAt(replacement.length() - 1);
|
||||||
ui.setExitPolicy(new ExitPolicy(exitChar) {
|
ui.setExitPolicy(new ExitPolicy(exitChar) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -350,7 +349,7 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the c editor, or <code>null</code> if it cannot be determined.
|
* Returns the C/C++ editor, or {@code null} if it cannot be determined.
|
||||||
*/
|
*/
|
||||||
private static CEditor getCEditor(IEditorPart editorPart) {
|
private static CEditor getCEditor(IEditorPart editorPart) {
|
||||||
if (editorPart instanceof CEditor) {
|
if (editorPart instanceof CEditor) {
|
||||||
|
|
|
@ -69,16 +69,16 @@ public class DOMSearchUtil {
|
||||||
{
|
{
|
||||||
shouldVisitNames = true;
|
shouldVisitNames = true;
|
||||||
}
|
}
|
||||||
public List<IASTName> nameList = new ArrayList<IASTName>();
|
public List<IASTName> nameList = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int visit(IASTName name) {
|
public int visit(IASTName name) {
|
||||||
nameList.add( name );
|
nameList.add(name);
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTName getName( int idx ){
|
public IASTName getName(int idx) {
|
||||||
if( idx < 0 || idx >= nameList.size() )
|
if (idx < 0 || idx >= nameList.size())
|
||||||
return null;
|
return null;
|
||||||
return nameList.get(idx);
|
return nameList.get(idx);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue