1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 00:36:16 +02:00

Content Assist Work : Moved logging and testing to the UI side of CDT

This commit is contained in:
Hoda Amer 2004-01-15 18:06:14 +00:00
parent e69bf2d4b5
commit 1196d4a5ff
52 changed files with 3184 additions and 2658 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,159 +0,0 @@
/*******************************************************************************
* Copyright (c) 2001 Rational Software Corp. 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:
* Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.core.codeassist.tests;
import java.io.FileInputStream;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.model.TranslationUnit;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.ui.text.contentassist.CCompletionProcessor;
import org.eclipse.cdt.testplugin.CProjectHelper;
import org.eclipse.core.internal.resources.ResourceException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
/**
* @author hamer
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class CompletionProposalsTest extends TestCase{
private final static long MAGIC_NUMBER = 1000;
private ICProject fCProject;
private IFile headerFile;
private IFile bodyFile;
private NullProgressMonitor monitor;
public static Test suite() {
TestSuite suite= new TestSuite(CompletionProposalsTest.class.getName());
suite.addTest(new CompletionProposalsTest("testCompletionProposals"));
return suite;
}
public CompletionProposalsTest(String name) {
super(name);
}
protected void setUp() throws Exception {
monitor = new NullProgressMonitor();
String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").find(new Path("/")).getFile();
fCProject= CProjectHelper.createCProject("TestProject1", "bin");
bodyFile = fCProject.getProject().getFile("CompletionProposalsTestStart.cpp");
headerFile = fCProject.getProject().getFile("CompletionProposalsTestStart.h");
if ((!headerFile.exists()) || (!bodyFile.exists())) {
try{
FileInputStream bodyFileIn = new FileInputStream(pluginRoot+ "resources/cfiles/CompletionProposalsTestStart.cpp");
bodyFile.create(bodyFileIn,false, monitor);
FileInputStream headerFileIn = new FileInputStream(pluginRoot+ "resources/cfiles/CompletionProposalsTestStart.h");
headerFile.create(headerFileIn,false, monitor);
} catch (CoreException e) {
e.printStackTrace();
}
}
if (!fCProject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
addNatureToProject(fCProject.getProject(), CCProjectNature.CC_NATURE_ID, null);
}
// use the new indexer
IndexManager indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
indexManager.reset();
}
private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
IProjectDescription description = proj.getDescription();
String[] prevNatures= description.getNatureIds();
String[] newNatures= new String[prevNatures.length + 1];
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
newNatures[prevNatures.length]= natureId;
description.setNatureIds(newNatures);
proj.setDescription(description, monitor);
}
protected void tearDown() {
try{
CProjectHelper.delete(fCProject);
}
catch (ResourceException e) {}
catch (CoreException e) {}
}
public void testCompletionProposals(){
try{
TranslationUnit headerTu = new TranslationUnit(fCProject, headerFile);
TranslationUnit tu = new TranslationUnit(fCProject, bodyFile);
String buffer = tu.getBuffer().getContents();
Document document = new Document(buffer);
int pos = buffer.indexOf(" a ") + 2;
CCompletionProcessor completionProcessor = new CCompletionProcessor(null);
IWorkingCopy wc = null;
try{
wc = tu.getWorkingCopy();
}catch (CModelException e){
fail("Failed to get working copy");
}
ICompletionProposal[] results = completionProcessor.evalProposals(document, pos, wc, null);
try {
Thread.sleep(MAGIC_NUMBER);
} catch (InterruptedException e1) {
fail( "Bogdan's hack did not suffice");
}
// assertEquals(results.length, 8);
for (int i = 0; i<results.length; i++){
ICompletionProposal proposal = results[i];
String displayString = proposal.getDisplayString();
switch(i){
case 0:
// assertEquals(displayString, "aVariable : int");
break;
case 1:
// assertEquals(displayString, "aFunction() bool");
break;
case 2:
// assertEquals(displayString, "aClass");
break;
case 3:
// assertEquals(displayString, "anotherClass");
break;
case 4:
// assertEquals(displayString, "anEnumeration");
break;
case 5:
// assertEquals(displayString, "AStruct");
break;
case 6:
// assertEquals(displayString, "AMacro");
break;
}
}
} catch(CModelException e){
}
}
}

View file

@ -29,8 +29,8 @@ import org.eclipse.cdt.core.model.ICElementDelta;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IElementChangedListener; import org.eclipse.cdt.core.model.IElementChangedListener;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.model.CModelManager; import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.model.TranslationUnit; import org.eclipse.cdt.internal.core.model.TranslationUnit;
import org.eclipse.cdt.testplugin.CProjectHelper; import org.eclipse.cdt.testplugin.CProjectHelper;
import org.eclipse.cdt.testplugin.TestPluginLauncher; import org.eclipse.cdt.testplugin.TestPluginLauncher;

View file

@ -21,7 +21,7 @@ import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.model.IBuffer; import org.eclipse.cdt.core.model.IBuffer;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.model.TranslationUnit; import org.eclipse.cdt.internal.core.model.TranslationUnit;
import org.eclipse.cdt.testplugin.CProjectHelper; import org.eclipse.cdt.testplugin.CProjectHelper;
import org.eclipse.cdt.testplugin.TestPluginLauncher; import org.eclipse.cdt.testplugin.TestPluginLauncher;

View file

@ -1,24 +0,0 @@
#include "CompletionProposalsTestStart.h"
#define AMacro(x) x+1
int aVariable = 0;
bool aFunction();
enum anEnumeration {
first,
second,
third
};
struct AStruct{
int aStructField;
};
void foo(){
int aLocalDeclaration = 1;
}
void anotherClass::anotherMethod(){
a
};

View file

@ -1,11 +0,0 @@
class aClass {
public:
int aField;
int aMethod();
};
class anotherClass {
public:
int anotherField;
void anotherMethod();
};

View file

@ -11,7 +11,6 @@ import junit.framework.TestSuite;
import org.eclipse.cdt.core.build.managed.tests.ManagedBuildTests; import org.eclipse.cdt.core.build.managed.tests.ManagedBuildTests;
import org.eclipse.cdt.core.build.managed.tests.StandardBuildTests; import org.eclipse.cdt.core.build.managed.tests.StandardBuildTests;
import org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest;
import org.eclipse.cdt.core.indexer.tests.DependencyTests; import org.eclipse.cdt.core.indexer.tests.DependencyTests;
import org.eclipse.cdt.core.indexer.tests.IndexManagerTests; import org.eclipse.cdt.core.indexer.tests.IndexManagerTests;
import org.eclipse.cdt.core.model.failedTests.CModelElementsFailedTests; import org.eclipse.cdt.core.model.failedTests.CModelElementsFailedTests;
@ -59,7 +58,6 @@ public class AutomatedIntegrationSuite extends TestSuite {
suite.addTest(ElementDeltaTests.suite()); suite.addTest(ElementDeltaTests.suite());
suite.addTest(WorkingCopyTests.suite()); suite.addTest(WorkingCopyTests.suite());
suite.addTest(SearchTestSuite.suite()); suite.addTest(SearchTestSuite.suite());
suite.addTestSuite( CompletionProposalsTest.class);
suite.addTest(DependencyTests.suite()); suite.addTest(DependencyTests.suite());
//Indexer Tests need to be run after any indexer client tests //Indexer Tests need to be run after any indexer client tests
//as the last test shuts down the indexing thread //as the last test shuts down the indexing thread

View file

@ -6,9 +6,6 @@ org.eclipse.cdt.core/debug/model=false
# Reports parser activity # Reports parser activity
org.eclipse.cdt.core/debug/parser=false org.eclipse.cdt.core/debug/parser=false
# Reports contentAssist activity
org.eclipse.cdt.core/debug/contentassist=false
# Reports background indexer activity: indexing, saving index file, index queries # Reports background indexer activity: indexing, saving index file, index queries
org.eclipse.cdt.core/debug/indexmanager=false org.eclipse.cdt.core/debug/indexmanager=false

View file

@ -1,3 +1,6 @@
2004-01-15 Hoda Amer
Moved Content Assist log to the UI plugin
2004-01-13 Alain Magloire 2004-01-13 Alain Magloire
Small fix on in the elf parser, we have to check for Small fix on in the elf parser, we have to check for

View file

@ -7,7 +7,6 @@ package org.eclipse.cdt.core.model;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.internal.core.model.IBufferFactory; import org.eclipse.cdt.internal.core.model.IBufferFactory;
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
/** /**
* Represents an entire C translation unit (<code>.c</code> source file). * Represents an entire C translation unit (<code>.c</code> source file).

View file

@ -1,4 +1,4 @@
package org.eclipse.cdt.internal.core.model; package org.eclipse.cdt.core.model;
/********************************************************************** /**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others. * Copyright (c) 2002,2003 Rational Software Corporation and others.
@ -12,8 +12,6 @@ package org.eclipse.cdt.internal.core.model;
***********************************************************************/ ***********************************************************************/
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;

