diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java index 71b586856dd..de0f27389db 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java @@ -161,8 +161,13 @@ public class DOMBuilder implements IParserCallback /** * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#inclusionBegin(java.lang.String) */ - public Object inclusionBegin(String includeFile, int offset, int inclusionBeginOffset) { - Inclusion inclusion = new Inclusion( includeFile, offset, inclusionBeginOffset, offset - inclusionBeginOffset + includeFile.length() + 1 ); + public Object inclusionBegin(String includeFile, int offset, int inclusionBeginOffset, boolean local) { + Inclusion inclusion = new Inclusion( + includeFile, + offset, + inclusionBeginOffset, + offset - inclusionBeginOffset + includeFile.length() + 1, + local ); translationUnit.addInclusion( inclusion ); return inclusion; } diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Inclusion.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Inclusion.java index d7415f372db..4f8acb7415a 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Inclusion.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Inclusion.java @@ -18,8 +18,18 @@ package org.eclipse.cdt.internal.core.dom; */ public class Inclusion extends PreprocessorStatement { - public Inclusion( String name, int nameOffset, int startingOffset, int totalLength ) + private final boolean local; + + public Inclusion( String name, int nameOffset, int startingOffset, int totalLength, boolean local ) { super( name, nameOffset, startingOffset, totalLength ); + this.local = local; } + /** + * @return + */ + public boolean isLocal() { + return local; + } + } diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/LineNumberedDOMBuilder.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/LineNumberedDOMBuilder.java index 5b10548a6ac..bd7692e7c4b 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/LineNumberedDOMBuilder.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/LineNumberedDOMBuilder.java @@ -91,8 +91,8 @@ public class LineNumberedDOMBuilder extends DOMBuilder { public Object inclusionBegin( String includeFile, int offset, - int inclusionBeginOffset) { - Object inclusion = super.inclusionBegin(includeFile, offset, inclusionBeginOffset); + int inclusionBeginOffset, boolean local) { + Object inclusion = super.inclusionBegin(includeFile, offset, inclusionBeginOffset, local); setLineNumber( (IOffsetable)inclusion, inclusionBeginOffset, true ); setLineNumber( (IOffsetable)inclusion, offset + includeFile.length() + 1, false ); return inclusion; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java index f0a8e0f06a2..332714fa20c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java @@ -10,8 +10,11 @@ import org.eclipse.cdt.core.model.IInclude; public class Include extends SourceManipulation implements IInclude { - public Include(ICElement parent, String name) { + private final boolean standard; + + public Include(ICElement parent, String name, boolean isStandard) { super(parent, name, CElement.C_INCLUDE); + standard = isStandard; } public String getIncludeName() { @@ -19,7 +22,7 @@ public class Include extends SourceManipulation implements IInclude { } public boolean isStandard() { - return true; + return standard; } protected CElementInfo createElementInfo () { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ModelBuilder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ModelBuilder.java index fe00f7d662b..545c60e4649 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ModelBuilder.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ModelBuilder.java @@ -28,7 +28,7 @@ public class ModelBuilder implements IStructurizerCallback { } public void includeDecl(String name, int startPos, int endPos, int startLine, int endLine) { - Include elem= new Include(fCurrFile, name); + Include elem= new Include(fCurrFile, name, true ); // assume standard inclusion elem.setPos(startPos, fixLength(startPos, endPos)); elem.setIdPos(startPos, fixLength(startPos, endPos)); elem.setLines(startLine, endLine); diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 1d7500b19d8..73c3e86aa1c 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -1,3 +1,6 @@ +2003-06-05 John Camelon + Fix Bug 38380 "Include" class public methods fails JUnit tests + 2003-05-05 John Camelon/Andrew Niefer Added Symboltable infrastructure into main parser. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java index efb9f3be661..25d422dc0d7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java @@ -249,7 +249,7 @@ public class CModelBuilder { } protected Include createInclusion(Parent parent, Inclusion inclusion){ // create element - Include element = new Include((CElement)parent, inclusion.getName()); + Include element = new Include((CElement)parent, inclusion.getName(), !inclusion.isLocal()); // add to parent parent.addChild((CElement) element); // set position diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionEvaluator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionEvaluator.java index 1b7d3448781..67863a0060e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionEvaluator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionEvaluator.java @@ -125,7 +125,7 @@ public class ExpressionEvaluator implements IParserCallback { /** * @see org.eclipse.cdt.internal.core.parser.IParserCallback#inclusionBegin(java.lang.String, int) */ - public Object inclusionBegin(String includeFile, int offset, int inclusionBeginOffset) { + public Object inclusionBegin(String includeFile, int offset, int inclusionBeginOffset, boolean local) { return null; } /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserCallback.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserCallback.java index c1c67b1c496..84116fb1ced 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserCallback.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserCallback.java @@ -17,7 +17,7 @@ public interface IParserCallback { public Object translationUnitBegin(); public void translationUnitEnd(Object unit); - public Object inclusionBegin(String includeFile, int nameBeginOffset, int inclusionBeginOffset); + public Object inclusionBegin(String includeFile, int nameBeginOffset, int inclusionBeginOffset, boolean local); public void inclusionEnd(Object inclusion); public Object macro(String macroName, int macroNameOffset, int macroBeginOffset, int macroEndOffset); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/NullParserCallback.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/NullParserCallback.java index 2118a21229f..8aa6840748c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/NullParserCallback.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/NullParserCallback.java @@ -18,7 +18,7 @@ public class NullParserCallback implements IParserCallback { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.IParserCallback#inclusionBegin(java.lang.String, int) */ - public Object inclusionBegin(String includeFile, int offset, int inclusionBeginOffset) { + public Object inclusionBegin(String includeFile, int offset, int inclusionBeginOffset, boolean local) { return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java index d7e78ca2edd..c254416c472 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java @@ -1664,7 +1664,7 @@ public class Scanner implements IScanner { if( callback != null ) { offset = contextStack.getCurrentContext().getOffset() - f.length() - 1; // -1 for the end quote - callback.inclusionEnd(callback.inclusionBegin( f, offset, beginningOffset )); + callback.inclusionEnd(callback.inclusionBegin( f, offset, beginningOffset, !useIncludePath )); } } else diff --git a/core/org.eclipse.cdt.ui.tests/ChangeLog b/core/org.eclipse.cdt.ui.tests/ChangeLog index 60fcc9c75f0..8005a6b9eb7 100644 --- a/core/org.eclipse.cdt.ui.tests/ChangeLog +++ b/core/org.eclipse.cdt.ui.tests/ChangeLog @@ -1,3 +1,7 @@ +2003-06-05 John Camelon + Moved testBug23478A() & testBug23478B() from failed tests to TranslationUnitTests.java. + Removed TranslationUnitFailedTests.java as it was empty. + 2003-05-05 John Camelon/Andrew Niefer Added CrossReferenceTests to ParserTestSuite to test symbol-table/DOM interworking. diff --git a/core/org.eclipse.cdt.ui.tests/failures/org/eclipse/cdt/core/model/failedTests/TranslationUnitFailedTests.java b/core/org.eclipse.cdt.ui.tests/failures/org/eclipse/cdt/core/model/failedTests/TranslationUnitFailedTests.java deleted file mode 100644 index ef9332cb8ee..00000000000 --- a/core/org.eclipse.cdt.ui.tests/failures/org/eclipse/cdt/core/model/failedTests/TranslationUnitFailedTests.java +++ /dev/null @@ -1,206 +0,0 @@ -package org.eclipse.cdt.core.model.failedTests; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ - -import java.io.FileInputStream; -import java.io.FileNotFoundException; - -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.IInclude; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.testplugin.CProjectHelper; -import org.eclipse.cdt.testplugin.util.ExpectedStrings; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceDescription; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; - - - -/** - * @author Peter Graves - * - * This file contains a set of generic tests for the core C model's TranslationUnit - * class. There is nothing exotic here, mostly just sanity type tests - * - */ -public class TranslationUnitFailedTests extends TestCase { - IWorkspace workspace; - IWorkspaceRoot root; - ICProject testProject; - IFile cfile, exefile, libfile, archfile, objfile; - Path cpath, exepath, libpath, archpath, objpath; - NullProgressMonitor monitor; - - /* This is a list of elements in the test .c file. It will be used - * in a number of places in the tests - */ - String[] expectedStringList= {"stdio.h", "unistd.h", "func2p", - "globalvar", "myenum", "mystruct", "mystruct_t", "myunion", "mytype", - "func1", "func2", "main", "func3"}; - int[] expectedLines={ 12,14,17,20,23,28,32,35,42,47,53,58,65}; - /* This is a list of that the types of the above list of elements is - * expected to be. - */ - int[] expectedTypes= { ICElement.C_INCLUDE, ICElement.C_INCLUDE, - ICElement.C_FUNCTION_DECLARATION, ICElement.C_VARIABLE, - ICElement.C_ENUMERATION, ICElement.C_STRUCT, ICElement.C_TYPEDEF, - ICElement.C_UNION, ICElement.C_TYPEDEF, ICElement.C_FUNCTION, - ICElement.C_FUNCTION, ICElement.C_FUNCTION,ICElement.C_FUNCTION}; - - - /** - * Constructor for TranslationUnitTests - * @param name - */ - public TranslationUnitFailedTests(String name) { - super(name); - } - - /** - * Sets up the test fixture. - * - * Called before every test case method. - * - * Example code test the packages in the project - * "com.qnx.tools.ide.cdt.core" - */ - protected void setUp() throws CoreException,FileNotFoundException { - /*** - * The rest of the tests assume that they have a working workspace - * and workspace root object to use to create projects/files in, - * so we need to get them setup first. - */ - IWorkspaceDescription desc; - String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.ui.tests").find(new Path("/")).getFile(); - workspace= ResourcesPlugin.getWorkspace(); - root= workspace.getRoot(); - monitor = new NullProgressMonitor(); - if (workspace==null) - fail("Workspace was not setup"); - if (root==null) - fail("Workspace root was not setup"); - - desc=workspace.getDescription(); - desc.setAutoBuilding(false); - workspace.setDescription(desc); - - /*** - * Setup the various files, paths and projects that are needed by the - * tests - */ - - testProject=CProjectHelper.createCProject("filetest", "none"); - if (testProject==null) - fail("Unable to create project"); - - cfile = testProject.getProject().getFile("exetest.c"); - if (!cfile.exists()) { - cfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/cfiles/TranslationUnits.c"),false, monitor); - - } - cpath=new Path(workspace.getRoot().getLocation()+"/filetest/main.c"); - - objfile = testProject.getProject().getFile("exetest.o"); - if (!objfile.exists()) { - objfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/x86/o.g/main.o"),false, monitor); - - } - objpath=new Path(workspace.getRoot().getLocation()+"/filetest/main.o"); - - exefile = testProject.getProject().getFile("test_g"); - if (!exefile.exists()) { - exefile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/x86/o.g/exe_g"),false, monitor); - - } - exepath=new Path(workspace.getRoot().getLocation()+"/filetest/exe_g"); - - archfile = testProject.getProject().getFile("libtestlib_g.a"); - if (!archfile.exists()) { - archfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/testlib/x86/a.g/libtestlib_g.a"),false, monitor); - - } - libpath=new Path(workspace.getRoot().getLocation()+"/filetest/libtestlib_g.so"); - - libfile = testProject.getProject().getFile("libtestlib_g.so"); - if (!libfile.exists()) { - libfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/testlib/x86/so.g/libtestlib_g.so"),false, monitor); - - } - archpath=new Path(workspace.getRoot().getLocation()+"/filetest/libtestlib_g.a"); - - - } - - /** - * Tears down the test fixture. - * - * Called after every test case method. - */ - protected void tearDown() throws CoreException { - // release resources here and clean-up - testProject.getProject().delete(true,true,monitor); - } - - - /*** - * Simple sanity tests for the getInclude call - */ - public void testBug23478A() { - IInclude myInclude; - int x; - String includes[]={"stdio.h", "unistd.h"}; - ITranslationUnit myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c"); - - for (x=0; x < includes.length; x++) { - myInclude=myTranslationUnit.getInclude(includes[x]); - if (myInclude==null) - fail("Unable to get include: " + includes[x]); - else { - // Failed test: Include.getIncludeName() always returns ""; - // assertTrue - assertFalse("PR:23478 Expected:"+ new String("") +" Got:"+ myInclude.getIncludeName(), includes[x].equals(myInclude.getIncludeName())); - } - } - - - } - /*** - * Simple sanity tests for the getIncludes call - */ - public void testBug23478B() throws CModelException { - IInclude myIncludes[]; - String includes[]={"stdio.h", "unistd.h"}; - ExpectedStrings myExp= new ExpectedStrings(includes); - int x; - ITranslationUnit myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c"); - - myIncludes=myTranslationUnit.getIncludes(); - for (x=0; x < myIncludes.length; x++) { - myExp.foundString(myIncludes[x].getIncludeName()); - } - // Failed test: Include.getIncludeName() always returns ""; - // assertTrue - assertFalse(myExp.getMissingString(), myExp.gotAll()); - assertFalse(myExp.getExtraString(), !myExp.gotExtra()); - } - -} diff --git a/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java index 31d5186c42c..adfd43bc2b6 100644 --- a/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java +++ b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java @@ -232,6 +232,51 @@ public class TranslationUnitTests extends TestCase { } } + + /*** + * Simple sanity tests for the getInclude call + */ + public void testBug23478A() { + IInclude myInclude; + int x; + String includes[]={"stdio.h", "unistd.h"}; + ITranslationUnit myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c"); + + for (x=0; x < includes.length; x++) { + myInclude=myTranslationUnit.getInclude(includes[x]); + if (myInclude==null) + fail("Unable to get include: " + includes[x]); + else { + // Failed test: Include.getIncludeName() always returns ""; + // assertTrue + assertTrue("PR:23478 Expected:"+ new String("") +" Got:"+ myInclude.getIncludeName(), includes[x].equals(myInclude.getIncludeName())); + } + } + + + } + /*** + * Simple sanity tests for the getIncludes call + */ + public void testBug23478B() throws CModelException { + IInclude myIncludes[]; + String includes[]={"stdio.h", "unistd.h"}; + ExpectedStrings myExp= new ExpectedStrings(includes); + int x; + ITranslationUnit myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c"); + + myIncludes=myTranslationUnit.getIncludes(); + for (x=0; x < myIncludes.length; x++) { + myExp.foundString(myIncludes[x].getIncludeName()); + } + // Failed test: Include.getIncludeName() always returns ""; + // assertTrue + assertTrue(myExp.getMissingString(), myExp.gotAll()); + assertTrue(myExp.getExtraString(), !myExp.gotExtra()); + } + + + /*** * Simple sanity tests for the getElementAtLine() call */ diff --git a/core/org.eclipse.cdt.ui.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.ui.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java index 08872677801..ffdfd540b36 100644 --- a/core/org.eclipse.cdt.ui.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java +++ b/core/org.eclipse.cdt.ui.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java @@ -83,7 +83,6 @@ public class AutomatedIntegrationSuite extends TestSuite implements TestListener suite.addTestSuite(ScannerFailedTest.class); suite.addTestSuite(STLFailedTests.class); suite.addTestSuite(CModelElementsFailedTests.class); - suite.addTestSuite(TranslationUnitFailedTests.class); // Last test to trigger report generation suite.addTest(suite.new GenerateReport("testGenerateReport"));