1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 01:05:38 +02:00

Fix for 178577: need IASTCompletionNode interface in dom parser (patch by Mike Kucera)

This commit is contained in:
Anton Leherbauer 2007-03-22 14:28:35 +00:00
parent b0bdfa4229
commit 34cf7052a6
21 changed files with 130 additions and 96 deletions

View file

@ -11,7 +11,7 @@
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.prefix;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction;
@ -20,7 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IVariable;
public class BasicCompletionTest extends CompletionTestBase {
private void testVar(ASTCompletionNode node) throws Exception {
private void testVar(IASTCompletionNode node) throws Exception {
IASTName[] names = node.getNames();
assertEquals(1, names.length);
IBinding[] bindings = names[0].getCompletionContext().findBindings(
@ -44,7 +44,7 @@ public class BasicCompletionTest extends CompletionTestBase {
code.append("void func2() { fu");
// C++
ASTCompletionNode node = getGPPCompletionNode(code.toString());
IASTCompletionNode node = getGPPCompletionNode(code.toString());
IASTName[] names = node.getNames();
// There are three names, one as an expression, one that isn't connected, one as a declaration
assertEquals(3, names.length);
@ -82,7 +82,7 @@ public class BasicCompletionTest extends CompletionTestBase {
code.append("bl");
// C++
ASTCompletionNode node = getGPPCompletionNode(code.toString());
IASTCompletionNode node = getGPPCompletionNode(code.toString());
IASTName[] names = node.getNames();
assertEquals(2, names.length);
assertNull(names[0].getTranslationUnit());

View file

@ -15,7 +15,7 @@ import java.util.Comparator;
import junit.framework.TestCase;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.ISourceCodeParser;
@ -44,7 +44,7 @@ public class CompletionTestBase extends TestCase {
private static final IParserLogService NULL_LOG = new NullLogService();
protected ASTCompletionNode getCompletionNode(String code, ParserLanguage lang, boolean useGNUExtensions) throws ParserException {
protected IASTCompletionNode getCompletionNode(String code, ParserLanguage lang, boolean useGNUExtensions) throws ParserException {
CodeReader codeReader = new CodeReader(code.toCharArray());
ScannerInfo scannerInfo = new ScannerInfo();
IScannerExtensionConfiguration configuration = null;
@ -84,11 +84,11 @@ public class CompletionTestBase extends TestCase {
return parser.getCompletionNode();
}
protected ASTCompletionNode getGPPCompletionNode(String code) throws ParserException {
protected IASTCompletionNode getGPPCompletionNode(String code) throws ParserException {
return getCompletionNode(code, ParserLanguage.CPP, true);
}
protected ASTCompletionNode getGCCCompletionNode(String code) throws ParserException {
protected IASTCompletionNode getGCCCompletionNode(String code) throws ParserException {
return getCompletionNode(code, ParserLanguage.C, true);
}

View file

@ -14,7 +14,7 @@
package org.eclipse.cdt.core.model;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndex;
@ -95,7 +95,7 @@ public interface ILanguage extends IAdaptable {
* @return
* @throws CoreException
*/
public ASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException;
public IASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException;
/**

View file

@ -13,7 +13,7 @@ package org.eclipse.cdt.core.model;
import java.util.Map;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.parser.CodeReader;
@ -479,5 +479,5 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
* @return
* @throws CoreException
*/
public ASTCompletionNode getCompletionNode(IIndex index, int style, int offset) throws CoreException;
public IASTCompletionNode getCompletionNode(IIndex index, int style, int offset) throws CoreException;
}

View file

@ -24,7 +24,7 @@ import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.CModelException;
@ -750,7 +750,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
return null;
}
public ASTCompletionNode getCompletionNode(IIndex index, int style, int offset) throws CoreException {
public IASTCompletionNode getCompletionNode(IIndex index, int style, int offset) throws CoreException {
ICodeReaderFactory codeReaderFactory;
if (index != null && (style & (ITranslationUnit.AST_SKIP_INDEXED_HEADERS | ITranslationUnit.AST_SKIP_ALL_HEADERS)) != 0) {
ICodeReaderFactory fallbackFactory;

View file

@ -16,19 +16,10 @@ import java.util.List;
import org.eclipse.cdt.core.parser.IToken;
/**
* This class represents the node that would occur at the point of a context
* completion.
*
* This node may contain the prefix text of an identifer up to the point. If
* there is no prefix, the completion occurred at the point where a new token
* would have begun.
*
* The node points to the parent node where this node, if replaced by a proper
* node, would reside in the tree.
*
* @author Doug Schaefer
*/
public class ASTCompletionNode {
public class ASTCompletionNode implements IASTCompletionNode {
private IToken completionToken;
@ -36,8 +27,6 @@ public class ASTCompletionNode {
private IASTTranslationUnit translationUnit;
// used for debug
public int count;
/**
* Only constructor.
@ -59,38 +48,29 @@ public class ASTCompletionNode {
names.add(name);
}
/**
* If the point of completion was at the end of a potential identifier, this
* string contains the text of that identifier.
*
* @return the prefix text up to the point of completion
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompletionNode#getPrefix()
*/
public String getPrefix() {
return completionToken.getType() != IToken.tEOC ? completionToken.getImage() : ""; //$NON-NLS-1$
}
/**
* Get the length of the completion point.
*
* @return length of completion token
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompletionNode#getLength()
*/
public int getLength() {
return completionToken.getLength();
}
/**
* Get a list of names that fit in this context.
*
* @return array of IASTName's
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompletionNode#getNames()
*/
public IASTName[] getNames() {
return (IASTName[]) names.toArray(new IASTName[names.size()]);
}
/**
* Get the translation unit for this completion
*
* @return the translation unit
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompletionNode#getTranslationUnit()
*/
public IASTTranslationUnit getTranslationUnit() {
return translationUnit;

View file

@ -0,0 +1,45 @@
package org.eclipse.cdt.core.dom.ast;
/**
* This represents the node that would occur at the point of a context
* completion.
*
* This node may contain the prefix text of an identifer up to the point. If
* there is no prefix, the completion occurred at the point where a new token
* would have begun.
*
* The node points to the parent node where this node, if replaced by a proper
* node, would reside in the tree.
*/
public interface IASTCompletionNode {
/**
* If the point of completion was at the end of a potential identifier, this
* string contains the text of that identifier.
*
* @return the prefix text up to the point of completion
*/
public String getPrefix();
/**
* Get the length of the completion point.
*
* @return length of completion token
*/
public int getLength();
/**
* Get a list of names that fit in this context.
*
* @return array of IASTName's
*/
public IASTName[] getNames();
/**
* Get the translation unit for this completion
*
* @return the translation unit
*/
public IASTTranslationUnit getTranslationUnit();
}

View file

@ -10,8 +10,9 @@
*******************************************************************************/
package org.eclipse.cdt.core.dom.parser;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.parser.ParseError;
/**
* Interface for an AST source code parser.
@ -49,11 +50,11 @@ public interface ISourceCodeParser {
public boolean encounteredError();
/**
* Compute an {@link ASTCompletionNode} for code completion.
* Compute an {@link IASTCompletionNode} for code completion.
* @return a completion node or <code>null</code> if none could be computed
*
* @throws ParseError if parsing has been cancelled or for other reasons
*/
public ASTCompletionNode getCompletionNode();
public IASTCompletionNode getCompletionNode();
}

View file

@ -17,7 +17,7 @@ import java.util.List;
import java.util.Set;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@ -27,8 +27,8 @@ import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.ISourceCodeParser;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.AbstractLanguage;
import org.eclipse.cdt.core.model.IContributedModelBuilder;
import org.eclipse.cdt.core.model.ICLanguageKeywords;
import org.eclipse.cdt.core.model.IContributedModelBuilder;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParserLogService;
@ -98,7 +98,7 @@ public abstract class AbstractCLanguage extends AbstractLanguage implements ICLa
return ast;
}
public ASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo,
public IASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo,
ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException {
IScanner scanner= createScanner(reader, scanInfo, fileCreator, log);
@ -108,10 +108,7 @@ public abstract class AbstractCLanguage extends AbstractLanguage implements ICLa
// Run the parse and return the completion node
parser.parse();
ASTCompletionNode node= parser.getCompletionNode();
if (node != null) {
node.count= scanner.getCount();
}
IASTCompletionNode node= parser.getCompletionNode();
return node;
}

View file

@ -17,7 +17,7 @@ import java.util.List;
import java.util.Set;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@ -97,7 +97,7 @@ public abstract class AbstractCPPLanguage extends AbstractLanguage implements IC
return ast;
}
public ASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo,
public IASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo,
ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException {
IScanner scanner= createScanner(reader, scanInfo, fileCreator, log);
scanner.setContentAssistMode(offset);
@ -106,10 +106,7 @@ public abstract class AbstractCPPLanguage extends AbstractLanguage implements IC
// Run the parse and return the completion node
parser.parse();
ASTCompletionNode node= parser.getCompletionNode();
if (node != null) {
node.count= scanner.getCount();
}
IASTCompletionNode node= parser.getCompletionNode();
return node;
}

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
import org.eclipse.cdt.core.dom.ast.IASTContinueStatement;
@ -147,7 +148,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
*
* @see org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser#getCompletionNode()
*/
public ASTCompletionNode getCompletionNode() {
public IASTCompletionNode getCompletionNode() {
return completionNode;
}

View file

@ -9,7 +9,7 @@
* IBM - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopyProvider;
import org.eclipse.cdt.internal.core.dom.InternalASTServiceProvider;
@ -139,14 +139,14 @@ public class CDOM implements IASTServiceProvider {
return defaultService.getTranslationUnit(fileToParse, fileCreator, configuration );
}
public ASTCompletionNode getCompletionNode(IFile fileToParse, int offset,
public IASTCompletionNode getCompletionNode(IFile fileToParse, int offset,
ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
//TODO - At this time, we purely delegate blindly
//In the future, we may need to delegate based upon context provided
return defaultService.getCompletionNode(fileToParse, offset, fileCreator);
}
public ASTCompletionNode getCompletionNode(IStorage fileToParse, IProject project, int offset,
public IASTCompletionNode getCompletionNode(IStorage fileToParse, IProject project, int offset,
ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
//TODO - At this time, we purely delegate blindly
//In the future, we may need to delegate based upon context provided

View file

@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.core.dom;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@ -95,7 +95,7 @@ public interface IASTServiceProvider {
* @return syntactical parse tree
* @throws UnsupportedDialectException
*/
public ASTCompletionNode getCompletionNode( IFile fileToParse, int offset, ICodeReaderFactory fileCreator) throws UnsupportedDialectException;
public IASTCompletionNode getCompletionNode( IFile fileToParse, int offset, ICodeReaderFactory fileCreator) throws UnsupportedDialectException;
/**
* Returns a parse tree that represents the content provided as parameters.
@ -107,6 +107,6 @@ public interface IASTServiceProvider {
* @return syntactical parse tree
* @throws UnsupportedDialectException
*/
public ASTCompletionNode getCompletionNode( IStorage fileToParse, IProject project, int offset, ICodeReaderFactory fileCreator) throws UnsupportedDialectException;
public IASTCompletionNode getCompletionNode( IStorage fileToParse, IProject project, int offset, ICodeReaderFactory fileCreator) throws UnsupportedDialectException;
}

View file

@ -14,7 +14,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IASTServiceProvider;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.dom.IParserConfiguration;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.ISourceCodeParser;
@ -171,17 +171,17 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
return parser.parse();
}
public ASTCompletionNode getCompletionNode(IStorage fileToParse, IProject project, int offset,
public IASTCompletionNode getCompletionNode(IStorage fileToParse, IProject project, int offset,
ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
return getCompletionNode(fileToParse.getFullPath().toOSString(), project, offset, fileCreator);
}
public ASTCompletionNode getCompletionNode(IFile fileToParse, int offset,
public IASTCompletionNode getCompletionNode(IFile fileToParse, int offset,
ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
return getCompletionNode(fileToParse.getLocation().toOSString(), fileToParse, offset, fileCreator);
}
public ASTCompletionNode getCompletionNode(String filename, IResource infoProvider, int offset,
public IASTCompletionNode getCompletionNode(String filename, IResource infoProvider, int offset,
ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
// Get the scanner info
IScannerInfo scanInfo = null;
@ -223,10 +223,7 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
// Run the parse and return the completion node
parser.parse();
ASTCompletionNode node = parser.getCompletionNode();
if (node != null) {
node.count = scanner.getCount();
}
IASTCompletionNode node = parser.getCompletionNode();
return node;
}

View file

@ -18,7 +18,7 @@ import org.eclipse.jface.text.ITextViewer;
import org.eclipse.ui.IEditorPart;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.model.ICProject;
@ -47,7 +47,7 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont
private boolean fTUComputed= false;
private int fParseOffset= -1;
private boolean fParseOffsetComputed= false;
private ASTCompletionNode fCN= null;
private IASTCompletionNode fCN= null;
private boolean fCNComputed= false;
private IIndex fIndex = null;
private int fContextInfoPosition;
@ -104,7 +104,7 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont
return unit == null ? null : unit.getCProject();
}
public ASTCompletionNode getCompletionNode() {
public IASTCompletionNode getCompletionNode() {
if (fCNComputed) return fCN;
fCNComputed = true;

View file

@ -20,10 +20,10 @@ import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextUtilities;
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.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
@ -75,7 +75,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
protected List computeCompletionProposals(
CContentAssistInvocationContext context,
ASTCompletionNode completionNode, String prefix) {
IASTCompletionNode completionNode, String prefix) {
List proposals = new ArrayList();
@ -138,7 +138,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
private void addMacroProposals(CContentAssistInvocationContext context, String prefix, List proposals) {
char[] prefixChars= prefix.toCharArray();
ASTCompletionNode completionNode = context.getCompletionNode();
IASTCompletionNode completionNode = context.getCompletionNode();
IASTPreprocessorMacroDefinition[] macros = completionNode.getTranslationUnit().getMacroDefinitions();
if (macros != null)
for (int i = 0; i < macros.length; ++i)

View file

@ -18,7 +18,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.swt.graphics.Image;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.model.ITranslationUnit;
@ -33,7 +33,7 @@ public class HelpCompletionProposalComputer extends ParsingBasedProposalComputer
protected List computeCompletionProposals(
CContentAssistInvocationContext cContext,
ASTCompletionNode completionNode, String prefix)
IASTCompletionNode completionNode, String prefix)
throws CoreException {
boolean handleHelp = false;

View file

@ -21,7 +21,7 @@ import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextUtilities;
import org.eclipse.swt.graphics.Image;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.model.ITranslationUnit;
@ -37,7 +37,7 @@ public class KeywordCompletionProposalComputer extends ParsingBasedProposalCompu
protected List computeCompletionProposals(
CContentAssistInvocationContext context,
ASTCompletionNode completionNode, String prefix)
IASTCompletionNode completionNode, String prefix)
throws CoreException {
// No prefix, no completions
@ -82,7 +82,7 @@ public class KeywordCompletionProposalComputer extends ParsingBasedProposalCompu
* @param context the content assist invocation context
* @return <code>false</code> if the given invocation context looks like a field reference
*/
private boolean isValidContext(ASTCompletionNode completionNode) {
private boolean isValidContext(IASTCompletionNode completionNode) {
IASTName[] names = completionNode.getNames();
for (int i = 0; i < names.length; ++i) {
IASTName name = names[i];

View file

@ -24,13 +24,14 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.contentassist.ICompletionContributor;
/**
* A proposal computer for handling the legacy extension from the
* completionContributors extension point.
* A proposal computer for handling the legacy extensions from the
* <tt>org.eclipse.cdt.core.completionContributors</tt> extension point.
*
* @since 4.0
*/
@ -44,8 +45,12 @@ public class LegacyCompletionProposalComputer extends ParsingBasedProposalComput
protected List computeCompletionProposals(
CContentAssistInvocationContext context,
ASTCompletionNode completionNode, String prefix) throws CoreException {
IASTCompletionNode completionNode, String prefix) throws CoreException {
if (!(completionNode instanceof ASTCompletionNode)) {
// unsupported IASTCompletionNode implementation
return Collections.EMPTY_LIST;
}
if (context.isContextInformationStyle()) {
// context information cannot be supported by completionContributors
return Collections.EMPTY_LIST;
@ -70,7 +75,9 @@ public class LegacyCompletionProposalComputer extends ParsingBasedProposalComput
if (!(contribObject instanceof ICompletionContributor))
continue;
ICompletionContributor contributor = (ICompletionContributor)contribObject;
contributor.contributeCompletionProposals(viewer, offset, workingCopy, completionNode, prefix, proposals);
contributor.contributeCompletionProposals(viewer, offset,
workingCopy, (ASTCompletionNode) completionNode,
prefix, proposals);
}
}

View file

@ -22,7 +22,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.ui.text.contentassist.ContentAssistInvocationContext;
import org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer;
@ -42,7 +42,7 @@ public abstract class ParsingBasedProposalComputer implements ICompletionProposa
if (context instanceof CContentAssistInvocationContext) {
CContentAssistInvocationContext cContext = (CContentAssistInvocationContext) context;
ASTCompletionNode completionNode = cContext.getCompletionNode();
IASTCompletionNode completionNode = cContext.getCompletionNode();
if (completionNode == null) return Collections.EMPTY_LIST;
String prefix = completionNode.getPrefix();
if (prefix == null) {
@ -60,7 +60,7 @@ public abstract class ParsingBasedProposalComputer implements ICompletionProposa
protected abstract List computeCompletionProposals(
CContentAssistInvocationContext context,
ASTCompletionNode completionNode,
IASTCompletionNode completionNode,
String prefix) throws CoreException;
public List computeContextInformation(

View file

@ -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
@ -12,10 +12,19 @@ package org.eclipse.cdt.ui.text.contentassist;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.model.IWorkingCopy;
/**
* This interface must be implemented by clients extending the extension point
* <tt>org.eclipse.cdt.core.completionContributors</tt>.
*
* @deprecated Clients should extend the new extension point
* <tt>completionProprosalComputer</tt> and implement interface
* {@link ICompletionProposalComputer}
*/
public interface ICompletionContributor {
/**
@ -24,7 +33,7 @@ public interface ICompletionContributor {
* @param viewer the text viewer where completion is occuring
* @param offset the offset into the text where the completion is occuring
* @param completionNode the completion node produced by the parser for the offset
* @param proposals the current list of proposals. This method should any additional
* @param proposals the current list of proposals. This method should add any additional
* proposals to this list.
*/
void contributeCompletionProposals(ITextViewer viewer,