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

Fix for 169860, port content assist to use index, by Bryan Wilkinson.

This commit is contained in:
Markus Schorn 2007-01-29 10:18:56 +00:00
parent 807f6f54de
commit 7506761fce
15 changed files with 48 additions and 36 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004 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
@ -7,6 +7,7 @@
*
* Contributors:
* IBM Rational Software - Initial API and implementation
* Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
@ -42,7 +43,6 @@ public class CompletionTest_ArgumentType_NoPrefix extends CompletionProposalsBa
public CompletionTest_ArgumentType_NoPrefix(String name) {
super(name);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=169860
setExpectFailure(169860);
}
public static Test suite() {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004 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
@ -7,6 +7,7 @@
*
* Contributors:
* IBM Rational Software - Initial API and implementation
* Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
@ -42,7 +43,6 @@ public class CompletionTest_ArgumentType_NoPrefix2 extends CompletionProposalsB
public CompletionTest_ArgumentType_NoPrefix2(String name) {
super(name);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=169860
setExpectFailure(169860);
}
public static Test suite() {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004 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
@ -7,6 +7,7 @@
*
* Contributors:
* IBM Rational Software - Initial API and implementation
* Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
@ -37,7 +38,6 @@ public class CompletionTest_ClassReference_NoPrefix extends CompletionProposals
public CompletionTest_ClassReference_NoPrefix(String name) {
super(name);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=169860
setExpectFailure(169860);
}
public static Test suite() {

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
* 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:
* IBM Corporation - initial API and implementation
* Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
@ -35,7 +36,6 @@ public class CompletionTest_ClassReference_Prefix extends CompletionProposalsBa
public CompletionTest_ClassReference_Prefix(String name) {
super(name);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=169860
setExpectFailure(169860);
}
public static Test suite() {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004 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
@ -7,6 +7,7 @@
*
* Contributors:
* IBM Rational Software - Initial API and implementation
* Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
@ -43,7 +44,6 @@ public class CompletionTest_ExceptionReference_NoPrefix extends CompletionPropo
public CompletionTest_ExceptionReference_NoPrefix(String name) {
super(name);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=169860
setExpectFailure(169860);
}
public static Test suite() {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004 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
@ -7,6 +7,7 @@
*
* Contributors:
* IBM Rational Software - Initial API and implementation
* Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
@ -41,7 +42,6 @@ public class CompletionTest_FieldType_NoPrefix extends CompletionProposalsBaseT
public CompletionTest_FieldType_NoPrefix(String name) {
super(name);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=169860
setExpectFailure(169860);
}
public static Test suite() {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004 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
@ -7,6 +7,7 @@
*
* Contributors:
* IBM Rational Software - Initial API and implementation
* Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
import junit.framework.Test;
@ -42,7 +43,6 @@ public class CompletionTest_FieldType_NoPrefix2 extends CompletionProposalsBase
public CompletionTest_FieldType_NoPrefix2(String name) {
super(name);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=169860
setExpectFailure(169860);
}
public static Test suite() {

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
* 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:
* IBM Rational Software - Initial API and implementation
* Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
import junit.framework.Test;
@ -34,7 +35,6 @@ public class CompletionTest_NamespaceRef_NoPrefix extends CompletionProposalsBa
public CompletionTest_NamespaceRef_NoPrefix(String name) {
super(name);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=169860
setExpectFailure(169860);
}
public static Test suite() {

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
* 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:
* IBM Rational Software - Initial API and implementation
* Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
@ -34,7 +35,6 @@ public class CompletionTest_NamespaceRef_Prefix extends CompletionProposalsBase
public CompletionTest_NamespaceRef_Prefix(String name) {
super(name);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=169860
setExpectFailure(169860);
}
public static Test suite() {

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
* 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:
* IBM Rational Software - Initial API and implementation
* Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
import junit.framework.Test;
@ -34,7 +35,6 @@ public class CompletionTest_TypeRef_NoPrefix extends CompletionProposalsBaseTes
public CompletionTest_TypeRef_NoPrefix(String name) {
super(name);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=169860
setExpectFailure(169860);
}
public static Test suite() {

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
* 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:
* IBM Rational Software - Initial API and implementation
* Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
@ -34,7 +35,6 @@ public class CompletionTest_TypeRef_Prefix extends CompletionProposalsBaseTest{
public CompletionTest_TypeRef_Prefix(String name) {
super(name);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=169860
setExpectFailure(169860);
}
public static Test suite() {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004 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
@ -7,6 +7,7 @@
*
* Contributors:
* IBM Rational Software - Initial API and implementation
* Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
import junit.framework.Test;
@ -39,7 +40,6 @@ public class CompletionTest_VariableType_NoPrefix extends CompletionProposalsBa
public CompletionTest_VariableType_NoPrefix(String name) {
super(name);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=169860
setExpectFailure(169860);
}
public static Test suite() {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2007 Wind River Systems, 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
@ -7,6 +7,7 @@
*
* Contributors:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
* Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
@ -40,7 +41,6 @@ public class CompletionTests extends AbstractCompletionTest {
//
//extern C1* gfC1();
//C2* gfC2();
//static C3* gfC3();
//
//enum E1 {e11, e12};
//
@ -239,7 +239,7 @@ public class CompletionTests extends AbstractCompletionTest {
//void f() {gf/*cursor*/
public void testGlobalFunctions_GlobalScope() throws Exception {
final String[] expected= {
"gfC1(void)", "gfC2(void)", "gfC3(void)"
"gfC1(void)", "gfC2(void)"
};
assertCompletionResults(fCursorOffset, expected, true);
}
@ -247,7 +247,7 @@ public class CompletionTests extends AbstractCompletionTest {
//void C3::f() {gf/*cursor*/
public void testGlobalFunctions_MethodScope() throws Exception {
final String[] expected= {
"gfC1(void)", "gfC2(void)", "gfC3(void)"
"gfC1(void)", "gfC2(void)"
};
assertCompletionResults(fCursorOffset, expected, true);
}

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
* 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:
* IBM - Initial API and implementation
* Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist;
@ -29,9 +30,11 @@ import org.eclipse.jface.text.contentassist.IContextInformationValidator;
import org.eclipse.ui.IEditorPart;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.ICCompletionProposal;
@ -78,11 +81,14 @@ public class CCompletionProcessor2 implements IContentAssistProcessor {
String prefix = null;
if (workingCopy != null) {
// TODO, to improve performance, we want to skip all headers
// But right now we're not getting any completions
// fCurrentCompletionNode = workingCopy.getCompletionNode(index, ITranslationUnit.AST_SKIP_ALL_HEADERS, offset);
fCurrentCompletionNode = workingCopy.getCompletionNode(index, 0, offset);
IPDOMManager manager = CCorePlugin.getPDOMManager();
String indexerId = manager.getIndexerId(workingCopy.getCProject());
int flags = ITranslationUnit.AST_SKIP_ALL_HEADERS;
if (IPDOMManager.ID_NO_INDEXER.equals(indexerId)) {
flags = 0;
}
fCurrentCompletionNode = workingCopy.getCompletionNode(index, flags, offset);
if (fCurrentCompletionNode != null)
prefix = fCurrentCompletionNode.getPrefix();
}

View file

@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Anton Leherbauer (Wind River Systems)
* Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist;
@ -23,6 +24,7 @@ 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.IASTFunctionStyleMacroParameter;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
@ -48,6 +50,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.contentassist.ICompletionContributor;
@ -61,7 +64,9 @@ public class DOMCompletionContributor implements ICompletionContributor {
ASTCompletionNode completionNode,
String prefix,
List proposals) {
if (completionNode != null) {
boolean handleMacros = false;
IASTName[] names = completionNode.getNames();
if (names == null || names.length == 0)
// No names, not much we can do here
@ -74,6 +79,7 @@ public class DOMCompletionContributor implements ICompletionContributor {
// 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) handleMacros = true;
if (bindings != null)
for (int j = 0; j < bindings.length; ++j) {
IBinding binding = bindings[j];
@ -91,11 +97,11 @@ public class DOMCompletionContributor implements ICompletionContributor {
}
// Find all macros if there is a prefix
if (prefix.length() > 0) {
if (prefix.length() > 0 && handleMacros) {
IASTPreprocessorMacroDefinition[] macros = completionNode.getTranslationUnit().getMacroDefinitions();
if (macros != null)
for (int i = 0; i < macros.length; ++i)
if (macros[i].getName().toString().startsWith(prefix))
if (CharArrayUtils.equals(macros[i].getName().toCharArray(), 0, prefix.length(), prefix.toCharArray(), false))
handleMacro(macros[i], completionNode, offset, viewer, proposals);
}
}