mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Fix for Bug 173342 - [Content Assist] Extra parameter hints due to search with prefix (patch by Bryan Wilkinson)
This commit is contained in:
parent
dda51e46b3
commit
841997be25
28 changed files with 429 additions and 193 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2005 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2007 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
|
||||
|
@ -3811,7 +3811,7 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
tu.accept(col);
|
||||
|
||||
IASTName f = col.getName(5);
|
||||
f.resolvePrefix();
|
||||
f.getCompletionContext().findBindings(f, true);
|
||||
}
|
||||
|
||||
public void testBug90654_1() throws Exception {
|
||||
|
@ -3971,7 +3971,8 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
IVariable a1 = (IVariable) col.getName(1).resolveBinding();
|
||||
IVariable a2 = (IVariable) col.getName(2).resolveBinding();
|
||||
|
||||
IBinding[] bs = col.getName(3).resolvePrefix();
|
||||
IBinding[] bs = col.getName(3).getCompletionContext().findBindings(
|
||||
col.getName(3), true);
|
||||
assertEquals(bs.length, 2);
|
||||
assertSame(bs[0], a1);
|
||||
assertSame(bs[1], a2);
|
||||
|
|
|
@ -23,7 +23,8 @@ public class BasicCompletionTest extends CompletionTestBase {
|
|||
private void testVar(ASTCompletionNode node) throws Exception {
|
||||
IASTName[] names = node.getNames();
|
||||
assertEquals(1, names.length);
|
||||
IBinding[] bindings = names[0].resolvePrefix();
|
||||
IBinding[] bindings = names[0].getCompletionContext().findBindings(
|
||||
names[0], true);
|
||||
assertEquals(1, bindings.length);
|
||||
IVariable var = (IVariable)bindings[0];
|
||||
assertEquals("blah", var.getName());
|
||||
|
@ -48,7 +49,8 @@ public class BasicCompletionTest extends CompletionTestBase {
|
|||
// There are three names, one as an expression, one that isn't connected, one as a declaration
|
||||
assertEquals(3, names.length);
|
||||
// The expression points to our functions
|
||||
IBinding[] bindings = names[0].resolvePrefix();
|
||||
IBinding[] bindings = names[0].getCompletionContext().findBindings(
|
||||
names[0], true);
|
||||
// There should be two since they both start with fu
|
||||
assertEquals(2, bindings.length);
|
||||
assertEquals("func", ((IFunction)bindings[0]).getName());
|
||||
|
@ -64,7 +66,8 @@ public class BasicCompletionTest extends CompletionTestBase {
|
|||
// There are two names, one as an expression, one as a declaration
|
||||
assertEquals(2, names.length);
|
||||
// The expression points to our functions
|
||||
bindings = sortBindings(names[0].resolvePrefix());
|
||||
bindings = sortBindings(names[0].getCompletionContext().findBindings(
|
||||
names[0], true));
|
||||
// There should be two since they both start with fu
|
||||
assertEquals(2, bindings.length);
|
||||
assertEquals("func", ((IFunction)bindings[0]).getName());
|
||||
|
@ -83,7 +86,8 @@ public class BasicCompletionTest extends CompletionTestBase {
|
|||
IASTName[] names = node.getNames();
|
||||
assertEquals(2, names.length);
|
||||
assertNull(names[0].getTranslationUnit());
|
||||
IBinding[] bindings = names[1].resolvePrefix();
|
||||
IBinding[] bindings = names[1].getCompletionContext().findBindings(
|
||||
names[1], true);
|
||||
assertEquals(1, bindings.length);
|
||||
assertEquals("blah", ((ITypedef)bindings[0]).getName());
|
||||
|
||||
|
@ -91,7 +95,7 @@ public class BasicCompletionTest extends CompletionTestBase {
|
|||
node = getGCCCompletionNode(code.toString());
|
||||
names = node.getNames();
|
||||
assertEquals(1, names.length);
|
||||
bindings = names[0].resolvePrefix();
|
||||
bindings = names[0].getCompletionContext().findBindings(names[0], true);
|
||||
assertEquals(1, bindings.length);
|
||||
assertEquals("blah", ((ITypedef)bindings[0]).getName());
|
||||
}
|
||||
|
|
|
@ -9,14 +9,12 @@
|
|||
* QNX - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
package org.eclipse.cdt.core.dom.ast;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
|
||||
/**
|
||||
* Interface for a code completion's context. Used for context-sensitive
|
||||
* finding of bindings with a certain prefix.
|
||||
* finding of bindings with a certain name or prefix.
|
||||
*
|
||||
* <p>
|
||||
* This interface is not intended to be implemented by clients.
|
||||
|
@ -34,11 +32,11 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
|
|||
public interface IASTCompletionContext {
|
||||
|
||||
/**
|
||||
* Returns bindings that start with the given prefix, only considering those
|
||||
* that are valid for this context.
|
||||
* Returns bindings that start with the given name or prefix, only
|
||||
* considering those that are valid for this context.
|
||||
*
|
||||
* @param n the name containing a prefix
|
||||
* @return valid bindings in this context for the given prefix
|
||||
*/
|
||||
IBinding[] resolvePrefix(IASTName n);
|
||||
IBinding[] findBindings(IASTName n, boolean isPrefix);
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2007 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
|
||||
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Bryan Wilkinson (QNX)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast;
|
||||
|
||||
|
@ -51,12 +52,11 @@ public interface IASTName extends IASTNode, IName {
|
|||
public IBinding resolveBinding();
|
||||
|
||||
/**
|
||||
* Return a list of bindings in the scope of the name that have the name as
|
||||
* a prefix.
|
||||
* Return the completion context for this name.
|
||||
*
|
||||
* @return <code>IBinding []</code> bindings that start with this name
|
||||
* @return <code>IASTCompletionContext</code> the context for completion
|
||||
*/
|
||||
public IBinding[] resolvePrefix();
|
||||
public IASTCompletionContext getCompletionContext();
|
||||
|
||||
/**
|
||||
* Determines the current linkage in which the name has to be resolved.
|
||||
|
|
|
@ -17,6 +17,7 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
|
@ -27,7 +28,6 @@ import org.eclipse.cdt.core.dom.ast.IField;
|
|||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTCompletionContext;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
|
||||
|
||||
/**
|
||||
|
@ -104,7 +104,7 @@ public class CASTFieldReference extends CASTNode implements IASTFieldReference,
|
|||
return CVisitor.getExpressionType(this);
|
||||
}
|
||||
|
||||
public IBinding[] resolvePrefix(IASTName n) {
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
IASTExpression expression = getFieldOwner();
|
||||
IType type = expression.getExpressionType();
|
||||
type = CPPSemantics.getUltimateType(type, true); //stop at pointer to member?
|
||||
|
@ -118,7 +118,7 @@ public class CASTFieldReference extends CASTNode implements IASTFieldReference,
|
|||
IField[] fields = compType.getFields();
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
char[] potential = fields[i].getNameCharArray();
|
||||
if (CharArrayUtils.equals(potential, 0, name.length, name, false)) {
|
||||
if (nameMatches(potential, name, isPrefix)) {
|
||||
bindings.add(fields[i]);
|
||||
}
|
||||
}
|
||||
|
@ -130,4 +130,12 @@ public class CASTFieldReference extends CASTNode implements IASTFieldReference,
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean nameMatches(char[] potential, char[] name, boolean isPrefix) {
|
||||
if (isPrefix) {
|
||||
return CharArrayUtils.equals(potential, 0, name.length, name, false);
|
||||
} else {
|
||||
return CharArrayUtils.equals(potential, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
|
@ -23,8 +24,8 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
|||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IndexFilter;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTCompletionContext;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -71,13 +72,13 @@ public class CASTIdExpression extends CASTNode implements IASTIdExpression, IAST
|
|||
return CVisitor.getExpressionType(this);
|
||||
}
|
||||
|
||||
public IBinding[] resolvePrefix(IASTName n) {
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
IScope scope = CVisitor.getContainingScope(n);
|
||||
|
||||
IBinding[] b1 = null;
|
||||
if (scope != null) {
|
||||
try {
|
||||
b1 = scope.find(n.toString(), true);
|
||||
b1 = scope.find(n.toString(), isPrefix);
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
}
|
||||
|
@ -87,9 +88,10 @@ public class CASTIdExpression extends CASTNode implements IASTIdExpression, IAST
|
|||
IBinding[] b2 = null;
|
||||
if (index != null) {
|
||||
try {
|
||||
b2 = index.findBindingsForPrefix(
|
||||
n.toCharArray(),
|
||||
IndexFilter.getFilter(ILinkage.C_LINKAGE_ID));
|
||||
IndexFilter filter = IndexFilter.getFilter(ILinkage.C_LINKAGE_ID);
|
||||
b2 = isPrefix ?
|
||||
index.findBindingsForPrefix(n.toCharArray(), filter) :
|
||||
index.findBindings(n.toCharArray(), filter, new NullProgressMonitor());
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,12 +15,12 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTCompletionContext;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -57,17 +57,16 @@ public class CASTName extends CASTNode implements IASTName {
|
|||
return binding;
|
||||
}
|
||||
|
||||
public IBinding[] resolvePrefix() {
|
||||
public IASTCompletionContext getCompletionContext() {
|
||||
IASTNode node = getParent();
|
||||
while (!(node instanceof IASTCompletionContext)) {
|
||||
if (node == null) {
|
||||
return null;
|
||||
while (node != null) {
|
||||
if (node instanceof IASTCompletionContext) {
|
||||
return (IASTCompletionContext) node;
|
||||
}
|
||||
node = node.getParent();
|
||||
}
|
||||
|
||||
IASTCompletionContext context = (IASTCompletionContext) node;
|
||||
return context.resolvePrefix(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setBinding(IBinding binding) {
|
||||
|
|
|
@ -18,6 +18,7 @@ import java.util.List;
|
|||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
|
@ -27,8 +28,8 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
|
|||
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IndexFilter;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTCompletionContext;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -78,7 +79,7 @@ public class CASTTypedefNameSpecifier extends CASTBaseDeclSpecifier implements
|
|||
return r_unclear;
|
||||
}
|
||||
|
||||
public IBinding[] resolvePrefix(IASTName n) {
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
List filtered = new ArrayList();
|
||||
IndexFilter filter = new IndexFilter() {
|
||||
public boolean acceptBinding(IBinding binding) {
|
||||
|
@ -98,7 +99,7 @@ public class CASTTypedefNameSpecifier extends CASTBaseDeclSpecifier implements
|
|||
}
|
||||
|
||||
try {
|
||||
IBinding[] bindings = scope.find(n.toString(), true);
|
||||
IBinding[] bindings = scope.find(n.toString(), isPrefix);
|
||||
for (int i = 0 ; i < bindings.length; i++) {
|
||||
if (filter.acceptBinding(bindings[i])) {
|
||||
filtered.add(bindings[i]);
|
||||
|
@ -111,7 +112,9 @@ public class CASTTypedefNameSpecifier extends CASTBaseDeclSpecifier implements
|
|||
|
||||
if (index != null) {
|
||||
try {
|
||||
IBinding[] bindings = index.findBindingsForPrefix(n.toCharArray(), filter);
|
||||
IBinding[] bindings = isPrefix ?
|
||||
index.findBindingsForPrefix(n.toCharArray(), filter) :
|
||||
index.findBindings(n.toCharArray(), filter, new NullProgressMonitor());
|
||||
for (int i = 0; i < bindings.length; i++) {
|
||||
filtered.add(bindings[i]);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import java.util.List;
|
|||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
|
@ -25,8 +26,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IndexFilter;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTCompletionContext;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -111,7 +112,7 @@ public class CPPASTBaseSpecifier extends CPPASTNode implements
|
|||
return r_unclear;
|
||||
}
|
||||
|
||||
public IBinding[] resolvePrefix(IASTName n) {
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
List filtered = new ArrayList();
|
||||
IndexFilter filter = new IndexFilter(){
|
||||
public boolean acceptBinding(IBinding binding) {
|
||||
|
@ -136,7 +137,7 @@ public class CPPASTBaseSpecifier extends CPPASTNode implements
|
|||
|
||||
if (scope != null) {
|
||||
try {
|
||||
IBinding[] bindings = scope.find(n.toString(), true);
|
||||
IBinding[] bindings = scope.find(n.toString(), isPrefix);
|
||||
for (int i = 0; i < bindings.length; i++) {
|
||||
if (filter.acceptBinding(bindings[i])) {
|
||||
filtered.add(bindings[i]);
|
||||
|
@ -150,7 +151,9 @@ public class CPPASTBaseSpecifier extends CPPASTNode implements
|
|||
|
||||
if (index != null) {
|
||||
try {
|
||||
IBinding[] bindings = index.findBindingsForPrefix(n.toCharArray(), filter);
|
||||
IBinding[] bindings = isPrefix ?
|
||||
index.findBindingsForPrefix(n.toCharArray(), filter) :
|
||||
index.findBindings(n.toCharArray(), filter, new NullProgressMonitor());
|
||||
for (int i = 0; i < bindings.length; i++) {
|
||||
filtered.add(bindings[i]);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
|
@ -29,7 +30,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTCompletionContext;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -115,7 +115,7 @@ public class CPPASTFieldReference extends CPPASTNode implements
|
|||
return CPPVisitor.getExpressionType(this);
|
||||
}
|
||||
|
||||
public IBinding[] resolvePrefix(IASTName n) {
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
IASTExpression expression = getFieldOwner();
|
||||
IType type = expression.getExpressionType();
|
||||
type = CPPSemantics.getUltimateType(type, true); //stop at pointer to member?
|
||||
|
@ -130,7 +130,7 @@ public class CPPASTFieldReference extends CPPASTNode implements
|
|||
if (fields != null) {
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
char[] potential = fields[i].getNameCharArray();
|
||||
if (CharArrayUtils.equals(potential, 0, name.length, name, false)) {
|
||||
if (nameMatches(potential, name, isPrefix)) {
|
||||
bindings.add(fields[i]);
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ public class CPPASTFieldReference extends CPPASTNode implements
|
|||
for (int i = 0; i < methods.length; i++) {
|
||||
if (!(methods[i] instanceof ICPPConstructor) && !methods[i].isImplicit()) {
|
||||
char[] potential = methods[i].getNameCharArray();
|
||||
if (CharArrayUtils.equals(potential, 0, name.length, name, false)) {
|
||||
if (nameMatches(potential, name, isPrefix)) {
|
||||
bindings.add(methods[i]);
|
||||
}
|
||||
}
|
||||
|
@ -153,16 +153,15 @@ public class CPPASTFieldReference extends CPPASTNode implements
|
|||
} catch (DOMException e) {
|
||||
}
|
||||
|
||||
collectBases(classType, bindings, n.toCharArray());
|
||||
collectBases(classType, bindings, n.toCharArray(), isPrefix);
|
||||
return (IBinding[]) bindings.toArray(new IBinding[bindings.size()]);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void collectBases(ICPPClassType classType, List bindings, char[] prefix) {
|
||||
if (CharArrayUtils.equals(classType.getNameCharArray(),
|
||||
0, prefix.length, prefix, false)) {
|
||||
private void collectBases(ICPPClassType classType, List bindings, char[] name, boolean isPrefix) {
|
||||
if (nameMatches(classType.getNameCharArray(), name, isPrefix)) {
|
||||
bindings.add(classType);
|
||||
}
|
||||
|
||||
|
@ -172,10 +171,18 @@ public class CPPASTFieldReference extends CPPASTNode implements
|
|||
IBinding base = bases[i].getBaseClass();
|
||||
if (base instanceof ICPPClassType) {
|
||||
ICPPClassType baseClass = (ICPPClassType) base;
|
||||
collectBases(baseClass, bindings, prefix);
|
||||
collectBases(baseClass, bindings, name, isPrefix);
|
||||
}
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean nameMatches(char[] potential, char[] name, boolean isPrefix) {
|
||||
if (isPrefix) {
|
||||
return CharArrayUtils.equals(potential, 0, name.length, name, false);
|
||||
} else {
|
||||
return CharArrayUtils.equals(potential, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
|
@ -22,8 +23,8 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
|||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IndexFilter;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTCompletionContext;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -69,13 +70,13 @@ public class CPPASTIdExpression extends CPPASTNode implements IASTIdExpression,
|
|||
return CPPVisitor.getExpressionType(this);
|
||||
}
|
||||
|
||||
public IBinding[] resolvePrefix(IASTName n) {
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
IScope scope = CPPVisitor.getContainingScope(n);
|
||||
|
||||
IBinding[] b1 = null;
|
||||
if (scope != null) {
|
||||
try {
|
||||
b1 = scope.find(n.toString(), true);
|
||||
b1 = scope.find(n.toString(), isPrefix);
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
}
|
||||
|
@ -85,9 +86,10 @@ public class CPPASTIdExpression extends CPPASTNode implements IASTIdExpression,
|
|||
IBinding[] b2 = null;
|
||||
if (index != null) {
|
||||
try {
|
||||
b2 = index.findBindingsForPrefix(
|
||||
n.toCharArray(),
|
||||
IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID));
|
||||
IndexFilter filter = IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID);
|
||||
b2 = isPrefix ?
|
||||
index.findBindingsForPrefix(n.toCharArray(), filter) :
|
||||
index.findBindings(n.toCharArray(), filter, new NullProgressMonitor());
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,13 +13,13 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTCompletionContext;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||
|
||||
/**
|
||||
|
@ -76,17 +76,16 @@ public class CPPASTName extends CPPASTNode implements IASTName {
|
|||
return binding;
|
||||
}
|
||||
|
||||
public IBinding[] resolvePrefix() {
|
||||
IASTNode node = getParent();
|
||||
while (!(node instanceof IASTCompletionContext)) {
|
||||
if (node == null) {
|
||||
return null;
|
||||
public IASTCompletionContext getCompletionContext() {
|
||||
IASTNode node = getParent();
|
||||
while (node != null) {
|
||||
if (node instanceof IASTCompletionContext) {
|
||||
return (IASTCompletionContext) node;
|
||||
}
|
||||
node = node.getParent();
|
||||
}
|
||||
|
||||
IASTCompletionContext context = (IASTCompletionContext) node;
|
||||
return context.resolvePrefix(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setBinding(IBinding binding) {
|
||||
|
|
|
@ -17,6 +17,7 @@ import java.util.List;
|
|||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
|
@ -28,8 +29,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IndexFilter;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTCompletionContext;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -97,14 +98,14 @@ public class CPPASTNamedTypeSpecifier extends CPPASTBaseDeclSpecifier implements
|
|||
return r_unclear;
|
||||
}
|
||||
|
||||
public IBinding[] resolvePrefix(IASTName n) {
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
List filtered = new ArrayList();
|
||||
|
||||
IScope scope = CPPVisitor.getContainingScope(n);
|
||||
|
||||
if (scope != null) {
|
||||
try {
|
||||
IBinding[] bindings = scope.find(n.toString(), true);
|
||||
IBinding[] bindings = scope.find(n.toString(), isPrefix);
|
||||
for (int i = 0; i < bindings.length; i++) {
|
||||
if (bindings[i] instanceof ICPPTemplateParameter) {
|
||||
filtered.add(bindings[i]);
|
||||
|
@ -127,7 +128,7 @@ public class CPPASTNamedTypeSpecifier extends CPPASTBaseDeclSpecifier implements
|
|||
};
|
||||
|
||||
try {
|
||||
IBinding[] bindings = getTranslationUnit().getScope().find(n.toString(), true);
|
||||
IBinding[] bindings = getTranslationUnit().getScope().find(n.toString(), isPrefix);
|
||||
for (int i = 0 ; i < bindings.length; i++) {
|
||||
if (filter.acceptBinding(bindings[i])) {
|
||||
filtered.add(bindings[i]);
|
||||
|
@ -140,7 +141,9 @@ public class CPPASTNamedTypeSpecifier extends CPPASTBaseDeclSpecifier implements
|
|||
|
||||
if (index != null) {
|
||||
try {
|
||||
IBinding[] bindings = index.findBindingsForPrefix(n.toCharArray(), filter);
|
||||
IBinding[] bindings = isPrefix ?
|
||||
index.findBindingsForPrefix(n.toCharArray(), filter) :
|
||||
index.findBindings(n.toCharArray(), filter, new NullProgressMonitor());
|
||||
for (int i = 0; i < bindings.length; i++) {
|
||||
filtered.add(bindings[i]);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
|
@ -30,7 +31,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTCompletionContext;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -56,10 +56,10 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
|||
return lastName != null ? lastName.resolveBinding() : null;
|
||||
}
|
||||
|
||||
public IBinding[] resolvePrefix() {
|
||||
public IASTCompletionContext getCompletionContext() {
|
||||
removeNullNames();
|
||||
IASTName lastName = getLastName();
|
||||
return lastName != null ? lastName.resolvePrefix() : new IBinding[0];
|
||||
return lastName != null ? lastName.getCompletionContext() : null;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -299,20 +299,21 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
|||
return false;
|
||||
}
|
||||
|
||||
public IBinding[] resolvePrefix(IASTName n) {
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
IBinding binding = names[names.length - 2].resolveBinding();
|
||||
if (binding instanceof ICPPClassType) {
|
||||
return resolveClassScopePrefix((ICPPClassType) binding,
|
||||
n.toCharArray());
|
||||
return findClassScopeBindings((ICPPClassType) binding,
|
||||
n.toCharArray(), isPrefix);
|
||||
} else if (binding instanceof ICPPNamespace) {
|
||||
return resolveNamespaceScopePrefix((ICPPNamespace) binding,
|
||||
n.toCharArray());
|
||||
return findNamespaceScopeBindings((ICPPNamespace) binding,
|
||||
n.toCharArray(), isPrefix);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private IBinding[] resolveClassScopePrefix(ICPPClassType classType, char[] name) {
|
||||
private IBinding[] findClassScopeBindings(ICPPClassType classType,
|
||||
char[] name, boolean isPrefix) {
|
||||
List bindings = new ArrayList();
|
||||
|
||||
try {
|
||||
|
@ -320,7 +321,7 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
|||
for (int i = 0; i < fields.length; i++) {
|
||||
if (fields[i].isStatic()) {
|
||||
char[] potential = fields[i].getNameCharArray();
|
||||
if (CharArrayUtils.equals(potential, 0, name.length, name, false)) {
|
||||
if (nameMatches(potential, name, isPrefix)) {
|
||||
bindings.add(fields[i]);
|
||||
}
|
||||
}
|
||||
|
@ -332,7 +333,7 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
|||
ICPPMethod[] methods = classType.getDeclaredMethods();
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
char[] potential = methods[i].getNameCharArray();
|
||||
if (CharArrayUtils.equals(potential, 0, name.length, name, false)) {
|
||||
if (nameMatches(potential, name, isPrefix)) {
|
||||
bindings.add(methods[i]);
|
||||
}
|
||||
}
|
||||
|
@ -343,7 +344,7 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
|||
ICPPClassType[] nested = classType.getNestedClasses();
|
||||
for (int i = 0; i < nested.length; i++) {
|
||||
char[] potential = nested[i].getNameCharArray();
|
||||
if (CharArrayUtils.equals(potential, 0, name.length, name, false)) {
|
||||
if (nameMatches(potential, name, isPrefix)) {
|
||||
bindings.add(nested[i]);
|
||||
}
|
||||
}
|
||||
|
@ -353,14 +354,15 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
|||
return (IBinding[]) bindings.toArray(new IBinding[bindings.size()]);
|
||||
}
|
||||
|
||||
private IBinding[] resolveNamespaceScopePrefix(ICPPNamespace namespace, char[] name) {
|
||||
private IBinding[] findNamespaceScopeBindings(ICPPNamespace namespace,
|
||||
char[] name, boolean isPrefix) {
|
||||
List bindings = new ArrayList();
|
||||
|
||||
try {
|
||||
IBinding[] members = namespace.getMemberBindings();
|
||||
for (int i = 0 ; i < members.length; i++) {
|
||||
char[] potential = members[i].getNameCharArray();
|
||||
if (CharArrayUtils.equals(potential, 0, name.length, name, false)) {
|
||||
if (nameMatches(potential, name, isPrefix)) {
|
||||
bindings.add(members[i]);
|
||||
}
|
||||
}
|
||||
|
@ -369,4 +371,12 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
|||
|
||||
return (IBinding[]) bindings.toArray(new IBinding[bindings.size()]);
|
||||
}
|
||||
|
||||
private boolean nameMatches(char[] potential, char[] name, boolean isPrefix) {
|
||||
if (isPrefix) {
|
||||
return CharArrayUtils.equals(potential, 0, name.length, name, false);
|
||||
} else {
|
||||
return CharArrayUtils.equals(potential, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
|
||||
|
@ -81,8 +82,7 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I
|
|||
return binding;
|
||||
}
|
||||
|
||||
public IBinding[] resolvePrefix() {
|
||||
// TODO Auto-generated method stub
|
||||
public IASTCompletionContext getCompletionContext() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
|
@ -25,8 +26,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
|||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IndexFilter;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTCompletionContext;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -95,7 +96,7 @@ public class CPPASTUsingDeclaration extends CPPASTNode implements
|
|||
return r_unclear;
|
||||
}
|
||||
|
||||
public IBinding[] resolvePrefix(IASTName n) {
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
List filtered = new ArrayList();
|
||||
IndexFilter filter = new IndexFilter() {
|
||||
public boolean acceptBinding(IBinding binding) {
|
||||
|
@ -112,7 +113,7 @@ public class CPPASTUsingDeclaration extends CPPASTNode implements
|
|||
if (decls[i] instanceof ICPPASTNamespaceDefinition) {
|
||||
ICPPASTNamespaceDefinition defn = (ICPPASTNamespaceDefinition) decls[i];
|
||||
IASTName name = defn.getName();
|
||||
if (CharArrayUtils.equals(name.toCharArray(), 0, nChars.length, nChars, false)) {
|
||||
if (nameMatches(name.toCharArray(), nChars, isPrefix)) {
|
||||
IBinding binding = name.resolveBinding();
|
||||
if (filter.acceptBinding(binding)) {
|
||||
filtered.add(binding);
|
||||
|
@ -125,7 +126,9 @@ public class CPPASTUsingDeclaration extends CPPASTNode implements
|
|||
|
||||
if (index != null) {
|
||||
try {
|
||||
IBinding[] bindings = index.findBindingsForPrefix(n.toCharArray(), filter);
|
||||
IBinding[] bindings = isPrefix ?
|
||||
index.findBindingsForPrefix(n.toCharArray(), filter) :
|
||||
index.findBindings(n.toCharArray(), filter, new NullProgressMonitor());
|
||||
for (int i = 0; i < bindings.length; i++) {
|
||||
filtered.add(bindings[i]);
|
||||
}
|
||||
|
@ -135,4 +138,12 @@ public class CPPASTUsingDeclaration extends CPPASTNode implements
|
|||
|
||||
return (IBinding[]) filtered.toArray(new IBinding[filtered.size()]);
|
||||
}
|
||||
|
||||
private boolean nameMatches(char[] potential, char[] name, boolean isPrefix) {
|
||||
if (isPrefix) {
|
||||
return CharArrayUtils.equals(potential, 0, name.length, name, false);
|
||||
} else {
|
||||
return CharArrayUtils.equals(potential, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
|
@ -25,8 +26,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
|||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IndexFilter;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTCompletionContext;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -80,7 +81,7 @@ public class CPPASTUsingDirective extends CPPASTNode implements
|
|||
return r_unclear;
|
||||
}
|
||||
|
||||
public IBinding[] resolvePrefix(IASTName n) {
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
List filtered = new ArrayList();
|
||||
IndexFilter filter = new IndexFilter() {
|
||||
public boolean acceptBinding(IBinding binding) {
|
||||
|
@ -97,7 +98,7 @@ public class CPPASTUsingDirective extends CPPASTNode implements
|
|||
if (decls[i] instanceof ICPPASTNamespaceDefinition) {
|
||||
ICPPASTNamespaceDefinition defn = (ICPPASTNamespaceDefinition) decls[i];
|
||||
IASTName name = defn.getName();
|
||||
if (CharArrayUtils.equals(name.toCharArray(), 0, nChars.length, nChars, false)) {
|
||||
if (nameMatches(name.toCharArray(), nChars, isPrefix)) {
|
||||
IBinding binding = name.resolveBinding();
|
||||
if (filter.acceptBinding(binding)) {
|
||||
filtered.add(binding);
|
||||
|
@ -110,7 +111,9 @@ public class CPPASTUsingDirective extends CPPASTNode implements
|
|||
|
||||
if (index != null) {
|
||||
try {
|
||||
IBinding[] bindings = index.findBindingsForPrefix(n.toCharArray(), filter);
|
||||
IBinding[] bindings = isPrefix ?
|
||||
index.findBindingsForPrefix(n.toCharArray(), filter) :
|
||||
index.findBindings(n.toCharArray(), filter, new NullProgressMonitor());
|
||||
for (int i = 0; i < bindings.length; i++) {
|
||||
filtered.add(bindings[i]);
|
||||
}
|
||||
|
@ -120,4 +123,12 @@ public class CPPASTUsingDirective extends CPPASTNode implements
|
|||
|
||||
return (IBinding[]) filtered.toArray(new IBinding[filtered.size()]);
|
||||
}
|
||||
|
||||
private boolean nameMatches(char[] potential, char[] name, boolean isPrefix) {
|
||||
if (isPrefix) {
|
||||
return CharArrayUtils.equals(potential, 0, name.length, name, false);
|
||||
} else {
|
||||
return CharArrayUtils.equals(potential, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.parser.scanner2;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansion;
|
||||
|
@ -665,7 +666,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
}
|
||||
|
||||
|
||||
public IBinding[] resolvePrefix() {
|
||||
public IASTCompletionContext getCompletionContext() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
@ -746,9 +747,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
public IBinding resolveBinding() {
|
||||
return null;
|
||||
}
|
||||
public IBinding[] resolvePrefix() {
|
||||
return null;
|
||||
}
|
||||
public IASTCompletionContext getCompletionContext() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public char[] toCharArray() {
|
||||
return name;
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.eclipse.cdt.core.dom.ILinkage;
|
|||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
|
@ -129,8 +130,8 @@ public class PDOMASTAdapter {
|
|||
return fDelegate.resolveBinding();
|
||||
}
|
||||
|
||||
public IBinding[] resolvePrefix() {
|
||||
return fDelegate.resolvePrefix();
|
||||
public IASTCompletionContext getCompletionContext() {
|
||||
return fDelegate.getCompletionContext();
|
||||
}
|
||||
|
||||
public void setBinding(IBinding binding) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2007 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
|
||||
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Bryan Wilkinson (QNX)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.text.contentassist2;
|
||||
|
||||
|
@ -21,6 +22,7 @@ import org.eclipse.core.resources.IFile;
|
|||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.jface.text.contentassist.ContentAssistant;
|
||||
import org.eclipse.jface.text.contentassist.ICompletionProposal;
|
||||
import org.eclipse.jface.text.contentassist.IContextInformation;
|
||||
import org.eclipse.jface.text.source.ISourceViewer;
|
||||
import org.eclipse.jface.text.templates.TemplateProposal;
|
||||
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
||||
|
@ -39,11 +41,7 @@ import org.eclipse.cdt.ui.text.ICCompletionProposal;
|
|||
|
||||
import org.eclipse.cdt.internal.ui.text.contentassist.CContentAssistProcessor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public abstract class AbstractCompletionTest extends BaseUITestCase {
|
||||
public abstract class AbstractContentAssistTest extends BaseUITestCase {
|
||||
|
||||
private ICProject fCProject;
|
||||
protected IFile fCFile;
|
||||
|
@ -57,7 +55,7 @@ public abstract class AbstractCompletionTest extends BaseUITestCase {
|
|||
fgAllKeywords.addAll(ParserFactory.getKeywordSet(KeywordSetKey.KEYWORDS, ParserLanguage.CPP));
|
||||
fgAllKeywords.addAll(ParserFactory.getKeywordSet(KeywordSetKey.TYPES, ParserLanguage.CPP));
|
||||
}
|
||||
public AbstractCompletionTest(String name) {
|
||||
public AbstractContentAssistTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
|
@ -88,7 +86,7 @@ public abstract class AbstractCompletionTest extends BaseUITestCase {
|
|||
super.tearDown();
|
||||
}
|
||||
|
||||
protected void assertCompletionResults(int offset, String[] expected, boolean compareIdString) throws Exception {
|
||||
protected void assertContentAssistResults(int offset, String[] expected, boolean isCompletion, boolean compareIdString) throws Exception {
|
||||
|
||||
if (CTestPlugin.getDefault().isDebugging()) {
|
||||
System.out.println("\n\n\n\n\nTesting "+this.getClass().getName());
|
||||
|
@ -100,11 +98,13 @@ public abstract class AbstractCompletionTest extends BaseUITestCase {
|
|||
ContentAssistant assistant = new ContentAssistant();
|
||||
CContentAssistProcessor processor = new CContentAssistProcessor(fEditor, assistant, contentType);
|
||||
long startTime= System.currentTimeMillis();
|
||||
ICompletionProposal[] results = processor.computeCompletionProposals(sourceViewer, offset);
|
||||
Object[] results = isCompletion
|
||||
? (Object[]) processor.computeCompletionProposals(sourceViewer, offset)
|
||||
: (Object[]) processor.computeContextInformation(sourceViewer, offset);
|
||||
long endTime= System.currentTimeMillis();
|
||||
assertTrue(results != null);
|
||||
|
||||
results= filterProposals(results);
|
||||
results= filterResults(results);
|
||||
String[] resultStrings= toStringArray(results, compareIdString);
|
||||
Arrays.sort(expected);
|
||||
Arrays.sort(resultStrings);
|
||||
|
@ -147,6 +147,44 @@ public abstract class AbstractCompletionTest extends BaseUITestCase {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter out template and keyword proposals.
|
||||
* @param results
|
||||
* @return filtered proposals
|
||||
*/
|
||||
private Object[] filterResults(Object[] results) {
|
||||
List filtered= new ArrayList();
|
||||
for (int i = 0; i < results.length; i++) {
|
||||
Object result = results[i];
|
||||
if (result instanceof TemplateProposal) {
|
||||
continue;
|
||||
}
|
||||
if (result instanceof ICCompletionProposal) {
|
||||
// check for keywords proposal
|
||||
if (fgAllKeywords.contains(((ICCompletionProposal)result).getDisplayString())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
filtered.add(result);
|
||||
}
|
||||
return filtered.toArray();
|
||||
}
|
||||
|
||||
private String[] toStringArray(Object[] results, boolean useIdString) {
|
||||
String[] strings= new String[results.length];
|
||||
for(int i=0; i< results.length; i++){
|
||||
Object result = results[i];
|
||||
if (result instanceof ICCompletionProposal && useIdString) {
|
||||
strings[i]= ((ICCompletionProposal)result).getIdString();
|
||||
} else if (result instanceof ICompletionProposal) {
|
||||
strings[i]= ((ICompletionProposal)result).getDisplayString();
|
||||
} else {
|
||||
strings[i]= ((IContextInformation)result).getContextDisplayString();
|
||||
}
|
||||
}
|
||||
return strings;
|
||||
}
|
||||
|
||||
private String toString(String[] strings) {
|
||||
StringBuffer buf= new StringBuffer();
|
||||
for(int i=0; i< strings.length; i++){
|
||||
|
@ -155,19 +193,6 @@ public abstract class AbstractCompletionTest extends BaseUITestCase {
|
|||
return buf.toString();
|
||||
}
|
||||
|
||||
private String[] toStringArray(ICompletionProposal[] proposals, boolean useIdString) {
|
||||
String[] strings= new String[proposals.length];
|
||||
for(int i=0; i< proposals.length; i++){
|
||||
ICompletionProposal proposal = proposals[i];
|
||||
if (proposal instanceof ICCompletionProposal && useIdString) {
|
||||
strings[i]= ((ICCompletionProposal)proposal).getIdString();
|
||||
} else {
|
||||
strings[i]= proposal.getDisplayString();
|
||||
}
|
||||
}
|
||||
return strings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to relax checking of extra results
|
||||
*/
|
||||
|
@ -175,33 +200,10 @@ public abstract class AbstractCompletionTest extends BaseUITestCase {
|
|||
return true ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter out template and keyword proposals.
|
||||
* @param results
|
||||
* @return filtered proposals
|
||||
*/
|
||||
private ICompletionProposal[] filterProposals(ICompletionProposal[] results) {
|
||||
List filtered= new ArrayList();
|
||||
for (int i = 0; i < results.length; i++) {
|
||||
ICompletionProposal proposal = results[i];
|
||||
if (proposal instanceof TemplateProposal) {
|
||||
continue;
|
||||
}
|
||||
if (proposal instanceof ICCompletionProposal) {
|
||||
// check for keywords proposal
|
||||
if (fgAllKeywords.contains(proposal.getDisplayString())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
filtered.add(proposal);
|
||||
}
|
||||
return (ICompletionProposal[]) filtered.toArray(new ICompletionProposal[filtered.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the content of the editor buffer
|
||||
*/
|
||||
protected String getBuffer() {
|
||||
return EditorTestHelper.getDocument(fEditor).get();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2007 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
|
||||
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Bryan Wilkinson (QNX)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.text.contentassist2;
|
||||
|
||||
|
@ -29,7 +30,7 @@ import org.eclipse.core.runtime.Path;
|
|||
|
||||
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
|
||||
|
||||
public abstract class CompletionProposalsBaseTest extends AbstractCompletionTest {
|
||||
public abstract class CompletionProposalsBaseTest extends AbstractContentAssistTest {
|
||||
|
||||
private boolean fFailingTest;
|
||||
|
||||
|
@ -89,6 +90,10 @@ public abstract class CompletionProposalsBaseTest extends AbstractCompletionTest
|
|||
return bodyFile;
|
||||
}
|
||||
|
||||
protected void assertCompletionResults(int offset, String[] expected, boolean compareIdString) throws Exception {
|
||||
assertContentAssistResults(offset, expected, true, compareIdString);
|
||||
}
|
||||
|
||||
public void testCompletionProposals() throws Exception {
|
||||
String[] expected = getExpectedResultsValues();
|
||||
assertCompletionResults(getCompletionPosition(), expected, false);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2007 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
|
||||
|
@ -27,7 +27,7 @@ public class CompletionTest_ScopedReference_NonCodeScope extends CompletionProp
|
|||
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
|
||||
private final String expectedPrefix = "";
|
||||
private final String[] expectedResults = {
|
||||
"Foo(void) ",
|
||||
"Foo(void)",
|
||||
"bar(void) void",
|
||||
"fum(void) void",
|
||||
"x : int"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2007 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
|
||||
|
@ -27,7 +27,7 @@ public class CompletionTest_VariableType_NestedPrefix extends CompletionProposa
|
|||
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
|
||||
private final String expectedPrefix = "";
|
||||
private final String[] expectedResults = {
|
||||
"Foo(void) ",
|
||||
"Foo(void)",
|
||||
"bar(void) void",
|
||||
"fum(void) void",
|
||||
"DEF",
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
|||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public class CompletionTests extends AbstractCompletionTest {
|
||||
public class CompletionTests extends AbstractContentAssistTest {
|
||||
|
||||
private static final String HEADER_FILE_NAME = "CompletionTest.h";
|
||||
private static final String SOURCE_FILE_NAME = "CompletionTest.cpp";
|
||||
|
@ -128,6 +128,10 @@ public class CompletionTests extends AbstractCompletionTest {
|
|||
return createFile(project, SOURCE_FILE_NAME, sourceContent.toString());
|
||||
}
|
||||
|
||||
protected void assertCompletionResults(int offset, String[] expected, boolean compareIdString) throws Exception {
|
||||
assertContentAssistResults(offset, expected, true, compareIdString);
|
||||
}
|
||||
|
||||
//void gfunc() {C1 v; v.m/*cursor*/
|
||||
public void _testLocalVariable() throws Exception {
|
||||
// fails because of additional m1private(void)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 Siemens AG.
|
||||
* Copyright (c) 2006, 2007 Siemens AG and others.
|
||||
* All rights reserved. This content 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
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Norbert Ploett - Initial implementation
|
||||
* Bryan Wilkinson (QNX)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.text.contentassist2;
|
||||
|
||||
|
@ -14,7 +15,7 @@ import junit.framework.Test;
|
|||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* This suite bundles all tests for the CContentAssistProcessor2
|
||||
* This suite bundles all tests for the CContentAssistProcessor
|
||||
*/
|
||||
public class ContentAssist2TestSuite extends TestSuite {
|
||||
|
||||
|
@ -25,7 +26,6 @@ public class ContentAssist2TestSuite extends TestSuite {
|
|||
public ContentAssist2TestSuite() {
|
||||
super("Tests in package org.eclipse.cdt.ui.tests.text.contentassist2");
|
||||
|
||||
addTest(CompletionTest_MemberReference_Arrow_Prefix2.suite());
|
||||
addTest(CompletionTest_ArgumentType_Prefix.suite());
|
||||
addTest(CompletionTest_ArgumentType_Prefix2.suite());
|
||||
addTest(CompletionTest_ClassReference_NoPrefix.suite());
|
||||
|
@ -41,6 +41,7 @@ public class ContentAssist2TestSuite extends TestSuite {
|
|||
addTest(CompletionTest_MacroRef_Prefix.suite());
|
||||
addTest(CompletionTest_MemberReference_Arrow_NoPrefix.suite());
|
||||
addTest(CompletionTest_MemberReference_Arrow_Prefix.suite());
|
||||
addTest(CompletionTest_MemberReference_Arrow_Prefix2.suite());
|
||||
addTest(CompletionTest_MemberReference_Dot_NoPrefix.suite());
|
||||
addTest(CompletionTest_MemberReference_Dot_Prefix.suite());
|
||||
addTest(CompletionTest_NamespaceRef_NoPrefix.suite());
|
||||
|
@ -64,5 +65,6 @@ public class ContentAssist2TestSuite extends TestSuite {
|
|||
addTest(CompletionTest_VariableType_Prefix.suite());
|
||||
|
||||
addTest(CompletionTests.suite());
|
||||
addTest(ParameterHintTests.suite());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 QNX Software Systems 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:
|
||||
* Bryan Wilkinson (QNX) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.text.contentassist2;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
|
||||
public class ParameterHintTests extends AbstractContentAssistTest {
|
||||
|
||||
private static final String HEADER_FILE_NAME = "PHTest.h";
|
||||
private static final String SOURCE_FILE_NAME = "PHTest.cpp";
|
||||
|
||||
//{PHTest.h}
|
||||
//class aClass {
|
||||
//public:
|
||||
// int aField;
|
||||
// void aMethod(char c);
|
||||
// void aMethod(char c, int x);
|
||||
//};
|
||||
//class bClass {
|
||||
//public:
|
||||
// bClass(int x);
|
||||
// bClass(int x, int y);
|
||||
//};
|
||||
//void aFunc(int i);
|
||||
//int anotherFunc(int i, int j);
|
||||
//int pi(aClass a);
|
||||
//int pie(aClass a);
|
||||
//int pies(aClass a);
|
||||
|
||||
public ParameterHintTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return BaseTestCase.suite(ParameterHintTests.class, "_");
|
||||
}
|
||||
|
||||
protected IFile setUpProjectContent(IProject project) throws Exception {
|
||||
String headerContent= readTaggedComment(HEADER_FILE_NAME);
|
||||
StringBuffer sourceContent= getContentsForTest(1)[0];
|
||||
sourceContent.insert(0, "#include \""+HEADER_FILE_NAME+"\"\n");
|
||||
assertNotNull(createFile(project, HEADER_FILE_NAME, headerContent));
|
||||
return createFile(project, SOURCE_FILE_NAME, sourceContent.toString());
|
||||
}
|
||||
|
||||
protected void assertParameterHints(String[] expected) throws Exception {
|
||||
assertContentAssistResults(getBuffer().length() - 1, expected, false, false);
|
||||
}
|
||||
|
||||
//void foo(){aFunc(
|
||||
public void testFunction() throws Exception {
|
||||
assertParameterHints(new String[] {
|
||||
"aFunc(int i) void"
|
||||
});
|
||||
}
|
||||
|
||||
////TODO move function into header once indexer supports templates
|
||||
//template<class T>void tFunc(T x, T y);
|
||||
//void foo(){tFunc(
|
||||
public void testTemplateFunction() throws Exception {
|
||||
assertParameterHints(new String[] {
|
||||
"tFunc(T x,T y) void"
|
||||
});
|
||||
}
|
||||
|
||||
////TODO move function into header once indexer supports templates
|
||||
//template<class T>void tFunc(T x, T y);
|
||||
//void foo(){tFunc<int>(
|
||||
public void _testTemplateFunction2() throws Exception {
|
||||
assertParameterHints(new String[] {
|
||||
"tFunc(T x,T y) void"
|
||||
});
|
||||
}
|
||||
|
||||
//void foo(){int a=5;aFunc ( anotherFunc ( a , (in
|
||||
public void testOffsetCalculation() throws Exception {
|
||||
assertParameterHints(new String[] {
|
||||
"anotherFunc(int i,int j) int"
|
||||
});
|
||||
}
|
||||
|
||||
//void foo(){int a=pie(
|
||||
public void testAccurateName() throws Exception {
|
||||
assertParameterHints(new String[] {
|
||||
"pie(aClass a) int"
|
||||
});
|
||||
}
|
||||
|
||||
//void foo(){int a=pi
|
||||
public void testInvalidInvocation() throws Exception {
|
||||
assertParameterHints(new String[] {});
|
||||
}
|
||||
|
||||
//void aClass::aMethod(
|
||||
public void testMethodDefinition() throws Exception {
|
||||
assertParameterHints(new String[] {
|
||||
"aMethod(char c) void",
|
||||
"aMethod(char c,int x) void"
|
||||
});
|
||||
}
|
||||
|
||||
//void aClass::aMethod(char c){aMethod(c,aFi
|
||||
public void testMethodScope() throws Exception {
|
||||
assertParameterHints(new String[] {
|
||||
"aMethod(char c) void",
|
||||
"aMethod(char c,int x) void"
|
||||
});
|
||||
}
|
||||
|
||||
//void foo(){aClass a=new aClass(
|
||||
public void testConstructor() throws Exception {
|
||||
assertParameterHints(new String[] {
|
||||
"aClass(void)",
|
||||
"aClass(const aClass &)"
|
||||
});
|
||||
}
|
||||
|
||||
//void foo(){bClass b(
|
||||
public void _testConstructor2() throws Exception {
|
||||
assertParameterHints(new String[] {
|
||||
"bClass(int x)",
|
||||
"bClass(int x,int y)",
|
||||
"bClass(const bClass &)"
|
||||
});
|
||||
}
|
||||
|
||||
////TODO move class into header once indexer supports templates
|
||||
//template<class T>class tClass {public:tClass(T t);};
|
||||
//void foo(){tClass<int> t=new tClass<int>(
|
||||
public void _testTemplateConstructor() throws Exception {
|
||||
assertParameterHints(new String[] {
|
||||
"tClass(void)",
|
||||
"tClass(T t)",
|
||||
"tClass(const tClass &)"
|
||||
});
|
||||
}
|
||||
|
||||
////TODO move class into header once indexer supports templates
|
||||
//template<class T>class tClass {public:tClass(T t);};
|
||||
//void foo(){tClass<int> t(
|
||||
public void _testTemplateConstructor2() throws Exception {
|
||||
assertParameterHints(new String[] {
|
||||
"tClass(T t)",
|
||||
"tClass(const tClass &)"
|
||||
});
|
||||
}
|
||||
|
||||
//void foo(){int pi = 3;pi(
|
||||
public void testFunctionsOnly() throws Exception {
|
||||
assertParameterHints(new String[] {
|
||||
"pi(aClass a) int"
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems and others.
|
||||
* Copyright (c) 2006, 2007 QNX Software Systems 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
|
||||
|
@ -106,7 +106,7 @@ public class IndexLabelProvider extends LabelProvider {
|
|||
else if (element instanceof IEnumeration)
|
||||
desc = CElementImageProvider.getEnumerationImageDescriptor();
|
||||
else if (element instanceof IEnumerator)
|
||||
CElementImageProvider.getEnumeratorImageDescriptor();
|
||||
desc = CElementImageProvider.getEnumeratorImageDescriptor();
|
||||
else if (element instanceof ITypedef)
|
||||
desc = CElementImageProvider.getTypedefImageDescriptor();
|
||||
else if (element instanceof ICProject)
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
package org.eclipse.cdt.internal.ui.text.contentassist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
|
@ -24,6 +22,7 @@ import org.eclipse.swt.graphics.Image;
|
|||
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
|
@ -82,40 +81,30 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
} else {
|
||||
boolean handleMacros= false;
|
||||
IASTName[] names = completionNode.getNames();
|
||||
if (names == null || names.length == 0)
|
||||
// No names, not much we can do here
|
||||
return Collections.EMPTY_LIST;
|
||||
|
||||
// Find all bindings
|
||||
List allBindings = new ArrayList();
|
||||
|
||||
for (int i = 0; i < names.length; ++i) {
|
||||
if (names[i].getTranslationUnit() == null)
|
||||
// The node isn't properly hooked up, must have backtracked out of this node
|
||||
continue;
|
||||
IBinding[] bindings = names[i].resolvePrefix();
|
||||
if (names[i].getParent() instanceof IASTIdExpression) {
|
||||
|
||||
IASTCompletionContext astContext = names[i].getCompletionContext();
|
||||
if (astContext == null) {
|
||||
continue;
|
||||
} else if (astContext instanceof IASTIdExpression) {
|
||||
// handle macros only if there is a prefix
|
||||
handleMacros = prefix.length() > 0;
|
||||
}
|
||||
|
||||
IBinding[] bindings = astContext.findBindings(
|
||||
names[i], !context.isContextInformationStyle());
|
||||
|
||||
if (bindings != null)
|
||||
for (int j = 0; j < bindings.length; ++j) {
|
||||
IBinding binding = bindings[j];
|
||||
//if (!allBindings.contains(binding))
|
||||
// TODO I removed this check since equals in the IBinding tree is currently broken
|
||||
// It is returning true at times when I don't think it should (Bug 91577)
|
||||
allBindings.add(binding);
|
||||
}
|
||||
}
|
||||
|
||||
Iterator iBinding = allBindings.iterator();
|
||||
while (iBinding.hasNext()) {
|
||||
IBinding binding = (IBinding)iBinding.next();
|
||||
handleBinding(binding, context, proposals);
|
||||
for (int j = 0; j < bindings.length; ++j)
|
||||
handleBinding(bindings[j], context, astContext, proposals);
|
||||
}
|
||||
|
||||
if (handleMacros) {
|
||||
if (handleMacros)
|
||||
addMacroProposals(context, prefix, proposals);
|
||||
}
|
||||
}
|
||||
|
||||
return proposals;
|
||||
|
@ -204,15 +193,17 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
proposals.add(createProposal(macroName, macroName, image, context));
|
||||
}
|
||||
|
||||
protected void handleBinding(IBinding binding, CContentAssistInvocationContext context, List proposals) {
|
||||
protected void handleBinding(IBinding binding,
|
||||
CContentAssistInvocationContext cContext,
|
||||
IASTCompletionContext astContext, List proposals) {
|
||||
if (binding instanceof ICPPClassType) {
|
||||
handleClass((ICPPClassType) binding, context, proposals);
|
||||
handleClass((ICPPClassType) binding, cContext, proposals);
|
||||
} else if (binding instanceof IFunction) {
|
||||
handleFunction((IFunction)binding, context, proposals);
|
||||
handleFunction((IFunction)binding, cContext, proposals);
|
||||
} else if (binding instanceof IVariable) {
|
||||
handleVariable((IVariable) binding, context, proposals);
|
||||
} else {
|
||||
proposals.add(createProposal(binding.getName(), binding.getName(), getImage(binding), context));
|
||||
handleVariable((IVariable) binding, cContext, proposals);
|
||||
} else if (!cContext.isContextInformationStyle()) {
|
||||
proposals.add(createProposal(binding.getName(), binding.getName(), getImage(binding), cContext));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,7 +277,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
StringBuffer dispStringBuff = new StringBuffer(repStringBuff.toString());
|
||||
dispStringBuff.append(dispargString);
|
||||
dispStringBuff.append(')');
|
||||
if (returnTypeStr != null) {
|
||||
if (returnTypeStr != null && returnTypeStr.length() > 0) {
|
||||
dispStringBuff.append(' ');
|
||||
dispStringBuff.append(returnTypeStr);
|
||||
}
|
||||
|
@ -315,6 +306,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
}
|
||||
|
||||
private void handleVariable(IVariable variable, CContentAssistInvocationContext context, List proposals) {
|
||||
if (context.isContextInformationStyle()) return;
|
||||
|
||||
StringBuffer repStringBuff = new StringBuffer();
|
||||
repStringBuff.append(variable.getName());
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue