From a8950694c7e37c9575bb985ee2c5b486d9b534d1 Mon Sep 17 00:00:00 2001
From: Hoda Amer
Date: Mon, 15 Dec 2003 19:50:46 +0000
Subject: [PATCH] Fix for [Bug 47234] new ParserMode required for a better
CModel
---
.../internal/core/model/CModelBuilder.java | 84 ++++--
.../core/model/StructuralParseCallback.java | 246 ++++++++++++++++++
.../internal/core/model/TranslationUnit.java | 5 +-
.../parser/ChangeLog-parser | 6 +
.../cdt/core/parser/ParserFactory.java | 11 +-
.../core/parser/QuickParseCallback.java | 29 ++-
.../ast/complete/ASTClassSpecifier.java | 14 +-
.../parser/ast/complete/ASTCodeScope.java | 18 +-
.../ast/complete/ASTCompilationUnit.java | 19 +-
.../core/parser/ast/complete/ASTFunction.java | 14 +-
.../ast/complete/ASTNamespaceDefinition.java | 17 +-
.../core/parser/ast/complete/ASTScope.java | 9 +-
.../src/org/eclipse/cdt/core/CCorePlugin.java | 19 +-
core/org.eclipse.cdt.ui/ChangeLog | 6 +
.../internal/ui/CPluginResources.properties | 2 +-
.../ui/preferences/CEditorPreferencePage.java | 7 +-
.../ui/preferences/CPluginPreferencePage.java | 17 +-
.../contentassist/CCompletionProcessor.java | 114 +++-----
.../text/contentassist/CompletionEngine.java | 6 +-
.../eclipse/cdt/ui/PreferenceConstants.java | 12 +-
20 files changed, 519 insertions(+), 136 deletions(-)
create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/StructuralParseCallback.java
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java
index cc81e6afee1..76ec66635fa 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java
@@ -15,12 +15,17 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.core.model.ITemplate;
+import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IQuickParseCallback;
+import org.eclipse.cdt.core.parser.IScannerInfo;
+import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserFactoryException;
import org.eclipse.cdt.core.parser.ParserLanguage;
@@ -67,53 +72,80 @@ public class CModelBuilder {
this.newElements = new HashMap();
}
- private IASTCompilationUnit parse( String code, boolean hasCppNature, boolean quick, boolean throwExceptionOnError ) throws ParserException
+ private IASTCompilationUnit parse( ITranslationUnit translationUnit, boolean quickParseMode, boolean throwExceptionOnError ) throws ParserException
{
- ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
- quickParseCallback = ParserFactory.createQuickParseCallback();
+ IProject currentProject = null;
+ boolean hasCppNature = true;
+ String code = "";
+ // get the current project
+ if (translationUnit != null && translationUnit.getCProject() != null) {
+ currentProject = translationUnit.getCProject().getProject();
+ }
+ // check the project's nature
+ if( currentProject != null )
+ {
+ hasCppNature = CoreModel.getDefault().hasCCNature(currentProject);
+ }
+ // get the code to parse
+ try{
+ code = translationUnit.getBuffer().getContents();
+ } catch (CModelException e) {
+
+ }
+ // use quick or structural parse mode
+ ParserMode mode = quickParseMode ? ParserMode.QUICK_PARSE : ParserMode.STRUCTURAL_PARSE;
+ if(quickParseMode)
+ quickParseCallback = ParserFactory.createQuickParseCallback();
+ else
+ quickParseCallback = ParserFactory.createStructuralParseCallback();
+
+ // pick the language
ParserLanguage language = hasCppNature ? ParserLanguage.CPP : ParserLanguage.C;
+ // create the parser
IParser parser = null;
try
{
+
+ IScannerInfo scanInfo = new ScannerInfo();
+ IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(currentProject);
+ if (provider != null){
+ IScannerInfo buildScanInfo = provider.getScannerInformation(currentProject);
+ if (buildScanInfo != null){
+ scanInfo = new ScannerInfo(buildScanInfo.getDefinedSymbols(), buildScanInfo.getIncludePaths());
+ }
+ }
+
parser = ParserFactory.createParser(
- ParserFactory.createScanner( new StringReader( code ), "code",
- new ScannerInfo(), mode, language, quickParseCallback, ParserUtil.getParserLogService()), quickParseCallback, mode, language, ParserUtil.getParserLogService() );
+ ParserFactory.createScanner(
+ new StringReader( code ),
+ translationUnit.getUnderlyingResource().getLocation().toOSString(),
+ scanInfo,
+ mode,
+ language,
+ quickParseCallback,
+ ParserUtil.getParserLogService())
+ ,quickParseCallback,
+ mode,
+ language,
+ ParserUtil.getParserLogService() );
}
catch( ParserFactoryException pfe )
{
throw new ParserException( "Parser/Scanner construction failure.");
}
-
+ // call parse
if( ! parser.parse() && throwExceptionOnError )
throw new ParserException("Parse failure");
return quickParseCallback.getCompilationUnit();
}
- private IASTCompilationUnit parse( String code, boolean hasCppNature )throws ParserException
- {
- return parse( code, hasCppNature, true, true );
- }
- public Map parse() throws Exception {
-
- Map options = null;
- IProject currentProject = null;
- boolean hasCppNature = true;
-
- if (translationUnit != null && translationUnit.getCProject() != null) {
- options = translationUnit.getCProject().getOptions(true);
- currentProject = translationUnit.getCProject().getProject();
- }
- if( currentProject != null )
- {
- hasCppNature = CoreModel.getDefault().hasCCNature(currentProject);
- }
-
+ public Map parse(boolean quickParseMode) throws Exception {
try
{
- compilationUnit = parse( translationUnit.getBuffer().getContents(), hasCppNature);
+ compilationUnit = parse( translationUnit, quickParseMode, true);
}
catch( ParserException e )
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/StructuralParseCallback.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/StructuralParseCallback.java
new file mode 100644
index 00000000000..31029ac48ce
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/StructuralParseCallback.java
@@ -0,0 +1,246 @@
+/**********************************************************************
+ * 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.model;
+import java.util.LinkedList;
+
+import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
+import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTField;
+import org.eclipse.cdt.core.parser.ast.IASTFunction;
+import org.eclipse.cdt.core.parser.ast.IASTInclusion;
+import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
+import org.eclipse.cdt.core.parser.ast.IASTMacro;
+import org.eclipse.cdt.core.parser.ast.IASTMethod;
+import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
+import org.eclipse.cdt.core.parser.ast.IASTNode;
+import org.eclipse.cdt.core.parser.ast.IASTScope;
+import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTVariable;
+import org.eclipse.cdt.internal.core.parser.QuickParseCallback;
+import org.eclipse.cdt.internal.core.parser.ast.complete.ASTScope;
+
+/**
+ * @author hamer
+ *
+ * To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Generation - Code and Comments
+ */
+public class StructuralParseCallback extends QuickParseCallback{
+
+ protected LinkedList scopeStack = new LinkedList();
+ protected IASTScope currentScope = null;
+ protected int inclusionLevel = 0;
+
+
+ private void addElement (IASTDeclaration element){
+ if(inclusionLevel == 0)
+ ((ASTScope)currentScope).addDeclaration(element);
+ }
+
+ private void enterScope(IASTNode node){
+ if(node instanceof IASTScope){
+ pushScope((IASTScope)node);
+ }
+ }
+
+ private void exitScope(IASTNode node){
+ if(node instanceof IASTScope){
+ popScope();
+ }
+ }
+
+ private void pushScope( IASTScope scope ){
+ scopeStack.addFirst( currentScope );
+ currentScope = (IASTScope)scope;
+ }
+
+ private IASTScope popScope(){
+ IASTScope oldScope = currentScope;
+ currentScope = (scopeStack.size() > 0 ) ? (IASTScope) scopeStack.removeFirst() : null;
+ return oldScope;
+ }
+
+ private IASTScope peekAtScope(){
+ return currentScope;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMacro(org.eclipse.cdt.core.parser.ast.IASTMacro)
+ */
+ public void acceptMacro(IASTMacro macro) {
+ if(inclusionLevel == 0)
+ macros.add(macro);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariable(org.eclipse.cdt.core.parser.ast.IASTVariable)
+ */
+ public void acceptVariable(IASTVariable variable) {
+ addElement(variable);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionDeclaration(org.eclipse.cdt.core.parser.ast.IASTFunction)
+ */
+ public void acceptFunctionDeclaration(IASTFunction function) {
+ addElement(function);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedefDeclaration(org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration)
+ */
+ public void acceptTypedefDeclaration(IASTTypedefDeclaration typedef) {
+ addElement(typedef);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationSpecifier(org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier)
+ */
+ public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration) {
+ enterScope(enumeration);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptElaboratedForewardDeclaration(org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier)
+ */
+ public void acceptElaboratedForewardDeclaration(IASTElaboratedTypeSpecifier elaboratedType) {
+ enterScope(elaboratedType);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptAbstractTypeSpecDeclaration(org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration)
+ */
+ public void acceptAbstractTypeSpecDeclaration(IASTAbstractTypeSpecifierDeclaration abstractDeclaration) {
+ addElement(abstractDeclaration);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion)
+ */
+ public void enterInclusion(IASTInclusion inclusion) {
+ if(inclusionLevel == 0)
+ inclusions.add(inclusion);
+ inclusionLevel++;
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition)
+ */
+ public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) {
+ addElement(namespaceDefinition);
+ enterScope(namespaceDefinition);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier)
+ */
+ public void enterClassSpecifier(IASTClassSpecifier classSpecification) {
+ enterScope(classSpecification);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification)
+ */
+ public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec) {
+ enterScope(linkageSpec);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit)
+ */
+ public void enterCompilationUnit(IASTCompilationUnit compilationUnit) {
+ enterScope(compilationUnit);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodDeclaration(org.eclipse.cdt.core.parser.ast.IASTMethod)
+ */
+ public void acceptMethodDeclaration(IASTMethod method) {
+ addElement(method);
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptField(org.eclipse.cdt.core.parser.ast.IASTField)
+ */
+ public void acceptField(IASTField field) {
+ addElement(field);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit)
+ */
+ public void exitCompilationUnit(IASTCompilationUnit compilationUnit) {
+ exitScope(compilationUnit);
+ this.compilationUnit = compilationUnit;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion)
+ */
+ public void exitInclusion( IASTInclusion inclusion )
+ {
+ inclusionLevel--;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.IQuickParseCallback#getCompilationUnit()
+ */
+ public IASTCompilationUnit getCompilationUnit() {
+ return compilationUnit; }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier)
+ */
+ public void exitClassSpecifier(IASTClassSpecifier classSpecification) {
+ exitScope(classSpecification);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification)
+ */
+ public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec) {
+ exitScope(linkageSpec);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition)
+ */
+ public void exitNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) {
+ exitScope(namespaceDefinition);
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction)
+ */
+ public void enterFunctionBody(IASTFunction function) {
+ addElement(function);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod)
+ */
+ public void enterMethodBody(IASTMethod method) {
+ addElement(method);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration)
+ */
+ public void enterTemplateDeclaration(IASTTemplateDeclaration declaration) {
+ addElement(declaration);
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java
index 9460629b6ac..4282ee1bf41 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java
@@ -10,6 +10,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IBuffer;
import org.eclipse.cdt.core.model.ICElement;
@@ -465,7 +466,9 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
try {
removeChildren();
CModelBuilder modelBuilder = new CModelBuilder(this);
- return modelBuilder.parse();
+
+ boolean quickParseMode = ! (CCorePlugin.getDefault().useStructuralParseMode());
+ return modelBuilder.parse(quickParseMode);
} catch (Exception e) {
// FIXME: use the debug log for this exception.
//System.out.println(e);
diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog-parser b/core/org.eclipse.cdt.core/parser/ChangeLog-parser
index d7a9f8a851d..f02e5ce67ed 100644
--- a/core/org.eclipse.cdt.core/parser/ChangeLog-parser
+++ b/core/org.eclipse.cdt.core/parser/ChangeLog-parser
@@ -1,3 +1,9 @@
+2003-12-15 Hoda Amer
+ Fixed [Bug 47234] new ParserMode required for a better CModel :
+ - Added a core plugin preference to build the CModel in Structural mode
+ - Added StructuralParseCallBack class
+ - Added lists of declarations to AST Scopes in the complete AST
+
2003-12-12 John Camelon
Added preliminary keyword support into IASTCompletionNode::getKeywords().
Refactored parser to put keyword string literals in one utility class.
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java
index c12ec471a4d..cbdad624739 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java
@@ -13,13 +13,15 @@ package org.eclipse.cdt.core.parser;
import java.io.Reader;
import org.eclipse.cdt.core.parser.ast.IASTFactory;
-import org.eclipse.cdt.internal.core.parser.*;
+import org.eclipse.cdt.internal.core.model.StructuralParseCallback;
import org.eclipse.cdt.internal.core.parser.CompleteParser;
+import org.eclipse.cdt.internal.core.parser.ContextualParser;
import org.eclipse.cdt.internal.core.parser.LineOffsetReconciler;
import org.eclipse.cdt.internal.core.parser.Preprocessor;
import org.eclipse.cdt.internal.core.parser.QuickParseCallback;
import org.eclipse.cdt.internal.core.parser.QuickParser;
import org.eclipse.cdt.internal.core.parser.Scanner;
+import org.eclipse.cdt.internal.core.parser.StructuralParser;
import org.eclipse.cdt.internal.core.parser.ast.complete.CompleteParseASTFactory;
import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory;
@@ -85,7 +87,12 @@ public class ParserFactory {
{
return new QuickParseCallback();
}
-
+
+ public static IQuickParseCallback createStructuralParseCallback()
+ {
+ return new StructuralParseCallback();
+ }
+
public static IParserLogService createDefaultLogService()
{
return defaultLogService;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParseCallback.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParseCallback.java
index 2128ceb7f86..cf413b3291c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParseCallback.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParseCallback.java
@@ -42,6 +42,15 @@ public class QuickParseCallback extends NullSourceElementRequestor implements IQ
return macros.iterator();
}
+ public Iterator getDeclarations(){
+ try{
+ return compilationUnit.getDeclarations();
+ }
+ catch (ASTNotImplementedException ne )
+ {
+ return null;
+ }
+ }
public void exitMethodBody( IASTMethod method )
{
@@ -89,25 +98,19 @@ public class QuickParseCallback extends NullSourceElementRequestor implements IQ
public OffsetableIterator()
{
- try
- {
- declarationIter = compilationUnit.getDeclarations();
- }
- catch (ASTNotImplementedException ne )
- {
-
- }
- inclusionIter = inclusions.iterator();
- macroIter = macros.iterator();
+ declarationIter = getDeclarations();
+ inclusionIter = getInclusions();
+ macroIter = getMacros();
updateInclusionIterator();
- updateDeclarationIterator();
updateMacroIterator();
+ updateDeclarationIterator();
}
private Object updateDeclarationIterator()
{
- Object offsetable = currentDeclaration;
- currentDeclaration = ( declarationIter.hasNext() ) ? (IASTOffsetableElement)declarationIter.next() : null;
+ Object offsetable = currentDeclaration;
+ if(declarationIter != null)
+ currentDeclaration = ( declarationIter.hasNext() ) ? (IASTOffsetableElement)declarationIter.next() : null;
return offsetable;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTClassSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTClassSpecifier.java
index a8bbde33d7b..62e1dce7586 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTClassSpecifier.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTClassSpecifier.java
@@ -10,6 +10,7 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
@@ -19,6 +20,7 @@ import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement;
import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets;
@@ -32,7 +34,7 @@ import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol.IParen
*/
public class ASTClassSpecifier extends ASTScope implements IASTClassSpecifier
{
-
+ private List declarations = new ArrayList();
public class BaseIterator implements Iterator
{
@@ -256,6 +258,16 @@ public class ASTClassSpecifier extends ASTScope implements IASTClassSpecifier
{
offsets.setNameEndOffset(o);
}
+
+ public Iterator getDeclarations()
+ {
+ return declarations.iterator();
+ }
+ public void addDeclaration(IASTDeclaration declaration)
+ {
+ declarations.add(declaration);
+ }
+
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCodeScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCodeScope.java
index 0733f0c722a..198508c0b31 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCodeScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCodeScope.java
@@ -6,8 +6,13 @@
*/
package org.eclipse.cdt.internal.core.parser.ast.complete;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
+import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
/**
@@ -18,6 +23,7 @@ import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
*/
public class ASTCodeScope extends ASTScope implements IASTCodeScope {
+ private List declarations = new ArrayList();
private final IASTCodeScope ownerCodeScope;
/**
@@ -71,7 +77,17 @@ public class ASTCodeScope extends ASTScope implements IASTCodeScope {
{
return ownerCodeScope;
}
-
+
+ public Iterator getDeclarations()
+ {
+ return declarations.iterator();
+ }
+
+ public void addDeclaration(IASTDeclaration declaration)
+ {
+ declarations.add(declaration);
+ }
+
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCompilationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCompilationUnit.java
index 53907c2bdc1..86d279c0e61 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCompilationUnit.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCompilationUnit.java
@@ -10,8 +10,13 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
+import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
/**
@@ -22,7 +27,8 @@ public class ASTCompilationUnit
extends ASTScope
implements IASTCompilationUnit
{
- /**
+ private List declarations = new ArrayList();
+ /**
* @param symbol
*/
public ASTCompilationUnit(ISymbol symbol)
@@ -64,7 +70,16 @@ public class ASTCompilationUnit
/* do nothing */
}
}
-
+
+ public Iterator getDeclarations()
+ {
+ return declarations.iterator();
+ }
+ public void addDeclaration(IASTDeclaration declaration)
+ {
+ declarations.add(declaration);
+ }
+
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java
index 5224ed725d4..9eccd1b92c9 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java
@@ -10,6 +10,7 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -17,6 +18,7 @@ import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTArrayModifier;
import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
+import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification;
import org.eclipse.cdt.core.parser.ast.IASTFunction;
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
@@ -42,7 +44,7 @@ public class ASTFunction extends ASTScope implements IASTFunction
private final List parameters;
protected final ASTReferenceStore references;
private final int nameEndOffset;
-
+ private List declarations = new ArrayList();
/**
* @param symbol
* @param parameters
@@ -319,7 +321,15 @@ public class ASTFunction extends ASTScope implements IASTFunction
return hasFunctionTryBlock;
}
-
+ public Iterator getDeclarations()
+ {
+ return declarations.iterator();
+ }
+ public void addDeclaration(IASTDeclaration declaration)
+ {
+ declarations.add(declaration);
+ }
+
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceDefinition.java
index 5f46b838a98..b6048b4224d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceDefinition.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceDefinition.java
@@ -10,7 +10,12 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
+import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement;
import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets;
@@ -27,6 +32,7 @@ public class ASTNamespaceDefinition
private NamedOffsets namedOffsets = new NamedOffsets();
private final ASTQualifiedNamedElement qualifiedName;
+ private List declarations = new ArrayList();
/**
* @param namespaceSymbol
@@ -158,7 +164,16 @@ public class ASTNamespaceDefinition
{
namedOffsets.setNameEndOffset(o);
}
-
+
+ public Iterator getDeclarations()
+ {
+ return declarations.iterator();
+ }
+ public void addDeclaration(IASTDeclaration declaration)
+ {
+ declarations.add(declaration);
+ }
+
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTScope.java
index f25f56257a9..2debe88aa24 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTScope.java
@@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.Iterator;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
+import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
@@ -39,9 +40,13 @@ public abstract class ASTScope extends ASTSymbol implements IASTScope
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations()
*/
- public Iterator getDeclarations() throws ASTNotImplementedException
+ public Iterator getDeclarations()
+ {
+ return null;
+ }
+
+ public void addDeclaration(IASTDeclaration declaration)
{
- throw new ASTNotImplementedException();
}
}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java
index 6e367370576..8d306ef9e41 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java
@@ -65,7 +65,8 @@ public class CCorePlugin extends Plugin {
public final static String PREF_BINARY_PARSER = "binaryparser";
public final static String DEFAULT_BINARY_PARSER_SIMPLE_ID = "ELF";
public final static String DEFAULT_BINARY_PARSER_UNIQ_ID = PLUGIN_ID + "." + DEFAULT_BINARY_PARSER_SIMPLE_ID;
-
+ public final static String PREF_USE_STRUCTURAL_PARSE_MODE = "useStructualParseMode";
+
public final static String ERROR_PARSER_SIMPLE_ID = "ErrorParser"; //$NON-NLS-1$
// Build Model Interface Discovery
@@ -236,6 +237,10 @@ public class CCorePlugin extends Plugin {
fDescriptorManager = new CDescriptorManager();
fDescriptorManager.startup();
+
+ // Set the default for using the structual parse mode to build the CModel
+ getPluginPreferences().setDefault(PREF_USE_STRUCTURAL_PARSE_MODE, false);
+
}
@@ -750,4 +755,16 @@ public class CCorePlugin extends Plugin {
}
}
}
+
+ // Preference to turn on/off the use of structural parse mode to build the CModel
+ public void setStructuralParseMode(boolean useNewParser) {
+ getPluginPreferences().setValue(PREF_USE_STRUCTURAL_PARSE_MODE, useNewParser);
+ savePluginPreferences();
+ }
+
+ public boolean useStructuralParseMode() {
+ return getPluginPreferences().getBoolean(PREF_USE_STRUCTURAL_PARSE_MODE);
+ }
+
+
}
\ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog
index 1897a87389c..abb7c05647e 100644
--- a/core/org.eclipse.cdt.ui/ChangeLog
+++ b/core/org.eclipse.cdt.ui/ChangeLog
@@ -1,3 +1,9 @@
+2003-12-15 Hoda Amer
+ Fixed [Bug 47234] new ParserMode required for a better CModel :
+ - Added a user preference to build the CModel using Structural mode
+ Enabled the Completion Engine and called the parser in Contextual Mode
+ Changed default user preference to Project scope until the completion engine is ready
+
2003-12-15 Thomas Fletcher
Re-activate the hover help based on the function summary extension point.
Fix a bug in the FunctionSummary class which displayed arguments as
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties
index bc2064acc5c..02e22e4484a 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties
@@ -17,7 +17,7 @@ CBasePreferencePage.consoleOnTop.label=Bring C-Build view to top when building (
CBasePreferencePage.buildConsole.errorMessage=Value must be an integer between 10 and 2147483647
CBasePreferencePage.linkToEditor.label=Link view selection to active editor
CBasePreferencePage.CUChildren.label=Show file members in Project View
-CBasePreferencePage.useNewParser.label=Use New Parser for Code Model
+CBasePreferencePage.OutlineView.structuralParseMode.label=Use Structural-Parse mode to build the CModel
CBasePreferencePage.editorFont.label=C Editor font:
CBasePreferencePage.consoleFont.label=C-Build view font:
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java
index 7bc3ee70531..b97579eeb24 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java
@@ -277,6 +277,10 @@ public class CEditorPreferencePage extends PreferencePage implements IWorkbenchP
store.setDefault(ExtendedTextEditorPreferenceConstants.EDITOR_OVERVIEW_RULER, true);
+ store.setDefault(ContentAssistPreference.CURRENT_FILE_SEARCH_SCOPE, false);
+ store.setDefault(ContentAssistPreference.PROJECT_SEARCH_SCOPE, true);
+ store.setDefault(ContentAssistPreference.PROJECT_AND_DEPENDENCY_SEARCH_SCOPE, false);
+
store.setDefault(ContentAssistPreference.AUTOACTIVATION_TRIGGERS_DOT, true);
store.setDefault(ContentAssistPreference.AUTOACTIVATION_TRIGGERS_ARROW, true);
store.setDefault(ContentAssistPreference.AUTOACTIVATION_TRIGGERS_DOUBLECOLON, true);
@@ -293,9 +297,6 @@ public class CEditorPreferencePage extends PreferencePage implements IWorkbenchP
//store.setDefault(ContentAssistPreference.CASE_SENSITIVITY, false);
store.setDefault(ContentAssistPreference.ORDER_PROPOSALS, false);
store.setDefault(ContentAssistPreference.ADD_INCLUDE, true);
- store.setDefault(ContentAssistPreference.CURRENT_FILE_SEARCH_SCOPE, true);
- store.setDefault(ContentAssistPreference.PROJECT_SEARCH_SCOPE, false);
- store.setDefault(ContentAssistPreference.PROJECT_AND_DEPENDENCY_SEARCH_SCOPE, false);
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CPluginPreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CPluginPreferencePage.java
index 91915991b04..b53b8997501 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CPluginPreferencePage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CPluginPreferencePage.java
@@ -5,6 +5,7 @@ package org.eclipse.cdt.internal.ui.preferences;
* All Rights Reserved.
*/
+import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
@@ -24,8 +25,8 @@ public class CPluginPreferencePage extends FieldEditorPreferencePage implements
private static final String LINK_TO_EDITOR_LABEL= "CBasePreferencePage.linkToEditor.label";
private static final String SHOW_CU_CHILDREN_LABEL= "CBasePreferencePage.CUChildren.label";
- private static final String USE_NEW_PARSER_LABEL= "CBasePreferencePage.useNewParser.label";
-
+ private static final String USE_STRUCTURAL_PARSE_MODE_LABEL= "CBasePreferencePage.OutlineView.structuralParseMode.label";
+
public CPluginPreferencePage() {
super(GRID);
setPreferenceStore(CUIPlugin.getDefault().getPreferenceStore());
@@ -50,6 +51,9 @@ public class CPluginPreferencePage extends FieldEditorPreferencePage implements
BooleanFieldEditor showCUChildrenEditor= new BooleanFieldEditor(PreferenceConstants.PREF_SHOW_CU_CHILDREN, CUIPlugin.getResourceString(SHOW_CU_CHILDREN_LABEL), parent);
addField(showCUChildrenEditor);
+
+ BooleanFieldEditor useStructuralParseMode= new BooleanFieldEditor(PreferenceConstants.PREF_USE_STRUCTURAL_PARSE_MODE, CUIPlugin.getResourceString(USE_STRUCTURAL_PARSE_MODE_LABEL), parent);
+ addField(useStructuralParseMode);
}
@@ -61,10 +65,15 @@ public class CPluginPreferencePage extends FieldEditorPreferencePage implements
return CUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_SHOW_CU_CHILDREN);
}
+ public static boolean useStructuralParseMode() {
+ return CUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_USE_STRUCTURAL_PARSE_MODE);
+ }
+
/**
* @see IWorkbenchPreferencePage#init
*/
public void init(IWorkbench workbench) {
+ CUIPlugin.getDefault().getPreferenceStore().setValue(CCorePlugin.PREF_USE_STRUCTURAL_PARSE_MODE, CCorePlugin.getDefault().useStructuralParseMode());
}
/**
@@ -73,6 +82,7 @@ public class CPluginPreferencePage extends FieldEditorPreferencePage implements
public static void initDefaults(IPreferenceStore prefs) {
prefs.setDefault(PreferenceConstants.PREF_LINK_TO_EDITOR, true);
prefs.setDefault(PreferenceConstants.PREF_SHOW_CU_CHILDREN, true);
+ prefs.setDefault(PreferenceConstants.PREF_USE_STRUCTURAL_PARSE_MODE, CCorePlugin.getDefault().useStructuralParseMode());
prefs.setDefault(PreferenceConstants.EDITOR_SHOW_SEGMENTS, false);
}
@@ -82,7 +92,8 @@ public class CPluginPreferencePage extends FieldEditorPreferencePage implements
public boolean performOk() {
if (!super.performOk())
return false;
-
+ // tell the Core Plugin about this preference
+ CCorePlugin.getDefault().setStructuralParseMode(useStructuralParseMode());
return true;
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor.java
index b7901747ec1..2caac16adb7 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor.java
@@ -12,15 +12,12 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
-import org.eclipse.cdt.core.model.IMember;
-import org.eclipse.cdt.core.model.IMethod;
-import org.eclipse.cdt.core.model.IMethodDeclaration;
-import org.eclipse.cdt.core.model.IStructure;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
+import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchConstants;
@@ -28,9 +25,7 @@ import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.model.CElement;
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
-import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.matching.OrPattern;
-import org.eclipse.cdt.internal.core.sourcedependency.DependencyQueryJob;
import org.eclipse.cdt.internal.corext.template.ContextType;
import org.eclipse.cdt.internal.corext.template.ContextTypeRegistry;
import org.eclipse.cdt.internal.ui.CCompletionContributorManager;
@@ -46,8 +41,6 @@ import org.eclipse.cdt.ui.IFunctionSummary;
import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.cdt.ui.text.ICCompletionProposal;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
@@ -327,6 +320,12 @@ public class CCompletionProcessor implements IContentAssistProcessor {
* Evaluate the actual proposals for C
*/
public ICCompletionProposal[] evalProposals(IDocument document, int pos, int length, ITranslationUnit unit) {
+ try{
+ currentOffset = pos;
+ currentSourceUnit = unit.getWorkingCopy();
+ } catch (CModelException e){
+
+ }
return order (evalProposals(document, pos, length, getCurrentScope (unit, pos)));
}
@@ -336,6 +335,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
String frag = "";
int pos = startPos;
+
// Move back the pos by one the position is 0-based
if (pos > 0) {
pos--;
@@ -415,7 +415,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
ArrayList completions = new ArrayList();
// Look in index manager
- addProposalsFromModel(region, frag,currentScope, completions);
+ addProposalsFromModel(region, completions);
// Loot in the contributed completions
addProposalsFromCompletionContributors(region, frag, completions);
@@ -472,20 +472,21 @@ public class CCompletionProcessor implements IContentAssistProcessor {
}
- private void addProposalsFromModel (IRegion region, String frag, ICElement currentScope, ArrayList completions) {
- List elementsFound = new LinkedList();
- String prefix = frag + "*";
+ private void addProposalsFromModel (IRegion region, ArrayList completions) {
- // TODO: change that to resource scope later
- if (currentScope == null)
+ if (currentSourceUnit == null)
return;
// clear the completion list at the result collector
resultCollector.clearCompletions();
//invoke the completion engine
- //IASTCompletionNode completionNode = completionEngine.complete(currentSourceUnit, currentOffset, completions);
-
+ IASTCompletionNode completionNode = completionEngine.complete(currentSourceUnit, currentOffset, completions);
+ if(completionNode == null)
+ return;
+ String prefix = completionNode.getCompletionPrefix();
+ String searchPrefix = prefix + "*";
+
// figure out the search scope
IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore();
boolean fileScope = store.getBoolean(ContentAssistPreference.CURRENT_FILE_SEARCH_SCOPE);
@@ -494,14 +495,32 @@ public class CCompletionProcessor implements IContentAssistProcessor {
ICSearchScope scope = null;
if ((projectScope) || (projectScopeAndDependency)){
+ List elementsFound = new LinkedList();
+ resultCollector.clearCompletions();
+ //////////////////////
+
ICElement[] projectScopeElement = new ICElement[1];
- projectScopeElement[0] = (ICElement)currentScope.getCProject();
+ projectScopeElement[0] = (ICElement)currentSourceUnit.getCProject();
scope = SearchEngine.createCSearchScope(projectScopeElement, projectScopeAndDependency);
+
+ OrPattern orPattern = new OrPattern();
+ // search for global variables, functions, classes, structs, unions, enums, macros, and namespaces
+ orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, ICSearchConstants.VAR, ICSearchConstants.DECLARATIONS, false ));
+ orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, ICSearchConstants.FUNCTION, ICSearchConstants.DEFINITIONS, false ));
+ orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, false ));
+ orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, ICSearchConstants.TYPE, ICSearchConstants.DECLARATIONS, false ));
+ orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, ICSearchConstants.ENUM, ICSearchConstants.DECLARATIONS, false ));
+ orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, ICSearchConstants.MACRO, ICSearchConstants.DECLARATIONS, false ));
+ orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, ICSearchConstants.NAMESPACE, ICSearchConstants.DEFINITIONS, false ));
+ searchEngine.search(CUIPlugin.getWorkspace(), orPattern, scope, searchResultCollector, true);
+ elementsFound.addAll(searchResultCollector.getSearchResults());
+
+ sendResultsToCollector(elementsFound.iterator(), region.getOffset(), region.getLength(), prefix );
}
else{
- //Try to get the file
- IResource actualFile = currentScope.getUnderlyingResource();
- IProject project = currentScope.getCProject().getProject();
+/* //Try to get the file
+ IResource actualFile = currentSourceUnit.getUnderlyingResource();
+ IProject project = currentSourceUnit.getCProject().getProject();
ArrayList dependencies = new ArrayList();
if (actualFile != null){
//Get file's dependencies
@@ -513,59 +532,8 @@ public class CCompletionProcessor implements IContentAssistProcessor {
}
//Create CFileSearchScope
scope = SearchEngine.createCFileSearchScope((IFile) actualFile, dependencies);
- }
+*/ }
- OrPattern orPattern = new OrPattern();
- // search for global variables, functions, classes, structs, unions, enums and macros
- orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.VAR, ICSearchConstants.DECLARATIONS, false ));
- orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, false ));
- orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.FUNCTION, ICSearchConstants.DEFINITIONS, false ));
- 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, searchResultCollector, true);
- elementsFound.addAll(searchResultCollector.getSearchResults());
-
- if((currentScope instanceof IMethod) || (currentScope instanceof IMethodDeclaration) ){
- // add the methods and fields of the parent class
- // Work around until CElement scope is implemented
- IStructure parentClass = (IStructure) currentScope.getParent();
- ArrayList children = new ArrayList();
- children.addAll(parentClass.getChildrenOfType(ICElement.C_METHOD));
- children.addAll(parentClass.getChildrenOfType(ICElement.C_METHOD_DECLARATION));
- children.addAll(parentClass.getChildrenOfType(ICElement.C_FIELD));
- Iterator c = children.iterator();
- while (c.hasNext()){
- IMember child = (IMember)c.next();
- if (child.getElementName().startsWith(frag))
- {
- BasicSearchMatch childMatch = new BasicSearchMatch();
- childMatch.setType(child.getElementType());
- childMatch.setParentName(parentClass.getElementName());
- if(child.getVisibility() == ASTAccessVisibility.PUBLIC )
- childMatch.setVisibility(ICElement.CPP_PUBLIC);
- else if(child.getVisibility() == ASTAccessVisibility.PROTECTED )
- childMatch.setVisibility(ICElement.CPP_PROTECTED);
- else if(child.getVisibility() == ASTAccessVisibility.PRIVATE )
- childMatch.setVisibility(ICElement.CPP_PRIVATE);
- childMatch.setConst(child.isConst());
- childMatch.setVolatile(child.isVolatile());
- childMatch.setStatic(child.isStatic());
- if(child instanceof IMethodDeclaration){
- childMatch.setName(((IMethodDeclaration)child).getSignature());
- childMatch.setReturnType( ((IMethodDeclaration)child).getReturnType() );
- }
- else {
- childMatch.setName(child.getElementName());
- }
-
- elementsFound.add(childMatch);
- }
- }
-
- }
-
- sendResultsToCollector(elementsFound.iterator(), region.getOffset(), region.getLength(), frag );
completions.addAll(resultCollector.getCompletions());
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java
index 355ad05bd99..28da81857b9 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java
@@ -165,8 +165,8 @@ public class CompletionEngine implements RelevanceConstants{
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() );
+ IScanner scanner = ParserFactory.createScanner( reader, realPath.toOSString(), scanInfo, ParserMode.CONTEXTUAL_PARSE, language, requestor, ParserUtil.getParserLogService() );
+ parser = ParserFactory.createParser( scanner, requestor, ParserMode.CONTEXTUAL_PARSE, language, ParserUtil.getParserLogService() );
}
catch( ParserFactoryException pfe )
{
@@ -269,6 +269,8 @@ public class CompletionEngine implements RelevanceConstants{
}
private void addToCompletions (LookupResult result){
+ if(result == null)
+ return;
Iterator nodes = result.getNodes();
while (nodes.hasNext()){
IASTNode node = (IASTNode) nodes.next();
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java
index 3eb5b87630f..e826827a712 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java
@@ -12,8 +12,8 @@ import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
/**
- * Preference constants used in the JDT-UI preference store. Clients should only read the
- * JDT-UI preference store using these values. Clients are not allowed to modify the
+ * Preference constants used in the CDT-UI preference store. Clients should only read the
+ * CDT-UI preference store using these values. Clients are not allowed to modify the
* preference store programmatically.
*
* @since 2.0
@@ -54,6 +54,14 @@ public class PreferenceConstants {
*
*/
public static final String PREF_SHOW_CU_CHILDREN= "org.eclipse.cdt.ui.editor.CUChildren"; //$NON-NLS-1$
+
+ /**
+ * A named preference that speficies whether to use the parser's structural mode to build the CModel.
+ *
+ * Value is of type Boolean
.
+ *
+ */
+ public static final String PREF_USE_STRUCTURAL_PARSE_MODE= "org.eclipse.cdt.ui.editor.UseStructuralMode"; //$NON-NLS-1$
/**
* A named preference that controls if segmented view (show selected element only) is turned on or off.