mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Bug 307818: Show target type of typedef specializations in content assist.
This commit is contained in:
parent
0908dbf0cd
commit
e45f335e8b
2 changed files with 58 additions and 40 deletions
|
@ -28,6 +28,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||||
|
@ -460,47 +461,46 @@ public class ASTTypeUtil {
|
||||||
IQualifierType cvq= null;
|
IQualifierType cvq= null;
|
||||||
ICPPReferenceType ref= null;
|
ICPPReferenceType ref= null;
|
||||||
while (type != null && ++i < 100) {
|
while (type != null && ++i < 100) {
|
||||||
if (!normalize) {
|
if (type instanceof ITypedef) {
|
||||||
types = (IType[]) ArrayUtil.append(IType.class, types, type);
|
if (normalize || type instanceof ICPPSpecialization) {
|
||||||
if (type instanceof ITypedef) {
|
// Skip the typedef and proceed with its target type.
|
||||||
type= null; // stop here
|
} else {
|
||||||
|
// Use the typedef and stop
|
||||||
|
types = (IType[]) ArrayUtil.append(IType.class, types, type);
|
||||||
|
type= null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (type instanceof ITypedef) {
|
if (type instanceof ICPPReferenceType) {
|
||||||
// skip it
|
// reference types ignore cv-qualifiers
|
||||||
} else {
|
cvq=null;
|
||||||
if (type instanceof ICPPReferenceType) {
|
// lvalue references win over rvalue references
|
||||||
// reference types ignore cv-qualifiers
|
if (ref == null || ref.isRValueReference()) {
|
||||||
cvq=null;
|
// delay reference to see if there are more
|
||||||
// lvalue references win over rvalue references
|
ref= (ICPPReferenceType) type;
|
||||||
if (ref == null || ref.isRValueReference()) {
|
|
||||||
// delay reference to see if there are more
|
|
||||||
ref= (ICPPReferenceType) type;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (cvq != null) {
|
|
||||||
// merge cv qualifiers
|
|
||||||
if (type instanceof IQualifierType || type instanceof IPointerType) {
|
|
||||||
type= SemanticUtil.addQualifiers(type, cvq.isConst(), cvq.isVolatile());
|
|
||||||
cvq= null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (type instanceof IQualifierType) {
|
|
||||||
// delay cv qualifier to merge it with others
|
|
||||||
cvq= (IQualifierType) type;
|
|
||||||
} else {
|
|
||||||
// no reference, no cv qualifier: output reference and cv-qualifier
|
|
||||||
if (ref != null) {
|
|
||||||
types = (IType[]) ArrayUtil.append(IType.class, types, ref);
|
|
||||||
ref= null;
|
|
||||||
}
|
|
||||||
if (cvq != null) {
|
|
||||||
types = (IType[]) ArrayUtil.append(IType.class, types, cvq);
|
|
||||||
cvq= null;
|
|
||||||
}
|
|
||||||
types = (IType[]) ArrayUtil.append(IType.class, types, type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (cvq != null) {
|
||||||
|
// merge cv qualifiers
|
||||||
|
if (type instanceof IQualifierType || type instanceof IPointerType) {
|
||||||
|
type= SemanticUtil.addQualifiers(type, cvq.isConst(), cvq.isVolatile());
|
||||||
|
cvq= null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (type instanceof IQualifierType) {
|
||||||
|
// delay cv qualifier to merge it with others
|
||||||
|
cvq= (IQualifierType) type;
|
||||||
|
} else {
|
||||||
|
// no reference, no cv qualifier: output reference and cv-qualifier
|
||||||
|
if (ref != null) {
|
||||||
|
types = (IType[]) ArrayUtil.append(IType.class, types, ref);
|
||||||
|
ref= null;
|
||||||
|
}
|
||||||
|
if (cvq != null) {
|
||||||
|
types = (IType[]) ArrayUtil.append(IType.class, types, cvq);
|
||||||
|
cvq= null;
|
||||||
|
}
|
||||||
|
types = (IType[]) ArrayUtil.append(IType.class, types, type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type instanceof ITypeContainer) {
|
if (type instanceof ITypeContainer) {
|
||||||
|
|
|
@ -221,7 +221,11 @@ public class CompletionTests extends AbstractContentAssistTest {
|
||||||
protected void assertCompletionResults(String[] expected) throws Exception {
|
protected void assertCompletionResults(String[] expected) throws Exception {
|
||||||
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
|
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void assertParameterHint(String[] expected) throws Exception {
|
||||||
|
assertContentAssistResults(fCursorOffset, expected, false, AbstractContentAssistTest.COMPARE_DISP_STRINGS);
|
||||||
|
}
|
||||||
|
|
||||||
//void gfunc() {C1 v; v.m/*cursor*/
|
//void gfunc() {C1 v; v.m/*cursor*/
|
||||||
public void testLocalVariable() throws Exception {
|
public void testLocalVariable() throws Exception {
|
||||||
final String[] expected= {
|
final String[] expected= {
|
||||||
|
@ -1286,8 +1290,22 @@ public class CompletionTests extends AbstractContentAssistTest {
|
||||||
//public:
|
//public:
|
||||||
// InitializerListTest() : h/*cursor*/
|
// InitializerListTest() : h/*cursor*/
|
||||||
//};
|
//};
|
||||||
public void testCunstructorInitializerList_BaseClassInput_Bug266586() throws Exception {
|
public void testConstructorInitializerList_BaseClassInput_Bug266586() throws Exception {
|
||||||
final String[] expected= { "Helper(void)", "Helper(const Helper &)" };
|
final String[] expected= { "Helper(void)", "Helper(const Helper &)" };
|
||||||
assertCompletionResults(fCursorOffset, expected, COMPARE_ID_STRINGS);
|
assertCompletionResults(fCursorOffset, expected, COMPARE_ID_STRINGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// template <typename T> struct vector {
|
||||||
|
// typedef T value_type;
|
||||||
|
// void push_back(const value_type& value) {}
|
||||||
|
// };
|
||||||
|
// typedef int MyType;
|
||||||
|
// void test() {
|
||||||
|
// vector<MyType> v;
|
||||||
|
// v.push_back(/*cursor*/);
|
||||||
|
// }
|
||||||
|
public void testTypedefSpecialization_Bug307818() throws Exception {
|
||||||
|
final String[] expected= { "push_back(const int & value) : void" };
|
||||||
|
assertParameterHint(expected);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue