diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog
index f00995c378c..1e4209a6bfd 100644
--- a/core/org.eclipse.cdt.core/ChangeLog
+++ b/core/org.eclipse.cdt.core/ChangeLog
@@ -1,3 +1,7 @@
+2003-11-27 Hoda Amer
+ Content Assist work : Added an ICompletionRequestor interface
+ and a CompletionRequestorAdaptor classe.
+
2003-11-20 Alain Magloire
The profiler need to get the line number of the offset within
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNode.java
index ffc45fb681a..4379a781c33 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNode.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNode.java
@@ -24,11 +24,15 @@ public interface IASTNode {
public static final LookupKind ALL = new LookupKind( 0 );
public static final LookupKind STRUCTURES = new LookupKind( 1 );
- public static final LookupKind FUNCTIONS = new LookupKind( 2 );
- public static final LookupKind LOCAL_VARIABLES = new LookupKind( 3 );
- public static final LookupKind METHODS = new LookupKind( 4 );
- public static final LookupKind FIELDS = new LookupKind( 5 );
- public static final LookupKind NAMESPACES = new LookupKind( 6 );
+ public static final LookupKind STRUCS = new LookupKind( 2 );
+ public static final LookupKind UNIONS = new LookupKind( 3 );
+ public static final LookupKind CLASSES = new LookupKind( 4 );
+ public static final LookupKind FUNCTIONS = new LookupKind( 5 );
+ public static final LookupKind VARIABLES = new LookupKind( 6 );
+ public static final LookupKind LOCAL_VARIABLES = new LookupKind( 7 );
+ public static final LookupKind METHODS = new LookupKind( 8 );
+ public static final LookupKind FIELDS = new LookupKind( 9 );
+ public static final LookupKind NAMESPACES = new LookupKind( 10 );
/**
* @param enumValue
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICompletionRequestor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICompletionRequestor.java
new file mode 100644
index 00000000000..9421b470906
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICompletionRequestor.java
@@ -0,0 +1,34 @@
+/**********************************************************************
+ * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Rational Software - Initial API and implementation
+***********************************************************************/
+package org.eclipse.cdt.core;
+
+import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
+
+/**
+ * @author hamer
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public interface ICompletionRequestor {
+ void acceptField(String name, String returnType, ASTAccessVisibility visibility, int completionStart, int completionLength, int relevance);
+ void acceptVariable(String name, String returnType, int completionStart, int completionLength, int relevance);
+ void acceptLocalVariable(String name, String returnType, int completionStart, int completionLength, int relevance);
+ void acceptMethod(String name, String parameterString, String returnType, ASTAccessVisibility visibility, int completionStart, int completionLength, int relevance);
+ void acceptFunction(String name, String parameterString, String returnType, int completionStart, int completionLength, int relevance);
+ void acceptClass(String name, int completionStart, int completionLength, int relevance);
+ void acceptStruct(String name, int completionStart, int completionLength, int relevance);
+ void acceptUnion(String name, int completionStart, int completionLength, int relevance);
+ void acceptNamespace(String name, int completionStart, int completionLength, int relevance);
+ void acceptMacro(String name, int completionStart, int completionLength, int relevance);
+ void acceptEnumeration(String name, int completionStart, int completionLength, int relevance);
+ void acceptEnumerator(String name, int completionStart, int completionLength, int relevance);
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/contentassist/CompletionEngine.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/contentassist/CompletionEngine.java
index 4551a2d78ae..9227ee6a124 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/contentassist/CompletionEngine.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/contentassist/CompletionEngine.java
@@ -1,18 +1,25 @@
-/*
- * Created on Nov 19, 2003
- *
- * To change the template for this generated file go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
+/**********************************************************************
+ * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Rational Software - Initial API and implementation
+***********************************************************************/
package org.eclipse.cdt.internal.core.contentassist;
import java.io.CharArrayReader;
import java.io.Reader;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.ICompletionRequestor;
import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IScannerInfo;
@@ -24,7 +31,11 @@ import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
+import org.eclipse.cdt.core.parser.ast.IASTField;
+import org.eclipse.cdt.core.parser.ast.IASTNode;
+import org.eclipse.cdt.core.parser.ast.IASTNode.LookupResult;
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
+import org.eclipse.cdt.internal.core.parser.util.ASTUtil;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
@@ -38,109 +49,197 @@ import org.eclipse.core.runtime.IPath;
*
*/
public class CompletionEngine {
+ List completions = new ArrayList();
+ ICompletionRequestor requestor;
+ int completionStart = 0;
+ int completionLength = 0;
+ public static final int LOCAL_VARIABLE_TYPE_RELEVANCE = 12;
+ public static final int FIELD_TYPE_RELEVANCE = 11;
+ public static final int VARIABLE_TYPE_RELEVANCE = 10;
+ public static final int METHOD_TYPE_RELEVANCE = 9;
+ public static final int FUNCTION_TYPE_RELEVANCE = 8;
+ public static final int CLASS_TYPE_RELEVANCE = 7;
+ public static final int STRUCT_TYPE_RELEVANCE = 6;
+ public static final int UNION_TYPE_RELEVANCE = 5;
+ public static final int NAMESPACE_TYPE_RELEVANCE = 4;
+ public static final int MACRO_TYPE_RELEVANCE = 3;
+ public static final int ENUMERATION_TYPE_RELEVANCE = 2;
+ public static final int ENUMERATOR_TYPE_RELEVANCE = 1;
+ public static final int DEFAULT_TYPE_RELEVANCE = 0;
-protected IASTCompletionNode parse(IWorkingCopy sourceUnit, int completionOffset){
- ContentAssistElementRequestor requestor = new ContentAssistElementRequestor();
- // Get resource info
- IResource currentResource = sourceUnit.getResource();
- IPath realPath = currentResource.getLocation();
- IProject project = currentResource.getProject();
- Reader reader = new CharArrayReader( sourceUnit.getContents() );
- //Get the scanner info
- IScannerInfo scanInfo = new ScannerInfo();
- IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
- if (provider != null){
- IScannerInfo buildScanInfo = provider.getScannerInformation(project);
- if( buildScanInfo != null )
- scanInfo = new ScannerInfo(buildScanInfo.getDefinedSymbols(), buildScanInfo.getIncludePaths());
+ public CompletionEngine(ICompletionRequestor completionRequestor){
+ completions.clear();
+ requestor = completionRequestor;
}
-
- //C or CPP?
- ParserLanguage language = CoreModel.getDefault().hasCCNature(project) ? ParserLanguage.CPP : ParserLanguage.C;
-
- IParser parser = null;
- try
- {
- IScanner scanner = ParserFactory.createScanner( reader, realPath.toOSString(), scanInfo, ParserMode.COMPLETE_PARSE, language, requestor, ParserUtil.getParserLogService() );
- parser = ParserFactory.createParser( scanner, requestor, ParserMode.COMPLETE_PARSE, language, ParserUtil.getParserLogService() );
+ public int computeTypeRelevance(int type){
+ switch (type){
+ case ICElement.C_FIELD:
+ return FIELD_TYPE_RELEVANCE;
+ case ICElement.C_VARIABLE:
+ case ICElement.C_VARIABLE_DECLARATION:
+ return VARIABLE_TYPE_RELEVANCE;
+ case ICElement.C_METHOD:
+ case ICElement.C_METHOD_DECLARATION:
+ return METHOD_TYPE_RELEVANCE;
+ case ICElement.C_FUNCTION:
+ case ICElement.C_FUNCTION_DECLARATION:
+ return FUNCTION_TYPE_RELEVANCE;
+ case ICElement.C_CLASS:
+ return CLASS_TYPE_RELEVANCE;
+ case ICElement.C_STRUCT:
+ return STRUCT_TYPE_RELEVANCE;
+ case ICElement.C_UNION:
+ return UNION_TYPE_RELEVANCE;
+ case ICElement.C_NAMESPACE:
+ return NAMESPACE_TYPE_RELEVANCE;
+ case ICElement.C_MACRO:
+ return MACRO_TYPE_RELEVANCE;
+ case ICElement.C_ENUMERATION:
+ return ENUMERATION_TYPE_RELEVANCE;
+ case ICElement.C_ENUMERATOR:
+ return ENUMERATOR_TYPE_RELEVANCE;
+ default :
+ return DEFAULT_TYPE_RELEVANCE;
+ }
}
- catch( ParserFactoryException pfe )
- {
-
- }
- if(parser != null){
- IASTCompletionNode result = parser.parse(completionOffset);
- return result;
- } else {
- return null;
- }
-}
-
-public List complete(IWorkingCopy sourceUnit, int completionOffset) {
+
+ private IASTCompletionNode parse(IWorkingCopy sourceUnit, int completionOffset){
+ ContentAssistElementRequestor requestor = new ContentAssistElementRequestor();
+ // Get resource info
+ IResource currentResource = sourceUnit.getResource();
+ IPath realPath = currentResource.getLocation();
+ IProject project = currentResource.getProject();
+ Reader reader = new CharArrayReader( sourceUnit.getContents() );
+
+ //Get the scanner info
+ IScannerInfo scanInfo = new ScannerInfo();
+ IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
+ if (provider != null){
+ IScannerInfo buildScanInfo = provider.getScannerInformation(project);
+ if( buildScanInfo != null )
+ scanInfo = new ScannerInfo(buildScanInfo.getDefinedSymbols(), buildScanInfo.getIncludePaths());
+ }
- // 1- Parse the translation unit
- IASTCompletionNode completionNode = parse(sourceUnit, completionOffset);
+ //C or CPP?
+ ParserLanguage language = CoreModel.getDefault().hasCCNature(project) ? ParserLanguage.CPP : ParserLanguage.C;
- if (completionNode == null)
- return null;
-
- List completions = new ArrayList();
- // 2- Check the return value
- if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.DOT_MEMBER){
- // CompletionOnDotMember
- }
- else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.ARROW_MEMBER){
- // CompletionOnArrowMember
- }
- else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.QUALIFIEDNAME_MEMBER){
- // CompletionOnQualifiedNameMember
- }
- else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.FIELD_TYPE){
- // CompletionOnFieldType
- }
- else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.VARIABLE_TYPE){
- // CompletionOnVariableType
- }
- else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.ARGUMENT_TYPE){
- // CompletionOnArgumentType
- }
- else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.METHOD_RETURN_TYPE){
- // CompletionOnMethodReturnType
- }
- else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.FUNCTIOND_RETURN_TYPE){
- // CompletionOnFunctionReturnType
- }
- else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE){
- // CompletionOnSingleNameReference
- }
- else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.QUALIFIED_NAME_REFERENCE){
- // CompletionOnQualifiedNameReference
- }
- else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.STRUCTURE_REFERENCE){
- // CompletionOnStructureReference
- }
- else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.CLASS_REFERENCE){
- // CompletionOnClassReference
- }
- else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.EXCEPTION_REFERENCE){
- // CompletionOnExceptionReference
- }
- else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.MACRO_REFERENCE){
- // CompletionOnMacroReference
- }
- else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.MESSAGE_SEND){
- // CompletionOnMessageSend
- }
- else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.QUALIFIED_ALLOCATION_EXPRESSION){
- // CompletionOnQualifiedAllocationExpression
- }
- else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.KEYWORD){
- // CompletionOnKeyword
+ IParser parser = null;
+ try
+ {
+ IScanner scanner = ParserFactory.createScanner( reader, realPath.toOSString(), scanInfo, ParserMode.COMPLETE_PARSE, language, requestor, ParserUtil.getParserLogService() );
+ parser = ParserFactory.createParser( scanner, requestor, ParserMode.COMPLETE_PARSE, language, ParserUtil.getParserLogService() );
+ }
+ catch( ParserFactoryException pfe )
+ {
+
+ }
+ if(parser != null){
+ IASTCompletionNode result = parser.parse(completionOffset);
+ return result;
+ } else {
+ return null;
+ }
}
- return completions;
+ private void addToCompletions (LookupResult result){
+ Iterator nodes = result.getNodes();
+ while (nodes.hasNext()){
+ IASTNode node = (IASTNode) nodes.next();
+ if(node instanceof IASTField){
+ int relevance = computeTypeRelevance(ICElement.C_FIELD);
+ IASTField field = (IASTField)node;
+ requestor.acceptField(field.getName(),
+ ASTUtil.getType(field.getAbstractDeclaration()),
+ field.getVisiblity(), completionStart, completionLength, relevance);
+ }
+ }
+ return ;
+ }
+
+ private void completionOnDotMember(IASTCompletionNode completionNode){
+ // Completing after a dot
+ // 1. Get the search scope node
+ IASTNode searchNode = completionNode.getCompletionContext();
+ // 2. lookup fields & add to completion proposals
+ LookupResult result = searchNode.lookup (completionNode.getCompletionPrefix(), IASTNode.LookupKind.FIELDS);
+ addToCompletions (result);
+ // 3. looup methods & add to completion proposals
+ result = searchNode.lookup (completionNode.getCompletionPrefix(), IASTNode.LookupKind.METHODS);
+ addToCompletions (result);
+ // 4. lookup nested structures & add to completion proposals
+ result = searchNode.lookup (completionNode.getCompletionPrefix(), IASTNode.LookupKind.METHODS);
+ addToCompletions (result);
+ }
+
+ public void complete(IWorkingCopy sourceUnit, int completionOffset, List completionList) {
+
+ // 1- Parse the translation unit
+ IASTCompletionNode completionNode = parse(sourceUnit, completionOffset);
+
+ if (completionNode == null)
+ return;
+
+ // set the completionStart and the completionLength
+ completionStart = completionOffset;
+ completionLength = completionNode.getCompletionPrefix().length();
+
+ // 2- Check the return value
+ if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.DOT_MEMBER){
+ completionOnDotMember(completionNode);
+ }
+ else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.ARROW_MEMBER){
+ // CompletionOnArrowMember
+ }
+ else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.QUALIFIEDNAME_MEMBER){
+ // CompletionOnQualifiedNameMember
+ }
+ else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.FIELD_TYPE){
+ // CompletionOnFieldType
+ }
+ else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.VARIABLE_TYPE){
+ // CompletionOnVariableType
+ }
+ else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.ARGUMENT_TYPE){
+ // CompletionOnArgumentType
+ }
+ else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.METHOD_RETURN_TYPE){
+ // CompletionOnMethodReturnType
+ }
+ else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.FUNCTIOND_RETURN_TYPE){
+ // CompletionOnFunctionReturnType
+ }
+ else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE){
+ // CompletionOnSingleNameReference
+ }
+ else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.QUALIFIED_NAME_REFERENCE){
+ // CompletionOnQualifiedNameReference
+ }
+ else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.STRUCTURE_REFERENCE){
+ // CompletionOnStructureReference
+ }
+ else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.CLASS_REFERENCE){
+ // CompletionOnClassReference
+ }
+ else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.EXCEPTION_REFERENCE){
+ // CompletionOnExceptionReference
+ }
+ else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.MACRO_REFERENCE){
+ // CompletionOnMacroReference
+ }
+ else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.MESSAGE_SEND){
+ // CompletionOnMessageSend
+ }
+ else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.QUALIFIED_ALLOCATION_EXPRESSION){
+ // CompletionOnQualifiedAllocationExpression
+ }
+ else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.KEYWORD){
+ // CompletionOnKeyword
+ }
+
+ completionList.addAll(completions);
+ return;
+
+ }
-}
-
}
\ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/contentassist/CompletionRequestorAdaptor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/contentassist/CompletionRequestorAdaptor.java
new file mode 100644
index 00000000000..a4261b6321c
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/contentassist/CompletionRequestorAdaptor.java
@@ -0,0 +1,128 @@
+/**********************************************************************
+ * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Rational Software - Initial API and implementation
+***********************************************************************/
+package org.eclipse.cdt.internal.core.contentassist;
+
+import org.eclipse.cdt.core.ICompletionRequestor;
+import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
+
+/**
+ * @author hamer
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class CompletionRequestorAdaptor implements ICompletionRequestor {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptField(java.lang.String, java.lang.String)
+ */
+ public void acceptField(String name, String returnType, ASTAccessVisibility visibility, int completionStart, int completionLength, int relevance) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptClass(java.lang.String)
+ */
+ public void acceptClass(String name, int completionStart, int completionLength, int relevance) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptEnumeration(java.lang.String)
+ */
+ public void acceptEnumeration(String name, int completionStart, int completionLength, int relevance) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptFunction(java.lang.String, java.lang.String, java.lang.String)
+ */
+ public void acceptFunction(
+ String name,
+ String parameterString,
+ String returnType, int completionStart, int completionLength, int relevance) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptMacro(java.lang.String)
+ */
+ public void acceptMacro(String name, int completionStart, int completionLength, int relevance) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptMethod(java.lang.String, java.lang.String, java.lang.String)
+ */
+ public void acceptMethod(
+ String name,
+ String parameterString,
+ String returnType, ASTAccessVisibility visibility, int completionStart, int completionLength, int relevance) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptStruct(java.lang.String)
+ */
+ public void acceptStruct(String name, int completionStart, int completionLength, int relevance) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptUnion(java.lang.String)
+ */
+ public void acceptUnion(String name, int completionStart, int completionLength, int relevance) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptVariable(java.lang.String, java.lang.String)
+ */
+ public void acceptVariable(String name, String returnType, int completionStart, int completionLength, int relevance) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptLocalVariable(java.lang.String, java.lang.String)
+ */
+ public void acceptLocalVariable(String name, String returnType, int completionStart, int completionLength, int relevance) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptNamespace(java.lang.String)
+ */
+ public void acceptNamespace(String name, int completionStart, int completionLength, int relevance) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptEnumerator(java.lang.String, int, int, int)
+ */
+ public void acceptEnumerator(
+ String name,
+ int completionStart,
+ int completionLength,
+ int relevance) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/.project b/core/org.eclipse.cdt.ui/.project
index 04403a7b87c..b2b4dfed198 100644
--- a/core/org.eclipse.cdt.ui/.project
+++ b/core/org.eclipse.cdt.ui/.project
@@ -4,6 +4,19 @@
org.eclipse.cdt.core
+ org.eclipse.compare
+ org.eclipse.core.boot
+ org.eclipse.core.resources
+ org.eclipse.core.runtime
+ org.eclipse.debug.core
+ org.eclipse.debug.ui
+ org.eclipse.jface.text
+ org.eclipse.search
+ org.eclipse.ui
+ org.eclipse.ui.editors
+ org.eclipse.ui.ide
+ org.eclipse.ui.views
+ org.eclipse.ui.workbench.texteditor
diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog
index aab1389aacd..22e104ea079 100644
--- a/core/org.eclipse.cdt.ui/ChangeLog
+++ b/core/org.eclipse.cdt.ui/ChangeLog
@@ -1,3 +1,8 @@
+2003-11-27 Hoda Amer
+ Content Assist work : Added a ResultCollector class
+ and moved the ICCompletionProposal from an internal package
+ to an external one.
+
2003-11-14 David Inglis
Fixed bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=46685
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CElementImageProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CElementImageProvider.java
index 295658813c8..2fb1c50180f 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CElementImageProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CElementImageProvider.java
@@ -285,74 +285,63 @@ public class CElementImageProvider {
case ICElement.C_STRUCT:
case ICElement.C_TEMPLATE_STRUCT:
- return CPluginImages.DESC_OBJS_STRUCT;
+ return getStructImageDescriptor();
case ICElement.C_CLASS:
case ICElement.C_TEMPLATE_CLASS:
- return CPluginImages.DESC_OBJS_CLASS;
+ return getClassImageDescriptor();
case ICElement.C_UNION:
case ICElement.C_TEMPLATE_UNION:
- return CPluginImages.DESC_OBJS_UNION;
+ return getUnionImageDescriptor();
case ICElement.C_TYPEDEF:
- return CPluginImages.DESC_OBJS_TYPEDEF;
+ return getTypedefImageDescriptor();
case ICElement.C_ENUMERATION:
- return CPluginImages.DESC_OBJS_ENUMERATION;
+ return getEnumerationImageDescriptor();
case ICElement.C_ENUMERATOR:
- return CPluginImages.DESC_OBJS_ENUMERATOR;
+ return getEnumeratorImageDescriptor();
case ICElement.C_FIELD:
{
- IField field = (IField)celement;
- ASTAccessVisibility visibility = field.getVisibility();
-
- if (visibility == ASTAccessVisibility.PUBLIC)
- return CPluginImages.DESC_OBJS_PUBLIC_FIELD;
- if( visibility == ASTAccessVisibility.PROTECTED)
- return CPluginImages.DESC_OBJS_PROTECTED_FIELD;
- if( visibility == ASTAccessVisibility.PRIVATE)
- return CPluginImages.DESC_OBJS_PRIVATE_FIELD;
+ IField field = (IField)celement;
+ ASTAccessVisibility visibility = field.getVisibility();
+ return getFieldImageDescriptor(visibility);
}
- case ICElement.C_VARIABLE:
- case ICElement.C_TEMPLATE_VARIABLE:
- return CPluginImages.DESC_OBJS_FIELD;
-
case ICElement.C_METHOD:
case ICElement.C_METHOD_DECLARATION:
case ICElement.C_TEMPLATE_METHOD:
{
IMethodDeclaration md= (IMethodDeclaration)celement;
- ASTAccessVisibility visibility =md.getVisibility();
- if( visibility == ASTAccessVisibility.PUBLIC)
- return CPluginImages.DESC_OBJS_PUBLIC_METHOD;
- if( visibility == ASTAccessVisibility.PROTECTED)
- return CPluginImages.DESC_OBJS_PROTECTED_METHOD;
- if( visibility == ASTAccessVisibility.PRIVATE)
- return CPluginImages.DESC_OBJS_PRIVATE_METHOD;
- }
+ ASTAccessVisibility visibility =md.getVisibility();
+ return getMethodImageDescriptor(visibility);
+ }
+
+ case ICElement.C_VARIABLE:
+ case ICElement.C_TEMPLATE_VARIABLE:
+ return getVariableImageDescriptor();
case ICElement.C_FUNCTION:
- return CPluginImages.DESC_OBJS_FUNCTION;
+ return getFunctionImageDescriptor();
case ICElement.C_VARIABLE_DECLARATION:
- return CPluginImages.DESC_OBJS_VAR_DECLARARION;
+ return getVariableDeclarationImageDescriptor();
case ICElement.C_FUNCTION_DECLARATION:
case ICElement.C_TEMPLATE_FUNCTION:
- return CPluginImages.DESC_OBJS_DECLARARION;
+ return getFunctionDeclarationImageDescriptor();
case ICElement.C_INCLUDE:
- return CPluginImages.DESC_OBJS_INCLUDE;
+ return getIncludeImageDescriptor();
case ICElement.C_MACRO:
- return CPluginImages.DESC_OBJS_MACRO;
+ return getMacroImageDescriptor();
case ICElement.C_NAMESPACE:
- return CPluginImages.DESC_OBJS_CONTAINER;
+ return getNamespaceImageDescriptor();
}
return null;
@@ -403,4 +392,75 @@ public class CElementImageProvider {
public void dispose() {
}
+ public static ImageDescriptor getStructImageDescriptor(){
+ return CPluginImages.DESC_OBJS_STRUCT;
+ }
+
+ public static ImageDescriptor getClassImageDescriptor(){
+ return CPluginImages.DESC_OBJS_CLASS;
+ }
+
+ public static ImageDescriptor getUnionImageDescriptor(){
+ return CPluginImages.DESC_OBJS_UNION;
+ }
+
+ public static ImageDescriptor getTypedefImageDescriptor(){
+ return CPluginImages.DESC_OBJS_TYPEDEF;
+ }
+
+ public static ImageDescriptor getEnumerationImageDescriptor(){
+ return CPluginImages.DESC_OBJS_ENUMERATION;
+ }
+
+ public static ImageDescriptor getEnumeratorImageDescriptor(){
+ return CPluginImages.DESC_OBJS_ENUMERATOR;
+ }
+
+ public static ImageDescriptor getFieldImageDescriptor(ASTAccessVisibility visibility) {
+ if (visibility == ASTAccessVisibility.PUBLIC)
+ return CPluginImages.DESC_OBJS_PUBLIC_FIELD;
+ if( visibility == ASTAccessVisibility.PROTECTED)
+ return CPluginImages.DESC_OBJS_PROTECTED_FIELD;
+
+ return CPluginImages.DESC_OBJS_PRIVATE_FIELD;
+ }
+
+ public static ImageDescriptor getMethodImageDescriptor(ASTAccessVisibility visibility) {
+ if( visibility == ASTAccessVisibility.PUBLIC)
+ return CPluginImages.DESC_OBJS_PUBLIC_METHOD;
+ if( visibility == ASTAccessVisibility.PROTECTED)
+ return CPluginImages.DESC_OBJS_PROTECTED_METHOD;
+
+ return CPluginImages.DESC_OBJS_PRIVATE_METHOD;
+
+ }
+
+ public static ImageDescriptor getVariableImageDescriptor(){
+ return CPluginImages.DESC_OBJS_FIELD;
+ }
+
+ public static ImageDescriptor getFunctionImageDescriptor(){
+ return CPluginImages.DESC_OBJS_FUNCTION;
+ }
+
+ public static ImageDescriptor getVariableDeclarationImageDescriptor(){
+ return CPluginImages.DESC_OBJS_VAR_DECLARARION;
+ }
+
+ public static ImageDescriptor getFunctionDeclarationImageDescriptor(){
+ return CPluginImages.DESC_OBJS_DECLARARION;
+ }
+
+ public static ImageDescriptor getIncludeImageDescriptor(){
+ return CPluginImages.DESC_OBJS_INCLUDE;
+ }
+
+ public static ImageDescriptor getMacroImageDescriptor(){
+ return CPluginImages.DESC_OBJS_MACRO;
+ }
+
+ public static ImageDescriptor getNamespaceImageDescriptor(){
+ return CPluginImages.DESC_OBJS_CONTAINER;
+ }
+
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java
index 118362f3d0a..670c39740ca 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java
@@ -26,6 +26,7 @@ import org.eclipse.cdt.core.search.BasicSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.SearchEngine;
+import org.eclipse.cdt.internal.core.contentassist.CompletionEngine;
import org.eclipse.cdt.internal.core.model.CElement;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.matching.OrPattern;
@@ -41,6 +42,7 @@ import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.FunctionPrototypeSummary;
import org.eclipse.cdt.ui.IFunctionSummary;
import org.eclipse.cdt.ui.IWorkingCopyManager;
+import org.eclipse.cdt.ui.text.*;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -73,7 +75,10 @@ public class CCompletionProcessor implements IContentAssistProcessor {
private boolean fRestrictToMatchingCase;
private boolean fAllowAddIncludes;
- BasicSearchResultCollector resultCollector = null;
+ BasicSearchResultCollector searchResultCollector = null;
+ ResultCollector resultCollector = null;
+ CompletionEngine completionEngine = null;
+
SearchEngine searchEngine = null;
CSearchResultLabelProvider labelProvider = null;
@@ -82,7 +87,9 @@ public class CCompletionProcessor implements IContentAssistProcessor {
// Needed for search
labelProvider = new CSearchResultLabelProvider();
- resultCollector = new BasicSearchResultCollector ();
+ searchResultCollector = new BasicSearchResultCollector ();
+ resultCollector = new ResultCollector();
+ completionEngine = new CompletionEngine(resultCollector);
searchEngine = new SearchEngine();
//Determine if this is a C or a C++ file for the context completion + //This is _totally_ ugly and likely belongs in the main editor class.
@@ -457,36 +464,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
}
}
- private int calculateRelevance (BasicSearchMatch element){
-
- int type = element.getElementType();
-
- switch (type){
- case ICElement.C_FIELD:
- return 9;
- case ICElement.C_VARIABLE:
- case ICElement.C_VARIABLE_DECLARATION:
- return 8;
- case ICElement.C_METHOD:
- case ICElement.C_METHOD_DECLARATION:
- return 7;
- case ICElement.C_FUNCTION:
- case ICElement.C_FUNCTION_DECLARATION:
- return 6;
- case ICElement.C_CLASS:
- return 5;
- case ICElement.C_STRUCT:
- return 4;
- case ICElement.C_UNION:
- return 3;
- case ICElement.C_MACRO:
- return 2;
- case ICElement.C_ENUMERATION:
- return 1;
- default :
- return 0;
- }
- }
+
private void addProposalsFromModel (IRegion region, String frag, ICElement currentScope, ArrayList completions) {
List elementsFound = new LinkedList();
String prefix = frag + "*";
@@ -529,8 +507,8 @@ public class CCompletionProcessor implements IContentAssistProcessor {
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.TYPE, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.ENUM, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.MACRO, ICSearchConstants.DECLARATIONS, false ));
- searchEngine.search(CUIPlugin.getWorkspace(), orPattern, scope, resultCollector, true);
- elementsFound.addAll(resultCollector.getSearchResults());
+ searchEngine.search(CUIPlugin.getWorkspace(), orPattern, scope, searchResultCollector, true);
+ elementsFound.addAll(searchResultCollector.getSearchResults());
if((currentScope instanceof IMethod) || (currentScope instanceof IMethodDeclaration) ){
// add the methods and fields of the parent class
@@ -571,57 +549,131 @@ public class CCompletionProcessor implements IContentAssistProcessor {
}
+ int completionStart = region.getOffset();
+ int completionLength = region.getLength();
Iterator i = elementsFound.iterator();
while (i.hasNext()){
- CCompletionProposal proposal;
- String replaceString = "";
- String displayString = "";
- Image image = null;
- StringBuffer infoString = new StringBuffer();
+ ASTAccessVisibility visibility;
BasicSearchMatch match = (BasicSearchMatch)i.next();
-
- //Make sure we replace with the appropriate string for functions and methods
- FunctionPrototypeSummary fproto = getPrototype(match);
- if(fproto != null) {
- replaceString = fproto.getName() + "()";
- displayString = fproto.getPrototypeString(true);
- } else {
- replaceString =
- displayString = match.getName();;
+ int type = match.getElementType();
+ switch (type){
+ case ICElement.C_FIELD:
+ switch (match.getVisibility()){
+ case ICElement.CPP_PUBLIC:
+ visibility = ASTAccessVisibility.PUBLIC;
+ break;
+ case ICElement.CPP_PROTECTED:
+ visibility = ASTAccessVisibility.PROTECTED;
+ break;
+ default:
+ visibility = ASTAccessVisibility.PRIVATE;
+ break;
+ };
+ resultCollector.acceptField(
+ match.getName(),
+ null,
+ visibility,
+ completionStart,
+ completionLength,
+ completionEngine.computeTypeRelevance(type));
+ break;
+
+ case ICElement.C_VARIABLE:
+ case ICElement.C_VARIABLE_DECLARATION:
+ resultCollector.acceptVariable(
+ match.getName(),
+ null,
+ completionStart,
+ completionLength,
+ completionEngine.computeTypeRelevance(type));
+ break;
+ case ICElement.C_METHOD:
+ case ICElement.C_METHOD_DECLARATION:
+ switch (match.getVisibility()){
+ case ICElement.CPP_PUBLIC:
+ visibility = ASTAccessVisibility.PUBLIC;
+ break;
+ case ICElement.CPP_PROTECTED:
+ visibility = ASTAccessVisibility.PROTECTED;
+ break;
+ default:
+ visibility = ASTAccessVisibility.PRIVATE;
+ break;
+ };
+ resultCollector.acceptMethod(
+ match.getName(),
+ null,
+ match.getReturnType(),
+ visibility,
+ completionStart,
+ completionLength,
+ completionEngine.computeTypeRelevance(type));
+ break;
+ case ICElement.C_FUNCTION:
+ case ICElement.C_FUNCTION_DECLARATION:
+ resultCollector.acceptFunction(
+ match.getName(),
+ null,
+ match.getReturnType(),
+ completionStart,
+ completionLength,
+ completionEngine.computeTypeRelevance(type));
+ break;
+ case ICElement.C_CLASS:
+ resultCollector.acceptClass(
+ match.getName(),
+ completionStart,
+ completionLength,
+ completionEngine.computeTypeRelevance(type));
+ break;
+ case ICElement.C_STRUCT:
+ resultCollector.acceptStruct(
+ match.getName(),
+ completionStart,
+ completionLength,
+ completionEngine.computeTypeRelevance(type));
+ break;
+ case ICElement.C_UNION:
+ resultCollector.acceptUnion(
+ match.getName(),
+ completionStart,
+ completionLength,
+ completionEngine.computeTypeRelevance(type));
+ break;
+ case ICElement.C_NAMESPACE:
+ resultCollector.acceptNamespace(
+ match.getName(),
+ completionStart,
+ completionLength,
+ completionEngine.computeTypeRelevance(type));
+ break;
+ case ICElement.C_MACRO:
+ resultCollector.acceptMacro(
+ match.getName(),
+ completionStart,
+ completionLength,
+ completionEngine.computeTypeRelevance(type));
+ break;
+ case ICElement.C_ENUMERATION:
+ resultCollector.acceptEnumeration(
+ match.getName(),
+ completionStart,
+ completionLength,
+ completionEngine.computeTypeRelevance(type));
+ break;
+ case ICElement.C_ENUMERATOR:
+ resultCollector.acceptEnumerator(
+ match.getName(),
+ completionStart,
+ completionLength,
+ completionEngine.computeTypeRelevance(type));
+ break;
+ default :
+ break;
}
-
- image = labelProvider.getImage(match);
- infoString.append(displayString);
- if(match.getParentName().length() > 0) {
- infoString.append(" - Parent: ");
- infoString.append(match.getParentName());
- }
-
- proposal = new CCompletionProposal(
- replaceString, // Replacement string
- region.getOffset(),
- region.getLength(),
- image,
- displayString, // Display string
- calculateRelevance(match)
- );
- completions.add(proposal);
-
- // No summary information available yet
- // context information is available for methods only
- if(fproto != null){
- String fargs = fproto.getArguments();
- if(fargs != null && fargs.length() > 0) {
- proposal.setContextInformation(new ContextInformation(replaceString, fargs));
- }
- }
-
- // The info string could be populated with documentation info.
- // For now, it has the name and the parent's name if available.
- if(!displayString.equals(infoString.toString()))
- proposal.setAdditionalProposalInfo(infoString.toString());
}
+ completions.addAll(resultCollector.getCompletions());
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProposal.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProposal.java
index e622b3f2f3c..0487aa1444d 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProposal.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProposal.java
@@ -5,6 +5,7 @@ package org.eclipse.cdt.internal.ui.text;
* All Rights Reserved.
*/
+import org.eclipse.cdt.ui.text.*;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProposalComparator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProposalComparator.java
index cc7fc40ca14..fbc039195fc 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProposalComparator.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProposalComparator.java
@@ -7,6 +7,8 @@ package org.eclipse.cdt.internal.ui.text;
import java.util.Comparator;
+import org.eclipse.cdt.ui.text.*;
+
public class CCompletionProposalComparator implements Comparator {
private boolean fOrderAlphabetically;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ResultCollector.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ResultCollector.java
new file mode 100644
index 00000000000..de9023bae43
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ResultCollector.java
@@ -0,0 +1,423 @@
+/**********************************************************************
+ * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Rational Software - Initial API and implementation
+***********************************************************************/
+package org.eclipse.cdt.internal.ui.text;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
+import org.eclipse.cdt.internal.core.contentassist.CompletionRequestorAdaptor;
+import org.eclipse.cdt.internal.ui.CElementImageProvider;
+import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry;
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.FunctionPrototypeSummary;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.text.contentassist.ContextInformation;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * @author hamer
+ *
+ * The Result Collector class receives information from the completion engine
+ * as a completion requestor. It might also receive information from others
+ * such as the results of a search operation to generate completion proposals.
+ *
+ */
+public class ResultCollector extends CompletionRequestorAdaptor {
+ private List completions = new ArrayList();
+ private ImageDescriptorRegistry registry = CUIPlugin.getImageDescriptorRegistry();
+
+ public ResultCollector(){
+ completions.clear();
+ }
+
+ /**
+ * @return the completion list
+ */
+ public List getCompletions() {
+ return completions;
+ }
+ /*
+ * Create a proposal
+ */
+ public ICompletionProposal createProposal(String replaceString, String displayString, String infoString, String arguments, Image image, int offset, int length, int relevance){
+ CCompletionProposal proposal;
+
+ proposal = new CCompletionProposal(
+ replaceString, // Replacement string
+ offset,
+ length,
+ image,
+ displayString, // Display string
+ relevance
+ );
+
+ if(arguments != null && arguments.length() > 0) {
+ proposal.setContextInformation(new ContextInformation(replaceString, arguments));
+ }
+
+ // The info string could be populated with documentation info.
+ // For now, it has the name and the parent's name if available.
+ if((infoString != null)&& (!displayString.equals(infoString)))
+ proposal.setAdditionalProposalInfo(infoString);
+
+ return proposal;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptField(java.lang.String, java.lang.String, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility, int, int, int)
+ */
+ public void acceptField(String name, String returnType, ASTAccessVisibility visibility,
+ int completionStart, int completionLength, int relevance) {
+ String replaceString = "";
+ String displayString = "";
+ Image image = null;
+ StringBuffer infoString = new StringBuffer();
+
+ // fill the replace, display and info strings
+ replaceString = name;
+ displayString = name;
+ if(returnType != null)
+ displayString+= " : " + returnType;
+
+ // get the image
+ ImageDescriptor imageDescriptor = CElementImageProvider.getFieldImageDescriptor(visibility);
+ image = registry.get( imageDescriptor );
+
+ // create proposal and add it to completions list
+ ICompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
+ null, image, completionStart, completionLength, relevance);
+ completions.add(proposal);
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptClass(java.lang.String, int, int, int)
+ */
+ public void acceptClass(
+ String name,
+ int completionStart,
+ int completionLength,
+ int relevance) {
+ String replaceString = "";
+ String displayString = "";
+ Image image = null;
+ StringBuffer infoString = new StringBuffer();
+
+ // fill the replace, display and info strings
+ replaceString = name;
+ displayString = name;
+
+ // get the image
+ ImageDescriptor imageDescriptor = CElementImageProvider.getClassImageDescriptor();
+ image = registry.get( imageDescriptor );
+
+ // create proposal and add it to completions list
+ ICompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
+ null, image, completionStart, completionLength, relevance);
+ completions.add(proposal);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptFunction(java.lang.String, java.lang.String, java.lang.String, int, int, int)
+ */
+ public void acceptFunction(
+ String name,
+ String parameterString,
+ String returnType,
+ int completionStart,
+ int completionLength,
+ int relevance) {
+ String replaceString = "";
+ String displayString = "";
+ String arguments = "";
+
+ Image image = null;
+ StringBuffer infoString = new StringBuffer();
+
+ // fill the replace, display and info strings
+ replaceString = name;
+ displayString = name;
+ String functionPrototype = returnType + " " + name;
+ if(parameterString != null)
+ functionPrototype += "(" + parameterString + ")";
+
+ FunctionPrototypeSummary fproto = new FunctionPrototypeSummary(functionPrototype);
+ if(fproto != null) {
+ replaceString = fproto.getName() + "()";
+ displayString = fproto.getPrototypeString(true);
+ infoString.append(displayString);
+ arguments = fproto.getArguments();
+ }
+
+ // get the image
+ ImageDescriptor imageDescriptor = CElementImageProvider.getFunctionImageDescriptor();
+ image = registry.get( imageDescriptor );
+
+ // create proposal and add it to completions list
+ ICompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
+ arguments, image, completionStart, completionLength, relevance);
+ completions.add(proposal);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptLocalVariable(java.lang.String, java.lang.String, int, int, int)
+ */
+ public void acceptLocalVariable(
+ String name,
+ String returnType,
+ int completionStart,
+ int completionLength,
+ int relevance) {
+
+ super.acceptLocalVariable(
+ name,
+ returnType,
+ completionStart,
+ completionLength,
+ relevance);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptMacro(java.lang.String, int, int, int)
+ */
+ public void acceptMacro(
+ String name,
+ int completionStart,
+ int completionLength,
+ int relevance) {
+
+ String replaceString = "";
+ String displayString = "";
+ Image image = null;
+ StringBuffer infoString = new StringBuffer();
+
+ // fill the replace, display and info strings
+ replaceString = name;
+ displayString = name;
+
+ // get the image
+ ImageDescriptor imageDescriptor = CElementImageProvider.getMacroImageDescriptor();
+ image = registry.get( imageDescriptor );
+
+ // create proposal and add it to completions list
+ ICompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
+ null, image, completionStart, completionLength, relevance);
+ completions.add(proposal);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptMethod(java.lang.String, java.lang.String, java.lang.String, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility, int, int, int)
+ */
+ public void acceptMethod(
+ String name,
+ String parameterString,
+ String returnType,
+ ASTAccessVisibility visibility,
+ int completionStart,
+ int completionLength,
+ int relevance) {
+
+ String replaceString = "";
+ String displayString = "";
+ String arguments = "";
+ Image image = null;
+ StringBuffer infoString = new StringBuffer();
+
+ // fill the replace, display and info strings
+ replaceString = name;
+ displayString = name;
+ String functionPrototype = returnType + " " + name;
+ if(parameterString != null)
+ functionPrototype += "(" + parameterString + ")";
+
+ FunctionPrototypeSummary fproto = new FunctionPrototypeSummary(functionPrototype);
+ if(fproto != null) {
+ replaceString = fproto.getName() + "()";
+ displayString = fproto.getPrototypeString(true);
+ infoString.append(displayString);
+ arguments = fproto.getArguments();
+ }
+
+ // get the image
+ ImageDescriptor imageDescriptor = CElementImageProvider.getMethodImageDescriptor(visibility);
+ image = registry.get( imageDescriptor );
+
+ // create proposal and add it to completions list
+ ICompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
+ arguments, image, completionStart, completionLength, relevance);
+ completions.add(proposal);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptNamespace(java.lang.String, int, int, int)
+ */
+ public void acceptNamespace(
+ String name,
+ int completionStart,
+ int completionLength,
+ int relevance) {
+ String replaceString = "";
+ String displayString = "";
+ Image image = null;
+ StringBuffer infoString = new StringBuffer();
+
+ // fill the replace, display and info strings
+ replaceString = name;
+ displayString = name;
+
+ // get the image
+ ImageDescriptor imageDescriptor = CElementImageProvider.getNamespaceImageDescriptor();
+ image = registry.get( imageDescriptor );
+
+ // create proposal and add it to completions list
+ ICompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
+ null, image, completionStart, completionLength, relevance);
+ completions.add(proposal);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptStruct(java.lang.String, int, int, int)
+ */
+ public void acceptStruct(
+ String name,
+ int completionStart,
+ int completionLength,
+ int relevance) {
+ String replaceString = "";
+ String displayString = "";
+ Image image = null;
+ StringBuffer infoString = new StringBuffer();
+
+ // fill the replace, display and info strings
+ replaceString = name;
+ displayString = name;
+
+ // get the image
+ ImageDescriptor imageDescriptor = CElementImageProvider.getStructImageDescriptor();
+ image = registry.get( imageDescriptor );
+
+ // create proposal and add it to completions list
+ ICompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(), null, image, completionStart, completionLength, relevance);
+ completions.add(proposal);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptUnion(java.lang.String, int, int, int)
+ */
+ public void acceptUnion(
+ String name,
+ int completionStart,
+ int completionLength,
+ int relevance) {
+ String replaceString = "";
+ String displayString = "";
+ Image image = null;
+ StringBuffer infoString = new StringBuffer();
+
+ // fill the replace, display and info strings
+ replaceString = name;
+ displayString = name;
+
+ // get the image
+ ImageDescriptor imageDescriptor = CElementImageProvider.getUnionImageDescriptor();
+ image = registry.get( imageDescriptor );
+
+ // create proposal and add it to completions list
+ ICompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(), null, image, completionStart, completionLength, relevance);
+ completions.add(proposal);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptVariable(java.lang.String, java.lang.String, int, int, int)
+ */
+ public void acceptVariable(
+ String name,
+ String returnType,
+ int completionStart,
+ int completionLength,
+ int relevance) {
+ String replaceString = "";
+ String displayString = "";
+ Image image = null;
+ StringBuffer infoString = new StringBuffer();
+
+ // fill the replace, display and info strings
+ replaceString = name;
+ displayString = name;
+ if(returnType != null)
+ displayString+= " : " + returnType;
+
+ // get the image
+ ImageDescriptor imageDescriptor = CElementImageProvider.getVariableImageDescriptor();
+ image = registry.get( imageDescriptor );
+
+ // create proposal and add it to completions list
+ ICompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(), null, image, completionStart, completionLength, relevance);
+ completions.add(proposal);
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptEnumeration(java.lang.String, int, int, int)
+ */
+ public void acceptEnumeration(
+ String name,
+ int completionStart,
+ int completionLength,
+ int relevance) {
+ String replaceString = "";
+ String displayString = "";
+ Image image = null;
+ StringBuffer infoString = new StringBuffer();
+
+ // fill the replace, display and info strings
+ replaceString = name;
+ displayString = name;
+
+ // get the image
+ ImageDescriptor imageDescriptor = CElementImageProvider.getEnumerationImageDescriptor();
+ image = registry.get( imageDescriptor );
+
+ // create proposal and add it to completions list
+ ICompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
+ null, image, completionStart, completionLength, relevance);
+ completions.add(proposal);
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.ICompletionRequestor#acceptEnumerator(java.lang.String, int, int, int)
+ */
+ public void acceptEnumerator(
+ String name,
+ int completionStart,
+ int completionLength,
+ int relevance) {
+ String replaceString = "";
+ String displayString = "";
+ Image image = null;
+ StringBuffer infoString = new StringBuffer();
+
+ // fill the replace, display and info strings
+ replaceString = name;
+ displayString = name;
+
+ // get the image
+ ImageDescriptor imageDescriptor = CElementImageProvider.getEnumeratorImageDescriptor();
+ image = registry.get( imageDescriptor );
+
+ // create proposal and add it to completions list
+ ICompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
+ null, image, completionStart, completionLength, relevance);
+ completions.add(proposal);
+ }
+
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/template/TemplateEngine.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/template/TemplateEngine.java
index e3e7a4ae012..42bcd1eb5db 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/template/TemplateEngine.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/template/TemplateEngine.java
@@ -12,8 +12,9 @@ import org.eclipse.cdt.internal.corext.template.Templates;
import org.eclipse.cdt.internal.corext.template.c.CompilationUnitContext;
import org.eclipse.cdt.internal.corext.template.c.CompilationUnitContextType;
import org.eclipse.cdt.internal.corext.template.c.ICompilationUnit;
-import org.eclipse.cdt.internal.ui.text.ICCompletionProposal;
import org.eclipse.cdt.internal.ui.text.link.LinkedPositionManager;
+import org.eclipse.cdt.ui.text.ICCompletionProposal;
+
import java.util.ArrayList;
import org.eclipse.jface.text.IDocument;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/template/TemplateProposal.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/template/TemplateProposal.java
index bc73c95ba8e..b0bd246a09b 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/template/TemplateProposal.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/template/TemplateProposal.java
@@ -10,10 +10,10 @@ import org.eclipse.cdt.internal.corext.template.TemplateBuffer;
import org.eclipse.cdt.internal.corext.template.TemplateContext;
import org.eclipse.cdt.internal.corext.template.TemplateMessages;
import org.eclipse.cdt.internal.corext.template.TemplatePosition;
-import org.eclipse.cdt.internal.ui.text.ICCompletionProposal;
import org.eclipse.cdt.internal.ui.text.link.LinkedPositionManager;
import org.eclipse.cdt.internal.ui.text.link.LinkedPositionUI;
import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.text.ICCompletionProposal;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.swt.graphics.Image;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ICCompletionProposal.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/ICCompletionProposal.java
similarity index 95%
rename from core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ICCompletionProposal.java
rename to core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/ICCompletionProposal.java
index 532b9a623aa..01bb51f67ee 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ICCompletionProposal.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/ICCompletionProposal.java
@@ -1,4 +1,4 @@
-package org.eclipse.cdt.internal.ui.text;
+package org.eclipse.cdt.ui.text;
/*******************************************************************************
* Copyright (c) 2000, 2002 International Business Machines Corp. and others.
@@ -14,7 +14,7 @@ package org.eclipse.cdt.internal.ui.text;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
-/*
+/**
* CompletionProposal with a relevance value.
* The relevance value is used to sort the completion proposals. Proposals with higher relevance
* should be listed before proposals with lower relevance.