diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 68ac85f9228..3d5dd1cb31f 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,6 @@ +2004-04-19 Alain Magloire + The CoreModel interfaces throw much more exception, we need to log them for errors. + 2004-04-19 Andrew Niefer added parser/CompleteParseASTTest.testBug59149() diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/BinaryTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/BinaryTests.java index 2d5674f26fa..ac7547c62c6 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/BinaryTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/BinaryTests.java @@ -15,6 +15,7 @@ import junit.framework.TestSuite; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.core.ICDescriptorOperation; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; @@ -216,7 +217,7 @@ public class BinaryTests extends TestCase { /*** * A quick check to make sure the getBSS function works as expected. */ - public void testGetBss(){ + public void testGetBss() throws CModelException{ IBinary bigBinary,littleBinary; bigBinary=CProjectHelper.findBinary(testProject, "exebig_g"); littleBinary=CProjectHelper.findBinary(testProject, "test_g"); @@ -227,7 +228,7 @@ public class BinaryTests extends TestCase { /*** * A quick check to make sure the getBSS function works as expected. */ - public void testGetData(){ + public void testGetData() throws CModelException{ IBinary bigBinary,littleBinary; bigBinary=CProjectHelper.findBinary(testProject, "exebig_g"); littleBinary=CProjectHelper.findBinary(testProject, "test_g"); @@ -241,7 +242,7 @@ public class BinaryTests extends TestCase { * something sane for the most common exe type (x86) and one other (ppc) * This is not a in depth test at all. */ - public void testGetCpu() { + public void testGetCpu() throws CModelException { IBinary myBinary; myBinary=CProjectHelper.findBinary(testProject, "exebig_g"); @@ -254,7 +255,7 @@ public class BinaryTests extends TestCase { /**** * A set of simple tests to make sute getNeededSharedLibs seems to be sane */ - public void testGetNeededSharedLibs() { + public void testGetNeededSharedLibs() throws CModelException { IBinary myBinary; String[] exelibs={"libsocket.so.2", "libc.so.2"}; String[] bigexelibs={"libc.so.2"}; @@ -294,7 +295,7 @@ public class BinaryTests extends TestCase { /**** * Simple tests for the getSoname method; */ - public void testGetSoname() { + public void testGetSoname() throws CModelException { IBinary myBinary; String name; myBinary=CProjectHelper.findBinary(testProject, "test_g"); @@ -311,7 +312,7 @@ public class BinaryTests extends TestCase { /*** * Simple tests for getText */ - public void testGetText() { + public void testGetText() throws CModelException { IBinary bigBinary,littleBinary; bigBinary=CProjectHelper.findBinary(testProject, bigexe.getLocation().lastSegment()); littleBinary=CProjectHelper.findBinary(testProject, exefile.getLocation().lastSegment()); @@ -323,7 +324,7 @@ public class BinaryTests extends TestCase { /*** * Simple tests for the hadDebug call */ - public void testHasDebug() { + public void testHasDebug() throws CModelException { IBinary myBinary; myBinary = CProjectHelper.findBinary(testProject, "test_g"); assertTrue(myBinary.hasDebug()); @@ -336,7 +337,7 @@ public class BinaryTests extends TestCase { /*** * Sanity - isBinary and isReadonly should always return true; */ - public void testisBinRead() { + public void testisBinRead() throws CModelException { IBinary myBinary; myBinary =CProjectHelper.findBinary(testProject, "test_g"); assertTrue(myBinary != null); @@ -347,7 +348,7 @@ public class BinaryTests extends TestCase { /*** * Quick tests to make sure isObject works as expected. */ - public void testIsObject() { + public void testIsObject() throws CModelException { IBinary myBinary; myBinary=CProjectHelper.findObject(testProject, "exetest.o"); assertTrue(myBinary.isObject()); @@ -367,7 +368,7 @@ public class BinaryTests extends TestCase { /*** * Quick tests to make sure isSharedLib works as expected. */ - public void testIsSharedLib() { + public void testIsSharedLib() throws CModelException { IBinary myBinary; myBinary=CProjectHelper.findObject(testProject, "exetest.o"); @@ -388,7 +389,7 @@ public class BinaryTests extends TestCase { /*** * Quick tests to make sure isExecutable works as expected. */ - public void testIsExecutable() throws InterruptedException { + public void testIsExecutable() throws InterruptedException, CModelException { IBinary myBinary; myBinary=CProjectHelper.findObject(testProject, "exetest.o"); assertTrue(!myBinary.isExecutable()); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java index fb337655652..7b7f281fc49 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java @@ -18,6 +18,7 @@ import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.IEnumeration; @@ -85,7 +86,7 @@ public class CModelElementsTests extends TestCase { CProjectHelper.delete(fCProject); } - public void testCModelElements(){ + public void testCModelElements() throws CModelException{ TranslationUnit tu = new TranslationUnit(fCProject, headerFile); // parse the translation unit to get the elements tree tu.parse(); @@ -119,7 +120,7 @@ public class CModelElementsTests extends TestCase { checkArrays(tu); } - private void checkInclude(IParent tu){ + private void checkInclude(IParent tu) throws CModelException{ List tuIncludes = tu.getChildrenOfType(ICElement.C_INCLUDE); IInclude inc1 = (IInclude) tuIncludes.get(0); assertEquals(inc1.getElementName(), new String("stdio.h")); @@ -127,7 +128,7 @@ public class CModelElementsTests extends TestCase { checkLineNumbers((CElement)inc1, 2, 2); } - private void checkMacro(IParent tu){ + private void checkMacro(IParent tu) throws CModelException{ List tuMacros = tu.getChildrenOfType(ICElement.C_MACRO); IMacro mac1 = (IMacro) tuMacros.get(0); assertEquals(mac1.getElementName(), new String("PRINT")); @@ -135,7 +136,7 @@ public class CModelElementsTests extends TestCase { checkLineNumbers((CElement)mac1, 5, 5); } - private void checkClass(IParent namespace){ + private void checkClass(IParent namespace) throws CModelException{ // MyPackage ---> class: Hello List nsClasses = namespace.getChildrenOfType(ICElement.C_CLASS); IStructure classHello = (IStructure) nsClasses.get(0); @@ -172,7 +173,7 @@ public class CModelElementsTests extends TestCase { checkNestedNamespace(classHello); } - private void checkNestedNamespace(IParent classHello){ + private void checkNestedNamespace(IParent classHello) throws CModelException{ // Hello ---> namespace: MyNestedPackage List helloNamespaces = classHello.getChildrenOfType(ICElement.C_NAMESPACE); INamespace myNestedPackage = (INamespace) helloNamespaces.get(0); @@ -183,7 +184,7 @@ public class CModelElementsTests extends TestCase { checkParentNestedClass(myNestedPackage); checkDerivedNestedClass(myNestedPackage); } - private void checkParentNestedClass(IParent myNestedPackage){ + private void checkParentNestedClass(IParent myNestedPackage) throws CModelException{ // MyNestedPackage ---> class: Y List nestedClasses = myNestedPackage.getChildrenOfType(ICElement.C_CLASS); IStructure classY = (IStructure) nestedClasses.get(0); @@ -209,7 +210,7 @@ public class CModelElementsTests extends TestCase { } - private void checkDerivedNestedClass(IParent myNestedPackage){ + private void checkDerivedNestedClass(IParent myNestedPackage) throws CModelException{ // MyNestedPackage ---> class: X public Y List nestedClasses = myNestedPackage.getChildrenOfType(ICElement.C_CLASS); IStructure classX = (IStructure) nestedClasses.get(1); @@ -246,7 +247,7 @@ public class CModelElementsTests extends TestCase { checkLineNumbers((CElement)xDoNothing, 50, 50); } - private void checkEnums(IParent namespace){ + private void checkEnums(IParent namespace) throws CModelException{ // MyPackage ---> enum: Noname List nsEnums = namespace.getChildrenOfType(ICElement.C_ENUMERATION); IEnumeration enum = (IEnumeration) nsEnums.get(0); @@ -291,7 +292,7 @@ public class CModelElementsTests extends TestCase { checkElementOffset((CElement)t); } - private void checkVariables(IParent namespace){ + private void checkVariables(IParent namespace) throws CModelException{ // MyPackage ---> int v List nsVars = namespace.getChildrenOfType(ICElement.C_VARIABLE); IVariable var1 = (IVariable) nsVars.get(0); @@ -322,7 +323,7 @@ public class CModelElementsTests extends TestCase { checkLineNumbers((CElement)vDecl2, 81, 81); } - private void checkVariableDeclarations(IParent namespace){ + private void checkVariableDeclarations(IParent namespace) throws CModelException{ // MyPackage ---> extern int evar List nsVarDecls = namespace.getChildrenOfType(ICElement.C_VARIABLE_DECLARATION); IVariableDeclaration vDecl1 = (IVariableDeclaration) nsVarDecls.get(0); @@ -332,7 +333,7 @@ public class CModelElementsTests extends TestCase { checkLineNumbers((CElement)vDecl1, 79, 79); } - private void checkFunctions(IParent namespace){ + private void checkFunctions(IParent namespace) throws CModelException{ List nsFunctionDeclarations = namespace.getChildrenOfType(ICElement.C_FUNCTION_DECLARATION); // MyPackage ---> function: void foo() @@ -364,7 +365,7 @@ public class CModelElementsTests extends TestCase { checkLineNumbers((CElement)f3, 90, 92); } - private void checkStructs(IParent namespace){ + private void checkStructs(IParent namespace) throws CModelException{ // struct with name List nsStructs = namespace.getChildrenOfType(ICElement.C_STRUCT); IStructure struct1 = (IStructure) nsStructs.get(0); @@ -424,15 +425,15 @@ public class CModelElementsTests extends TestCase { fail("field visibility should be public!"); } - private void checkTemplates(IParent namespace){ + private void checkTemplates(IParent namespace) throws CModelException{ // template function List functionTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_FUNCTION); FunctionTemplate ft = (FunctionTemplate)functionTemplates.get(0); assertEquals(ft.getElementName(), new String("aTemplatedFunction")); - checkElementOffset((CElement)ft); - String sig = ft.getTemplateSignature(); + checkElementOffset(ft); + ft.getTemplateSignature(); assertEquals(ft.getTemplateSignature(), new String("aTemplatedFunction(B) : A")); - checkLineNumbers((CElement)ft, 112, 113); + checkLineNumbers(ft, 112, 113); // template method List nsClasses = namespace.getChildrenOfType(ICElement.C_CLASS); @@ -441,26 +442,26 @@ public class CModelElementsTests extends TestCase { List methodTemplates = enclosingClass.getChildrenOfType(ICElement.C_TEMPLATE_METHOD); MethodTemplate mt = (MethodTemplate)methodTemplates.get(0); assertEquals(mt.getElementName(), new String("aTemplatedMethod")); - checkElementOffset((CElement)mt); + checkElementOffset(mt); assertEquals(mt.getTemplateSignature(), new String("aTemplatedMethod(B) : A")); - checkLineNumbers((CElement)mt, 118, 119 ); + checkLineNumbers(mt, 118, 119 ); assertEquals(mt.getVisibility(), ASTAccessVisibility.PUBLIC); // template class List classTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_CLASS); StructureTemplate ct = (StructureTemplate)classTemplates.get(0); assertEquals(ct.getElementName(), new String("myarray")); - checkElementOffset((CElement)ct); + checkElementOffset(ct); assertEquals(ct.getTemplateSignature(), new String("myarray")); - checkLineNumbers((CElement)ct, 122, 123); + checkLineNumbers(ct, 122, 123); // template struct List structTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_STRUCT); StructureTemplate st = (StructureTemplate)structTemplates.get(0); assertEquals(st.getElementName(), new String("mystruct")); - checkElementOffset((CElement)st); + checkElementOffset(st); assertEquals(st.getTemplateSignature(), new String("mystruct")); - checkLineNumbers((CElement)st, 125, 126); + checkLineNumbers(st, 125, 126); // moved to failed tests // also commented in the source file @@ -473,7 +474,7 @@ public class CModelElementsTests extends TestCase { // checkLineNumbers((CElement)vt, 128, 129); } - private void checkArrays(IParent tu){ + private void checkArrays(IParent tu) throws CModelException{ // array variable List variables = tu.getChildrenOfType(ICElement.C_VARIABLE); IVariable arrayVar = (IVariable) variables.get(0); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IMacroTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IMacroTests.java index 5bf3edac60c..4fb7c7b99f0 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IMacroTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IMacroTests.java @@ -4,6 +4,7 @@ */ package org.eclipse.cdt.core.model.tests; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.IMacro; import junit.framework.Test; import junit.framework.TestSuite; @@ -53,7 +54,7 @@ public class IMacroTests extends IntegratedCModelTest { return "IMacroTest.h"; } - public void testGetElementName() { + public void testGetElementName() throws CModelException { ITranslationUnit tu = getTU(); List arrayElements = tu.getChildrenOfType( ITranslationUnit.C_MACRO ); @@ -70,7 +71,7 @@ public class IMacroTests extends IntegratedCModelTest { } } - public void testGetIdentifierList() { + public void testGetIdentifierList() throws CModelException { ITranslationUnit tu = getTU(); List arrayElements = tu.getChildrenOfType( ITranslationUnit.C_MACRO ); @@ -87,7 +88,7 @@ public class IMacroTests extends IntegratedCModelTest { } } - public void testGetTokenSequence() { + public void testGetTokenSequence() throws CModelException { ITranslationUnit tu = getTU(); List arrayElements = tu.getChildrenOfType( ITranslationUnit.C_MACRO ); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IStructureTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IStructureTests.java index 94227be5d5a..87c68f34f37 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IStructureTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IStructureTests.java @@ -69,7 +69,7 @@ public class IStructureTests extends IntegratedCModelTest { return suite; } - public void testGetChildrenOfTypeStruct() { + public void testGetChildrenOfTypeStruct() throws CModelException { ITranslationUnit tu = getTU(); List arrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); String[] myExpectedStructs = { @@ -84,7 +84,7 @@ public class IStructureTests extends IntegratedCModelTest { assertEquals(myExpectedStructs[i], myIStruct.getElementName()); } } - public void testGetChildrenOfTypeClass() { + public void testGetChildrenOfTypeClass() throws CModelException { ITranslationUnit tu = getTU(); List arrayClasses = tu.getChildrenOfType(ICElement.C_CLASS); String[] myExpectedClasses = { @@ -98,7 +98,7 @@ public class IStructureTests extends IntegratedCModelTest { } } - public void testGetFields() { + public void testGetFields() throws CModelException { ITranslationUnit tu = getTU(); List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); IStructure myIStruct = (IStructure) myArrayStructs.get(0); @@ -116,7 +116,7 @@ public class IStructureTests extends IntegratedCModelTest { } // TODO Bug# 38985: remove testGetFieldsHack() - public void testGetFieldsHack() { + public void testGetFieldsHack() throws CModelException { ITranslationUnit tu = getTU(); List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); IStructure myIStruct = (IStructure) myArrayStructs.get(0); @@ -133,7 +133,7 @@ public class IStructureTests extends IntegratedCModelTest { myExpectedFields[i], myIField.getElementName()); } } - public void testGetField() { + public void testGetField() throws CModelException { ITranslationUnit tu = getTU(); List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); IStructure myIStruct = (IStructure) myArrayStructs.get(0); @@ -154,7 +154,7 @@ public class IStructureTests extends IntegratedCModelTest { assertNull( "Failed on "+i, myIField); } } - public void testGetMethods() { + public void testGetMethods() throws CModelException { ITranslationUnit tu = getTU(); List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); IStructure myIStruct = (IStructure) myArrayStructs.get(0); @@ -170,7 +170,7 @@ public class IStructureTests extends IntegratedCModelTest { } } // TODO Bug# 38985: remove testGetMethodsHack() - public void testGetMethodsHack() { + public void testGetMethodsHack() throws CModelException { ITranslationUnit tu = getTU(); List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); IStructure myIStruct = (IStructure) myArrayStructs.get(0); @@ -187,7 +187,7 @@ public class IStructureTests extends IntegratedCModelTest { myExpectedMethods[i], myIMethod.getElementName()); } } - public void testGetMethod() { + public void testGetMethod() throws CModelException { ITranslationUnit tu = getTU(); List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); IStructure myIStruct = (IStructure) myArrayStructs.get(0); @@ -282,7 +282,7 @@ public class IStructureTests extends IntegratedCModelTest { assertFalse( myStructNonClass.isClass() ); } - public void testIsAbstract() { + public void testIsAbstract() throws CModelException { ITranslationUnit tu = getTU(); ICElement myElementAbstract = null; ICElement myElementNonAbstract = null; @@ -394,7 +394,7 @@ public class IStructureTests extends IntegratedCModelTest { assertEquals( ICElement.C_VARIABLE, myElement.getElementType() ); } - public void testInnerStruct() { + public void testInnerStruct() throws CModelException { ITranslationUnit tu = getTU(); ICElement myElement = null; try { diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/ITemplateTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/ITemplateTests.java index d92b527a3aa..8df4502a586 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/ITemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/ITemplateTests.java @@ -5,6 +5,7 @@ package org.eclipse.cdt.core.model.tests; import org.eclipse.cdt.core.model.*; + import junit.framework.*; import java.util.ArrayList; import java.util.List; @@ -56,7 +57,7 @@ public class ITemplateTests extends IntegratedCModelTest { return suite; } - public List getTemplateMethods(ITranslationUnit tu) + public List getTemplateMethods(ITranslationUnit tu) throws CModelException { IStructure myElem = null; try { @@ -69,7 +70,7 @@ public class ITemplateTests extends IntegratedCModelTest { return myElem.getChildrenOfType(ICElement.C_TEMPLATE_METHOD); } - public void testGetChildrenOfTypeTemplate() { + public void testGetChildrenOfTypeTemplate() throws CModelException { ITranslationUnit tu = getTU(); { List arrayElements = tu.getChildrenOfType(ICElement.C_TEMPLATE_STRUCT); @@ -150,7 +151,7 @@ public class ITemplateTests extends IntegratedCModelTest { */ } - public void testGetNumberOfTemplateParameters() + public void testGetNumberOfTemplateParameters() throws CModelException { ITranslationUnit tu = getTU(); ArrayList arrayElements = new ArrayList(); @@ -174,7 +175,7 @@ public class ITemplateTests extends IntegratedCModelTest { myTemplate.getNumberOfTemplateParameters()); } } - public void testGetTemplateParameterTypes() + public void testGetTemplateParameterTypes() throws CModelException { ITranslationUnit tu = getTU(); ArrayList arrayElements = new ArrayList(); @@ -219,7 +220,7 @@ public class ITemplateTests extends IntegratedCModelTest { } } } - public void testGetTemplateSignature() + public void testGetTemplateSignature() throws CModelException { ITranslationUnit tu = getTU(); ArrayList arrayElements = new ArrayList(); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java index d49fe47ec18..02f6bb2896f 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java @@ -89,7 +89,7 @@ public class TranslationUnitTests extends TranslationUnitBaseTest { * Simple sanity tests to make sure TranslationUnit.getChildren seems to * basicly work */ - public void testGetChildren() { + public void testGetChildren() throws CModelException { ITranslationUnit myTranslationUnit; ICElement[] elements; int x; @@ -142,7 +142,7 @@ public class TranslationUnitTests extends TranslationUnitBaseTest { /*** * Simple sanity tests for the getInclude call */ - public void testBug23478A() { + public void testBug23478A() throws CModelException { IInclude myInclude; int x; String includes[]={"stdio.h", "unistd.h"}; diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/CProjectHelper.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/CProjectHelper.java index 2fca7b9a9d6..f0a5376433f 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/CProjectHelper.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/CProjectHelper.java @@ -7,6 +7,7 @@ import junit.framework.Assert; import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CProjectNature; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IArchive; import org.eclipse.cdt.core.model.IArchiveContainer; @@ -159,7 +160,7 @@ public class CProjectHelper { /** * Attempts to find an archive with the given name in the workspace */ - public static IArchive findArchive(ICProject testProject, String name) { + public static IArchive findArchive(ICProject testProject, String name) throws CModelException { int x; IArchive[] myArchives; IArchiveContainer archCont; @@ -181,7 +182,7 @@ public class CProjectHelper { /** * Attempts to find a binary with the given name in the workspace */ - public static IBinary findBinary(ICProject testProject, String name) { + public static IBinary findBinary(ICProject testProject, String name) throws CModelException { IBinaryContainer binCont; int x; IBinary[] myBinaries; @@ -199,7 +200,7 @@ public class CProjectHelper { /** * Attempts to find an object with the given name in the workspace */ - public static IBinary findObject(ICProject testProject, String name) { + public static IBinary findObject(ICProject testProject, String name) throws CModelException { ICElement[] sourceRoots = testProject.getChildren(); for (int i = 0; i < sourceRoots.length; i++) { ISourceRoot root = (ISourceRoot) sourceRoots[i]; @@ -218,7 +219,7 @@ public class CProjectHelper { /** * Attempts to find a TranslationUnit with the given name in the workspace */ - public static ITranslationUnit findTranslationUnit(ICProject testProject, String name) { + public static ITranslationUnit findTranslationUnit(ICProject testProject, String name) throws CModelException { ICElement[] sourceRoots = testProject.getChildren(); for (int i = 0; i < sourceRoots.length; i++) { ISourceRoot root = (ISourceRoot) sourceRoots[i]; @@ -237,7 +238,7 @@ public class CProjectHelper { /** * Attempts to find an element with the given name in the workspace */ - public static ICElement findElement(ICProject testProject, String name) { + public static ICElement findElement(ICProject testProject, String name) throws CModelException { ICElement[] sourceRoots = testProject.getChildren(); for (int i = 0; i < sourceRoots.length; i++) { ISourceRoot root = (ISourceRoot) sourceRoots[i]; diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index 140e543044e..56c4b320c85 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -1,3 +1,29 @@ +2004-04-19 Alain Magloire + + It has become necessary to add exception in the interface + IParent.getChildren() + IParent.getChildrenOfType() + IArchive.getBinaries() + IBinary.getBinaries() + ... + Now they throw CModelException. + Lots of files changed, will not bother enumerated them + all in the log. + + * model/org/eclipse/cdt/core/IArchive.java + * model/org/eclipse/cdt/core/IArchiveContainer.java + * model/org/eclipse/cdt/core/IBinaryContainer.java + * model/org/eclipse/cdt/core/IBinaryModule.java + * model/org/eclipse/cdt/core/ICModel.java + * model/org/eclipse/cdt/core/IParent.java + * model/org/eclipse/cdt/core/IStructure.java + + * model/org/eclipse/cdt/internal/core/model/* + * browser/org/eclipse/cdt/core/model/TypeInfo.java + * search/org/eclipse/cdt/internal/core/search/CSearchScope.java + * search/org/eclipse/cdt/internal/core/search/CWorkspaceScope.java + + 2004-04-19 David Inglis Fixed dead lock - don't fire descriptor events with descriptor lock diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/TypeInfo.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/TypeInfo.java index fff39f72225..1e1017eb21b 100644 --- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/TypeInfo.java +++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/TypeInfo.java @@ -15,6 +15,7 @@ import java.util.Arrays; import java.util.Comparator; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; @@ -226,14 +227,17 @@ public class TypeInfo implements ITypeInfo, Comparable private ICElement findCElement(ICElement celement, String name) { if (isValidType(celement.getElementType()) && celement.getElementName().equals(name)) return celement; - - if (celement instanceof IParent) { - ICElement[] children = ((IParent)celement).getChildren(); - for (int i = 0; i < children.length; i++) { - ICElement child= children[i]; - if (isValidType(child.getElementType()) && child.getElementName().equals(name)) - return child; + try { + if (celement instanceof IParent) { + ICElement[] children = ((IParent)celement).getChildren(); + for (int i = 0; i < children.length; i++) { + ICElement child= children[i]; + if (isValidType(child.getElementType()) && child.getElementName().equals(name)) + return child; + } } + } catch (CModelException e) { + } return null; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IArchive.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IArchive.java index 1f1f471099b..32bda09a25a 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IArchive.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IArchive.java @@ -14,5 +14,5 @@ public interface IArchive extends ICElement, IParent, IOpenable { * Return the binaries contain in the archive. * It does not actually extract the files. */ - public IBinary[] getBinaries(); + public IBinary[] getBinaries() throws CModelException; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IArchiveContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IArchiveContainer.java index 6554e42fd04..4fab28eeedf 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IArchiveContainer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IArchiveContainer.java @@ -10,5 +10,10 @@ package org.eclipse.cdt.core.model; * while inspecting the project. */ public interface IArchiveContainer extends ICElement, IParent, IOpenable { - public IArchive[] getArchives(); + /** + * + * @return + * @throws CModelException + */ + public IArchive[] getArchives() throws CModelException; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinaryContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinaryContainer.java index 2a937c485a9..1aca3c0c2c1 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinaryContainer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinaryContainer.java @@ -11,5 +11,10 @@ package org.eclipse.cdt.core.model; */ public interface IBinaryContainer extends ICElement, IParent, IOpenable { - public IBinary[] getBinaries(); + /** + * + * @return + * @throws CModelException + */ + public IBinary[] getBinaries() throws CModelException; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinaryModule.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinaryModule.java index d72fd072eb1..aa4c12cfe9e 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinaryModule.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinaryModule.java @@ -9,5 +9,10 @@ package org.eclipse.cdt.core.model; */ public interface IBinaryModule extends IParent, IBinaryElement { - IBinaryElement[] getBinaryElements(); + /** + * + * @return + * @throws CModelException + */ + IBinaryElement[] getBinaryElements() throws CModelException; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModel.java index a70c3fa8b7e..366bbeb815d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModel.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModel.java @@ -170,7 +170,7 @@ public interface ICModel extends ICElement, IParent, IOpenable { * Returns the C projects. * */ - ICProject[] getCProjects(); + ICProject[] getCProjects() throws CModelException; /** * Returns an array of non-C resources (i.e. non-C projects) in diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IParent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IParent.java index a8bef15f593..64a39ef9ab6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IParent.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IParent.java @@ -19,12 +19,12 @@ public interface IParent { * @exception CModelException if this element does not exist or if an * exception occurs while accessing its corresponding resource */ - ICElement[] getChildren(); + ICElement[] getChildren() throws CModelException; /** * returns the children of a certain type */ - public List getChildrenOfType(int type); + public List getChildrenOfType(int type) throws CModelException; /** * Returns whether this element has one or more immediate children. * This is a convenience method, and may be more efficient than diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IStructure.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IStructure.java index e66fd371bbc..10538941574 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IStructure.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IStructure.java @@ -11,10 +11,22 @@ package org.eclipse.cdt.core.model; */ public interface IStructure extends IInheritance, IParent, IVariableDeclaration { public IField getField(String name); - public IField[] getFields(); + + /** + * + * @return + * @throws CModelException + */ + public IField[] getFields() throws CModelException; public IMethodDeclaration getMethod(String name); - public IMethodDeclaration [] getMethods(); + + /** + * + * @return + * @throws CModelException + */ + public IMethodDeclaration [] getMethods() throws CModelException; public boolean isUnion(); @@ -22,6 +34,11 @@ public interface IStructure extends IInheritance, IParent, IVariableDeclaration public boolean isStruct(); - public boolean isAbstract(); + /** + * + * @return + * @throws CModelException + */ + public boolean isAbstract() throws CModelException; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java index a3c2297f303..34c126ecb3c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java @@ -32,7 +32,7 @@ public class Archive extends Openable implements IArchive { binaryArchive = ar; } - public IBinary[] getBinaries() { + public IBinary[] getBinaries() throws CModelException { ICElement[] e = getChildren(); IBinary[] b = new IBinary[e.length]; System.arraycopy(e, 0, b, 0, e.length); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java index 0b005544190..3099ca5f147 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java @@ -20,7 +20,7 @@ public class ArchiveContainer extends Openable implements IArchiveContainer { super (cProject, null, CCorePlugin.getResourceString("CoreModel.ArchiveContainer.Archives"), CElement.C_VCONTAINER); //$NON-NLS-1$ } - public IArchive[] getArchives() { + public IArchive[] getArchives() throws CModelException { ((ArchiveContainerInfo)getElementInfo()).sync(); ICElement[] e = getChildren(); IArchive[] a = new IArchive[e.length]; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java index bc65b1c174c..570d01e10ed 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java @@ -21,7 +21,7 @@ public class BinaryContainer extends Openable implements IBinaryContainer { super (cProject, null, CCorePlugin.getResourceString("CoreModel.BinaryContainer.Binaries"), CElement.C_VCONTAINER); //$NON-NLS-1$ } - public IBinary[] getBinaries() { + public IBinary[] getBinaries() throws CModelException { ((BinaryContainerInfo)getElementInfo()).sync(); ICElement[] e = getChildren(); ArrayList list = new ArrayList(e.length); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryElement.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryElement.java index 474cea9011a..7d3adad6607 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryElement.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryElement.java @@ -98,7 +98,7 @@ public class BinaryElement extends CElement implements IBinaryElement, ISourceMa /* (non-Javadoc) * @see org.eclipse.cdt.core.model.ISourceReference#getTranslationUnit() */ - public ITranslationUnit getTranslationUnit() { + public ITranslationUnit getTranslationUnit() { ITranslationUnit tu = null; CModelManager mgr = CModelManager.getDefault(); ICElement parent = getParent(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryModule.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryModule.java index 8b0a60c36cb..5a90dd97c97 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryModule.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryModule.java @@ -27,7 +27,7 @@ public class BinaryModule extends Parent implements IBinaryModule { /* (non-Javadoc) * @see org.eclipse.cdt.core.model.IBinaryModule#getBinaryElements() */ - public IBinaryElement[] getBinaryElements() { + public IBinaryElement[] getBinaryElements() throws CModelException { ICElement[] e = getChildren(); IBinaryElement[] b = new IBinaryElement[e.length]; System.arraycopy(e, 0, b, 0, e.length); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java index 23703e59837..7b0c8165186 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java @@ -6,6 +6,7 @@ package org.eclipse.cdt.internal.core.model; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ElementChangedEvent; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICModel; @@ -80,18 +81,22 @@ public class BinaryRunner { void fireEvents(ICProject cproject, Parent container) { // Fired the event. - ICElement[] children = container.getChildren(); - if (children.length > 0) { - CModelManager factory = CModelManager.getDefault(); - ICElement root = (ICModel) factory.getCModel(); - CElementDelta cdelta = new CElementDelta(root); - cdelta.added(cproject); - cdelta.added(container); - for (int i = 0; i < children.length; i++) { - cdelta.added(children[i]); + try { + ICElement[] children = container.getChildren(); + if (children.length > 0) { + CModelManager factory = CModelManager.getDefault(); + ICElement root = (ICModel) factory.getCModel(); + CElementDelta cdelta = new CElementDelta(root); + cdelta.added(cproject); + cdelta.added(container); + for (int i = 0; i < children.length; i++) { + cdelta.added(children[i]); + } + factory.registerCModelDelta(cdelta); + factory.fire(ElementChangedEvent.POST_CHANGE); } - factory.registerCModelDelta(cdelta); - factory.fire(ElementChangedEvent.POST_CHANGE); + } catch (CModelException e) { + // } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModel.java index 408b092963a..db07e80a876 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModel.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModel.java @@ -38,7 +38,7 @@ public class CModel extends Openable implements ICModel { return super.equals(o); } - public ICProject[] getCProjects() { + public ICProject[] getCProjects() throws CModelException { List list = getChildrenOfType(C_PROJECT); ICProject[] array= new ICProject[list.size()]; list.toArray(array); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java index 468dcf9178e..bfb39384758 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java @@ -331,7 +331,6 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe IPath rootPath = root.getPath(); IPath resourcePath = file.getFullPath(); IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount()); - String fileName = path.lastSegment(); path = path.removeLastSegments(1); String[] segments = path.segments(); ICContainer cfolder = root; @@ -427,23 +426,31 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe ArrayList list = new ArrayList(5); if (pinfo != null && pinfo.vBin != null) { if (peekAtInfo(pinfo.vBin) != null) { - ICElement[] bins = pinfo.vBin.getChildren(); - for (int i = 0; i < bins.length; i++) { - if (celement.getPath().isPrefixOf(bins[i].getPath())) { - //pinfo.vBin.removeChild(bins[i]); - list.add(bins[i]); + try { + ICElement[] bins = pinfo.vBin.getChildren(); + for (int i = 0; i < bins.length; i++) { + if (celement.getPath().isPrefixOf(bins[i].getPath())) { + //pinfo.vBin.removeChild(bins[i]); + list.add(bins[i]); + } } + } catch (CModelException e) { + // .. } } } if (pinfo != null && pinfo.vLib != null) { if (peekAtInfo(pinfo.vLib) != null) { - ICElement[] ars = pinfo.vLib.getChildren(); - for (int i = 0; i < ars.length; i++) { - if (celement.getPath().isPrefixOf(ars[i].getPath())) { - //pinfo.vLib.removeChild(ars[i]); - list.add(ars[i]); + try { + ICElement[] ars = pinfo.vLib.getChildren(); + for (int i = 0; i < ars.length; i++) { + if (celement.getPath().isPrefixOf(ars[i].getPath())) { + //pinfo.vLib.removeChild(ars[i]); + list.add(ars[i]); + } } + } catch (CModelException e) { + // .. } } } @@ -979,7 +986,10 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe switch (resource.getType()) { case IResource.ROOT : if (this.cProjectsCache == null) { - this.cProjectsCache = this.getCModel().getCProjects(); + try { + this.cProjectsCache = this.getCModel().getCProjects(); + } catch (CModelException e) { + } } IResourceDelta[] children = delta.getAffectedChildren(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateFieldOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateFieldOperation.java index cae08069224..0ebe1dc4554 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateFieldOperation.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateFieldOperation.java @@ -5,6 +5,7 @@ package org.eclipse.cdt.internal.core.model; * All Rights Reserved. */ +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.IStructure; import org.eclipse.cdt.core.model.ICModelStatus; @@ -44,7 +45,7 @@ public class CreateFieldOperation extends CreateMemberOperation { */ protected void initializeDefaultPosition() { IStructure parentElement = getStructure(); - //try { + try { ICElement[] elements = parentElement.getFields(); if (elements != null && elements.length > 0) { createAfter(elements[elements.length - 1]); @@ -54,8 +55,8 @@ public class CreateFieldOperation extends CreateMemberOperation { createBefore(elements[0]); } } - //} catch (CModelException e) { - //} + } catch (CModelException e) { + } } /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java index aa59ba1b6ff..36002542050 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java @@ -184,21 +184,27 @@ public class DeltaProcessor { CProjectInfo pinfo = (CProjectInfo)factory.peekAtInfo(cproject); if (pinfo != null && pinfo.vBin != null) { if (factory.peekAtInfo(pinfo.vBin) != null) { - ICElement[] bins = pinfo.vBin.getChildren(); - for (int i = 0; i < bins.length; i++) { - if (celement.getPath().isPrefixOf(bins[i].getPath())) { - fCurrentDelta.changed(pinfo.vBin, ICElementDelta.CHANGED); + try { + ICElement[] bins = pinfo.vBin.getChildren(); + for (int i = 0; i < bins.length; i++) { + if (celement.getPath().isPrefixOf(bins[i].getPath())) { + fCurrentDelta.changed(pinfo.vBin, ICElementDelta.CHANGED); + } } + } catch (CModelException e) { } } } if (pinfo != null && pinfo.vLib != null) { if (factory.peekAtInfo(pinfo.vLib) != null) { - ICElement[] ars = pinfo.vLib.getChildren(); - for (int i = 0; i < ars.length; i++) { - if (celement.getPath().isPrefixOf(ars[i].getPath())) { - fCurrentDelta.changed(pinfo.vBin, ICElementDelta.CHANGED); + try { + ICElement[] ars = pinfo.vLib.getChildren(); + for (int i = 0; i < ars.length; i++) { + if (celement.getPath().isPrefixOf(ars[i].getPath())) { + fCurrentDelta.changed(pinfo.vBin, ICElementDelta.CHANGED); + } } + } catch (CModelException e) { } } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Parent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Parent.java index 24633c37705..6aef45375a0 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Parent.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Parent.java @@ -8,6 +8,7 @@ package org.eclipse.cdt.internal.core.model; import java.util.ArrayList; import java.util.List; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; public abstract class Parent extends CElement { @@ -43,7 +44,7 @@ public abstract class Parent extends CElement { * Returns null if the element does not support children * Implementations override this method to support children */ - public ICElement[] getChildren() { + public ICElement[] getChildren() throws CModelException { CElementInfo info = getElementInfo(); if (info != null) return info.getChildren(); @@ -56,7 +57,7 @@ public abstract class Parent extends CElement { * @param type * @return ArrayList */ - public List getChildrenOfType(int type){ + public List getChildrenOfType(int type) throws CModelException { ICElement[] children = getChildren(); int size = children.length; ArrayList list = new ArrayList(size); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceMapper.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceMapper.java index 44952ecb9d6..6a5b1b80c05 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceMapper.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceMapper.java @@ -6,6 +6,7 @@ package org.eclipse.cdt.internal.core.model; import java.util.List; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICContainer; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; @@ -26,29 +27,32 @@ public class SourceMapper { } public ITranslationUnit findTranslationUnit(IParent container, String filename) { - List list = container.getChildrenOfType(ICElement.C_UNIT); - for (int i = 0; i < list.size(); i++) { - Object o = list.get(i); - if (o instanceof ITranslationUnit) { - ITranslationUnit tu = (ITranslationUnit)o; - // TODO: What about non case sensitive filesystems. - if (filename.equals(tu.getElementName())) { - return tu; + try { + List list = container.getChildrenOfType(ICElement.C_UNIT); + for (int i = 0; i < list.size(); i++) { + Object o = list.get(i); + if (o instanceof ITranslationUnit) { + ITranslationUnit tu = (ITranslationUnit)o; + // TODO: What about non case sensitive filesystems. + if (filename.equals(tu.getElementName())) { + return tu; + } } } - } - - // TODO: This to simple, we are not protected against - // loop in the file system symbolic links etc .. - list = container.getChildrenOfType(ICElement.C_CCONTAINER); - for (int i = 0; i < list.size(); i++) { - Object o = list.get(i); - if (o instanceof ICContainer) { - ITranslationUnit tu = findTranslationUnit((ICContainer)o, filename); - if (tu != null) { - return tu; + + // TODO: This to simple, we are not protected against + // loop in the file system symbolic links etc .. + list = container.getChildrenOfType(ICElement.C_CCONTAINER); + for (int i = 0; i < list.size(); i++) { + Object o = list.get(i); + if (o instanceof ICContainer) { + ITranslationUnit tu = findTranslationUnit((ICContainer)o, filename); + if (tu != null) { + return tu; + } } } + } catch (CModelException e) { } return null; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Structure.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Structure.java index 54603117757..c9ba018890d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Structure.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Structure.java @@ -10,6 +10,7 @@ import java.util.List; import java.util.Map; import java.util.TreeMap; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.IField; import org.eclipse.cdt.core.model.IMethodDeclaration; @@ -24,24 +25,27 @@ public class Structure extends SourceManipulation implements IStructure { super(parent, name, kind); } - public IField[] getFields() { + public IField[] getFields() throws CModelException { List fields = new ArrayList(); fields.addAll(getChildrenOfType(ICElement.C_FIELD)); return (IField[]) fields.toArray(new IField[fields.size()]); } public IField getField(String name) { - IField[] fields = getFields(); - for (int i = 0; i 0; + try { + IBinaryContainer cont = (IBinaryContainer)element; + IBinary[] bins = getExecutables(cont); + return (bins != null) && bins.length > 0; + } catch (CModelException e) { + return false; + } } if (element instanceof IParent) { @@ -244,7 +253,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider { return parent; } - protected Object[] getCProjects(ICModel cModel) { + protected Object[] getCProjects(ICModel cModel) throws CModelException { Object[] objects = cModel.getCProjects(); try { Object[] nonC = cModel.getNonCResources(); @@ -257,44 +266,37 @@ public class BaseCElementContentProvider implements ITreeContentProvider { return objects; } - protected Object[] getSourceRoots(ICProject cproject) { + protected Object[] getSourceRoots(ICProject cproject) throws CModelException { if (!cproject.getProject().isOpen()) return NO_CHILDREN; List list= new ArrayList(); - try { - ISourceRoot[] roots = cproject.getSourceRoots(); - // filter out source roots that correspond to projects and - // replace them with the package fragments directly - for (int i= 0; i < roots.length; i++) { - ISourceRoot root= roots[i]; - if (isProjectSourceRoot(root)) { - Object[] children= root.getChildren(); - for (int k= 0; k < children.length; k++) { - list.add(children[k]); - } - } else { - list.add(root); + ISourceRoot[] roots = cproject.getSourceRoots(); + // filter out source roots that correspond to projects and + // replace them with the package fragments directly + for (int i= 0; i < roots.length; i++) { + ISourceRoot root= roots[i]; + if (isProjectSourceRoot(root)) { + Object[] children= root.getChildren(); + for (int k= 0; k < children.length; k++) { + list.add(children[k]); } + } else { + list.add(root); } - } catch (CModelException e1) { } Object[] objects = list.toArray(); - try { - Object[] nonC = cproject.getNonCResources(); - if (nonC != null && nonC.length > 0) { - nonC = filterNonCResources(nonC, cproject); - objects = concatenate(objects, nonC); - } - } catch (CModelException e) { - // + Object[] nonC = cproject.getNonCResources(); + if (nonC != null && nonC.length > 0) { + nonC = filterNonCResources(nonC, cproject); + objects = concatenate(objects, nonC); } return objects; } - protected Object[] getCResources(ICContainer container) { + protected Object[] getCResources(ICContainer container) throws CModelException { Object[] objects = null; Object[] children = container.getChildren(); try { @@ -318,7 +320,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider { return NO_CHILDREN; } - private Object[] getResources(IFolder folder) { + private Object[] getResources(IFolder folder) throws CModelException { ICProject cproject = CoreModel.getDefault().create(folder.getProject()); Object[] members = null; try { @@ -332,7 +334,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider { return filterNonCResources(members, cproject); } - private Object[] filterNonCResources(Object[] objects, ICProject cproject) { + private Object[] filterNonCResources(Object[] objects, ICProject cproject) throws CModelException { ICElement[] binaries = getBinaries(cproject); ICElement[] archives = getArchives(cproject); ISourceRoot[] roots = null; @@ -410,12 +412,12 @@ public class BaseCElementContentProvider implements ITreeContentProvider { return true; } - protected IBinary[] getExecutables(ICProject cproject) { + protected IBinary[] getExecutables(ICProject cproject) throws CModelException { IBinaryContainer container = cproject.getBinaryContainer(); return getExecutables(container); } - protected IBinary[] getExecutables(IBinaryContainer container) { + protected IBinary[] getExecutables(IBinaryContainer container) throws CModelException { ICElement[] celements = container.getChildren(); ArrayList list = new ArrayList(celements.length); for (int i = 0; i < celements.length; i++) { @@ -431,12 +433,12 @@ public class BaseCElementContentProvider implements ITreeContentProvider { return bins; } - protected IBinary[] getBinaries(ICProject cproject) { + protected IBinary[] getBinaries(ICProject cproject) throws CModelException { IBinaryContainer container = cproject.getBinaryContainer(); return getBinaries(container); } - protected IBinary[] getBinaries(IBinaryContainer container) { + protected IBinary[] getBinaries(IBinaryContainer container) throws CModelException { ICElement[] celements = container.getChildren(); ArrayList list = new ArrayList(celements.length); for (int i = 0; i < celements.length; i++) { @@ -450,12 +452,12 @@ public class BaseCElementContentProvider implements ITreeContentProvider { return bins; } - protected IArchive[] getArchives(ICProject cproject) { + protected IArchive[] getArchives(ICProject cproject) throws CModelException { IArchiveContainer container = cproject.getArchiveContainer(); return getArchives(container); } - protected IArchive[] getArchives(IArchiveContainer container) { + protected IArchive[] getArchives(IArchiveContainer container) throws CModelException { ICElement[] celements = container.getChildren(); ArrayList list = new ArrayList(celements.length); for (int i = 0; i < celements.length; i++) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CWorkbenchAdapter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CWorkbenchAdapter.java index 322b2de4777..2445767370a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CWorkbenchAdapter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CWorkbenchAdapter.java @@ -8,9 +8,11 @@ package org.eclipse.cdt.internal.ui; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.model.IWorkbenchAdapter; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.ui.CElementLabelProvider; +import org.eclipse.cdt.ui.CUIPlugin; /** * An imlementation of the IWorkbenchAdapter for CElements. @@ -31,9 +33,13 @@ public class CWorkbenchAdapter implements IWorkbenchAdapter { */ public Object[] getChildren(Object o) { if (o instanceof IParent) { - Object[] members = ((IParent) o).getChildren(); - if (members != null) { - return members; + try { + Object[] members = ((IParent) o).getChildren(); + if (members != null) { + return members; + } + } catch (CModelException e) { + CUIPlugin.getDefault().log(e); } } return fgEmptyArray; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewContentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewContentProvider.java index 7b28438a26a..bfc24ea985e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewContentProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewContentProvider.java @@ -45,18 +45,21 @@ public class CViewContentProvider extends CElementContentProvider { public Object[] getChildren(Object element) { Object[] objs = super.getChildren(element); Object[] extras = null; - if (element instanceof ICProject) { - extras = getProjectChildren((ICProject)element); - } else if (element instanceof IBinaryContainer) { - extras = getExecutables((IBinaryContainer)element); - } else if (element instanceof IArchiveContainer) { - extras = getArchives((IArchiveContainer)element); - } else if (element instanceof LibraryRefContainer) { - extras = ((LibraryRefContainer)element).getChildren(element); - } else if (element instanceof IncludeRefContainer) { - extras = ((IncludeRefContainer)element).getChildren(element); + try { + if (element instanceof ICProject) { + extras = getProjectChildren((ICProject)element); + } else if (element instanceof IBinaryContainer) { + extras = getExecutables((IBinaryContainer)element); + } else if (element instanceof IArchiveContainer) { + extras = getArchives((IArchiveContainer)element); + } else if (element instanceof LibraryRefContainer) { + extras = ((LibraryRefContainer)element).getChildren(element); + } else if (element instanceof IncludeRefContainer) { + extras = ((IncludeRefContainer)element).getChildren(element); + } + } catch (CModelException e) { + extras = null; } - if (extras != null && extras.length > 0) { objs = concatenate(objs, extras); } @@ -66,7 +69,7 @@ public class CViewContentProvider extends CElementContentProvider { /** * @return */ - private Object[] getProjectChildren(ICProject cproject) { + private Object[] getProjectChildren(ICProject cproject) throws CModelException { Object[] extras = null; IArchiveContainer archive = cproject.getArchiveContainer(); if (getArchives(archive).length > 0) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathProjectsEntryPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathProjectsEntryPage.java index e80d6f4b519..2ad68f1fe0b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathProjectsEntryPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathProjectsEntryPage.java @@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.ui.dialogs.cpaths; import java.util.ArrayList; import java.util.List; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICModel; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.IPathEntry; @@ -20,6 +21,7 @@ import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil; import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField; +import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -111,33 +113,36 @@ public class CPathProjectsEntryPage extends CPathBasePage { void updateProjectsList(ICProject currCProject) { ICModel cmodel = currCProject.getCModel(); - ICProject[] cprojects = cmodel.getCProjects(); - List projects = new ArrayList(cprojects.length); - - // a vector remembering all projects that dont have to be added anymore - List existingProjects = new ArrayList(cprojects.length); - existingProjects.add(currCProject.getProject()); - - final List checkedProjects = new ArrayList(cprojects.length); - // add the projects-cpentries that are already on the C Path - List cpelements = fCPathList.getElements(); - for (int i = cpelements.size() - 1; i >= 0; i--) { - CPListElement cpelem = (CPListElement) cpelements.get(i); - if (isEntryKind(cpelem.getEntryKind())) { - existingProjects.add(cpelem.getResource()); - projects.add(cpelem); - checkedProjects.add(cpelem); + List projects = new ArrayList(); + final List checkedProjects = new ArrayList(); + try { + ICProject[] cprojects = cmodel.getCProjects(); + + // a vector remembering all projects that dont have to be added anymore + List existingProjects = new ArrayList(cprojects.length); + existingProjects.add(currCProject.getProject()); + + // add the projects-cpentries that are already on the C Path + List cpelements = fCPathList.getElements(); + for (int i = cpelements.size() - 1; i >= 0; i--) { + CPListElement cpelem = (CPListElement) cpelements.get(i); + if (isEntryKind(cpelem.getEntryKind())) { + existingProjects.add(cpelem.getResource()); + projects.add(cpelem); + checkedProjects.add(cpelem); + } } - } - - for (int i = 0; i < cprojects.length; i++) { - IProject proj = cprojects[i].getProject(); - if (!existingProjects.contains(proj)) { - projects.add(new CPListElement(fCurrCProject, IPathEntry.CDT_PROJECT, proj.getFullPath(), proj)); + + for (int i = 0; i < cprojects.length; i++) { + IProject proj = cprojects[i].getProject(); + if (!existingProjects.contains(proj)) { + projects.add(new CPListElement(fCurrCProject, IPathEntry.CDT_PROJECT, proj.getFullPath(), proj)); + } } + } catch (CModelException e) { + CUIPlugin.getDefault().log(e); } - fProjectsList.setElements(projects); fProjectsList.setCheckedElements(checkedProjects); fCurrCProject = currCProject; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java index b50cb9eebd9..320f87cec66 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java @@ -196,7 +196,14 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage { public void init(ICProject project, List cPaths) { fCurrCProject = project; - List list = new ArrayList(project.getChildrenOfType(ICElement.C_CCONTAINER)); + List list = new ArrayList(); + try { + List clist = project.getChildrenOfType(ICElement.C_CCONTAINER); + list.addAll(clist); + } catch (CModelException e) { + CUIPlugin.getDefault().log(e); + } + int i; for (i = 0; i < list.size(); i++) { if (((ISourceRoot) list.get(i)).getResource() == project.getProject()) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsTabBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsTabBlock.java index 6cf42e3ec74..0aa34e187ea 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsTabBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsTabBlock.java @@ -12,12 +12,14 @@ package org.eclipse.cdt.internal.ui.dialogs.cpaths; import java.util.ArrayList; import java.util.List; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICContainer; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter; import org.eclipse.cdt.internal.ui.wizards.dialogfields.TreeListDialogField; +import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.events.KeyEvent; @@ -52,8 +54,12 @@ public class IncludesSymbolsTabBlock extends AbstractPathOptionBlock { public Object[] getChildren(TreeListDialogField field, Object element) { List children = new ArrayList(); if (element instanceof ICContainer) { - children.addAll(((ICContainer) element).getChildrenOfType(ICElement.C_CCONTAINER)); - children.addAll(((ICContainer) element).getChildrenOfType(ICElement.C_UNIT)); + try { + children.addAll(((ICContainer) element).getChildrenOfType(ICElement.C_CCONTAINER)); + children.addAll(((ICContainer) element).getChildrenOfType(ICElement.C_UNIT)); + } catch (CModelException e) { + CUIPlugin.getDefault().log(e); + } } return children.toArray(); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResult.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResult.java index 4a815b1cee4..82e3a16c106 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResult.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResult.java @@ -11,6 +11,7 @@ import java.util.HashSet; import java.util.Set; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.IParent; @@ -61,10 +62,13 @@ public class CSearchResult extends AbstractTextSearchResult { } if (element instanceof IParent) { IParent parent= (IParent) element; - - ICElement[] children= parent.getChildren(); - for (int i= 0; i < children.length; i++) { - collectMatches(matches, children[i]); + try { + ICElement[] children= parent.getChildren(); + for (int i= 0; i < children.length; i++) { + collectMatches(matches, children[i]); + } + } catch (CModelException e) { + // we will not be tracking these results } } 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 5c6532fd0cb..1c768e2a8ce 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 @@ -415,9 +415,12 @@ public class NewClassWizardPage extends WizardPage implements Listener { } if (elem == null || elem.getElementType() == ICElement.C_MODEL) { - ICProject[] projects= CoreModel.create(CUIPlugin.getWorkspace().getRoot()).getCProjects(); - if (projects.length == 1) { - elem= projects[0]; + try { + ICProject[] projects = CoreModel.create(CUIPlugin.getWorkspace().getRoot()).getCProjects(); + if (projects.length == 1) { + elem= projects[0]; + } + } catch (CModelException e) { } } return elem; @@ -438,7 +441,6 @@ public class NewClassWizardPage extends WizardPage implements Listener { } private IProject getSelectionProject(IStructuredSelection selection) { - IProject project= null; if (selection != null && !selection.isEmpty()) { Object selectedElement= selection.getFirstElement(); if (selectedElement instanceof IAdaptable) { @@ -452,74 +454,74 @@ public class NewClassWizardPage extends WizardPage implements Listener { return null; } - private ITypeInfo[] findClassElementsInProject(){ + private ITypeInfo[] findClassElementsInProject(){ if(eSelection == null){ - return null; + return null; } - + if( elementsOfTypeClassInProject != null ){ return elementsOfTypeClassInProject; } - - ICProject cProject= eSelection.getCProject(); - ICElement[] elements= new ICElement[] { cProject }; - final ICSearchScope scope= SearchEngine.createCSearchScope(elements, true); - final int[] kinds= { ICElement.C_CLASS, ICElement.C_STRUCT }; - final Collection typeList= new ArrayList(); - - if (AllTypesCache.isCacheUpToDate()) { - // run without progress monitor - AllTypesCache.getTypes(scope, kinds, null, typeList); - } else { - IRunnableWithProgress runnable= new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - AllTypesCache.getTypes(scope, kinds, monitor, typeList); - if (monitor.isCanceled()) { - throw new InterruptedException(); - } - } - }; - - try { - getContainer().run(true, true, runnable); - } catch (InvocationTargetException e) { - String title= NewWizardMessages.getString("NewClassWizardPage.getProjectClasses.exception.title"); //$NON-NLS-1$ - String message= NewWizardMessages.getString("NewClassWizardPage.getProjectClasses.exception.message"); //$NON-NLS-1$ - ExceptionHandler.handle(e, title, message); - return null; - } catch (InterruptedException e) { - // cancelled by user - return null; - } - } - if (typeList.isEmpty()) { - elementsOfTypeClassInProject= new ITypeInfo[0]; - } else { - elementsOfTypeClassInProject= (ITypeInfo[]) typeList.toArray(new ITypeInfo[typeList.size()]); - Arrays.sort(elementsOfTypeClassInProject, TYPE_NAME_COMPARATOR); + ICProject cProject= eSelection.getCProject(); + ICElement[] elements= new ICElement[] { cProject }; + final ICSearchScope scope= SearchEngine.createCSearchScope(elements, true); + final int[] kinds= { ICElement.C_CLASS, ICElement.C_STRUCT }; + final Collection typeList= new ArrayList(); + + if (AllTypesCache.isCacheUpToDate()) { + // run without progress monitor + AllTypesCache.getTypes(scope, kinds, null, typeList); + } else { + IRunnableWithProgress runnable= new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + AllTypesCache.getTypes(scope, kinds, monitor, typeList); + if (monitor.isCanceled()) { + throw new InterruptedException(); + } + } + }; + + try { + getContainer().run(true, true, runnable); + } catch (InvocationTargetException e) { + String title= NewWizardMessages.getString("NewClassWizardPage.getProjectClasses.exception.title"); //$NON-NLS-1$ + String message= NewWizardMessages.getString("NewClassWizardPage.getProjectClasses.exception.message"); //$NON-NLS-1$ + ExceptionHandler.handle(e, title, message); + return null; + } catch (InterruptedException e) { + // cancelled by user + return null; + } } - + + if (typeList.isEmpty()) { + elementsOfTypeClassInProject= new ITypeInfo[0]; + } else { + elementsOfTypeClassInProject= (ITypeInfo[]) typeList.toArray(new ITypeInfo[typeList.size()]); + Arrays.sort(elementsOfTypeClassInProject, TYPE_NAME_COMPARATOR); + } + return elementsOfTypeClassInProject; } - protected ITypeInfo chooseBaseClass(){ - ITypeInfo[] elementsFound= findClassElementsInProject(); - if (elementsFound == null || elementsFound.length == 0) { - String title= NewWizardMessages.getString("NewClassWizardPage.getProjectClasses.noclasses.title"); //$NON-NLS-1$ - String message= NewWizardMessages.getString("NewClassWizardPage.getProjectClasses.noclasses.message"); //$NON-NLS-1$ - MessageDialog.openInformation(getShell(), title, message); - return null; - } - - BaseClassSelectionDialog dialog= new BaseClassSelectionDialog(getShell()); - dialog.setElements(elementsFound); - - int result= dialog.open(); - if (result != IDialogConstants.OK_ID) - return null; - - return (ITypeInfo)dialog.getFirstResult(); + protected ITypeInfo chooseBaseClass(){ + ITypeInfo[] elementsFound= findClassElementsInProject(); + if (elementsFound == null || elementsFound.length == 0) { + String title= NewWizardMessages.getString("NewClassWizardPage.getProjectClasses.noclasses.title"); //$NON-NLS-1$ + String message= NewWizardMessages.getString("NewClassWizardPage.getProjectClasses.noclasses.message"); //$NON-NLS-1$ + MessageDialog.openInformation(getShell(), title, message); + return null; + } + + BaseClassSelectionDialog dialog= new BaseClassSelectionDialog(getShell()); + dialog.setElements(elementsFound); + + int result= dialog.open(); + if (result != IDialogConstants.OK_ID) + return null; + + return (ITypeInfo)dialog.getFirstResult(); } // ------------- getter methods for dialog controls ------------- @@ -703,7 +705,6 @@ public class NewClassWizardPage extends WizardPage implements Listener { } catch (CoreException e) { // If the file already existed locally, just refresh to get contents - int code = e.getStatus().getCode(); if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED) fileHandle.refreshLocal(IResource.DEPTH_ZERO, null); else @@ -778,43 +779,43 @@ public class NewClassWizardPage extends WizardPage implements Listener { } return null; } - + // ------------ Constructing File Contents ----------------- - protected String constructHeaderFileContent(ITranslationUnit header, String lineDelimiter){ + protected String constructHeaderFileContent(ITranslationUnit header, String lineDelimiter){ StringBuffer text = new StringBuffer(); boolean extendingBase = false; String baseClassName = getBaseClassName(); String baseClassFileName = ""; //$NON-NLS-1$ - boolean systemIncludePath= false; - + boolean systemIncludePath= false; + if((baseClassName != null) && (baseClassName.length() > 0)) { extendingBase = true; - - ITypeInfo[] classElements = findClassElementsInProject(); - ITypeInfo baseClass = findInList(baseClassName, null, classElements); - - if (baseClass != null) { - IPath projectPath= null; - IPath baseClassPath= null; - ICProject cProject= eSelection.getCProject(); - if (cProject != null) { - projectPath= cProject.getPath(); - baseClassPath= baseClass.resolveIncludePath(cProject); - if (baseClassPath != null && projectPath != null && !projectPath.isPrefixOf(baseClassPath)) { - systemIncludePath= true; - } - } - if (baseClassPath == null) - baseClassPath= resolveRelativePath(baseClass.getPath(), header.getPath(), projectPath); - - if (baseClassPath != null) - baseClassFileName= baseClassPath.toString(); - else - baseClassFileName= baseClass.getFileName(); - } else { + + ITypeInfo[] classElements = findClassElementsInProject(); + ITypeInfo baseClass = findInList(baseClassName, null, classElements); + + if (baseClass != null) { + IPath projectPath= null; + IPath baseClassPath= null; + ICProject cProject= eSelection.getCProject(); + if (cProject != null) { + projectPath= cProject.getPath(); + baseClassPath= baseClass.resolveIncludePath(cProject); + if (baseClassPath != null && projectPath != null && !projectPath.isPrefixOf(baseClassPath)) { + systemIncludePath= true; + } + } + if (baseClassPath == null) + baseClassPath= resolveRelativePath(baseClass.getPath(), header.getPath(), projectPath); + + if (baseClassPath != null) + baseClassFileName= baseClassPath.toString(); + else + baseClassFileName= baseClass.getFileName(); + } else { baseClassFileName = baseClassName + HEADER_EXT; - } + } } if(isIncludeGuard()){ @@ -830,16 +831,16 @@ public class NewClassWizardPage extends WizardPage implements Listener { } if(extendingBase){ - text.append("#include "); //$NON-NLS-1$ - if (systemIncludePath) - text.append('<'); //$NON-NLS-1$ - else - text.append('\"'); //$NON-NLS-1$ + text.append("#include "); //$NON-NLS-1$ + if (systemIncludePath) + text.append('<'); //$NON-NLS-1$ + else + text.append('\"'); //$NON-NLS-1$ text.append(baseClassFileName); - if (systemIncludePath) - text.append('>'); //$NON-NLS-1$ - else - text.append('\"'); //$NON-NLS-1$ + if (systemIncludePath) + text.append('>'); //$NON-NLS-1$ + else + text.append('\"'); //$NON-NLS-1$ text.append(lineDelimiter); text.append(lineDelimiter); } @@ -895,29 +896,29 @@ public class NewClassWizardPage extends WizardPage implements Listener { text.append("_H"); //$NON-NLS-1$ text.append(lineDelimiter); } - + return text.toString(); } + + private IPath resolveRelativePath(IPath baseClassPath, IPath headerPath, IPath projectPath) { + if (baseClassPath == null || headerPath == null || projectPath == null) + return baseClassPath; - private IPath resolveRelativePath(IPath baseClassPath, IPath headerPath, IPath projectPath) { - if (baseClassPath == null || headerPath == null || projectPath == null) - return baseClassPath; - - if (projectPath.isPrefixOf(baseClassPath) && projectPath.isPrefixOf(headerPath)) { - int segments= headerPath.matchingFirstSegments(baseClassPath); - if (segments > 0) { - IPath headerPrefix= headerPath.removeFirstSegments(segments).removeLastSegments(1); - IPath baseClassSuffix= baseClassPath.removeFirstSegments(segments); - IPath relativeBaseClassPath= new Path(""); //$NON-NLS-1$ - for (int i= 0; i < headerPrefix.segmentCount(); ++i) { - relativeBaseClassPath= relativeBaseClassPath.append(".." + IPath.SEPARATOR); //$NON-NLS-1$ - } - return relativeBaseClassPath.append(baseClassSuffix); - } - } - return baseClassPath; - } - + if (projectPath.isPrefixOf(baseClassPath) && projectPath.isPrefixOf(headerPath)) { + int segments= headerPath.matchingFirstSegments(baseClassPath); + if (segments > 0) { + IPath headerPrefix= headerPath.removeFirstSegments(segments).removeLastSegments(1); + IPath baseClassSuffix= baseClassPath.removeFirstSegments(segments); + IPath relativeBaseClassPath= new Path(""); //$NON-NLS-1$ + for (int i= 0; i < headerPrefix.segmentCount(); ++i) { + relativeBaseClassPath= relativeBaseClassPath.append(".." + IPath.SEPARATOR); //$NON-NLS-1$ + } + return relativeBaseClassPath.append(baseClassSuffix); + } + } + return baseClassPath; + } + protected String constructBodyFileContent(String lineDelimiter){ StringBuffer text = new StringBuffer(); text.append("#include \""); //$NON-NLS-1$ @@ -928,7 +929,7 @@ public class NewClassWizardPage extends WizardPage implements Listener { if(isInline()) return text.toString(); - + // constructor text.append(getNewClassName()); text.append("::"); //$NON-NLS-1$ @@ -948,7 +949,7 @@ public class NewClassWizardPage extends WizardPage implements Listener { text.append(lineDelimiter); return text.toString(); } - + // ------ validation -------- protected void doStatusUpdate() { // status of all used components diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index fed13efa717..e58d5d98362 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,9 @@ +2004-04-19 Alain Magloire + + CoreModel throws Exception. + + * src/org/eclipse/cdt/debug/core/CDebugTarget.java + 2004-04-15 Mikhail Khodjaiants Fix for bug 58711: Breakpoint race condition. To avoid race condition all breakpoint marker updates (like increment/decrement the install count, diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java index 1ec9809ee3d..c3145795c51 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.StringTokenizer; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.IBinaryModule; @@ -2027,17 +2028,20 @@ public class CDebugTarget extends CDebugElement private List getCFileGlobals( IParent file ) { ArrayList list = new ArrayList(); - ICElement[] elements = file.getChildren(); - for ( int i = 0; i < elements.length; ++i ) - { - if ( elements[i] instanceof org.eclipse.cdt.core.model.IVariable ) + try { + ICElement[] elements = file.getChildren(); + for ( int i = 0; i < elements.length; ++i ) { - list.add( createGlobalVariable( (org.eclipse.cdt.core.model.IVariable)elements[i] ) ); - } - else if ( elements[i] instanceof org.eclipse.cdt.core.model.IParent ) - { - list.addAll( getCFileGlobals( (org.eclipse.cdt.core.model.IParent)elements[i] ) ); + if ( elements[i] instanceof org.eclipse.cdt.core.model.IVariable ) + { + list.add( createGlobalVariable( (org.eclipse.cdt.core.model.IVariable)elements[i] ) ); + } + else if ( elements[i] instanceof org.eclipse.cdt.core.model.IParent ) + { + list.addAll( getCFileGlobals( (org.eclipse.cdt.core.model.IParent)elements[i] ) ); + } } + } catch (CModelException e) { } return list; } diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CDebugHelper.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CDebugHelper.java index 4b2b22035cb..f6c8ef3a380 100644 --- a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CDebugHelper.java +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CDebugHelper.java @@ -3,6 +3,7 @@ package org.eclipse.cdt.debug.testplugin; import java.io.File; import java.io.IOException; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.debug.core.cdi.ICDISession; @@ -50,7 +51,7 @@ public class CDebugHelper { /** * Creates a ICDISession. */ - public static ICDISession createSession(String exe, ICProject project) throws IOException, MIException { + public static ICDISession createSession(String exe, ICProject project) throws IOException, MIException, CModelException { MIPlugin mi; String workspacePath= Platform.getLocation().toOSString(); ICDISession session; diff --git a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CProjectHelper.java b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CProjectHelper.java index 61bd39a8a8d..18e243f9e0d 100644 --- a/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CProjectHelper.java +++ b/debug/org.eclipse.cdt.debug.ui.tests/src/org/eclipse/cdt/debug/testplugin/CProjectHelper.java @@ -8,6 +8,7 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.core.ICDescriptorOperation; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.IArchive; import org.eclipse.cdt.core.model.IArchiveContainer; import org.eclipse.cdt.core.model.IBinary; @@ -105,7 +106,7 @@ public class CProjectHelper { /** * Attempts to find an archive with the given name in the workspace */ - public static IArchive findArchive(ICProject testProject,String name) { + public static IArchive findArchive(ICProject testProject,String name) throws CModelException { int x; IArchive[] myArchives; IArchiveContainer archCont; @@ -122,7 +123,7 @@ public class CProjectHelper { /** * Attempts to find a binary with the given name in the workspace */ - public static IBinary findBinary(ICProject testProject,String name) { + public static IBinary findBinary(ICProject testProject,String name) throws CModelException { IBinaryContainer binCont; int x; IBinary[] myBinaries; @@ -141,7 +142,7 @@ public class CProjectHelper { /** * Attempts to find an object with the given name in the workspace */ - public static IBinary findObject(ICProject testProject,String name) { + public static IBinary findObject(ICProject testProject,String name) throws CModelException { int x; ICElement[] myElements; myElements=testProject.getChildren(); @@ -149,18 +150,16 @@ public class CProjectHelper { return(null); for (x=0;x