From 24b55c3712c4fc22918a01d42df767f32510ce3c Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Thu, 18 Mar 2004 05:42:51 +0000 Subject: [PATCH] Change in the hierarchy of the core Model: ICModel ICProject ISourceRoot IBinary IArchive ITranslatioUnit ICContainer The ISourceRoot been added to better separate the files. By default the entire project is the SourceRoot. --- core/org.eclipse.cdt.core.tests/ChangeLog | 24 + .../core/model/tests/CModelElementsTests.java | 68 +- .../cdt/core/model/tests/CPathEntryTest.java | 17 +- .../core/model/tests/ElementDeltaTests.java | 16 +- .../cdt/core/model/tests/IMacroTests.java | 8 +- .../cdt/core/model/tests/IStructureTests.java | 24 +- .../cdt/core/model/tests/ITemplateTests.java | 13 +- .../model/tests/TranslationUnitBaseTest.java | 2 - .../cdt/testplugin/CProjectHelper.java | 85 +- core/org.eclipse.cdt.core/ChangeLog | 27 + .../org/eclipse/cdt/core/model/CoreModel.java | 162 ++-- .../eclipse/cdt/core/model/ICContainer.java | 81 +- .../org/eclipse/cdt/core/model/ICProject.java | 47 +- .../eclipse/cdt/core/model/IIncludeEntry.java | 7 - .../eclipse/cdt/core/model/IMacroEntry.java | 6 - .../eclipse/cdt/core/model/IOutputEntry.java | 35 + .../org/eclipse/cdt/core/model/IParent.java | 4 +- .../eclipse/cdt/core/model/ISourceEntry.java | 16 +- .../eclipse/cdt/core/model/ISourceRoot.java | 33 + .../cdt/internal/core/model/APathEntry.java | 29 +- .../cdt/internal/core/model/Binary.java | 87 +- .../internal/core/model/BinaryElement.java | 2 +- .../cdt/internal/core/model/BinaryRunner.java | 78 +- .../cdt/internal/core/model/CContainer.java | 182 ++++- .../internal/core/model/CContainerInfo.java | 37 +- .../cdt/internal/core/model/CElement.java | 2 +- .../cdt/internal/core/model/CModel.java | 77 +- .../cdt/internal/core/model/CModelInfo.java | 7 +- .../internal/core/model/CModelManager.java | 229 ++++-- .../cdt/internal/core/model/CProject.java | 169 +++- .../cdt/internal/core/model/CProjectInfo.java | 69 ++ .../model/CopyResourceElementsOperation.java | 2 +- .../internal/core/model/DeltaProcessor.java | 117 ++- .../cdt/internal/core/model/IncludeEntry.java | 7 +- .../core/model/LibraryReferenceShared.java | 4 +- .../cdt/internal/core/model/MacroEntry.java | 5 +- .../cdt/internal/core/model/OutputEntry.java | 50 ++ .../cdt/internal/core/model/Parent.java | 3 +- .../cdt/internal/core/model/PathEntry.java | 10 +- .../internal/core/model/PathEntryManager.java | 205 +++-- .../cdt/internal/core/model/SourceEntry.java | 25 +- .../cdt/internal/core/model/SourceMapper.java | 7 +- .../cdt/internal/core/model/SourceRoot.java | 83 ++ .../eclipse/cdt/internal/core/model/Util.java | 756 ++++++++++++++---- core/org.eclipse.cdt.ui/ChangeLog | 18 + .../ui/BaseCElementContentProvider.java | 188 +++-- .../internal/ui/CElementImageProvider.java | 20 +- .../cdt/internal/ui/CPluginImages.java | 4 +- .../cdt/ui/CElementContentProvider.java | 126 +-- 49 files changed, 2355 insertions(+), 918 deletions(-) create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IOutputEntry.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ISourceRoot.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/OutputEntry.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceRoot.java diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index ba53c715a13..af0f24d138c 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,27 @@ +2004-03-18 Alain Magloire + + Change in the hierarchy of the core Model: + ICModel + ICProject + ISourceRoot + IBinary + IArchive + ITranslatioUnit + ICContainer + The ISourceRoot been added to better separate + the files. By default the entire project is the + SourceRoot. + + * model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java + * model/org/eclipse/cdt/core/model/tests/CPathEntryTest.java + * model/org/eclipse/cdt/core/model/tests/ElementDeltaTests.java + * model/org/eclipse/cdt/core/model/tests/IMacroTests.java + * model/org/eclipse/cdt/core/model/tests/IStructureTests.java + * model/org/eclipse/cdt/core/model/tests/ITemplateTests.java + * model/org/eclipse/cdt/core/model/tests/TranslationUnitBaseTests.java + + * suite/org/eclipse/cdt/testplugin/CProjectHelper.java + 2003-03-16 Andrew Niefer added CompleteParseASTTest.testBug55163 diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java index 47ab4335032..fb337655652 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java @@ -12,7 +12,7 @@ package org.eclipse.cdt.core.model.tests; ***********************************************************************/ import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.util.ArrayList; +import java.util.List; import junit.framework.Test; import junit.framework.TestCase; @@ -97,7 +97,7 @@ public class CModelElementsTests extends TestCase { checkMacro(tu); // tu ---> namespace: MyPackage - ArrayList tuPackages = tu.getChildrenOfType(ICElement.C_NAMESPACE); + List tuPackages = tu.getChildrenOfType(ICElement.C_NAMESPACE); INamespace namespace = (INamespace) tuPackages.get(0); assertEquals(namespace.getElementName(), new String("MyPackage")); checkElementOffset((CElement)namespace); @@ -120,7 +120,7 @@ public class CModelElementsTests extends TestCase { } private void checkInclude(IParent tu){ - ArrayList tuIncludes = tu.getChildrenOfType(ICElement.C_INCLUDE); + List tuIncludes = tu.getChildrenOfType(ICElement.C_INCLUDE); IInclude inc1 = (IInclude) tuIncludes.get(0); assertEquals(inc1.getElementName(), new String("stdio.h")); checkElementOffset((CElement)inc1); @@ -128,7 +128,7 @@ public class CModelElementsTests extends TestCase { } private void checkMacro(IParent tu){ - ArrayList tuMacros = tu.getChildrenOfType(ICElement.C_MACRO); + List tuMacros = tu.getChildrenOfType(ICElement.C_MACRO); IMacro mac1 = (IMacro) tuMacros.get(0); assertEquals(mac1.getElementName(), new String("PRINT")); checkElementOffset((CElement)mac1); @@ -137,14 +137,14 @@ public class CModelElementsTests extends TestCase { private void checkClass(IParent namespace){ // MyPackage ---> class: Hello - ArrayList nsClasses = namespace.getChildrenOfType(ICElement.C_CLASS); + List nsClasses = namespace.getChildrenOfType(ICElement.C_CLASS); IStructure classHello = (IStructure) nsClasses.get(0); assertEquals(classHello.getElementName(), new String("Hello")); checkElementOffset((CElement)classHello); checkLineNumbers((CElement)classHello, 12, 53); // Hello --> field: int x - ArrayList helloFields = classHello.getChildrenOfType(ICElement.C_FIELD); + List helloFields = classHello.getChildrenOfType(ICElement.C_FIELD); IField intX = (IField) helloFields.get(0); assertEquals(intX.getElementName(), new String("x")); checkElementOffset((CElement)intX); @@ -156,7 +156,7 @@ public class CModelElementsTests extends TestCase { fail("visibility should be protected!"); // Hello ---> method: void setX(int X) - ArrayList helloMethods = classHello.getChildrenOfType(ICElement.C_METHOD); + List helloMethods = classHello.getChildrenOfType(ICElement.C_METHOD); IMethod setX = (IMethod) helloMethods.get(0); assertEquals(setX.getElementName(), new String("setX")); checkElementOffset((CElement)setX); @@ -174,7 +174,7 @@ public class CModelElementsTests extends TestCase { } private void checkNestedNamespace(IParent classHello){ // Hello ---> namespace: MyNestedPackage - ArrayList helloNamespaces = classHello.getChildrenOfType(ICElement.C_NAMESPACE); + List helloNamespaces = classHello.getChildrenOfType(ICElement.C_NAMESPACE); INamespace myNestedPackage = (INamespace) helloNamespaces.get(0); assertEquals(myNestedPackage.getElementName(), new String("MyNestedPackage")); checkElementOffset((CElement)myNestedPackage); @@ -185,14 +185,14 @@ public class CModelElementsTests extends TestCase { } private void checkParentNestedClass(IParent myNestedPackage){ // MyNestedPackage ---> class: Y - ArrayList nestedClasses = myNestedPackage.getChildrenOfType(ICElement.C_CLASS); + List nestedClasses = myNestedPackage.getChildrenOfType(ICElement.C_CLASS); IStructure classY = (IStructure) nestedClasses.get(0); assertEquals(classY.getElementName(), new String("Y")); checkElementOffset((CElement)classY); checkLineNumbers((CElement)classY, 28, 35); // Y ---> constructor: Y - ArrayList yMethods = classY.getChildrenOfType(ICElement.C_METHOD_DECLARATION); + List yMethods = classY.getChildrenOfType(ICElement.C_METHOD_DECLARATION); IMethodDeclaration constructor = (IMethodDeclaration) yMethods.get(0); assertEquals(constructor.getElementName(), new String("Y")); checkElementOffset((CElement)constructor); @@ -211,7 +211,7 @@ public class CModelElementsTests extends TestCase { private void checkDerivedNestedClass(IParent myNestedPackage){ // MyNestedPackage ---> class: X public Y - ArrayList nestedClasses = myNestedPackage.getChildrenOfType(ICElement.C_CLASS); + List nestedClasses = myNestedPackage.getChildrenOfType(ICElement.C_CLASS); IStructure classX = (IStructure) nestedClasses.get(1); assertEquals(classX.getElementName(), new String("X")); checkElementOffset((CElement)classX); @@ -219,7 +219,7 @@ public class CModelElementsTests extends TestCase { // TODO : Check for base classes here // X --> field: B b - ArrayList xFieldChildren = classX.getChildrenOfType(ICElement.C_FIELD); + List xFieldChildren = classX.getChildrenOfType(ICElement.C_FIELD); IField bB = (IField) xFieldChildren.get(0); assertEquals(bB.getElementName(), new String("b")); checkElementOffset((CElement)bB); @@ -230,7 +230,7 @@ public class CModelElementsTests extends TestCase { fail("visibility should be private!"); // X ---> constructor chain: X - ArrayList xMethodChildren = classX.getChildrenOfType(ICElement.C_METHOD); + List xMethodChildren = classX.getChildrenOfType(ICElement.C_METHOD); IMethod xconstructor = (IMethod) xMethodChildren.get(0); assertEquals(xconstructor.getElementName(), new String("X")); checkElementOffset((CElement)xconstructor); @@ -238,7 +238,7 @@ public class CModelElementsTests extends TestCase { checkLineNumbers((CElement)xconstructor, 46, 48); // X ---> method declaration: doNothing - ArrayList xMethodDeclarations = classX.getChildrenOfType(ICElement.C_METHOD_DECLARATION); + List xMethodDeclarations = classX.getChildrenOfType(ICElement.C_METHOD_DECLARATION); IMethodDeclaration xDoNothing = (IMethodDeclaration) xMethodDeclarations.get(0); assertEquals(xDoNothing.getElementName(), new String("doNothing")); checkElementOffset((CElement)xDoNothing); @@ -248,14 +248,14 @@ public class CModelElementsTests extends TestCase { private void checkEnums(IParent namespace){ // MyPackage ---> enum: Noname - ArrayList nsEnums = namespace.getChildrenOfType(ICElement.C_ENUMERATION); + List nsEnums = namespace.getChildrenOfType(ICElement.C_ENUMERATION); IEnumeration enum = (IEnumeration) nsEnums.get(0); assertEquals(enum.getElementName(), new String("")); checkElementOffset((CElement)enum); checkLineNumbers((CElement)enum, 57, 61); // enum ---> enumerator: first = 1 - ArrayList enumEnumerators = enum.getChildrenOfType(ICElement.C_ENUMERATOR); + List enumEnumerators = enum.getChildrenOfType(ICElement.C_ENUMERATOR); IEnumerator first = (IEnumerator) enumEnumerators.get(0); assertEquals(first.getElementName(), new String("first")); assertEquals("1", first.getConstantExpression()); @@ -277,7 +277,7 @@ public class CModelElementsTests extends TestCase { checkLineNumbers((CElement)myEnum, 64, 67); // enum ---> enumerator: first - ArrayList myEnumEnumerators = myEnum.getChildrenOfType(ICElement.C_ENUMERATOR); + List myEnumEnumerators = myEnum.getChildrenOfType(ICElement.C_ENUMERATOR); IEnumerator f = (IEnumerator) myEnumEnumerators.get(0); assertEquals(f.getElementName(), new String("f")); checkElementOffset((CElement)f); @@ -293,7 +293,7 @@ public class CModelElementsTests extends TestCase { private void checkVariables(IParent namespace){ // MyPackage ---> int v - ArrayList nsVars = namespace.getChildrenOfType(ICElement.C_VARIABLE); + List nsVars = namespace.getChildrenOfType(ICElement.C_VARIABLE); IVariable var1 = (IVariable) nsVars.get(0); assertEquals(var1.getElementName(), new String("v")); checkElementOffset((CElement)var1); @@ -324,7 +324,7 @@ public class CModelElementsTests extends TestCase { private void checkVariableDeclarations(IParent namespace){ // MyPackage ---> extern int evar - ArrayList nsVarDecls = namespace.getChildrenOfType(ICElement.C_VARIABLE_DECLARATION); + List nsVarDecls = namespace.getChildrenOfType(ICElement.C_VARIABLE_DECLARATION); IVariableDeclaration vDecl1 = (IVariableDeclaration) nsVarDecls.get(0); assertEquals(vDecl1.getElementName(), new String("evar")); checkElementOffset((CElement)vDecl1); @@ -333,7 +333,7 @@ public class CModelElementsTests extends TestCase { } private void checkFunctions(IParent namespace){ - ArrayList nsFunctionDeclarations = namespace.getChildrenOfType(ICElement.C_FUNCTION_DECLARATION); + List nsFunctionDeclarations = namespace.getChildrenOfType(ICElement.C_FUNCTION_DECLARATION); // MyPackage ---> function: void foo() IFunctionDeclaration f1 = (IFunctionDeclaration) nsFunctionDeclarations.get(0); @@ -356,7 +356,7 @@ public class CModelElementsTests extends TestCase { assertEquals(paramTypes[1], new String("char**")); // MyPackage ---> function: void boo() {} - ArrayList nsFunctions = namespace.getChildrenOfType(ICElement.C_FUNCTION); + List nsFunctions = namespace.getChildrenOfType(ICElement.C_FUNCTION); IFunction f3 = (IFunction) nsFunctions.get(0); assertEquals(f3.getElementName(), new String("boo")); checkElementOffset((CElement)f3); @@ -366,12 +366,12 @@ public class CModelElementsTests extends TestCase { private void checkStructs(IParent namespace){ // struct with name - ArrayList nsStructs = namespace.getChildrenOfType(ICElement.C_STRUCT); + List nsStructs = namespace.getChildrenOfType(ICElement.C_STRUCT); IStructure struct1 = (IStructure) nsStructs.get(0); assertEquals(struct1.getElementName(), new String ("MyStruct")); checkElementOffset((CElement)struct1); checkLineNumbers((CElement)struct1, 95, 97); - ArrayList struct1Fields = struct1.getChildrenOfType(ICElement.C_FIELD); + List struct1Fields = struct1.getChildrenOfType(ICElement.C_FIELD); IField field1 = (IField) struct1Fields.get(0); assertEquals(field1.getElementName(), new String("sint")); checkElementOffset((CElement)field1); @@ -386,7 +386,7 @@ public class CModelElementsTests extends TestCase { assertEquals(struct2.getElementName(), new String ("")); checkElementOffset((CElement)struct2); checkLineNumbers((CElement)struct2, 101, 103); - ArrayList struct2Fields = struct2.getChildrenOfType(ICElement.C_FIELD); + List struct2Fields = struct2.getChildrenOfType(ICElement.C_FIELD); IField field2 = (IField) struct2Fields.get(0); assertEquals(field2.getElementName(), new String("ss")); checkElementOffset((CElement)field2); @@ -396,7 +396,7 @@ public class CModelElementsTests extends TestCase { fail("field visibility should be public!"); // typedefs - ArrayList nsTypeDefs = namespace.getChildrenOfType(ICElement.C_TYPEDEF); + List nsTypeDefs = namespace.getChildrenOfType(ICElement.C_TYPEDEF); ITypeDef td1 = (ITypeDef) nsTypeDefs.get(0); assertEquals(td1.getElementName(), new String ("myStruct")); checkElementOffset((CElement)td1); @@ -409,12 +409,12 @@ public class CModelElementsTests extends TestCase { checkLineNumbers((CElement)td2, 101, 103); // union - ArrayList nsUnions = namespace.getChildrenOfType(ICElement.C_UNION); + List nsUnions = namespace.getChildrenOfType(ICElement.C_UNION); IStructure u0 = (IStructure) nsUnions.get(0); assertEquals(u0.getElementName(), new String("U")); checkElementOffset((CElement)u0); checkLineNumbers((CElement)u0, 105, 107); - ArrayList u0Fields = u0.getChildrenOfType(ICElement.C_FIELD); + List u0Fields = u0.getChildrenOfType(ICElement.C_FIELD); IField field3 = (IField) u0Fields.get(0); assertEquals(field3.getElementName(), new String("U1")); checkElementOffset((CElement)field3); @@ -426,7 +426,7 @@ public class CModelElementsTests extends TestCase { private void checkTemplates(IParent namespace){ // template function - ArrayList functionTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_FUNCTION); + List functionTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_FUNCTION); FunctionTemplate ft = (FunctionTemplate)functionTemplates.get(0); assertEquals(ft.getElementName(), new String("aTemplatedFunction")); checkElementOffset((CElement)ft); @@ -435,10 +435,10 @@ public class CModelElementsTests extends TestCase { checkLineNumbers((CElement)ft, 112, 113); // template method - ArrayList nsClasses = namespace.getChildrenOfType(ICElement.C_CLASS); + List nsClasses = namespace.getChildrenOfType(ICElement.C_CLASS); IStructure enclosingClass = (IStructure) nsClasses.get(1); checkLineNumbers((CElement)enclosingClass, 115, 120); - ArrayList methodTemplates = enclosingClass.getChildrenOfType(ICElement.C_TEMPLATE_METHOD); + List methodTemplates = enclosingClass.getChildrenOfType(ICElement.C_TEMPLATE_METHOD); MethodTemplate mt = (MethodTemplate)methodTemplates.get(0); assertEquals(mt.getElementName(), new String("aTemplatedMethod")); checkElementOffset((CElement)mt); @@ -447,7 +447,7 @@ public class CModelElementsTests extends TestCase { assertEquals(mt.getVisibility(), ASTAccessVisibility.PUBLIC); // template class - ArrayList classTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_CLASS); + List classTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_CLASS); StructureTemplate ct = (StructureTemplate)classTemplates.get(0); assertEquals(ct.getElementName(), new String("myarray")); checkElementOffset((CElement)ct); @@ -455,7 +455,7 @@ public class CModelElementsTests extends TestCase { checkLineNumbers((CElement)ct, 122, 123); // template struct - ArrayList structTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_STRUCT); + List structTemplates = namespace.getChildrenOfType(ICElement.C_TEMPLATE_STRUCT); StructureTemplate st = (StructureTemplate)structTemplates.get(0); assertEquals(st.getElementName(), new String("mystruct")); checkElementOffset((CElement)st); @@ -475,7 +475,7 @@ public class CModelElementsTests extends TestCase { private void checkArrays(IParent tu){ // array variable - ArrayList variables = tu.getChildrenOfType(ICElement.C_VARIABLE); + List variables = tu.getChildrenOfType(ICElement.C_VARIABLE); IVariable arrayVar = (IVariable) variables.get(0); assertEquals(arrayVar.getElementName(), new String("myArray")); checkElementOffset((CElement)arrayVar); @@ -483,7 +483,7 @@ public class CModelElementsTests extends TestCase { checkLineNumbers((CElement)arrayVar, 133, 133); // array parameter in function main - ArrayList functions = tu.getChildrenOfType(ICElement.C_FUNCTION); + List functions = tu.getChildrenOfType(ICElement.C_FUNCTION); IFunction mainFunction = (IFunction) functions.get(0); assertEquals(mainFunction.getElementName(), new String("main")); checkElementOffset((CElement)mainFunction); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CPathEntryTest.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CPathEntryTest.java index 46216c4a935..5b86c5291da 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CPathEntryTest.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CPathEntryTest.java @@ -139,14 +139,20 @@ public class CPathEntryTest extends TestCase { fail("Unable to create project"); } IPathEntry[] entries = testProject.getResolvedPathEntries(); - assertTrue("No cpathentries", entries.length == 0); + // We always have at least two entries: + // 1) the default sourceEntry becomes the project + // 2) the default outputEntry becomes the project + assertTrue("No cpathentries", entries.length == 2); entries = new IPathEntry[3]; entries[0] = CoreModel.newIncludeEntry(new Path(""), new Path("/usr/include"), true); entries[1] = CoreModel.newIncludeEntry(new Path("cpaththest/foo.c"), new Path("/usr/include"), true); entries[2] = CoreModel.newLibraryEntry(new Path("/usr/lib/libc.so.1"), null, null, null); testProject.setRawPathEntries(entries, new NullProgressMonitor()); entries = testProject.getResolvedPathEntries(); - assertTrue("Expecting 3 pathentries", entries.length == 3); + // We always have at least two entries: + // 1) the default sourceEntry becomes the project + // 2) the default outputEntry becomes the project + assertTrue("Expecting 3 pathentries", entries.length == (3 + 2)); testProject.setRawPathEntries(null, null); } @@ -161,7 +167,7 @@ public class CPathEntryTest extends TestCase { if (testProject == null) { fail("Unable to create project"); } - CProjectHelper.addSourceContainer(testProject, "foo"); + CProjectHelper.addCContainer(testProject, "foo"); IPathEntry[] entries = new IPathEntry[3]; entries[0] = CoreModel.newIncludeEntry(new Path(""), new Path("/usr/include"), true); entries[1] = CoreModel.newIncludeEntry(new Path("foo"), new Path("/usr/include"), true); @@ -208,6 +214,9 @@ public class CPathEntryTest extends TestCase { CoreModel.getDefault().setRawPathEntries(testProject, new IPathEntry[]{containerEntry}, new NullProgressMonitor()); CoreModel.getDefault().setPathEntryContainer(new ICProject[]{testProject}, container, new NullProgressMonitor()); IPathEntry[] entries = testProject.getResolvedPathEntries(); - assertTrue("Expecting 3 pathentries from container", entries.length == 3); + // We always have at least two entries: + // 1) the default sourceEntry becomes the project + // 2) the default outputEntry becomes the project + assertTrue("Expecting 3 pathentries from container", entries.length == (3 + 2)); } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/ElementDeltaTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/ElementDeltaTests.java index bb8c2573822..a5b7d085663 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/ElementDeltaTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/ElementDeltaTests.java @@ -22,6 +22,7 @@ import junit.framework.TestCase; import junit.framework.TestSuite; import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ElementChangedEvent; import org.eclipse.cdt.core.model.IBuffer; import org.eclipse.cdt.core.model.ICElement; @@ -31,7 +32,6 @@ import org.eclipse.cdt.core.model.IElementChangedListener; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.internal.core.model.CModelManager; -import org.eclipse.cdt.internal.core.model.TranslationUnit; import org.eclipse.cdt.testplugin.CProjectHelper; import org.eclipse.cdt.testplugin.CTestPlugin; import org.eclipse.cdt.testplugin.TestPluginLauncher; @@ -96,7 +96,12 @@ public class ElementDeltaTests extends TestCase implements IElementChangedListen public void testElementDeltas() throws Exception { - ITranslationUnit tu = new TranslationUnit(fCProject, headerFile); + //ITranslationUnit tu = new TranslationUnit(fCProject, headerFile); + ICElement celement = CoreModel.getDefault().create(headerFile); + ITranslationUnit tu = null; + if (celement instanceof ITranslationUnit) { + tu = (ITranslationUnit)celement; + } assertNotNull (tu); IWorkingCopy wc = tu.getWorkingCopy(); assertNotNull (wc); @@ -110,6 +115,7 @@ public class ElementDeltaTests extends TestCase implements IElementChangedListen wc.commit(true, monitor); assertChangedElement(ICElement.C_MODEL, ""); assertChangedElement(ICElement.C_PROJECT, "TestProject1"); + assertChangedElement(ICElement.C_CCONTAINER, "TestProject1"); assertChangedElement(ICElement.C_UNIT, "WorkingCopyTest.h"); assertAddedElement(ICElement.C_CLASS, "Hello"); assertRemovedElement(ICElement.C_INCLUDE, "stdio.h"); @@ -121,6 +127,7 @@ public class ElementDeltaTests extends TestCase implements IElementChangedListen wc.commit(true, monitor); assertChangedElement(ICElement.C_MODEL, ""); assertChangedElement(ICElement.C_PROJECT, "TestProject1"); + assertChangedElement(ICElement.C_CCONTAINER, "TestProject1"); assertChangedElement(ICElement.C_UNIT, "WorkingCopyTest.h"); assertChangedElement(ICElement.C_CLASS, "Hello"); assertAddedElement(ICElement.C_FIELD, "x"); @@ -132,6 +139,7 @@ public class ElementDeltaTests extends TestCase implements IElementChangedListen wc.commit(true, monitor); assertChangedElement(ICElement.C_MODEL, ""); assertChangedElement(ICElement.C_PROJECT, "TestProject1"); + assertChangedElement(ICElement.C_CCONTAINER, "TestProject1"); assertChangedElement(ICElement.C_UNIT, "WorkingCopyTest.h"); assertChangedElement(ICElement.C_CLASS, "Hello"); assertAddedElement(ICElement.C_METHOD_DECLARATION, "setValue"); @@ -144,6 +152,7 @@ public class ElementDeltaTests extends TestCase implements IElementChangedListen wc.commit(true, monitor); assertChangedElement(ICElement.C_MODEL, ""); assertChangedElement(ICElement.C_PROJECT, "TestProject1"); + assertChangedElement(ICElement.C_CCONTAINER, "TestProject1"); assertChangedElement(ICElement.C_UNIT, "WorkingCopyTest.h"); assertChangedElement(ICElement.C_CLASS, "Hello"); assertAddedElement(ICElement.C_FIELD, "y"); @@ -156,6 +165,7 @@ public class ElementDeltaTests extends TestCase implements IElementChangedListen wc.commit(true, monitor); assertChangedElement(ICElement.C_MODEL, ""); assertChangedElement(ICElement.C_PROJECT, "TestProject1"); + assertChangedElement(ICElement.C_CCONTAINER, "TestProject1"); assertChangedElement(ICElement.C_UNIT, "WorkingCopyTest.h"); assertChangedElement(ICElement.C_CLASS, "Hello"); assertChangedElement(ICElement.C_FIELD, "y"); @@ -168,6 +178,7 @@ public class ElementDeltaTests extends TestCase implements IElementChangedListen wc.commit(true, monitor); assertChangedElement(ICElement.C_MODEL, ""); assertChangedElement(ICElement.C_PROJECT, "TestProject1"); + assertChangedElement(ICElement.C_CCONTAINER, "TestProject1"); assertChangedElement(ICElement.C_UNIT, "WorkingCopyTest.h"); assertChangedElement(ICElement.C_CLASS, "Hello"); assertRemovedElement(ICElement.C_FIELD, "y"); @@ -179,6 +190,7 @@ public class ElementDeltaTests extends TestCase implements IElementChangedListen wc.commit(true, monitor); assertChangedElement(ICElement.C_MODEL, ""); assertChangedElement(ICElement.C_PROJECT, "TestProject1"); + assertChangedElement(ICElement.C_CCONTAINER, "TestProject1"); assertChangedElement(ICElement.C_UNIT, "WorkingCopyTest.h"); assertRemovedElement(ICElement.C_CLASS, "Hello"); assertEmptyDelta(); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IMacroTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IMacroTests.java index f4d1d67d5d0..5bf3edac60c 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IMacroTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IMacroTests.java @@ -8,7 +8,7 @@ import org.eclipse.cdt.core.model.IMacro; import junit.framework.Test; import junit.framework.TestSuite; -import java.util.ArrayList; +import java.util.List; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.tests.IntegratedCModelTest; @@ -55,7 +55,7 @@ public class IMacroTests extends IntegratedCModelTest { public void testGetElementName() { ITranslationUnit tu = getTU(); - ArrayList arrayElements = tu.getChildrenOfType( ITranslationUnit.C_MACRO ); + List arrayElements = tu.getChildrenOfType( ITranslationUnit.C_MACRO ); String expectedList[] = new String[] { "SINGLETON", @@ -72,7 +72,7 @@ public class IMacroTests extends IntegratedCModelTest { public void testGetIdentifierList() { ITranslationUnit tu = getTU(); - ArrayList arrayElements = tu.getChildrenOfType( ITranslationUnit.C_MACRO ); + List arrayElements = tu.getChildrenOfType( ITranslationUnit.C_MACRO ); String expectedList[] = new String[] { "", @@ -89,7 +89,7 @@ public class IMacroTests extends IntegratedCModelTest { public void testGetTokenSequence() { ITranslationUnit tu = getTU(); - ArrayList arrayElements = tu.getChildrenOfType( ITranslationUnit.C_MACRO ); + List arrayElements = tu.getChildrenOfType( ITranslationUnit.C_MACRO ); String expectedList[] = new String[] { "", diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IStructureTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IStructureTests.java index de0967cd9e6..94227be5d5a 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IStructureTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IStructureTests.java @@ -9,7 +9,7 @@ import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import junit.framework.*; -import java.util.ArrayList; +import java.util.List; /** * @author bnicolle @@ -71,7 +71,7 @@ public class IStructureTests extends IntegratedCModelTest { public void testGetChildrenOfTypeStruct() { ITranslationUnit tu = getTU(); - ArrayList arrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); + List arrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); String[] myExpectedStructs = { "testStruct1", "testStruct2", "testStruct3", /* 2 anonymous structs */ "", "", "testStruct7", @@ -86,7 +86,7 @@ public class IStructureTests extends IntegratedCModelTest { } public void testGetChildrenOfTypeClass() { ITranslationUnit tu = getTU(); - ArrayList arrayClasses = tu.getChildrenOfType(ICElement.C_CLASS); + List arrayClasses = tu.getChildrenOfType(ICElement.C_CLASS); String[] myExpectedClasses = { "testClass1", "testClass3", "testClass4Abstract", "testClass5", "testClass6" }; @@ -100,7 +100,7 @@ public class IStructureTests extends IntegratedCModelTest { public void testGetFields() { ITranslationUnit tu = getTU(); - ArrayList myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); + List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); IStructure myIStruct = (IStructure) myArrayStructs.get(0); IField[] myArrayIField = myIStruct.getFields(); String[] myExpectedFields = { @@ -118,13 +118,13 @@ public class IStructureTests extends IntegratedCModelTest { // TODO Bug# 38985: remove testGetFieldsHack() public void testGetFieldsHack() { ITranslationUnit tu = getTU(); - ArrayList myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); + List myArrayStructs = tu.getChildrenOfType(ICElement.C_STRUCT); IStructure myIStruct = (IStructure) myArrayStructs.get(0); String[] myExpectedFields = { "m_field1","m_field2","m_field3", "m_field4","m_field5","m_field6", }; - ArrayList myArrayIField = myIStruct.getChildrenOfType(ICElement.C_FIELD); + List myArrayIField = myIStruct.getChildrenOfType(ICElement.C_FIELD); assertEquals(myExpectedFields.length, myArrayIField.size()); for(int i=0; i::first", "IsGreaterThan", "Foo::fum" diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitBaseTest.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitBaseTest.java index e30913ad65d..1480715bdeb 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitBaseTest.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitBaseTest.java @@ -11,7 +11,6 @@ package org.eclipse.cdt.core.model.tests; import java.io.FileInputStream; -import java.io.FileNotFoundException; import junit.framework.TestCase; @@ -27,7 +26,6 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; /** * @author jcamelon diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/CProjectHelper.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/CProjectHelper.java index a68438ff212..9ff72c1a104 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/CProjectHelper.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/testplugin/CProjectHelper.java @@ -7,6 +7,7 @@ import junit.framework.Assert; import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CProjectNature; +import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IArchive; import org.eclipse.cdt.core.model.IArchiveContainer; import org.eclipse.cdt.core.model.IBinary; @@ -14,8 +15,8 @@ import org.eclipse.cdt.core.model.IBinaryContainer; import org.eclipse.cdt.core.model.ICContainer; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.ISourceRoot; import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.internal.core.model.CModelManager; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; @@ -123,38 +124,41 @@ public class CProjectHelper { } /** - * Adds a source container to a ICProject. + * Adds a folder container to a ICProject. */ - public static ICContainer addSourceContainer(ICProject cproject, String containerName) throws CoreException { + public static ICContainer addCContainer(ICProject cproject, String containerName) throws CoreException { IProject project = cproject.getProject(); ICContainer container = null; if (containerName == null || containerName.length() == 0) { - container = CModelManager.getDefault().create(project); + ICContainer[] conts = cproject.getSourceRoots(); + if (conts.length > 0) { + container = conts[0]; + } } else { IFolder folder = project.getFolder(containerName); if (!folder.exists()) { folder.create(false, true, null); } - container = CModelManager.getDefault().create(folder); + container = CoreModel.getDefault().create(folder); } return container; } /** - * Adds a source container to a ICProject and imports all files contained + * Adds a folder container to a ICProject and imports all files contained * in the given Zip file. */ - public static ICContainer addSourceContainerWithImport(ICProject cproject, String containerName, ZipFile zipFile) + public static ICContainer addCContainerWithImport(ICProject cproject, String containerName, ZipFile zipFile) throws InvocationTargetException, CoreException { - ICContainer root = addSourceContainer(cproject, containerName); + ICContainer root = addCContainer(cproject, containerName); importFilesFromZip(zipFile, root.getPath(), null); return root; } /** - * Removes a source folder from a ICProject. + * Removes a folder from a ICProject. */ - public static void removeSourceContainer(ICProject cproject, String containerName) throws CoreException { + public static void removeCContainer(ICProject cproject, String containerName) throws CoreException { IFolder folder = cproject.getProject().getFolder(containerName); folder.delete(true, null); } @@ -205,52 +209,55 @@ public class CProjectHelper { * Attempts to find an object with the given name in the workspace */ public static IBinary findObject(ICProject testProject, String name) { - int x; - ICElement[] myElements; - myElements = testProject.getChildren(); - if (myElements.length < 1) - return (null); - for (x = 0; x < myElements.length; x++) { - if (myElements[x].getElementName().equals(name)) - if (myElements[x] instanceof IBinary) { - return ((IBinary)myElements[x]); + ICElement[] sourceRoots = testProject.getChildren(); + for (int i = 0; i < sourceRoots.length; i++) { + ISourceRoot root = (ISourceRoot)sourceRoots[i]; + ICElement[] myElements = root.getChildren(); + for (int x = 0; x < myElements.length; x++) { + if (myElements[x].getElementName().equals(name)) { + if (myElements[x] instanceof IBinary) { + return ((IBinary)myElements[x]); + } } + } } - return (null); + return null; } /** * Attempts to find a TranslationUnit with the given name in the workspace */ public static ITranslationUnit findTranslationUnit(ICProject testProject, String name) { - int x; - ICElement[] myElements; - myElements = testProject.getChildren(); - if (myElements.length < 1) - return (null); - for (x = 0; x < myElements.length; x++) { - if (myElements[x].getElementName().equals(name)) - if (myElements[x] instanceof ITranslationUnit) { - return ((ITranslationUnit)myElements[x]); + ICElement[] sourceRoots = testProject.getChildren(); + for (int i = 0; i < sourceRoots.length; i++) { + ISourceRoot root = (ISourceRoot)sourceRoots[i]; + ICElement[] myElements = root.getChildren(); + for (int x = 0; x < myElements.length; x++) { + if (myElements[x].getElementName().equals(name)) { + if (myElements[x] instanceof ITranslationUnit) { + return ((ITranslationUnit)myElements[x]); + } } + } } - return (null); + return null; } /** * Attempts to find an element with the given name in the workspace */ public static ICElement findElement(ICProject testProject, String name) { - int x; - ICElement[] myElements; - myElements = testProject.getChildren(); - if (myElements.length < 1) - return (null); - for (x = 0; x < myElements.length; x++) { - if (myElements[x].getElementName().equals(name)) - return myElements[x]; + ICElement[] sourceRoots = testProject.getChildren(); + for (int i = 0; i < sourceRoots.length; i++) { + ISourceRoot root = (ISourceRoot)sourceRoots[i]; + ICElement[] myElements = root.getChildren(); + for (int x = 0; x < myElements.length; x++) { + if (myElements[x].getElementName().equals(name)) { + return myElements[x]; + } + } } - return (null); + return null; } private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException { diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index b757b1f41ce..d86d6ed7534 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -1,3 +1,30 @@ +2004-03-18 Alain Magloire + + Change in the hierarchy of the core Model: + ICModel + ICProject + ISourceRoot + IBinary + IArchive + ITranslatioUnit + ICContainer + The ISourceRoot been added to better separate + the files. By default the entire project is the + SourceRoot. + + * model/org/eclipse/cdt/core/model/CoreModel.java + * model/org/eclipse/cdt/core/model/ICContainer.java + * model/org/eclipse/cdt/core/model/ICElement.java + * model/org/eclipse/cdt/core/model/ICProject.java + * model/org/eclipse/cdt/core/model/IIncludeEnty.java + * model/org/eclipse/cdt/core/model/IOutputEntry.java + * model/org/eclipse/cdt/core/model/IMacroEntry.java + * model/org/eclipse/cdt/core/model/IParent.java + * model/org/eclipse/cdt/core/model/ISourceEntry.java + * model/org/eclipse/cdt/core/model/ISourceRoot.java + + * model/org/eclipse/cdt/internal/core/model/* + 2004-03-17 Alain Magloire Put the framework in to take advantage of being a diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java index 3d89c48b5ae..4f286e71871 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java @@ -3,16 +3,17 @@ package org.eclipse.cdt.core.model; /* * (c) Copyright QNX Software Systems Ltd. 2002. All Rights Reserved. */ - import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CDescriptorEvent; import org.eclipse.cdt.core.ICDescriptorListener; import org.eclipse.cdt.internal.core.model.BatchOperation; +import org.eclipse.cdt.internal.core.model.CModel; import org.eclipse.cdt.internal.core.model.CModelManager; import org.eclipse.cdt.internal.core.model.ContainerEntry; import org.eclipse.cdt.internal.core.model.IncludeEntry; import org.eclipse.cdt.internal.core.model.LibraryEntry; import org.eclipse.cdt.internal.core.model.MacroEntry; +import org.eclipse.cdt.internal.core.model.OutputEntry; import org.eclipse.cdt.internal.core.model.PathEntryManager; import org.eclipse.cdt.internal.core.model.ProjectEntry; import org.eclipse.cdt.internal.core.model.SourceEntry; @@ -22,6 +23,7 @@ import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -29,11 +31,9 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; public class CoreModel implements ICDescriptorListener { - private static CoreModel cmodel = null; private static CModelManager manager = null; private static PathEntryManager pathEntryManager = null; - public final static String CORE_MODEL_ID = CCorePlugin.PLUGIN_ID + ".coremodel"; //$NON-NLS-1$ /** @@ -47,30 +47,47 @@ public class CoreModel implements ICDescriptorListener { * Creates an ICElement form and IFile. Returns null if not found. */ public ICElement create(IFile file) { - return manager.create(file); + return manager.create(file, null); + } /** * Creates an ICElement form and IFolder. Returns null if not found. */ public ICContainer create(IFolder folder) { - return manager.create(folder); + return manager.create(folder, null); } /** * Creates an ICElement form and IProject. Returns null if not found. */ public ICProject create(IProject project) { - return manager.create(project); + if (project == null) { + return null; + } + CModel cModel = manager.getCModel(); + return cModel.getCProject(project); } /** * Creates an ICElement form and IResource. Returns null if not found. */ public ICElement create(IResource resource) { - return manager.create(resource); + return manager.create(resource, null); } + /** + * Returns the C model. + * + * @param root the given root + * @return the C model, or null if the root is null + */ + public static ICModel create(IWorkspaceRoot root) { + if (root == null) { + return null; + } + return manager.getCModel(); + } /** * Returns the default ICModel. */ @@ -295,6 +312,35 @@ public class CoreModel implements ICDescriptorListener { return new LibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, sourceAttachmentPrefixMapping, isExported); } + /** + * Creates and returns a new entry of kind CDT_OUTPUT for + * the project's output folder + *

+ * + * @param path + * the project-relative path of a binary folder + * @return a new source entry with not exclusion patterns + * + */ + public static IOutputEntry newOutputEntry(IPath path) { + return newOutputEntry(path, OutputEntry.NO_EXCLUSION_PATTERNS); + } + + /** + * Creates and returns a new entry of kind CDT_OUPUT for + * the project + * + * @param path + * the absolute project-relative path of a binary folder + * @param exclusionPatterns + * the possibly empty list of exclusion patterns represented as + * relative paths + * @return a new source entry with the given exclusion patterns + */ + public static IOutputEntry newOutputEntry(IPath path, IPath[] exclusionPatterns) { + return new OutputEntry(path, exclusionPatterns, false); + } + /** * Creates and returns a new entry of kind CDT_SOURCE for * the project's source folder identified by the given absolute @@ -322,60 +368,6 @@ public class CoreModel implements ICDescriptorListener { return newSourceEntry(path, SourceEntry.NO_EXCLUSION_PATTERNS); } - /** - * Creates and returns a new entry of kind CDT_SOURCE for - * the project's source folder identified by the given absolute - * workspace-relative path but excluding all source files with paths - * matching any of the given patterns. This specifies that all package - * fragments within the root will have children of type ICompilationUnit. - *

- * The source folder is referred to using an absolute path relative to the - * workspace root, e.g. /Project/src. A project's source - * folders are located with that project. That is, a source entry - * specifying the path /P1/src is only usable for project - * P1. - *

- * - * @param path - * the project-relative path of a source folder - * @param exclusionPatterns - * the possibly empty list of exclusion patterns represented as - * relative paths - * @return a new source entry with the given exclusion patterns - * - */ - public static ISourceEntry newSourceEntry(IPath path, IPath[] exclusionPatterns) { - return newSourceEntry(path, null, exclusionPatterns); - } - - /** - * Creates and returns a new entry of kind CDT_SOURCE for - * the project's source folder identified by the given absolute - * workspace-relative path but excluding all source files with paths - * matching any of the given patterns. This specifies that all package - * fragments within the root will have children of type ICompilationUnit. - *

- * The source folder is referred to using an absolute path relative to the - * workspace root, e.g. /Project/src. A project's source - * folders are located with that project. That is, a source entry - * specifying the path /P1/src is only usable for project - * P1. - *

- * - * @param path - * the project-relative path of a source folder - * @param exclusionPatterns - * the possibly empty list of exclusion patterns represented as - * relative paths - * @param specificOutputLocation - * the specific output location for this source entry (null - * if using project default ouput location) - * @return a new source entry with the given exclusion patterns - */ - public static ISourceEntry newSourceEntry(IPath path, IPath outputLocation, IPath[] exclusionPatterns) { - return newSourceEntry(path, outputLocation, true, exclusionPatterns); - } - /** * Creates and returns a new entry of kind CDT_SOURCE for * the project's source folder identified by the given absolute @@ -395,13 +387,10 @@ public class CoreModel implements ICDescriptorListener { * @param exclusionPatterns * the possibly empty list of exclusion patterns represented as * relative paths - * @param specificOutputLocation - * the specific output location for this source entry (null - * if using project default ouput location) * @return a new source entry with the given exclusion patterns */ - public static ISourceEntry newSourceEntry(IPath path, IPath outputLocation, boolean isRecursive, IPath[] exclusionPatterns) { - return new SourceEntry(path, outputLocation, isRecursive, exclusionPatterns); + public static ISourceEntry newSourceEntry(IPath path, IPath[] exclusionPatterns) { + return new SourceEntry(path, exclusionPatterns); } /** @@ -429,11 +418,10 @@ public class CoreModel implements ICDescriptorListener { } /** - /** - * Creates and returns a new entry of kind CDT_INCLUDE + * * Creates and returns a new entry of kind CDT_INCLUDE * * @param path - * the affected project-relative resource path + * the affected project-relative resource path * @param includePath * the absolute path of the include * @param isSystemInclude @@ -442,7 +430,7 @@ public class CoreModel implements ICDescriptorListener { * @return IIncludeEntry */ public static IIncludeEntry newIncludeEntry(IPath resourcePath, IPath includePath, boolean isSystemInclude) { - return newIncludeEntry(resourcePath, includePath, isSystemInclude, true, IncludeEntry.NO_EXCLUSION_PATTERNS); + return newIncludeEntry(resourcePath, includePath, isSystemInclude, IncludeEntry.NO_EXCLUSION_PATTERNS); } /** @@ -462,9 +450,24 @@ public class CoreModel implements ICDescriptorListener { * exclusion patterns in the resource if a container * @return IIincludeEntry */ - public static IIncludeEntry newIncludeEntry(IPath resourcePath, IPath includePath, boolean isSystemInclude, boolean isRecursive, - IPath[] exclusionPatterns) { - return new IncludeEntry(resourcePath, includePath, isSystemInclude, isRecursive, exclusionPatterns); + public static IIncludeEntry newIncludeEntry(IPath resourcePath, IPath includePath, boolean isSystemInclude, + IPath[] exclusionPatterns) { + return new IncludeEntry(resourcePath, includePath, isSystemInclude, exclusionPatterns); + } + + /** + * Creates and returns an entry kind CDT_MACRO + * + * @param path + * the affected workspace-relative resource path + * @param macroName + * the name of the macro + * @param macroValue + * the value of the macro + * @return + */ + public static IMacroEntry newMacroEntry(String macroName, String macroValue) { + return newMacroEntry(null, macroName, macroValue, MacroEntry.NO_EXCLUSION_PATTERNS); } /** @@ -479,7 +482,7 @@ public class CoreModel implements ICDescriptorListener { * @return */ public static IMacroEntry newMacroEntry(IPath path, String macroName, String macroValue) { - return newMacroEntry(path, macroName, macroValue, true, MacroEntry.NO_EXCLUSION_PATTERNS, true); + return newMacroEntry(path, macroName, macroValue, MacroEntry.NO_EXCLUSION_PATTERNS); } /** @@ -491,18 +494,12 @@ public class CoreModel implements ICDescriptorListener { * the name of the macro * @param macroValue * the value of the macro - * @param isRecursive - * if the resource is a folder the include applied to all - * recursively * @param exclusionPatterns * exclusion patterns in the resource if a container - * @param isExported - * whether this cpath is exported. * @return */ - public static IMacroEntry newMacroEntry(IPath path, String macroName, String macroValue, boolean isRecursive, - IPath[] exclusionPatterns, boolean isExported) { - return new MacroEntry(path, macroName, macroValue, isRecursive, exclusionPatterns, isExported); + public static IMacroEntry newMacroEntry(IPath path, String macroName, String macroValue, IPath[] exclusionPatterns) { + return new MacroEntry(path, macroName, macroValue, exclusionPatterns); } /** @@ -731,5 +728,4 @@ public class CoreModel implements ICDescriptorListener { public IndexManager getIndexManager() { return manager.getIndexManager(); } - } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICContainer.java index 7b1a1c2b3ab..c58215a5d2e 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICContainer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICContainer.java @@ -1,5 +1,6 @@ package org.eclipse.cdt.core.model; + /* * (c) Copyright QNX Software Systems Ltd. 2002. * All Rights Reserved. @@ -10,6 +11,7 @@ package org.eclipse.cdt.core.model; * A C Folder Resource. */ public interface ICContainer extends ICElement, IParent, IOpenable { + /** * Returns an array of non-C resources directly contained in this project. * It does not transitively answer non-C resources contained in folders; @@ -24,4 +26,81 @@ public interface ICContainer extends ICElement, IParent, IOpenable { */ Object[] getNonCResources() throws CModelException; -} + /** + * Returns all of the translation units in this ccontainer. + * + * @exception CModelException if this element does not exist or if an + * exception occurs while accessing its corresponding resource. + * @return all of the translation units in this ccontainer + */ + ITranslationUnit[] getTranslationUnits() throws CModelException; + + /** + * Returns the tranlation unit with the specified name + * in this container (for example, "foobar.c"). + * The name has to be a valid translation unit name. + * This is a handle-only operation. The celement + * may or may not exist. + * + * @param name the given name + * @return the translation unit with the specified name in this container + */ + ITranslationUnit getTranslationUnit(String name); + + /** + * Returns the all the binaries of this container. + * + * @return + * @throws CModelException + */ + IBinary[] getBinaries() throws CModelException; + + /** + * Return the binary for this name, it must be a + * valid binary + * This is a handle-only operation. The celement + * may or may not exist. + * + * @return + * @throws CModelException + */ + IBinary getBinary(String name); + + /** + * Returns all the archive of this container + * + * @return + * @throws CModelException + */ + IArchive[] getArchives() throws CModelException; + + /** + * This is a handle-only operation. The celement + * may or may not exist. + * + * @param file + * @return + * @throws CModelException + */ + IArchive getArchive(String name); + + /** + * Return al the child containers of this container. + * + * @return + * @throws CModelException + */ + ICContainer[] getCContainers() throws CModelException; + + /** + * Returns the container with the given name. + * An empty string indicates the default package. + * This is a handle-only operation. The celement + * may or may not exist. + * + * @param name the given container + * @return the container with the given name + */ + ICContainer getCContainer(String name); + +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java index f43af7f969b..91c890ce320 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java @@ -8,6 +8,7 @@ package org.eclipse.cdt.core.model; import java.util.Map; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -20,7 +21,7 @@ import org.eclipse.core.runtime.IProgressMonitor; * @see CCore#create(org.eclipse.core.resources.IProject) * @see IBuildEntry */ -public interface ICProject extends ICContainer { +public interface ICProject extends IParent, IOpenable, ICElement { /** * Returns the ICElement corresponding to the given @@ -42,6 +43,36 @@ public interface ICProject extends ICContainer { */ IBinaryContainer getBinaryContainer(); + /** + * Returns the source root folders of the project. + * @return ISourceRoot - root folders + * @exception CModelException + */ + ISourceRoot[] getSourceRoots() throws CModelException; + + /** + * + * @param entry + * @return ISourceRoot + * @throws CModelException + */ + ISourceRoot getSourceRoot(ISourceEntry entry) throws CModelException; + + /** + * Return the output entries. + * + * @return + * @throws CModelException + */ + public IOutputEntry[] getOutputEntries() throws CModelException; + + /** + * @param resource + * @return + */ + boolean isOnOutputEntry(IResource resource); + + /** * Return the library references for this project. * @@ -157,4 +188,18 @@ public interface ICProject extends ICContainer { */ void setRawPathEntries(IPathEntry[] entries, IProgressMonitor monitor) throws CModelException; + /** + * Returns an array of non-C resources directly contained in this project. + * It does not transitively answer non-C resources contained in folders; + * these would have to be explicitly iterated over. + *

+ * Non-C resources includes files, folders, projects not accounted for. + *

+ * + * @return an array of non-C resources directly contained in this project + * @exception JavaModelException if this element does not exist or if an + * exception occurs while accessing its corresponding resource + */ + Object[] getNonCResources() throws CModelException; + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IIncludeEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IIncludeEntry.java index bb5d6cf1e1b..c2b7f61180b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IIncludeEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IIncludeEntry.java @@ -28,13 +28,6 @@ public interface IIncludeEntry extends IPathEntry { */ boolean isSystemInclude(); - /** - * Whether or not the include affects the resource(if it is a folder) - * recursively - * @return boolean - */ - boolean isRecursive(); - /** * If isRecursive() is true, specify an exclude file patterns. * @return IPath diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMacroEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMacroEntry.java index 0542ba6f5a8..7f6956a7086 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMacroEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMacroEntry.java @@ -28,12 +28,6 @@ public interface IMacroEntry extends IPathEntry { */ String getMacroValue(); - /** - * Whether or not the macro is applied recursively. - * @return boolean - */ - boolean isRecursive(); - /** * Returns an array of inclusion paths affecting the * resource when looking for files recursively. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IOutputEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IOutputEntry.java new file mode 100644 index 00000000000..25f3f4bd537 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IOutputEntry.java @@ -0,0 +1,35 @@ +/********************************************************************** + * Copyright (c) 2002,2003,2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ + +package org.eclipse.cdt.core.model; + +import org.eclipse.core.runtime.IPath; + + +/** + * IOuputEntry + */ +public interface IOutputEntry extends IPathEntry { + + /** + * Returns an array of inclusion paths affecting the + * source folder when looking for files recursively. + * @return IPath + */ + IPath[] getExclusionPatterns(); + + /** + * Returns a char based representation of the exclusions patterns full path. + */ + public char[][] fullExclusionPatternChars(); + + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IParent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IParent.java index c375b4e7f2e..9e42de3e77a 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IParent.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IParent.java @@ -1,6 +1,6 @@ package org.eclipse.cdt.core.model; -import java.util.ArrayList; +import java.util.List; /* * (c) Copyright QNX Software Systems Ltd. 2002. @@ -24,7 +24,7 @@ public interface IParent { /** * returns the children of a certain type */ - public ArrayList getChildrenOfType(int type); + public List getChildrenOfType(int type); /** * Returns whether this element has one or more immediate children. * This is a convenience method, and may be more efficient than diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ISourceEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ISourceEntry.java index f1f48bc45ab..48525f74240 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ISourceEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ISourceEntry.java @@ -16,24 +16,16 @@ import org.eclipse.core.runtime.IPath; public interface ISourceEntry extends IPathEntry { - /** - * Whether or not to look recursively in the folder. - * @return boolean - */ - boolean isRecursive(); - /** * Returns an array of inclusion paths affecting the * source folder when looking for files recursively. - * @return IPath + * @return IPath[] */ IPath[] getExclusionPatterns(); - + /** - * Binary output location for this source folder. - * @return IPath, null means to use the - * default output location of the project. + * Returns a char based representation of the exclusions patterns full path. */ - IPath getOutputLocation(); + public char[][] fullExclusionPatternChars(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ISourceRoot.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ISourceRoot.java new file mode 100644 index 00000000000..d7c55965858 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ISourceRoot.java @@ -0,0 +1,33 @@ +/********************************************************************** + * Copyright (c) 2002,2003 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation +***********************************************************************/ + +package org.eclipse.cdt.core.model; + +import org.eclipse.core.resources.IResource; + +/** + * ISourceRoot + */ +public interface ISourceRoot extends ICContainer { + + /** + * @param resource + * @return + */ + boolean isOnSourceEntry(IResource resource); + + /** + * @param element + * @return + */ + boolean isOnSourceEntry(ICElement element); + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java index 4873a0d6cee..487e40e07b8 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java @@ -18,12 +18,12 @@ public abstract class APathEntry extends PathEntry { public static IPath[] NO_EXCLUSION_PATTERNS = {}; IPath[] exclusionPatterns; - boolean isRecursive; + private final static char[][] UNINIT_PATTERNS = new char[][] { "Non-initialized yet".toCharArray() }; //$NON-NLS-1$ + char[][]fullCharExclusionPatterns = UNINIT_PATTERNS; - public APathEntry (int kind, IPath path, boolean isRecursive, IPath[] exclusionPatterns, boolean isExported) { + public APathEntry (int kind, IPath path, IPath[] exclusionPatterns, boolean isExported) { super(kind, path, isExported); this.exclusionPatterns = exclusionPatterns; - this.isRecursive = isRecursive; } /** @@ -33,13 +33,21 @@ public abstract class APathEntry extends PathEntry { public IPath[] getExclusionPatterns() { return exclusionPatterns; } - - /** - * Whether or not it is recursive - * @return boolean + + /* + * Returns a char based representation of the exclusions patterns full path. */ - public boolean isRecursive() { - return isRecursive; + public char[][] fullExclusionPatternChars() { + if (this.fullCharExclusionPatterns == UNINIT_PATTERNS) { + int length = this.exclusionPatterns.length; + this.fullCharExclusionPatterns = new char[length][]; + IPath prefixPath = this.path.removeTrailingSeparator(); + for (int i = 0; i < length; i++) { + this.fullCharExclusionPatterns[i] = + prefixPath.append(this.exclusionPatterns[i]).toString().toCharArray(); + } + } + return this.fullCharExclusionPatterns; } public boolean equals(Object obj) { @@ -48,9 +56,6 @@ public abstract class APathEntry extends PathEntry { if (!super.equals(otherEntry)) { return false; } - if (isRecursive != otherEntry.isRecursive()) { - return false; - } IPath[] otherExcludes = otherEntry.getExclusionPatterns(); if (exclusionPatterns != otherExcludes) { int excludeLength = (exclusionPatterns == null) ? 0 : exclusionPatterns.length; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java index 0de9af10324..754185f6ead 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java @@ -12,7 +12,6 @@ import java.util.HashMap; import java.util.Map; import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable; -import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; import org.eclipse.cdt.core.IBinaryParser.IBinaryShared; import org.eclipse.cdt.core.IBinaryParser.ISymbol; @@ -39,16 +38,16 @@ public class Binary extends Openable implements IBinary { private long fLastModification; - IBinaryFile binaryFile; + IBinaryObject binaryObject; - public Binary(ICElement parent, IFile file, IBinaryFile bin) { + public Binary(ICElement parent, IFile file, IBinaryObject bin) { super(parent, file, ICElement.C_BINARY); - binaryFile = bin; + binaryObject = bin; } - public Binary(ICElement parent, IPath path, IBinaryFile bin) { + public Binary(ICElement parent, IPath path, IBinaryObject bin) { super (parent, path, ICElement.C_BINARY); - binaryFile = bin; + binaryObject = bin; } public boolean isSharedLib() { @@ -70,7 +69,10 @@ public class Binary extends Openable implements IBinary { public boolean hasDebug() { if (isObject() || isExecutable() || isSharedLib()) { if (hasDebug == null || hasChanged()) { - hasDebug = new Boolean(((IBinaryObject)getBinaryFile()).hasDebug()).toString(); + IBinaryObject obj = getBinaryObject(); + if (obj != null) { + hasDebug = new Boolean(obj.hasDebug()).toString(); + } } } return Boolean.valueOf(hasDebug).booleanValue(); @@ -79,7 +81,8 @@ public class Binary extends Openable implements IBinary { public String getCPU() { if (isObject() || isExecutable() || isSharedLib() || isCore()) { if (cpu == null || hasChanged()) { - cpu = ((IBinaryObject)getBinaryFile()).getCPU(); + IBinaryObject obj = getBinaryObject(); + cpu = obj.getCPU(); } } return (cpu == null ? "" : cpu); //$NON-NLS-1$ @@ -88,7 +91,10 @@ public class Binary extends Openable implements IBinary { public String[] getNeededSharedLibs() { if (isExecutable() || isSharedLib()) { if (needed == null || hasChanged()) { - needed = ((IBinaryExecutable)getBinaryFile()).getNeededSharedLibs(); + IBinaryObject obj = getBinaryObject(); + if (obj instanceof IBinaryExecutable) { + needed = ((IBinaryExecutable)obj).getNeededSharedLibs(); + } } } return (needed == null ? new String[0] : needed); @@ -97,7 +103,10 @@ public class Binary extends Openable implements IBinary { public long getText() { if (isObject() || isExecutable() || isSharedLib()) { if (longText == -1 || hasChanged()) { - longText = ((IBinaryObject)getBinaryFile()).getText(); + IBinaryObject obj = getBinaryObject(); + if (obj != null) { + longText = obj.getText(); + } } } return longText; @@ -106,7 +115,10 @@ public class Binary extends Openable implements IBinary { public long getData() { if (isObject() || isExecutable() || isSharedLib()) { if (longData == -1 || hasChanged()) { - longData = ((IBinaryObject)getBinaryFile()).getData(); + IBinaryObject obj = getBinaryObject(); + if (obj != null) { + longData = obj.getData(); + } } } return longData; @@ -115,7 +127,10 @@ public class Binary extends Openable implements IBinary { public long getBSS() { if (isObject() || isExecutable() || isSharedLib()) { if (longBSS == -1 || hasChanged()) { - longBSS = ((IBinaryObject)getBinaryFile()).getBSS(); + IBinaryObject obj = getBinaryObject(); + if (obj != null) { + longBSS = obj.getBSS(); + } } } return longBSS; @@ -124,7 +139,10 @@ public class Binary extends Openable implements IBinary { public String getSoname() { if (isSharedLib()) { if (soname == null || hasChanged()) { - soname = ((IBinaryShared)getBinaryFile()).getSoName(); + IBinaryObject obj = getBinaryObject(); + if (obj instanceof IBinaryShared) { + soname = ((IBinaryShared)obj).getSoName(); + } } } return (soname == null ? "" : soname); //$NON-NLS-1$ @@ -133,19 +151,23 @@ public class Binary extends Openable implements IBinary { public boolean isLittleEndian() { if (isObject() || isExecutable() || isSharedLib() || isCore()) { if (endian == null || hasChanged()) { - endian = new Boolean(((IBinaryObject)getBinaryFile()).isLittleEndian()).toString(); + IBinaryObject obj = getBinaryObject(); + if (obj != null) { + endian = new Boolean(obj.isLittleEndian()).toString(); + } } } return Boolean.valueOf(endian).booleanValue(); } - protected IBinaryFile getBinaryFile() { - return binaryFile; + protected IBinaryObject getBinaryObject() { + return binaryObject; } protected int getType() { - if (getBinaryFile() != null && (fBinType == 0 || hasChanged())) { - fBinType = getBinaryFile().getType(); + IBinaryObject obj = getBinaryObject(); + if (obj != null && (fBinType == 0 || hasChanged())) { + fBinType = obj.getType(); } return fBinType; } @@ -197,24 +219,27 @@ public class Binary extends Openable implements IBinary { boolean computeChildren(OpenableInfo info, IResource res) { + boolean ok = false; if (isObject() || isExecutable() || isSharedLib()) { Map hash = new HashMap(); - ISymbol[] symbols = ((IBinaryObject)getBinaryFile()).getSymbols(); - for (int i = 0; i < symbols.length; i++) { - switch (symbols[i].getType()) { - case ISymbol.FUNCTION : - addFunction(info, symbols[i], hash); - break; + IBinaryObject obj = getBinaryObject(); + if (obj != null) { + ISymbol[] symbols = obj.getSymbols(); + for (int i = 0; i < symbols.length; i++) { + switch (symbols[i].getType()) { + case ISymbol.FUNCTION : + addFunction(info, symbols[i], hash); + break; - case ISymbol.VARIABLE : - addVariable(info, symbols[i], hash); - break; + case ISymbol.VARIABLE : + addVariable(info, symbols[i], hash); + break; + } } + ok = true; } - } else { - return false; } - return true; + return ok; } private void addFunction(OpenableInfo info, ISymbol symbol, Map hash) { @@ -288,7 +313,7 @@ public class Binary extends Openable implements IBinary { // set the buffer source if (buffer.getCharacters() == null){ - IBinaryFile bin = getBinaryFile(); + IBinaryObject bin = getBinaryObject(); if (bin != null) { StringBuffer sb = new StringBuffer(); try { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryElement.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryElement.java index 0b77437a19c..474cea9011a 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryElement.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryElement.java @@ -107,7 +107,7 @@ public class BinaryElement extends CElement implements IBinaryElement, ISourceMa if (path != null && path.isAbsolute()) { IResource res = mgr.getCModel().getWorkspace().getRoot().getFileForLocation(path); if (res != null && res.exists() && res.getType() == IResource.FILE) { - ICElement e = CModelManager.getDefault().create(res); + ICElement e = CModelManager.getDefault().create(res, null); if (e instanceof ITranslationUnit) { tu = (ITranslationUnit)e; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java index 05cf2dc653f..a63cdd6df7b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java @@ -6,20 +6,27 @@ package org.eclipse.cdt.internal.core.model; */ import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; +import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ElementChangedEvent; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICModel; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IOutputEntry; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceVisitor; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; public class BinaryRunner { IProject project; Thread runner; + ArchiveContainer vlib; + BinaryContainer vbin; public BinaryRunner(IProject prj) { project = prj; @@ -32,23 +39,48 @@ public class BinaryRunner { if (cproject == null || Thread.currentThread().isInterrupted()) { return; } - ArchiveContainer clib; - BinaryContainer cbin; - cbin = (BinaryContainer)cproject.getBinaryContainer(); - clib = (ArchiveContainer)cproject.getArchiveContainer(); - clib.removeChildren(); - cbin.removeChildren(); + IOutputEntry[] outs = null; try { - cproject.getProject().accept(new Visitor(BinaryRunner.this)); - } catch (CoreException e) { - //e.printStackTrace(); - } catch (Exception e) { - // What is wrong ? - e.printStackTrace(); + outs = cproject.getOutputEntries(); + } catch (CModelException e) { + outs = new IOutputEntry[0]; + } + + vbin = (BinaryContainer)cproject.getBinaryContainer(); + vlib = (ArchiveContainer)cproject.getArchiveContainer(); + vlib.removeChildren(); + vbin.removeChildren(); + IPath projectPath = project.getFullPath(); + for (int i = 0; i < outs.length; i++) { + IPath path = outs[i].getPath(); + if (projectPath.equals(path)) { + try { + project.accept(new Visitor(BinaryRunner.this)); + } catch (CoreException e) { + //e.printStackTrace(); + } catch (Exception e) { + // What is wrong ? + e.printStackTrace(); + } + break; // We are done. + } else if (projectPath.isPrefixOf(path)) { + path = path.removeFirstSegments(projectPath.segmentCount()); + IResource res =project.findMember(path); + if (res != null) { + try { + res.accept(new Visitor(BinaryRunner.this)); + } catch (CoreException e) { + //e.printStackTrace(); + } catch (Exception e) { + // What is wrong ? + e.printStackTrace(); + } + } + } } if (!Thread.currentThread().isInterrupted()) { - fireEvents(cproject, cbin); - fireEvents(cproject, clib); + fireEvents(cproject, vbin); + fireEvents(cproject, vlib); } // Tell the listeners we are done. synchronized(BinaryRunner.this) { @@ -104,10 +136,20 @@ public class BinaryRunner { if (!factory.isTranslationUnit(file)) { IBinaryFile bin = factory.createBinaryFile(file); if (bin != null) { - IResource res = file.getParent(); - ICElement parent = factory.create(res); - // By creating the element, it will be added to the correct (bin/archive)container. - factory.create(parent, file, bin); + ICElement parent = factory.create(file.getParent(), null); + if (bin.getType() == IBinaryFile.ARCHIVE) { + if (parent == null) { + parent = vlib; + } + Archive ar = new Archive(parent, file, (IBinaryArchive)bin); + vlib.addChild(ar); + } else if (bin.getType() == IBinaryFile.EXECUTABLE || bin.getType() == IBinaryFile.SHARED) { + if (parent == null) { + parent = vbin; + } + Binary binary = new Binary(parent, file, (IBinaryObject)bin); + vbin.addChild(binary); + } } } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java index 19e9cef666a..af099c19d85 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java @@ -1,73 +1,144 @@ package org.eclipse.cdt.internal.core.model; /* - * (c) Copyright QNX Software Systems Ltd. 2002. - * All Rights Reserved. + * (c) Copyright QNX Software Systems Ltd. 2002. All Rights Reserved. */ - import java.util.ArrayList; +import java.util.List; import java.util.Map; - +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; +import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.IArchive; import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.ICContainer; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; public class CContainer extends Openable implements ICContainer { + CModelManager factory = CModelManager.getDefault(); - public CContainer (ICElement parent, IResource res) { - this (parent, res, ICElement.C_CCONTAINER); + public CContainer(ICElement parent, IResource res) { + this(parent, res, ICElement.C_CCONTAINER); } - public CContainer (ICElement parent, IResource res, int type) { - super (parent, res, type); + public CContainer(ICElement parent, IResource res, int type) { + super(parent, res, type); } /** * Returns a the collection of binary files in this ccontainer - * + * * @see ICContainer#getBinaries() */ public IBinary[] getBinaries() throws CModelException { - ArrayList list = getChildrenOfType(C_BINARY); + List list = getChildrenOfType(C_BINARY); IBinary[] array = new IBinary[list.size()]; list.toArray(array); return array; } + /** + * @see ICContainer#getBinary(String) + */ + public IBinary getBinary(String name) { + IFile file = getContainer().getFile(new Path(name)); + return getBinary(file); + } + + public IBinary getBinary(IFile file) { + IBinaryFile bin = factory.createBinaryFile(file); + if (bin instanceof IBinaryObject) { + return new Binary(this, file, (IBinaryObject) bin); + } + return new Binary(this, file, null); + } + /** * Returns a the collection of archive files in this ccontainer - * + * * @see ICContainer#getArchives() */ public IArchive[] getArchives() throws CModelException { - ArrayList list = getChildrenOfType(C_ARCHIVE); + List list = getChildrenOfType(C_ARCHIVE); IArchive[] array = new IArchive[list.size()]; list.toArray(array); return array; } + /** + * @see ICContainer#getArchive(String) + */ + public IArchive getArchive(String name) { + IFile file = getContainer().getFile(new Path(name)); + return getArchive(file); + } + + public IArchive getArchive(IFile file) { + IBinaryFile ar = factory.createBinaryFile(file); + if (ar != null && ar.getType() == IBinaryFile.ARCHIVE) { + return new Archive(this, file, (IBinaryArchive) ar); + } + return new Archive(this, file, null); + } + /** * @see ICContainer#getTranslationUnits() */ - public ITranslationUnit[] getTranslationUnit() throws CModelException { - ArrayList list = getChildrenOfType(C_UNIT); + public ITranslationUnit[] getTranslationUnits() throws CModelException { + List list = getChildrenOfType(C_UNIT); ITranslationUnit[] array = new ITranslationUnit[list.size()]; list.toArray(array); return array; } - protected CElementInfo createElementInfo () { + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.model.ICContainer#getTranslationUnit(java.lang.String) + */ + public ITranslationUnit getTranslationUnit(String name) { + IFile file = getContainer().getFile(new Path(name)); + return getTranslationUnit(file); + } + + public ITranslationUnit getTranslationUnit(IFile file) { + return new TranslationUnit(this, file); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.model.ICContainer#getCContainer(java.lang.String) + */ + public ICContainer getCContainer(String name) { + IFolder folder = getContainer().getFolder(new Path(name)); + return getCContainer(folder); + } + + public ICContainer getCContainer(IFolder folder) { + return new CContainer(this, folder); + } + + public IContainer getContainer() { + return (IContainer) getResource(); + } + + protected CElementInfo createElementInfo() { return new CContainerInfo(this); } - + // CHECKPOINT: folders will return the hash code of their path public int hashCode() { return getPath().hashCode(); @@ -76,9 +147,8 @@ public class CContainer extends Openable implements ICContainer { /** * @see Openable */ - protected boolean generateInfos(OpenableInfo info, IProgressMonitor pm, - Map newElements, IResource underlyingResource) throws CModelException { - + protected boolean generateInfos(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) + throws CModelException { boolean validInfo = false; try { IResource res = getResource(); @@ -95,39 +165,60 @@ public class CContainer extends Openable implements ICContainer { return validInfo; } - /* (non-Javadoc) - * Returns an array of non-c resources contained in the receiver. + /* + * (non-Javadoc) Returns an array of non-c resources contained in the + * receiver. + * * @see org.eclipse.cdt.core.model.ICContainer#getNonCResources() */ public Object[] getNonCResources() throws CModelException { - return ((CContainerInfo)getElementInfo()).getNonCResources(getResource()); + return ((CContainerInfo) getElementInfo()).getNonCResources(getResource()); } - protected boolean computeChildren(OpenableInfo info, IResource res) { + protected boolean computeChildren(OpenableInfo info, IResource res) throws CModelException { ArrayList vChildren = new ArrayList(); ArrayList notChildren = new ArrayList(); try { IResource[] resources = null; - if (res != null) { - //System.out.println (" Resource: " + res.getFullPath().toOSString()); - switch(res.getType()) { - case IResource.ROOT: - case IResource.PROJECT: - case IResource.FOLDER: - IContainer container = (IContainer)res; - resources = container.members(false); - break; - - case IResource.FILE: - break; - } + if (res instanceof IContainer) { + //System.out.println (" Resource: " + + // res.getFullPath().toOSString()); + IContainer container = (IContainer) res; + resources = container.members(false); } - if (resources != null) { - CModelManager factory = CModelManager.getDefault(); + ICProject cproject = getCProject(); for (int i = 0; i < resources.length; i++) { // Check for Valid C Element only. - ICElement celement = factory.create(this, resources[i]); + ICElement celement = null; + switch (resources[i].getType()) { + case IResource.FILE : + { + IFile file = (IFile) resources[i]; + if (factory.isTranslationUnit(file)) { + celement = new TranslationUnit(this, file); + } else if (cproject.isOnOutputEntry(file)) { + IBinaryParser.IBinaryFile bin = factory.createBinaryFile(file); + if (bin != null) { + if (bin.getType() == IBinaryFile.ARCHIVE) { + celement = new Archive(this, file, (IBinaryArchive)bin); + ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer(); + vlib.addChild(celement); + } else { + celement = new Binary(this, file, (IBinaryObject)bin); + if (bin.getType() == IBinaryFile.EXECUTABLE || bin.getType() == IBinaryFile.SHARED) { + BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer(); + vbin.addChild(celement); + } + } + } + } + break; + } + case IResource.FOLDER : + celement = new CContainer(this, (IFolder) resources[i]); + break; + } if (celement != null) { vChildren.add(celement); } else { @@ -139,11 +230,22 @@ public class CContainer extends Openable implements ICContainer { //System.out.println (e); //CPlugin.log (e); //e.printStackTrace(); + throw new CModelException(e); } ICElement[] children = new ICElement[vChildren.size()]; vChildren.toArray(children); info.setChildren(children); - ((CContainerInfo)getElementInfo()).setNonCResources(notChildren.toArray()); + ((CContainerInfo) getElementInfo()).setNonCResources(notChildren.toArray()); return true; } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.model.ICContainer#getCContainers() + */ + public ICContainer[] getCContainers() throws CModelException { + // TODO Auto-generated method stub + return null; + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainerInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainerInfo.java index 287e0135365..ef43a6b29c0 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainerInfo.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainerInfo.java @@ -1,3 +1,13 @@ +/********************************************************************** + * Copyright (c) 2002,2003 QNX Software Systems Ltd. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ package org.eclipse.cdt.internal.core.model; import java.util.ArrayList; @@ -7,11 +17,6 @@ import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - /** */ public class CContainerInfo extends OpenableInfo { @@ -42,18 +47,9 @@ public class CContainerInfo extends OpenableInfo { ICElement parent = getElement(); try { IResource[] resources = null; - if (res != null) { - switch(res.getType()) { - case IResource.ROOT: - case IResource.PROJECT: - case IResource.FOLDER: - IContainer container = (IContainer)res; - resources = container.members(false); - break; - - case IResource.FILE: - break; - } + if (res instanceof IContainer) { + IContainer container = (IContainer)res; + resources = container.members(false); } if (resources != null) { @@ -63,7 +59,7 @@ public class CContainerInfo extends OpenableInfo { boolean found = false; for (int j = 0; j < children.length; j++) { IResource r = children[j].getResource(); - if (r.equals(resources[i])){ + if (r != null && r.equals(resources[i])){ found = true; break; } @@ -71,11 +67,6 @@ public class CContainerInfo extends OpenableInfo { if (!found) { notChildren.add(resources[i]); } - // Check for Valid C projects only. - //ICElement celement = factory.create(parent, resources[i]); - //if (celement == null) { - // notChildren.add(resources[i]); - //} } } } catch (CoreException e) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java index e6432790aa9..594d4d76c55 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java @@ -364,7 +364,7 @@ public abstract class CElement extends PlatformObject implements ICElement { } /** - * @see IJavaElement + * @see ICElement */ public ICElement getAncestor(int ancestorType) { ICElement element = this; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModel.java index b067ced75e0..123c6fefae5 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModel.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModel.java @@ -5,19 +5,23 @@ package org.eclipse.cdt.internal.core.model; * All Rights Reserved. */ -import java.util.ArrayList; +import java.util.List; +import java.util.Map; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICModel; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IProgressMonitor; -public class CModel extends CContainer implements ICModel { +public class CModel extends Openable implements ICModel { public CModel () { this(ResourcesPlugin.getWorkspace().getRoot()); @@ -33,12 +37,33 @@ public class CModel extends CContainer implements ICModel { } public ICProject[] getCProjects() { - ArrayList list = getChildrenOfType(C_PROJECT); + List list = getChildrenOfType(C_PROJECT); ICProject[] array= new ICProject[list.size()]; list.toArray(array); return array; } + /** + * Returns the active C project associated with the specified + * resource, or null if no C project yet exists + * for the resource. + * + * @exception IllegalArgumentException if the given resource + * is not one of an IProject, IFolder, or IFile. + */ + public ICProject getCProject(IResource resource) { + switch(resource.getType()){ + case IResource.FOLDER: + return new CProject(this, ((IFolder)resource).getProject()); + case IResource.FILE: + return new CProject(this, ((IFile)resource).getProject()); + case IResource.PROJECT: + return new CProject(this, (IProject)resource); + default: + throw new IllegalArgumentException("element.invalidResourceForProject"); //$NON-NLS-1$ + } + } + public IWorkspace getWorkspace() { return getUnderlyingResource().getWorkspace(); } @@ -105,5 +130,49 @@ public class CModel extends CContainer implements ICModel { public int hashCode() { return resource.hashCode(); } - + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.model.Openable#generateInfos(org.eclipse.cdt.internal.core.model.OpenableInfo, org.eclipse.core.runtime.IProgressMonitor, java.util.Map, org.eclipse.core.resources.IResource) + */ + protected boolean generateInfos(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws CModelException { + boolean validInfo = false; + try { + IResource res = getResource(); + if (res != null && (res instanceof IWorkspaceRoot || res.getProject().isOpen())) { + // put the info now, because computing the roots requires it + CModelManager.getDefault().putInfo(this, info); + validInfo = computeChildren(info, res); + } + } finally { + if (!validInfo) { + CModelManager.getDefault().removeInfo(this); + } + } + return validInfo; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.model.ICModel#getNonCResources() + */ + public Object[] getNonCResources() throws CModelException { + return ((CModelInfo)getElementInfo()).getNonCResources(); + } + + protected boolean computeChildren(OpenableInfo info, IResource res) throws CModelException { + CModelManager factory = CModelManager.getDefault(); + + // determine my children + IWorkspaceRoot root = (IWorkspaceRoot)getResource(); + IProject[] projects = root.getProjects(); + for (int i = 0, max = projects.length; i < max; i++) { + IProject project = projects[i]; + if (factory.hasCNature(project) || factory.hasCCNature(project)) { + ICProject cproject = new CProject(this, project); + info.addChild(cproject); + } + } + ((CModelInfo)getElementInfo()).setNonCResources(null); + return true; + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelInfo.java index f2cac585ec8..f942687a79f 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelInfo.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelInfo.java @@ -24,20 +24,23 @@ public class CModelInfo extends CContainerInfo { * Compute the non-C resources contained in this C project. */ private Object[] computeNonCResources() { + CModelManager mgr = CModelManager.getDefault(); IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); int length = projects.length; Object[] nonCProjects = null; int index = 0; for (int i = 0; i < length; i++) { IProject project = projects[i]; - if (!CProject.hasCNature(project)) { + if (!(mgr.hasCNature(project) || mgr.hasCCNature(project))) { if (nonCProjects == null) { nonCProjects = new Object[length]; } nonCProjects[index++] = project; } } - if (index == 0) return NO_NON_C_RESOURCES; + if (index == 0) { + return NO_NON_C_RESOURCES; + } if (index < length) { System.arraycopy(nonCProjects, 0, nonCProjects = new Object[index], 0, index); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java index 07c76441341..239145f7aa8 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java @@ -23,6 +23,7 @@ import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.core.ICDescriptorListener; import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ElementChangedEvent; import org.eclipse.cdt.core.model.IArchive; @@ -34,8 +35,10 @@ import org.eclipse.cdt.core.model.ICModel; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.IElementChangedListener; import org.eclipse.cdt.core.model.IParent; +import org.eclipse.cdt.core.model.ISourceRoot; import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.internal.core.search.indexing.IndexManager; +import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; @@ -50,6 +53,7 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; public class CModelManager implements IResourceChangeListener, ICDescriptorListener { @@ -150,7 +154,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe //return create(root); } - public ICModel getCModel() { + public CModel getCModel() { return cModel; } @@ -160,30 +164,37 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe IResource res = root.findMember(path); if (res == null) { IPath rootPath = root.getLocation(); - if (path.equals(rootPath)) + if (path.equals(rootPath)) { return getCModel(root); + } res = root.getContainerForLocation(path); - if (res == null || !res.exists()) + if (res == null || !res.exists()) { res = root.getFileForLocation(path); - if (res != null && !res.exists()) + } + if (res != null && !res.exists()) { res = null; + } } // TODO: for extenal resources ?? - return create(res); + return create(res, null); } - public ICElement create (IResource resource) { + public ICElement create (IResource resource, ICProject cproject) { if (resource == null) { return null; } + + if (cproject == null) { + cproject = create(resource.getProject()); + } int type = resource.getType(); switch (type) { case IResource.PROJECT : return create((IProject)resource); case IResource.FILE : - return create((IFile)resource); + return create((IFile)resource, cproject); case IResource.FOLDER : - return create((IFolder)resource); + return create((IFolder)resource, cproject); case IResource.ROOT : return create((IWorkspaceRoot)resource); default : @@ -191,39 +202,137 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe } } - public ICElement create(ICElement parent, IResource resource) { - int type = resource.getType(); - switch (type) { - case IResource.PROJECT : - return create(parent, (IProject)resource); - case IResource.FILE : - return create(parent, (IFile)resource); - case IResource.FOLDER : - return create(parent, (IFolder)resource); - case IResource.ROOT : - return create((IWorkspaceRoot)resource); - default : - return null; + public ICProject create(IProject project) { + if (project == null) { + return null; } + return cModel.getCProject(project); } - public ICElement create(IFile file) { - IResource parent = file.getParent(); - ICElement cparent = null; - if (parent instanceof IFolder) { - cparent = create((IFolder)parent); - } else if (parent instanceof IProject) { - cparent = create((IProject)parent); + public ICModel create(IWorkspaceRoot root) { + return getCModel(); + } + + public ICContainer create(IFolder folder, ICProject cproject) { + if (folder == null) { + return null; } - if (cparent != null) - return create(cparent, file); - return null; + if (cproject == null) { + cproject = create(folder.getProject()); + } + ICContainer celement = null; + IPath resourcePath = folder.getFullPath(); + try { + ISourceRoot[] roots = cproject.getSourceRoots(); + for (int i = 0; i < roots.length; ++i) { + ISourceRoot root = roots[i]; + IPath rootPath = root.getPath(); + if (rootPath.equals(resourcePath)) { + celement = root; + break; // We are done. + } else if (root.isOnSourceEntry(folder)) { + IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount()); + String[] segments = path.segments(); + ICContainer cfolder = root; + for (int j = 0; j < segments.length; j++) { + IResource res = cfolder.getResource(); + if (res instanceof IContainer) { + IContainer container = (IContainer)res; + res = container.findMember(new Path(segments[j])); + if (res instanceof IFolder) { + cfolder = cfolder.getCContainer(segments[j]); + } else { + cfolder = null; + break; + } + } + } + if (cfolder != null) { + celement = cfolder; + } + } + } + } catch (CModelException e) { + // + } + return celement; } - public ICElement create(ICElement parent, IFile file) { - return create(parent, file, null); - } + public ICElement create(IFile file, ICProject cproject) { + if (file == null) { + return null; + } + if (cproject == null) { + cproject = create(file.getProject()); + } + ICElement celement = null; + try { + ISourceRoot[] roots = cproject.getSourceRoots(); + for (int i = 0; i < roots.length; ++i) { + ISourceRoot root = roots[i]; + IPath rootPath = root.getPath(); + if (root.isOnSourceEntry(file)) { + IPath resourcePath = file.getFullPath(); + IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount()); + String[] segments = path.segments(); + ICContainer cfolder = root; + for (int j = 0; j < segments.length; j++) { + IResource res = cfolder.getResource(); + if (res instanceof IContainer) { + IContainer container = (IContainer)res; + res = container.findMember(new Path(segments[j])); + if (res instanceof IFolder) { + cfolder = cfolder.getCContainer(segments[j]); + } else if (res instanceof IFile) { + IFile f = (IFile)res; + if (isTranslationUnit(f)) { + celement = new TranslationUnit(cfolder, f); + } else if (cproject.isOnOutputEntry(f)) { + IBinaryFile bin = createBinaryFile(f); + if (bin != null) { + if (bin.getType() == IBinaryFile.ARCHIVE) { + celement = new Archive(cfolder, f, (IBinaryArchive)bin); + ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer(); + vlib.addChild(celement); + } else { + celement = new Binary(cfolder, f, (IBinaryObject)bin); + if (bin.getType() == IBinaryFile.EXECUTABLE || bin.getType() == IBinaryFile.SHARED) { + BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer(); + vbin.addChild(celement); + } + } + } + } + break; + } + } + } + } + } + // try in the outputEntry + if (celement == null && cproject.isOnOutputEntry(file)) { + IBinaryFile bin = createBinaryFile(file); + if (bin != null) { + if (bin.getType() == IBinaryFile.ARCHIVE) { + ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer(); + celement = new Archive(vlib, file, (IBinaryArchive)bin); + vlib.addChild(celement); + } else { + BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer(); + celement = new Binary(vbin, file, (IBinaryObject)bin); + if (bin.getType() == IBinaryFile.EXECUTABLE || bin.getType() == IBinaryFile.SHARED) { + vbin.addChild(celement); + } + } + } + } + } catch (CModelException e) { + // + } + return celement; + } + /* public synchronized ICElement create(ICElement parent, IFile file, IBinaryFile bin) { ICElement cfile = null; @@ -261,45 +370,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe } return cfile; } - - public ICContainer create(IFolder folder) { - IResource parent = folder.getParent(); - ICElement cparent = null; - if (parent instanceof IFolder) { - cparent = create ((IFolder)parent); - } else if (parent instanceof IProject) { - cparent = create ((IProject)parent); - } - if (cparent != null) - return (ICContainer) create (cparent, folder); - return null; - } - - public ICContainer create(ICElement parent, IFolder folder) { - return new CContainer(parent, folder); - } - - public ICProject create(IProject project) { - IResource parent = project.getParent(); - ICElement celement = null; - if (parent instanceof IWorkspaceRoot) { - celement = create ((IWorkspaceRoot)parent); - } - return create(celement, project); - } - - public ICProject create(ICElement parent, IProject project) { - if (hasCNature(project)){ - return new CProject(parent, project); - } - return null; - } - - public ICModel create(IWorkspaceRoot root) { - return getCModel(); - //return new CModel(root); - } - +*/ public void releaseCElement(ICElement celement) { // Guard. @@ -391,7 +462,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe // Remove the child from the parent list. Parent parent = (Parent)celement.getParent(); - if (parent != null) { + if (parent != null && peekAtInfo(parent) != null) { parent.removeChild(celement); } @@ -486,7 +557,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe } public boolean isSharedLib(IFile file) { - ICElement celement = create(file); + ICElement celement = create(file, null); if (celement instanceof IBinary) { return ((IBinary)celement).isSharedLib(); } @@ -494,7 +565,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe } public boolean isObject(IFile file) { - ICElement celement = create(file); + ICElement celement = create(file, null); if (celement instanceof IBinary) { return ((IBinary)celement).isObject(); } @@ -502,7 +573,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe } public boolean isExecutable(IFile file) { - ICElement celement = create(file); + ICElement celement = create(file, null); if (celement instanceof IBinary) { return ((IBinary)celement).isExecutable(); } @@ -510,12 +581,12 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe } public boolean isBinary(IFile file) { - ICElement celement = create(file); + ICElement celement = create(file, null); return (celement instanceof IBinary); } public boolean isArchive(IFile file) { - ICElement celement = create(file); + ICElement celement = create(file, null); return(celement instanceof IArchive); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java index 53bffeed28c..2ede4a63b99 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java @@ -17,6 +17,7 @@ import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IArchiveContainer; @@ -26,8 +27,13 @@ import org.eclipse.cdt.core.model.ICModelStatusConstants; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ILibraryEntry; import org.eclipse.cdt.core.model.ILibraryReference; +import org.eclipse.cdt.core.model.IOutputEntry; import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.cdt.core.model.ISourceEntry; +import org.eclipse.cdt.core.model.ISourceRoot; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -36,6 +42,8 @@ import org.eclipse.core.runtime.QualifiedName; public class CProject extends CContainer implements ICProject { + private static final String CUSTOM_DEFAULT_OPTION_VALUE = "#\r\n\r#custom-non-empty-default-value#\r\n\r#"; //$NON-NLS-1$ + public CProject(ICElement parent, IProject project) { super(parent, project, CElement.C_PROJECT); } @@ -52,8 +60,6 @@ public class CProject extends CContainer implements ICProject { return getUnderlyingResource().getProject(); } - private static final String CUSTOM_DEFAULT_OPTION_VALUE = "#\r\n\r#custom-non-empty-default-value#\r\n\r#"; //$NON-NLS-1$ - public ICElement findElement(IPath path) throws CModelException { ICElement celem = null; if (path.isAbsolute()) { @@ -126,8 +132,8 @@ public class CProject extends CContainer implements ICProject { if (bin != null) { if (bin.getType() == IBinaryFile.ARCHIVE) { lib = new LibraryReferenceArchive(cproject, entry, (IBinaryArchive)bin); - } else { - lib = new LibraryReferenceShared(cproject, entry, bin); + } else if (bin instanceof IBinaryObject){ + lib = new LibraryReferenceShared(cproject, entry, (IBinaryObject)bin); } break; } @@ -323,4 +329,159 @@ public class CProject extends CContainer implements ICProject { CoreModel.getDefault().setRawPathEntries(this, newEntries, monitor); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.model.ICProject#getSourceRoot(org.eclipse.cdt.core.model.ISourceEntry) + */ + public ISourceRoot getSourceRoot(ISourceEntry entry) throws CModelException { + IPath p = getPath(); + IPath sp = entry.getPath(); + if (p.isPrefixOf(sp)) { + int count = sp.matchingFirstSegments(p); + sp = sp.removeFirstSegments(count); + IResource res = null; + if (sp.isEmpty()) { + res = getProject(); + } else { + res = getProject().findMember(sp); + } + if (res != null) { + return new SourceRoot(this, res, entry); + } + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.model.ICProject#getSourceRoots() + */ + public ISourceRoot[] getSourceRoots() throws CModelException { + return computeSourceRoots(); + } + + public IOutputEntry[] getOutputEntries() throws CModelException { + IPathEntry[] entries = getResolvedPathEntries(); + ArrayList list = new ArrayList(entries.length); + for (int i = 0; i < entries.length; i++) { + if (entries[i].getEntryKind() == IPathEntry .CDT_OUTPUT) { + list.add(entries[i]); + } + } + IOutputEntry[] outputs = new IOutputEntry[list.size()]; + list.toArray(outputs); + return outputs; + } + + public boolean isOnOutputEntry(IResource resource) { + IPath path = resource.getFullPath(); + + // ensure that folders are only excluded if all of their children are excluded + if (resource.getType() == IResource.FOLDER) { + path = path.append("*"); //$NON-NLS-1$ + } + + try { + IOutputEntry[] entries = getOutputEntries(); + for (int i = 0; i < entries.length; i++) { + boolean on = isOnOutputEntry(entries[i], path); + if (on) { + return on; + } + } + } catch (CModelException e) { + // + } + return false; + } + + private boolean isOnOutputEntry(IOutputEntry entry, IPath path) { + if (entry.getPath().isPrefixOf(path) + && !Util.isExcluded(path, entry.fullExclusionPatternChars())) { + return true; + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.model.Openable#generateInfos(org.eclipse.cdt.internal.core.model.OpenableInfo, org.eclipse.core.runtime.IProgressMonitor, java.util.Map, org.eclipse.core.resources.IResource) + */ + protected boolean generateInfos(OpenableInfo info, IProgressMonitor pm, + Map newElements, IResource underlyingResource) + throws CModelException { + boolean validInfo = false; + try { + IResource res = getResource(); + if (res != null && (res instanceof IWorkspaceRoot || res.getProject().isOpen())) { + // put the info now, because computing the roots requires it + CModelManager.getDefault().putInfo(this, info); + validInfo = computeSourceRoots(info, res); + } + } finally { + if (!validInfo) { + CModelManager.getDefault().removeInfo(this); + } + } + return validInfo; + } + + protected ISourceRoot[] computeSourceRoots() throws CModelException { + IPathEntry[] entries = getResolvedPathEntries(); + ArrayList list = new ArrayList(entries.length); + for (int i = 0; i < entries.length; i++) { + if (entries[i].getEntryKind() == IPathEntry.CDT_SOURCE) { + ISourceEntry sourceEntry = (ISourceEntry)entries[i]; + ISourceRoot root = getSourceRoot(sourceEntry); + if (root != null) { + list.add(root); + } + } + } + ISourceRoot[] roots = new ISourceRoot[list.size()]; + list.toArray(roots); + return roots; + } + + protected boolean computeSourceRoots(OpenableInfo info, IResource res) throws CModelException { + info.setChildren(computeSourceRoots()); + if (info instanceof CProjectInfo) { + CProjectInfo pinfo = (CProjectInfo)info; + pinfo.setNonCResources(null); + } + + return true; + } + + /* + * @see ICProject + */ + public boolean isOnClasspath(ICElement element) { + try { + ISourceRoot[] roots = getSourceRoots(); + for (int i = 0; i < roots.length; i++) { + if (roots[i].isOnSourceEntry(element)) { + return true; + } + } + } catch (CModelException e) { + // .. + } + return false; + } + + /* + * @see ICProject + */ + public boolean isOnClasspath(IResource resource) { + try { + ISourceRoot[] roots = getSourceRoots(); + for (int i = 0; i < roots.length; i++) { + if (roots[i].isOnSourceEntry(resource)) { + return true; + } + } + } catch (CModelException e) { + // + } + return false; + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java index 03c05ecd5cd..61642c0ae07 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java @@ -5,8 +5,16 @@ package org.eclipse.cdt.internal.core.model; * All Rights Reserved. */ +import java.util.ArrayList; + import org.eclipse.cdt.core.model.IArchiveContainer; import org.eclipse.cdt.core.model.IBinaryContainer; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ISourceRoot; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; /** * Info for ICProject. @@ -39,4 +47,65 @@ class CProjectInfo extends CContainerInfo { return vLib; } + /** + * @return + */ + public Object[] getNonCResources(IResource res) { + if (nonCResources != null) + return nonCResources; + + // determine if src == project and/or if bin == project + IPath projectPath = res.getProject().getFullPath(); + ISourceRoot root = null; + ICElement[] elements = getChildren(); + for (int i = 0; i < elements.length; i++) { + if (elements[i] instanceof ISourceRoot) { + ISourceRoot source = (ISourceRoot)elements[i]; + if (getElement().getPath().equals(source.getPath())) { + root = source; + break; + } + } + } + + ArrayList notChildren = new ArrayList(); + ICElement parent = getElement(); + try { + IResource[] resources = null; + if (res instanceof IContainer) { + IContainer container = (IContainer)res; + resources = container.members(false); + } + + if (resources != null) { + CModelManager factory = CModelManager.getDefault(); + for (int i = 0; i < resources.length; i++) { + ICElement[] children; + if (root == null) { + children = getChildren(); + } else { + children = root.getChildren(); + } + boolean found = false; + for (int j = 0; j < children.length; j++) { + IResource r = children[j].getResource(); + if (r != null && r.equals(resources[i])){ + found = true; + break; + } + } + if (!found) { + notChildren.add(resources[i]); + } + } + } + } catch (CoreException e) { + //System.out.println (e); + //CPlugin.log (e); + //e.printStackTrace(); + } + setNonCResources(notChildren.toArray()); + return nonCResources; + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyResourceElementsOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyResourceElementsOperation.java index e4b4a6cf1a2..111d1537df3 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyResourceElementsOperation.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyResourceElementsOperation.java @@ -155,7 +155,7 @@ public class CopyResourceElementsOperation extends MultiOperation { // update new resource content // register the correct change deltas - ICElement cdest = CModelManager.getDefault().create(destFile); + ICElement cdest = CModelManager.getDefault().create(destFile, null); prepareDeltas(source, cdest); fCreatedElements.add(cdest); //if (newName != null) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java index 102bad9103b..00bd1c5b9ca 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java @@ -9,13 +9,16 @@ import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IArchiveContainer; import org.eclipse.cdt.core.model.IBinaryContainer; +import org.eclipse.cdt.core.model.ICContainer; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElementDelta; import org.eclipse.cdt.core.model.ICModel; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.IParent; +import org.eclipse.cdt.core.model.ISourceRoot; import org.eclipse.cdt.internal.core.search.indexing.IndexManager; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceDelta; @@ -53,16 +56,38 @@ public class DeltaProcessor { * Returns null if none was found. */ protected ICElement createElement(IResource resource) { - CModelManager manager = CModelManager.getDefault(); - if (resource == null) + if (resource == null) { return null; - ICElement celement = manager.create(resource); + } + CModelManager manager = CModelManager.getDefault(); + ICElement celement = manager.create(resource, null); if (celement == null) { - ICElement parent = manager.create(resource.getParent()); // Probably it was deleted, find it + IResource resParent = resource.getParent(); + ICElement parent = null; + // the sourceRoot == Project + if (resParent instanceof IProject) { + ICProject cpj = manager.create((IProject)resParent); + if (cpj != null) { + try { + ISourceRoot[] roots = cpj.getSourceRoots(); + for (int i = 0; i < roots.length; i++) { + if (roots[i].isOnSourceEntry(resource)) { + parent = roots[i]; + break; + } + } + } catch (CModelException e) { + // + } + } + } + if (parent == null) { + parent = manager.create(resParent, null); + } if (parent instanceof IParent) { ICElement[] children; - if ( CModelManager.getDefault().peekAtInfo(parent) != null ) { + if (manager.peekAtInfo(parent) != null ) { children = ((CElement)parent).getElementInfo().getChildren(); for (int i = 0; i < children.length; i++) { IResource res = children[i].getResource(); @@ -72,40 +97,64 @@ public class DeltaProcessor { } } } - // BUG 36424: - // The Binary may only be visible in the BinaryContainers - if (celement == null) { - ICProject cproj = parent.getCProject(); - if (cproj != null) { - IBinaryContainer bin = cproj.getBinaryContainer(); - children = ((CElement)bin).getElementInfo().getChildren(); - for (int i = 0; i < children.length; i++) { - IResource res = children[i].getResource(); - if (res != null && res.equals(resource)) { - celement = children[i]; - break; - } + } + } + + // BUG 36424: + // The Binary may only be visible in the BinaryContainers + if (celement == null) { + ICElement[] children; + ICProject cproj = manager.create(resource.getProject()); + if (cproj != null && manager.peekAtInfo(cproj) != null) { + IBinaryContainer bin = cproj.getBinaryContainer(); + if (manager.peekAtInfo(bin) != null) { + children = ((CElement)bin).getElementInfo().getChildren(); + for (int i = 0; i < children.length; i++) { + IResource res = children[i].getResource(); + if (res != null && res.equals(resource)) { + celement = children[i]; + break; } } } - // BUG 36424: - // The Archive may only be visible in the ArchiveContainers - if (celement == null) { - ICProject cproj = parent.getCProject(); - if (cproj != null) { - IArchiveContainer bin = cproj.getArchiveContainer(); - children = ((CElement)bin).getElementInfo().getChildren(); - for (int i = 0; i < children.length; i++) { - IResource res = children[i].getResource(); - if (res != null && res.equals(resource)) { - celement = children[i]; - break; - } + } + } + // BUG 36424: + // The Archive may only be visible in the ArchiveContainers + if (celement == null) { + ICElement[] children; + ICProject cproj = manager.create(resource.getProject()); + if (cproj != null && manager.peekAtInfo(cproj) != null) { + IArchiveContainer ar = cproj.getArchiveContainer(); + if (manager.peekAtInfo(ar) != null) { + children = ((CElement)ar).getElementInfo().getChildren(); + for (int i = 0; i < children.length; i++) { + IResource res = children[i].getResource(); + if (res != null && res.equals(resource)) { + celement = children[i]; + break; } - } + } + } + } + } + + // return an handler + if (celement == null) { + IResource resParent = resource.getParent(); + ICElement parent = manager.create(resParent, null); + if (parent instanceof ICContainer) { + String name = resource.getName(); + if (resource instanceof IFile) { + if (manager.isValidTranslationUnitName(name)) { + celement = ((ICContainer)parent).getTranslationUnit(name); + } + } else if (resource instanceof IFolder) { + celement = ((ICContainer)parent).getCContainer(name); } } } + return celement; } @@ -490,7 +539,7 @@ public class DeltaProcessor { switch (element.getElementType()) { case ICElement.C_PROJECT : - this.indexManager.removeIndexFamily(element.getCProject().getProject().getFullPath()); + indexManager.removeIndexFamily(element.getCProject().getProject().getFullPath()); // NB: Discarding index jobs belonging to this project was done during PRE_DELETE break; // NB: Update of index if project is opened, closed, or its c nature is added or removed @@ -498,7 +547,7 @@ public class DeltaProcessor { case ICElement.C_UNIT: IFile file = (IFile) delta.getResource(); - indexManager.remove(file.getFullPath().toString(), file.getProject().getProject().getFullPath()); + indexManager.remove(file.getFullPath().toString(), file.getProject().getFullPath()); break; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java index ba1f2ab3fc7..8ea0c7f4e3c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java @@ -16,13 +16,11 @@ import org.eclipse.cdt.core.model.IIncludeEntry; import org.eclipse.core.runtime.IPath; public class IncludeEntry extends APathEntry implements IIncludeEntry { - IPath includePath; boolean isSystemInclude; - public IncludeEntry(IPath path, IPath includePath, boolean isSystemInclude, boolean isRecursive, - IPath[] exclusionPatterns) { - super(IIncludeEntry.CDT_INCLUDE, path, isRecursive, exclusionPatterns, path == null); + public IncludeEntry(IPath path, IPath includePath, boolean isSystemInclude, IPath[] exclusionPatterns) { + super(IIncludeEntry.CDT_INCLUDE, path, exclusionPatterns, path == null); this.includePath = includePath; this.isSystemInclude = isSystemInclude; } @@ -76,5 +74,4 @@ public class IncludeEntry extends APathEntry implements IIncludeEntry { } return super.equals(obj); } - } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReferenceShared.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReferenceShared.java index 7c5411a8660..b52209e7be2 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReferenceShared.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReferenceShared.java @@ -6,7 +6,7 @@ */ package org.eclipse.cdt.internal.core.model; -import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ILibraryEntry; import org.eclipse.cdt.core.model.ILibraryReference; @@ -20,7 +20,7 @@ public class LibraryReferenceShared extends Binary implements ILibraryReference ILibraryEntry entry; - public LibraryReferenceShared(ICElement parent, ILibraryEntry e, IBinaryFile bin) { + public LibraryReferenceShared(ICElement parent, ILibraryEntry e, IBinaryObject bin) { super(parent, e.getPath(), bin); setElementType(ICElement.C_VCONTAINER); entry = e; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java index 1d1fc433e7e..1c45543a55b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java @@ -20,9 +20,8 @@ public class MacroEntry extends APathEntry implements IMacroEntry { String macroName; String macroValue; - public MacroEntry (IPath path, String macroName, String macroValue, - boolean isRecursive, IPath[] exclusionPatterns, boolean isExported) { - super(IMacroEntry.CDT_MACRO, path, isRecursive, exclusionPatterns, isExported); + public MacroEntry (IPath path, String macroName, String macroValue, IPath[] exclusionPatterns) { + super(IMacroEntry.CDT_MACRO, path, exclusionPatterns, path == null); this.macroName = macroName; this.macroValue = macroValue; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/OutputEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/OutputEntry.java new file mode 100644 index 00000000000..ce538c5062f --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/OutputEntry.java @@ -0,0 +1,50 @@ +/********************************************************************** + * Copyright (c) 2002,2003,2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ +package org.eclipse.cdt.internal.core.model; + +import org.eclipse.cdt.core.model.IOutputEntry; +import org.eclipse.core.runtime.IPath; + +/** + * OutputEntry + */ +public class OutputEntry extends APathEntry implements IOutputEntry { + /** + * @param kind + * @param path + * @param isRecursive + * @param exclusionPatterns + * @param isExported + */ + public OutputEntry(IPath path, IPath[] exclusionPatterns, boolean isExported) { + super(CDT_OUTPUT, path, exclusionPatterns, isExported); + } + + public boolean equals(Object obj) { + if (obj instanceof IOutputEntry) { + IOutputEntry otherEntry = (IOutputEntry) obj; + if (!super.equals(otherEntry)) { + return false; + } + if (path == null) { + if (otherEntry.getPath() != null) { + return false; + } + } else { + if (!path.toString().equals(otherEntry.getPath().toString())) { + return false; + } + } + return true; + } + return super.equals(obj); + } +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Parent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Parent.java index 375a97925a9..3908962a9dd 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Parent.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Parent.java @@ -6,6 +6,7 @@ package org.eclipse.cdt.internal.core.model; */ import java.util.ArrayList; +import java.util.List; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.IParent; @@ -56,7 +57,7 @@ public abstract class Parent extends CElement implements IParent { * @param type * @return ArrayList */ - public ArrayList getChildrenOfType(int type){ + public List getChildrenOfType(int type){ ICElement[] children = getChildren(); int size = children.length; ArrayList list = new ArrayList(size); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java index e61ccf26893..d5b77636678 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java @@ -81,6 +81,8 @@ public class PathEntry implements IPathEntry { return IPathEntry.CDT_MACRO; if (kindStr.equalsIgnoreCase("con")) //$NON-NLS-1$ return IPathEntry.CDT_CONTAINER; + if (kindStr.equalsIgnoreCase("out")) //$NON-NLS-1$ + return IPathEntry.CDT_OUTPUT; return -1; } @@ -104,6 +106,8 @@ public class PathEntry implements IPathEntry { return "mac"; //$NON-NLS-1$ case IPathEntry.CDT_CONTAINER : return "con"; //$NON-NLS-1$ + case IPathEntry.CDT_OUTPUT: + return "out"; //$NON-NLS-1$ default : return "unknown"; //$NON-NLS-1$ } @@ -125,9 +129,9 @@ public class PathEntry implements IPathEntry { case IPathEntry.CDT_SOURCE : buffer.append("CDT_SOURCE"); //$NON-NLS-1$ break; - //case IPathEntry.CDT_VARIABLE : - // buffer.append("CDT_VARIABLE"); //$NON-NLS-1$ - // break; + case IPathEntry.CDT_OUTPUT : + buffer.append("CDT_OUTPUT"); //$NON-NLS-1$ + break; case IPathEntry.CDT_INCLUDE : buffer.append("CDT_INCLUDE"); //$NON-NLS-1$ break; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java index 8d9ce47bc00..4e5881fe78d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java @@ -9,14 +9,12 @@ * * Contributors: * QNX Software Systems - Initial API and implementation -***********************************************************************/ - + ***********************************************************************/ package org.eclipse.cdt.internal.core.model; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; - import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.core.model.CModelException; @@ -30,6 +28,7 @@ import org.eclipse.cdt.core.model.IContainerEntry; import org.eclipse.cdt.core.model.IIncludeEntry; import org.eclipse.cdt.core.model.ILibraryEntry; import org.eclipse.cdt.core.model.IMacroEntry; +import org.eclipse.cdt.core.model.IOutputEntry; import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.core.model.IPathEntryContainer; import org.eclipse.cdt.core.model.IProjectEntry; @@ -57,7 +56,6 @@ import org.w3c.dom.NodeList; * */ public class PathEntryManager { - static String CONTAINER_INITIALIZER_EXTPOINT_ID = "pathEntryContainerInitializer"; //$NON-NLS-1$ static String PATH_ENTRY = "pathentry"; //$NON-NLS-1$ static String PATH_ENTRY_ID = "org.eclipse.cdt.core.pathentry"; //$NON-NLS-1$ @@ -68,28 +66,22 @@ public class PathEntryManager { static String ATTRIBUTE_ROOTPATH = "roopath"; //$NON-NLS-1$ static String ATTRIBUTE_PREFIXMAPPING = "prefixmapping"; //$NON-NLS-1$ static String ATTRIBUTE_EXCLUDING = "excluding"; //$NON-NLS-1$ - static String ATTRIBUTE_RECUSIVE = "recusive"; //$NON-NLS-1$ - static String ATTRIBUTE_OUTPUT = "output"; //$NON-NLS-1$ static String ATTRIBUTE_INCLUDE = "include"; //$NON-NLS-1$ static String ATTRIBUTE_SYSTEM = "system"; //$NON-NLS-1$ static String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$ static String ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$ static String VALUE_TRUE = "true"; //$NON-NLS-1$ - final static IPathEntry[] EMPTY = {}; - /** - * An empty array of strings indicating that a project doesn't have any prerequesite projects. + * An empty array of strings indicating that a project doesn't have any + * prerequesite projects. */ static final String[] NO_PREREQUISITES = new String[0]; - /** * pathentry containers pool */ public static HashMap Containers = new HashMap(5); - HashMap resolvedMap = new HashMap(); - private static PathEntryManager pathEntryManager; private PathEntryManager() { @@ -137,7 +129,7 @@ public class PathEntryManager { public void setRawPathEntries(ICProject cproject, IPathEntry[] newEntries, IProgressMonitor monitor) throws CModelException { try { - IPathEntry[] oldResolvedEntries = (IPathEntry[])resolvedMap.get(cproject); + IPathEntry[] oldResolvedEntries = (IPathEntry[]) resolvedMap.get(cproject); resolvedMap.put(cproject, null); SetPathEntriesOperation op = new SetPathEntriesOperation(cproject, oldResolvedEntries, newEntries); CModelManager.getDefault().runOperation(op, monitor); @@ -163,31 +155,48 @@ public class PathEntryManager { } catch (CoreException e) { throw new CModelException(e); } + + // Checks/hacks for backward compatibility .. + // if no output is specified we return the project + // if no source is specified we return the project + boolean foundSource = false; + boolean foundOutput = false; + for (int i = 0; i < pathEntries.size(); i++) { + IPathEntry rawEntry = (IPathEntry)pathEntries.get(i); + if (rawEntry.getEntryKind() == IPathEntry.CDT_SOURCE) { + foundSource = true; + } + if (rawEntry.getEntryKind() == IPathEntry.CDT_OUTPUT) { + foundOutput = true; + } + } + + if (!foundSource) { + pathEntries.add(CoreModel.newSourceEntry(cproject.getPath())); + } + if (!foundOutput) { + pathEntries.add(CoreModel.newOutputEntry(cproject.getPath())); + } return (IPathEntry[]) pathEntries.toArray(EMPTY); } - public void setPathEntryContainer(ICProject[] affectedProjects, IPathEntryContainer newContainer, IProgressMonitor monitor) throws CModelException { - + public void setPathEntryContainer(ICProject[] affectedProjects, IPathEntryContainer newContainer, IProgressMonitor monitor) + throws CModelException { if (monitor != null && monitor.isCanceled()) { return; } - IPath containerPath = (newContainer == null) ? new Path("") : newContainer.getPath(); //$NON-NLS-1$ final int projectLength = affectedProjects.length; final ICProject[] modifiedProjects = new ICProject[projectLength]; System.arraycopy(affectedProjects, 0, modifiedProjects, 0, projectLength); final IPathEntry[][] oldResolvedEntries = new IPathEntry[projectLength][]; - // filter out unmodified project containers int remaining = 0; for (int i = 0; i < projectLength; i++) { - if (monitor != null && monitor.isCanceled()) { return; } - ICProject affectedProject = affectedProjects[i]; - boolean found = false; IPathEntry[] rawPath = getRawPathEntries(affectedProject); for (int j = 0, cpLength = rawPath.length; j < cpLength; j++) { @@ -201,26 +210,26 @@ public class PathEntryManager { } } if (!found) { - // filter out this project - does not reference the container path + // filter out this project - does not reference the container + // path modifiedProjects[i] = null; continue; } IPathEntryContainer oldContainer = containerGet(affectedProject, containerPath); if (oldContainer != null && newContainer != null && oldContainer.equals(newContainer)) { - modifiedProjects[i] = null; // filter out this project - container did not change + modifiedProjects[i] = null; // filter out this project - + // container did not change continue; } remaining++; - oldResolvedEntries[i] = (IPathEntry[])resolvedMap.get(affectedProject); + oldResolvedEntries[i] = (IPathEntry[]) resolvedMap.get(affectedProject); resolvedMap.put(affectedProject, null); containerPut(affectedProject, containerPath, newContainer); } - // Nothing change. if (remaining == 0) { return; } - // trigger model refresh try { CoreModel.run(new IWorkspaceRunnable() { @@ -235,18 +244,16 @@ public class PathEntryManager { if (affectedProject == null) { continue; // was filtered out } - IPathEntry[] newEntries = getResolvedPathEntries(affectedProject); - ICElementDelta[] deltas = generatePathEntryDeltas(affectedProject, - oldResolvedEntries[i], newEntries); + ICElementDelta[] deltas = generatePathEntryDeltas(affectedProject, oldResolvedEntries[i], newEntries); if (deltas.length > 0) { shouldFire = true; for (int j = 0; j < deltas.length; j++) { mgr.registerCModelDelta(deltas[j]); } } - - //affectedProject.setRawPathEntries(affectedProject.getRawPathEntries(), progressMonitor); + //affectedProject.setRawPathEntries(affectedProject.getRawPathEntries(), + // progressMonitor); } if (shouldFire) { mgr.fire(ElementChangedEvent.POST_CHANGE); @@ -267,33 +274,35 @@ public class PathEntryManager { } public IPathEntryContainer getPathEntryContainer(final IPath containerPath, final ICProject project) throws CModelException { - // Try the cache. IPathEntryContainer container = containerGet(project, containerPath); - if (container == null) { final PathEntryContainerInitializer initializer = getPathEntryContainerInitializer(containerPath.segment(0)); if (initializer != null) { containerPut(project, containerPath, container); boolean ok = false; try { - // wrap initializer call with Safe runnable in case initializer would be + // wrap initializer call with Safe runnable in case + // initializer would be // causing some grief Platform.run(new ISafeRunnable() { public void handleException(Throwable exception) { - //Util.log(exception, "Exception occurred in container initializer: "+initializer); //$NON-NLS-1$ + //Util.log(exception, "Exception occurred in + // container initializer: "+initializer); + // //$NON-NLS-1$ } + public void run() throws Exception { initializer.initialize(containerPath, project); } }); - // retrieve value (if initialization was successful) container = containerGet(project, containerPath); ok = true; } finally { if (!ok) { - containerPut(project, containerPath, null); // flush cache + containerPut(project, containerPath, null); // flush + // cache } } } @@ -302,20 +311,21 @@ public class PathEntryManager { } /** - * Helper method finding the container initializer registered for a given container ID or null - * if none was found while iterating over the contributions to extension point to the extension point + * Helper method finding the container initializer registered for a given + * container ID or null if none was found while iterating + * over the contributions to extension point to the extension point * "org.eclipse.cdt.core.PathEntryContainerInitializer". *

- * A containerID is the first segment of any container path, used to identify the registered container initializer. + * A containerID is the first segment of any container path, used to + * identify the registered container initializer. *

* * @param containerID - * a containerID identifying a registered initializer - * @return PathEntryContainerInitializer - the registered container initializer or null if none was - * found. + * @return PathEntryContainerInitializer - the registered container + * initializer or null if none was found. */ public PathEntryContainerInitializer getPathEntryContainerInitializer(String containerID) { - Plugin core = CCorePlugin.getDefault(); if (core == null) { return null; @@ -369,7 +379,7 @@ public class PathEntryManager { ArrayList prerequisites = new ArrayList(); for (int i = 0, length = entries.length; i < length; i++) { if (entries[i].getEntryKind() == IPathEntry.CDT_PROJECT) { - IProjectEntry entry = (IProjectEntry)entries[i]; + IProjectEntry entry = (IProjectEntry) entries[i]; prerequisites.add(entry.getPath().lastSegment()); } } @@ -382,6 +392,7 @@ public class PathEntryManager { } return NO_PREREQUISITES; } + public void saveRawPathEntries(ICProject cproject, IPathEntry[] newRawEntries) throws CModelException { try { ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(cproject.getProject()); @@ -392,7 +403,6 @@ public class PathEntryManager { rootElement.removeChild(child); child = rootElement.getFirstChild(); } - // Save the entries if (newRawEntries != null && newRawEntries.length > 0) { // Serialize the include paths @@ -410,7 +420,6 @@ public class PathEntryManager { CModelManager manager = CModelManager.getDefault(); boolean needToUpdateDependents = false; boolean hasDelta = false; - // Check the removed entries. if (oldEntries != null) { for (int i = 0; i < oldEntries.length; i++) { @@ -425,8 +434,7 @@ public class PathEntryManager { } // Was it deleted. if (!found) { - ICElementDelta delta = - makePathEntryDelta(cproject, oldEntries[i], true); + ICElementDelta delta = makePathEntryDelta(cproject, oldEntries[i], true); if (delta != null) { list.add(delta); } @@ -447,8 +455,7 @@ public class PathEntryManager { } // is it new? if (!found) { - ICElementDelta delta = - makePathEntryDelta(cproject, newEntries[i], false); + ICElementDelta delta = makePathEntryDelta(cproject, newEntries[i], false); if (delta != null) { list.add(delta); } @@ -471,25 +478,25 @@ public class PathEntryManager { ISourceEntry source = (ISourceEntry) entry; IPath path = source.getPath(); celement = CoreModel.getDefault().create(path); - flag = (removed) ? ICElementDelta.F_REMOVED_PATHENTRY_SOURCE : ICElementDelta.F_ADDED_PATHENTRY_SOURCE; + flag = (removed) ? ICElementDelta.F_REMOVED_PATHENTRY_SOURCE : ICElementDelta.F_ADDED_PATHENTRY_SOURCE; } else if (kind == IPathEntry.CDT_LIBRARY) { ILibraryEntry lib = (ILibraryEntry) entry; - celement = CProject.getLibraryReference(cproject, null,lib); - flag = (removed) ? ICElementDelta.F_ADDED_PATHENTRY_LIBRARY : ICElementDelta.F_REMOVED_PATHENTRY_LIBRARY; + celement = CProject.getLibraryReference(cproject, null, lib); + flag = (removed) ? ICElementDelta.F_ADDED_PATHENTRY_LIBRARY : ICElementDelta.F_REMOVED_PATHENTRY_LIBRARY; } else if (kind == IPathEntry.CDT_PROJECT) { //IProjectEntry pentry = (IProjectEntry) entry; celement = cproject; - flag = ICElementDelta.F_CHANGED_PATHENTRY_PROJECT; + flag = ICElementDelta.F_CHANGED_PATHENTRY_PROJECT; } else if (kind == IPathEntry.CDT_INCLUDE) { IIncludeEntry include = (IIncludeEntry) entry; IPath path = include.getPath(); celement = CoreModel.getDefault().create(path); - flag = ICElementDelta.F_CHANGED_PATHENTRY_INCLUDE; + flag = ICElementDelta.F_CHANGED_PATHENTRY_INCLUDE; } else if (kind == IPathEntry.CDT_MACRO) { IMacroEntry macro = (IMacroEntry) entry; IPath path = macro.getPath(); celement = CoreModel.getDefault().create(path); - flag = ICElementDelta.F_CHANGED_PATHENTRY_MACRO; + flag = ICElementDelta.F_CHANGED_PATHENTRY_MACRO; } else if (kind == IPathEntry.CDT_CONTAINER) { //IContainerEntry container = (IContainerEntry) entry; //celement = cproject; @@ -528,32 +535,28 @@ public class PathEntryManager { static IPathEntry decodePathEntry(ICProject cProject, Element element) throws CModelException { IPath projectPath = cProject.getProject().getFullPath(); - // kind String kindAttr = element.getAttribute(ATTRIBUTE_KIND); int kind = PathEntry.kindFromString(kindAttr); - // exported flag boolean isExported = false; if (element.hasAttribute(ATTRIBUTE_EXPORTED)) { isExported = element.getAttribute(ATTRIBUTE_EXPORTED).equals(VALUE_TRUE); } - // ensure path is absolute + boolean hasPath = element.hasAttribute(ATTRIBUTE_PATH); String pathAttr = element.getAttribute(ATTRIBUTE_PATH); IPath path = new Path(pathAttr); if (kind != IPathEntry.CDT_VARIABLE && !path.isAbsolute()) { path = projectPath.append(path); } - // source attachment info (optional) - IPath sourceAttachmentPath = - element.hasAttribute(ATTRIBUTE_SOURCEPATH) ? new Path(element.getAttribute(ATTRIBUTE_SOURCEPATH)) : null; - IPath sourceAttachmentRootPath = - element.hasAttribute(ATTRIBUTE_ROOTPATH) ? new Path(element.getAttribute(ATTRIBUTE_ROOTPATH)) : null; - IPath sourceAttachmentPrefixMapping = - element.hasAttribute(ATTRIBUTE_PREFIXMAPPING) ? new Path(element.getAttribute(ATTRIBUTE_PREFIXMAPPING)) : null; - + IPath sourceAttachmentPath = element.hasAttribute(ATTRIBUTE_SOURCEPATH) ? new Path(element + .getAttribute(ATTRIBUTE_SOURCEPATH)) : null; + IPath sourceAttachmentRootPath = element.hasAttribute(ATTRIBUTE_ROOTPATH) ? new Path(element + .getAttribute(ATTRIBUTE_ROOTPATH)) : null; + IPath sourceAttachmentPrefixMapping = element.hasAttribute(ATTRIBUTE_PREFIXMAPPING) ? new Path(element + .getAttribute(ATTRIBUTE_PREFIXMAPPING)) : null; // exclusion patterns (optional) String exclusion = element.getAttribute(ATTRIBUTE_EXCLUDING); IPath[] exclusionPatterns = APathEntry.NO_EXCLUSION_PATTERNS; @@ -567,72 +570,53 @@ public class PathEntryManager { } } } - - boolean isRecursive = false; - if (element.hasAttribute(ATTRIBUTE_RECUSIVE)) { - isRecursive = element.getAttribute(ATTRIBUTE_RECUSIVE).equals(VALUE_TRUE); - } - // recreate the CP entry - switch (kind) { - case IPathEntry.CDT_PROJECT : return CoreModel.newProjectEntry(path, isExported); - case IPathEntry.CDT_LIBRARY : - return CoreModel.newLibraryEntry( - path, - sourceAttachmentPath, - sourceAttachmentRootPath, - sourceAttachmentPrefixMapping, - isExported); - + return CoreModel.newLibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, + sourceAttachmentPrefixMapping, isExported); case IPathEntry.CDT_SOURCE : { - // custom output location - IPath outputLocation = element.hasAttribute(ATTRIBUTE_OUTPUT) ? projectPath.append(element.getAttribute(ATTRIBUTE_OUTPUT)) : null; // must be an entry in this project or specify another // project String projSegment = path.segment(0); - if (projSegment != null && projSegment.equals(cProject.getElementName())) { // this project - return CoreModel.newSourceEntry(path, outputLocation, isRecursive, exclusionPatterns); + if (projSegment != null && projSegment.equals(cProject.getElementName())) { // this + // project + return CoreModel.newSourceEntry(path, exclusionPatterns); } else { // another project return CoreModel.newProjectEntry(path, isExported); } } - + case IPathEntry.CDT_OUTPUT : + { + return CoreModel.newOutputEntry(path, exclusionPatterns); + } case IPathEntry.CDT_INCLUDE : { // include path info - IPath includePath = - element.hasAttribute(ATTRIBUTE_INCLUDE) ? new Path(element.getAttribute(ATTRIBUTE_INCLUDE)) : null; + IPath includePath = element.hasAttribute(ATTRIBUTE_INCLUDE) + ? new Path(element.getAttribute(ATTRIBUTE_INCLUDE)) + : null; // isSysteminclude boolean isSystemInclude = false; if (element.hasAttribute(ATTRIBUTE_SYSTEM)) { isSystemInclude = element.getAttribute(ATTRIBUTE_SYSTEM).equals(VALUE_TRUE); } - return CoreModel.newIncludeEntry( - path, - includePath, - isSystemInclude, - isRecursive, - exclusionPatterns); + return CoreModel.newIncludeEntry(path, includePath, isSystemInclude, exclusionPatterns); } - case IPathEntry.CDT_MACRO : { String macroName = element.getAttribute(ATTRIBUTE_NAME); String macroValue = element.getAttribute(ATTRIBUTE_VALUE); - return CoreModel.newMacroEntry(path, macroName, macroValue, isRecursive, exclusionPatterns, isExported); + return CoreModel.newMacroEntry(path, macroName, macroValue, exclusionPatterns); } - case IPathEntry.CDT_CONTAINER : { IPath id = new Path(element.getAttribute(ATTRIBUTE_PATH)); return CoreModel.newContainerEntry(id, isExported); } - default : { ICModelStatus status = new CModelStatus(ICModelStatus.ERROR, "PathEntry: unknown kind (" + kindAttr + ")"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -647,10 +631,8 @@ public class PathEntryManager { element = doc.createElement(PATH_ENTRY); configRootElement.appendChild(element); int kind = entries[i].getEntryKind(); - // Set the kind element.setAttribute(ATTRIBUTE_KIND, PathEntry.kindToString(kind)); - // Save the exclusions attributes if (entries[i] instanceof APathEntry) { APathEntry entry = (APathEntry) entries[i]; @@ -665,19 +647,15 @@ public class PathEntryManager { } element.setAttribute(ATTRIBUTE_EXCLUDING, excludeRule.toString()); } - if (entry.isRecursive()) { - element.setAttribute(ATTRIBUTE_RECUSIVE, VALUE_TRUE); - } } - if (kind == IPathEntry.CDT_SOURCE) { ISourceEntry source = (ISourceEntry) entries[i]; IPath path = source.getPath(); element.setAttribute(ATTRIBUTE_PATH, path.toString()); - IPath output = source.getOutputLocation(); - if (output != null && output.isEmpty()) { - element.setAttribute(ATTRIBUTE_OUTPUT, output.toString()); - } + } else if (kind == IPathEntry.CDT_OUTPUT) { + IOutputEntry out = (IOutputEntry) entries[i]; + IPath path = out.getPath(); + element.setAttribute(ATTRIBUTE_PATH, path.toString()); } else if (kind == IPathEntry.CDT_LIBRARY) { ILibraryEntry lib = (ILibraryEntry) entries[i]; IPath path = lib.getPath(); @@ -698,7 +676,9 @@ public class PathEntryManager { } else if (kind == IPathEntry.CDT_INCLUDE) { IIncludeEntry include = (IIncludeEntry) entries[i]; IPath path = include.getPath(); - element.setAttribute(ATTRIBUTE_PATH, path.toString()); + if (path != null) { + element.setAttribute(ATTRIBUTE_PATH, path.toString()); + } IPath includePath = include.getIncludePath(); element.setAttribute(ATTRIBUTE_INCLUDE, includePath.toString()); if (include.isSystemInclude()) { @@ -707,7 +687,9 @@ public class PathEntryManager { } else if (kind == IPathEntry.CDT_MACRO) { IMacroEntry macro = (IMacroEntry) entries[i]; IPath path = macro.getPath(); - element.setAttribute(ATTRIBUTE_PATH, path.toString()); + if (path != null) { + element.setAttribute(ATTRIBUTE_PATH, path.toString()); + } element.setAttribute(ATTRIBUTE_NAME, macro.getMacroName()); element.setAttribute(ATTRIBUTE_VALUE, macro.getMacroValue()); } else if (kind == IPathEntry.CDT_CONTAINER) { @@ -719,5 +701,4 @@ public class PathEntryManager { } } } - } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceEntry.java index 6b12d7cf86e..393319aa3a5 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceEntry.java @@ -17,20 +17,8 @@ import org.eclipse.core.runtime.IPath; public class SourceEntry extends APathEntry implements ISourceEntry { - IPath outputLocation; - - public SourceEntry(IPath path, IPath outputLocation, boolean isRecursive, IPath[] exclusionPatterns) { - super(ISourceEntry.CDT_SOURCE, path, isRecursive, exclusionPatterns, false); - this.outputLocation = outputLocation; - } - - /** - * Binary output location for this source folder. - * @return IPath, null means to use the - * default output location of the project. - */ - public IPath getOutputLocation() { - return outputLocation; + public SourceEntry(IPath path, IPath[] exclusionPatterns) { + super(ISourceEntry.CDT_SOURCE, path, exclusionPatterns, false); } public boolean equals (Object obj) { @@ -48,15 +36,6 @@ public class SourceEntry extends APathEntry implements ISourceEntry { return false; } } - if (outputLocation == null) { - if (otherEntry.getOutputLocation() != null) { - return false; - } - } else { - if (!outputLocation.toString().equals(otherEntry.getOutputLocation().toString())) { - return false; - } - } return true; } return super.equals(obj); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceMapper.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceMapper.java index 7714236d3be..44952ecb9d6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceMapper.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceMapper.java @@ -4,11 +4,12 @@ */ package org.eclipse.cdt.internal.core.model; -import java.util.ArrayList; +import java.util.List; import org.eclipse.cdt.core.model.ICContainer; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.ITranslationUnit; /** @@ -24,8 +25,8 @@ public class SourceMapper { return findTranslationUnit(cproject, filename); } - public ITranslationUnit findTranslationUnit(ICContainer container, String filename) { - ArrayList list = container.getChildrenOfType(ICElement.C_UNIT); + public ITranslationUnit findTranslationUnit(IParent container, String filename) { + List list = container.getChildrenOfType(ICElement.C_UNIT); for (int i = 0; i < list.size(); i++) { Object o = list.get(i); if (o instanceof ITranslationUnit) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceRoot.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceRoot.java new file mode 100644 index 00000000000..4be6c1336aa --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceRoot.java @@ -0,0 +1,83 @@ +/********************************************************************** + * Copyright (c) 2002,2003,2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ + +package org.eclipse.cdt.internal.core.model; + +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ISourceEntry; +import org.eclipse.cdt.core.model.ISourceRoot; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; + +/** + * SourceRoot + */ +public class SourceRoot extends CContainer implements ISourceRoot { + + ISourceEntry sourceEntry; + + /** + * @param parent + * @param res + */ + public SourceRoot(ICElement parent, IResource res, ISourceEntry entry) { + super(parent, res); + sourceEntry = entry; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.model.CContainer#computeChildren(org.eclipse.cdt.internal.core.model.OpenableInfo, org.eclipse.core.resources.IResource) + */ + protected boolean computeChildren(OpenableInfo info, IResource res) + throws CModelException { + return super.computeChildren(info, res); + } + + public ISourceEntry getSourceEntry() { + return sourceEntry; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.model.ISourceRoot#isOnclasspath(org.eclipse.cdt.core.model.ICElement) + */ + public boolean isOnSourceEntry(ICElement element) { + IPath path = element.getPath(); + if (element.getElementType() == ICElement.C_CCONTAINER) { + // ensure that folders are only excluded if all of their children are excluded + path = path.append("*"); //$NON-NLS-1$ + } + return this.isOnSourceEntry(path); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.model.ISourceRoot#isOnSourceEntry(org.eclipse.core.resources.IResource) + */ + public boolean isOnSourceEntry(IResource resource) { + IPath path = resource.getFullPath(); + + // ensure that folders are only excluded if all of their children are excluded + if (resource.getType() == IResource.FOLDER) { + path = path.append("*"); //$NON-NLS-1$ + } + + return isOnSourceEntry(path); + } + + private boolean isOnSourceEntry(IPath path) { + if (sourceEntry.getPath().isPrefixOf(path) + && !Util.isExcluded(path, sourceEntry.fullExclusionPatternChars())) { + return true; + } + return false; + } + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java index 35ffc4d1c3b..2dc7b3792c2 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java @@ -1,37 +1,34 @@ package org.eclipse.cdt.internal.core.model; /* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. + * (c) Copyright IBM Corp. 2000, 2001. All Rights Reserved. */ - import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.text.MessageFormat; - import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ICLogConstants; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICModelStatusConstants; import org.eclipse.cdt.internal.core.model.IDebugLogConstants.DebugLogConstant; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; public class Util implements ICLogConstants { - public static boolean VERBOSE_PARSER = false; public static boolean VERBOSE_SCANNER = false; public static boolean VERBOSE_MODEL = false; - + private Util() { } - - + public static StringBuffer getContent(IFile file) throws IOException { InputStream stream = null; try { @@ -40,7 +37,7 @@ public class Util implements ICLogConstants { throw new IOException(e.getMessage()); } try { - char [] b = getInputStreamAsCharArray(stream, -1, null); + char[] b = getInputStreamAsCharArray(stream, -1, null); return new StringBuffer(b.length).append(b); } finally { try { @@ -52,18 +49,20 @@ public class Util implements ICLogConstants { } /** - * Returns the given input stream's contents as a character array. - * If a length is specified (ie. if length != -1), only length chars - * are returned. Otherwise all chars in the stream are returned. - * Note this doesn't close the stream. - * @throws IOException if a problem occured reading the stream. + * Returns the given input stream's contents as a character array. If a + * length is specified (ie. if length != -1), only length chars are + * returned. Otherwise all chars in the stream are returned. Note this + * doesn't close the stream. + * + * @throws IOException + * if a problem occured reading the stream. */ - public static char[] getInputStreamAsCharArray(InputStream stream, int length, String encoding) - throws IOException { + public static char[] getInputStreamAsCharArray(InputStream stream, + int length, String encoding) throws IOException { InputStreamReader reader = null; reader = encoding == null - ? new InputStreamReader(stream) - : new InputStreamReader(stream, encoding); + ? new InputStreamReader(stream) + : new InputStreamReader(stream, encoding); char[] contents; if (length == -1) { contents = new char[0]; @@ -71,34 +70,23 @@ public class Util implements ICLogConstants { int charsRead = -1; do { int available = stream.available(); - // resize contents if needed if (contentsLength + available > contents.length) { - System.arraycopy( - contents, - 0, - contents = new char[contentsLength + available], - 0, - contentsLength); + System.arraycopy(contents, 0, + contents = new char[contentsLength + available], 0, + contentsLength); } - // read as many chars as possible charsRead = reader.read(contents, contentsLength, available); - if (charsRead > 0) { // remember length of contents contentsLength += charsRead; } } while (charsRead > 0); - // resize contents if necessary if (contentsLength < contents.length) { - System.arraycopy( - contents, - 0, - contents = new char[contentsLength], - 0, - contentsLength); + System.arraycopy(contents, 0, + contents = new char[contentsLength], 0, contentsLength); } } else { contents = new char[length]; @@ -106,41 +94,47 @@ public class Util implements ICLogConstants { int readSize = 0; while ((readSize != -1) && (len != length)) { // See PR 1FMS89U - // We record first the read size. In this case len is the actual read size. + // We record first the read size. In this case len is the + // actual read size. len += readSize; readSize = reader.read(contents, len, length - len); } // See PR 1FMS89U - // Now we need to resize in case the default encoding used more than one byte for each - // character + // Now we need to resize in case the default encoding used more + // than one byte for each + // character if (len != length) - System.arraycopy(contents, 0, (contents = new char[len]), 0, len); + System.arraycopy(contents, 0, (contents = new char[len]), 0, + len); } - return contents; } - public static void save (StringBuffer buffer, IFile file) throws CoreException { + public static void save(StringBuffer buffer, IFile file) + throws CoreException { byte[] bytes = buffer.toString().getBytes(); ByteArrayInputStream stream = new ByteArrayInputStream(bytes); // use a platform operation to update the resource contents boolean force = true; file.setContents(stream, force, true, null); // record history } - + /** * Returns the given file's contents as a character array. */ - public static char[] getResourceContentsAsCharArray(IFile file) throws CModelException { + public static char[] getResourceContentsAsCharArray(IFile file) + throws CModelException { return getResourceContentsAsCharArray(file, null); } - - public static char[] getResourceContentsAsCharArray(IFile file, String encoding) throws CModelException { - InputStream stream= null; + + public static char[] getResourceContentsAsCharArray(IFile file, + String encoding) throws CModelException { + InputStream stream = null; try { stream = new BufferedInputStream(file.getContents(true)); } catch (CoreException e) { - throw new CModelException(e, ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST); + throw new CModelException(e, + ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST); } try { return Util.getInputStreamAsCharArray(stream, -1, encoding); @@ -153,47 +147,45 @@ public class Util implements ICLogConstants { } } } + /* * Add a log entry */ public static void log(Throwable e, String message, LogConst logType) { - IStatus status= new Status( - IStatus.ERROR, - CCorePlugin.getDefault().getDescriptor().getUniqueIdentifier(), - IStatus.ERROR, - message, - e); - Util.log(status, logType); - } - - public static void log(IStatus status, LogConst logType){ - if (logType.equals(ICLogConstants.PDE)){ - CCorePlugin.getDefault().getLog().log(status); - } - else if (logType.equals(ICLogConstants.CDT)){ - CCorePlugin.getDefault().cdtLog.log(status); - } - } - - public static void log(String message, LogConst logType){ - IStatus status = new Status(IStatus.INFO, - CCorePlugin.getDefault().getDescriptor().getUniqueIdentifier(), - IStatus.INFO, - message, - null); + IStatus status = new Status(IStatus.ERROR, CCorePlugin.getDefault() + .getDescriptor().getUniqueIdentifier(), IStatus.ERROR, message, + e); Util.log(status, logType); } - + + public static void log(IStatus status, LogConst logType) { + if (logType.equals(ICLogConstants.PDE)) { + CCorePlugin.getDefault().getLog().log(status); + } else if (logType.equals(ICLogConstants.CDT)) { + CCorePlugin.getDefault().cdtLog.log(status); + } + } + + public static void log(String message, LogConst logType) { + IStatus status = new Status(IStatus.INFO, CCorePlugin.getDefault() + .getDescriptor().getUniqueIdentifier(), IStatus.INFO, message, + null); + Util.log(status, logType); + } + public static void debugLog(String message, DebugLogConstant client) { Util.debugLog(message, client, true); } - - public static void debugLog(String message, DebugLogConstant client, boolean addTimeStamp) { - if( CCorePlugin.getDefault() == null ) return; - if ( CCorePlugin.getDefault().isDebugging() && isActive(client)) { + + public static void debugLog(String message, DebugLogConstant client, + boolean addTimeStamp) { + if (CCorePlugin.getDefault() == null) + return; + if (CCorePlugin.getDefault().isDebugging() && isActive(client)) { // Time stamp - if(addTimeStamp) - message = MessageFormat.format( "[{0}] {1}", new Object[] { new Long( System.currentTimeMillis() ), message } ); //$NON-NLS-1$ + if (addTimeStamp) + message = MessageFormat.format("[{0}] {1}", new Object[]{ + new Long(System.currentTimeMillis()), message}); //$NON-NLS-1$ while (message.length() > 100) { String partial = message.substring(0, 100); message = message.substring(100); @@ -206,94 +198,584 @@ public class Util implements ICLogConstants { } } } - + /** * @param client * @return */ public static boolean isActive(DebugLogConstant client) { - if (client.equals(IDebugLogConstants.PARSER)){ + if (client.equals(IDebugLogConstants.PARSER)) { return VERBOSE_PARSER; - } - else if (client.equals(IDebugLogConstants.SCANNER )) + } else if (client.equals(IDebugLogConstants.SCANNER)) return VERBOSE_SCANNER; - else if (client.equals(IDebugLogConstants.MODEL)){ + else if (client.equals(IDebugLogConstants.MODEL)) { return VERBOSE_MODEL; } return false; } - public static void setDebugging(boolean value){ + public static void setDebugging(boolean value) { CCorePlugin.getDefault().setDebugging(value); } - + /** * Combines two hash codes to make a new one. */ public static int combineHashCodes(int hashCode1, int hashCode2) { return hashCode1 * 17 + hashCode2; } - /** - * Compares two arrays using equals() on the elements. - * Either or both arrays may be null. - * Returns true if both are null. - * Returns false if only one is null. - * If both are arrays, returns true iff they have the same length and - * all elements compare true with equals. - */ - public static boolean equalArraysOrNull(Object[] a, Object[] b) { - if (a == b) return true; - if (a == null || b == null) return false; - int len = a.length; - if (len != b.length) return false; - for (int i = 0; i < len; ++i) { - if (a[i] == null) { - if (b[i] != null) return false; - } else { - if (!a[i].equals(b[i])) return false; - } - } + /** + * Compares two arrays using equals() on the elements. Either or both + * arrays may be null. Returns true if both are null. Returns false if only + * one is null. If both are arrays, returns true iff they have the same + * length and all elements compare true with equals. + */ + public static boolean equalArraysOrNull(Object[] a, Object[] b) { + if (a == b) return true; - } - /** - * Compares two arrays using equals() on the elements. - * Either or both arrays may be null. - * Returns true if both are null. - * Returns false if only one is null. - * If both are arrays, returns true iff they have the same length and - * all elements are equal. - */ - public static boolean equalArraysOrNull(int[] a, int[] b) { - if (a == b) - return true; - if (a == null || b == null) - return false; - int len = a.length; - if (len != b.length) - return false; - for (int i = 0; i < len; ++i) { - if (a[i] != b[i]) + if (a == null || b == null) + return false; + int len = a.length; + if (len != b.length) + return false; + for (int i = 0; i < len; ++i) { + if (a[i] == null) { + if (b[i] != null) + return false; + } else { + if (!a[i].equals(b[i])) return false; } + } + return true; + } + + /** + * Compares two arrays using equals() on the elements. Either or both + * arrays may be null. Returns true if both are null. Returns false if only + * one is null. If both are arrays, returns true iff they have the same + * length and all elements are equal. + */ + public static boolean equalArraysOrNull(int[] a, int[] b) { + if (a == b) + return true; + if (a == null || b == null) + return false; + int len = a.length; + if (len != b.length) + return false; + for (int i = 0; i < len; ++i) { + if (a[i] != b[i]) + return false; + } + return true; + } + + /** + * Compares two objects using equals(). Either or both array may be null. + * Returns true if both are null. Returns false if only one is null. + * Otherwise, return the result of comparing with equals(). + */ + public static boolean equalOrNull(Object a, Object b) { + if (a == b) { return true; } + if (a == null || b == null) { + return false; + } + return a.equals(b); + } - /** - * Compares two objects using equals(). - * Either or both array may be null. - * Returns true if both are null. - * Returns false if only one is null. - * Otherwise, return the result of comparing with equals(). - */ - public static boolean equalOrNull(Object a, Object b) { - if (a == b) { + /* + * Returns whether the given resource path matches one of the exclusion + * patterns. + * + * @see IClasspathEntry#getExclusionPatterns + */ + public final static boolean isExcluded(IPath resourcePath, + char[][] exclusionPatterns) { + if (exclusionPatterns == null) + return false; + char[] path = resourcePath.toString().toCharArray(); + for (int i = 0, length = exclusionPatterns.length; i < length; i++) + if (pathMatch(exclusionPatterns[i], path, true, '/')) return true; - } - if (a == null || b == null) { + return false; + } + + /* + * Returns whether the given resource matches one of the exclusion + * patterns. + * + * @see IClasspathEntry#getExclusionPatterns + */ + public final static boolean isExcluded(IResource resource, + char[][] exclusionPatterns) { + IPath path = resource.getFullPath(); + // ensure that folders are only excluded if all of their children are + // excluded + if (resource.getType() == IResource.FOLDER) + path = path.append("*"); //$NON-NLS-1$ + return isExcluded(path, exclusionPatterns); + } + + /** + * Answers true if the pattern matches the given name, false otherwise. + * This char[] pattern matching accepts wild-cards '*' and '?'. + * + * When not case sensitive, the pattern is assumed to already be + * lowercased, the name will be lowercased character per character as + * comparing. If name is null, the answer is false. If pattern is null, the + * answer is true if name is not null.
+ *
+ * For example: + *

    + *
  1. + * + *
    +	 *  pattern = { '?', 'b', '*' }
    +	 *  name = { 'a', 'b', 'c' , 'd' }
    +	 *  isCaseSensitive = true
    +	 *  result => true
    +	 * 
    + * + *
  2. + *
  3. + * + *
    +	 *  pattern = { '?', 'b', '?' }
    +	 *  name = { 'a', 'b', 'c' , 'd' }
    +	 *  isCaseSensitive = true
    +	 *  result => false
    +	 * 
    + * + *
  4. + *
  5. + * + *
    +	 *  pattern = { 'b', '*' }
    +	 *  name = { 'a', 'b', 'c' , 'd' }
    +	 *  isCaseSensitive = true
    +	 *  result => false
    +	 * 
    + * + *
  6. + *
+ * + * @param pattern + * the given pattern + * @param name + * the given name + * @param isCaseSensitive + * flag to know whether or not the matching should be case + * sensitive + * @return true if the pattern matches the given name, false otherwise + */ + public static final boolean match(char[] pattern, char[] name, + boolean isCaseSensitive) { + if (name == null) + return false; // null name cannot match + if (pattern == null) + return true; // null pattern is equivalent to '*' + return match(pattern, 0, pattern.length, name, 0, name.length, + isCaseSensitive); + } + + /** + * Answers true if the a sub-pattern matches the subpart of the given name, + * false otherwise. char[] pattern matching, accepting wild-cards '*' and + * '?'. Can match only subset of name/pattern. end positions are + * non-inclusive. The subpattern is defined by the patternStart and + * pattternEnd positions. When not case sensitive, the pattern is assumed + * to already be lowercased, the name will be lowercased character per + * character as comparing.
+ *
+ * For example: + *
    + *
  1. + * + *
    +	 *  pattern = { '?', 'b', '*' }
    +	 *  patternStart = 1
    +	 *  patternEnd = 3
    +	 *  name = { 'a', 'b', 'c' , 'd' }
    +	 *  nameStart = 1
    +	 *  nameEnd = 4
    +	 *  isCaseSensitive = true
    +	 *  result => true
    +	 * 
    + * + *
  2. + *
  3. + * + *
    +	 *  pattern = { '?', 'b', '*' }
    +	 *  patternStart = 1
    +	 *  patternEnd = 2
    +	 *  name = { 'a', 'b', 'c' , 'd' }
    +	 *  nameStart = 1
    +	 *  nameEnd = 2
    +	 *  isCaseSensitive = true
    +	 *  result => false
    +	 * 
    + * + *
  4. + *
+ * + * @param pattern + * the given pattern + * @param patternStart + * the given pattern start + * @param patternEnd + * the given pattern end + * @param name + * the given name + * @param nameStart + * the given name start + * @param nameEnd + * the given name end + * @param isCaseSensitive + * flag to know if the matching should be case sensitive + * @return true if the a sub-pattern matches the subpart of the given name, + * false otherwise + */ + public static final boolean match(char[] pattern, int patternStart, + int patternEnd, char[] name, int nameStart, int nameEnd, + boolean isCaseSensitive) { + if (name == null) + return false; // null name cannot match + if (pattern == null) + return true; // null pattern is equivalent to '*' + int iPattern = patternStart; + int iName = nameStart; + if (patternEnd < 0) + patternEnd = pattern.length; + if (nameEnd < 0) + nameEnd = name.length; + /* check first segment */ + char patternChar = 0; + while ((iPattern < patternEnd) + && (patternChar = pattern[iPattern]) != '*') { + if (iName == nameEnd) + return false; + if (patternChar != (isCaseSensitive ? name[iName] : Character + .toLowerCase(name[iName])) + && patternChar != '?') { return false; } - return a.equals(b); - } - + iName++; + iPattern++; + } + /* check sequence of star+segment */ + int segmentStart; + if (patternChar == '*') { + segmentStart = ++iPattern; // skip star + } else { + segmentStart = 0; // force iName check + } + int prefixStart = iName; + checkSegment : while (iName < nameEnd) { + if (iPattern == patternEnd) { + iPattern = segmentStart; // mismatch - restart current segment + iName = ++prefixStart; + continue checkSegment; + } + /* segment is ending */ + if ((patternChar = pattern[iPattern]) == '*') { + segmentStart = ++iPattern; // skip start + if (segmentStart == patternEnd) { + return true; + } + prefixStart = iName; + continue checkSegment; + } + /* check current name character */ + if ((isCaseSensitive ? name[iName] : Character + .toLowerCase(name[iName])) != patternChar + && patternChar != '?') { + iPattern = segmentStart; // mismatch - restart current segment + iName = ++prefixStart; + continue checkSegment; + } + iName++; + iPattern++; + } + return (segmentStart == patternEnd) + || (iName == nameEnd && iPattern == patternEnd) + || (iPattern == patternEnd - 1 && pattern[iPattern] == '*'); + } + + /** + * Answers true if the pattern matches the filepath using the + * pathSepatator, false otherwise. + * + * Path char[] pattern matching, accepting wild-cards '**', '*' and '?' + * (using Ant directory tasks conventions, also see + * "http://jakarta.apache.org/ant/manual/dirtasks.html#defaultexcludes"). + * Path pattern matching is enhancing regular pattern matching in + * supporting extra rule where '**' represent any folder combination. + * Special rule: - foo\ is equivalent to foo\** When not case sensitive, + * the pattern is assumed to already be lowercased, the name will be + * lowercased character per character as comparing. + * + * @param pattern + * the given pattern + * @param filepath + * the given path + * @param isCaseSensitive + * to find out whether or not the matching should be case + * sensitive + * @param pathSeparator + * the given path separator + * @return true if the pattern matches the filepath using the + * pathSepatator, false otherwise + */ + public static final boolean pathMatch(char[] pattern, char[] filepath, + boolean isCaseSensitive, char pathSeparator) { + if (filepath == null) + return false; // null name cannot match + if (pattern == null) + return true; // null pattern is equivalent to '*' + // offsets inside pattern + int pSegmentStart = pattern[0] == pathSeparator ? 1 : 0; + int pLength = pattern.length; + int pSegmentEnd = indexOf(pathSeparator, pattern, pSegmentStart + 1); + if (pSegmentEnd < 0) + pSegmentEnd = pLength; + // special case: pattern foo\ is equivalent to foo\** + boolean freeTrailingDoubleStar = pattern[pLength - 1] == pathSeparator; + // offsets inside filepath + int fSegmentStart, fLength = filepath.length; + if (filepath[0] != pathSeparator) { + fSegmentStart = 0; + } else { + fSegmentStart = 1; + } + if (fSegmentStart != pSegmentStart) { + return false; // both must start with a separator or none. + } + int fSegmentEnd = indexOf(pathSeparator, filepath, fSegmentStart + 1); + if (fSegmentEnd < 0) + fSegmentEnd = fLength; + // first segments + while (pSegmentStart < pLength + && !(pSegmentEnd == pLength && freeTrailingDoubleStar || (pSegmentEnd == pSegmentStart + 2 + && pattern[pSegmentStart] == '*' && pattern[pSegmentStart + 1] == '*'))) { + if (fSegmentStart >= fLength) + return false; + if (!match(pattern, pSegmentStart, pSegmentEnd, filepath, + fSegmentStart, fSegmentEnd, isCaseSensitive)) { + return false; + } + // jump to next segment + pSegmentEnd = indexOf(pathSeparator, pattern, + pSegmentStart = pSegmentEnd + 1); + // skip separator + if (pSegmentEnd < 0) + pSegmentEnd = pLength; + fSegmentEnd = indexOf(pathSeparator, filepath, + fSegmentStart = fSegmentEnd + 1); + // skip separator + if (fSegmentEnd < 0) + fSegmentEnd = fLength; + } + /* check sequence of doubleStar+segment */ + int pSegmentRestart; + if ((pSegmentStart >= pLength && freeTrailingDoubleStar) + || (pSegmentEnd == pSegmentStart + 2 + && pattern[pSegmentStart] == '*' && pattern[pSegmentStart + 1] == '*')) { + pSegmentEnd = indexOf(pathSeparator, pattern, + pSegmentStart = pSegmentEnd + 1); + // skip separator + if (pSegmentEnd < 0) + pSegmentEnd = pLength; + pSegmentRestart = pSegmentStart; + } else { + if (pSegmentStart >= pLength) + return fSegmentStart >= fLength; // true if filepath is done + // too. + pSegmentRestart = 0; // force fSegmentStart check + } + int fSegmentRestart = fSegmentStart; + checkSegment : while (fSegmentStart < fLength) { + if (pSegmentStart >= pLength) { + if (freeTrailingDoubleStar) + return true; + // mismatch - restart current path segment + pSegmentEnd = indexOf(pathSeparator, pattern, + pSegmentStart = pSegmentRestart); + if (pSegmentEnd < 0) + pSegmentEnd = pLength; + fSegmentRestart = indexOf(pathSeparator, filepath, + fSegmentRestart + 1); + // skip separator + if (fSegmentRestart < 0) { + fSegmentRestart = fLength; + } else { + fSegmentRestart++; + } + fSegmentEnd = indexOf(pathSeparator, filepath, + fSegmentStart = fSegmentRestart); + if (fSegmentEnd < 0) + fSegmentEnd = fLength; + continue checkSegment; + } + /* path segment is ending */ + if (pSegmentEnd == pSegmentStart + 2 + && pattern[pSegmentStart] == '*' + && pattern[pSegmentStart + 1] == '*') { + pSegmentEnd = indexOf(pathSeparator, pattern, + pSegmentStart = pSegmentEnd + 1); + // skip separator + if (pSegmentEnd < 0) + pSegmentEnd = pLength; + pSegmentRestart = pSegmentStart; + fSegmentRestart = fSegmentStart; + if (pSegmentStart >= pLength) + return true; + continue checkSegment; + } + /* chech current path segment */ + if (!match(pattern, pSegmentStart, pSegmentEnd, filepath, + fSegmentStart, fSegmentEnd, isCaseSensitive)) { + // mismatch - restart current path segment + pSegmentEnd = indexOf(pathSeparator, pattern, + pSegmentStart = pSegmentRestart); + if (pSegmentEnd < 0) + pSegmentEnd = pLength; + fSegmentRestart = indexOf(pathSeparator, filepath, + fSegmentRestart + 1); + // skip separator + if (fSegmentRestart < 0) { + fSegmentRestart = fLength; + } else { + fSegmentRestart++; + } + fSegmentEnd = indexOf(pathSeparator, filepath, + fSegmentStart = fSegmentRestart); + if (fSegmentEnd < 0) + fSegmentEnd = fLength; + continue checkSegment; + } + // jump to next segment + pSegmentEnd = indexOf(pathSeparator, pattern, + pSegmentStart = pSegmentEnd + 1); + // skip separator + if (pSegmentEnd < 0) + pSegmentEnd = pLength; + fSegmentEnd = indexOf(pathSeparator, filepath, + fSegmentStart = fSegmentEnd + 1); + // skip separator + if (fSegmentEnd < 0) + fSegmentEnd = fLength; + } + return (pSegmentRestart >= pSegmentEnd) + || (fSegmentStart >= fLength && pSegmentStart >= pLength) + || (pSegmentStart == pLength - 2 + && pattern[pSegmentStart] == '*' && pattern[pSegmentStart + 1] == '*') + || (pSegmentStart == pLength && freeTrailingDoubleStar); + } + + /** + * Answers the first index in the array for which the corresponding + * character is equal to toBeFound. Answers -1 if no occurrence of this + * character is found.
+ *
+ * For example: + *
    + *
  1. + * + *
    +	 *  toBeFound = 'c'
    +	 *  array = { ' a', 'b', 'c', 'd' }
    +	 *  result => 2
    +	 * 
    + * + *
  2. + *
  3. + * + *
    +	 *  toBeFound = 'e'
    +	 *  array = { ' a', 'b', 'c', 'd' }
    +	 *  result => -1
    +	 * 
    + * + *
  4. + *
+ * + * @param toBeFound + * the character to search + * @param array + * the array to be searched + * @return the first index in the array for which the corresponding + * character is equal to toBeFound, -1 otherwise + * @throws NullPointerException + * if array is null + */ + public static final int indexOf(char toBeFound, char[] array) { + for (int i = 0; i < array.length; i++) + if (toBeFound == array[i]) + return i; + return -1; + } + + /** + * Answers the first index in the array for which the corresponding + * character is equal to toBeFound starting the search at index start. + * Answers -1 if no occurrence of this character is found.
+ *
+ * For example: + *
    + *
  1. + * + *
    +	 *  toBeFound = 'c'
    +	 *  array = { ' a', 'b', 'c', 'd' }
    +	 *  start = 2
    +	 *  result => 2
    +	 * 
    + * + *
  2. + *
  3. + * + *
    +	 *  toBeFound = 'c'
    +	 *  array = { ' a', 'b', 'c', 'd' }
    +	 *  start = 3
    +	 *  result => -1
    +	 * 
    + * + *
  4. + *
  5. + * + *
    +	 *  toBeFound = 'e'
    +	 *  array = { ' a', 'b', 'c', 'd' }
    +	 *  start = 1
    +	 *  result => -1
    +	 * 
    + * + *
  6. + *
+ * + * @param toBeFound + * the character to search + * @param array + * the array to be searched + * @param start + * the starting index + * @return the first index in the array for which the corresponding + * character is equal to toBeFound, -1 otherwise + * @throws NullPointerException + * if array is null + * @throws ArrayIndexOutOfBoundsException + * if start is lower than 0 + */ + public static final int indexOf(char toBeFound, char[] array, int start) { + for (int i = start; i < array.length; i++) + if (toBeFound == array[i]) + return i; + return -1; + } } diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 9c705596e6d..4c53a70b856 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,21 @@ +2004-03-18 Alain Magloire + Change in the hierarchy of the core Model: + ICModel + ICProject + ISourceRoot + IBinary + IArchive + ITranslatioUnit + ICContainer + The ISourceRoot been added to better separate + the files. By default the entire project is the + SourceRoot. + + * src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java + * src/org/eclipse/cdt/internal/ui/CElementImageProvider.java + * src/org/eclipse/cdt/internal/ui/CPluginImages.java + * src/org/eclipse/cdt/ui/CElementContentProvider.java + 2004-03-17 Tanya Wolff Syntax errors in property files * CBrowsingMessages.properties diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java index 68fb7520ff0..dc247264522 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java @@ -20,10 +20,13 @@ import org.eclipse.cdt.core.model.ICModel; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ILibraryReference; import org.eclipse.cdt.core.model.IParent; +import org.eclipse.cdt.core.model.ISourceRoot; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.ITreeContentProvider; @@ -38,13 +41,14 @@ import org.eclipse.jface.viewers.Viewer; * The following C element hierarchy is surfaced by this content provider: *

*

-C model (ICModel)
-   C project (ICProject)
-      C Container(folders) (ICContainer)
-      Translation unit (ITranslationUnit)
-      Binary file (IBinary)
-      Archive file (IArchive)
-      Non C Resource file (Object)
+C model (ICModel)
+ C project (ICProject)
+ Source root (ISourceRoot)
+ C Container(folders) (ICContainer)
+ Translation unit (ITranslationUnit)
+ Binary file (IBinary)
+ Archive file (IArchive)
+ Non C Resource file (Object)
*
*/ @@ -118,36 +122,38 @@ public class BaseCElementContentProvider implements ITreeContentProvider { * Method declared on ITreeContentProvider. */ public Object[] getChildren(Object element) { - if (element instanceof ICElement) { - ICElement celement = (ICElement)element; - if (celement instanceof ICModel) { - return getCProjects((ICModel)celement); - } else if (celement instanceof ICProject ) { - return getCProjectResources((ICProject)celement); - } else if (celement instanceof ICContainer) { - return getCResources((ICContainer)celement); - } else if (celement instanceof ITranslationUnit) { - // if we want to get the chidren of a translation unit - if (fProvideMembers) { - // if we want to use the working copy of it - if(fProvideWorkingCopy){ - // if it is not already a working copy - if(!(celement instanceof IWorkingCopy)){ - // if it has a valid working copy - ITranslationUnit tu = (ITranslationUnit)celement; - IWorkingCopy copy = tu.findSharedWorkingCopy(CUIPlugin.getBufferFactory()); - if(copy != null) { - return ((IParent)copy).getChildren(); - } + if (!exists(element)) + return NO_CHILDREN; + + if (element instanceof ICModel) { + return getCProjects((ICModel)element); + } else if (element instanceof ICProject ) { + return getSourceRoots((ICProject)element); + } else if (element instanceof ICContainer) { + return getCResources((ICContainer)element); + } else if (element instanceof ITranslationUnit) { + // if we want to get the chidren of a translation unit + if (fProvideMembers) { + // if we want to use the working copy of it + if(fProvideWorkingCopy){ + // if it is not already a working copy + if(!(element instanceof IWorkingCopy)){ + // if it has a valid working copy + ITranslationUnit tu = (ITranslationUnit)element; + IWorkingCopy copy = tu.findSharedWorkingCopy(CUIPlugin.getBufferFactory()); + if(copy != null) { + return ((IParent)copy).getChildren(); } } - return ((IParent)celement).getChildren(); } - } else if (celement instanceof IParent) { - return (Object[])((IParent)celement).getChildren(); + return ((IParent)element).getChildren(); } + } else if (element instanceof IParent) { + return (Object[])((IParent)element).getChildren(); + } else if (element instanceof IFolder) { + return getResources((IFolder)element); } - return getResources(element); + return NO_CHILDREN; } /* (non-Cdoc) @@ -162,11 +168,12 @@ public class BaseCElementContentProvider implements ITreeContentProvider { } } else { // don't allow to drill down into a compilation unit or class file - if (element instanceof ITranslationUnit || element instanceof IBinary || element instanceof IArchive) { + if (element instanceof ITranslationUnit || element instanceof IBinary || element instanceof IArchive + || element instanceof IFile) { return false; } } - + if (element instanceof ICProject) { ICProject cp= (ICProject)element; if (!cp.getProject().isOpen()) { @@ -176,13 +183,11 @@ public class BaseCElementContentProvider implements ITreeContentProvider { } } - if (element instanceof ICContainer) { - return true; - } - if (element instanceof IParent) { // when we have C children return true, else we fetch all the children - return ((IParent)element).hasChildren(); + if (((IParent)element).hasChildren()) { + return true; + } } Object[] children= getChildren(element); return (children != null) && children.length > 0; @@ -199,9 +204,6 @@ public class BaseCElementContentProvider implements ITreeContentProvider { } public Object internalGetParent(Object element) { - if (element instanceof ICElement) { - return ((ICElement)element).getParent(); - } if (element instanceof IResource) { IResource parent= ((IResource)element).getParent(); ICElement cParent= CoreModel.getDefault().create(parent); @@ -210,15 +212,64 @@ public class BaseCElementContentProvider implements ITreeContentProvider { } return parent; } - return null; + Object parent = null; + if (element instanceof ICElement) { + parent = ((ICElement)element).getParent(); + } + // if the parent is the default ISourceRoot == ICProject return the project + if (parent instanceof ISourceRoot) { + if (isProjectSourceRoot((ISourceRoot)parent)) { + parent = ((ISourceRoot)parent).getCProject(); + } + } else if (parent instanceof IBinaryContainer || parent instanceof IArchiveContainer) { + // If the virtual container is the parent we must find the legitimate parent. + if (element instanceof ICElement) { + IResource res = ((ICElement)element).getResource(); + if (res != null) { + parent = internalGetParent(res.getParent()); + } + } + } + return parent; } protected Object[] getCProjects(ICModel cModel) { return cModel.getCProjects(); } - protected Object[] getCProjectResources(ICProject cproject) { - Object[] objects = getCResources((ICContainer)cproject); + protected Object[] getSourceRoots(ICProject cproject) { + if (!cproject.getProject().isOpen()) + return NO_CHILDREN; + + List list= new ArrayList(); + try { + ISourceRoot[] roots = cproject.getSourceRoots(); + // filter out source roots that correspond to projects and + // replace them with the package fragments directly + for (int i= 0; i < roots.length; i++) { + ISourceRoot root= roots[i]; + if (isProjectSourceRoot(root)) { + Object[] children= root.getChildren(); + for (int k= 0; k < children.length; k++) { + list.add(children[k]); + } + } else if (hasChildren(root)) { + list.add(root); + } + } + } catch (CModelException e1) { + } + + Object[] objects = list.toArray(); + try { + Object[] nonC = cproject.getNonCResources(); + if (nonC != null && nonC.length > 0) { + objects = concatenate(objects, cproject.getNonCResources()); + } + } catch (CModelException e) { + // + } + //Object[] objects = getCResources((ICContainer)cproject); IArchiveContainer archives = cproject.getArchiveContainer(); if (archives.hasChildren()) { objects = concatenate(objects, new Object[] {archives}); @@ -248,32 +299,41 @@ public class BaseCElementContentProvider implements ITreeContentProvider { return concatenate(children, objects); } - private Object[] getResources(Object resource) { + private Object[] getResources(IFolder folder) { try { - if (resource instanceof IContainer) { - Object[] members= ((IContainer)resource).members(); - List nonCResources= new ArrayList(); - for (int i= 0; i < members.length; i++) { - Object o= members[i]; - nonCResources.add(o); + Object[] members= folder.members(); + List nonCResources= new ArrayList(); + for (int i= 0; i < members.length; i++) { + Object o= members[i]; + // A folder can also be a source root in the following case + // Project + // + src <- source folder + // + excluded <- excluded from class path + // + included <- a new source folder. + // Included is a member of excluded, but since it is rendered as a source + // folder we have to exclude it as a normal child. + if (o instanceof IFolder) { + ICElement element= CoreModel.getDefault().create((IFolder)o); + if (element instanceof ISourceRoot && element.exists()) { + continue; + } } - return nonCResources.toArray(); + nonCResources.add(o); } + return nonCResources.toArray(); } catch(CoreException e) { } return NO_CHILDREN; } -/* - protected boolean isBuildPathChange(ICElementDelta delta) { - int flags= delta.getFlags(); - return (delta.getKind() == ICElementDelta.CHANGED && - ((flags & ICElementDelta.F_ADDED_TO_CLASSPATH) != 0) || - ((flags & ICElementDelta.F_REMOVED_FROM_CLASSPATH) != 0) || - ((flags & ICElementDelta.F_CLASSPATH_REORDER) != 0)); + + /** + * Note: This method is for internal use only. Clients should not call this method. + */ + protected boolean isProjectSourceRoot(ISourceRoot root) { + IResource resource= root.getResource(); + return (resource instanceof IProject); } -*/ - - + protected boolean exists(Object element) { if (element == null) { return false; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CElementImageProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CElementImageProvider.java index 774fb15b590..33a85570a49 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CElementImageProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CElementImageProvider.java @@ -283,17 +283,17 @@ public class CElementImageProvider { case ICElement.C_PROJECT: ICProject cp= (ICProject)celement; if (cp.getProject().isOpen()) { - IProject project= cp.getProject(); - IWorkbenchAdapter adapter= (IWorkbenchAdapter)project.getAdapter(IWorkbenchAdapter.class); - if (adapter != null) { - ImageDescriptor result= adapter.getImageDescriptor(project); - if (result != null) - return result; - } - return DESC_OBJ_PROJECT; + IProject project= cp.getProject(); + IWorkbenchAdapter adapter= (IWorkbenchAdapter)project.getAdapter(IWorkbenchAdapter.class); + if (adapter != null) { + ImageDescriptor result= adapter.getImageDescriptor(project); + if (result != null) + return result; } - return DESC_OBJ_PROJECT_CLOSED; - + return DESC_OBJ_PROJECT; + } + return DESC_OBJ_PROJECT_CLOSED; + case ICElement.C_STRUCT: case ICElement.C_TEMPLATE_STRUCT: return getStructImageDescriptor(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java index 03d430f573d..b6edae88a21 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java @@ -66,7 +66,8 @@ public class CPluginImages { public static final String IMG_OBJS_TUNIT= NAME_PREFIX + "c_file_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_TUNIT_HEADER= NAME_PREFIX + "h_file_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_TUNIT_ASM= NAME_PREFIX + "s_file_obj.gif"; //$NON-NLS-1$ - public static final String IMG_OBJS_TUNIT_RESOURCE = NAME_PREFIX + "c_resource_obj.gif"; //$NON-NLS-1$ + public static final String IMG_OBJS_TUNIT_RESOURCE= NAME_PREFIX + "c_resource_obj.gif"; //$NON-NLS-1$ + public static final String IMG_OBJS_SOURCE_ROOT= NAME_PREFIX + "cfolder_obj.gif"; // $NON-NLS-1$ public static final String IMG_OBJS_ARCHIVE= NAME_PREFIX + "ar_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_BINARY= NAME_PREFIX + "bin_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_SHLIB= NAME_PREFIX + "shlib_obj.gif"; //$NON-NLS-1$ @@ -109,6 +110,7 @@ public class CPluginImages { public static final ImageDescriptor DESC_OBJS_TUNIT_HEADER= createManaged(T_OBJ, IMG_OBJS_TUNIT_HEADER); public static final ImageDescriptor DESC_OBJS_TUNIT_ASM= createManaged(T_OBJ, IMG_OBJS_TUNIT_ASM); public static final ImageDescriptor DESC_OBJS_TUNIT_RESOURCE= createManaged(T_OBJ, IMG_OBJS_TUNIT_RESOURCE); + public static final ImageDescriptor DESC_OBJS_SOURCE_ROOT= createManaged(T_OBJ, IMG_OBJS_SOURCE_ROOT); public static final ImageDescriptor DESC_OBJS_ARCHIVE= createManaged(T_OBJ, IMG_OBJS_ARCHIVE); public static final ImageDescriptor DESC_OBJS_BINARY= createManaged(T_OBJ, IMG_OBJS_BINARY); public static final ImageDescriptor DESC_OBJS_SHLIB= createManaged(T_OBJ, IMG_OBJS_SHLIB); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementContentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementContentProvider.java index 9fd625a9f84..1e9a3d2cd5d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementContentProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementContentProvider.java @@ -23,12 +23,30 @@ import org.eclipse.cdt.internal.core.model.BinaryContainer; import org.eclipse.cdt.internal.ui.BaseCElementContentProvider; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.StructuredViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.widgets.Control; +/** + * A content provider for C elements. + *

+ * The following C element hierarchy is surfaced by this content provider: + *

+ *

+C model (ICModel)
+ C project (ICProject)
+ Virtual binaries container(IBinaryContainery) + Virtual archives container(IArchiveContainery) + Source root (ISourceRoot)
+ C Container(folders) (ICContainer)
+ Translation unit (ITranslationUnit)
+ Binary file (IBinary)
+ Archive file (IArchive)
+ Non C Resource file (Object)
+ + *
+ */ public class CElementContentProvider extends BaseCElementContentProvider implements ITreeContentProvider, IElementChangedListener { protected StructuredViewer fViewer; @@ -84,6 +102,16 @@ public class CElementContentProvider extends BaseCElementContentProvider impleme } } + protected boolean isPathEntryChange(ICElementDelta delta) { + int flags= delta.getFlags(); + return (delta.getKind() == ICElementDelta.CHANGED && + ((flags & ICElementDelta.F_BINARY_PARSER_CHANGED) != 0 || + (flags & ICElementDelta.F_ADDED_PATHENTRY_LIBRARY) != 0 || + (flags & ICElementDelta.F_ADDED_PATHENTRY_SOURCE) != 0 || + (flags & ICElementDelta.F_REMOVED_PATHENTRY_LIBRARY) != 0 || + (flags & ICElementDelta.F_REMOVED_PATHENTRY_SOURCE) != 0)); + } + /** * Processes a delta recursively. When more than two children are affected the * tree is fully refreshed starting at this node. The delta is processed in the @@ -95,9 +123,9 @@ public class CElementContentProvider extends BaseCElementContentProvider impleme ICElement element= delta.getElement(); //System.out.println("Processing " + element); + // handle open and closing of a solution or project - if (((flags & ICElementDelta.F_CLOSED) != 0) - || ((flags & ICElementDelta.F_OPENED) != 0)) { + if (((flags & ICElementDelta.F_CLOSED) != 0) || ((flags & ICElementDelta.F_OPENED) != 0)) { postRefresh(element); } @@ -118,12 +146,7 @@ public class CElementContentProvider extends BaseCElementContentProvider impleme } if (kind == ICElementDelta.CHANGED) { - if ((flags & ICElementDelta.F_BINARY_PARSER_CHANGED) != 0) { - // throw the towel and do a full refresh of the affected C project. - postRefresh(element.getCProject()); - return; - } else if (element instanceof ITranslationUnit || - element instanceof IBinary || element instanceof IArchive) { + if (element instanceof ITranslationUnit || element instanceof IBinary || element instanceof IArchive) { postRefresh(element); return; } else if (element instanceof ArchiveContainer || element instanceof BinaryContainer) { @@ -132,6 +155,11 @@ public class CElementContentProvider extends BaseCElementContentProvider impleme } + if (isPathEntryChange(delta)) { + // throw the towel and do a full refresh of the affected C project. + postRefresh(element.getCProject()); + } + if (delta.getResourceDeltas() != null) { IResourceDelta[] rd= delta.getResourceDeltas(); for (int i= 0; i < rd.length; i++) { @@ -143,11 +171,6 @@ public class CElementContentProvider extends BaseCElementContentProvider impleme for (int i= 0; i < affectedChildren.length; i++) { processDelta(affectedChildren[i]); } - - // Make sure that containers are updated. - //if (element instanceof ICModel) { - // updateContainer((ICModel)element); - //} } /* @@ -163,21 +186,9 @@ public class CElementContentProvider extends BaseCElementContentProvider impleme // this could be optimized by handling all the added children in the parent if ((status & IResourceDelta.REMOVED) != 0) { -// if (!(parent instanceof ICContainer)) { -// // refresh one level above to deal with empty package filtering properly -// postRefresh(internalGetParent(parent)); -// } else { -// postRemove(resource); -// } postRemove(resource); } if ((status & IResourceDelta.ADDED) != 0) { -// if (!(parent instanceof ICContainer)) { -// // refresh one level above to deal with empty package filtering properly -// postRefresh(internalGetParent(parent)); -// } else { -// postAdd(parent, resource); -// } postAdd(parent, resource); } IResourceDelta[] affectedChildren= delta.getAffectedChildren(); @@ -193,36 +204,6 @@ public class CElementContentProvider extends BaseCElementContentProvider impleme } } - -// private void updateContainer(ICModel root) { -// postRunnable(new Runnable() { -// public void run () { -// Control ctrl= fViewer.getControl(); -// if (ctrl != null && !ctrl.isDisposed()) { -// IStructuredSelection s = (IStructuredSelection)fViewer.getSelection(); -// if (s.isEmpty()) -// return; -// Object element = s.getFirstElement(); -// if (element instanceof ICProject) { -// updateContainer((ICProject)element); -// } -// } -// } -// }); -// } - -// protected boolean updateContainer(ICProject cproject) { -// IParent binContainer = cproject.getBinaryContainer(); -// IParent libContainer = cproject.getArchiveContainer(); -// if (binContainer != null) { -// postContainerRefresh(binContainer, cproject); -// } -// if (libContainer != null) { -// postContainerRefresh(libContainer, cproject); -// } -// return false; -// } - private boolean updateContainer(ICElement cfile) { IParent container = null; ICProject cproject = null; @@ -288,7 +269,6 @@ public class CElementContentProvider extends BaseCElementContentProvider impleme // 1GF87WR: ITPUI:ALL - SWTEx + NPE closing a workbench window. Control ctrl= fViewer.getControl(); if (ctrl != null && !ctrl.isDisposed()){ -// fViewer.add(parent, element); fViewer.refresh(parent); if(parent instanceof IWorkingCopy){ fViewer.refresh(((IWorkingCopy)parent).getOriginalElement()); @@ -306,7 +286,6 @@ public class CElementContentProvider extends BaseCElementContentProvider impleme // 1GF87WR: ITPUI:ALL - SWTEx + NPE closing a workbench window. Control ctrl= fViewer.getControl(); if (ctrl != null && !ctrl.isDisposed()) { -// fViewer.remove(element); Object parent = internalGetParent(element); fViewer.refresh(parent); if(parent instanceof IWorkingCopy){ @@ -326,35 +305,4 @@ public class CElementContentProvider extends BaseCElementContentProvider impleme } } - /** - * The workbench has changed. Process the delta and issue updates to the viewer, - * inside the UI thread. - * - * @see IResourceChangeListener#resourceChanged - */ - //public void resourceChanged(final IResourceChangeEvent event) { - // final IResourceDelta delta = event.getDelta(); - // Control ctrl = viewer.getControl(); - // if (ctrl != null && !ctrl.isDisposed()) { - // ctrl.getDisplay().syncExec(new Runnable() { - // public void run() { - // processDelta(delta); - // } - // }); - // } - //} - - - /** - * Returns the implementation of IWorkbenchAdapter for the given - * object. Returns null if the adapter is not defined or the - * object is not adaptable. - */ - protected ICElement getAdapter(Object o) { - if (!(o instanceof IAdaptable)) { - return null; - } - return (ICElement)((IAdaptable)o).getAdapter(ICElement.class); - } - }