1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Change The Core Model interfaces to throw CModelException when

the fail abnormally.  This forces a lot of try{} catch(){}
bloks and rethrow to be added in the code.
This commit is contained in:
Alain Magloire 2004-04-20 00:06:27 +00:00
parent e2983ad1f8
commit 7ef1a6ed7e
50 changed files with 631 additions and 436 deletions

View file

@ -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 2004-04-19 Andrew Niefer
added parser/CompleteParseASTTest.testBug59149() added parser/CompleteParseASTTest.testBug59149()

View file

@ -15,6 +15,7 @@ import junit.framework.TestSuite;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICDescriptorOperation; 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.IBinary;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
@ -216,7 +217,7 @@ public class BinaryTests extends TestCase {
/*** /***
* A quick check to make sure the getBSS function works as expected. * A quick check to make sure the getBSS function works as expected.
*/ */
public void testGetBss(){ public void testGetBss() throws CModelException{
IBinary bigBinary,littleBinary; IBinary bigBinary,littleBinary;
bigBinary=CProjectHelper.findBinary(testProject, "exebig_g"); bigBinary=CProjectHelper.findBinary(testProject, "exebig_g");
littleBinary=CProjectHelper.findBinary(testProject, "test_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. * A quick check to make sure the getBSS function works as expected.
*/ */
public void testGetData(){ public void testGetData() throws CModelException{
IBinary bigBinary,littleBinary; IBinary bigBinary,littleBinary;
bigBinary=CProjectHelper.findBinary(testProject, "exebig_g"); bigBinary=CProjectHelper.findBinary(testProject, "exebig_g");
littleBinary=CProjectHelper.findBinary(testProject, "test_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) * something sane for the most common exe type (x86) and one other (ppc)
* This is not a in depth test at all. * This is not a in depth test at all.
*/ */
public void testGetCpu() { public void testGetCpu() throws CModelException {
IBinary myBinary; IBinary myBinary;
myBinary=CProjectHelper.findBinary(testProject, "exebig_g"); 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 * A set of simple tests to make sute getNeededSharedLibs seems to be sane
*/ */
public void testGetNeededSharedLibs() { public void testGetNeededSharedLibs() throws CModelException {
IBinary myBinary; IBinary myBinary;
String[] exelibs={"libsocket.so.2", "libc.so.2"}; String[] exelibs={"libsocket.so.2", "libc.so.2"};
String[] bigexelibs={"libc.so.2"}; String[] bigexelibs={"libc.so.2"};
@ -294,7 +295,7 @@ public class BinaryTests extends TestCase {
/**** /****
* Simple tests for the getSoname method; * Simple tests for the getSoname method;
*/ */
public void testGetSoname() { public void testGetSoname() throws CModelException {
IBinary myBinary; IBinary myBinary;
String name; String name;
myBinary=CProjectHelper.findBinary(testProject, "test_g"); myBinary=CProjectHelper.findBinary(testProject, "test_g");
@ -311,7 +312,7 @@ public class BinaryTests extends TestCase {
/*** /***
* Simple tests for getText * Simple tests for getText
*/ */
public void testGetText() { public void testGetText() throws CModelException {
IBinary bigBinary,littleBinary; IBinary bigBinary,littleBinary;
bigBinary=CProjectHelper.findBinary(testProject, bigexe.getLocation().lastSegment()); bigBinary=CProjectHelper.findBinary(testProject, bigexe.getLocation().lastSegment());
littleBinary=CProjectHelper.findBinary(testProject, exefile.getLocation().lastSegment()); littleBinary=CProjectHelper.findBinary(testProject, exefile.getLocation().lastSegment());
@ -323,7 +324,7 @@ public class BinaryTests extends TestCase {
/*** /***
* Simple tests for the hadDebug call * Simple tests for the hadDebug call
*/ */
public void testHasDebug() { public void testHasDebug() throws CModelException {
IBinary myBinary; IBinary myBinary;
myBinary = CProjectHelper.findBinary(testProject, "test_g"); myBinary = CProjectHelper.findBinary(testProject, "test_g");
assertTrue(myBinary.hasDebug()); assertTrue(myBinary.hasDebug());
@ -336,7 +337,7 @@ public class BinaryTests extends TestCase {
/*** /***
* Sanity - isBinary and isReadonly should always return true; * Sanity - isBinary and isReadonly should always return true;
*/ */
public void testisBinRead() { public void testisBinRead() throws CModelException {
IBinary myBinary; IBinary myBinary;
myBinary =CProjectHelper.findBinary(testProject, "test_g"); myBinary =CProjectHelper.findBinary(testProject, "test_g");
assertTrue(myBinary != null); assertTrue(myBinary != null);
@ -347,7 +348,7 @@ public class BinaryTests extends TestCase {
/*** /***
* Quick tests to make sure isObject works as expected. * Quick tests to make sure isObject works as expected.
*/ */
public void testIsObject() { public void testIsObject() throws CModelException {
IBinary myBinary; IBinary myBinary;
myBinary=CProjectHelper.findObject(testProject, "exetest.o"); myBinary=CProjectHelper.findObject(testProject, "exetest.o");
assertTrue(myBinary.isObject()); assertTrue(myBinary.isObject());
@ -367,7 +368,7 @@ public class BinaryTests extends TestCase {
/*** /***
* Quick tests to make sure isSharedLib works as expected. * Quick tests to make sure isSharedLib works as expected.
*/ */
public void testIsSharedLib() { public void testIsSharedLib() throws CModelException {
IBinary myBinary; IBinary myBinary;
myBinary=CProjectHelper.findObject(testProject, "exetest.o"); myBinary=CProjectHelper.findObject(testProject, "exetest.o");
@ -388,7 +389,7 @@ public class BinaryTests extends TestCase {
/*** /***
* Quick tests to make sure isExecutable works as expected. * Quick tests to make sure isExecutable works as expected.
*/ */
public void testIsExecutable() throws InterruptedException { public void testIsExecutable() throws InterruptedException, CModelException {
IBinary myBinary; IBinary myBinary;
myBinary=CProjectHelper.findObject(testProject, "exetest.o"); myBinary=CProjectHelper.findObject(testProject, "exetest.o");
assertTrue(!myBinary.isExecutable()); assertTrue(!myBinary.isExecutable());

View file

@ -18,6 +18,7 @@ import junit.framework.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IEnumeration; import org.eclipse.cdt.core.model.IEnumeration;
@ -85,7 +86,7 @@ public class CModelElementsTests extends TestCase {
CProjectHelper.delete(fCProject); CProjectHelper.delete(fCProject);
} }
public void testCModelElements(){ public void testCModelElements() throws CModelException{
TranslationUnit tu = new TranslationUnit(fCProject, headerFile); TranslationUnit tu = new TranslationUnit(fCProject, headerFile);
// parse the translation unit to get the elements tree // parse the translation unit to get the elements tree
tu.parse(); tu.parse();
@ -119,7 +120,7 @@ public class CModelElementsTests extends TestCase {
checkArrays(tu); checkArrays(tu);
} }
private void checkInclude(IParent tu){ private void checkInclude(IParent tu) throws CModelException{
List tuIncludes = tu.getChildrenOfType(ICElement.C_INCLUDE); List tuIncludes = tu.getChildrenOfType(ICElement.C_INCLUDE);
IInclude inc1 = (IInclude) tuIncludes.get(0); IInclude inc1 = (IInclude) tuIncludes.get(0);
assertEquals(inc1.getElementName(), new String("stdio.h")); assertEquals(inc1.getElementName(), new String("stdio.h"));
@ -127,7 +128,7 @@ public class CModelElementsTests extends TestCase {
checkLineNumbers((CElement)inc1, 2, 2); checkLineNumbers((CElement)inc1, 2, 2);
} }
private void checkMacro(IParent tu){ private void checkMacro(IParent tu) throws CModelException{
List tuMacros = tu.getChildrenOfType(ICElement.C_MACRO); List tuMacros = tu.getChildrenOfType(ICElement.C_MACRO);
IMacro mac1 = (IMacro) tuMacros.get(0); IMacro mac1 = (IMacro) tuMacros.get(0);
assertEquals(mac1.getElementName(), new String("PRINT")); assertEquals(mac1.getElementName(), new String("PRINT"));
@ -135,7 +136,7 @@ public class CModelElementsTests extends TestCase {
checkLineNumbers((CElement)mac1, 5, 5); checkLineNumbers((CElement)mac1, 5, 5);
} }
private void checkClass(IParent namespace){ private void checkClass(IParent namespace) throws CModelException{
// MyPackage ---> class: Hello // MyPackage ---> class: Hello
List nsClasses = namespace.getChildrenOfType(ICElement.C_CLASS); List nsClasses = namespace.getChildrenOfType(ICElement.C_CLASS);
IStructure classHello = (IStructure) nsClasses.get(0); IStructure classHello = (IStructure) nsClasses.get(0);
@ -172,7 +173,7 @@ public class CModelElementsTests extends TestCase {
checkNestedNamespace(classHello); checkNestedNamespace(classHello);
} }
private void checkNestedNamespace(IParent classHello){ private void checkNestedNamespace(IParent classHello) throws CModelException{
// Hello ---> namespace: MyNestedPackage // Hello ---> namespace: MyNestedPackage
List helloNamespaces = classHello.getChildrenOfType(ICElement.C_NAMESPACE); List helloNamespaces = classHello.getChildrenOfType(ICElement.C_NAMESPACE);
INamespace myNestedPackage = (INamespace) helloNamespaces.get(0); INamespace myNestedPackage = (INamespace) helloNamespaces.get(0);
@ -183,7 +184,7 @@ public class CModelElementsTests extends TestCase {
checkParentNestedClass(myNestedPackage); checkParentNestedClass(myNestedPackage);
checkDerivedNestedClass(myNestedPackage); checkDerivedNestedClass(myNestedPackage);
} }
private void checkParentNestedClass(IParent myNestedPackage){ private void checkParentNestedClass(IParent myNestedPackage) throws CModelException{
// MyNestedPackage ---> class: Y // MyNestedPackage ---> class: Y
List nestedClasses = myNestedPackage.getChildrenOfType(ICElement.C_CLASS); List nestedClasses = myNestedPackage.getChildrenOfType(ICElement.C_CLASS);
IStructure classY = (IStructure) nestedClasses.get(0); 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 // MyNestedPackage ---> class: X public Y
List nestedClasses = myNestedPackage.getChildrenOfType(ICElement.C_CLASS); List nestedClasses = myNestedPackage.getChildrenOfType(ICElement.C_CLASS);
IStructure classX = (IStructure) nestedClasses.get(1); IStructure classX = (IStructure) nestedClasses.get(1);
@ -246,7 +247,7 @@ public class CModelElementsTests extends TestCase {
checkLineNumbers((CElement)xDoNothing, 50, 50); checkLineNumbers((CElement)xDoNothing, 50, 50);
} }
private void checkEnums(IParent namespace){ private void checkEnums(IParent namespace) throws CModelException{
// MyPackage ---> enum: Noname // MyPackage ---> enum: Noname
List nsEnums = namespace.getChildrenOfType(ICElement.C_ENUMERATION); List nsEnums = namespace.getChildrenOfType(ICElement.C_ENUMERATION);
IEnumeration enum = (IEnumeration) nsEnums.get(0); IEnumeration enum = (IEnumeration) nsEnums.get(0);
@ -291,7 +292,7 @@ public class CModelElementsTests extends TestCase {
checkElementOffset((CElement)t); checkElementOffset((CElement)t);
} }
private void checkVariables(IParent namespace){ private void checkVariables(IParent namespace) throws CModelException{
// MyPackage ---> int v // MyPackage ---> int v
List nsVars = namespace.getChildrenOfType(ICElement.C_VARIABLE); List nsVars = namespace.getChildrenOfType(ICElement.C_VARIABLE);
IVariable var1 = (IVariable) nsVars.get(0); IVariable var1 = (IVariable) nsVars.get(0);
@ -322,7 +323,7 @@ public class CModelElementsTests extends TestCase {
checkLineNumbers((CElement)vDecl2, 81, 81); checkLineNumbers((CElement)vDecl2, 81, 81);
} }
private void checkVariableDeclarations(IParent namespace){ private void checkVariableDeclarations(IParent namespace) throws CModelException{
// MyPackage ---> extern int evar // MyPackage ---> extern int evar
List nsVarDecls = namespace.getChildrenOfType(ICElement.C_VARIABLE_DECLARATION); List nsVarDecls = namespace.getChildrenOfType(ICElement.C_VARIABLE_DECLARATION);
IVariableDeclaration vDecl1 = (IVariableDeclaration) nsVarDecls.get(0); IVariableDeclaration vDecl1 = (IVariableDeclaration) nsVarDecls.get(0);
@ -332,7 +333,7 @@ public class CModelElementsTests extends TestCase {
checkLineNumbers((CElement)vDecl1, 79, 79); 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); List nsFunctionDeclarations = namespace.getChildrenOfType(ICElement.C_FUNCTION_DECLARATION);
// MyPackage ---> function: void foo() // MyPackage ---> function: void foo()
@ -364,7 +365,7 @@ public class CModelElementsTests extends TestCase {
checkLineNumbers((CElement)f3, 90, 92); checkLineNumbers((CElement)f3, 90, 92);
} }
private void checkStructs(IParent namespace){ private void checkStructs(IParent namespace) throws CModelException{
// struct with name // struct with name
List nsStructs = namespace.getChildrenOfType(ICElement.C_STRUCT); List nsStructs = namespace.getChildrenOfType(ICElement.C_STRUCT);
IStructure struct1 = (IStructure) nsStructs.get(0); IStructure struct1 = (IStructure) nsStructs.get(0);
@ -424,15 +425,15 @@ public class CModelElementsTests extends TestCase {
fail("field visibility should be public!"); fail("field visibility should be public!");
} }
private void checkTemplates(IParent namespace){ private void checkTemplates(IParent namespace) throws CModelException{
// template function // template function
List functionTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_FUNCTION); List functionTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_FUNCTION);
FunctionTemplate ft = (FunctionTemplate)functionTemplates.get(0); FunctionTemplate ft = (FunctionTemplate)functionTemplates.get(0);
assertEquals(ft.getElementName(), new String("aTemplatedFunction")); assertEquals(ft.getElementName(), new String("aTemplatedFunction"));
checkElementOffset((CElement)ft); checkElementOffset(ft);
String sig = ft.getTemplateSignature(); ft.getTemplateSignature();
assertEquals(ft.getTemplateSignature(), new String("aTemplatedFunction<A, B>(B) : A")); assertEquals(ft.getTemplateSignature(), new String("aTemplatedFunction<A, B>(B) : A"));
checkLineNumbers((CElement)ft, 112, 113); checkLineNumbers(ft, 112, 113);
// template method // template method
List nsClasses = namespace.getChildrenOfType(ICElement.C_CLASS); List nsClasses = namespace.getChildrenOfType(ICElement.C_CLASS);
@ -441,26 +442,26 @@ public class CModelElementsTests extends TestCase {
List methodTemplates = enclosingClass.getChildrenOfType(ICElement.C_TEMPLATE_METHOD); List methodTemplates = enclosingClass.getChildrenOfType(ICElement.C_TEMPLATE_METHOD);
MethodTemplate mt = (MethodTemplate)methodTemplates.get(0); MethodTemplate mt = (MethodTemplate)methodTemplates.get(0);
assertEquals(mt.getElementName(), new String("aTemplatedMethod")); assertEquals(mt.getElementName(), new String("aTemplatedMethod"));
checkElementOffset((CElement)mt); checkElementOffset(mt);
assertEquals(mt.getTemplateSignature(), new String("aTemplatedMethod<A, B>(B) : A")); assertEquals(mt.getTemplateSignature(), new String("aTemplatedMethod<A, B>(B) : A"));
checkLineNumbers((CElement)mt, 118, 119 ); checkLineNumbers(mt, 118, 119 );
assertEquals(mt.getVisibility(), ASTAccessVisibility.PUBLIC); assertEquals(mt.getVisibility(), ASTAccessVisibility.PUBLIC);
// template class // template class
List classTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_CLASS); List classTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_CLASS);
StructureTemplate ct = (StructureTemplate)classTemplates.get(0); StructureTemplate ct = (StructureTemplate)classTemplates.get(0);
assertEquals(ct.getElementName(), new String("myarray")); assertEquals(ct.getElementName(), new String("myarray"));
checkElementOffset((CElement)ct); checkElementOffset(ct);
assertEquals(ct.getTemplateSignature(), new String("myarray<T, Tibor>")); assertEquals(ct.getTemplateSignature(), new String("myarray<T, Tibor>"));
checkLineNumbers((CElement)ct, 122, 123); checkLineNumbers(ct, 122, 123);
// template struct // template struct
List structTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_STRUCT); List structTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_STRUCT);
StructureTemplate st = (StructureTemplate)structTemplates.get(0); StructureTemplate st = (StructureTemplate)structTemplates.get(0);
assertEquals(st.getElementName(), new String("mystruct")); assertEquals(st.getElementName(), new String("mystruct"));
checkElementOffset((CElement)st); checkElementOffset(st);
assertEquals(st.getTemplateSignature(), new String("mystruct<T, Tibor>")); assertEquals(st.getTemplateSignature(), new String("mystruct<T, Tibor>"));
checkLineNumbers((CElement)st, 125, 126); checkLineNumbers(st, 125, 126);
// moved to failed tests // moved to failed tests
// also commented in the source file // also commented in the source file
@ -473,7 +474,7 @@ public class CModelElementsTests extends TestCase {
// checkLineNumbers((CElement)vt, 128, 129); // checkLineNumbers((CElement)vt, 128, 129);
} }
private void checkArrays(IParent tu){ private void checkArrays(IParent tu) throws CModelException{
// array variable // array variable
List variables = tu.getChildrenOfType(ICElement.C_VARIABLE); List variables = tu.getChildrenOfType(ICElement.C_VARIABLE);
IVariable arrayVar = (IVariable) variables.get(0); IVariable arrayVar = (IVariable) variables.get(0);

View file

@ -4,6 +4,7 @@
*/ */
package org.eclipse.cdt.core.model.tests; package org.eclipse.cdt.core.model.tests;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IMacro; import org.eclipse.cdt.core.model.IMacro;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
@ -53,7 +54,7 @@ public class IMacroTests extends IntegratedCModelTest {
return "IMacroTest.h"; return "IMacroTest.h";
} }
public void testGetElementName() { public void testGetElementName() throws CModelException {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
List arrayElements = tu.getChildrenOfType( ITranslationUnit.C_MACRO ); 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(); ITranslationUnit tu = getTU();
List arrayElements = tu.getChildrenOfType( ITranslationUnit.C_MACRO ); 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(); ITranslationUnit tu = getTU();
List arrayElements = tu.getChildrenOfType( ITranslationUnit.C_MACRO ); List arrayElements = tu.getChildrenOfType( ITranslationUnit.C_MACRO );

View file

@ -69,7 +69,7 @@ public class IStructureTests extends IntegratedCModelTest {
return suite; return suite;
} }
public void testGetChildrenOfTypeStruct() { public void testGetChildrenOfTypeStruct() throws CModelException {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
List arrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); List arrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT);
String[] myExpectedStructs = { String[] myExpectedStructs = {
@ -84,7 +84,7 @@ public class IStructureTests extends IntegratedCModelTest {
assertEquals(myExpectedStructs[i], myIStruct.getElementName()); assertEquals(myExpectedStructs[i], myIStruct.getElementName());
} }
} }
public void testGetChildrenOfTypeClass() { public void testGetChildrenOfTypeClass() throws CModelException {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
List arrayClasses = tu.getChildrenOfType(ICElement.C_CLASS); List arrayClasses = tu.getChildrenOfType(ICElement.C_CLASS);
String[] myExpectedClasses = { String[] myExpectedClasses = {
@ -98,7 +98,7 @@ public class IStructureTests extends IntegratedCModelTest {
} }
} }
public void testGetFields() { public void testGetFields() throws CModelException {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT);
IStructure myIStruct = (IStructure) myArrayStructs.get(0); IStructure myIStruct = (IStructure) myArrayStructs.get(0);
@ -116,7 +116,7 @@ public class IStructureTests extends IntegratedCModelTest {
} }
// TODO Bug# 38985: remove testGetFieldsHack() // TODO Bug# 38985: remove testGetFieldsHack()
public void testGetFieldsHack() { public void testGetFieldsHack() throws CModelException {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT);
IStructure myIStruct = (IStructure) myArrayStructs.get(0); IStructure myIStruct = (IStructure) myArrayStructs.get(0);
@ -133,7 +133,7 @@ public class IStructureTests extends IntegratedCModelTest {
myExpectedFields[i], myIField.getElementName()); myExpectedFields[i], myIField.getElementName());
} }
} }
public void testGetField() { public void testGetField() throws CModelException {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT);
IStructure myIStruct = (IStructure) myArrayStructs.get(0); IStructure myIStruct = (IStructure) myArrayStructs.get(0);
@ -154,7 +154,7 @@ public class IStructureTests extends IntegratedCModelTest {
assertNull( "Failed on "+i, myIField); assertNull( "Failed on "+i, myIField);
} }
} }
public void testGetMethods() { public void testGetMethods() throws CModelException {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT);
IStructure myIStruct = (IStructure) myArrayStructs.get(0); IStructure myIStruct = (IStructure) myArrayStructs.get(0);
@ -170,7 +170,7 @@ public class IStructureTests extends IntegratedCModelTest {
} }
} }
// TODO Bug# 38985: remove testGetMethodsHack() // TODO Bug# 38985: remove testGetMethodsHack()
public void testGetMethodsHack() { public void testGetMethodsHack() throws CModelException {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT);
IStructure myIStruct = (IStructure) myArrayStructs.get(0); IStructure myIStruct = (IStructure) myArrayStructs.get(0);
@ -187,7 +187,7 @@ public class IStructureTests extends IntegratedCModelTest {
myExpectedMethods[i], myIMethod.getElementName()); myExpectedMethods[i], myIMethod.getElementName());
} }
} }
public void testGetMethod() { public void testGetMethod() throws CModelException {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT);
IStructure myIStruct = (IStructure) myArrayStructs.get(0); IStructure myIStruct = (IStructure) myArrayStructs.get(0);
@ -282,7 +282,7 @@ public class IStructureTests extends IntegratedCModelTest {
assertFalse( myStructNonClass.isClass() ); assertFalse( myStructNonClass.isClass() );
} }
public void testIsAbstract() { public void testIsAbstract() throws CModelException {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
ICElement myElementAbstract = null; ICElement myElementAbstract = null;
ICElement myElementNonAbstract = null; ICElement myElementNonAbstract = null;
@ -394,7 +394,7 @@ public class IStructureTests extends IntegratedCModelTest {
assertEquals( ICElement.C_VARIABLE, myElement.getElementType() ); assertEquals( ICElement.C_VARIABLE, myElement.getElementType() );
} }
public void testInnerStruct() { public void testInnerStruct() throws CModelException {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
ICElement myElement = null; ICElement myElement = null;
try { try {

View file

@ -5,6 +5,7 @@
package org.eclipse.cdt.core.model.tests; package org.eclipse.cdt.core.model.tests;
import org.eclipse.cdt.core.model.*; import org.eclipse.cdt.core.model.*;
import junit.framework.*; import junit.framework.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -56,7 +57,7 @@ public class ITemplateTests extends IntegratedCModelTest {
return suite; return suite;
} }
public List getTemplateMethods(ITranslationUnit tu) public List getTemplateMethods(ITranslationUnit tu) throws CModelException
{ {
IStructure myElem = null; IStructure myElem = null;
try { try {
@ -69,7 +70,7 @@ public class ITemplateTests extends IntegratedCModelTest {
return myElem.getChildrenOfType(ICElement.C_TEMPLATE_METHOD); return myElem.getChildrenOfType(ICElement.C_TEMPLATE_METHOD);
} }
public void testGetChildrenOfTypeTemplate() { public void testGetChildrenOfTypeTemplate() throws CModelException {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
{ {
List arrayElements = tu.getChildrenOfType(ICElement.C_TEMPLATE_STRUCT); 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(); ITranslationUnit tu = getTU();
ArrayList arrayElements = new ArrayList(); ArrayList arrayElements = new ArrayList();
@ -174,7 +175,7 @@ public class ITemplateTests extends IntegratedCModelTest {
myTemplate.getNumberOfTemplateParameters()); myTemplate.getNumberOfTemplateParameters());
} }
} }
public void testGetTemplateParameterTypes() public void testGetTemplateParameterTypes() throws CModelException
{ {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
ArrayList arrayElements = new ArrayList(); ArrayList arrayElements = new ArrayList();
@ -219,7 +220,7 @@ public class ITemplateTests extends IntegratedCModelTest {
} }
} }
} }
public void testGetTemplateSignature() public void testGetTemplateSignature() throws CModelException
{ {
ITranslationUnit tu = getTU(); ITranslationUnit tu = getTU();
ArrayList arrayElements = new ArrayList(); ArrayList arrayElements = new ArrayList();

View file

@ -89,7 +89,7 @@ public class TranslationUnitTests extends TranslationUnitBaseTest {
* Simple sanity tests to make sure TranslationUnit.getChildren seems to * Simple sanity tests to make sure TranslationUnit.getChildren seems to
* basicly work * basicly work
*/ */
public void testGetChildren() { public void testGetChildren() throws CModelException {
ITranslationUnit myTranslationUnit; ITranslationUnit myTranslationUnit;
ICElement[] elements; ICElement[] elements;
int x; int x;
@ -142,7 +142,7 @@ public class TranslationUnitTests extends TranslationUnitBaseTest {
/*** /***
* Simple sanity tests for the getInclude call * Simple sanity tests for the getInclude call
*/ */
public void testBug23478A() { public void testBug23478A() throws CModelException {
IInclude myInclude; IInclude myInclude;
int x; int x;
String includes[]={"stdio.h", "unistd.h"}; String includes[]={"stdio.h", "unistd.h"};

View file

@ -7,6 +7,7 @@ import junit.framework.Assert;
import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature; 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.CoreModel;
import org.eclipse.cdt.core.model.IArchive; import org.eclipse.cdt.core.model.IArchive;
import org.eclipse.cdt.core.model.IArchiveContainer; 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 * 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; int x;
IArchive[] myArchives; IArchive[] myArchives;
IArchiveContainer archCont; IArchiveContainer archCont;
@ -181,7 +182,7 @@ public class CProjectHelper {
/** /**
* Attempts to find a binary with the given name in the workspace * 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; IBinaryContainer binCont;
int x; int x;
IBinary[] myBinaries; IBinary[] myBinaries;
@ -199,7 +200,7 @@ public class CProjectHelper {
/** /**
* Attempts to find an object with the given name in the workspace * 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(); ICElement[] sourceRoots = testProject.getChildren();
for (int i = 0; i < sourceRoots.length; i++) { for (int i = 0; i < sourceRoots.length; i++) {
ISourceRoot root = (ISourceRoot) sourceRoots[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 * 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(); ICElement[] sourceRoots = testProject.getChildren();
for (int i = 0; i < sourceRoots.length; i++) { for (int i = 0; i < sourceRoots.length; i++) {
ISourceRoot root = (ISourceRoot) sourceRoots[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 * 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(); ICElement[] sourceRoots = testProject.getChildren();
for (int i = 0; i < sourceRoots.length; i++) { for (int i = 0; i < sourceRoots.length; i++) {
ISourceRoot root = (ISourceRoot) sourceRoots[i]; ISourceRoot root = (ISourceRoot) sourceRoots[i];

View file

@ -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 2004-04-19 David Inglis
Fixed dead lock - don't fire descriptor events with descriptor lock Fixed dead lock - don't fire descriptor events with descriptor lock

View file

@ -15,6 +15,7 @@ import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import org.eclipse.cdt.core.CCorePlugin; 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.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
@ -226,14 +227,17 @@ public class TypeInfo implements ITypeInfo, Comparable
private ICElement findCElement(ICElement celement, String name) { private ICElement findCElement(ICElement celement, String name) {
if (isValidType(celement.getElementType()) && celement.getElementName().equals(name)) if (isValidType(celement.getElementType()) && celement.getElementName().equals(name))
return celement; return celement;
try {
if (celement instanceof IParent) { if (celement instanceof IParent) {
ICElement[] children = ((IParent)celement).getChildren(); ICElement[] children = ((IParent)celement).getChildren();
for (int i = 0; i < children.length; i++) { for (int i = 0; i < children.length; i++) {
ICElement child= children[i]; ICElement child= children[i];
if (isValidType(child.getElementType()) && child.getElementName().equals(name)) if (isValidType(child.getElementType()) && child.getElementName().equals(name))
return child; return child;
}
} }
} catch (CModelException e) {
} }
return null; return null;
} }

View file

@ -14,5 +14,5 @@ public interface IArchive extends ICElement, IParent, IOpenable {
* Return the binaries contain in the archive. * Return the binaries contain in the archive.
* It does not actually extract the files. * It does not actually extract the files.
*/ */
public IBinary[] getBinaries(); public IBinary[] getBinaries() throws CModelException;
} }

View file

@ -10,5 +10,10 @@ package org.eclipse.cdt.core.model;
* while inspecting the project. * while inspecting the project.
*/ */
public interface IArchiveContainer extends ICElement, IParent, IOpenable { public interface IArchiveContainer extends ICElement, IParent, IOpenable {
public IArchive[] getArchives(); /**
*
* @return
* @throws CModelException
*/
public IArchive[] getArchives() throws CModelException;
} }

View file

@ -11,5 +11,10 @@ package org.eclipse.cdt.core.model;
*/ */
public interface IBinaryContainer extends ICElement, IParent, IOpenable { public interface IBinaryContainer extends ICElement, IParent, IOpenable {
public IBinary[] getBinaries(); /**
*
* @return
* @throws CModelException
*/
public IBinary[] getBinaries() throws CModelException;
} }

View file

@ -9,5 +9,10 @@ package org.eclipse.cdt.core.model;
*/ */
public interface IBinaryModule extends IParent, IBinaryElement { public interface IBinaryModule extends IParent, IBinaryElement {
IBinaryElement[] getBinaryElements(); /**
*
* @return
* @throws CModelException
*/
IBinaryElement[] getBinaryElements() throws CModelException;
} }

View file

@ -170,7 +170,7 @@ public interface ICModel extends ICElement, IParent, IOpenable {
* Returns the C projects. * Returns the C projects.
* *
*/ */
ICProject[] getCProjects(); ICProject[] getCProjects() throws CModelException;
/** /**
* Returns an array of non-C resources (i.e. non-C projects) in * Returns an array of non-C resources (i.e. non-C projects) in

View file

@ -19,12 +19,12 @@ public interface IParent {
* @exception CModelException if this element does not exist or if an * @exception CModelException if this element does not exist or if an
* exception occurs while accessing its corresponding resource * exception occurs while accessing its corresponding resource
*/ */
ICElement[] getChildren(); ICElement[] getChildren() throws CModelException;
/** /**
* returns the children of a certain type * 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. * Returns whether this element has one or more immediate children.
* This is a convenience method, and may be more efficient than * This is a convenience method, and may be more efficient than

View file

@ -11,10 +11,22 @@ package org.eclipse.cdt.core.model;
*/ */
public interface IStructure extends IInheritance, IParent, IVariableDeclaration { public interface IStructure extends IInheritance, IParent, IVariableDeclaration {
public IField getField(String name); public IField getField(String name);
public IField[] getFields();
/**
*
* @return
* @throws CModelException
*/
public IField[] getFields() throws CModelException;
public IMethodDeclaration getMethod(String name); public IMethodDeclaration getMethod(String name);
public IMethodDeclaration [] getMethods();
/**
*
* @return
* @throws CModelException
*/
public IMethodDeclaration [] getMethods() throws CModelException;
public boolean isUnion(); public boolean isUnion();
@ -22,6 +34,11 @@ public interface IStructure extends IInheritance, IParent, IVariableDeclaration
public boolean isStruct(); public boolean isStruct();
public boolean isAbstract(); /**
*
* @return
* @throws CModelException
*/
public boolean isAbstract() throws CModelException;
} }

View file

@ -32,7 +32,7 @@ public class Archive extends Openable implements IArchive {
binaryArchive = ar; binaryArchive = ar;
} }
public IBinary[] getBinaries() { public IBinary[] getBinaries() throws CModelException {
ICElement[] e = getChildren(); ICElement[] e = getChildren();
IBinary[] b = new IBinary[e.length]; IBinary[] b = new IBinary[e.length];
System.arraycopy(e, 0, b, 0, e.length); System.arraycopy(e, 0, b, 0, e.length);

View file

@ -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$ 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(); ((ArchiveContainerInfo)getElementInfo()).sync();
ICElement[] e = getChildren(); ICElement[] e = getChildren();
IArchive[] a = new IArchive[e.length]; IArchive[] a = new IArchive[e.length];

View file

@ -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$ 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(); ((BinaryContainerInfo)getElementInfo()).sync();
ICElement[] e = getChildren(); ICElement[] e = getChildren();
ArrayList list = new ArrayList(e.length); ArrayList list = new ArrayList(e.length);

View file

@ -98,7 +98,7 @@ public class BinaryElement extends CElement implements IBinaryElement, ISourceMa
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ISourceReference#getTranslationUnit() * @see org.eclipse.cdt.core.model.ISourceReference#getTranslationUnit()
*/ */
public ITranslationUnit getTranslationUnit() { public ITranslationUnit getTranslationUnit() {
ITranslationUnit tu = null; ITranslationUnit tu = null;
CModelManager mgr = CModelManager.getDefault(); CModelManager mgr = CModelManager.getDefault();
ICElement parent = getParent(); ICElement parent = getParent();

View file

@ -27,7 +27,7 @@ public class BinaryModule extends Parent implements IBinaryModule {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.model.IBinaryModule#getBinaryElements() * @see org.eclipse.cdt.core.model.IBinaryModule#getBinaryElements()
*/ */
public IBinaryElement[] getBinaryElements() { public IBinaryElement[] getBinaryElements() throws CModelException {
ICElement[] e = getChildren(); ICElement[] e = getChildren();
IBinaryElement[] b = new IBinaryElement[e.length]; IBinaryElement[] b = new IBinaryElement[e.length];
System.arraycopy(e, 0, b, 0, e.length); System.arraycopy(e, 0, b, 0, e.length);

View file

@ -6,6 +6,7 @@ package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; 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.ElementChangedEvent;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModel; import org.eclipse.cdt.core.model.ICModel;
@ -80,18 +81,22 @@ public class BinaryRunner {
void fireEvents(ICProject cproject, Parent container) { void fireEvents(ICProject cproject, Parent container) {
// Fired the event. // Fired the event.
ICElement[] children = container.getChildren(); try {
if (children.length > 0) { ICElement[] children = container.getChildren();
CModelManager factory = CModelManager.getDefault(); if (children.length > 0) {
ICElement root = (ICModel) factory.getCModel(); CModelManager factory = CModelManager.getDefault();
CElementDelta cdelta = new CElementDelta(root); ICElement root = (ICModel) factory.getCModel();
cdelta.added(cproject); CElementDelta cdelta = new CElementDelta(root);
cdelta.added(container); cdelta.added(cproject);
for (int i = 0; i < children.length; i++) { cdelta.added(container);
cdelta.added(children[i]); for (int i = 0; i < children.length; i++) {
cdelta.added(children[i]);
}
factory.registerCModelDelta(cdelta);
factory.fire(ElementChangedEvent.POST_CHANGE);
} }
factory.registerCModelDelta(cdelta); } catch (CModelException e) {
factory.fire(ElementChangedEvent.POST_CHANGE); //
} }
} }

View file

@ -38,7 +38,7 @@ public class CModel extends Openable implements ICModel {
return super.equals(o); return super.equals(o);
} }
public ICProject[] getCProjects() { public ICProject[] getCProjects() throws CModelException {
List list = getChildrenOfType(C_PROJECT); List list = getChildrenOfType(C_PROJECT);
ICProject[] array= new ICProject[list.size()]; ICProject[] array= new ICProject[list.size()];
list.toArray(array); list.toArray(array);

View file

@ -331,7 +331,6 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
IPath rootPath = root.getPath(); IPath rootPath = root.getPath();
IPath resourcePath = file.getFullPath(); IPath resourcePath = file.getFullPath();
IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount()); IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount());
String fileName = path.lastSegment();
path = path.removeLastSegments(1); path = path.removeLastSegments(1);
String[] segments = path.segments(); String[] segments = path.segments();
ICContainer cfolder = root; ICContainer cfolder = root;
@ -427,23 +426,31 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
ArrayList list = new ArrayList(5); ArrayList list = new ArrayList(5);
if (pinfo != null && pinfo.vBin != null) { if (pinfo != null && pinfo.vBin != null) {
if (peekAtInfo(pinfo.vBin) != null) { if (peekAtInfo(pinfo.vBin) != null) {
ICElement[] bins = pinfo.vBin.getChildren(); try {
for (int i = 0; i < bins.length; i++) { ICElement[] bins = pinfo.vBin.getChildren();
if (celement.getPath().isPrefixOf(bins[i].getPath())) { for (int i = 0; i < bins.length; i++) {
//pinfo.vBin.removeChild(bins[i]); if (celement.getPath().isPrefixOf(bins[i].getPath())) {
list.add(bins[i]); //pinfo.vBin.removeChild(bins[i]);
list.add(bins[i]);
}
} }
} catch (CModelException e) {
// ..
} }
} }
} }
if (pinfo != null && pinfo.vLib != null) { if (pinfo != null && pinfo.vLib != null) {
if (peekAtInfo(pinfo.vLib) != null) { if (peekAtInfo(pinfo.vLib) != null) {
ICElement[] ars = pinfo.vLib.getChildren(); try {
for (int i = 0; i < ars.length; i++) { ICElement[] ars = pinfo.vLib.getChildren();
if (celement.getPath().isPrefixOf(ars[i].getPath())) { for (int i = 0; i < ars.length; i++) {
//pinfo.vLib.removeChild(ars[i]); if (celement.getPath().isPrefixOf(ars[i].getPath())) {
list.add(ars[i]); //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()) { switch (resource.getType()) {
case IResource.ROOT : case IResource.ROOT :
if (this.cProjectsCache == null) { if (this.cProjectsCache == null) {
this.cProjectsCache = this.getCModel().getCProjects(); try {
this.cProjectsCache = this.getCModel().getCProjects();
} catch (CModelException e) {
}
} }
IResourceDelta[] children = delta.getAffectedChildren(); IResourceDelta[] children = delta.getAffectedChildren();

View file

@ -5,6 +5,7 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved. * All Rights Reserved.
*/ */
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IStructure; import org.eclipse.cdt.core.model.IStructure;
import org.eclipse.cdt.core.model.ICModelStatus; import org.eclipse.cdt.core.model.ICModelStatus;
@ -44,7 +45,7 @@ public class CreateFieldOperation extends CreateMemberOperation {
*/ */
protected void initializeDefaultPosition() { protected void initializeDefaultPosition() {
IStructure parentElement = getStructure(); IStructure parentElement = getStructure();
//try { try {
ICElement[] elements = parentElement.getFields(); ICElement[] elements = parentElement.getFields();
if (elements != null && elements.length > 0) { if (elements != null && elements.length > 0) {
createAfter(elements[elements.length - 1]); createAfter(elements[elements.length - 1]);
@ -54,8 +55,8 @@ public class CreateFieldOperation extends CreateMemberOperation {
createBefore(elements[0]); createBefore(elements[0]);
} }
} }
//} catch (CModelException e) { } catch (CModelException e) {
//} }
} }
/** /**

View file

@ -184,21 +184,27 @@ public class DeltaProcessor {
CProjectInfo pinfo = (CProjectInfo)factory.peekAtInfo(cproject); CProjectInfo pinfo = (CProjectInfo)factory.peekAtInfo(cproject);
if (pinfo != null && pinfo.vBin != null) { if (pinfo != null && pinfo.vBin != null) {
if (factory.peekAtInfo(pinfo.vBin) != null) { if (factory.peekAtInfo(pinfo.vBin) != null) {
ICElement[] bins = pinfo.vBin.getChildren(); try {
for (int i = 0; i < bins.length; i++) { ICElement[] bins = pinfo.vBin.getChildren();
if (celement.getPath().isPrefixOf(bins[i].getPath())) { for (int i = 0; i < bins.length; i++) {
fCurrentDelta.changed(pinfo.vBin, ICElementDelta.CHANGED); if (celement.getPath().isPrefixOf(bins[i].getPath())) {
fCurrentDelta.changed(pinfo.vBin, ICElementDelta.CHANGED);
}
} }
} catch (CModelException e) {
} }
} }
} }
if (pinfo != null && pinfo.vLib != null) { if (pinfo != null && pinfo.vLib != null) {
if (factory.peekAtInfo(pinfo.vLib) != null) { if (factory.peekAtInfo(pinfo.vLib) != null) {
ICElement[] ars = pinfo.vLib.getChildren(); try {
for (int i = 0; i < ars.length; i++) { ICElement[] ars = pinfo.vLib.getChildren();
if (celement.getPath().isPrefixOf(ars[i].getPath())) { for (int i = 0; i < ars.length; i++) {
fCurrentDelta.changed(pinfo.vBin, ICElementDelta.CHANGED); if (celement.getPath().isPrefixOf(ars[i].getPath())) {
fCurrentDelta.changed(pinfo.vBin, ICElementDelta.CHANGED);
}
} }
} catch (CModelException e) {
} }
} }
} }

View file

@ -8,6 +8,7 @@ package org.eclipse.cdt.internal.core.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
public abstract class Parent extends CElement { 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 * Returns null if the element does not support children
* Implementations override this method to support children * Implementations override this method to support children
*/ */
public ICElement[] getChildren() { public ICElement[] getChildren() throws CModelException {
CElementInfo info = getElementInfo(); CElementInfo info = getElementInfo();
if (info != null) if (info != null)
return info.getChildren(); return info.getChildren();
@ -56,7 +57,7 @@ public abstract class Parent extends CElement {
* @param type * @param type
* @return ArrayList * @return ArrayList
*/ */
public List getChildrenOfType(int type){ public List getChildrenOfType(int type) throws CModelException {
ICElement[] children = getChildren(); ICElement[] children = getChildren();
int size = children.length; int size = children.length;
ArrayList list = new ArrayList(size); ArrayList list = new ArrayList(size);

View file

@ -6,6 +6,7 @@ package org.eclipse.cdt.internal.core.model;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICContainer; import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
@ -26,29 +27,32 @@ public class SourceMapper {
} }
public ITranslationUnit findTranslationUnit(IParent container, String filename) { public ITranslationUnit findTranslationUnit(IParent container, String filename) {
List list = container.getChildrenOfType(ICElement.C_UNIT); try {
for (int i = 0; i < list.size(); i++) { List list = container.getChildrenOfType(ICElement.C_UNIT);
Object o = list.get(i); for (int i = 0; i < list.size(); i++) {
if (o instanceof ITranslationUnit) { Object o = list.get(i);
ITranslationUnit tu = (ITranslationUnit)o; if (o instanceof ITranslationUnit) {
// TODO: What about non case sensitive filesystems. ITranslationUnit tu = (ITranslationUnit)o;
if (filename.equals(tu.getElementName())) { // TODO: What about non case sensitive filesystems.
return tu; if (filename.equals(tu.getElementName())) {
return tu;
}
} }
} }
}
// TODO: This to simple, we are not protected against
// TODO: This to simple, we are not protected against // loop in the file system symbolic links etc ..
// loop in the file system symbolic links etc .. list = container.getChildrenOfType(ICElement.C_CCONTAINER);
list = container.getChildrenOfType(ICElement.C_CCONTAINER); for (int i = 0; i < list.size(); i++) {
for (int i = 0; i < list.size(); i++) { Object o = list.get(i);
Object o = list.get(i); if (o instanceof ICContainer) {
if (o instanceof ICContainer) { ITranslationUnit tu = findTranslationUnit((ICContainer)o, filename);
ITranslationUnit tu = findTranslationUnit((ICContainer)o, filename); if (tu != null) {
if (tu != null) { return tu;
return tu; }
} }
} }
} catch (CModelException e) {
} }
return null; return null;
} }

View file

@ -10,6 +10,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IField; import org.eclipse.cdt.core.model.IField;
import org.eclipse.cdt.core.model.IMethodDeclaration; import org.eclipse.cdt.core.model.IMethodDeclaration;
@ -24,24 +25,27 @@ public class Structure extends SourceManipulation implements IStructure {
super(parent, name, kind); super(parent, name, kind);
} }
public IField[] getFields() { public IField[] getFields() throws CModelException {
List fields = new ArrayList(); List fields = new ArrayList();
fields.addAll(getChildrenOfType(ICElement.C_FIELD)); fields.addAll(getChildrenOfType(ICElement.C_FIELD));
return (IField[]) fields.toArray(new IField[fields.size()]); return (IField[]) fields.toArray(new IField[fields.size()]);
} }
public IField getField(String name) { public IField getField(String name) {
IField[] fields = getFields(); try {
for (int i = 0; i<fields.length; i++){ IField[] fields = getFields();
IField field = fields[i]; for (int i = 0; i<fields.length; i++){
if(field.getElementName().equals(name)){ IField field = fields[i];
return field; if(field.getElementName().equals(name)){
return field;
}
} }
} catch (CModelException e) {
} }
return null; return null;
} }
public IMethodDeclaration[] getMethods() { public IMethodDeclaration[] getMethods() throws CModelException {
List methods = new ArrayList(); List methods = new ArrayList();
methods.addAll(getChildrenOfType(ICElement.C_METHOD_DECLARATION)); methods.addAll(getChildrenOfType(ICElement.C_METHOD_DECLARATION));
methods.addAll(getChildrenOfType(ICElement.C_METHOD)); methods.addAll(getChildrenOfType(ICElement.C_METHOD));
@ -49,12 +53,15 @@ public class Structure extends SourceManipulation implements IStructure {
} }
public IMethodDeclaration getMethod(String name) { public IMethodDeclaration getMethod(String name) {
IMethodDeclaration[] methods = getMethods(); try {
for (int i = 0; i<methods.length; i++){ IMethodDeclaration[] methods = getMethods();
IMethodDeclaration method = methods[i]; for (int i = 0; i<methods.length; i++){
if(method.getElementName().equals(name)){ IMethodDeclaration method = methods[i];
return method; if(method.getElementName().equals(name)){
return method;
}
} }
} catch (CModelException e) {
} }
return null; return null;
} }
@ -71,7 +78,7 @@ public class Structure extends SourceManipulation implements IStructure {
return getStructureInfo().isStruct(); return getStructureInfo().isStruct();
} }
public boolean isAbstract() { public boolean isAbstract() throws CModelException {
IMethodDeclaration[] methods = getMethods(); IMethodDeclaration[] methods = getMethods();
for(int i=0; i<methods.length; i++){ for(int i=0; i<methods.length; i++){
IMethodDeclaration method = methods[i]; IMethodDeclaration method = methods[i];

View file

@ -79,23 +79,29 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
} }
public ICElement getElement(String name ) { public ICElement getElement(String name ) {
ICElement[] celements = getChildren(); try {
for (int i = 0; i < celements.length; i++) { ICElement[] celements = getChildren();
if (name.equals(celements[i].getElementName())) { for (int i = 0; i < celements.length; i++) {
return celements[i]; if (name.equals(celements[i].getElementName())) {
return celements[i];
}
} }
} catch (CModelException e) {
} }
return null; return null;
} }
public IInclude getInclude(String name) { public IInclude getInclude(String name) {
ICElement[] celements = getChildren(); try {
for (int i = 0; i < celements.length; i++) { ICElement[] celements = getChildren();
if (celements[i].getElementType() == ICElement.C_INCLUDE) { for (int i = 0; i < celements.length; i++) {
if (name.equals(celements[i].getElementName())) { if (celements[i].getElementType() == ICElement.C_INCLUDE) {
return (IInclude)celements[i]; if (name.equals(celements[i].getElementName())) {
return (IInclude)celements[i];
}
} }
} }
} catch (CModelException e) {
} }
return null; return null;
} }
@ -112,14 +118,17 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
} }
public IUsing getUsing(String name) { public IUsing getUsing(String name) {
ICElement[] celements = getChildren(); try {
for (int i = 0; i < celements.length; i++) { ICElement[] celements = getChildren();
if (celements[i].getElementType() == ICElement.C_USING) { for (int i = 0; i < celements.length; i++) {
if (name.equals(celements[i].getElementName())) { if (celements[i].getElementType() == ICElement.C_USING) {
return (IUsing)celements[i]; if (name.equals(celements[i].getElementName())) {
return (IUsing)celements[i];
}
} }
} }
} } catch (CModelException e) {
}
return null; return null;
} }
@ -474,10 +483,10 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
* Parse the buffer contents of this element. * Parse the buffer contents of this element.
*/ */
public Map parse(){ public Map parse(){
removeChildren(this);
CModelBuilder modelBuilder = new CModelBuilder(this);
boolean quickParseMode = ! (CCorePlugin.getDefault().useStructuralParseMode());
try { try {
removeChildren(this);
CModelBuilder modelBuilder = new CModelBuilder(this);
boolean quickParseMode = ! (CCorePlugin.getDefault().useStructuralParseMode());
return modelBuilder.parse(quickParseMode); return modelBuilder.parse(quickParseMode);
} catch (Exception e) { } catch (Exception e) {
// use the debug log for this exception. // use the debug log for this exception.
@ -486,7 +495,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
} }
} }
public void removeChildren(ICElement element){ public void removeChildren(ICElement element) throws CModelException{
if (element instanceof Parent){ if (element instanceof Parent){
Parent parent = (Parent) element; Parent parent = (Parent) element;
ICElement[] children = parent.getChildren(); ICElement[] children = parent.getChildren();

View file

@ -15,6 +15,7 @@ import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IMember; import org.eclipse.cdt.core.model.IMember;
@ -61,7 +62,7 @@ public class CSearchScope implements ICSearchScope {
this.enclosingProjects[length] = path; this.enclosingProjects[length] = path;
} }
public void add(ICProject cProject, boolean includesPrereqProjects, HashSet visitedProjects) { public void add(ICProject cProject, boolean includesPrereqProjects, HashSet visitedProjects) throws CModelException {
IProject project = cProject.getProject(); IProject project = cProject.getProject();
if (!project.isAccessible() || !visitedProjects.add(project)) return; if (!project.isAccessible() || !visitedProjects.add(project)) return;
@ -90,7 +91,7 @@ public class CSearchScope implements ICSearchScope {
* @param b * @param b
* @param set * @param set
*/ */
public void add(IProject project, boolean includesPrereqProjects, HashSet visitedProjects) { public void add(IProject project, boolean includesPrereqProjects, HashSet visitedProjects) throws CModelException {
if (!project.isAccessible() || !visitedProjects.add(project)) return; if (!project.isAccessible() || !visitedProjects.add(project)) return;

View file

@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.core.search;
import java.util.HashSet; import java.util.HashSet;
import org.eclipse.cdt.core.CCorePlugin; 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.ICElement;
import org.eclipse.cdt.core.model.ICElementDelta; import org.eclipse.cdt.core.model.ICElementDelta;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -46,9 +47,13 @@ public class CWorkspaceScope extends CSearchScope {
public void initialize() { public void initialize() {
super.initialize(); super.initialize();
try {
IProject[] projects = CCorePlugin.getWorkspace().getRoot().getProjects(); IProject[] projects = CCorePlugin.getWorkspace().getRoot().getProjects();
for (int i = 0, length = projects.length; i < length; i++) for (int i = 0, length = projects.length; i < length; i++)
this.add(projects[i], false, new HashSet(2)); this.add(projects[i], false, new HashSet(2));
} catch (CModelException e) {
// ignore
}
this.needsInitialize = false; this.needsInitialize = false;
} }

View file

@ -1,3 +1,18 @@
2004-04-19 Alain Magloire
The Core Model interfaces now is throwing CModelException
we have to catch them and take appropriate actions.
* refactor/org/eclipse/cdt/internal/corext/refactorin/rename/RenameElementProcessor.java
* src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java
* src/org/eclipse/cdt/internal/ui/CWorkbenchAdapter.java
* src/org/eclipse/cdt/internal/ui/cview/CViewContentProvider.java
* src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathProjectsEntryPage.java
* src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExtendedCPathBasePage.java
* src/org/eclipse/cdt/internal/ui/dialogs/cpaths/IncludesSymbolsTabBlock.java
* src/org/eclipse/cdt/internal/ui/search/CSearchResult.java
* src/org/eclipse/cdt/ui/wizards/NewClasWizardPage.java
2004-04-18 Alain Magloire 2004-04-18 Alain Magloire
First part to move to Eclipse-3.0 new DocumentProvider scheme First part to move to Eclipse-3.0 new DocumentProvider scheme

View file

@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IEnumeration; import org.eclipse.cdt.core.model.IEnumeration;
@ -249,7 +250,7 @@ public class RenameElementProcessor extends RenameProcessor implements IReferenc
* @see org.eclipse.cdt.internal.corext.refactoring.IRefactoringProcessor#checkActivation() * @see org.eclipse.cdt.internal.corext.refactoring.IRefactoringProcessor#checkActivation()
*/ */
public RefactoringStatus checkActivation() throws CoreException { public RefactoringStatus checkActivation() throws CoreException {
RefactoringStatus result= null; //RefactoringStatus result= null;
if (!eligibleForRefactoring(fCElement)) { if (!eligibleForRefactoring(fCElement)) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.getString("RenameTypeRefactoring.wrong_element")); //$NON-NLS-1$ return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.getString("RenameTypeRefactoring.wrong_element")); //$NON-NLS-1$
} }
@ -366,9 +367,9 @@ public class RenameElementProcessor extends RenameProcessor implements IReferenc
ITranslationUnit tu = CModelUtil.toWorkingCopy(cu); ITranslationUnit tu = CModelUtil.toWorkingCopy(cu);
if((tu == null) || (!( tu instanceof ITranslationUnit))) if(tu == null)
return; return;
ITranslationUnit wc = (ITranslationUnit)tu; ITranslationUnit wc = tu;
String name= RefactoringCoreMessages.getString("RenameTypeRefactoring.update_reference"); //$NON-NLS-1$ String name= RefactoringCoreMessages.getString("RenameTypeRefactoring.update_reference"); //$NON-NLS-1$
BasicSearchMatch[] results= fReferences[i].getSearchResults(); BasicSearchMatch[] results= fReferences[i].getSearchResults();
@ -513,16 +514,20 @@ public class RenameElementProcessor extends RenameProcessor implements IReferenc
} }
private RefactoringStatus checkSiblingsCollision() { private RefactoringStatus checkSiblingsCollision() {
RefactoringStatus result= new RefactoringStatus(); RefactoringStatus result= new RefactoringStatus();
// get the siblings of the CElement and check if it has the same name try {
ICElement[] siblings= ((IParent)fCElement.getParent()).getChildren(); // get the siblings of the CElement and check if it has the same name
for (int i = 0; i <siblings.length; ++i ){ ICElement[] siblings= ((IParent)fCElement.getParent()).getChildren();
ICElement sibling = (ICElement)siblings[i]; for (int i = 0; i <siblings.length; ++i ){
if ((sibling.getElementName().equals(fNewElementName)) ICElement sibling = siblings[i];
&& (sibling.getElementType() == fCElement.getElementType()) ) { if ((sibling.getElementName().equals(fNewElementName))
String msg= RefactoringCoreMessages.getFormattedString("RenameTypeRefactoring.member_type_exists", //$NON-NLS-1$ && (sibling.getElementType() == fCElement.getElementType()) ) {
new String[]{fNewElementName, fCElement.getParent().getElementName()}); String msg= RefactoringCoreMessages.getFormattedString("RenameTypeRefactoring.member_type_exists", //$NON-NLS-1$
result.addError(msg); new String[]{fNewElementName, fCElement.getParent().getElementName()});
result.addError(msg);
}
} }
} catch (CModelException e) {
result.addFatalError(e.getMessage());
} }
return result; return result;
} }

View file

@ -123,7 +123,8 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
public Object[] getChildren(Object element) { public Object[] getChildren(Object element) {
if (!exists(element)) if (!exists(element))
return NO_CHILDREN; return NO_CHILDREN;
try {
if (element instanceof ICModel) { if (element instanceof ICModel) {
return getCProjects((ICModel)element); return getCProjects((ICModel)element);
} else if (element instanceof ICProject ) { } else if (element instanceof ICProject ) {
@ -158,6 +159,10 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
} else if (element instanceof IFolder) { } else if (element instanceof IFolder) {
return getResources((IFolder)element); return getResources((IFolder)element);
} }
} catch (CModelException e) {
CUIPlugin.getDefault().log(e);
return NO_CHILDREN;
}
return NO_CHILDREN; return NO_CHILDREN;
} }
@ -189,9 +194,13 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
} }
if (element instanceof IBinaryContainer) { if (element instanceof IBinaryContainer) {
IBinaryContainer cont = (IBinaryContainer)element; try {
IBinary[] bins = getExecutables(cont); IBinaryContainer cont = (IBinaryContainer)element;
return (bins != null) && bins.length > 0; IBinary[] bins = getExecutables(cont);
return (bins != null) && bins.length > 0;
} catch (CModelException e) {
return false;
}
} }
if (element instanceof IParent) { if (element instanceof IParent) {
@ -244,7 +253,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
return parent; return parent;
} }
protected Object[] getCProjects(ICModel cModel) { protected Object[] getCProjects(ICModel cModel) throws CModelException {
Object[] objects = cModel.getCProjects(); Object[] objects = cModel.getCProjects();
try { try {
Object[] nonC = cModel.getNonCResources(); Object[] nonC = cModel.getNonCResources();
@ -257,44 +266,37 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
return objects; return objects;
} }
protected Object[] getSourceRoots(ICProject cproject) { protected Object[] getSourceRoots(ICProject cproject) throws CModelException {
if (!cproject.getProject().isOpen()) if (!cproject.getProject().isOpen())
return NO_CHILDREN; return NO_CHILDREN;
List list= new ArrayList(); List list= new ArrayList();
try { ISourceRoot[] roots = cproject.getSourceRoots();
ISourceRoot[] roots = cproject.getSourceRoots(); // filter out source roots that correspond to projects and
// filter out source roots that correspond to projects and // replace them with the package fragments directly
// replace them with the package fragments directly for (int i= 0; i < roots.length; i++) {
for (int i= 0; i < roots.length; i++) { ISourceRoot root= roots[i];
ISourceRoot root= roots[i]; if (isProjectSourceRoot(root)) {
if (isProjectSourceRoot(root)) { Object[] children= root.getChildren();
Object[] children= root.getChildren(); for (int k= 0; k < children.length; k++) {
for (int k= 0; k < children.length; k++) { list.add(children[k]);
list.add(children[k]);
}
} else {
list.add(root);
} }
} else {
list.add(root);
} }
} catch (CModelException e1) {
} }
Object[] objects = list.toArray(); Object[] objects = list.toArray();
try { Object[] nonC = cproject.getNonCResources();
Object[] nonC = cproject.getNonCResources(); if (nonC != null && nonC.length > 0) {
if (nonC != null && nonC.length > 0) { nonC = filterNonCResources(nonC, cproject);
nonC = filterNonCResources(nonC, cproject); objects = concatenate(objects, nonC);
objects = concatenate(objects, nonC);
}
} catch (CModelException e) {
//
} }
return objects; return objects;
} }
protected Object[] getCResources(ICContainer container) { protected Object[] getCResources(ICContainer container) throws CModelException {
Object[] objects = null; Object[] objects = null;
Object[] children = container.getChildren(); Object[] children = container.getChildren();
try { try {
@ -318,7 +320,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
return NO_CHILDREN; return NO_CHILDREN;
} }
private Object[] getResources(IFolder folder) { private Object[] getResources(IFolder folder) throws CModelException {
ICProject cproject = CoreModel.getDefault().create(folder.getProject()); ICProject cproject = CoreModel.getDefault().create(folder.getProject());
Object[] members = null; Object[] members = null;
try { try {
@ -332,7 +334,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
return filterNonCResources(members, cproject); 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[] binaries = getBinaries(cproject);
ICElement[] archives = getArchives(cproject); ICElement[] archives = getArchives(cproject);
ISourceRoot[] roots = null; ISourceRoot[] roots = null;
@ -410,12 +412,12 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
return true; return true;
} }
protected IBinary[] getExecutables(ICProject cproject) { protected IBinary[] getExecutables(ICProject cproject) throws CModelException {
IBinaryContainer container = cproject.getBinaryContainer(); IBinaryContainer container = cproject.getBinaryContainer();
return getExecutables(container); return getExecutables(container);
} }
protected IBinary[] getExecutables(IBinaryContainer container) { protected IBinary[] getExecutables(IBinaryContainer container) throws CModelException {
ICElement[] celements = container.getChildren(); ICElement[] celements = container.getChildren();
ArrayList list = new ArrayList(celements.length); ArrayList list = new ArrayList(celements.length);
for (int i = 0; i < celements.length; i++) { for (int i = 0; i < celements.length; i++) {
@ -431,12 +433,12 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
return bins; return bins;
} }
protected IBinary[] getBinaries(ICProject cproject) { protected IBinary[] getBinaries(ICProject cproject) throws CModelException {
IBinaryContainer container = cproject.getBinaryContainer(); IBinaryContainer container = cproject.getBinaryContainer();
return getBinaries(container); return getBinaries(container);
} }
protected IBinary[] getBinaries(IBinaryContainer container) { protected IBinary[] getBinaries(IBinaryContainer container) throws CModelException {
ICElement[] celements = container.getChildren(); ICElement[] celements = container.getChildren();
ArrayList list = new ArrayList(celements.length); ArrayList list = new ArrayList(celements.length);
for (int i = 0; i < celements.length; i++) { for (int i = 0; i < celements.length; i++) {
@ -450,12 +452,12 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
return bins; return bins;
} }
protected IArchive[] getArchives(ICProject cproject) { protected IArchive[] getArchives(ICProject cproject) throws CModelException {
IArchiveContainer container = cproject.getArchiveContainer(); IArchiveContainer container = cproject.getArchiveContainer();
return getArchives(container); return getArchives(container);
} }
protected IArchive[] getArchives(IArchiveContainer container) { protected IArchive[] getArchives(IArchiveContainer container) throws CModelException {
ICElement[] celements = container.getChildren(); ICElement[] celements = container.getChildren();
ArrayList list = new ArrayList(celements.length); ArrayList list = new ArrayList(celements.length);
for (int i = 0; i < celements.length; i++) { for (int i = 0; i < celements.length; i++) {

View file

@ -8,9 +8,11 @@ package org.eclipse.cdt.internal.ui;
import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.model.IWorkbenchAdapter; 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.ICElement;
import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.ui.CElementLabelProvider; import org.eclipse.cdt.ui.CElementLabelProvider;
import org.eclipse.cdt.ui.CUIPlugin;
/** /**
* An imlementation of the IWorkbenchAdapter for CElements. * An imlementation of the IWorkbenchAdapter for CElements.
@ -31,9 +33,13 @@ public class CWorkbenchAdapter implements IWorkbenchAdapter {
*/ */
public Object[] getChildren(Object o) { public Object[] getChildren(Object o) {
if (o instanceof IParent) { if (o instanceof IParent) {
Object[] members = ((IParent) o).getChildren(); try {
if (members != null) { Object[] members = ((IParent) o).getChildren();
return members; if (members != null) {
return members;
}
} catch (CModelException e) {
CUIPlugin.getDefault().log(e);
} }
} }
return fgEmptyArray; return fgEmptyArray;

View file

@ -45,18 +45,21 @@ public class CViewContentProvider extends CElementContentProvider {
public Object[] getChildren(Object element) { public Object[] getChildren(Object element) {
Object[] objs = super.getChildren(element); Object[] objs = super.getChildren(element);
Object[] extras = null; Object[] extras = null;
if (element instanceof ICProject) { try {
extras = getProjectChildren((ICProject)element); if (element instanceof ICProject) {
} else if (element instanceof IBinaryContainer) { extras = getProjectChildren((ICProject)element);
extras = getExecutables((IBinaryContainer)element); } else if (element instanceof IBinaryContainer) {
} else if (element instanceof IArchiveContainer) { extras = getExecutables((IBinaryContainer)element);
extras = getArchives((IArchiveContainer)element); } else if (element instanceof IArchiveContainer) {
} else if (element instanceof LibraryRefContainer) { extras = getArchives((IArchiveContainer)element);
extras = ((LibraryRefContainer)element).getChildren(element); } else if (element instanceof LibraryRefContainer) {
} else if (element instanceof IncludeRefContainer) { extras = ((LibraryRefContainer)element).getChildren(element);
extras = ((IncludeRefContainer)element).getChildren(element); } else if (element instanceof IncludeRefContainer) {
extras = ((IncludeRefContainer)element).getChildren(element);
}
} catch (CModelException e) {
extras = null;
} }
if (extras != null && extras.length > 0) { if (extras != null && extras.length > 0) {
objs = concatenate(objs, extras); objs = concatenate(objs, extras);
} }
@ -66,7 +69,7 @@ public class CViewContentProvider extends CElementContentProvider {
/** /**
* @return * @return
*/ */
private Object[] getProjectChildren(ICProject cproject) { private Object[] getProjectChildren(ICProject cproject) throws CModelException {
Object[] extras = null; Object[] extras = null;
IArchiveContainer archive = cproject.getArchiveContainer(); IArchiveContainer archive = cproject.getArchiveContainer();
if (getArchives(archive).length > 0) { if (getArchives(archive).length > 0) {

View file

@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.ui.dialogs.cpaths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICModel; import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IPathEntry; 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.IDialogFieldListener;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil; import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField; 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.resources.IProject;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
@ -111,33 +113,36 @@ public class CPathProjectsEntryPage extends CPathBasePage {
void updateProjectsList(ICProject currCProject) { void updateProjectsList(ICProject currCProject) {
ICModel cmodel = currCProject.getCModel(); ICModel cmodel = currCProject.getCModel();
ICProject[] cprojects = cmodel.getCProjects();
List projects = new ArrayList(cprojects.length); List projects = new ArrayList();
final List checkedProjects = new ArrayList();
// a vector remembering all projects that dont have to be added anymore try {
List existingProjects = new ArrayList(cprojects.length); ICProject[] cprojects = cmodel.getCProjects();
existingProjects.add(currCProject.getProject());
// a vector remembering all projects that dont have to be added anymore
final List checkedProjects = new ArrayList(cprojects.length); List existingProjects = new ArrayList(cprojects.length);
// add the projects-cpentries that are already on the C Path existingProjects.add(currCProject.getProject());
List cpelements = fCPathList.getElements();
for (int i = cpelements.size() - 1; i >= 0; i--) { // add the projects-cpentries that are already on the C Path
CPListElement cpelem = (CPListElement) cpelements.get(i); List cpelements = fCPathList.getElements();
if (isEntryKind(cpelem.getEntryKind())) { for (int i = cpelements.size() - 1; i >= 0; i--) {
existingProjects.add(cpelem.getResource()); CPListElement cpelem = (CPListElement) cpelements.get(i);
projects.add(cpelem); if (isEntryKind(cpelem.getEntryKind())) {
checkedProjects.add(cpelem); existingProjects.add(cpelem.getResource());
projects.add(cpelem);
checkedProjects.add(cpelem);
}
} }
}
for (int i = 0; i < cprojects.length; i++) {
for (int i = 0; i < cprojects.length; i++) { IProject proj = cprojects[i].getProject();
IProject proj = cprojects[i].getProject(); if (!existingProjects.contains(proj)) {
if (!existingProjects.contains(proj)) { projects.add(new CPListElement(fCurrCProject, IPathEntry.CDT_PROJECT, proj.getFullPath(), proj));
projects.add(new CPListElement(fCurrCProject, IPathEntry.CDT_PROJECT, proj.getFullPath(), proj)); }
} }
} catch (CModelException e) {
CUIPlugin.getDefault().log(e);
} }
fProjectsList.setElements(projects); fProjectsList.setElements(projects);
fProjectsList.setCheckedElements(checkedProjects); fProjectsList.setCheckedElements(checkedProjects);
fCurrCProject = currCProject; fCurrCProject = currCProject;

View file

@ -196,7 +196,14 @@ public abstract class ExtendedCPathBasePage extends CPathBasePage {
public void init(ICProject project, List cPaths) { public void init(ICProject project, List cPaths) {
fCurrCProject = project; 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; int i;
for (i = 0; i < list.size(); i++) { for (i = 0; i < list.size(); i++) {
if (((ISourceRoot) list.get(i)).getResource() == project.getProject()) { if (((ISourceRoot) list.get(i)).getResource() == project.getProject()) {

View file

@ -12,12 +12,14 @@ package org.eclipse.cdt.internal.ui.dialogs.cpaths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICContainer; import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; 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.ITreeListAdapter;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.TreeListDialogField; 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.dialogs.Dialog;
import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyEvent;
@ -52,8 +54,12 @@ public class IncludesSymbolsTabBlock extends AbstractPathOptionBlock {
public Object[] getChildren(TreeListDialogField field, Object element) { public Object[] getChildren(TreeListDialogField field, Object element) {
List children = new ArrayList(); List children = new ArrayList();
if (element instanceof ICContainer) { if (element instanceof ICContainer) {
children.addAll(((ICContainer) element).getChildrenOfType(ICElement.C_CCONTAINER)); try {
children.addAll(((ICContainer) element).getChildrenOfType(ICElement.C_UNIT)); 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(); return children.toArray();
} }

View file

@ -11,6 +11,7 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.eclipse.cdt.core.CCorePlugin; 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.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.IParent;
@ -61,10 +62,13 @@ public class CSearchResult extends AbstractTextSearchResult {
} }
if (element instanceof IParent) { if (element instanceof IParent) {
IParent parent= (IParent) element; IParent parent= (IParent) element;
try {
ICElement[] children= parent.getChildren(); ICElement[] children= parent.getChildren();
for (int i= 0; i < children.length; i++) { for (int i= 0; i < children.length; i++) {
collectMatches(matches, children[i]); collectMatches(matches, children[i]);
}
} catch (CModelException e) {
// we will not be tracking these results
} }
} }

View file

@ -415,9 +415,12 @@ public class NewClassWizardPage extends WizardPage implements Listener {
} }
if (elem == null || elem.getElementType() == ICElement.C_MODEL) { if (elem == null || elem.getElementType() == ICElement.C_MODEL) {
ICProject[] projects= CoreModel.create(CUIPlugin.getWorkspace().getRoot()).getCProjects(); try {
if (projects.length == 1) { ICProject[] projects = CoreModel.create(CUIPlugin.getWorkspace().getRoot()).getCProjects();
elem= projects[0]; if (projects.length == 1) {
elem= projects[0];
}
} catch (CModelException e) {
} }
} }
return elem; return elem;
@ -438,7 +441,6 @@ public class NewClassWizardPage extends WizardPage implements Listener {
} }
private IProject getSelectionProject(IStructuredSelection selection) { private IProject getSelectionProject(IStructuredSelection selection) {
IProject project= null;
if (selection != null && !selection.isEmpty()) { if (selection != null && !selection.isEmpty()) {
Object selectedElement= selection.getFirstElement(); Object selectedElement= selection.getFirstElement();
if (selectedElement instanceof IAdaptable) { if (selectedElement instanceof IAdaptable) {
@ -452,74 +454,74 @@ public class NewClassWizardPage extends WizardPage implements Listener {
return null; return null;
} }
private ITypeInfo[] findClassElementsInProject(){ private ITypeInfo[] findClassElementsInProject(){
if(eSelection == null){ if(eSelection == null){
return null; return null;
} }
if( elementsOfTypeClassInProject != null ){ if( elementsOfTypeClassInProject != null ){
return elementsOfTypeClassInProject; 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()) { ICProject cProject= eSelection.getCProject();
elementsOfTypeClassInProject= new ITypeInfo[0]; ICElement[] elements= new ICElement[] { cProject };
} else { final ICSearchScope scope= SearchEngine.createCSearchScope(elements, true);
elementsOfTypeClassInProject= (ITypeInfo[]) typeList.toArray(new ITypeInfo[typeList.size()]); final int[] kinds= { ICElement.C_CLASS, ICElement.C_STRUCT };
Arrays.sort(elementsOfTypeClassInProject, TYPE_NAME_COMPARATOR); 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; return elementsOfTypeClassInProject;
} }
protected ITypeInfo chooseBaseClass(){ protected ITypeInfo chooseBaseClass(){
ITypeInfo[] elementsFound= findClassElementsInProject(); ITypeInfo[] elementsFound= findClassElementsInProject();
if (elementsFound == null || elementsFound.length == 0) { if (elementsFound == null || elementsFound.length == 0) {
String title= NewWizardMessages.getString("NewClassWizardPage.getProjectClasses.noclasses.title"); //$NON-NLS-1$ String title= NewWizardMessages.getString("NewClassWizardPage.getProjectClasses.noclasses.title"); //$NON-NLS-1$
String message= NewWizardMessages.getString("NewClassWizardPage.getProjectClasses.noclasses.message"); //$NON-NLS-1$ String message= NewWizardMessages.getString("NewClassWizardPage.getProjectClasses.noclasses.message"); //$NON-NLS-1$
MessageDialog.openInformation(getShell(), title, message); MessageDialog.openInformation(getShell(), title, message);
return null; return null;
} }
BaseClassSelectionDialog dialog= new BaseClassSelectionDialog(getShell()); BaseClassSelectionDialog dialog= new BaseClassSelectionDialog(getShell());
dialog.setElements(elementsFound); dialog.setElements(elementsFound);
int result= dialog.open(); int result= dialog.open();
if (result != IDialogConstants.OK_ID) if (result != IDialogConstants.OK_ID)
return null; return null;
return (ITypeInfo)dialog.getFirstResult(); return (ITypeInfo)dialog.getFirstResult();
} }
// ------------- getter methods for dialog controls ------------- // ------------- getter methods for dialog controls -------------
@ -703,7 +705,6 @@ public class NewClassWizardPage extends WizardPage implements Listener {
} }
catch (CoreException e) { catch (CoreException e) {
// If the file already existed locally, just refresh to get contents // If the file already existed locally, just refresh to get contents
int code = e.getStatus().getCode();
if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED) if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED)
fileHandle.refreshLocal(IResource.DEPTH_ZERO, null); fileHandle.refreshLocal(IResource.DEPTH_ZERO, null);
else else
@ -778,43 +779,43 @@ public class NewClassWizardPage extends WizardPage implements Listener {
} }
return null; return null;
} }
// ------------ Constructing File Contents ----------------- // ------------ Constructing File Contents -----------------
protected String constructHeaderFileContent(ITranslationUnit header, String lineDelimiter){ protected String constructHeaderFileContent(ITranslationUnit header, String lineDelimiter){
StringBuffer text = new StringBuffer(); StringBuffer text = new StringBuffer();
boolean extendingBase = false; boolean extendingBase = false;
String baseClassName = getBaseClassName(); String baseClassName = getBaseClassName();
String baseClassFileName = ""; //$NON-NLS-1$ String baseClassFileName = ""; //$NON-NLS-1$
boolean systemIncludePath= false; boolean systemIncludePath= false;
if((baseClassName != null) && (baseClassName.length() > 0)) if((baseClassName != null) && (baseClassName.length() > 0))
{ {
extendingBase = true; extendingBase = true;
ITypeInfo[] classElements = findClassElementsInProject(); ITypeInfo[] classElements = findClassElementsInProject();
ITypeInfo baseClass = findInList(baseClassName, null, classElements); ITypeInfo baseClass = findInList(baseClassName, null, classElements);
if (baseClass != null) { if (baseClass != null) {
IPath projectPath= null; IPath projectPath= null;
IPath baseClassPath= null; IPath baseClassPath= null;
ICProject cProject= eSelection.getCProject(); ICProject cProject= eSelection.getCProject();
if (cProject != null) { if (cProject != null) {
projectPath= cProject.getPath(); projectPath= cProject.getPath();
baseClassPath= baseClass.resolveIncludePath(cProject); baseClassPath= baseClass.resolveIncludePath(cProject);
if (baseClassPath != null && projectPath != null && !projectPath.isPrefixOf(baseClassPath)) { if (baseClassPath != null && projectPath != null && !projectPath.isPrefixOf(baseClassPath)) {
systemIncludePath= true; systemIncludePath= true;
} }
} }
if (baseClassPath == null) if (baseClassPath == null)
baseClassPath= resolveRelativePath(baseClass.getPath(), header.getPath(), projectPath); baseClassPath= resolveRelativePath(baseClass.getPath(), header.getPath(), projectPath);
if (baseClassPath != null) if (baseClassPath != null)
baseClassFileName= baseClassPath.toString(); baseClassFileName= baseClassPath.toString();
else else
baseClassFileName= baseClass.getFileName(); baseClassFileName= baseClass.getFileName();
} else { } else {
baseClassFileName = baseClassName + HEADER_EXT; baseClassFileName = baseClassName + HEADER_EXT;
} }
} }
if(isIncludeGuard()){ if(isIncludeGuard()){
@ -830,16 +831,16 @@ public class NewClassWizardPage extends WizardPage implements Listener {
} }
if(extendingBase){ if(extendingBase){
text.append("#include "); //$NON-NLS-1$ text.append("#include "); //$NON-NLS-1$
if (systemIncludePath) if (systemIncludePath)
text.append('<'); //$NON-NLS-1$ text.append('<'); //$NON-NLS-1$
else else
text.append('\"'); //$NON-NLS-1$ text.append('\"'); //$NON-NLS-1$
text.append(baseClassFileName); text.append(baseClassFileName);
if (systemIncludePath) if (systemIncludePath)
text.append('>'); //$NON-NLS-1$ text.append('>'); //$NON-NLS-1$
else else
text.append('\"'); //$NON-NLS-1$ text.append('\"'); //$NON-NLS-1$
text.append(lineDelimiter); text.append(lineDelimiter);
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("_H"); //$NON-NLS-1$
text.append(lineDelimiter); text.append(lineDelimiter);
} }
return text.toString(); 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 (projectPath.isPrefixOf(baseClassPath) && projectPath.isPrefixOf(headerPath)) {
if (baseClassPath == null || headerPath == null || projectPath == null) int segments= headerPath.matchingFirstSegments(baseClassPath);
return baseClassPath; if (segments > 0) {
IPath headerPrefix= headerPath.removeFirstSegments(segments).removeLastSegments(1);
if (projectPath.isPrefixOf(baseClassPath) && projectPath.isPrefixOf(headerPath)) { IPath baseClassSuffix= baseClassPath.removeFirstSegments(segments);
int segments= headerPath.matchingFirstSegments(baseClassPath); IPath relativeBaseClassPath= new Path(""); //$NON-NLS-1$
if (segments > 0) { for (int i= 0; i < headerPrefix.segmentCount(); ++i) {
IPath headerPrefix= headerPath.removeFirstSegments(segments).removeLastSegments(1); relativeBaseClassPath= relativeBaseClassPath.append(".." + IPath.SEPARATOR); //$NON-NLS-1$
IPath baseClassSuffix= baseClassPath.removeFirstSegments(segments); }
IPath relativeBaseClassPath= new Path(""); //$NON-NLS-1$ return relativeBaseClassPath.append(baseClassSuffix);
for (int i= 0; i < headerPrefix.segmentCount(); ++i) { }
relativeBaseClassPath= relativeBaseClassPath.append(".." + IPath.SEPARATOR); //$NON-NLS-1$ }
} return baseClassPath;
return relativeBaseClassPath.append(baseClassSuffix); }
}
}
return baseClassPath;
}
protected String constructBodyFileContent(String lineDelimiter){ protected String constructBodyFileContent(String lineDelimiter){
StringBuffer text = new StringBuffer(); StringBuffer text = new StringBuffer();
text.append("#include \""); //$NON-NLS-1$ text.append("#include \""); //$NON-NLS-1$
@ -928,7 +929,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
if(isInline()) if(isInline())
return text.toString(); return text.toString();
// constructor // constructor
text.append(getNewClassName()); text.append(getNewClassName());
text.append("::"); //$NON-NLS-1$ text.append("::"); //$NON-NLS-1$
@ -948,7 +949,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
text.append(lineDelimiter); text.append(lineDelimiter);
return text.toString(); return text.toString();
} }
// ------ validation -------- // ------ validation --------
protected void doStatusUpdate() { protected void doStatusUpdate() {
// status of all used components // status of all used components

View file

@ -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 2004-04-15 Mikhail Khodjaiants
Fix for bug 58711: Breakpoint race condition. Fix for bug 58711: Breakpoint race condition.
To avoid race condition all breakpoint marker updates (like increment/decrement the install count, To avoid race condition all breakpoint marker updates (like increment/decrement the install count,

View file

@ -11,6 +11,7 @@ import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.eclipse.cdt.core.CCorePlugin; 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.CoreModel;
import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.IBinaryModule; import org.eclipse.cdt.core.model.IBinaryModule;
@ -2027,17 +2028,20 @@ public class CDebugTarget extends CDebugElement
private List getCFileGlobals( IParent file ) private List getCFileGlobals( IParent file )
{ {
ArrayList list = new ArrayList(); ArrayList list = new ArrayList();
ICElement[] elements = file.getChildren(); try {
for ( int i = 0; i < elements.length; ++i ) ICElement[] elements = file.getChildren();
{ for ( int i = 0; i < elements.length; ++i )
if ( elements[i] instanceof org.eclipse.cdt.core.model.IVariable )
{ {
list.add( createGlobalVariable( (org.eclipse.cdt.core.model.IVariable)elements[i] ) ); if ( elements[i] instanceof org.eclipse.cdt.core.model.IVariable )
} {
else if ( elements[i] instanceof org.eclipse.cdt.core.model.IParent ) list.add( createGlobalVariable( (org.eclipse.cdt.core.model.IVariable)elements[i] ) );
{ }
list.addAll( getCFileGlobals( (org.eclipse.cdt.core.model.IParent)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; return list;
} }

View file

@ -3,6 +3,7 @@ package org.eclipse.cdt.debug.testplugin;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.debug.core.cdi.ICDISession; import org.eclipse.cdt.debug.core.cdi.ICDISession;
@ -50,7 +51,7 @@ public class CDebugHelper {
/** /**
* Creates a ICDISession. * 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; MIPlugin mi;
String workspacePath= Platform.getLocation().toOSString(); String workspacePath= Platform.getLocation().toOSString();
ICDISession session; ICDISession session;

View file

@ -8,6 +8,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICDescriptorOperation; 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.IArchive;
import org.eclipse.cdt.core.model.IArchiveContainer; import org.eclipse.cdt.core.model.IArchiveContainer;
import org.eclipse.cdt.core.model.IBinary; 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 * 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; int x;
IArchive[] myArchives; IArchive[] myArchives;
IArchiveContainer archCont; IArchiveContainer archCont;
@ -122,7 +123,7 @@ public class CProjectHelper {
/** /**
* Attempts to find a binary with the given name in the workspace * 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; IBinaryContainer binCont;
int x; int x;
IBinary[] myBinaries; IBinary[] myBinaries;
@ -141,7 +142,7 @@ public class CProjectHelper {
/** /**
* Attempts to find an object with the given name in the workspace * 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; int x;
ICElement[] myElements; ICElement[] myElements;
myElements=testProject.getChildren(); myElements=testProject.getChildren();
@ -149,18 +150,16 @@ public class CProjectHelper {
return(null); return(null);
for (x=0;x<myElements.length;x++) { for (x=0;x<myElements.length;x++) {
if (myElements[x].getElementName().equals(name)) if (myElements[x].getElementName().equals(name))
if (myElements[x] instanceof ICElement) { if (myElements[x] instanceof IBinary) {
if (myElements[x] instanceof IBinary) { return((IBinary) myElements[x]);
return((IBinary) myElements[x]); }
}
}
} }
return(null); return(null);
} }
/** /**
* Attempts to find a TranslationUnit with the given name in the workspace * 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 {
int x; int x;
ICElement[] myElements; ICElement[] myElements;
myElements=testProject.getChildren(); myElements=testProject.getChildren();
@ -168,11 +167,9 @@ public class CProjectHelper {
return(null); return(null);
for (x=0;x<myElements.length;x++) { for (x=0;x<myElements.length;x++) {
if (myElements[x].getElementName().equals(name)) if (myElements[x].getElementName().equals(name))
if (myElements[x] instanceof ICElement) { if (myElements[x] instanceof ITranslationUnit) {
if (myElements[x] instanceof ITranslationUnit) { return((ITranslationUnit) myElements[x]);
return((ITranslationUnit) myElements[x]); }
}
}
} }
return(null); return(null);
} }
@ -182,7 +179,7 @@ public class CProjectHelper {
/** /**
* Attempts to find an element with the given name in the workspace * 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 {
int x; int x;
ICElement[] myElements; ICElement[] myElements;
myElements=testProject.getChildren(); myElements=testProject.getChildren();
@ -190,11 +187,7 @@ public class CProjectHelper {
return(null); return(null);
for (x=0;x<myElements.length;x++) { for (x=0;x<myElements.length;x++) {
if (myElements[x].getElementName().equals(name)) if (myElements[x].getElementName().equals(name))
if (myElements[x] instanceof ICElement) { return myElements[x];
return((ICElement) myElements[x]);
}
} }
return(null); return(null);
} }

View file

@ -1,3 +1,9 @@
2004-04-19 Alain Magloire
Core Model interface throws Exception
* src/org/eclipse/cdt/launch/internal/CApplicationLaunchShortcut.java
* sr/org/eclipse/cdt/launch/ui/CMaintab.java
2004-04-06 Mikhail Khodjaiants 2004-04-06 Mikhail Khodjaiants
Do not remove debugger process from launch. Do not remove debugger process from launch.

View file

@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
@ -351,12 +352,15 @@ public class CApplicationLaunchShortcut implements ILaunchShortcut, ILaunchFilte
if (r != null) { if (r != null) {
ICProject cproject = CoreModel.getDefault().create(r.getProject()); ICProject cproject = CoreModel.getDefault().create(r.getProject());
if (cproject != null) { if (cproject != null) {
IBinary[] bins = cproject.getBinaryContainer().getBinaries(); try {
IBinary[] bins = cproject.getBinaryContainer().getBinaries();
for (int j = 0; j < bins.length; j++) { for (int j = 0; j < bins.length; j++) {
if (bins[j].isExecutable()) { if (bins[j].isExecutable()) {
results.add(bins[j]); results.add(bins[j]);
}
} }
} catch (CModelException e) {
} }
} }
} }

View file

@ -9,6 +9,7 @@ import java.util.ArrayList;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
@ -360,7 +361,11 @@ public class CMainTab extends CLaunchConfigurationTab {
final Object[] ret = new Object[1]; final Object[] ret = new Object[1];
BusyIndicator.showWhile(display, new Runnable() { BusyIndicator.showWhile(display, new Runnable() {
public void run() { public void run() {
ret[0] = cproject.getBinaryContainer().getBinaries(); try {
ret[0] = cproject.getBinaryContainer().getBinaries();
} catch (CModelException e) {
LaunchUIPlugin.errorDialog("Launch UI internal error", e); //$NON-NLS-1$
}
} }
}); });
@ -387,21 +392,24 @@ public class CMainTab extends CLaunchConfigurationTab {
* or null if there was none. * or null if there was none.
*/ */
protected ICProject chooseCProject() { protected ICProject chooseCProject() {
ICProject[] projects; try {
projects = getCProjects(); ICProject[] projects = getCProjects();
ILabelProvider labelProvider = new CElementLabelProvider(); ILabelProvider labelProvider = new CElementLabelProvider();
ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider); ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider);
dialog.setTitle(LaunchUIPlugin.getResourceString("CMainTab.Project_Selection")); //$NON-NLS-1$ dialog.setTitle(LaunchUIPlugin.getResourceString("CMainTab.Project_Selection")); //$NON-NLS-1$
dialog.setMessage(LaunchUIPlugin.getResourceString("CMainTab.Choose_project_to_constrain_search_for_program")); //$NON-NLS-1$ dialog.setMessage(LaunchUIPlugin.getResourceString("CMainTab.Choose_project_to_constrain_search_for_program")); //$NON-NLS-1$
dialog.setElements(projects); dialog.setElements(projects);
ICProject cProject = getCProject(); ICProject cProject = getCProject();
if (cProject != null) { if (cProject != null) {
dialog.setInitialSelections(new Object[] { cProject }); dialog.setInitialSelections(new Object[] { cProject });
} }
if (dialog.open() == ElementListSelectionDialog.OK) { if (dialog.open() == ElementListSelectionDialog.OK) {
return (ICProject) dialog.getFirstResult(); return (ICProject) dialog.getFirstResult();
}
} catch (CModelException e) {
LaunchUIPlugin.errorDialog("Launch UI internal error", e); //$NON-NLS-1$
} }
return null; return null;
} }
@ -410,7 +418,7 @@ public class CMainTab extends CLaunchConfigurationTab {
* Return an array a ICProject whose platform match that of the runtime env. * Return an array a ICProject whose platform match that of the runtime env.
**/ **/
protected ICProject[] getCProjects() { protected ICProject[] getCProjects() throws CModelException {
ICProject cproject[] = CoreModel.getDefault().getCModel().getCProjects(); ICProject cproject[] = CoreModel.getDefault().getCModel().getCProjects();
ArrayList list = new ArrayList(cproject.length); ArrayList list = new ArrayList(cproject.length);
boolean isNative = filterPlatform.equals(BootLoader.getOS()); boolean isNative = filterPlatform.equals(BootLoader.getOS());