diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index b68a0ebdeb8..0e86ce1701c 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,7 @@ +2003-08-12 + Added CompletionProposalsTest to the suit to test the generation + of completion proposals. + 2003-08-12 Bogdan Gheorghe - Changed testVariableIndexPrefix, testVariableDeclaration to reflect changes to the var search pattern diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/CModelElementsFailedTests.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/CModelElementsFailedTests.java index eb8639ac0e5..0370a17697f 100644 --- a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/CModelElementsFailedTests.java +++ b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/CModelElementsFailedTests.java @@ -97,7 +97,7 @@ public class CModelElementsFailedTests extends TestCase { public void testBug36379() { TranslationUnit tu = new TranslationUnit(fCProject, headerFile); // parse the translation unit to get the elements tree - Map newElement = tu.parse(true); // require line numbers + Map newElement = tu.parse(); // require line numbers // tu ---> namespace: MyPackage ArrayList tuPackages = tu.getChildrenOfType(ICElement.C_NAMESPACE); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/codeassist/tests/CompletionProposalsTest.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/codeassist/tests/CompletionProposalsTest.java new file mode 100644 index 00000000000..df5775ce391 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/codeassist/tests/CompletionProposalsTest.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * 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.TranslationUnit; +import org.eclipse.cdt.internal.core.search.indexing.IndexManager; +import org.eclipse.cdt.internal.ui.text.CCompletionProcessor; +import org.eclipse.cdt.testplugin.CProjectHelper; +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 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"); + headerFile = fCProject.getProject().getFile("CompletionProposalsTest.h"); + if (!headerFile.exists()) { + try{ + FileInputStream fileIn = new FileInputStream(pluginRoot+ "resources/cfiles/CompletionProposalsTestStart.h"); + headerFile.create(fileIn,false, monitor); + } catch (CoreException e) { + e.printStackTrace(); + } + } + if (!fCProject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) { + addNatureToProject(fCProject.getProject(), CCProjectNature.CC_NATURE_ID, null); + } + + CCorePlugin.getDefault().setUseNewParser(true); + // use the new indexer + + IndexManager indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager(); + indexManager.setEnabled(fCProject.getProject(),true); + + } + + 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() throws Exception { + CProjectHelper.delete(fCProject); + } + + public void testCompletionProposals(){ + try{ + TranslationUnit tu = new TranslationUnit(fCProject, headerFile); + Document document = new Document(tu.getBuffer().getContents()); + int pos = 399; + int length = 0; + CCompletionProcessor completionProcessor = new CCompletionProcessor(null); + ICompletionProposal[] results = completionProcessor.evalProposals(document, pos, length, tu); + try { + Thread.sleep(MAGIC_NUMBER); + } catch (InterruptedException e1) { + fail( "Bogdan's hack did not suffice"); + } + assertEquals(results.length, 9); + for (int i = 0; i include checkInclude(tu); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IntegratedCModelTest.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IntegratedCModelTest.java index d9ae14b3ce5..54c19d18068 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IntegratedCModelTest.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IntegratedCModelTest.java @@ -98,7 +98,7 @@ public abstract class IntegratedCModelTest extends TestCase { protected ITranslationUnit getTU() { TranslationUnit tu = new TranslationUnit(fCProject, sourceFile); // parse the translation unit to get the elements tree - Map newElement = tu.parse(false); // FALSE=require line numbers + Map newElement = tu.parse(); return tu; } } diff --git a/core/org.eclipse.cdt.core.tests/resources/cfiles/CompletionProposalsTestStart.h b/core/org.eclipse.cdt.core.tests/resources/cfiles/CompletionProposalsTestStart.h new file mode 100644 index 00000000000..5ffddeb8870 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/resources/cfiles/CompletionProposalsTestStart.h @@ -0,0 +1,32 @@ +#define aMacro(x) x+1 + +int aVariable = 0; +void aFunction(char P1, int P2){ + int f1 = 0; +} + +enum anEnumeration { + first, + second, + third +}; + +struct aStruct{ + int aStructField = 0; +}; + +class aClass { +public: + int aField; + int aMethod(int P1, char P2){ + return P1 + P2; + } +}; + +class anotherClass { +public: + int anotherField = 0; + void anotherMethod(int P1, char P2){ + a + } +}; \ No newline at end of file diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java index 802c946e30b..0c8a8f0f779 100644 --- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java +++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java @@ -20,7 +20,7 @@ import org.eclipse.cdt.core.search.ICSearchConstants; import org.eclipse.cdt.core.search.ICSearchPattern; import org.eclipse.cdt.core.search.IMatch; import org.eclipse.cdt.core.search.SearchEngine; -import org.eclipse.cdt.internal.core.search.CharOperation; +import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.search.matching.ClassDeclarationPattern; import org.eclipse.cdt.internal.core.search.matching.MatchLocator; import org.eclipse.cdt.internal.core.search.matching.OrPattern; diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java index 402abfa722f..e3b6c225377 100644 --- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java +++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java @@ -17,7 +17,7 @@ import java.util.Set; import org.eclipse.cdt.core.search.ICSearchPattern; import org.eclipse.cdt.core.search.SearchEngine; -import org.eclipse.cdt.internal.core.search.CharOperation; +import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.search.matching.MethodDeclarationPattern; /** diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java index 6471030a043..58cac22532a 100644 --- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java +++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java @@ -18,7 +18,7 @@ import java.util.Set; import org.eclipse.cdt.core.search.ICSearchPattern; import org.eclipse.cdt.core.search.IMatch; import org.eclipse.cdt.core.search.SearchEngine; -import org.eclipse.cdt.internal.core.search.CharOperation; +import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.search.matching.FieldDeclarationPattern; import org.eclipse.cdt.internal.core.search.matching.NamespaceDeclarationPattern; import org.eclipse.cdt.internal.core.search.matching.OrPattern; diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java index 02f7b34d1cf..814201c633c 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java @@ -19,6 +19,7 @@ import junit.textui.TestRunner; import org.eclipse.cdt.core.build.managed.tests.AllBuildTests; import org.eclipse.cdt.core.build.managed.tests.StandardBuildTests; +import org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest; import org.eclipse.cdt.core.indexer.tests.IndexManagerTests; import org.eclipse.cdt.core.model.failedTests.CModelElementsFailedTests; import org.eclipse.cdt.core.model.tests.AllCoreTests; @@ -91,6 +92,7 @@ public class AutomatedIntegrationSuite extends TestSuite suite.addTestSuite(OtherPatternTests.class ); suite.addTest(IndexManagerTests.suite()); suite.addTestSuite( ParseTestOnSearchFiles.class); + suite.addTestSuite( CompletionProposalsTest.class); // Last test to trigger report generation suite.addTest(suite.new GenerateReport("startFailedTests")); diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index 164cac21237..39418bddff1 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -1,3 +1,8 @@ +2003-08-12 Hoda Amer + Moved CharOperations and Utils from internal.core.search to internal.core + Added CConventions class to validate class names + Used the new search (indexer) for Code completion in CCompletionProcessor + 2003-08-11 Andrew Niefer Added getSharedWorkingCopies to CCorePlugin. diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/AddFileToDependencyTree.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/AddFileToDependencyTree.java index 62ed9301ab4..77a52408047 100644 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/AddFileToDependencyTree.java +++ b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/AddFileToDependencyTree.java @@ -84,7 +84,7 @@ public class AddFileToDependencyTree extends DependencyRequest { try { IPath location = resource.getLocation(); if (location != null) - this.contents = org.eclipse.cdt.internal.core.search.Util.getFileCharContent(location.toFile(), null); + this.contents = org.eclipse.cdt.internal.core.Util.getFileCharContent(location.toFile(), null); } catch (IOException e) { } } diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyManager.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyManager.java index 50cded45c14..a13090af3cc 100644 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyManager.java +++ b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyManager.java @@ -21,7 +21,7 @@ import java.util.zip.CRC32; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.internal.core.search.CharOperation; +import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.search.SimpleLookupTable; import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor; import org.eclipse.cdt.internal.core.search.processing.JobManager; @@ -207,7 +207,7 @@ public class DependencyManager extends JobManager implements ISourceDependency { private char[] readDTreeState() { try { - return org.eclipse.cdt.internal.core.search.Util.getFileCharContent(savedDTreesFile, null); + return org.eclipse.cdt.internal.core.Util.getFileCharContent(savedDTreesFile, null); } catch (IOException ignored) { if (VERBOSE) JobManager.verbose("Failed to read saved dTree file names"); //$NON-NLS-1$ @@ -216,7 +216,7 @@ public class DependencyManager extends JobManager implements ISourceDependency { } private void rebuildDTree(String treeName, IPath path) { - Object target = org.eclipse.cdt.internal.core.search.Util.getTarget(ResourcesPlugin.getWorkspace().getRoot(), path, true); + Object target = org.eclipse.cdt.internal.core.Util.getTarget(ResourcesPlugin.getWorkspace().getRoot(), path, true); if (target == null) return; if (VERBOSE) diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/EntireProjectDependencyTree.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/EntireProjectDependencyTree.java index 06ae94709fd..751d98f518f 100644 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/EntireProjectDependencyTree.java +++ b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/EntireProjectDependencyTree.java @@ -14,10 +14,10 @@ package org.eclipse.cdt.internal.core.sourcedependency; import java.util.HashSet; import org.eclipse.cdt.core.build.managed.ManagedBuildManager; +import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.index.IQueryResult; import org.eclipse.cdt.internal.core.index.impl.IFileDocument; import org.eclipse.cdt.internal.core.search.SimpleLookupTable; -import org.eclipse.cdt.internal.core.search.Util; import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor; import org.eclipse.cdt.internal.core.search.processing.JobManager; import org.eclipse.core.resources.IFile; diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/IncludeEntry.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/IncludeEntry.java index 9fdf6ed08a3..0a0ca38ee87 100644 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/IncludeEntry.java +++ b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/IncludeEntry.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.internal.core.sourcedependency.impl; import java.util.ArrayList; import java.util.Iterator; -import org.eclipse.cdt.internal.core.search.CharOperation; +import org.eclipse.cdt.internal.core.CharOperation; /** * @author bgheorgh diff --git a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/IncludeEntryHashedArray.java b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/IncludeEntryHashedArray.java index a7524f531b7..584e1726363 100644 --- a/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/IncludeEntryHashedArray.java +++ b/core/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/impl/IncludeEntryHashedArray.java @@ -11,7 +11,7 @@ package org.eclipse.cdt.internal.core.sourcedependency.impl; -import org.eclipse.cdt.internal.core.search.CharOperation; +import org.eclipse.cdt.internal.core.CharOperation; public final class IncludeEntryHashedArray { diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/CharOperation.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/CharOperation.java similarity index 99% rename from core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/CharOperation.java rename to core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/CharOperation.java index 46dbea2cf51..a2399affc21 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/CharOperation.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/CharOperation.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.cdt.internal.core.search; +package org.eclipse.cdt.internal.core; /** * This class is a collection of helper methods to manipulate char arrays. diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/Util.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/Util.java similarity index 99% rename from core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/Util.java rename to core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/Util.java index 2dde51b261b..108bfa9b16f 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/Util.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/Util.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.cdt.internal.core.search; +package org.eclipse.cdt.internal.core; import java.io.BufferedInputStream; import java.io.File; @@ -21,6 +21,7 @@ import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; +import org.eclipse.cdt.internal.core.*; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; @@ -33,7 +34,7 @@ public class Util { /* Bundle containing messages */ protected static ResourceBundle bundle; - private final static String bundleName = "org.eclipse.cdt.internal.core.search.messages"; //$NON-NLS-1$ + private final static String bundleName = "org.eclipse.cdt.internal.core.messages"; //$NON-NLS-1$ static { relocalize(); } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java index d0c15fa457b..622253fc82b 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java @@ -15,11 +15,11 @@ import java.io.IOException; import java.io.RandomAccessFile; import java.util.ArrayList; -import org.eclipse.cdt.internal.core.search.CharOperation; +import org.eclipse.cdt.internal.core.CharOperation; +import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.index.IDocument; import org.eclipse.cdt.internal.core.index.IEntryResult; import org.eclipse.cdt.internal.core.index.IQueryResult; -import org.eclipse.cdt.internal.core.search.Util; import org.eclipse.cdt.internal.core.util.LRUCache; /** diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/EntryResult.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/EntryResult.java index a5be977eead..32867e1cec8 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/EntryResult.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/EntryResult.java @@ -10,8 +10,8 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.index.impl; +import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.index.IEntryResult; -import org.eclipse.cdt.internal.core.search.CharOperation; public class EntryResult implements IEntryResult { diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IFileDocument.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IFileDocument.java index 984f97b792d..9ac1afee68f 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IFileDocument.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IFileDocument.java @@ -14,7 +14,7 @@ import java.io.IOException; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IPath; -import org.eclipse.cdt.internal.core.search.CharOperation; +import org.eclipse.cdt.internal.core.CharOperation; /** @@ -54,7 +54,7 @@ public class IFileDocument extends PropertyDocument { if (byteContents != null) return byteContents; IPath location = file.getLocation(); if (location == null) return new byte[0]; - return byteContents = org.eclipse.cdt.internal.core.search.Util.getFileByteContent(location.toFile()); + return byteContents = org.eclipse.cdt.internal.core.Util.getFileByteContent(location.toFile()); } /** * @see org.eclipse.jdt.internal.core.index.IDocument#getCharContent() @@ -63,7 +63,7 @@ public class IFileDocument extends PropertyDocument { if (charContents != null) return charContents; IPath location = file.getLocation(); if (location == null) return CharOperation.NO_CHAR; - return charContents = org.eclipse.cdt.internal.core.search.Util.getFileCharContent( + return charContents = org.eclipse.cdt.internal.core.Util.getFileCharContent( location.toFile(), getEncoding()); } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexBlock.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexBlock.java index f5b60794b5b..e395747ab8f 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexBlock.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexBlock.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.index.impl; -import org.eclipse.cdt.internal.core.search.CharOperation; +import org.eclipse.cdt.internal.core.CharOperation; /** * An indexBlock stores wordEntries. diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexSummary.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexSummary.java index 2c50a2fb502..a0386b626eb 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexSummary.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/IndexSummary.java @@ -14,7 +14,7 @@ import java.io.IOException; import java.io.RandomAccessFile; import java.util.ArrayList; -import org.eclipse.cdt.internal.core.search.CharOperation; +import org.eclipse.cdt.internal.core.CharOperation; /** * An indexSummary is used when saving an index into a BlocksIndexOuput or diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/WordEntry.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/WordEntry.java index 48cc6129f6a..20727388e74 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/WordEntry.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/WordEntry.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.index.impl; -import org.eclipse.cdt.internal.core.search.CharOperation; +import org.eclipse.cdt.internal.core.CharOperation; public class WordEntry { protected char[] fWord; diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/WordEntryHashedArray.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/WordEntryHashedArray.java index a5ece06589e..3e57fa9dda4 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/WordEntryHashedArray.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/impl/WordEntryHashedArray.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.index.impl; -import org.eclipse.cdt.internal.core.search.CharOperation; +import org.eclipse.cdt.internal.core.CharOperation; public final class WordEntryHashedArray { diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/messages.properties b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/messages.properties similarity index 51% rename from core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/messages.properties rename to core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/messages.properties index 4338a0aa07d..7d7bc92324f 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/messages.properties +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/messages.properties @@ -13,4 +13,17 @@ engine.searching = Searching... exception.wrongFormat = Wrong format process.name = CDT Indexer -manager.filesToIndex = {0} files to index \ No newline at end of file +manager.filesToIndex = {0} files to index + +convention.illegalIdentifier= Illegal Identifier +convention.scope.lowercaseName= Scope starts with lower case +convention.scope.nullName= Scope name is null +convention.scope.emptyName= Scope name is empty +convention.scope.dotName= Scope name starts or ends with a . +convention.scope.nameWithBlanks= Scop name has blanks + +convention.class.nullName= Class name is null +convention.class.nameWithBlanks= Class name has blanks +convention.class.dollarName= Class name has $ +convention.class.lowercaseName= Class name starts with lower case +convention.class.invalidName= Class name is invalid diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java index d2b278fa613..182580bd35b 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java @@ -26,10 +26,10 @@ import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.core.search.ICSearchConstants; +import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.index.IDocument; import org.eclipse.cdt.internal.core.index.IIndexer; import org.eclipse.cdt.internal.core.index.IIndexerOutput; -import org.eclipse.cdt.internal.core.search.CharOperation; public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSearchConstants { diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AddCompilationUnitToIndex.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AddCompilationUnitToIndex.java index 6b0674a48c7..ecff290b200 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AddCompilationUnitToIndex.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AddCompilationUnitToIndex.java @@ -34,7 +34,7 @@ public class AddCompilationUnitToIndex extends AddFileToIndex { try { IPath location = resource.getLocation(); if (location != null) - this.contents = org.eclipse.cdt.internal.core.search.Util.getFileCharContent(location.toFile(), null); + this.contents = org.eclipse.cdt.internal.core.Util.getFileCharContent(location.toFile(), null); } catch (IOException e) { } } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AddFolderToIndex.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AddFolderToIndex.java index 030510a0162..20e7ad15281 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AddFolderToIndex.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AddFolderToIndex.java @@ -11,8 +11,8 @@ package org.eclipse.cdt.internal.core.search.indexing; +import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.index.IIndex; -import org.eclipse.cdt.internal.core.search.Util; import org.eclipse.cdt.internal.core.search.processing.JobManager; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexAllProject.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexAllProject.java index 6d482f628ca..bc4d89a97ed 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexAllProject.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexAllProject.java @@ -24,7 +24,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.internal.core.search.Util; +import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.index.IIndex; import org.eclipse.cdt.internal.core.index.IQueryResult; import org.eclipse.cdt.internal.core.index.impl.IFileDocument; diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java index 02dbf50883b..65ac979ed0c 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java @@ -21,6 +21,16 @@ import java.util.Iterator; import java.util.Map; import java.util.zip.CRC32; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.internal.core.CharOperation; +import org.eclipse.cdt.internal.core.index.IIndex; +import org.eclipse.cdt.internal.core.index.impl.Index; +import org.eclipse.cdt.internal.core.model.CProject; +import org.eclipse.cdt.internal.core.search.CWorkspaceScope; +import org.eclipse.cdt.internal.core.search.IndexSelector; +import org.eclipse.cdt.internal.core.search.SimpleLookupTable; +import org.eclipse.cdt.internal.core.search.processing.IJob; +import org.eclipse.cdt.internal.core.search.processing.JobManager; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspace; @@ -28,16 +38,7 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.cdt.internal.core.search.processing.JobManager; -import org.eclipse.cdt.internal.core.search.processing.IJob; -import org.eclipse.cdt.internal.core.search.CWorkspaceScope; -import org.eclipse.cdt.internal.core.search.IndexSelector; -import org.eclipse.cdt.internal.core.search.SimpleLookupTable; -import org.eclipse.cdt.internal.core.search.CharOperation; -import org.eclipse.cdt.internal.core.index.IIndex; -import org.eclipse.cdt.internal.core.index.impl.Index; -import org.eclipse.cdt.internal.core.model.CProject; -import org.eclipse.cdt.core.CCorePlugin; + public class IndexManager extends JobManager implements IIndexConstants { /* number of file contents in memory */ @@ -303,11 +304,11 @@ public class IndexManager extends JobManager implements IIndexConstants { * Name of the background process */ public String processName(){ - return org.eclipse.cdt.internal.core.search.Util.bind("process.name"); //$NON-NLS-1$ + return org.eclipse.cdt.internal.core.Util.bind("process.name"); //$NON-NLS-1$ } private void rebuildIndex(String indexName, IPath path) { - Object target = org.eclipse.cdt.internal.core.search.Util.getTarget(ResourcesPlugin.getWorkspace().getRoot(), path, true); + Object target = org.eclipse.cdt.internal.core.Util.getTarget(ResourcesPlugin.getWorkspace().getRoot(), path, true); if (target == null) return; if (VERBOSE) @@ -546,7 +547,7 @@ public class IndexManager extends JobManager implements IIndexConstants { private char[] readIndexState() { try { - return org.eclipse.cdt.internal.core.search.Util.getFileCharContent(savedIndexNamesFile, null); + return org.eclipse.cdt.internal.core.Util.getFileCharContent(savedIndexNamesFile, null); } catch (IOException ignored) { if (VERBOSE) JobManager.verbose("Failed to read saved index file names"); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/RemoveFolderFromIndex.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/RemoveFolderFromIndex.java index 5419bae10ef..74f269f0032 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/RemoveFolderFromIndex.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/RemoveFolderFromIndex.java @@ -13,9 +13,9 @@ package org.eclipse.cdt.internal.core.search.indexing; import java.io.IOException; +import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.index.IIndex; import org.eclipse.cdt.internal.core.index.IQueryResult; -import org.eclipse.cdt.internal.core.search.Util; import org.eclipse.cdt.internal.core.search.processing.JobManager; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IPath; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICElement.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICElement.java index 1eda0c75f90..e4282aa43e7 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICElement.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICElement.java @@ -200,10 +200,14 @@ public interface ICElement extends IAdaptable { static final int CPP_PUBLIC = 0x2000; + /** + * Modifier indicating a protected class + */ + static final int CPP_PROTECTED = 0x4000; /** * Modifier indicating a friend class */ - static final int CPP_FRIEND = 0x4000; + static final int CPP_FRIEND = 0x8000; /** * Returns whether this C element exists in the model. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java index 3fdb5b60396..16fbe0247c0 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java @@ -4,6 +4,8 @@ package org.eclipse.cdt.core.model; * (c) Copyright IBM Corp. 2000, 2001. * All Rights Reserved. */ +import java.util.Map; + import org.eclipse.cdt.internal.core.model.IBufferFactory; import org.eclipse.cdt.internal.core.model.IWorkingCopy; import org.eclipse.core.runtime.IProgressMonitor; @@ -204,4 +206,9 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource * @return boolean */ boolean isWorkingCopy(); + /** + * parse() + * returns a map of all new elements and their element info + */ + Map parse(); } 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 fa680f92577..22ac7e1ca7d 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 @@ -73,7 +73,9 @@ public class CModelBuilder { { ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE; quickParseCallback = ParserFactory.createQuickParseCallback(); - IParser parser = ParserFactory.createParser( ParserFactory.createScanner( new StringReader( code ), "code", new ScannerInfo(), mode, quickParseCallback), quickParseCallback, mode ); + IParser parser = ParserFactory.createParser( + ParserFactory.createScanner( new StringReader( code ), "code", + new ScannerInfo(), mode, quickParseCallback), quickParseCallback, mode ); parser.setCppNature(hasCppNature); if( ! parser.parse() && throwExceptionOnError ) throw new ParserException("Parse failure"); @@ -459,8 +461,7 @@ public class CModelBuilder { } element.setTypeName ( getType(varDeclaration.getAbstractDeclaration()) ); element.setConst(varDeclaration.getAbstractDeclaration().isConst()); - // TODO : fix volatile for variables - // element.setVolatile(varDeclaration.isVolatile()); + element.setVolatile(varDeclaration.getAbstractDeclaration().isVolatile()); element.setStatic(varDeclaration.isStatic()); // add to parent parent.addChild( element ); @@ -519,6 +520,8 @@ public class CModelBuilder { } } + element.setVolatile(methodDeclaration.isVolatile()); + element.setConst(methodDeclaration.isConst()); } else // instance of IASTFunction { @@ -547,10 +550,7 @@ public class CModelBuilder { } element.setParameterTypes(parameterTypes); element.setReturnType( getType(functionDeclaration.getReturnType()) ); - // TODO: Fix volatile and const - //element.setVolatile(functionDeclaration.isVolatile()); element.setStatic(functionDeclaration.isStatic()); - //element.setConst(functionDeclaration.isConst()); // add to parent parent.addChild( element ); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java index 774c936d6e0..274501145d3 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java @@ -44,7 +44,7 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus /** * Singleton OK object */ - public static final ICModelStatus VERIFIED_OK = new CModelStatus(OK); + public static final ICModelStatus VERIFIED_OK = new CModelStatus(OK, OK, org.eclipse.cdt.internal.core.Util.bind("status.OK"));; /** * Constructs an C model status with no corresponding elements. @@ -59,7 +59,7 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus */ public CModelStatus(int code) { super(ERROR, CCorePlugin.PLUGIN_ID, code, "CModelStatus", null); //$NON-NLS-1$ - //fElements= CElementInfo.fgEmptyChildren; + fElements= CElementInfo.fgEmptyChildren; } /** @@ -76,18 +76,22 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus * Constructs an C model status with no corresponding elements. */ public CModelStatus(int code, String string) { - super(ERROR, CCorePlugin.PLUGIN_ID, code, "CModelStatus", null); //$NON-NLS-1$ - //fElements= CElementInfo.fgEmptyChildren; + this(ERROR, code, string); + } + + public CModelStatus(int severity, int code, String string) { + super(severity, CCorePlugin.PLUGIN_ID, code, "CModelStatus", null); //$NON-NLS-1$ + fElements= CElementInfo.fgEmptyChildren; fPath= null; fString = string; - } + } /** * Constructs an C model status with no corresponding elements. */ public CModelStatus(int code, Throwable throwable) { super(ERROR, CCorePlugin.PLUGIN_ID, code, "CModelStatus", throwable); //$NON-NLS-1$ - //fElements= CElementInfo.fgEmptyChildren; + fElements= CElementInfo.fgEmptyChildren; } /** @@ -95,7 +99,7 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus */ public CModelStatus(int code, IPath path) { super(ERROR, CCorePlugin.PLUGIN_ID, code, "CModelStatus", null); //$NON-NLS-1$ - //fElements= CElementInfo.fgEmptyChildren; + fElements= CElementInfo.fgEmptyChildren; fPath= path; } @@ -116,6 +120,11 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus fString= string; } + public CModelStatus(int code, ICElement element, IPath path) { + this(code, new ICElement[]{element}); + fPath = path; + } + /** * Constructs an C model status with no corresponding elements. */ 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 d40387bf0de..9238c637c6d 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 @@ -321,7 +321,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit { TranslationUnitInfo unitInfo = (TranslationUnitInfo) info; // generate structure - Map mapping = this.parse(false); // false since this is for working copies + Map mapping = this.parse(); // this is temporary until the New Model Builder is implemented if(mapping == null) { @@ -481,7 +481,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit { /** * Parse the buffer contents of this element. */ - public Map parse(boolean requireLineNumbers){ + public Map parse(){ try{ String buf =this.getBuffer().getContents(); if (buf != null) { diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchMatch.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchMatch.java index 4ac49e1d4a8..3030e116fca 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchMatch.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchMatch.java @@ -139,4 +139,74 @@ public class BasicSearchMatch implements IMatch { public boolean isVolatile() { return isVolatile; } + /** + * @return + */ + public int getType() { + return type; + } + + /** + * @param i + */ + public void setEndOffset(int i) { + endOffset = i; + } + + /** + * @param b + */ + public void setConst(boolean b) { + isConst = b; + } + + /** + * @param b + */ + public void setStatic(boolean b) { + isStatic = b; + } + + /** + * @param b + */ + public void setVolatile(boolean b) { + isVolatile = b; + } + + /** + * @param string + */ + public void setName(String string) { + name = string; + } + + /** + * @param string + */ + public void setParentName(String string) { + parentName = string; + } + + /** + * @param i + */ + public void setStartOffset(int i) { + startOffset = i; + } + + /** + * @param i + */ + public void setType(int i) { + type = i; + } + + /** + * @param i + */ + public void setVisibility(int i) { + visibility = i; + } + } diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java index 0b16f85ee2b..62ffb876c1c 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java @@ -28,6 +28,7 @@ import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.parser.ast.IASTEnumerator; import org.eclipse.cdt.core.parser.ast.IASTField; import org.eclipse.cdt.core.parser.ast.IASTFunction; +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.IASTOffsetableElement; @@ -200,6 +201,8 @@ public class BasicSearchResultCollector implements ICSearchResultCollector { match.type = ICElement.C_NAMESPACE; } else if ( node instanceof IASTEnumerationSpecifier ){ match.type = ICElement.C_ENUMERATION; + } else if ( node instanceof IASTMacro ){ + match.type = ICElement.C_MACRO; } else if ( node instanceof IASTField ){ match.type = ICElement.C_FIELD; IASTField field = (IASTField)node; diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java index d5f6e221694..71893d4dd8f 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java @@ -17,13 +17,13 @@ import java.util.HashSet; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.model.CModelManager; import org.eclipse.cdt.internal.core.model.IWorkingCopy; import org.eclipse.cdt.internal.core.search.CSearchScope; import org.eclipse.cdt.internal.core.search.CWorkspaceScope; import org.eclipse.cdt.internal.core.search.PathCollector; import org.eclipse.cdt.internal.core.search.PatternSearchJob; -import org.eclipse.cdt.internal.core.search.Util; import org.eclipse.cdt.internal.core.search.indexing.IndexManager; import org.eclipse.cdt.internal.core.search.matching.CSearchPattern; import org.eclipse.cdt.internal.core.search.matching.MatchLocator; diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java index fee6932ad03..90ccbeedb37 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java @@ -27,12 +27,12 @@ import org.eclipse.cdt.core.parser.ast.ASTClassKind; import org.eclipse.cdt.core.search.ICSearchConstants; import org.eclipse.cdt.core.search.ICSearchPattern; import org.eclipse.cdt.core.search.ICSearchScope; +import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.index.IEntryResult; import org.eclipse.cdt.internal.core.index.IIndex; import org.eclipse.cdt.internal.core.index.impl.BlocksIndexInput; import org.eclipse.cdt.internal.core.index.impl.IndexInput; import org.eclipse.cdt.internal.core.parser.ScannerInfo; -import org.eclipse.cdt.internal.core.search.CharOperation; import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor; import org.eclipse.cdt.internal.core.search.indexing.IIndexConstants; import org.eclipse.core.runtime.IProgressMonitor; diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java index 3a38f03192c..4e5c70108fa 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java @@ -22,10 +22,10 @@ import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement; import org.eclipse.cdt.core.search.ICSearchScope; +import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.index.IEntryResult; import org.eclipse.cdt.internal.core.index.impl.IndexInput; import org.eclipse.cdt.internal.core.index.impl.IndexedFile; -import org.eclipse.cdt.internal.core.search.CharOperation; import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor; import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer; diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java index 265342043ab..121aa97fe3e 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java @@ -21,10 +21,10 @@ import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement; import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.core.search.ICSearchScope; +import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.index.IEntryResult; import org.eclipse.cdt.internal.core.index.impl.IndexInput; import org.eclipse.cdt.internal.core.index.impl.IndexedFile; -import org.eclipse.cdt.internal.core.search.CharOperation; import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor; import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer; diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MacroDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MacroDeclarationPattern.java index 5da2e7834b7..893b5c630ae 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MacroDeclarationPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MacroDeclarationPattern.java @@ -19,10 +19,10 @@ import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; import org.eclipse.cdt.core.parser.ast.IASTMacro; import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; import org.eclipse.cdt.core.search.ICSearchScope; +import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.index.IEntryResult; import org.eclipse.cdt.internal.core.index.impl.IndexInput; import org.eclipse.cdt.internal.core.index.impl.IndexedFile; -import org.eclipse.cdt.internal.core.search.CharOperation; import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor; import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer; diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java index b1ee2391230..a1dfe4ac94d 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java @@ -25,10 +25,10 @@ import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement; import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; import org.eclipse.cdt.core.search.ICSearchScope; +import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.index.IEntryResult; import org.eclipse.cdt.internal.core.index.impl.IndexInput; import org.eclipse.cdt.internal.core.index.impl.IndexedFile; -import org.eclipse.cdt.internal.core.search.CharOperation; import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor; import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer; diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/NamespaceDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/NamespaceDeclarationPattern.java index 9eb162d9b4f..952ff562d6c 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/NamespaceDeclarationPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/NamespaceDeclarationPattern.java @@ -18,10 +18,10 @@ import java.io.IOException; import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; import org.eclipse.cdt.core.search.ICSearchScope; +import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.index.IEntryResult; import org.eclipse.cdt.internal.core.index.impl.IndexInput; import org.eclipse.cdt.internal.core.index.impl.IndexedFile; -import org.eclipse.cdt.internal.core.search.CharOperation; import org.eclipse.cdt.internal.core.search.IIndexSearchRequestor; import org.eclipse.cdt.internal.core.search.indexing.AbstractIndexer; diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/processing/JobManager.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/processing/JobManager.java index bd6c0220f1e..97dd2018c4a 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/processing/JobManager.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/processing/JobManager.java @@ -13,7 +13,7 @@ */ package org.eclipse.cdt.internal.core.search.processing; -import org.eclipse.cdt.internal.core.search.Util; +import org.eclipse.cdt.internal.core.Util; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.SubProgressMonitor; diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CConventions.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CConventions.java new file mode 100644 index 00000000000..2a849770541 --- /dev/null +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CConventions.java @@ -0,0 +1,137 @@ +/******************************************************************************* + * 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; + +import java.util.StringTokenizer; + +import org.eclipse.cdt.internal.core.CharOperation; +import org.eclipse.cdt.internal.core.Util; +import org.eclipse.cdt.internal.core.model.CModelStatus; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +/** + * @author hamer + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ + +public class CConventions { + private final static String scopeResolutionOperator= "::"; + private final static char fgDot= '.'; + private final static char fgColon= ':'; + + /** + * Validate the given CPP class name, either simple or qualified. + * For example, "A::B::C", or "C". + *

+ * + * @param name the name of a class + * @return a status object with code IStatus.OK if + * the given name is valid as a CPP class name, + * a status with code IStatus.WARNING + * indicating why the given name is discouraged, + * otherwise a status object indicating what is wrong with + * the name + */ + public static IStatus validateClassName(String name) { + if (name == null) { + return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.class.nullName"), null); //$NON-NLS-1$ + } + String trimmed = name.trim(); + if ((!name.equals(trimmed)) || (name.indexOf(" ") != -1) ){ + return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.class.nameWithBlanks"), null); //$NON-NLS-1$ + } + int index = name.lastIndexOf(scopeResolutionOperator); + char[] scannedID; + if (index == -1) { + // simple name + scannedID = name.toCharArray(); + } else { + // qualified name + String pkg = name.substring(0, index).trim(); + IStatus status = validateScopeName(pkg); + if (!status.isOK()) { + return status; + } + String type = name.substring(index + 1).trim(); + scannedID = type.toCharArray(); + } + + if (scannedID != null) { + IStatus status = ResourcesPlugin.getWorkspace().validateName(new String(scannedID), IResource.FILE); + if (!status.isOK()) { + return status; + } + if (CharOperation.contains('$', scannedID)) { + return new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.class.dollarName"), null); //$NON-NLS-1$ + } + if ((scannedID.length > 0 && Character.isLowerCase(scannedID[0]))) { + return new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.class.lowercaseName"), null); //$NON-NLS-1$ + } + return CModelStatus.VERIFIED_OK; + } else { + return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.class.invalidName", name), null); //$NON-NLS-1$ + } + } + /** + * Validate the given scope name. + *

+ * @return a status object with code IStatus.OK if + * the given name is valid as a class name, otherwise a status + * object indicating what is wrong with the name + */ + public static IStatus validateScopeName(String name) { + + if (name == null) { + return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.scope.nullName"), null); //$NON-NLS-1$ + } + int length; + if ((length = name.length()) == 0) { + return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.scope.emptyName"), null); //$NON-NLS-1$ + } + if (name.charAt(0) == fgDot || name.charAt(length-1) == fgDot) { + return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.scope.dotName"), null); //$NON-NLS-1$ + } + if (CharOperation.isWhitespace(name.charAt(0)) || CharOperation.isWhitespace(name.charAt(name.length() - 1))) { + return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.scope.nameWithBlanks"), null); //$NON-NLS-1$ + } +// int dot = 0; +// while (dot != -1 && dot < length-1) { +// if ((dot = name.indexOf(fgDot, dot+1)) != -1 && dot < length-1 && name.charAt(dot+1) == fgDot) { +// return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.package.consecutiveDotsName"), null); //$NON-NLS-1$ +// } +// } + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + StringTokenizer st = new StringTokenizer(name, scopeResolutionOperator); + boolean firstToken = true; + while (st.hasMoreTokens()) { + String typeName = st.nextToken(); + typeName = typeName.trim(); // grammar allows spaces + char[] scannedID = typeName.toCharArray(); + if (scannedID == null) { + return new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.illegalIdentifier", typeName), null); //$NON-NLS-1$ + } + IStatus status = workspace.validateName(new String(scannedID), IResource.FOLDER); + if (!status.isOK()) { + return status; + } + if (firstToken && scannedID.length > 0 && Character.isLowerCase(scannedID[0])) { + return new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, -1, Util.bind("convention.scope.lowercaseName"), null); //$NON-NLS-1$ + } + firstToken = false; + } + return CModelStatus.VERIFIED_OK; + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index bd36c492a49..9959afe6f44 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,7 @@ +2003-08-12 + Added class name validation to NewClassWizardPage + Used the new search (indexer) for Code completion in CCompletionProcessor + 2003-08-11 Andrew Niefer - Added some code to CUIPlugin to access working copies diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java index 90b25a0c416..a40ce0e8d88 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java @@ -7,24 +7,42 @@ package org.eclipse.cdt.internal.ui.text; import java.util.ArrayList; import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; -import org.eclipse.cdt.core.index.ITagEntry; -import org.eclipse.cdt.core.index.IndexModel; import org.eclipse.cdt.core.index.TagFlags; import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.IField; +import org.eclipse.cdt.core.model.IFunction; +import org.eclipse.cdt.core.model.IFunctionDeclaration; +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.search.BasicSearchMatch; +import org.eclipse.cdt.core.search.BasicSearchResultCollector; +import org.eclipse.cdt.core.search.ICSearchConstants; +import org.eclipse.cdt.core.search.ICSearchScope; +import org.eclipse.cdt.core.search.SearchEngine; +import org.eclipse.cdt.internal.core.model.CElement; +import org.eclipse.cdt.internal.core.search.matching.OrPattern; import org.eclipse.cdt.internal.corext.template.ContextType; import org.eclipse.cdt.internal.corext.template.ContextTypeRegistry; import org.eclipse.cdt.internal.ui.CCompletionContributorManager; import org.eclipse.cdt.internal.ui.CPluginImages; import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.text.template.TemplateEngine; -import org.eclipse.cdt.ui.CElementLabelProvider; +import org.eclipse.cdt.ui.CSearchResultLabelProvider; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.FunctionPrototypeSummary; import org.eclipse.cdt.ui.IFunctionSummary; +import org.eclipse.cdt.ui.IWorkingCopyManager; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; @@ -36,9 +54,7 @@ import org.eclipse.jface.text.contentassist.IContextInformation; import org.eclipse.jface.text.contentassist.IContextInformationValidator; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; -import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IFileEditorInput; /** * C completion processor. @@ -55,11 +71,17 @@ public class CCompletionProcessor implements IContentAssistProcessor { private boolean fRestrictToMatchingCase; private boolean fAllowAddIncludes; - private CElementLabelProvider fElementLabelProvider; - //private ImageRegistry fImageRegistry; - + BasicSearchResultCollector resultCollector = null; + SearchEngine searchEngine = null; + CSearchResultLabelProvider labelProvider = null; + public CCompletionProcessor(IEditorPart editor) { fEditor = (CEditor) editor; + + // Needed for search + labelProvider = new CSearchResultLabelProvider(); + resultCollector = new BasicSearchResultCollector (); + searchEngine = new SearchEngine(); //Determine if this is a C or a C++ file for the context completion + //This is _totally_ ugly and likely belongs in the main editor class. String contextNames[] = new String[2]; @@ -102,9 +124,6 @@ public class CCompletionProcessor implements IContentAssistProcessor { fAllowAddIncludes = true; fComparator = new CCompletionProposalComparator(); - - fElementLabelProvider = new CElementLabelProvider(); - //fImageRegistry= CUIPlugin.getDefault().getImageRegistry(); } /** @@ -188,7 +207,9 @@ public class CCompletionProcessor implements IContentAssistProcessor { * @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int) */ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) { - //IDocument unit= fManager.getWorkingCopy(fEditor.getEditorInput()); + IWorkingCopyManager fManager = CUIPlugin.getDefault().getWorkingCopyManager(); + ITranslationUnit unit = fManager.getWorkingCopy(fEditor.getEditorInput()); + IDocument document = viewer.getDocument(); ICCompletionProposal[] results = null; @@ -205,9 +226,7 @@ public class CCompletionProcessor implements IContentAssistProcessor { length = selection.y; } - //CCompletionEvaluator evaluator= new CCompletionEvaluator(document, offset, length); - //evaluator.restrictProposalsToMatchingCases(fRestrictToMatchingCase); - results = evalProposals(document, offset, length); + results = evalProposals(document, offset, length, unit); } } catch (Exception e) { CUIPlugin.getDefault().log(e); @@ -248,22 +267,67 @@ public class CCompletionProcessor implements IContentAssistProcessor { return results; } + private ICElement getCurrentScope(ITranslationUnit unit, int documentOffset){ + // quick parse the unit + Map elements = unit.parse(); + // figure out what element is the enclosing the current offset + ICElement currentScope = unit; + Iterator i = elements.keySet().iterator(); + while (i.hasNext()){ + CElement element = (CElement) i.next(); + + if ((element.getStartPos() < documentOffset ) + && ( element.getStartPos() + element.getLength() > documentOffset) + ) + { + if(currentScope instanceof ITranslationUnit){ + currentScope = element; + }else + if (currentScope instanceof CElement){ + CElement currentScopeElement = (CElement) currentScope; + if( + (currentScopeElement.getStartPos() < element.getStartPos()) + && ( + (currentScopeElement.getStartPos() + currentScopeElement.getLength() ) + > (element.getStartPos() + element.getLength()) ) + ) + currentScope = element; + } + } + } + return currentScope; + } + /** * Order the given proposals. */ private ICCompletionProposal[] order(ICCompletionProposal[] proposals) { - Arrays.sort(proposals, fComparator); + if(proposals != null) + Arrays.sort(proposals, fComparator); return proposals; } /** * Evaluate the actual proposals for C */ - private ICCompletionProposal[] evalProposals(IDocument document, int pos, int length) { + public ICCompletionProposal[] evalProposals(IDocument document, int pos, int length, ITranslationUnit unit) { + return order (evalProposals(document, pos, length, getCurrentScope (unit, pos))); + } + + private ICCompletionProposal[] evalProposals(IDocument document, int pos, int length, ICElement currentScope) { boolean isDereference = false; IRegion region; String frag = ""; - + + // TODO: Do all possible scopes + // possible scopes include IStructure, INamespace, and ITranslationUnit + if( ( !(currentScope instanceof IMethod)) + && ( !(currentScope instanceof IMethodDeclaration)) + && ( !(currentScope instanceof IFunction)) + && ( !(currentScope instanceof IFunctionDeclaration)) + ){ + return null; + } // Move back the pos by one the position is 0-based if (pos > 0) { pos--; @@ -342,7 +406,7 @@ public class CCompletionProcessor implements IContentAssistProcessor { ArrayList completions = new ArrayList(); // Look in index manager - addProposalsFromModel(region, frag, completions); + addProposalsFromModel(region, frag,currentScope, completions); // Loot in the contributed completions addProposalsFromCompletionContributors(region, frag, completions); @@ -384,7 +448,8 @@ public class CCompletionProcessor implements IContentAssistProcessor { } } - private void addProposalsFromModel(IRegion region, String frag, ArrayList completions) { +// It is not needed to follow referenced projects since search does this for us now +/* private void addProposalsFromModel(IRegion region, String frag, ICElement currentScope, ArrayList completions) { IProject project = null; IEditorInput input = fEditor.getEditorInput(); if (input instanceof IFileEditorInput) { @@ -396,22 +461,182 @@ public class CCompletionProcessor implements IContentAssistProcessor { } } if (project != null) { - addProjectCompletions(project, region, frag, completions); + addProjectCompletions(project, region, frag, currentScope, completions); // Now query referenced projects IProject referenced[]; try { referenced = project.getReferencedProjects(); if (referenced.length > 0) { for (int i = 0; i < referenced.length; i++) { - addProjectCompletions(referenced[i], region, frag, completions); + addProjectCompletions(referenced[i], region, frag, currentScope, completions); } } } catch (CoreException e) { } } } +*/ + private FunctionPrototypeSummary getPrototype (BasicSearchMatch match) { + switch(match.getElementType()){ + case ICElement.C_FUNCTION: + case ICElement.C_FUNCTION_DECLARATION: + case ICElement.C_METHOD: + case ICElement.C_METHOD_DECLARATION: + { + return (new FunctionPrototypeSummary ( match.getName() )); + } + default: + return null; + } + } + + private int calculateRelevance (BasicSearchMatch element){ + + int type = element.getElementType(); + + switch (type){ + case ICElement.C_FIELD: + return 9; + case ICElement.C_VARIABLE: + case ICElement.C_VARIABLE_DECLARATION: + return 8; + case ICElement.C_METHOD: + case ICElement.C_METHOD_DECLARATION: + return 7; + case ICElement.C_FUNCTION: + case ICElement.C_FUNCTION_DECLARATION: + return 6; + case ICElement.C_CLASS: + return 5; + case ICElement.C_STRUCT: + return 4; + case ICElement.C_UNION: + return 3; + case ICElement.C_MACRO: + return 2; + case ICElement.C_ENUMERATION: + return 1; + default : + return 0; + } + } + private void addProposalsFromModel (IRegion region, String frag, ICElement currentScope, ArrayList completions) { + List elementsFound = new LinkedList(); + String prefix = frag + "*"; + + // TODO: change that to resource scope later + ICElement[] projectScopeElement = new ICElement[1]; + projectScopeElement[0] = (ICElement)currentScope.getCProject(); + ICSearchScope scope = SearchEngine.createCSearchScope(projectScopeElement, true); + OrPattern orPattern = new OrPattern(); + // search for global variables, functions, classes, structs, unions, enums and macros + orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.VAR, ICSearchConstants.DECLARATIONS, true )); + orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, true )); + orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.FUNCTION, ICSearchConstants.DEFINITIONS, true )); + orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.TYPE, ICSearchConstants.DECLARATIONS, true )); + orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.ENUM, ICSearchConstants.DECLARATIONS, true )); + orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.MACRO, ICSearchConstants.DECLARATIONS, true )); + searchEngine.search(CUIPlugin.getWorkspace(), orPattern, scope, resultCollector); + elementsFound.addAll(resultCollector.getSearchResults()); - private void addProjectCompletions(IProject project, IRegion region, String frag, ArrayList completions) { + if((currentScope instanceof IMethod) || (currentScope instanceof IMethodDeclaration) ){ + // add the methods and fields of the parent class +/* // use search with CElement Scope + ICElement[] classScopeElements = new ICElement[1]; + classScopeElements[0] = currentScope.getParent(); + ICSearchScope classScope = SearchEngine.createCSearchScope(classScopeElements); + OrPattern classOrPattern = new OrPattern(); + classOrPattern.addPattern(SearchEngine.createSearchPattern(prefix, ICSearchConstants.FIELD, ICSearchConstants.DECLARATIONS, true)); + classOrPattern.addPattern(SearchEngine.createSearchPattern(prefix, ICSearchConstants.METHOD, ICSearchConstants.DECLARATIONS, true)); + classOrPattern.addPattern(SearchEngine.createSearchPattern(prefix, ICSearchConstants.METHOD, ICSearchConstants.DEFINITIONS, true)); + searchEngine.search(CUIPlugin.getWorkspace(), classOrPattern, classScope, resultCollector); + elementsFound.addAll(resultCollector.getSearchResults()); +*/ + // 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()); + } + else { + childMatch.setName(child.getElementName()); + } + + elementsFound.add(childMatch); + } + } + + } + + Iterator i = elementsFound.iterator(); + while (i.hasNext()){ + CCompletionProposal proposal; + FunctionPrototypeSummary fproto = null; + String fname = ""; + String displayString = ""; + Image image = null; + StringBuffer infoString = new StringBuffer(); + + BasicSearchMatch match = (BasicSearchMatch)i.next(); + fproto = getPrototype(match); + fname = (fproto == null) ? match.getName() : fproto.getName(); + displayString = (fproto == null) ? fname : fproto.getPrototypeString(true); + image = labelProvider.getImage(match); + infoString.append(displayString); + if(match.getParentName().length() > 0) { + infoString.append(" - Parent: "); + infoString.append(match.getParentName()); + } + + + + proposal = new CCompletionProposal( + fname, // replacement string + region.getOffset(), + region.getLength(), + image, + displayString, // displayString + calculateRelevance(match) + ); + completions.add(proposal); + + // No summary information available yet + // context information is available for methods only + if(fproto != null){ + String fargs = fproto.getArguments(); + if(fargs != null && fargs.length() > 0) { + proposal.setContextInformation(new ContextInformation(fname, fargs)); + } + } + + // The info string could be populated with documentation info. + // For now, it has the name and the parent's name if available. + proposal.setAdditionalProposalInfo(infoString.toString()); + } + } + +// Search (and the new indexer) is used now instead of the old indexer and CTags +/* private void addProjectCompletions(IProject project, IRegion region, String frag, ArrayList completions) { IndexModel model = IndexModel.getDefault(); ITagEntry[] tags = model.query(project, frag + "*", false, false); @@ -457,7 +682,7 @@ public class CCompletionProcessor implements IContentAssistProcessor { } } } - +*/ private Image getTagImage(int kind) { switch (kind) { case TagFlags.T_PROTOTYPE : diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CSearchResultLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CSearchResultLabelProvider.java index 4ebc2e08937..38ab191e9ff 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CSearchResultLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CSearchResultLabelProvider.java @@ -72,6 +72,7 @@ public class CSearchResultLabelProvider extends LabelProvider { case ICElement.C_UNION: imageDescriptor = CPluginImages.DESC_OBJS_UNION; break; case ICElement.C_NAMESPACE: imageDescriptor = CPluginImages.DESC_OBJS_CONTAINER; break; case ICElement.C_ENUMERATION: imageDescriptor = CPluginImages.DESC_OBJS_ENUMERATION; break; + case ICElement.C_MACRO: imageDescriptor = CPluginImages.DESC_OBJS_MACRO; break; case ICElement.C_FUNCTION: imageDescriptor = CPluginImages.DESC_OBJS_FUNCTION; break; case ICElement.C_VARIABLE: imageDescriptor = CPluginImages.DESC_OBJS_FIELD; break; case ICElement.C_ENUMERATOR: imageDescriptor = CPluginImages.DESC_OBJS_ENUMERATOR; break; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizard.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizard.java index 4865a441c42..9f2624ac65b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizard.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizard.java @@ -68,7 +68,7 @@ public class NewClassWizard extends BasicNewResourceWizard implements INewWizard /** * @see Wizard#performFinish */ - public boolean performFinish() { + public boolean performFinish() { IWorkspaceRunnable op= new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException { try { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java index 34079501f2b..17cafd48f8b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java @@ -15,10 +15,11 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; -import java.util.LinkedList; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; +import org.eclipse.cdt.core.CConventions; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; @@ -347,7 +348,7 @@ public class NewClassWizardPage extends WizardPage implements Listener { if(fBaseClassDialogField.getText().length() > 0) { fAccessButtons.setEnabled(true); - fBaseClassStatus = baseClassChanged(); + fBaseClassStatus = baseClassNameChanged(); } else{ fAccessButtons.setEnabled(false); @@ -405,8 +406,9 @@ public class NewClassWizardPage extends WizardPage implements Listener { private void searchForClasses(ICProject cProject, List elementsFound, IProgressMonitor monitor, int worked){ ICSearchPattern pattern = SearchEngine.createSearchPattern( "*", ICSearchConstants.CLASS, ICSearchConstants.DECLARATIONS, false ); - // TODO: change that to project scope later - ICSearchScope scope = SearchEngine.createWorkspaceScope();; + ICElement[] elements = new ICElement[1]; + elements[0] = cProject; + ICSearchScope scope = SearchEngine.createCSearchScope(elements, true); searchEngine.search(CUIPlugin.getWorkspace(), pattern, scope, resultCollector); elementsFound.addAll(resultCollector.getSearchResults()); @@ -761,13 +763,13 @@ public class NewClassWizardPage extends WizardPage implements Listener { { extendingBase = true; List classElements = findClassElementsInProject(); - BasicSearchMatch baseClass = (BasicSearchMatch)findInList(baseClassName, classElements); + BasicSearchMatch baseClass = (BasicSearchMatch)findInList(baseClassName, null, classElements); - if(baseClass != null){ - baseClassFileName = baseClass.getLocation().toString(); - } else { +// if(baseClass != null){ +// baseClassFileName = baseClass.getLocation().toString(); +// } else { baseClassFileName = baseClassName + HEADER_EXT; - } +// } } if(isIncludeGuard()){ @@ -915,26 +917,30 @@ public class NewClassWizardPage extends WizardPage implements Listener { */ protected IStatus classNameChanged() { StatusInfo status= new StatusInfo(); - String typeName= getNewClassName(); - // class name must not be empty - if (typeName.length() == 0) { + String className= getNewClassName(); + // must not be empty + if (className.length() == 0) { status.setError(NewWizardMessages.getString("NewClassWizardPage.error.EnterClassName")); //$NON-NLS-1$ return status; } - - // class name must not be qualified - if (typeName.indexOf('.') != -1) { + if (className.indexOf("::") != -1) { status.setError(NewWizardMessages.getString("NewClassWizardPage.error.QualifiedName")); //$NON-NLS-1$ return status; } - - // class name must follow the C/CPP convensions + IStatus val= CConventions.validateClassName(className); + if (val.getSeverity() == IStatus.ERROR) { + status.setError(NewWizardMessages.getFormattedString("NewClassWizardPage.error.InvalidClassName", val.getMessage())); //$NON-NLS-1$ + return status; + } else if (val.getSeverity() == IStatus.WARNING) { + status.setWarning(NewWizardMessages.getFormattedString("NewClassWizardPage.warning.ClassNameDiscouraged", val.getMessage())); //$NON-NLS-1$ + // continue checking + } - // class must NOT exist -// ArrayList elementsFound = findClassElementsInProject(); -// if(foundInList(getNewClassName(), elementsFound)){ -// status.setWarning(NewWizardMessages.getString("NewClassWizardPage.error.ClassNameExists")); //$NON-NLS-1$ -// } + // must not exist + List elementsFound = findClassElementsInProject(); + if(foundInList(getNewClassName(), getContainerPath(linkedResourceGroupForHeader), elementsFound)){ + status.setWarning(NewWizardMessages.getString("NewClassWizardPage.error.ClassNameExists")); //$NON-NLS-1$ + } return status; } /** @@ -946,32 +952,48 @@ public class NewClassWizardPage extends WizardPage implements Listener { * * @return the status of the validation */ - protected IStatus baseClassChanged() { + protected IStatus baseClassNameChanged() { + String baseClassName = getBaseClassName(); StatusInfo status= new StatusInfo(); + if (baseClassName.length() == 0) { + // accept the empty field (stands for java.lang.Object) + return status; + } // class name must follow the C/CPP convensions + IStatus val= CConventions.validateClassName(baseClassName); + if (val.getSeverity() == IStatus.ERROR) { + status.setError(NewWizardMessages.getString("NewClassWizardPage.error.InvalidBaseClassName")); //$NON-NLS-1$ + return status; + } // if class does not exist, give warning List elementsFound = findClassElementsInProject(); - if(!foundInList(getBaseClassName(), elementsFound)){ + if(!foundInList(baseClassName, null, elementsFound)){ status.setWarning(NewWizardMessages.getString("NewClassWizardPage.warning.BaseClassNotExists")); //$NON-NLS-1$ } - return status; - + return status; } - - private Object findInList(String name, List elements){ + + private Object findInList(String name, IPath path, List elements){ Iterator i = elements.iterator(); while (i.hasNext()){ BasicSearchMatch element = (BasicSearchMatch)i.next(); - if (name.equals(element.getName())) - return element; + if(path != null){ + // check both the name and the path + if ((name.equals(element.getName())) && (path.makeAbsolute().equals(element.getLocation()))) + return element; + } else { + // we don't care about the path + if (name.equals(element.getName())) + return element; + } } return null; } - private boolean foundInList(String name, List elements){ - if(findInList(name, elements) != null) + private boolean foundInList(String name, IPath path, List elements){ + if(findInList(name, path, elements) != null) return true; else return false;