View file

@ -18,6 +18,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.model.*;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ElementChangedEvent; import org.eclipse.cdt.core.model.ElementChangedEvent;
import org.eclipse.cdt.core.model.IArchive; import org.eclipse.cdt.core.model.IArchive;

View file

@ -23,6 +23,4 @@ public interface IDebugLogConstants {
public static final DebugLogConstant PARSER = new DebugLogConstant( 1 ); public static final DebugLogConstant PARSER = new DebugLogConstant( 1 );
public static final DebugLogConstant MODEL = new DebugLogConstant ( 2 ); public static final DebugLogConstant MODEL = new DebugLogConstant ( 2 );
public static final DebugLogConstant CONTENTASSIST = new DebugLogConstant ( 3 );
} }

View file

@ -11,6 +11,7 @@ import java.util.Iterator;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.*;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IBuffer; import org.eclipse.cdt.core.model.IBuffer;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;

View file

@ -26,7 +26,6 @@ public class Util implements ICLogConstants {
public static boolean VERBOSE_PARSER = false; public static boolean VERBOSE_PARSER = false;
public static boolean VERBOSE_MODEL = false; public static boolean VERBOSE_MODEL = false;
public static boolean VERBOSE_CONTENTASSIST = false;
private Util() { private Util() {
} }
@ -218,9 +217,6 @@ public class Util implements ICLogConstants {
else if (client.equals(IDebugLogConstants.MODEL)){ else if (client.equals(IDebugLogConstants.MODEL)){
return VERBOSE_MODEL; return VERBOSE_MODEL;
} }
else if (client.equals(IDebugLogConstants.CONTENTASSIST)){
return VERBOSE_CONTENTASSIST;
}
return false; return false;
} }

View file

