mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Content Assist Work : Added lookups for Macros with Function style
This commit is contained in:
parent
9cac774800
commit
69cb22837f
11 changed files with 176 additions and 12 deletions
|
@ -632,7 +632,11 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
||||||
|
|
||||||
public boolean isVisible( ISymbol symbol, IContainerSymbol qualifyingSymbol ){
|
public boolean isVisible( ISymbol symbol, IContainerSymbol qualifyingSymbol ){
|
||||||
ISymbolASTExtension extension = symbol.getASTExtension();
|
ISymbolASTExtension extension = symbol.getASTExtension();
|
||||||
|
if(extension == null)
|
||||||
|
return true;
|
||||||
IASTNode node = extension.getPrimaryDeclaration();
|
IASTNode node = extension.getPrimaryDeclaration();
|
||||||
|
if(node == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
if( node instanceof IASTMember ){
|
if( node instanceof IASTMember ){
|
||||||
ASTAccessVisibility visibility;
|
ASTAccessVisibility visibility;
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
2004-01-19 Hoda Amer
|
||||||
|
Added a JUnit test case for completion on Macros with function style.
|
||||||
|
|
||||||
2004-01-16 Hoda Amer
|
2004-01-16 Hoda Amer
|
||||||
Added More success JUnit tests.
|
Added More success JUnit tests.
|
||||||
Added two failed JUnit tests.
|
Added two failed JUnit tests.
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
#include "CompletionTestStart.h"
|
||||||
|
|
||||||
|
void foo(int x){
|
||||||
|
int y = AM
|
||||||
|
}
|
|
@ -43,6 +43,7 @@ public class AutomatedSuite extends TestSuite {
|
||||||
addTest(CompletionProposalsTest5.suite());
|
addTest(CompletionProposalsTest5.suite());
|
||||||
addTest(CompletionProposalsTest6.suite());
|
addTest(CompletionProposalsTest6.suite());
|
||||||
addTest(CompletionProposalsTest7.suite());
|
addTest(CompletionProposalsTest7.suite());
|
||||||
|
addTest(CompletionProposalsTest8.suite());
|
||||||
|
|
||||||
// Failed Tests
|
// Failed Tests
|
||||||
addTest(CompletionProposalsFailedTest1.suite());
|
addTest(CompletionProposalsFailedTest1.suite());
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class CompletionProposalsTest1 extends CompletionProposalsBaseTest{
|
||||||
"aNamespace",
|
"aNamespace",
|
||||||
"anEnumeration",
|
"anEnumeration",
|
||||||
"AStruct",
|
"AStruct",
|
||||||
"AMacro"
|
"AMacro(x)"
|
||||||
};
|
};
|
||||||
|
|
||||||
public CompletionProposalsTest1(String name) {
|
public CompletionProposalsTest1(String name) {
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class CompletionProposalsTest3 extends CompletionProposalsBaseTest{
|
||||||
"anotherClass",
|
"anotherClass",
|
||||||
"anEnumeration",
|
"anEnumeration",
|
||||||
"AStruct",
|
"AStruct",
|
||||||
"AMacro"
|
"AMacro(x)"
|
||||||
};
|
};
|
||||||
|
|
||||||
public CompletionProposalsTest3(String name) {
|
public CompletionProposalsTest3(String name) {
|
||||||
|
|
|
@ -0,0 +1,114 @@
|
||||||
|
/**********************************************************************
|
||||||
|
* Copyright (c) 2004 Rational Software Corporation and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v0.5
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v05.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Rational Software - Initial API and implementation
|
||||||
|
***********************************************************************/
|
||||||
|
package org.eclipse.cdt.ui.tests.text.contentassist;
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hamer
|
||||||
|
*
|
||||||
|
* Testing Function/Method scope, Macro lookups
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class CompletionProposalsTest8 extends CompletionProposalsBaseTest{
|
||||||
|
private final String fileName = "CompletionTestStart8.cpp";
|
||||||
|
private final String fileFullPath ="resources/contentassist/" + fileName;
|
||||||
|
private final String headerFileName = "CompletionTestStart.h";
|
||||||
|
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
|
||||||
|
private final String expectedScopeName = "ASTFunction";
|
||||||
|
private final String expectedContextName = "null";
|
||||||
|
private final CompletionKind expectedKind = CompletionKind.SINGLE_NAME_REFERENCE;
|
||||||
|
private final String expectedPrefix = "AM";
|
||||||
|
private final String[] expectedResults = {
|
||||||
|
"AMacro(x)"
|
||||||
|
};
|
||||||
|
|
||||||
|
public CompletionProposalsTest8(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suite() {
|
||||||
|
TestSuite suite= new TestSuite(CompletionProposalsTest8.class.getName());
|
||||||
|
suite.addTest(new CompletionProposalsTest8("testCompletionProposals"));
|
||||||
|
return suite;
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getCompletionPosition()
|
||||||
|
*/
|
||||||
|
protected int getCompletionPosition() {
|
||||||
|
return getBuffer().indexOf(" AM ") + 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedScope()
|
||||||
|
*/
|
||||||
|
protected String getExpectedScopeClassName() {
|
||||||
|
return expectedScopeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedContext()
|
||||||
|
*/
|
||||||
|
protected String getExpectedContextClassName() {
|
||||||
|
return expectedContextName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedKind()
|
||||||
|
*/
|
||||||
|
protected CompletionKind getExpectedKind() {
|
||||||
|
return expectedKind;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedPrefix()
|
||||||
|
*/
|
||||||
|
protected String getExpectedPrefix() {
|
||||||
|
return expectedPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedResultsValues()
|
||||||
|
*/
|
||||||
|
protected String[] getExpectedResultsValues() {
|
||||||
|
return expectedResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileName()
|
||||||
|
*/
|
||||||
|
protected String getFileName() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileFullPath()
|
||||||
|
*/
|
||||||
|
protected String getFileFullPath() {
|
||||||
|
return fileFullPath;
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileFullPath()
|
||||||
|
*/
|
||||||
|
protected String getHeaderFileFullPath() {
|
||||||
|
return headerFileFullPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileName()
|
||||||
|
*/
|
||||||
|
protected String getHeaderFileName() {
|
||||||
|
return headerFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,3 +1,6 @@
|
||||||
|
2004-01-19 Hoda Amer
|
||||||
|
Completed looking up macros with function style.
|
||||||
|
|
||||||
2004-01-16 Hoda Amer
|
2004-01-16 Hoda Amer
|
||||||
Added lookupMacros to the CompletionEngine
|
Added lookupMacros to the CompletionEngine
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
|
import org.eclipse.cdt.core.parser.IMacroDescriptor;
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
import org.eclipse.cdt.core.parser.IParser;
|
||||||
import org.eclipse.cdt.core.parser.IScanner;
|
import org.eclipse.cdt.core.parser.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
|
@ -439,7 +440,11 @@ public class CompletionEngine implements RelevanceConstants{
|
||||||
value = key;
|
value = key;
|
||||||
}
|
}
|
||||||
if( value.equalsIgnoreCase( prefix ) ) {
|
if( value.equalsIgnoreCase( prefix ) ) {
|
||||||
resultSet.add( key );
|
IMacroDescriptor macroD = (IMacroDescriptor)macroMap.get(key);
|
||||||
|
if (macroD.getMacroType() == IMacroDescriptor.MacroType.FUNCTION_LIKE )
|
||||||
|
resultSet.add( macroD.getCompleteSignature() );
|
||||||
|
else
|
||||||
|
resultSet.add( macroD.getName() );
|
||||||
}
|
}
|
||||||
else if( value.compareToIgnoreCase( prefix ) > 0 )
|
else if( value.compareToIgnoreCase( prefix ) > 0 )
|
||||||
break;
|
break;
|
||||||
|
@ -578,7 +583,10 @@ public class CompletionEngine implements RelevanceConstants{
|
||||||
kinds[4] = IASTNode.LookupKind.FUNCTIONS;
|
kinds[4] = IASTNode.LookupKind.FUNCTIONS;
|
||||||
kinds[5] = IASTNode.LookupKind.NAMESPACES;
|
kinds[5] = IASTNode.LookupKind.NAMESPACES;
|
||||||
kinds[6] = IASTNode.LookupKind.ENUMERATORS;
|
kinds[6] = IASTNode.LookupKind.ENUMERATORS;
|
||||||
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
|
String prefix = completionNode.getCompletionPrefix();
|
||||||
|
if(prefix.equals("("))
|
||||||
|
prefix = "";
|
||||||
|
ILookupResult result = lookup(searchNode, prefix, kinds, completionNode.getCompletionContext());
|
||||||
addToCompletions(result);
|
addToCompletions(result);
|
||||||
|
|
||||||
List macros = lookupMacros(completionNode.getCompletionPrefix());
|
List macros = lookupMacros(completionNode.getCompletionPrefix());
|
||||||
|
|
|
@ -225,20 +225,42 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
||||||
|
|
||||||
String replaceString = "";
|
String replaceString = "";
|
||||||
String displayString = "";
|
String displayString = "";
|
||||||
|
String arguments = "";
|
||||||
Image image = null;
|
Image image = null;
|
||||||
StringBuffer infoString = new StringBuffer();
|
StringBuffer infoString = new StringBuffer();
|
||||||
|
String prototype = "";
|
||||||
|
|
||||||
// fill the replace, display and info strings
|
// fill the replace, display and info strings
|
||||||
replaceString = name;
|
final String DEFINE ="#define ";
|
||||||
displayString = name;
|
if(name.startsWith(DEFINE)){
|
||||||
|
prototype = name.substring(DEFINE.length(), name.length());
|
||||||
|
}else {
|
||||||
|
prototype = name;
|
||||||
|
}
|
||||||
|
int leftbracket = prototype.indexOf('(');
|
||||||
|
int rightbracket = prototype.lastIndexOf(')');
|
||||||
|
if(( leftbracket == -1 ) && (rightbracket == -1)) {
|
||||||
|
replaceString = prototype;
|
||||||
|
displayString = prototype;
|
||||||
|
}else {
|
||||||
|
FunctionPrototypeSummary fproto = new FunctionPrototypeSummary(prototype);
|
||||||
|
if(fproto != null) {
|
||||||
|
replaceString = fproto.getName() + "()";
|
||||||
|
displayString = fproto.getPrototypeString(true, false);
|
||||||
|
infoString.append(displayString);
|
||||||
|
arguments = fproto.getArguments();
|
||||||
|
} else {
|
||||||
|
replaceString = prototype;
|
||||||
|
displayString = prototype;
|
||||||
|
}
|
||||||
|
}
|
||||||
// get the image
|
// get the image
|
||||||
ImageDescriptor imageDescriptor = CElementImageProvider.getMacroImageDescriptor();
|
ImageDescriptor imageDescriptor = CElementImageProvider.getMacroImageDescriptor();
|
||||||
image = registry.get( imageDescriptor );
|
image = registry.get( imageDescriptor );
|
||||||
|
|
||||||
// create proposal and add it to completions list
|
// create proposal and add it to completions list
|
||||||
ICompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
|
ICompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
|
||||||
null, image, completionStart, completionLength, relevance);
|
arguments, image, completionStart, completionLength, relevance);
|
||||||
completions.add(proposal);
|
completions.add(proposal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,8 +75,12 @@ public class FunctionPrototypeSummary implements IFunctionSummary.IFunctionProto
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrototypeString(boolean namefirst) {
|
public String getPrototypeString(boolean namefirst) {
|
||||||
|
return getPrototypeString(namefirst, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrototypeString(boolean namefirst, boolean appendReturnType) {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
if(!namefirst) {
|
if((!namefirst) && (appendReturnType)) {
|
||||||
buffer.append(getReturnType());
|
buffer.append(getReturnType());
|
||||||
buffer.append(" ");
|
buffer.append(" ");
|
||||||
}
|
}
|
||||||
|
@ -86,7 +90,7 @@ public class FunctionPrototypeSummary implements IFunctionSummary.IFunctionProto
|
||||||
buffer.append(getArguments());
|
buffer.append(getArguments());
|
||||||
}
|
}
|
||||||
buffer.append(")");
|
buffer.append(")");
|
||||||
if(namefirst) {
|
if((namefirst) && (appendReturnType) ) {
|
||||||
buffer.append(" ");
|
buffer.append(" ");
|
||||||
buffer.append(getReturnType());
|
buffer.append(getReturnType());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue