From ff970aefd8e996260f3adb9bea2ce79f64473dc3 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Mon, 18 Jun 2007 13:00:51 +0000 Subject: [PATCH] Fix + Testcase for 192787, proposal shows anonymous type of a parameter. --- .../internal/index/tests/IndexBugsTests.java | 2 +- .../eclipse/cdt/core/dom/ast/ASTTypeUtil.java | 47 +++++++++++++------ .../text/contentassist2/CompletionTests.java | 17 +++++++ .../DOMCompletionProposalComputer.java | 8 ++-- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java index 85c095bda65..e618ec1b417 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java @@ -695,9 +695,9 @@ public class IndexBugsTests extends BaseTestCase { ICProject p2 = CProjectHelper.createCCProject("__bugsTest_2_", "bin", IPDOMManager.ID_FAST_INDEXER); try { - IFile f3= TestSourceReader.createFile(p2.getProject(), "src.cpp", contents[2].toString()); IFile f1= TestSourceReader.createFile(fCProject.getProject(), "common.h", contents[0].toString()); IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1].toString()); + IFile f3= TestSourceReader.createFile(p2.getProject(), "src.cpp", contents[2].toString()); waitForIndexer(); IIndex index= CCorePlugin.getIndexManager().getIndex(new ICProject[]{fCProject, p2}); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java index 3988b61eb9c..22bae4b30bf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java @@ -266,38 +266,57 @@ public class ASTTypeUtil { } catch (DOMException e) {} } + else if (type instanceof ITypedef) { + result.append(((ITypedef)type).getNameCharArray()); + } return result.toString(); } /** * 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 * @return the type represntation of the IType */ 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(); IType[] types = new IType[DEAULT_ITYPE_SIZE]; // push all of the types onto the stack - while(type != null && type instanceof ITypeContainer) { - types = (IType[]) ArrayUtil.append( IType.class, types, type ); - - try { - type = ((ITypeContainer)type).getType(); - } catch (DOMException e) {} - } - - if (type != null && !(type instanceof ITypeContainer)) { - types = (IType[]) ArrayUtil.append( IType.class, types, type ); + while(type != null) { + final boolean isTypedef= type instanceof ITypedef; + if (!resolveTypedefs || !isTypedef) { + types = (IType[]) ArrayUtil.append( IType.class, types, type ); + } + if (!resolveTypedefs && isTypedef) { + type= null; // stop here + } + else if (type instanceof ITypeContainer) { + 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 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) { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java index facbc79d00f..338b3199402 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java @@ -8,6 +8,7 @@ * Contributors: * Anton Leherbauer (Wind River Systems) - initial API and implementation * Bryan Wilkinson (QNX) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.ui.tests.text.contentassist2; @@ -767,4 +768,20 @@ public class CompletionTests extends AbstractContentAssistTest { }; 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); + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java index ca99f54818b..3dc5b254f39 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java @@ -277,8 +277,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer idargs.append(','); } - dispargs.append(ASTTypeUtil.getType(paramType)); - idargs.append(ASTTypeUtil.getType(paramType)); + dispargs.append(ASTTypeUtil.getType(paramType, false)); + idargs.append(ASTTypeUtil.getType(paramType, false)); String paramName = params[i].getName(); if (paramName != null && paramName.length() > 0) { dispargs.append(' '); @@ -302,7 +302,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer if (functionType != null) { IType returnType = functionType.getReturnType(); if (returnType != null) - returnTypeStr = ASTTypeUtil.getType(returnType); + returnTypeStr = ASTTypeUtil.getType(returnType, false); } } catch (DOMException e) { } @@ -349,7 +349,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer try { IType varType = variable.getType(); if (varType != null) - returnTypeStr = ASTTypeUtil.getType(varType); + returnTypeStr = ASTTypeUtil.getType(varType, false); } catch (DOMException e) { }