From 7982f97b6cfbdb91b45db9ce1357ff3a4b8788b5 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Thu, 8 Jan 2009 17:03:40 +0000 Subject: [PATCH] Removal / deprecation of options to create ast with comment nodes, bug 259841. --- .../cdt/core/parser/tests/ast2/AST2Tests.java | 8 ++-- .../core/parser/tests/ast2/CommentTests.java | 20 ++++----- .../parser/tests/ast2/TaskParserTest.java | 2 +- .../org/eclipse/cdt/core/model/ILanguage.java | 6 +-- .../cdt/core/model/ITranslationUnit.java | 6 +-- .../internal/core/model/TranslationUnit.java | 3 -- .../dom/parser/AbstractCLikeLanguage.java | 1 - .../org/eclipse/cdt/core/parser/IScanner.java | 43 +++++++++++-------- .../core/pdom/AbstractIndexerTask.java | 2 +- .../core/dom/InternalASTServiceProvider.java | 19 ++++---- 10 files changed, 54 insertions(+), 56 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index b6dd08b96e4..e6a208a67e0 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -3975,8 +3975,8 @@ public class AST2Tests extends AST2BaseTest { // INVALID(1, 2) // public void test192639() throws Exception { - parse( getAboveComment(), ParserLanguage.CPP, false, false, true ); - parse( getAboveComment(), ParserLanguage.C, false, false, true ); + parse( getAboveComment(), ParserLanguage.CPP, false, false ); + parse( getAboveComment(), ParserLanguage.C, false, false ); } public void test195943() throws Exception { @@ -5786,10 +5786,8 @@ public class AST2Tests extends AST2BaseTest { buf.append(input[2].toString()); final String code= buf.toString(); for (ParserLanguage lang : ParserLanguage.values()) { - IASTTranslationUnit tu= parse(code, lang, false, true, true); - tu= null; long mem= memoryUsed(); - tu= parse(code, lang, false, true, true); + IASTTranslationUnit tu= parse(code, lang, false, true, true); long diff= memoryUsed()-mem; final int expected = 1024*20 + code.length()*2; // a copy of the buffer + some assertTrue(String.valueOf(diff) + " expected < " + expected, diff < expected); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CommentTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CommentTests.java index f0d8de7e3f4..acccc8bda6d 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CommentTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CommentTests.java @@ -30,14 +30,14 @@ public class CommentTests extends AST2BaseTest { } public void testCountCommentsInHeaderFile() throws ParserException{ - IASTTranslationUnit tu = parse(getHSource(), ParserLanguage.CPP, false, true, true); + IASTTranslationUnit tu = parse(getHSource(), ParserLanguage.CPP, false, true); IASTComment[] comments = tu.getComments(); assertEquals(9, comments.length); } public void testCommentsInHeaderFile() throws ParserException{ - IASTTranslationUnit tu = parse(getHSource(), ParserLanguage.CPP, false, true, true); + IASTTranslationUnit tu = parse(getHSource(), ParserLanguage.CPP, false, true); IASTComment[] comments = tu.getComments(); assertEquals("/* A very cool class\n * isn't it?\n */", new String(comments[0].getComment())); @@ -52,14 +52,14 @@ public class CommentTests extends AST2BaseTest { } public void testCountCommentsInCPPFile() throws ParserException{ - IASTTranslationUnit tu = parse(getCppSource(), ParserLanguage.CPP, false, true, true); + IASTTranslationUnit tu = parse(getCppSource(), ParserLanguage.CPP, false, true); IASTComment[] comments = tu.getComments(); assertEquals(10, comments.length); } public void testCommentsInCPPFile() throws ParserException{ - IASTTranslationUnit tu = parse(getCppSource(), ParserLanguage.CPP, false, true, true); + IASTTranslationUnit tu = parse(getCppSource(), ParserLanguage.CPP, false, true); IASTComment[] comments = tu.getComments(); assertEquals("// Comment in cpp", new String(comments[0].getComment())); @@ -75,14 +75,14 @@ public class CommentTests extends AST2BaseTest { } public void testCountCommentsInCFile() throws ParserException{ - IASTTranslationUnit tu = parse(getCSource(), ParserLanguage.C, false, true, true); + IASTTranslationUnit tu = parse(getCSource(), ParserLanguage.C, false, true); IASTComment[] comments = tu.getComments(); assertEquals(4, comments.length); } public void testCommentsInCFile() throws ParserException{ - IASTTranslationUnit tu = parse(getCSource(), ParserLanguage.C, false, true, true); + IASTTranslationUnit tu = parse(getCSource(), ParserLanguage.C, false, true); IASTComment[] comments = tu.getComments(); assertEquals("//A little input/output programm", new String(comments[0].getComment())); @@ -202,7 +202,7 @@ public class CommentTests extends AST2BaseTest { // #endif public void testCommentsInInactiveCode_bug183930() throws Exception { StringBuffer code= getContents(1)[0]; - IASTTranslationUnit tu = parse(code.toString(), ParserLanguage.CPP, false, true, true); + IASTTranslationUnit tu = parse(code.toString(), ParserLanguage.CPP, false, true); IASTComment[] comments = tu.getComments(); assertEquals(2, comments.length); @@ -213,14 +213,14 @@ public class CommentTests extends AST2BaseTest { // //comment public void testCommentLocation_bug186337() throws Exception{ StringBuffer code= getContents(1)[0]; - IASTTranslationUnit tu = parse(code.toString(), ParserLanguage.CPP, false, true, true); + IASTTranslationUnit tu = parse(code.toString(), ParserLanguage.CPP, false, true); IASTComment[] comments = tu.getComments(); assertEquals(1, comments.length); assertNotNull(comments[0].getFileLocation()); assertNotNull(comments[0].getNodeLocations()); - tu = parse(code.toString(), ParserLanguage.C, false, true, true); + tu = parse(code.toString(), ParserLanguage.C, false, true); comments = tu.getComments(); assertEquals(1, comments.length); @@ -237,7 +237,7 @@ public class CommentTests extends AST2BaseTest { public void testCommentInDirectives_bug192546() throws Exception { StringBuffer code= getContents(1)[0]; - IASTTranslationUnit tu = parse(code.toString(), ParserLanguage.CPP, false, false, true); + IASTTranslationUnit tu = parse(code.toString(), ParserLanguage.CPP, false, false); IASTComment[] comments = tu.getComments(); assertEquals(5, comments.length); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TaskParserTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TaskParserTest.java index f44ef205a03..4b212a6c2dd 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TaskParserTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TaskParserTest.java @@ -50,7 +50,7 @@ public class TaskParserTest extends AST2BaseTest { "// TODO FIXME tag 5\n" + "\n" + "const char* x = \"TODO Not a tag\";"; - IASTTranslationUnit tu = parse(code, ParserLanguage.CPP, false, true, true); + IASTTranslationUnit tu = parse(code, ParserLanguage.CPP, false, true); TodoTaskParser parser = new TodoTaskParser(taskTags, taskPriorities, isTaskCaseSensitive); Task[] tasks = parser.parse(tu.getComments()); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java index 789c97f8f1a..7a17447690b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java @@ -40,9 +40,9 @@ public interface ILanguage extends IAdaptable { public final static int OPTION_SKIP_FUNCTION_BODIES= 0x1; /** - * Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)} - * Instructs the parser to add comment nodes to the ast. + * @deprecated, has no effect. */ + @Deprecated public final static int OPTION_ADD_COMMENTS= 0x2; /** @@ -140,7 +140,7 @@ public interface ILanguage extends IAdaptable { * @param index (optional) index to use to provide support for ambiguity * resolution. * @param options A combination of - * {@link #OPTION_SKIP_FUNCTION_BODIES}, {@link #OPTION_ADD_COMMENTS}, + * {@link #OPTION_SKIP_FUNCTION_BODIES}, * {@link #OPTION_NO_IMAGE_LOCATIONS}, {@link #OPTION_IS_SOURCE_UNIT}, * or 0. * @param log logger diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java index b3c1735a331..0b452099325 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java @@ -72,10 +72,10 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource public static final int AST_SKIP_IF_NO_BUILD_INFO = 0x8; /** - * Style constant for {@link #getAST(IIndex, int)}. - * Meaning: Add nodes for comments to the ast. + * @deprecated The option has no effect. * @since 4.0 */ + @Deprecated public static final int AST_CREATE_COMMENT_NODES = 0x10; /** @@ -491,7 +491,7 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource * translation unit does not support ASTs. * @param index index to back up the parsing of the AST, may be null * @param style 0 or a combination of {@link #AST_SKIP_ALL_HEADERS}, - * {@link #AST_SKIP_IF_NO_BUILD_INFO}, {@link #AST_SKIP_INDEXED_HEADERS}, {@link #AST_CREATE_COMMENT_NODES} + * {@link #AST_SKIP_IF_NO_BUILD_INFO}, {@link #AST_SKIP_INDEXED_HEADERS} * and {@link #AST_CONFIGURE_USING_SOURCE_CONTEXT}. * @return the AST requested or null * @throws CoreException diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java index d99f6791b70..777a9a535fb 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java @@ -820,9 +820,6 @@ public class TranslationUnit extends Openable implements ITranslationUnit { if ((style & AST_SKIP_FUNCTION_BODIES) != 0) { options |= ILanguage.OPTION_SKIP_FUNCTION_BODIES; } - if ((style & AST_CREATE_COMMENT_NODES) != 0) { - options |= ILanguage.OPTION_ADD_COMMENTS; - } if ((style & AST_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS) != 0) { options |= ILanguage.OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractCLikeLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractCLikeLanguage.java index 9025b81234a..717f8626dad 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractCLikeLanguage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractCLikeLanguage.java @@ -113,7 +113,6 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements ICodeReaderFactory codeReaderFactory, IIndex index, int options, IParserLogService log) throws CoreException { final IScanner scanner= createScanner(reader, scanInfo, codeReaderFactory, log); - scanner.setScanComments((options & OPTION_ADD_COMMENTS) != 0); scanner.setComputeImageLocations((options & OPTION_NO_IMAGE_LOCATIONS) == 0); final ISourceCodeParser parser= createParser(scanner, log, index, false, options); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java index b7f581eda0d..237ab119b2d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java @@ -26,27 +26,11 @@ import org.eclipse.cdt.internal.core.parser.scanner.Lexer; * work or that it will remain the same. Please do not use this API without * consulting with the CDT team. *

+ * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. */ public interface IScanner { - /** - * Puts the scanner into content assist mode. - */ - public void setContentAssistMode( int offset ); - - /** - * Turns on/off comment parsing. - * @since 4.0 - */ - public void setScanComments(boolean val); - - /** - * Turns on/off creation of image locations. - * @see IASTName#getImageLocation() - * @since 5.0 - */ - public void setComputeImageLocations(boolean val); - /** * Returns a map from {@link String} to {@link IMacroBinding} containing * all the definitions that are defined at the current point in the @@ -73,6 +57,29 @@ public interface IScanner { /** * Returns the location resolver associated with this scanner. + * @noreference This method is not intended to be referenced by clients. */ public ILocationResolver getLocationResolver(); + + /** + * Puts the scanner into content assist mode. + * @noreference This method is not intended to be referenced by clients. + */ + public void setContentAssistMode(int offset); + + /** + * Method has no effect. + * @noreference This method is not intended to be referenced by clients. + * @since 4.0 + */ + @Deprecated + public void setScanComments(boolean val); + + /** + * Turns on/off creation of image locations. + * @see IASTName#getImageLocation() + * @noreference This method is not intended to be referenced by clients. + * @since 5.0 + */ + public void setComputeImageLocations(boolean val); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java index 3cedb8518dc..b9f53dc838d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java @@ -217,7 +217,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter { } fTodoTaskUpdater= createTodoTaskUpdater(); - fASTOptions= ILanguage.OPTION_ADD_COMMENTS | ILanguage.OPTION_NO_IMAGE_LOCATIONS + fASTOptions= ILanguage.OPTION_NO_IMAGE_LOCATIONS | ILanguage.OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS; if (getSkipReferences() == SKIP_ALL_REFERENCES) { fASTOptions |= ILanguage.OPTION_SKIP_FUNCTION_BODIES; diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java index d50e5f145af..a0fd7ceb5a7 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java @@ -71,14 +71,14 @@ public class InternalASTServiceProvider implements IASTServiceProvider { * @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit() */ public IASTTranslationUnit getTranslationUnit(IFile fileToParse) throws UnsupportedDialectException { - return getTranslationUnit( fileToParse.getLocation().toOSString(), fileToParse, SavedCodeReaderFactory.getInstance(), null, false); + return getTranslationUnit( fileToParse.getLocation().toOSString(), fileToParse, SavedCodeReaderFactory.getInstance(), null); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit(org.eclipse.cdt.core.dom.ICodeReaderFactory) */ public IASTTranslationUnit getTranslationUnit(IFile fileToParse, ICodeReaderFactory fileCreator) throws UnsupportedDialectException { - return getTranslationUnit( fileToParse.getLocation().toOSString(), fileToParse, fileCreator, null, false); + return getTranslationUnit( fileToParse.getLocation().toOSString(), fileToParse, fileCreator, null); } /* (non-Javadoc) @@ -86,11 +86,11 @@ public class InternalASTServiceProvider implements IASTServiceProvider { */ public IASTTranslationUnit getTranslationUnit( IFile fileToParse, ICodeReaderFactory fileCreator, IParserConfiguration configuration) throws UnsupportedDialectException { - return getTranslationUnit( fileToParse.getLocation().toOSString(), fileToParse, fileCreator, configuration, false); + return getTranslationUnit( fileToParse.getLocation().toOSString(), fileToParse, fileCreator, configuration); } public IASTTranslationUnit getTranslationUnit( - String filename, IResource infoProvider, ICodeReaderFactory fileCreator, IParserConfiguration configuration, boolean parseComment) throws UnsupportedDialectException + String filename, IResource infoProvider, ICodeReaderFactory fileCreator, IParserConfiguration configuration) throws UnsupportedDialectException { IProject project = infoProvider.getProject(); IScannerInfo scanInfo = null; @@ -127,7 +127,6 @@ public class InternalASTServiceProvider implements IASTServiceProvider { scannerExtensionConfiguration = C_GNU_SCANNER_EXTENSION; scanner= createScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, l, ParserFactory.createDefaultLogService(), scannerExtensionConfiguration, fileCreator); - scanner.setScanComments(parseComment); //assume GCC if( l == ParserLanguage.C ) parser = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, ParserUtil.getParserLogService(), new GCCParserExtensionConfiguration() ); @@ -146,8 +145,6 @@ public class InternalASTServiceProvider implements IASTServiceProvider { else throw new UnsupportedDialectException(); - scanner.setScanComments(parseComment); - if( dialect.equals( dialects[0])) { ICParserExtensionConfiguration config = new ANSICParserExtensionConfiguration(); @@ -278,18 +275,18 @@ public class InternalASTServiceProvider implements IASTServiceProvider { } public IASTTranslationUnit getTranslationUnit(IStorage fileToParse, IProject project, ICodeReaderFactory fileCreator) throws UnsupportedDialectException{ - return getTranslationUnit( fileToParse.getFullPath().toOSString(), project, fileCreator, null, false); + return getTranslationUnit( fileToParse.getFullPath().toOSString(), project, fileCreator, null); } public IASTTranslationUnit getTranslationUnit(IStorage fileToParse, IProject project) throws UnsupportedDialectException { - return getTranslationUnit( fileToParse.getFullPath().toOSString(), project, SavedCodeReaderFactory.getInstance(), null, false); + return getTranslationUnit( fileToParse.getFullPath().toOSString(), project, SavedCodeReaderFactory.getInstance(), null); } public IASTTranslationUnit getTranslationUnit(IFile fileToParse, boolean parseComments) throws UnsupportedDialectException { - return getTranslationUnit( fileToParse.getLocation().toOSString(), fileToParse, SavedCodeReaderFactory.getInstance(), null, parseComments); + return getTranslationUnit( fileToParse.getLocation().toOSString(), fileToParse, SavedCodeReaderFactory.getInstance(), null); } public IASTTranslationUnit getTranslationUnit(IFile fileToParse, ICodeReaderFactory fileCreator, boolean parseComments) throws UnsupportedDialectException { - return getTranslationUnit( fileToParse.getLocation().toOSString(), fileToParse, fileCreator, null, parseComments); + return getTranslationUnit( fileToParse.getLocation().toOSString(), fileToParse, fileCreator, null); } }