mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix + Testcase for 192787, proposal shows anonymous type of a parameter.
This commit is contained in:
parent
f5841dcac0
commit
ff970aefd8
4 changed files with 55 additions and 19 deletions
|
@ -695,9 +695,9 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
|
|
||||||
ICProject p2 = CProjectHelper.createCCProject("__bugsTest_2_", "bin", IPDOMManager.ID_FAST_INDEXER);
|
ICProject p2 = CProjectHelper.createCCProject("__bugsTest_2_", "bin", IPDOMManager.ID_FAST_INDEXER);
|
||||||
try {
|
try {
|
||||||
IFile f3= TestSourceReader.createFile(p2.getProject(), "src.cpp", contents[2].toString());
|
|
||||||
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "common.h", contents[0].toString());
|
IFile f1= TestSourceReader.createFile(fCProject.getProject(), "common.h", contents[0].toString());
|
||||||
IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1].toString());
|
IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1].toString());
|
||||||
|
IFile f3= TestSourceReader.createFile(p2.getProject(), "src.cpp", contents[2].toString());
|
||||||
waitForIndexer();
|
waitForIndexer();
|
||||||
|
|
||||||
IIndex index= CCorePlugin.getIndexManager().getIndex(new ICProject[]{fCProject, p2});
|
IIndex index= CCorePlugin.getIndexManager().getIndex(new ICProject[]{fCProject, p2});
|
||||||
|
|
|
@ -266,38 +266,57 @@ public class ASTTypeUtil {
|
||||||
} catch (DOMException e) {}
|
} catch (DOMException e) {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else if (type instanceof ITypedef) {
|
||||||
|
result.append(((ITypedef)type).getNameCharArray());
|
||||||
|
}
|
||||||
|
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the type represntation of the IType as a String. This function uses the IType interfaces to build the
|
* Returns the type represntation of the IType as a String. This function uses the IType interfaces to build the
|
||||||
* String representation of the IType.
|
* String representation of the IType. Resolves typedefs.
|
||||||
* @param type
|
* @param type
|
||||||
* @return the type represntation of the IType
|
* @return the type represntation of the IType
|
||||||
*/
|
*/
|
||||||
public static String getType(IType type) {
|
public static String getType(IType type) {
|
||||||
|
return getType(type, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the type represntation of the IType as a String. This function uses the IType interfaces to build the
|
||||||
|
* String representation of the IType.
|
||||||
|
* @param type
|
||||||
|
* @param resolveTypedefs whether or not typedefs shall be resolved to their real types
|
||||||
|
* @return the type represntation of the IType
|
||||||
|
*/
|
||||||
|
public static String getType(IType type, boolean resolveTypedefs) {
|
||||||
StringBuffer result = new StringBuffer();
|
StringBuffer result = new StringBuffer();
|
||||||
IType[] types = new IType[DEAULT_ITYPE_SIZE];
|
IType[] types = new IType[DEAULT_ITYPE_SIZE];
|
||||||
|
|
||||||
// push all of the types onto the stack
|
// push all of the types onto the stack
|
||||||
while(type != null && type instanceof ITypeContainer) {
|
while(type != null) {
|
||||||
types = (IType[]) ArrayUtil.append( IType.class, types, type );
|
final boolean isTypedef= type instanceof ITypedef;
|
||||||
|
if (!resolveTypedefs || !isTypedef) {
|
||||||
try {
|
types = (IType[]) ArrayUtil.append( IType.class, types, type );
|
||||||
type = ((ITypeContainer)type).getType();
|
}
|
||||||
} catch (DOMException e) {}
|
if (!resolveTypedefs && isTypedef) {
|
||||||
}
|
type= null; // stop here
|
||||||
|
}
|
||||||
if (type != null && !(type instanceof ITypeContainer)) {
|
else if (type instanceof ITypeContainer) {
|
||||||
types = (IType[]) ArrayUtil.append( IType.class, types, type );
|
try {
|
||||||
|
type = ((ITypeContainer)type).getType();
|
||||||
|
} catch (DOMException e) {
|
||||||
|
type= null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
type= null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pop all of the types off of the stack, and build the string representation while doing so
|
// pop all of the types off of the stack, and build the string representation while doing so
|
||||||
for(int j=types.length-1; j>=0; j--) {
|
for(int j=types.length-1; j>=0; j--) {
|
||||||
if (types[j] instanceof ITypedef)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (types[j] != null && result.length() > 0) result.append(SPACE); // only add a space if this is not the first type being added
|
if (types[j] != null && result.length() > 0) result.append(SPACE); // only add a space if this is not the first type being added
|
||||||
|
|
||||||
if (types[j] != null) {
|
if (types[j] != null) {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||||
* Bryan Wilkinson (QNX)
|
* Bryan Wilkinson (QNX)
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.ui.tests.text.contentassist2;
|
package org.eclipse.cdt.ui.tests.text.contentassist2;
|
||||||
|
|
||||||
|
@ -767,4 +768,20 @@ public class CompletionTests extends AbstractContentAssistTest {
|
||||||
};
|
};
|
||||||
assertMinimumCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
|
assertMinimumCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// typedef struct {
|
||||||
|
// int sx;
|
||||||
|
// } my_struct;
|
||||||
|
//
|
||||||
|
// void func(my_struct s);
|
||||||
|
//
|
||||||
|
// void test() {
|
||||||
|
// fun/*cursor*/
|
||||||
|
public void testFunctionWithTypedefToAnonymousType_bug192787() throws Exception {
|
||||||
|
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=192787
|
||||||
|
final String[] expected= {
|
||||||
|
"func(my_struct s) void"
|
||||||
|
};
|
||||||
|
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_DISP_STRINGS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,8 +277,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
idargs.append(',');
|
idargs.append(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
dispargs.append(ASTTypeUtil.getType(paramType));
|
dispargs.append(ASTTypeUtil.getType(paramType, false));
|
||||||
idargs.append(ASTTypeUtil.getType(paramType));
|
idargs.append(ASTTypeUtil.getType(paramType, false));
|
||||||
String paramName = params[i].getName();
|
String paramName = params[i].getName();
|
||||||
if (paramName != null && paramName.length() > 0) {
|
if (paramName != null && paramName.length() > 0) {
|
||||||
dispargs.append(' ');
|
dispargs.append(' ');
|
||||||
|
@ -302,7 +302,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
if (functionType != null) {
|
if (functionType != null) {
|
||||||
IType returnType = functionType.getReturnType();
|
IType returnType = functionType.getReturnType();
|
||||||
if (returnType != null)
|
if (returnType != null)
|
||||||
returnTypeStr = ASTTypeUtil.getType(returnType);
|
returnTypeStr = ASTTypeUtil.getType(returnType, false);
|
||||||
}
|
}
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
}
|
}
|
||||||
|
@ -349,7 +349,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
try {
|
try {
|
||||||
IType varType = variable.getType();
|
IType varType = variable.getType();
|
||||||
if (varType != null)
|
if (varType != null)
|
||||||
returnTypeStr = ASTTypeUtil.getType(varType);
|
returnTypeStr = ASTTypeUtil.getType(varType, false);
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue