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 ){
|
||||
ISymbolASTExtension extension = symbol.getASTExtension();
|
||||
if(extension == null)
|
||||
return true;
|
||||
IASTNode node = extension.getPrimaryDeclaration();
|
||||
if(node == null)
|
||||
return true;
|
||||
|
||||
if( node instanceof IASTMember ){
|
||||
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
|
||||
Added More success 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(CompletionProposalsTest6.suite());
|
||||
addTest(CompletionProposalsTest7.suite());
|
||||
addTest(CompletionProposalsTest8.suite());
|
||||
|
||||
// Failed Tests
|
||||
addTest(CompletionProposalsFailedTest1.suite());
|
||||
|
|
|
@ -41,7 +41,7 @@ public class CompletionProposalsTest1 extends CompletionProposalsBaseTest{
|
|||
"aNamespace",
|
||||
"anEnumeration",
|
||||
"AStruct",
|
||||
"AMacro"
|
||||
"AMacro(x)"
|
||||
};
|
||||
|
||||
public CompletionProposalsTest1(String name) {
|
||||
|
|
|
@ -34,7 +34,7 @@ public class CompletionProposalsTest3 extends CompletionProposalsBaseTest{
|
|||
"anotherClass",
|
||||
"anEnumeration",
|
||||
"AStruct",
|
||||
"AMacro"
|
||||
"AMacro(x)"
|
||||
};
|
||||
|
||||
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
|
||||
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.ICElement;
|
||||
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.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
|
@ -439,7 +440,11 @@ public class CompletionEngine implements RelevanceConstants{
|
|||
value = key;
|
||||
}
|
||||
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 )
|
||||
break;
|
||||
|
@ -577,8 +582,11 @@ public class CompletionEngine implements RelevanceConstants{
|
|||
kinds[3] = IASTNode.LookupKind.METHODS;
|
||||
kinds[4] = IASTNode.LookupKind.FUNCTIONS;
|
||||
kinds[5] = IASTNode.LookupKind.NAMESPACES;
|
||||
kinds[6] = IASTNode.LookupKind.ENUMERATORS;
|
||||
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
|
||||
kinds[6] = IASTNode.LookupKind.ENUMERATORS;
|
||||
String prefix = completionNode.getCompletionPrefix();
|
||||
if(prefix.equals("("))
|
||||
prefix = "";
|
||||
ILookupResult result = lookup(searchNode, prefix, kinds, completionNode.getCompletionContext());
|
||||
addToCompletions(result);
|
||||
|
||||
List macros = lookupMacros(completionNode.getCompletionPrefix());
|
||||
|
|
|
@ -225,20 +225,42 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
|
||||
String replaceString = "";
|
||||
String displayString = "";
|
||||
String arguments = "";
|
||||
Image image = null;
|
||||
StringBuffer infoString = new StringBuffer();
|
||||
|
||||
String prototype = "";
|
||||
|
||||
// fill the replace, display and info strings
|
||||
replaceString = name;
|
||||
displayString = name;
|
||||
|
||||
final String DEFINE ="#define ";
|
||||
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
|
||||
ImageDescriptor imageDescriptor = CElementImageProvider.getMacroImageDescriptor();
|
||||
image = registry.get( imageDescriptor );
|
||||
|
||||
// create proposal and add it to completions list
|
||||
ICompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
|
||||
null, image, completionStart, completionLength, relevance);
|
||||
arguments, image, completionStart, completionLength, relevance);
|
||||
completions.add(proposal);
|
||||
}
|
||||
|
||||
|
|
|
@ -75,8 +75,12 @@ public class FunctionPrototypeSummary implements IFunctionSummary.IFunctionProto
|
|||
}
|
||||
|
||||
public String getPrototypeString(boolean namefirst) {
|
||||
return getPrototypeString(namefirst, true);
|
||||
}
|
||||
|
||||
public String getPrototypeString(boolean namefirst, boolean appendReturnType) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
if(!namefirst) {
|
||||
if((!namefirst) && (appendReturnType)) {
|
||||
buffer.append(getReturnType());
|
||||
buffer.append(" ");
|
||||
}
|
||||
|
@ -86,7 +90,7 @@ public class FunctionPrototypeSummary implements IFunctionSummary.IFunctionProto
|
|||
buffer.append(getArguments());
|
||||
}
|
||||
buffer.append(")");
|
||||
if(namefirst) {
|
||||
if((namefirst) && (appendReturnType) ) {
|
||||
buffer.append(" ");
|
||||
buffer.append(getReturnType());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue