Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-02-07 08:59:34 +0000
committerMarkus Schorn2008-02-07 08:59:34 +0000
commit8565f9f346d8c391ab3063e4ff7f337ce7d097b5 (patch)
treecf093fd3bdbabb4f4e9376a614c6474e15be7609 /core/org.eclipse.cdt.core/model/org
parente885c18bc41ffd1f8a0467fb786ab8549196462c (diff)
downloadorg.eclipse.cdt-8565f9f346d8c391ab3063e4ff7f337ce7d097b5.tar.gz
org.eclipse.cdt-8565f9f346d8c391ab3063e4ff7f337ce7d097b5.tar.xz
org.eclipse.cdt-8565f9f346d8c391ab3063e4ff7f337ce7d097b5.zip
Makes relevant methods/options of AbstractLanguage available in ILanguage + cleanup.
Diffstat (limited to 'core/org.eclipse.cdt.core/model/org')
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/AbstractLanguage.java53
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java73
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java38
3 files changed, 69 insertions, 95 deletions
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/AbstractLanguage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/AbstractLanguage.java
index 4f98e6c9977..c645b0e5806 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/AbstractLanguage.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/AbstractLanguage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,11 +9,9 @@
* Markus Schorn - initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
-
package org.eclipse.cdt.core.model;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
-import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.parser.CodeReader;
@@ -27,40 +25,6 @@ import org.eclipse.core.runtime.PlatformObject;
* @since 4.0
*/
public abstract class AbstractLanguage extends PlatformObject implements ILanguage {
- /**
- * Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
- * Instructs the parser to skip function and method bodies.
- */
- public final static int OPTION_SKIP_FUNCTION_BODIES= 1;
-
- /**
- * Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
- * Instructs the parser to add comment nodes to the ast.
- */
- public final static int OPTION_ADD_COMMENTS= 2;
-
- /**
- * Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
- * Performance optimization, instructs the parser not to create image-locations.
- * When using this option {@link IASTName#getImageLocation()} will always return <code>null</code>.
- */
- public final static int OPTION_NO_IMAGE_LOCATIONS= 4;
-
- /**
- * @deprecated, throws an UnsupportedOperationException
- */
- final public IASTTranslationUnit getASTTranslationUnit(ITranslationUnit file, int style) throws CoreException {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @deprecated, throws an UnsupportedOperationException
- */
- final public IASTTranslationUnit getASTTranslationUnit(ITranslationUnit file, ICodeReaderFactory codeReaderFactory,
- int style) throws CoreException {
- throw new UnsupportedOperationException();
- }
-
/*
* @see org.eclipse.cdt.core.model.ILanguage#getName()
*/
@@ -72,21 +36,6 @@ public abstract class AbstractLanguage extends PlatformObject implements ILangua
return getId();
}
- /**
- * Construct an AST for the source code provided by <code>reader</code>.
- * As an option you can supply
- * @param reader source code to be parsed.
- * @param scanInfo provides include paths and defined symbols.
- * @param fileCreator factory that provides CodeReaders for files included
- * by the source code being parsed.
- * @param index (optional) index to use to provide support for ambiguity
- * resolution.
- * @param options A combination of
- * {@link #OPTION_SKIP_FUNCTION_BODIES} and {@link #OPTION_ADD_COMMENTS} or <code>0</code>.
- * @param log logger
- * @return an AST for the source code provided by reader.
- * @throws CoreException
- */
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, int options, IParserLogService log)
throws CoreException {
// for backwards compatibility
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 811d8f00bac..3d7c49cdbd4 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 QNX Software Systems and others.
+ * Copyright (c) 2005, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,7 +10,6 @@
* Markus Schorn (Wind River Systems)
* IBM Corporation
*******************************************************************************/
-
package org.eclipse.cdt.core.model;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
@@ -32,8 +31,31 @@ import org.eclipse.core.runtime.IAdaptable;
*/
public interface ILanguage extends IAdaptable {
- //public static final QualifiedName KEY = new QualifiedName(CCorePlugin.PLUGIN_ID, "language"); //$NON-NLS-1$
- public static final String KEY = "language"; //$NON-NLS-1$
+ /**
+ * Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
+ * Instructs the parser to skip function and method bodies.
+ */
+ public final static int OPTION_SKIP_FUNCTION_BODIES= 1;
+
+ /**
+ * Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
+ * Instructs the parser to add comment nodes to the ast.
+ */
+ public final static int OPTION_ADD_COMMENTS= 2;
+
+ /**
+ * Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
+ * Performance optimization, instructs the parser not to create image-locations.
+ * When using this option {@link IASTName#getImageLocation()} will always return <code>null</code>.
+ */
+ public final static int OPTION_NO_IMAGE_LOCATIONS= 4;
+
+ /**
+ * Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
+ * Marks the ast as being based on a source-file rather than a header-file. This makes a difference
+ * when bindings from the AST are used for searching the index, e.g. for static variables.
+ */
+ public final static int OPTION_IS_SOURCE_UNIT= 8;
/**
* Return the language id for this language.
@@ -56,21 +78,6 @@ public interface ILanguage extends IAdaptable {
public String getName();
/**
- * @deprecated use {@link ITranslationUnit#getAST()}.
- */
- public IASTTranslationUnit getASTTranslationUnit(
- ITranslationUnit file,
- int style) throws CoreException;
-
- /**
- * @deprecated use {@link ITranslationUnit#getAST(...)}.
- */
- public IASTTranslationUnit getASTTranslationUnit(
- ITranslationUnit file,
- ICodeReaderFactory codeReaderFactory,
- int style) throws CoreException;
-
- /**
* Return the AST completion node for the given offset.
*
* @param reader
@@ -109,15 +116,41 @@ public interface ILanguage extends IAdaptable {
/**
* Construct an AST for the source code provided by <code>reader</code>.
+ * Fully equivalent to
+ * <code> getASTTranslationUnit(reader, scanInfo, fileCreator, index, 0, log) </code>
+ * @param reader source code to be parsed.
+ * @param scanInfo provides include paths and defined symbols.
+ * @param fileCreator factory that provides CodeReaders for files included
+ * by the source code being parsed.
+ * @param index (optional) index to use to provide support for ambiguity
+ * resolution.
+ * @param log logger
+ * @return an AST for the source code provided by reader.
+ * @throws CoreException
+ */
+ public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
+ ICodeReaderFactory fileCreator, IIndex index, IParserLogService log)
+ throws CoreException;
+
+ /**
+ * Construct an AST for the source code provided by <code>reader</code>.
+ * As an option you can supply
* @param reader source code to be parsed.
* @param scanInfo provides include paths and defined symbols.
* @param fileCreator factory that provides CodeReaders for files included
* by the source code being parsed.
* @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_NO_IMAGE_LOCATIONS}, {@link #OPTION_IS_SOURCE_UNIT},
+ * or <code>0</code>.
* @param log logger
* @return an AST for the source code provided by reader.
* @throws CoreException
*/
- public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log) throws CoreException;
+ public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
+ ICodeReaderFactory fileCreator, IIndex index, int options, IParserLogService log)
+ 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 c496de54972..c83ded1e388 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
@@ -11,7 +11,6 @@
* IBM Corporation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
-
package org.eclipse.cdt.internal.core.model;
import java.io.FileInputStream;
@@ -221,13 +220,13 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
public IInclude[] getIncludes() throws CModelException {
ICElement[] celements = getChildren();
- ArrayList aList = new ArrayList();
+ ArrayList<ICElement> aList = new ArrayList<ICElement>();
for (int i = 0; i < celements.length; i++) {
if (celements[i].getElementType() == ICElement.C_INCLUDE) {
aList.add(celements[i]);
}
}
- return (IInclude[]) aList.toArray(new IInclude[0]);
+ return aList.toArray(new IInclude[0]);
}
public IUsing getUsing(String name) {
@@ -247,13 +246,13 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
public IUsing[] getUsings() throws CModelException {
ICElement[] celements = getChildren();
- ArrayList aList = new ArrayList();
+ ArrayList<ICElement> aList = new ArrayList<ICElement>();
for (int i = 0; i < celements.length; i++) {
if (celements[i].getElementType() == ICElement.C_USING) {
aList.add(celements[i]);
}
}
- return (IUsing[]) aList.toArray(new IUsing[0]);
+ return aList.toArray(new IUsing[0]);
}
public INamespace getNamespace(String name) {
@@ -286,13 +285,13 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
public INamespace[] getNamespaces() throws CModelException {
ICElement[] celements = getChildren();
- ArrayList aList = new ArrayList();
+ ArrayList<ICElement> aList = new ArrayList<ICElement>();
for (int i = 0; i < celements.length; i++) {
if (celements[i].getElementType() == ICElement.C_NAMESPACE) {
aList.add(celements[i]);
}
}
- return (INamespace[]) aList.toArray(new INamespace[0]);
+ return aList.toArray(new INamespace[0]);
}
protected void setLocationURI(URI loc) {
@@ -786,24 +785,17 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
fLanguageOfContext= language;
if (language != null) {
ICodeReaderFactory crf= getCodeReaderFactory(style, index, language.getLinkageID());
- IASTTranslationUnit ast= null;
- if (language instanceof AbstractLanguage) {
- int options= 0;
- if ((style & AST_SKIP_FUNCTION_BODIES) != 0) {
- options |= AbstractLanguage.OPTION_SKIP_FUNCTION_BODIES;
- }
- if ((style & AST_CREATE_COMMENT_NODES) != 0) {
- options |= AbstractLanguage.OPTION_ADD_COMMENTS;
- }
- ast= ((AbstractLanguage)language).getASTTranslationUnit(reader, scanInfo, crf, index, options, ParserUtil.getParserLogService());
+ int options= 0;
+ if ((style & AST_SKIP_FUNCTION_BODIES) != 0) {
+ options |= ILanguage.OPTION_SKIP_FUNCTION_BODIES;
}
- else {
- ast= language.getASTTranslationUnit(reader, scanInfo, crf, index, ParserUtil.getParserLogService());
+ if ((style & AST_CREATE_COMMENT_NODES) != 0) {
+ options |= ILanguage.OPTION_ADD_COMMENTS;
}
- if (ast != null) {
- ast.setIsHeaderUnit(isHeaderUnit());
+ if (isSourceUnit()) {
+ options |= ILanguage.OPTION_IS_SOURCE_UNIT;
}
- return ast;
+ return ((AbstractLanguage)language).getASTTranslationUnit(reader, scanInfo, crf, index, options, ParserUtil.getParserLogService());
}
}
return null;
@@ -836,7 +828,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
IIndexFile indexFile= index.getFile(CTX_LINKAGES[i], ifl);
if (indexFile != null) {
// bug 199412, when a source-file includes itself the context may recurse.
- HashSet visited= new HashSet();
+ HashSet<IIndexFile> visited= new HashSet<IIndexFile>();
visited.add(indexFile);
indexFile = getParsedInContext(indexFile);
while (indexFile != null && visited.add(indexFile)) {

Back to the top