1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for Bug 72824 - [Content Assist] Content Assist erases code (Patch by Bryan Wilkinson)

This commit is contained in:
Anton Leherbauer 2007-02-19 08:42:34 +00:00
parent 2a54313bd6
commit dcff673b3e
5 changed files with 41 additions and 34 deletions

View file

@ -21,12 +21,14 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNameOwner; import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
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.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
@ -314,44 +316,41 @@ public class CPPASTQualifiedName extends CPPASTNode implements
private IBinding[] findClassScopeBindings(ICPPClassType classType, private IBinding[] findClassScopeBindings(ICPPClassType classType,
char[] name, boolean isPrefix) { char[] name, boolean isPrefix) {
List bindings = new ArrayList(); List filtered = new ArrayList();
try {
IField[] fields = classType.getFields();
for (int i = 0; i < fields.length; i++) {
if (fields[i].isStatic()) {
char[] potential = fields[i].getNameCharArray();
if (nameMatches(potential, name, isPrefix)) {
bindings.add(fields[i]);
}
}
}
} catch (DOMException e) {
}
try {
ICPPMethod[] methods = classType.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
char[] potential = methods[i].getNameCharArray();
if (nameMatches(potential, name, isPrefix)) {
bindings.add(methods[i]);
}
}
} catch (DOMException e) {
}
try { try {
ICPPClassType[] nested = classType.getNestedClasses(); ICPPClassType[] nested = classType.getNestedClasses();
for (int i = 0; i < nested.length; i++) { for (int i = 0; i < nested.length; i++) {
char[] potential = nested[i].getNameCharArray(); char[] potential = nested[i].getNameCharArray();
if (nameMatches(potential, name, isPrefix)) { if (nameMatches(potential, name, isPrefix)) {
bindings.add(nested[i]); filtered.add(nested[i]);
} }
} }
} catch (DOMException e) { } catch (DOMException e) {
} }
return (IBinding[]) bindings.toArray(new IBinding[bindings.size()]); try {
IBinding[] bindings = classType.getCompositeScope().find(new String(name), isPrefix);
for (int i = 0; i < bindings.length; i++) {
if (bindings[i] instanceof ICPPMember) {
ICPPMember member = (ICPPMember) bindings[i];
if (!classType.isSameType(member.getClassOwner())) continue;
if (member instanceof IField) {
IField field = (IField) member;
if (!field.isStatic()) continue;
} else if (member instanceof ICPPMethod) {
ICPPMethod method = (ICPPMethod) member;
if (method.isImplicit()) continue;
}
} else if (!(bindings[i] instanceof IEnumerator)) continue;
filtered.add(bindings[i]);
}
} catch(DOMException e) {
}
return (IBinding[]) filtered.toArray(new IBinding[filtered.size()]);
} }
private IBinding[] findNamespaceScopeBindings(ICPPNamespace namespace, private IBinding[] findNamespaceScopeBindings(ICPPNamespace namespace,

View file

@ -315,11 +315,19 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
IASTName [] ns = ((ICPPASTQualifiedName)compName).getNames(); IASTName [] ns = ((ICPPASTQualifiedName)compName).getNames();
compName = ns[ ns.length - 1 ]; compName = ns[ ns.length - 1 ];
} }
IBinding[] results = null;
if((prefixLookup && CharArrayUtils.equals(compName.toCharArray(), 0, n.length, n, false)) if((prefixLookup && CharArrayUtils.equals(compName.toCharArray(), 0, n.length, n, false))
|| (!prefixLookup && CharArrayUtils.equals(compName.toCharArray(), n))) { || (!prefixLookup && CharArrayUtils.equals(compName.toCharArray(), n))) {
return (IBinding[]) ArrayUtil.addAll( IBinding.class, null, getConstructors( bindings, true ) ); results = (IBinding[]) ArrayUtil.addAll( IBinding.class, null, getConstructors( bindings, true ) );
if (!prefixLookup) {
return results;
}
} }
return super.find( name, prefixLookup );
results = (IBinding[]) ArrayUtil.addAll( IBinding.class, results, super.find( name, prefixLookup ));
return results != null ? results : IBinding.EMPTY_BINDING_ARRAY;
} }
public static boolean isConstructorReference( IASTName name ){ public static boolean isConstructorReference( IASTName name ){

View file

@ -3806,7 +3806,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
clause clause
.setPropertyInParent(IASTInitializerList.NESTED_INITIALIZER); .setPropertyInParent(IASTInitializerList.NESTED_INITIALIZER);
} }
if (LT(1) == IToken.tRBRACE) if (LT(1) == IToken.tRBRACE || LT(1) == IToken.tEOC)
break; break;
consume(IToken.tCOMMA); consume(IToken.tCOMMA);
} }

View file

@ -9,6 +9,7 @@
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
* Bryan Wilkinson (QNX)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@ -416,8 +417,7 @@ ICPPClassScope, IPDOMMemberOwner, IIndexType, IIndexScope {
} }
public boolean visit(IPDOMNode node) throws CoreException { public boolean visit(IPDOMNode node) throws CoreException {
if (node instanceof PDOMNamedNode && node instanceof IBinding if (node instanceof PDOMNamedNode && node instanceof IBinding) {
&& !(node instanceof ICPPConstructor)) {
char[] n= ((PDOMNamedNode) node).getDBName().getChars(); char[] n= ((PDOMNamedNode) node).getDBName().getChars();
if ((fPrefixLookup && CharArrayUtils.equals(n, 0, fName.length, fName, false)) if ((fPrefixLookup && CharArrayUtils.equals(n, 0, fName.length, fName, false))
|| (!fPrefixLookup && CharArrayUtils.equals(n, fName))) { || (!fPrefixLookup && CharArrayUtils.equals(n, fName))) {

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -193,7 +193,7 @@ public class ContentAssistTests extends BaseUITestCase {
assertEquals( "veryLongName : int", results[0].getDisplayString() ); //$NON-NLS-1$ assertEquals( "veryLongName : int", results[0].getDisplayString() ); //$NON-NLS-1$
} }
public void _testBug72824() throws Exception { public void testBug72824() throws Exception {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
writer.write( "class Strategy { \n"); //$NON-NLS-1$ writer.write( "class Strategy { \n"); //$NON-NLS-1$
writer.write( "public : \n"); //$NON-NLS-1$ writer.write( "public : \n"); //$NON-NLS-1$