@ -66,7 +66,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
} }
/** /**
* @see org.eclipse.cdt.internal.core.model.IWorkingCopy#commit(boolean, org.eclipse.core.runtime.IProgressMonitor) * @see org.eclipse.cdt.core.model.IWorkingCopy#commit(boolean, org.eclipse.core.runtime.IProgressMonitor)
*/ */
public void commit(boolean force, IProgressMonitor monitor) public void commit(boolean force, IProgressMonitor monitor)
throws CModelException { throws CModelException {
@ -106,7 +106,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
} }
/** /**
* @see org.eclipse.cdt.internal.core.model.IWorkingCopy#destroy() * @see org.eclipse.cdt.core.model.IWorkingCopy#destroy()
*/ */
public void destroy() { public void destroy() {
if (--this.useCount > 0) { if (--this.useCount > 0) {
@ -171,7 +171,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
} }
/** /**
* @see org.eclipse.cdt.internal.core.model.IWorkingCopy#getOriginalElement() * @see org.eclipse.cdt.core.model.IWorkingCopy#getOriginalElement()
*/ */
public ITranslationUnit getOriginalElement() { public ITranslationUnit getOriginalElement() {
return new TranslationUnit(getParent(), getFile()); return new TranslationUnit(getParent(), getFile());
@ -281,7 +281,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
/** /**
* @see org.eclipse.cdt.internal.core.model.IWorkingCopy#reconcile() * @see org.eclipse.cdt.core.model.IWorkingCopy#reconcile()
*/ */
public IMarker[] reconcile() throws CModelException { public IMarker[] reconcile() throws CModelException {
reconcile(false, null); reconcile(false, null);
@ -289,7 +289,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
} }
/** /**
* @see org.eclipse.cdt.internal.core.model.IWorkingCopy#reconcile(boolean, org.eclipse.core.runtime.IProgressMonitor) * @see org.eclipse.cdt.core.model.IWorkingCopy#reconcile(boolean, org.eclipse.core.runtime.IProgressMonitor)
*/ */
public boolean reconcile(boolean forceProblemDetection, IProgressMonitor monitor) public boolean reconcile(boolean forceProblemDetection, IProgressMonitor monitor)
throws CModelException { throws CModelException {
@ -343,7 +343,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
return somethingChanged; return somethingChanged;
} }
/** /**
* @see org.eclipse.cdt.internal.core.model.IWorkingCopy#restore() * @see org.eclipse.cdt.core.model.IWorkingCopy#restore()
*/ */
public void restore() throws CModelException{ public void restore() throws CModelException{
if (this.useCount == 0) throw newNotPresentException(); //was destroyed if (this.useCount == 0) throw newNotPresentException(); //was destroyed

File diff suppressed because it is too large Load diff

View file

@ -24,7 +24,7 @@ public interface IASTNode {
public static final LookupKind ALL = new LookupKind( 0 ); public static final LookupKind ALL = new LookupKind( 0 );
public static final LookupKind STRUCTURES = new LookupKind( 1 ); public static final LookupKind STRUCTURES = new LookupKind( 1 );
public static final LookupKind STRUCS = new LookupKind( 2 ); public static final LookupKind STRUCTS = new LookupKind( 2 );
public static final LookupKind UNIONS = new LookupKind( 3 ); public static final LookupKind UNIONS = new LookupKind( 3 );
public static final LookupKind CLASSES = new LookupKind( 4 ); public static final LookupKind CLASSES = new LookupKind( 4 );
public static final LookupKind FUNCTIONS = new LookupKind( 5 ); public static final LookupKind FUNCTIONS = new LookupKind( 5 );

View file

@ -74,7 +74,7 @@ public class TypeFilter {
return false; return false;
} }
} }
else if ( typeInfo.isType( TypeInfo.t_type ) || typeInfo.isType( TypeInfo.t_bool, TypeInfo.t_enumerator ) ) else if ( typeInfo.isType( TypeInfo.t_type ) || typeInfo.isType( TypeInfo.t_bool, TypeInfo.t_void ) )
{ {
if( ( acceptedKinds.contains( LookupKind.VARIABLES ) && !symbolIsMember && !symbolIsLocal ) || if( ( acceptedKinds.contains( LookupKind.VARIABLES ) && !symbolIsMember && !symbolIsLocal ) ||
( acceptedKinds.contains( LookupKind.LOCAL_VARIABLES ) && !symbolIsMember && symbolIsLocal ) || ( acceptedKinds.contains( LookupKind.LOCAL_VARIABLES ) && !symbolIsMember && symbolIsLocal ) ||
@ -99,7 +99,7 @@ public class TypeFilter {
else if ( kind == LookupKind.STRUCTURES ) { acceptedTypes.add( TypeInfo.t_class ); else if ( kind == LookupKind.STRUCTURES ) { acceptedTypes.add( TypeInfo.t_class );
acceptedTypes.add( TypeInfo.t_struct ); acceptedTypes.add( TypeInfo.t_struct );
acceptedTypes.add( TypeInfo.t_union ); } acceptedTypes.add( TypeInfo.t_union ); }
else if ( kind == LookupKind.STRUCS ) { acceptedTypes.add( TypeInfo.t_struct ); } else if ( kind == LookupKind.STRUCTS ) { acceptedTypes.add( TypeInfo.t_struct ); }
else if ( kind == LookupKind.UNIONS ) { acceptedTypes.add( TypeInfo.t_union ); } else if ( kind == LookupKind.UNIONS ) { acceptedTypes.add( TypeInfo.t_union ); }
else if ( kind == LookupKind.CLASSES ) { acceptedTypes.add( TypeInfo.t_class ); } else if ( kind == LookupKind.CLASSES ) { acceptedTypes.add( TypeInfo.t_class ); }
else if ( kind == LookupKind.CONSTRUCTORS ){ acceptedTypes.add( TypeInfo.t_constructor ); } else if ( kind == LookupKind.CONSTRUCTORS ){ acceptedTypes.add( TypeInfo.t_constructor ); }

View file

@ -119,7 +119,7 @@ public class ASTUtil {
type.append("("); type.append("(");
type.append(getPointerOperator(po)); type.append(getPointerOperator(po));
type.append(")"); type.append(")");
String[] parameters =getParameterTypes(declaration.getParameters()); String[] parameters =getParameterTypes(declaration.getParameters(), false /* replace with takeVarArgs() later*/);
type.append(getParametersString(parameters)); type.append(getParametersString(parameters));
} }
return type.toString(); return type.toString();
@ -200,19 +200,25 @@ public class ASTUtil {
public static String[] getFunctionParameterTypes(IASTFunction functionDeclaration) public static String[] getFunctionParameterTypes(IASTFunction functionDeclaration)
{ {
Iterator parameters = functionDeclaration.getParameters(); Iterator parameters = functionDeclaration.getParameters();
return getParameterTypes(parameters); return getParameterTypes(parameters, functionDeclaration.takesVarArgs());
} }
public static String[] getParameterTypes(Iterator parameters){ public static String[] getParameterTypes(Iterator parameters, boolean takesVarArgs){
List paramList = new ArrayList(); List paramList = new ArrayList();
while (parameters.hasNext()){ while (parameters.hasNext()){
IASTParameterDeclaration param = (IASTParameterDeclaration)parameters.next(); IASTParameterDeclaration param = (IASTParameterDeclaration)parameters.next();
paramList.add(getType(param)); paramList.add(getType(param));
} }
String[] parameterTypes = new String[paramList.size()]; int paramListSize = paramList.size();
if(takesVarArgs)
paramListSize++;
String[] parameterTypes = new String[paramListSize];
for(int i=0; i<paramList.size(); ++i){ for(int i=0; i<paramList.size(); ++i){
parameterTypes[i] = (String)paramList.get(i); parameterTypes[i] = (String)paramList.get(i);
} }
// add the ellipse to the parameter type list
if(takesVarArgs)
parameterTypes[paramListSize-1] = "...";
return parameterTypes; return parameterTypes;
} }
public static String getParametersString(String[] parameterTypes) public static String getParametersString(String[] parameterTypes)

View file

@ -20,9 +20,9 @@ import java.util.Iterator;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.model.CModelManager; import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.search.AcceptMatchOperation; import org.eclipse.cdt.internal.core.search.AcceptMatchOperation;
import org.eclipse.cdt.internal.core.search.CSearchScope; import org.eclipse.cdt.internal.core.search.CSearchScope;
import org.eclipse.cdt.internal.core.search.CWorkspaceScope; import org.eclipse.cdt.internal.core.search.CWorkspaceScope;

View file

@ -26,6 +26,7 @@ import java.util.LinkedList;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.DefaultProblemHandler; import org.eclipse.cdt.core.parser.DefaultProblemHandler;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.IProblem;
@ -80,7 +81,6 @@ import org.eclipse.cdt.core.search.ICSearchPattern;
import org.eclipse.cdt.core.search.ICSearchResultCollector; import org.eclipse.cdt.core.search.ICSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchScope; import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.IMatch; import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;

View file

@ -17,6 +17,7 @@ import java.util.MissingResourceException;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.IScannerInfoProvider; import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.core.search.SearchEngine;
@ -26,7 +27,6 @@ import org.eclipse.cdt.internal.core.model.BufferManager;
import org.eclipse.cdt.internal.core.model.CModelManager; import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.cdt.internal.core.model.DeltaProcessor; import org.eclipse.cdt.internal.core.model.DeltaProcessor;
import org.eclipse.cdt.internal.core.model.IBufferFactory; import org.eclipse.cdt.internal.core.model.IBufferFactory;
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.model.Util; import org.eclipse.cdt.internal.core.model.Util;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager; import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.indexing.SourceIndexer; import org.eclipse.cdt.internal.core.search.indexing.SourceIndexer;
@ -731,9 +731,6 @@ public class CCorePlugin extends Plugin {
option = Platform.getDebugOption(MODEL); option = Platform.getDebugOption(MODEL);
if(option != null) Util.VERBOSE_MODEL = option.equalsIgnoreCase("true") ; //$NON-NLS-1$ if(option != null) Util.VERBOSE_MODEL = option.equalsIgnoreCase("true") ; //$NON-NLS-1$
option = Platform.getDebugOption(CONTENTASSIST);
if(option != null) Util.VERBOSE_CONTENTASSIST = option.equalsIgnoreCase("true") ; //$NON-NLS-1$
boolean indexFlag = false; boolean indexFlag = false;
option = Platform.getDebugOption(INDEX_MANAGER); option = Platform.getDebugOption(INDEX_MANAGER);

View file

@ -3,7 +3,26 @@
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="ui"/> <classpathentry kind="src" path="ui"/>
<classpathentry kind="src" path="core"/> <classpathentry kind="src" path="core"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.jface.text_3.0.0/jfacetextsrc.zip" kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.jface.text_3.0.0/jfacetext.jar"/>
<classpathentry sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.text_3.0.0/textsrc.zip" kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.text_3.0.0/text.jar"/>
<classpathentry sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.core.resources_3.0.0/resourcessrc.zip" kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.core.resources_3.0.0/resources.jar"/>
<classpathentry kind="src" path="/org.eclipse.cdt.ui"/>
<classpathentry sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_WIN32_WIN32_X86_SRC/org.eclipse.swt.win32_3.0.0/ws/win32/swtsrc.zip" kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.swt.win32_3.0.0/ws/win32/swt.jar"/>
<classpathentry sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.ui_3.0.0/uisrc.zip" kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.ui_3.0.0/ui.jar"/>
<classpathentry sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.jface_3.0.0/jfacesrc.zip" kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.jface_3.0.0/jface.jar"/>
<classpathentry sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.ui.workbench_3.0.0/workbenchsrc.zip" kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.ui.workbench_3.0.0/workbench.jar"/>
<classpathentry sourcepath="ORG_ECLIPSE_JDT_SOURCE_SRC/org.junit_3.8.1/junitsrc.zip" kind="var" path="ECLIPSE_HOME/plugins/org.junit_3.8.1/junit.jar"/>
<classpathentry sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.core.runtime.compatibility_3.0.0/compatibilitysrc.zip" kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.core.runtime.compatibility_3.0.0/compatibility.jar"/>
<classpathentry sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.core.runtime_3.0.0/runtimesrc.zip" kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.core.runtime_3.0.0/runtime.jar"/>
<classpathentry sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.osgi.util_3.0.0/utilsrc.zip" kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.osgi.util_3.0.0/util.jar"/>
<classpathentry sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.osgi_3.0.0/osgisrc.zip" kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.osgi_3.0.0/osgi.jar"/>
<classpathentry sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.osgi_3.0.0/coresrc.zip" kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.osgi_3.0.0/core.jar"/>
<classpathentry sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.osgi_3.0.0/resolversrc.zip" kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.osgi_3.0.0/resolver.jar"/>
<classpathentry sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.osgi_3.0.0/defaultAdaptorsrc.zip" kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.osgi_3.0.0/defaultAdaptor.jar"/>
<classpathentry sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.osgi_3.0.0/eclipseAdaptorsrc.zip" kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.osgi_3.0.0/eclipseAdaptor.jar"/>
<classpathentry sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.update.configurator_3.0.0/configuratorsrc.zip" kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.update.configurator_3.0.0/configurator.jar"/>
<classpathentry kind="src" path="/org.eclipse.cdt.core"/>
<classpathentry kind="src" path="/org.eclipse.cdt.core.tests"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View file

@ -4,6 +4,7 @@
<comment></comment> <comment></comment>
<projects> <projects>
<project>org.eclipse.cdt.core</project> <project>org.eclipse.cdt.core</project>
<project>org.eclipse.cdt.core.tests</project>
<project>org.eclipse.cdt.ui</project> <project>org.eclipse.cdt.ui</project>
</projects> </projects>
<buildSpec> <buildSpec>

View file

@ -1,3 +1,8 @@
2004-01-15 Hoda Amer
Moved Content Assist testing to the UI.tests plugin
Started a new framework of JUnit tests for content assist.
Added Content assist tests to the AutomatedSuite test of the UI.tests plugin
2003-07-17 Peter Graves 2003-07-17 Peter Graves
Remove the usage of the assert, as it's a reserved keyword in Remove the usage of the assert, as it's a reserved keyword in
Java 1.4 (Bugzilla 40377) Java 1.4 (Bugzilla 40377)

View file

@ -19,6 +19,8 @@
<import plugin="org.eclipse.ui"/> <import plugin="org.eclipse.ui"/>
<import plugin="org.junit"/> <import plugin="org.junit"/>
<import plugin="org.eclipse.core.runtime.compatibility"/> <import plugin="org.eclipse.core.runtime.compatibility"/>
<import plugin="org.eclipse.cdt.core"/>
<import plugin="org.eclipse.cdt.core.tests"/>
</requires> </requires>

View file

@ -0,0 +1,30 @@
#define AMacro(x) x+1
int aVariable = 0;
bool aFunction();
enum anEnumeration {
aFirstEnum,
aSecondEnum,
aThirdEnum
};
struct AStruct{
int aStructField;
};
void anotherFunction(){
int aLocalDeclaration = 1;
}
class aClass {
public:
int aField;
int aMethod();
};
class anotherClass {
public:
int anotherField;
void anotherMethod();
};

View file

@ -0,0 +1,6 @@
#include "CompletionTestStart.h"
void anotherClass::anotherMethod()
{
a
}

View file

@ -0,0 +1,7 @@
#include "CompletionTestStart.h"
void anotherClass::anotherMethod()
{
aClass c;
c.a
}

View file

@ -0,0 +1,3 @@
#include "CompletionTestStart.h"
a

View file

@ -9,6 +9,9 @@ import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.eclipse.cdt.ui.tests.text.PartitionTokenScannerTest; import org.eclipse.cdt.ui.tests.text.PartitionTokenScannerTest;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionProposalsTest1;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionProposalsTest2;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionProposalsTest3;
import org.eclipse.cdt.ui.tests.textmanipulation.TextBufferTest; import org.eclipse.cdt.ui.tests.textmanipulation.TextBufferTest;
@ -32,8 +35,9 @@ public class AutomatedSuite extends TestSuite {
public AutomatedSuite() { public AutomatedSuite() {
addTest(PartitionTokenScannerTest.suite()); addTest(PartitionTokenScannerTest.suite());
addTest(TextBufferTest.suite()); addTest(TextBufferTest.suite());
addTest(CompletionProposalsTest1.suite());
addTest(CompletionProposalsTest2.suite());
addTest(CompletionProposalsTest3.suite());
} }
} }

View file

@ -0,0 +1,200 @@
/**********************************************************************
* Copyright (c) 2004 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.ui.tests.text.contentassist;
/**
* @author hamer
*
* This abstract class is the base class for all completion proposals test cases
*
*/
import java.io.FileInputStream;
import junit.framework.TestCase;
import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.internal.core.model.TranslationUnit;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.ui.text.contentassist.CCompletionProcessor;
import org.eclipse.cdt.testplugin.CProjectHelper;
import org.eclipse.core.internal.resources.ResourceException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
public abstract class CompletionProposalsTest extends TestCase{
private final String pluginName = "org.eclipse.cdt.ui.tests";
private final String projectName = "TestProject1";
private final String projectType = "bin";
private ICProject fCProject;
private IFile fCFile;
private IFile fHeaderFile;
private NullProgressMonitor monitor;
private TranslationUnit tu = null;
private String buffer = "";
private Document document = null;
public CompletionProposalsTest(String name) {
super(name);
}
/*
* Derived classes have to provide there abstract methods
*/
protected abstract String getFileName();
protected abstract String getFileFullPath();
protected abstract String getHeaderFileName();
protected abstract String getHeaderFileFullPath();
protected abstract int getCompletionPosition();
protected abstract String getExpectedScopeClassName();
protected abstract String getExpectedContextClassName();
protected abstract String getExpectedPrefix();
protected abstract IASTCompletionNode.CompletionKind getExpectedKind();
protected abstract String[] getExpectedResultsValues();
protected void setUp() throws Exception {
monitor = new NullProgressMonitor();
String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin(pluginName).find(new Path("/")).getFile();
fCProject= CProjectHelper.createCProject(projectName, projectType);
fHeaderFile = fCProject.getProject().getFile(getHeaderFileName());
String fileName = getFileName();
fCFile = fCProject.getProject().getFile(fileName);
if ( (!fCFile.exists()) &&( !fHeaderFile.exists() )) {
try{
String fileFullPath = pluginRoot+ getFileFullPath();
FileInputStream headerFileIn = new FileInputStream(pluginRoot+ getHeaderFileFullPath());
fHeaderFile.create(headerFileIn,false, monitor);
FileInputStream bodyFileIn = new FileInputStream(fileFullPath);
fCFile.create(bodyFileIn,false, monitor);
} catch (CoreException e) {
e.printStackTrace();
}
}
if (!fCProject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
addNatureToProject(fCProject.getProject(), CCProjectNature.CC_NATURE_ID, null);
}
// use the new indexer
IndexManager indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
indexManager.reset();
}
private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
IProjectDescription description = proj.getDescription();
String[] prevNatures= description.getNatureIds();
String[] newNatures= new String[prevNatures.length + 1];
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
newNatures[prevNatures.length]= natureId;
description.setNatureIds(newNatures);
proj.setDescription(description, monitor);
}
protected void tearDown() {
try{
CProjectHelper.delete(fCProject);
}
catch (ResourceException e) {}
catch (CoreException e) {}
}
public void testCompletionProposals(){
try{
// setup the translation unit, the buffer and the document
TranslationUnit header = new TranslationUnit(fCProject, fHeaderFile);
tu = new TranslationUnit(fCProject, fCFile);
buffer = tu.getBuffer().getContents();
document = new Document(buffer);
int pos = getCompletionPosition();
CCompletionProcessor completionProcessor = new CCompletionProcessor(null);
IWorkingCopy wc = null;
try{
wc = tu.getWorkingCopy();
}catch (CModelException e){
fail("Failed to get working copy");
}
// call the CompletionProcessor
ICompletionProposal[] results = completionProcessor.evalProposals(document, pos, wc, null);
assertTrue(results != null);
// check the completion node
IASTCompletionNode completionNode = completionProcessor.getCurrentCompletionNode();
assertNotNull(completionNode);
// scope
IASTScope scope = completionNode.getCompletionScope();
assertNotNull(scope);
String scopeClassName = scope.getClass().getName();
assertTrue(scope.getClass().getName().endsWith(getExpectedScopeClassName()));
// context
IASTNode context = completionNode.getCompletionContext();
if(context == null)
assertTrue(getExpectedContextClassName().equals("null"));
else
assertTrue(context.getClass().getName().endsWith(getExpectedContextClassName()));
// kind
IASTCompletionNode.CompletionKind kind = completionNode.getCompletionKind();
assertTrue(kind == getExpectedKind());
// prefix
String prefix = completionNode.getCompletionPrefix();
assertEquals(prefix, getExpectedPrefix());
String[] expected = getExpectedResultsValues();
assertEquals(results.length, expected.length);
for (int i = 0; i<results.length; i++){
ICompletionProposal proposal = results[i];
String displayString = proposal.getDisplayString();
assertEquals(displayString, expected[i]);
}
} catch(CModelException e){
}
}
/**
* @return Returns the buffer.
*/
public String getBuffer() {
return buffer;
}
/**
* @return Returns the document.
*/
public Document getDocument() {
return document;
}
/**
* @return Returns the tu.
*/
public TranslationUnit getTranslationUnit() {
return tu;
}
}

View file

@ -0,0 +1,125 @@
/*******************************************************************************
* Copyright (c) 2001 Rational Software Corp. 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:
* Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
/**
* @author hamer
*
*/
public class CompletionProposalsTest1 extends CompletionProposalsTest{
private final String fileName = "CompletionTestStart1.cpp";
private final String fileFullPath ="resources/contentassist/" + fileName;
private final String headerFileName = "CompletionTestStart.h";
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedScopeName = "ASTMethod";
private final String expectedContextName = "null";
private final CompletionKind expectedKind = CompletionKind.STATEMENT_START;
private final String expectedPrefix = "a";
private final String[] expectedResults = {
"anotherField : int",
"aVariable : int",
"anotherMethod() void",
"aFunction() bool",
"anotherFunction() void",
"aClass",
"anotherClass",
"anEnumeration",
"AStruct",
// "AMacro",
"asm",
"auto"
};
public CompletionProposalsTest1(String name) {
super(name);
}
public static Test suite() {
TestSuite suite= new TestSuite(CompletionProposalsTest1.class.getName());
suite.addTest(new CompletionProposalsTest1("testCompletionProposals"));
return suite;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getCompletionPosition()
*/
protected int getCompletionPosition() {
return getBuffer().indexOf(" a ") + 2;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedScope()
*/
protected String getExpectedScopeClassName() {
return expectedScopeName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedContext()
*/
protected String getExpectedContextClassName() {
return expectedContextName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedKind()
*/
protected CompletionKind getExpectedKind() {
return expectedKind;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedPrefix()
*/
protected String getExpectedPrefix() {
return expectedPrefix;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedResultsValues()
*/
protected String[] getExpectedResultsValues() {
return expectedResults;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileName()
*/
protected String getFileName() {
return fileName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileFullPath()
*/
protected String getFileFullPath() {
return fileFullPath;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileFullPath()
*/
protected String getHeaderFileFullPath() {
return headerFileFullPath;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileName()
*/
protected String getHeaderFileName() {
return headerFileName;
}
}

View file

@ -0,0 +1,113 @@
/**********************************************************************
* Copyright (c) 2004 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.ui.tests.text.contentassist;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
/**
* @author hamer
*
*/
public class CompletionProposalsTest2 extends CompletionProposalsTest{
private final String fileName = "CompletionTestStart2.cpp";
private final String fileFullPath ="resources/contentassist/" + fileName;
private final String headerFileName = "CompletionTestStart.h";
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedScopeName = "ASTMethod";
private final String expectedContextName = "ASTClassSpecifier";
private final CompletionKind expectedKind = CompletionKind.MEMBER_REFERENCE;
private final String expectedPrefix = "a";
private final String[] expectedResults = {
"aField : int",
"aMethod() int"
};
public CompletionProposalsTest2(String name) {
super(name);
}
public static Test suite() {
TestSuite suite= new TestSuite(CompletionProposalsTest2.class.getName());
suite.addTest(new CompletionProposalsTest2("testCompletionProposals"));
return suite;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getCompletionPosition()
*/
protected int getCompletionPosition() {
return getBuffer().indexOf(" c.a ") + 4;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedScope()
*/
protected String getExpectedScopeClassName() {
return expectedScopeName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedContext()
*/
protected String getExpectedContextClassName() {
return expectedContextName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedKind()
*/
protected CompletionKind getExpectedKind() {
return expectedKind;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedPrefix()
*/
protected String getExpectedPrefix() {
return expectedPrefix;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedResultsValues()
*/
protected String[] getExpectedResultsValues() {
return expectedResults;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileName()
*/
protected String getFileName() {
return fileName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileFullPath()
*/
protected String getFileFullPath() {
return fileFullPath;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileFullPath()
*/
protected String getHeaderFileFullPath() {
return headerFileFullPath;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileName()
*/
protected String getHeaderFileName() {
return headerFileName;
}
}

View file

@ -0,0 +1,118 @@
/**********************************************************************
* Copyright (c) 2004 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.ui.tests.text.contentassist;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
/**
* @author hamer
*
*/
public class CompletionProposalsTest3 extends CompletionProposalsTest{
private final String fileName = "CompletionTestStart3.cpp";
private final String fileFullPath ="resources/contentassist/" + fileName;
private final String headerFileName = "CompletionTestStart.h";
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedScopeName = "ASTCompilationUnit";
private final String expectedContextName = "null";
private final CompletionKind expectedKind = CompletionKind.VARIABLE_TYPE;
private final String expectedPrefix = "a";
private final String[] expectedResults = {
"aClass",
"anotherClass",
"anEnumeration",
"AStruct",
// "AMacro",
"asm",
"auto"
};
public CompletionProposalsTest3(String name) {
super(name);
}
public static Test suite() {
TestSuite suite= new TestSuite(CompletionProposalsTest2.class.getName());
suite.addTest(new CompletionProposalsTest2("testCompletionProposals"));
return suite;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getCompletionPosition()
*/
protected int getCompletionPosition() {
return getBuffer().indexOf(" c.a ") + 4;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedScope()
*/
protected String getExpectedScopeClassName() {
return expectedScopeName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedContext()
*/
protected String getExpectedContextClassName() {
return expectedContextName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedKind()
*/
protected CompletionKind getExpectedKind() {
return expectedKind;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedPrefix()
*/
protected String getExpectedPrefix() {
return expectedPrefix;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedResultsValues()
*/
protected String[] getExpectedResultsValues() {
return expectedResults;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileName()
*/
protected String getFileName() {
return fileName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileFullPath()
*/
protected String getFileFullPath() {
return fileFullPath;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileFullPath()
*/
protected String getHeaderFileFullPath() {
return headerFileFullPath;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileName()
*/
protected String getHeaderFileName() {
return headerFileName;
}
}

View file

@ -0,0 +1,5 @@
org.eclipse.cdt.ui/debug=true
# Reports contentAssist activity
org.eclipse.cdt.ui/debug/contentassist=false

View file

@ -1,3 +1,6 @@
2004-01-15 Hoda Amer
Moved Content Assist log to the UI plugin
2004-01-15 John Camelon 2004-01-15 John Camelon
Updated references to LookupResult as it was renamed to ILookupResult. Updated references to LookupResult as it was renamed to ILookupResult.
Updated references of ParserFactoryException to ParserFactoryError. Updated references of ParserFactoryException to ParserFactoryError.

View file

@ -9,7 +9,7 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.model.WorkingCopy; import org.eclipse.cdt.internal.core.model.WorkingCopy;
import org.eclipse.cdt.internal.ui.CFileElementWorkingCopy; import org.eclipse.cdt.internal.ui.CFileElementWorkingCopy;
import org.eclipse.cdt.internal.ui.StandardCElementLabelProvider; import org.eclipse.cdt.internal.ui.StandardCElementLabelProvider;

View file

@ -14,8 +14,8 @@ import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IBuffer; import org.eclipse.cdt.core.model.IBuffer;
import org.eclipse.cdt.core.model.IOpenable; import org.eclipse.cdt.core.model.IOpenable;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.model.IBufferFactory; import org.eclipse.cdt.internal.core.model.IBufferFactory;
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.ui.CStatusConstants; import org.eclipse.cdt.internal.ui.CStatusConstants;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.IEditorInputDelegate; import org.eclipse.cdt.ui.IEditorInputDelegate;

View file

@ -17,7 +17,7 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ISourceRange; import org.eclipse.cdt.core.model.ISourceRange;
import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.ui.IContextMenuConstants; import org.eclipse.cdt.internal.ui.IContextMenuConstants;
import org.eclipse.cdt.internal.ui.editor.asm.AsmTextTools; import org.eclipse.cdt.internal.ui.editor.asm.AsmTextTools;
import org.eclipse.cdt.internal.ui.text.CPairMatcher; import org.eclipse.cdt.internal.ui.text.CPairMatcher;

View file

@ -16,7 +16,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.ui.IWorkingCopyManager; import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.cdt.ui.IWorkingCopyManagerExtension; import org.eclipse.cdt.ui.IWorkingCopyManagerExtension;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;

View file

@ -7,7 +7,7 @@ package org.eclipse.cdt.internal.ui.text;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.ui.editor.CContentOutlinePage; import org.eclipse.cdt.internal.ui.editor.CContentOutlinePage;
import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;

View file

@ -13,6 +13,7 @@ import java.util.List;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
import org.eclipse.cdt.core.search.BasicSearchMatch; import org.eclipse.cdt.core.search.BasicSearchMatch;
@ -20,7 +21,6 @@ import org.eclipse.cdt.core.search.BasicSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchConstants; import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchScope; import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.search.matching.OrPattern; import org.eclipse.cdt.internal.core.search.matching.OrPattern;
import org.eclipse.cdt.internal.corext.template.ContextType; import org.eclipse.cdt.internal.corext.template.ContextType;
import org.eclipse.cdt.internal.corext.template.ContextTypeRegistry; import org.eclipse.cdt.internal.corext.template.ContextTypeRegistry;
@ -119,6 +119,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
private int fCurrentOffset = 0; private int fCurrentOffset = 0;
private IWorkingCopy fCurrentSourceUnit = null; private IWorkingCopy fCurrentSourceUnit = null;
private IASTCompletionNode fCurrentCompletionNode = null;
private int fNumberOfComputedResults= 0; private int fNumberOfComputedResults= 0;
private ITextViewer fTextViewer; private ITextViewer fTextViewer;
@ -383,12 +384,18 @@ public class CCompletionProcessor implements IContentAssistProcessor {
// clear the completion list at the result collector // clear the completion list at the result collector
resultCollector.reset(viewer); resultCollector.reset(viewer);
IASTCompletionNode completionNode = addProposalsFromModel(completions); fCurrentCompletionNode = addProposalsFromModel(completions);
addProposalsFromSearch(completionNode, completions); if(fCurrentCompletionNode != null){
addProposalsFromCompletionContributors(completionNode, completions); addProposalsFromSearch(fCurrentCompletionNode, completions);
addProposalsFromTemplates(viewer, completionNode, completions); addProposalsFromCompletionContributors(fCurrentCompletionNode, completions);
addProposalsFromTemplates(viewer, fCurrentCompletionNode, completions);
return order ( (ICCompletionProposal[]) completions.toArray(new ICCompletionProposal[0]) ); return order ( (ICCompletionProposal[]) completions.toArray(new ICCompletionProposal[0]) );
}
else{
return null;
}
} }
private void addProposalsFromTemplates(ITextViewer viewer, IASTCompletionNode completionNode, List completions){ private void addProposalsFromTemplates(ITextViewer viewer, IASTCompletionNode completionNode, List completions){
@ -670,4 +677,12 @@ public class CCompletionProcessor implements IContentAssistProcessor {
} // end switch } // end switch
} // end while } // end while
} }
/**
* @return Returns the fCurrentCompletionNode.
* This method is added for JUnit tests.
*/
public IASTCompletionNode getCurrentCompletionNode() {
return fCurrentCompletionNode;
}
} }

View file

@ -19,6 +19,7 @@ import java.util.List;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfo;
@ -50,10 +51,9 @@ import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind; import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind;
import org.eclipse.cdt.core.parser.ast.IASTNode.ILookupResult; import org.eclipse.cdt.core.parser.ast.IASTNode.ILookupResult;
import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.model.IDebugLogConstants;
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.model.Util;
import org.eclipse.cdt.internal.core.parser.util.ASTUtil; import org.eclipse.cdt.internal.core.parser.util.ASTUtil;
import org.eclipse.cdt.internal.ui.util.IDebugLogConstants;
import org.eclipse.cdt.internal.ui.util.Util;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
@ -176,7 +176,7 @@ public class CompletionEngine implements RelevanceConstants{
IScannerInfo buildScanInfo = provider.getScannerInformation(project); IScannerInfo buildScanInfo = provider.getScannerInformation(project);
if( buildScanInfo != null ) if( buildScanInfo != null )
scanInfo = new ScannerInfo(buildScanInfo.getDefinedSymbols(), buildScanInfo.getIncludePaths()); scanInfo = new ScannerInfo(buildScanInfo.getDefinedSymbols(), buildScanInfo.getIncludePaths());
} }
//C or CPP? //C or CPP?
ParserLanguage language = CoreModel.getDefault().hasCCNature(project) ? ParserLanguage.CPP : ParserLanguage.C; ParserLanguage language = CoreModel.getDefault().hasCCNature(project) ? ParserLanguage.CPP : ParserLanguage.C;
@ -339,10 +339,13 @@ public class CompletionEngine implements RelevanceConstants{
} }
private void addKeywordsToCompletions(Iterator keywords){ private void addKeywordsToCompletions(Iterator keywords){
int numOfKeywords = 0;
while (keywords.hasNext()){ while (keywords.hasNext()){
String keyword = (String) keywords.next(); String keyword = (String) keywords.next();
addKeywordToCompletions(keyword); addKeywordToCompletions(keyword);
numOfKeywords++;
} }
log("No of Keywords = " + numOfKeywords);
} }
private void resetElementNumbers(){ private void resetElementNumbers(){
@ -364,6 +367,9 @@ public class CompletionEngine implements RelevanceConstants{
return; return;
Iterator nodes = result.getNodes(); Iterator nodes = result.getNodes();
int numberOfElements = result.getResultsSize(); int numberOfElements = result.getResultsSize();
log("No of Lookup Results = " + numberOfElements);
resetElementNumbers(); resetElementNumbers();
while (nodes.hasNext()){ while (nodes.hasNext()){
IASTNode node = (IASTNode) nodes.next(); IASTNode node = (IASTNode) nodes.next();
@ -418,7 +424,7 @@ public class CompletionEngine implements RelevanceConstants{
ILookupResult result = null; ILookupResult result = null;
// lookup fields and methods with the right visibility // lookup fields and methods with the right visibility
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[7]; IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[8];
kinds[0] = IASTNode.LookupKind.FIELDS; kinds[0] = IASTNode.LookupKind.FIELDS;
kinds[1] = IASTNode.LookupKind.METHODS; kinds[1] = IASTNode.LookupKind.METHODS;
kinds[2] = IASTNode.LookupKind.VARIABLES; kinds[2] = IASTNode.LookupKind.VARIABLES;
@ -426,6 +432,8 @@ public class CompletionEngine implements RelevanceConstants{
kinds[4] = IASTNode.LookupKind.ENUMERATIONS; kinds[4] = IASTNode.LookupKind.ENUMERATIONS;
kinds[5] = IASTNode.LookupKind.NAMESPACES; kinds[5] = IASTNode.LookupKind.NAMESPACES;
kinds[6] = IASTNode.LookupKind.FUNCTIONS; kinds[6] = IASTNode.LookupKind.FUNCTIONS;
kinds[7] = IASTNode.LookupKind.LOCAL_VARIABLES;
result = lookup (searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext()); result = lookup (searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
addToCompletions (result); addToCompletions (result);
} }
@ -491,16 +499,16 @@ public class CompletionEngine implements RelevanceConstants{
IASTScope searchNode = completionNode.getCompletionScope(); IASTScope searchNode = completionNode.getCompletionScope();
// if prefix is not empty // if prefix is not empty
if (completionNode.getCompletionPrefix().length() > 0){ if (completionNode.getCompletionPrefix().length() > 0){
// here we have to look for anything that could be referenced within this scope // here we have to look for any names that could be referenced within this scope
// 1. lookup local variables, global variables, functions, methods, structures, enums, macros, and namespaces // 1. lookup local variables, global variables, functions, methods, structures, enums, macros, and namespaces
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[7]; IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[7];
kinds[0] = IASTNode.LookupKind.LOCAL_VARIABLES; kinds[0] = IASTNode.LookupKind.LOCAL_VARIABLES;
kinds[1] = IASTNode.LookupKind.FIELDS; kinds[1] = IASTNode.LookupKind.FIELDS;
kinds[2] = IASTNode.LookupKind.VARIABLES; kinds[2] = IASTNode.LookupKind.VARIABLES;
kinds[3] = IASTNode.LookupKind.STRUCTURES; kinds[3] = IASTNode.LookupKind.METHODS;
kinds[4] = IASTNode.LookupKind.ENUMERATIONS; kinds[4] = IASTNode.LookupKind.FUNCTIONS;
kinds[5] = IASTNode.LookupKind.METHODS; kinds[5] = IASTNode.LookupKind.NAMESPACES;
kinds[6] = IASTNode.LookupKind.FUNCTIONS; kinds[6] = IASTNode.LookupKind.ENUMERATORS;
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext()); ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
addToCompletions(result); addToCompletions(result);
} else // prefix is empty } else // prefix is empty
@ -571,6 +579,7 @@ public class CompletionEngine implements RelevanceConstants{
} }
public IASTCompletionNode complete(IWorkingCopy sourceUnit, int completionOffset) { public IASTCompletionNode complete(IWorkingCopy sourceUnit, int completionOffset) {
long startTime = System.currentTimeMillis();
// 1- Parse the translation unit // 1- Parse the translation unit
IASTCompletionNode completionNode = parse(sourceUnit, completionOffset); IASTCompletionNode completionNode = parse(sourceUnit, completionOffset);
@ -584,7 +593,13 @@ public class CompletionEngine implements RelevanceConstants{
logNode("Scope = " , completionNode.getCompletionScope()); logNode("Scope = " , completionNode.getCompletionScope());
logNode("Context = " , completionNode.getCompletionContext()); logNode("Context = " , completionNode.getCompletionContext());
logKind("Kind = ", completionNode.getCompletionKind().getEnumValue()); logKind("Kind = ", completionNode.getCompletionKind());
log ("Prefix = " + completionNode.getCompletionPrefix());
if (completionNode.getCompletionScope() == null){
log("Null Completion Scope Error");
return null;
}
// set the completionStart and the completionLength // set the completionStart and the completionLength
completionStart = completionOffset - completionNode.getCompletionPrefix().length(); completionStart = completionOffset - completionNode.getCompletionPrefix().length();
@ -592,149 +607,118 @@ public class CompletionEngine implements RelevanceConstants{
CompletionKind kind = completionNode.getCompletionKind(); CompletionKind kind = completionNode.getCompletionKind();
// 2- Check the return value // 2- Check the return value
if(kind == IASTCompletionNode.CompletionKind.MEMBER_REFERENCE){ if(kind == CompletionKind.MEMBER_REFERENCE){
// completionOnMemberReference // completionOnMemberReference
completionOnMemberReference(completionNode); completionOnMemberReference(completionNode);
} }
else if(kind == IASTCompletionNode.CompletionKind.SCOPED_REFERENCE){ else if(kind == CompletionKind.SCOPED_REFERENCE){
// completionOnMemberReference // completionOnMemberReference
completionOnScopedReference(completionNode); completionOnScopedReference(completionNode);
} }
else if(kind == IASTCompletionNode.CompletionKind.FIELD_TYPE){ else if(kind == CompletionKind.STATEMENT_START )
{
// CompletionOnStatementStart
completionOnStatementStart(completionNode);
}
else if(kind == CompletionKind.FIELD_TYPE){
// CompletionOnFieldType // CompletionOnFieldType
completionOnFieldType(completionNode); completionOnFieldType(completionNode);
} }
else if(kind == IASTCompletionNode.CompletionKind.VARIABLE_TYPE) { else if(kind == CompletionKind.VARIABLE_TYPE) {
// CompletionOnVariableType // CompletionOnVariableType
completionOnVariableType(completionNode); completionOnVariableType(completionNode);
} }
else if(kind == IASTCompletionNode.CompletionKind.ARGUMENT_TYPE){ else if(kind == CompletionKind.ARGUMENT_TYPE){
// CompletionOnArgumentType // CompletionOnArgumentType
completionOnTypeReference(completionNode); completionOnTypeReference(completionNode);
} }
else if(kind == IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE){ else if(kind == CompletionKind.SINGLE_NAME_REFERENCE){
// CompletionOnSingleNameReference // CompletionOnSingleNameReference
completionOnSingleNameReference(completionNode); completionOnSingleNameReference(completionNode);
} }
else if(kind == IASTCompletionNode.CompletionKind.TYPE_REFERENCE){ else if(kind == CompletionKind.TYPE_REFERENCE){
// CompletionOnStructureReference // CompletionOnStructureReference
completionOnTypeReference(completionNode); completionOnTypeReference(completionNode);
} }
else if(kind == IASTCompletionNode.CompletionKind.CLASS_REFERENCE){ else if(kind == CompletionKind.CLASS_REFERENCE){
// CompletionOnClassReference // CompletionOnClassReference
completionOnClassReference(completionNode); completionOnClassReference(completionNode);
} }
else if(kind == IASTCompletionNode.CompletionKind.NAMESPACE_REFERENCE){ else if(kind == CompletionKind.NAMESPACE_REFERENCE){
// completionOnNamespaceReference // completionOnNamespaceReference
completionOnNamespaceReference(completionNode); completionOnNamespaceReference(completionNode);
} }
else if(kind == IASTCompletionNode.CompletionKind.EXCEPTION_REFERENCE){ else if(kind == CompletionKind.EXCEPTION_REFERENCE){
// CompletionOnExceptionReference // CompletionOnExceptionReference
completionOnExceptionReference(completionNode); completionOnExceptionReference(completionNode);
} }
else if(kind == IASTCompletionNode.CompletionKind.MACRO_REFERENCE){ else if(kind == CompletionKind.MACRO_REFERENCE){
// CompletionOnMacroReference // CompletionOnMacroReference
completionOnMacroReference(completionNode); completionOnMacroReference(completionNode);
} }
else if(kind == IASTCompletionNode.CompletionKind.FUNCTION_REFERENCE){ else if(kind == CompletionKind.FUNCTION_REFERENCE){
// completionOnFunctionReference // completionOnFunctionReference
completionOnFunctionReference(completionNode); completionOnFunctionReference(completionNode);
} }
else if(kind == IASTCompletionNode.CompletionKind.CONSTRUCTOR_REFERENCE){ else if(kind == CompletionKind.CONSTRUCTOR_REFERENCE){
// completionOnConstructorReference // completionOnConstructorReference
completionOnConstructorReference(completionNode); completionOnConstructorReference(completionNode);
} }
else if(kind == IASTCompletionNode.CompletionKind.KEYWORD){ else if(kind == CompletionKind.KEYWORD){
// CompletionOnKeyword // CompletionOnKeyword
completionOnKeyword(completionNode); completionOnKeyword(completionNode);
} }
else if(kind == IASTCompletionNode.CompletionKind.STATEMENT_START )
{
completionOnStatementStart(completionNode);
}
addKeywordsToCompletions( completionNode.getKeywords()); if((kind != CompletionKind.MEMBER_REFERENCE) &&(kind != CompletionKind.SCOPED_REFERENCE)){
addKeywordsToCompletions( completionNode.getKeywords());
}
log("Time spent in Completion Engine = "+ ( System.currentTimeMillis() - startTime ) + " ms");
return completionNode; return completionNode;
} }
private void logKind(String message, int kindEnum){ private void logKind(String message, IASTCompletionNode.CompletionKind kind){
if (! CCorePlugin.getDefault().isDebugging() && Util.isActive(IDebugLogConstants.CONTENTASSIST) ) if (! CCorePlugin.getDefault().isDebugging() && Util.isActive(IDebugLogConstants.CONTENTASSIST) )
return; return;
String kindStr = ""; String kindStr = "";
switch (kindEnum){ if(kind == IASTCompletionNode.CompletionKind.MEMBER_REFERENCE)
case 0:
kindStr = "MEMBER_REFERENCE"; kindStr = "MEMBER_REFERENCE";
break; else if(kind == IASTCompletionNode.CompletionKind.SCOPED_REFERENCE)
case 1:
kindStr = "SCOPED_REFERENCE"; kindStr = "SCOPED_REFERENCE";
break; else if(kind == IASTCompletionNode.CompletionKind.FIELD_TYPE)
kindStr = "FIELD_TYPE Class Scope";
case 2: else if(kind == IASTCompletionNode.CompletionKind.VARIABLE_TYPE)
kindStr = "FIELD_TYPE"; kindStr = "VARIABLE_TYPE Global Scope";
break; else if(kind == IASTCompletionNode.CompletionKind.ARGUMENT_TYPE)
case 3:
kindStr = "VARIABLE_TYPE";
break;
case 4:
kindStr = "ARGUMENT_TYPE"; kindStr = "ARGUMENT_TYPE";
break; else if(kind == IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE)
case 5:
kindStr = "SINGLE_NAME_REFERENCE"; kindStr = "SINGLE_NAME_REFERENCE";
break; else if(kind == IASTCompletionNode.CompletionKind.TYPE_REFERENCE)
case 6:
kindStr = "TYPE_REFERENCE"; kindStr = "TYPE_REFERENCE";
break; else if(kind == IASTCompletionNode.CompletionKind.CLASS_REFERENCE)
case 7:
kindStr = "CLASS_REFERENCE"; kindStr = "CLASS_REFERENCE";
break; else if(kind == IASTCompletionNode.CompletionKind.NAMESPACE_REFERENCE)
case 8:
kindStr = "NAMESPACE_REFERENCE"; kindStr = "NAMESPACE_REFERENCE";
break; else if(kind == IASTCompletionNode.CompletionKind.EXCEPTION_REFERENCE)
case 9:
kindStr = "EXCEPTION_REFERENCE"; kindStr = "EXCEPTION_REFERENCE";
break; else if(kind == IASTCompletionNode.CompletionKind.MACRO_REFERENCE)
case 10:
kindStr = "MACRO_REFERENCE"; kindStr = "MACRO_REFERENCE";
break; else if(kind == IASTCompletionNode.CompletionKind.FUNCTION_REFERENCE)
case 11:
kindStr = "FUNCTION_REFERENCE"; kindStr = "FUNCTION_REFERENCE";
break; else if(kind == IASTCompletionNode.CompletionKind.CONSTRUCTOR_REFERENCE)
case 12:
kindStr = "CONSTRUCTOR_REFERENCE"; kindStr = "CONSTRUCTOR_REFERENCE";
break; else if(kind == IASTCompletionNode.CompletionKind.KEYWORD)
case 13:
kindStr = "KEYWORD"; kindStr = "KEYWORD";
break; else if(kind == IASTCompletionNode.CompletionKind.PREPROCESSOR_DIRECTIVE)
case 14:
kindStr = "PREPROCESSOR_DIRECTIVE"; kindStr = "PREPROCESSOR_DIRECTIVE";
break; else if(kind == IASTCompletionNode.CompletionKind.USER_SPECIFIED_NAME)
case 15:
kindStr = "USER_SPECIFIED_NAME"; kindStr = "USER_SPECIFIED_NAME";
break; else if(kind == IASTCompletionNode.CompletionKind.STATEMENT_START)
case 16:
kindStr = "STATEMENT_START"; kindStr = "STATEMENT_START";
break; else if(kind == IASTCompletionNode.CompletionKind.NO_SUCH_KIND)
case 200:
kindStr = "NO_SUCH_KIND"; kindStr = "NO_SUCH_KIND";
break;
}
log (message + kindStr); log (message + kindStr);
} }
private void logNode(String message, IASTNode node){ private void logNode(String message, IASTNode node){
@ -768,6 +752,11 @@ public class CompletionEngine implements RelevanceConstants{
log(message + name); log(message + name);
return; return;
} }
if(node instanceof IASTCodeScope){
String name = "Code Scope";
log(message + name);
return;
}
log(message + node.toString()); log(message + node.toString());
return; return;
@ -780,66 +769,48 @@ public class CompletionEngine implements RelevanceConstants{
StringBuffer kindName = new StringBuffer("Looking For "); StringBuffer kindName = new StringBuffer("Looking For ");
for(int i = 0; i<kinds.length; i++){ for(int i = 0; i<kinds.length; i++){
LookupKind kind = (LookupKind) kinds[i]; LookupKind kind = (LookupKind) kinds[i];
switch (kind.getEnumValue()){ if(kind == IASTNode.LookupKind.ALL)
case 0:
kindName.append("ALL"); kindName.append("ALL");
break; else if(kind == IASTNode.LookupKind.STRUCTURES)
case 1:
kindName.append("STRUCTURES"); kindName.append("STRUCTURES");
break; else if(kind == IASTNode.LookupKind.STRUCTS)
case 2: kindName.append("STRUCTS");
kindName.append("STRUCS"); else if(kind == IASTNode.LookupKind.UNIONS)
break;
case 3:
kindName.append("UNIONS"); kindName.append("UNIONS");
break; else if(kind == IASTNode.LookupKind.CLASSES)
case 4:
kindName.append("CLASSES"); kindName.append("CLASSES");
break; else if(kind == IASTNode.LookupKind.FUNCTIONS)
case 5:
kindName.append("FUNCTIONS"); kindName.append("FUNCTIONS");
break; else if(kind == IASTNode.LookupKind.VARIABLES)
case 6:
kindName.append("VARIABLES"); kindName.append("VARIABLES");
break; else if(kind == IASTNode.LookupKind.LOCAL_VARIABLES)
case 7:
kindName.append("LOCAL_VARIABLES"); kindName.append("LOCAL_VARIABLES");
break; else if(kind == IASTNode.LookupKind.MEMBERS)
case 8:
kindName.append("MEMBERS"); kindName.append("MEMBERS");
break; else if(kind == IASTNode.LookupKind.METHODS)
case 9:
kindName.append("METHODS"); kindName.append("METHODS");
break; else if(kind == IASTNode.LookupKind.FIELDS)
case 10:
kindName.append("FIELDS"); kindName.append("FIELDS");
break; else if(kind == IASTNode.LookupKind.CONSTRUCTORS)
case 11:
kindName.append("CONSTRUCTORS"); kindName.append("CONSTRUCTORS");
break; else if(kind == IASTNode.LookupKind.NAMESPACES)
case 12:
kindName.append("NAMESPACES"); kindName.append("NAMESPACES");
break; else if(kind == IASTNode.LookupKind.MACROS)
case 13:
kindName.append("MACROS"); kindName.append("MACROS");
break; else if(kind == IASTNode.LookupKind.ENUMERATIONS)
case 14:
kindName.append("ENUMERATIONS"); kindName.append("ENUMERATIONS");
break; else if(kind == IASTNode.LookupKind.ENUMERATORS)
case 15:
kindName.append("ENUMERATORS"); kindName.append("ENUMERATORS");
break; else if(kind == IASTNode.LookupKind.THIS)
case 16:
kindName.append("THIS"); kindName.append("THIS");
break;
}
kindName.append(", "); kindName.append(", ");
} }
log (kindName.toString()); log (kindName.toString());
} }
private void log(String message){ private void log(String message){
if (! CCorePlugin.getDefault().isDebugging() && Util.isActive(IDebugLogConstants.CONTENTASSIST)) if (! CUIPlugin.getDefault().isDebugging() && Util.isActive(IDebugLogConstants.CONTENTASSIST))
return; return;
Util.debugLog(message, IDebugLogConstants.CONTENTASSIST, false); Util.debugLog(message, IDebugLogConstants.CONTENTASSIST);
} }
} }

View file

@ -15,8 +15,8 @@ import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.resources.FileStorage; import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.utils.spawner.ProcessFactory; import org.eclipse.cdt.utils.spawner.ProcessFactory;

View file

@ -0,0 +1,30 @@
/**********************************************************************
* Copyright (c) 2004 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.util;
/**
* @author hamer
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public interface IDebugLogConstants {
public class DebugLogConstant {
private DebugLogConstant( int value )
{
this.value = value;
}
private final int value;
}
public static final DebugLogConstant CONTENTASSIST = new DebugLogConstant ( 1 );
}

View file

@ -0,0 +1,50 @@
/**********************************************************************
* Copyright (c) 2004 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.util;
import org.eclipse.cdt.ui.CUIPlugin;
/**
* @author hamer
*
*/
public class Util implements IDebugLogConstants{
public static boolean VERBOSE_CONTENTASSIST = false;
private Util() {
}
/*
* Add a log entry
*/
public static void debugLog(String message, DebugLogConstant client) {
if( CUIPlugin.getDefault() == null ) return;
if ( CUIPlugin.getDefault().isDebugging() && isActive(client)) {
while (message.length() > 100) {
String partial = message.substring(0, 100);
message = message.substring(100);
System.out.println(partial + "\\");
}
if (message.endsWith("\n")) {
System.err.print(message);
} else {
System.out.println(message);
}
}
}
public static boolean isActive(DebugLogConstant client) {
if (client.equals(IDebugLogConstants.CONTENTASSIST)){
return VERBOSE_CONTENTASSIST;
}
return false;
}
}

View file

@ -19,8 +19,8 @@ import java.util.ResourceBundle;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.model.IBufferFactory; import org.eclipse.cdt.internal.core.model.IBufferFactory;
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.ui.BuildConsoleManager; import org.eclipse.cdt.internal.ui.BuildConsoleManager;
import org.eclipse.cdt.internal.ui.CElementAdapterFactory; import org.eclipse.cdt.internal.ui.CElementAdapterFactory;
import org.eclipse.cdt.internal.ui.CPluginImages; import org.eclipse.cdt.internal.ui.CPluginImages;
@ -36,6 +36,7 @@ import org.eclipse.cdt.internal.ui.preferences.CPluginPreferencePage;
import org.eclipse.cdt.internal.ui.text.CTextTools; import org.eclipse.cdt.internal.ui.text.CTextTools;
import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry; import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry;
import org.eclipse.cdt.internal.ui.util.ProblemMarkerManager; import org.eclipse.cdt.internal.ui.util.ProblemMarkerManager;
import org.eclipse.cdt.internal.ui.util.Util;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
@ -80,6 +81,8 @@ public class CUIPlugin extends AbstractUIPlugin {
private ImageDescriptorRegistry fImageDescriptorRegistry; private ImageDescriptorRegistry fImageDescriptorRegistry;
static String SEPARATOR = System.getProperty("file.separator"); static String SEPARATOR = System.getProperty("file.separator");
private static final String CONTENTASSIST = CUIPlugin.PLUGIN_ID + "/debug/contentassist" ; //$NON-NLS-1$
// -------- static methods -------- // -------- static methods --------
@ -308,6 +311,8 @@ public class CUIPlugin extends AbstractUIPlugin {
*/ */
public void startup() throws CoreException { public void startup() throws CoreException {
super.startup(); super.startup();
//Set debug tracing options
CUIPlugin.getDefault().configurePluginDebugOptions();
runUI(new Runnable() { runUI(new Runnable() {
public void run() { public void run() {
@ -381,4 +386,13 @@ public class CUIPlugin extends AbstractUIPlugin {
fSharedTextColors= new SharedTextColors(); fSharedTextColors= new SharedTextColors();
return fSharedTextColors; return fSharedTextColors;
} }
public void configurePluginDebugOptions(){
if(CUIPlugin.getDefault().isDebugging()){
String option = Platform.getDebugOption(CONTENTASSIST);
if(option != null) Util.VERBOSE_CONTENTASSIST = option.equalsIgnoreCase("true") ; //$NON-NLS-1$
}
}
} }

View file

@ -10,7 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui; package org.eclipse.cdt.ui;
import org.eclipse.cdt.internal.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorInput;

View file

@ -11,7 +11,7 @@
package org.eclipse.cdt.ui; package org.eclipse.cdt.ui;
import org.eclipse.cdt.internal.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorInput;
/** /**

View file

@ -28,13 +28,13 @@ import org.eclipse.cdt.core.model.IOpenable;
import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.core.model.IStructure; import org.eclipse.cdt.core.model.IStructure;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.search.BasicSearchMatch; import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.BasicSearchResultCollector; import org.eclipse.cdt.core.search.BasicSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchConstants; import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchPattern; import org.eclipse.cdt.core.search.ICSearchPattern;
import org.eclipse.cdt.core.search.ICSearchScope; import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.cdt.internal.ui.dialogs.StatusUtil; import org.eclipse.cdt.internal.ui.dialogs.StatusUtil;
import org.eclipse.cdt.internal.ui.wizards.NewWizardMessages; import org.eclipse.cdt.internal.ui.wizards.NewWizardMessages;