1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-26 02:15:31 +02:00

Bug 434446 - [code assist] struct not being recognised as a valid base

class

structs are now being shown as candidates for base classes

while I was at it I also fixed proposals for typedefs, template
parameters and template aliases.

Change-Id: I319b06a195eed88a12969207a21584dc2477219e
Signed-off-by: Michi <woskimi@yahoo.de>
Reviewed-on: https://git.eclipse.org/r/38379
Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
Michi 2014-12-16 21:01:12 +01:00 committed by Sergey Prigogin
parent 5ba7b39f01
commit c647a52118
5 changed files with 93 additions and 88 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2011 IBM Corporation and others.
* Copyright (c) 2004, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -9,6 +9,7 @@
* John Camelon (IBM) - Initial API and implementation
* Bryan Wilkinson (QNX)
* Markus Schorn (Wind River Systems)
* Michael Woski
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -19,10 +20,14 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICPPASTCompletionContext;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNameSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
@ -30,12 +35,10 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
* Base class specifier
*/
public class CPPASTBaseSpecifier extends ASTNode implements ICPPASTBaseSpecifier, ICPPASTCompletionContext {
private boolean isVirtual;
private int visibility;
private ICPPASTNameSpecifier nameSpecifier;
private boolean fIsPackExpansion;
public CPPASTBaseSpecifier() {
}
@ -121,9 +124,9 @@ public class CPPASTBaseSpecifier extends ASTNode implements ICPPASTBaseSpecifier
public boolean accept(ASTVisitor action) {
if (action.shouldVisitBaseSpecifiers) {
switch (action.visit(this)) {
case ASTVisitor.PROCESS_ABORT : return false;
case ASTVisitor.PROCESS_SKIP : return true;
default : break;
case ASTVisitor.PROCESS_ABORT: return false;
case ASTVisitor.PROCESS_SKIP: return true;
default: break;
}
}
@ -157,12 +160,23 @@ public class CPPASTBaseSpecifier extends ASTNode implements ICPPASTBaseSpecifier
}
for (IBinding binding : bindings) {
if (binding instanceof ICPPClassType) {
ICPPClassType base = (ICPPClassType) binding;
int key = base.getKey();
if (key == ICPPClassType.k_class &&
(classType == null || !base.isSameType(classType))) {
filtered.add(base);
if (binding instanceof IType) {
IType type = (IType) binding;
while (type instanceof ITypedef || type instanceof ICPPAliasTemplate) {
type = type instanceof ITypedef ?
((ITypedef) type).getType() : ((ICPPAliasTemplate) type).getType();
}
if (type instanceof ICPPClassType) {
int key = ((ICPPClassType) type).getKey();
if ((key == ICPPClassType.k_class || key == ICPPClassType.k_struct
|| type instanceof ICPPDeferredClassInstance || type instanceof ICPPUnknownMemberClass)
&& (classType == null || !type.isSameType(classType))) {
filtered.add(binding);
}
} else if (type instanceof ICPPTemplateTypeParameter) {
filtered.add(binding);
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2013 Google, Inc and others.
* Copyright (c) 2009, 2014 Google, Inc and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
@ -76,7 +77,8 @@ public class AccessContext {
*/
private boolean isUnqualifiedLookup;
private ICPPClassType namingClass; // depends on the binding for which we check the access
private ICPPClassType firstCandidateForNamingClass; // the first candidate is independent of the binding for which we do the access-check
// The first candidate is independent of the binding for which we do the access-check.
private ICPPClassType firstCandidateForNamingClass;
private DOMException initializationException;
public AccessContext(IASTName name) {
@ -89,6 +91,9 @@ public class AccessContext {
* @return <code>true</code> if the binding is accessible.
*/
public boolean isAccessible(IBinding binding) {
if (binding instanceof ICPPTemplateParameter)
return true;
int bindingVisibility;
if (binding instanceof ICPPMember) {
bindingVisibility = ((ICPPMember) binding).getVisibility();
@ -97,7 +102,8 @@ public class AccessContext {
binding = ((ICPPSpecialization) binding).getSpecializedBinding();
}
if (binding instanceof ICPPClassTemplatePartialSpecialization) {
// A class template partial specialization inherits the visibility of its primary class template.
// A class template partial specialization inherits the visibility of its primary
// class template.
binding = ((ICPPClassTemplatePartialSpecialization) binding).getPrimaryClassTemplate();
}
if (binding instanceof ICPPAliasTemplateInstance) {

View file

@ -1,13 +1,13 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
* Bryan Wilkinson (QNX)
* IBM Rational Software - Initial API and implementation
* Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
@ -17,26 +17,26 @@ import junit.framework.TestSuite;
/**
* @author hamer
*
* Testing Class_Reference, with No prefix
* Bug#50621 :Wrong completion kind in a class declaration
*
* Testing class reference, with no prefix
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=50621
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=169860
*/
public class CompletionTest_ClassReference_NoPrefix extends CompletionProposalsBaseTest{
private final String fileName = "CompletionTestStart21.h";
private final String fileFullPath ="resources/contentassist/" + fileName;
private final String headerFileName = "CompletionTestStart.h";
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedPrefix = "";
private final String expectedPrefix = "";
private final String[] expectedResults = {
"aClass",
"anotherClass",
"xOtherClass"
"xOtherClass",
"AStruct",
"XStruct"
};
public CompletionTest_ClassReference_NoPrefix(String name) {
super(name);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=169860
}
public static Test suite() {
@ -45,59 +45,38 @@ public class CompletionTest_ClassReference_NoPrefix extends CompletionProposals
return suite;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getCompletionPosition()
*/
@Override
protected int getCompletionPosition() {
return getBuffer().indexOf(" ") + 2;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedPrefix()
*/
@Override
protected String getExpectedPrefix() {
return expectedPrefix;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedResultsValues()
*/
@Override
protected String[] getExpectedResultsValues() {
return expectedResults;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileName()
*/
@Override
protected String getFileName() {
return fileName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileFullPath()
*/
@Override
protected String getFileFullPath() {
return fileFullPath;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileFullPath()
*/
@Override
protected String getHeaderFileFullPath() {
return headerFileFullPath;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileName()
*/
@Override
protected String getHeaderFileName() {
return headerFileName;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -17,86 +17,64 @@ import junit.framework.TestSuite;
/**
* @author hamer
*
* Testing Class_Reference, with prefix
* Bug#50621 :Wrong completion kind in a class declaration
*
* Testing class reference, with prefix
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=50621
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=169860
*/
public class CompletionTest_ClassReference_Prefix extends CompletionProposalsBaseTest{
private final String fileName = "CompletionTestStart20.h"; //$NON-NLS-1$
private final String fileFullPath ="resources/contentassist/" + fileName; //$NON-NLS-1$
private final String headerFileName = "CompletionTestStart.h"; //$NON-NLS-1$
private final String headerFileFullPath ="resources/contentassist/" + headerFileName; //$NON-NLS-1$
private final String expectedPrefix = "a"; //$NON-NLS-1$
private final String fileName = "CompletionTestStart20.h";
private final String fileFullPath ="resources/contentassist/" + fileName;
private final String headerFileName = "CompletionTestStart.h";
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedPrefix = "a";
private final String[] expectedResults = {
"aClass", //$NON-NLS-1$
"anotherClass" //$NON-NLS-1$
"aClass",
"anotherClass",
"AStruct"
};
public CompletionTest_ClassReference_Prefix(String name) {
super(name);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=169860
}
public static Test suite() {
TestSuite suite= new TestSuite(CompletionTest_ClassReference_Prefix.class.getName());
suite.addTest(new CompletionTest_ClassReference_Prefix("testCompletionProposals")); //$NON-NLS-1$
suite.addTest(new CompletionTest_ClassReference_Prefix("testCompletionProposals"));
return suite;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getCompletionPosition()
*/
@Override
protected int getCompletionPosition() {
return getBuffer().indexOf(" a ") + 2; //$NON-NLS-1$
return getBuffer().indexOf(" a ") + 2;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedPrefix()
*/
@Override
protected String getExpectedPrefix() {
return expectedPrefix;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedResultsValues()
*/
@Override
protected String[] getExpectedResultsValues() {
return expectedResults;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileName()
*/
@Override
protected String getFileName() {
return fileName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileFullPath()
*/
@Override
protected String getFileFullPath() {
return fileFullPath;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileFullPath()
*/
@Override
protected String getHeaderFileFullPath() {
return headerFileFullPath;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileName()
*/
@Override
protected String getHeaderFileName() {
return headerFileName;
}
}

View file

@ -14,6 +14,7 @@
* Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion)
* Nathan Ridge
* Thomas Corbat (IFS)
* Michael Woski
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
@ -194,6 +195,12 @@ public class CompletionTests extends AbstractContentAssistTest {
// template<>
// struct Specialization<int, int> {
// };
//
// template<typename T1, typename T2>
// using AliasForSpecialization = Specialization<T1, T2>;
//
// template<typename T1, typename T2>
// using AliasForTemplateAlias = AliasForSpecialization<T1, T2>;
public CompletionTests(String name) {
super(name, true);
@ -694,15 +701,36 @@ public class CompletionTests extends AbstractContentAssistTest {
assertCompletionResults(fCursorOffset, expected, ID);
}
//void f(){T1::~/*cursor*/
// void f(){T1::~/*cursor*/
public void testTypedefSyntheticMembers_415495() throws Exception {
final String[] expected= {};
final String[] expected = {};
assertCompletionResults(fCursorOffset, expected, REPLACEMENT);
}
//void f(){A1::~/*cursor*/
// void f(){A1::~/*cursor*/
public void testAliasSyntheticMembers_415495() throws Exception {
final String[] expected= {};
final String[] expected = {};
assertCompletionResults(fCursorOffset, expected, REPLACEMENT);
}
// class BaseTest : Spec/*cursor*/
public void testBaseClassIsStruct_434446() throws Exception {
final String[] expected = { "Specialization<>" };
assertCompletionResults(fCursorOffset, expected, REPLACEMENT);
}
// class BaseTest : Alias/*cursor*/
public void testBaseClassIsTemplateAlias_434446() throws Exception {
// TODO Bug 455797, proposals are currently not presented as templates.
final String[] expected = { "AliasForSpecialization",
"AliasForTemplateAlias" };
assertCompletionResults(fCursorOffset, expected, ID);
}
// template<typename TP_Param>
// class BaseTest : TP/*cursor*/
public void testBaseClassIsTemplateParameter() throws Exception {
final String[] expected = { "TP_Param" };
assertCompletionResults(fCursorOffset, expected, REPLACEMENT);
}