From c4df8f4e6fb3b2e2a2654c31b66085d55dbc1e51 Mon Sep 17 00:00:00 2001
From: John Camelon
+ * For a complete description of the configurable options, see
+ * For a complete description of the configurable options, see
+ * For a complete description of the configurable options, see
+ * For a complete description of the configurable options, see
+ * For a complete description of the configurable options, see
+ * For a complete description of the configurable options, see
+ * For a complete description of the configurable options, see "org.eclipse.cdt.core.problem"
).
* This can be used to recognize those markers in the workspace that flag problems
- * detected by the C ompilers.
+ * detected by the C compilers.
*/
public static final String C_MODEL_PROBLEM_MARKER = CCorePlugin.PLUGIN_ID + ".problem"; //$NON-NLS-1$
@@ -30,6 +30,15 @@ public interface ICModelMarker {
* itself if it can be found.
*/
public static final String C_MODEL_MARKER_VARIABLE = "problem.variable"; //$NON-NLS-1$
+
+ /**
+ * C model task marker type (value "org.eclipse.cdt.core.task"
).
+ * This can be used to recognize task markers in the workspace that correspond to tasks
+ * specified in C/C++ source comments and detected during translation (for example, 'TO-DO: ...').
+ * Tasks are identified by a task tag, which can be customized through CCorePlugin
+ * option "org.eclipse.cdt.core.translation.taskTag"
.
+ */
+ public static final String TASK_MARKER = CCorePlugin.PLUGIN_ID + ".task"; //$NON-NLS-1$
}
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 0a830ea9f47..93d9ce181de 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,8 @@ package org.eclipse.cdt.core.model;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
+import java.util.Map;
+
/**
* A C project represents a view of a project resource in terms of C
* elements such as , ICContainer, ITranslationUnit ....
@@ -51,4 +53,59 @@ public interface ICProject extends ICContainer {
* @return IProject
*/
IProject getProject();
+
+ /**
+ * Helper method for returning one option value only. Equivalent to (String)this.getOptions(inheritCCoreOptions).get(optionName)
+ * Note that it may answer null
if this option does not exist, or if there is no custom value for it.
+ * CCorePlugin#getDefaultOptions
.
+ * CCorePlugin
.
+ * CCorePlugin#getDefaultOptions
.
+ * String
; value type: String
)
+ * @see CCorePlugin#getDefaultOptions
+ */
+ Map getOptions(boolean inheritCCoreOptions);
+
+ /**
+ * Helper method for setting one option value only. Equivalent to Map options = this.getOptions(false); map.put(optionName, optionValue); this.setOptions(map)
+ * CCorePlugin#getDefaultOptions
.
+ * CCorePlugin#getDefaultOptions
.
+ * String
; value type: String
),
+ * or null
to flush all custom options (clients will automatically get the global CCorePlugin options).
+ * @see CCorePlugin#getDefaultOptions
+ */
+ void setOptions(Map newOptions);
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java
index d07551fed27..56ddb04463f 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java
@@ -17,15 +17,20 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.HashSet;
+import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.cdt.core.model.INamespace;
import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.core.model.IStructure;
import org.eclipse.cdt.core.model.ITemplate;
import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.core.parser.ITranslationResult;
import org.eclipse.cdt.core.parser.IParser;
+import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.internal.core.dom.ArrayQualifier;
@@ -52,11 +57,20 @@ import org.eclipse.cdt.internal.core.dom.TemplateDeclaration;
import org.eclipse.cdt.internal.core.dom.TemplateParameter;
import org.eclipse.cdt.internal.core.dom.TranslationUnit;
import org.eclipse.cdt.internal.core.dom.TypeSpecifier;
+import org.eclipse.cdt.internal.core.parser.DefaultErrorHandlingPolicies;
+import org.eclipse.cdt.internal.core.parser.TranslationResult;
+import org.eclipse.cdt.internal.core.parser.TranslationOptions;
+import org.eclipse.cdt.internal.core.parser.ITranslationResultRequestor;
import org.eclipse.cdt.internal.core.parser.Name;
+import org.eclipse.cdt.internal.core.parser.problem.DefaultProblemFactory;
+import org.eclipse.cdt.internal.core.parser.problem.ProblemReporter;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
-public class CModelBuilder {
+public class CModelBuilder implements ITranslationResultRequestor {
protected org.eclipse.cdt.internal.core.model.TranslationUnit translationUnit;
protected Map newElements;
@@ -67,9 +81,38 @@ public class CModelBuilder {
}
public Map parse() throws Exception {
- DOMBuilder domBuilder = new DOMBuilder();
- IParser parser = ParserFactory.createParser(ParserFactory.createScanner( new StringReader( translationUnit.getBuffer().getContents() ), null, null, null, ParserMode.QUICK_PARSE ), domBuilder, ParserMode.QUICK_PARSE);
-
+
+ DOMBuilder domBuilder = new DOMBuilder();
+
+ // create a problem reporter
+ Map options = null;
+ if (translationUnit != null && translationUnit.getCProject() != null) {
+ options = translationUnit.getCProject().getOptions(true);
+ }
+ TranslationOptions cOptions = new TranslationOptions(options);
+ ProblemReporter problemReporter = new ProblemReporter(
+ DefaultErrorHandlingPolicies.proceedWithAllProblems(),
+ cOptions,
+ new DefaultProblemFactory()
+ );
+
+ // create translation result
+ TranslationResult unitResult = new TranslationResult(translationUnit);
+
+ IParser parser = ParserFactory.createParser(
+ ParserFactory.createScanner(
+ new StringReader(
+ translationUnit.getBuffer().getContents()
+ ),
+ null, null, null,
+ ParserMode.QUICK_PARSE,
+ problemReporter, unitResult
+ ),
+ domBuilder,
+ ParserMode.QUICK_PARSE,
+ problemReporter, unitResult
+ );
+
if( translationUnit.getCProject() != null )
{
IProject currentProject = translationUnit.getCProject().getProject();
@@ -95,6 +138,9 @@ public class CModelBuilder {
System.out.println( "NullPointer exception generating CModel");
npe.printStackTrace();
}
+
+ // process translation results
+ acceptResult(unitResult);
// For the debuglog to take place, you have to call
// Util.setDebugging(true);
@@ -1009,4 +1055,100 @@ public class CModelBuilder {
return name;
}
+
+
+ /**
+ * @see ITranslatorRequestor#acceptResult(ITranslationResult)
+ */
+ public void acceptResult(ITranslationResult result) {
+ ITranslationUnit translationUnit = result.getTranslationUnit();
+
+ try {
+ updateTasksFor(translationUnit, result); // record tasks
+ } catch (CoreException e) {
+ System.out.println("Exception while accepting parse results");
+ e.printStackTrace();
+ }
+ }
+
+ protected void updateTasksFor(ITranslationUnit sourceFile, ITranslationResult result) throws CoreException {
+ IProblem[] tasks = result.getTasks();
+
+ storeTasksFor(sourceFile, tasks);
+ }
+
+ protected void storeTasksFor(ITranslationUnit sourceFile, IProblem[] tasks) throws CoreException {
+ if (sourceFile == null) return;
+
+ if (tasks == null) tasks = new IProblem[0];
+
+ IResource resource = sourceFile.getResource();
+ IMarker[] existingTaskMarkers = resource.findMarkers(ICModelMarker.TASK_MARKER, false, IResource.DEPTH_ONE);
+ HashSet taskSet = new HashSet();
+
+ if (existingTaskMarkers != null)
+ for (int i=0; iIResourceDelta
s into ICElementDelta
s.
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 f96d6e787d5..776cf0d3a65 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
@@ -6,6 +6,10 @@ package org.eclipse.cdt.internal.core.model;
*/
import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature;
@@ -21,6 +25,8 @@ import org.eclipse.cdt.core.model.ILibraryReference;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.core.runtime.QualifiedName;
public class CProject extends CContainer implements ICProject {
@@ -39,6 +45,8 @@ public class CProject extends CContainer implements ICProject {
public IProject getProject() {
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;
@@ -92,4 +100,149 @@ public class CProject extends CContainer implements ICProject {
}
return (ILibraryReference[])list.toArray(new ILibraryReference[0]);
}
+
+ /**
+ * @see org.eclipse.cdt.core.model.ICProject#getOption(String, boolean)
+ */
+ public String getOption(String optionName, boolean inheritCCoreOptions) {
+
+ if (CModelManager.OptionNames.contains(optionName)) {
+ Preferences preferences = getPreferences();
+
+ if (preferences == null || preferences.isDefault(optionName)) {
+ return inheritCCoreOptions ? CCorePlugin.getOption(optionName) : null;
+ }
+
+ return preferences.getString(optionName).trim();
+ }
+
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.ICProject#getOptions(boolean)
+ */
+ public Map getOptions(boolean inheritCCoreOptions) {
+ // initialize to the defaults from CCorePlugin options pool
+ Map options = inheritCCoreOptions ? CCorePlugin.getOptions() : new HashMap(5);
+
+ Preferences preferences = getPreferences();
+ if (preferences == null) return options;
+ HashSet optionNames = CModelManager.OptionNames;
+
+ // get preferences set to their default
+ if (inheritCCoreOptions){
+ String[] defaultPropertyNames = preferences.defaultPropertyNames();
+ for (int i = 0; i < defaultPropertyNames.length; i++){
+ String propertyName = defaultPropertyNames[i];
+ if (optionNames.contains(propertyName)){
+ options.put(propertyName, preferences.getDefaultString(propertyName).trim());
+ }
+ }
+ }
+ // get custom preferences not set to their default
+ String[] propertyNames = preferences.propertyNames();
+ for (int i = 0; i < propertyNames.length; i++){
+ String propertyName = propertyNames[i];
+ if (optionNames.contains(propertyName)){
+ options.put(propertyName, preferences.getString(propertyName).trim());
+ }
+ }
+ return options;
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.ICProject#setOption(java.lang.String, java.lang.String)
+ */
+ public void setOption(String optionName, String optionValue) {
+ if (!CModelManager.OptionNames.contains(optionName)) return; // unrecognized option
+
+ Preferences preferences = getPreferences();
+ preferences.setDefault(optionName, CUSTOM_DEFAULT_OPTION_VALUE); // empty string isn't the default (26251)
+ preferences.setValue(optionName, optionValue);
+
+ savePreferences(preferences);
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.ICProject#setOptions(Map)
+ */
+ public void setOptions(Map newOptions)
+ {
+ Preferences preferences = new Preferences();
+ setPreferences(preferences); // always reset (26255)
+
+ if (newOptions != null){
+ Iterator keys = newOptions.keySet().iterator();
+
+ while (keys.hasNext()){
+ String key = (String)keys.next();
+ if (!CModelManager.OptionNames.contains(key)) continue; // unrecognized option
+
+ // no filtering for encoding (custom encoding for project is allowed)
+ String value = (String)newOptions.get(key);
+ preferences.setDefault(key, CUSTOM_DEFAULT_OPTION_VALUE); // empty string isn't the default (26251)
+ preferences.setValue(key, value);
+ }
+ }
+
+ // persist options
+ savePreferences(preferences);
+ }
+
+ /**
+ * Returns the project custom preference pool.
+ * Project preferences may include custom encoding.
+ */
+ private Preferences getPreferences() {
+ Preferences preferences = new Preferences();
+ Iterator iter = CModelManager.OptionNames.iterator();
+
+ while (iter.hasNext()) {
+ String qualifiedName = (String)iter.next();
+ String dequalifiedName = qualifiedName.substring(CCorePlugin.PLUGIN_ID.length()+1);
+ String value = null;
+
+ try {
+ value = resource.getPersistentProperty(new QualifiedName(CCorePlugin.PLUGIN_ID, dequalifiedName));
+ } catch (CoreException e) {
+ }
+
+ if (value != null) preferences.setValue(qualifiedName, value);
+ }
+
+ return preferences;
+ }
+
+ /**
+ * Save project custom preferences to persistent properties
+ */
+ private void savePreferences(Preferences preferences) {
+ if (preferences == null) return;
+ Iterator iter = CModelManager.OptionNames.iterator();
+
+ while (iter.hasNext()) {
+ String qualifiedName = (String)iter.next();
+ String dequalifiedName = qualifiedName.substring(CCorePlugin.PLUGIN_ID.length()+1);
+ String value = null;
+
+ try {
+ value = preferences.getString(qualifiedName);
+
+ if (value != null && !value.equals(preferences.getDefaultString(qualifiedName))) {
+ resource.setPersistentProperty(new QualifiedName(CCorePlugin.PLUGIN_ID, dequalifiedName), value);
+ } else {
+ resource.setPersistentProperty(new QualifiedName(CCorePlugin.PLUGIN_ID, dequalifiedName), null);
+ }
+ } catch (CoreException e) {
+ }
+ }
+ }
+
+ /*
+ * Set cached preferences, no preferences are saved, only info is updated
+ */
+ private void setPreferences(Preferences preferences) {
+ // Do nothing
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog
index dcf548c7843..0412009b09e 100644
--- a/core/org.eclipse.cdt.core/parser/ChangeLog
+++ b/core/org.eclipse.cdt.core/parser/ChangeLog
@@ -2,6 +2,11 @@
Update IASTExpression.
Move Parser.Backtrack and Parser.EndOfFile to external interface.
+2003-06-26 Victor Mozgin
+ Task tags support in C/C++ comments (initial revision).
+ Infrastructure to support problem reporting during translation.
+ Additional infrastructure for options/preferences handling.
+
2003-06-25 John Camelon
Fixed bug39348 - sizeof elaborated types fail in parsing expression
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IProblem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IProblem.java
index e5595b272e0..f6cc971ebe1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IProblem.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IProblem.java
@@ -1,19 +1,148 @@
-/**********************************************************************
- * 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
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation 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-v05.html
+ * http://www.eclipse.org/legal/cpl-v10.html
*
- * Contributors:
- * IBM Rational Software - Initial API and implementation
-***********************************************************************/
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
package org.eclipse.cdt.core.parser;
-
+
/**
- * @author jcamelon
- *
+ * Description of a C/C++ problem, as detected by the translation or some of the underlying
+ * technology reusing it.
+ * A problem provides access to:
+ *
+ *
*/
-public interface IProblem {
+public interface IProblem {
+
+ /**
+ * Answer back the original arguments recorded into the problem.
+ * @return the original arguments recorded into the problem
+ */
+ String[] getArguments();
+ /**
+ * Returns the problem id
+ *
+ * @return the problem id
+ */
+ int getID();
+
+ /**
+ * Answer a localized, human-readable message string which describes the problem.
+ *
+ * @return a localized, human-readable message string which describes the problem
+ */
+ String getMessage();
+
+ /**
+ * Answer the file name in which the problem was found.
+ *
+ * @return the file name in which the problem was found
+ */
+ char[] getOriginatingFileName();
+
+ /**
+ * Answer the end position of the problem (inclusive), or -1 if unknown.
+ *
+ * @return the end position of the problem (inclusive), or -1 if unknown
+ */
+ int getSourceEnd();
+
+ /**
+ * Answer the line number in source where the problem begins.
+ *
+ * @return the line number in source where the problem begins
+ */
+ int getSourceLineNumber();
+
+ /**
+ * Answer the start position of the problem (inclusive), or -1 if unknown.
+ *
+ * @return the start position of the problem (inclusive), or -1 if unknown
+ */
+ int getSourceStart();
+
+ /**
+ * Checks the severity to see if the Error bit is set.
+ *
+ * @return true if the Error bit is set for the severity, false otherwise
+ */
+ boolean isError();
+
+ /**
+ * Checks the severity to see if the Warning bit is not set.
+ *
+ * @return true if the Warning bit is not set for the severity, false otherwise
+ */
+ boolean isWarning();
+
+ /**
+ * Set the end position of the problem (inclusive), or -1 if unknown.
+ * Used for shifting problem positions.
+ *
+ * @param sourceEnd the given end position
+ */
+ void setSourceEnd(int sourceEnd);
+
+ /**
+ * Set the line number in source where the problem begins.
+ *
+ * @param lineNumber the given line number
+ */
+ void setSourceLineNumber(int lineNumber);
+
+ /**
+ * Set the start position of the problem (inclusive), or -1 if unknown.
+ * Used for shifting problem positions.
+ *
+ * @param the given start position
+ */
+ void setSourceStart(int sourceStart);
+
+ /**
+ * Problem Categories
+ * The high bits of a problem ID contains information about the category of a problem.
+ * For example, (problemID & TypeRelated) != 0, indicates that this problem is type related.
+ *
+ * A problem category can help to implement custom problem filters. Indeed, when numerous problems
+ * are listed, focusing on import related problems first might be relevant.
+ *
+ * When a problem is tagged as Internal, it means that no change other than a local source code change
+ * can fix the corresponding problem.
+ */
+ int TypeRelated = 0x01000000;
+ int FieldRelated = 0x02000000;
+ int MethodRelated = 0x04000000;
+ int ConstructorRelated = 0x08000000;
+ int ImportRelated = 0x10000000;
+ int Internal = 0x20000000;
+ int Syntax = 0x40000000;
+
+ /**
+ * Mask to use in order to filter out the category portion of the problem ID.
+ */
+ int IgnoreCategoriesMask = 0xFFFFFF;
+
+ /**
+ * Below are listed all available problem IDs. Note that this list could be augmented in the future,
+ * as new features are added to the C/C++ core implementation.
+ */
+
+ /**
+ * ID reserved for referencing an internal error inside the CCorePlugin implementation which
+ * may be surfaced as a problem associated with the translation unit which caused it to occur.
+ */
+ int Unclassified = 0;
+
+ // detected task
+ int Task = Internal + 450;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IProblemReporter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IProblemReporter.java
new file mode 100644
index 00000000000..8dc3e8e0e27
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IProblemReporter.java
@@ -0,0 +1,27 @@
+/*
+ * Created on 25-Jun-2003
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package org.eclipse.cdt.core.parser;
+
+/**
+ * @author vmozgin
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public interface IProblemReporter {
+
+ public ITranslationOptions getOptions();
+
+ public abstract void task(
+ String tag,
+ String message,
+ String priority,
+ int start,
+ int end,
+ int line,
+ ITranslationResult result);
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IReferenceContext.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IReferenceContext.java
new file mode 100644
index 00000000000..5bde5620cfd
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IReferenceContext.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser;
+
+/**
+ * Implementors are valid translation contexts from which we can
+ * escape in case of error:
+ * For example: method, type or translation unit.
+ */
+public interface IReferenceContext {
+
+ ITranslationResult translationResult();
+}
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 25f36ca4d26..61358e74aad 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
@@ -33,12 +33,9 @@ public interface IScanner {
public int getCount();
public int getDepth();
- /**
- * @return
- */
+
public IToken nextTokenForStringizing() throws ScannerException, EndOfFile;
- /**
- * @param b
- */
public void setTokenizingMacroReplacementList(boolean b);
+
+ public void onParseEnd();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScannerContext.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScannerContext.java
index 05586936e6f..fb8ce485c84 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScannerContext.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScannerContext.java
@@ -24,9 +24,10 @@ public interface IScannerContext {
*
* @param macroOffset Offset of the expanding macro
* @param macroLength Length of the macro identifier
+ * @param line Initial line counter for the context
* @return
*/
- public IScannerContext initialize(Reader r, String f, int k, IASTInclusion i, int macroOffset, int macroLength);
+ public IScannerContext initialize(Reader r, String f, int k, IASTInclusion i, int macroOffset, int macroLength, int line);
public IScannerContext initialize(Reader r, String f, int k, IASTInclusion i);
public int read() throws IOException;
@@ -55,7 +56,13 @@ public interface IScannerContext {
* @return int
*/
public int getRelativeOffset();
-
+
+ /**
+ * Returns current line counter.
+ * @return int
+ */
+ public int getLine();
+
public Reader getReader();
public int undoStackSize();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ITranslationOptions.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ITranslationOptions.java
new file mode 100644
index 00000000000..c0b2c11fea7
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ITranslationOptions.java
@@ -0,0 +1,35 @@
+/*
+ * Created on 25-Jun-2003
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+
+package org.eclipse.cdt.core.parser;
+
+import java.util.Map;
+
+/**
+ * @author vmozgin
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public interface ITranslationOptions {
+
+ /**
+ * Option IDs
+ */
+ public static final String OPTION_TaskTags
+ = "org.eclipse.cdt.core.translation.taskTags"; //$NON-NLS-1$
+ public static final String OPTION_TaskPriorities
+ = "org.eclipse.cdt.core.translation.taskPriorities"; //$NON-NLS-1$
+
+ /**
+ * Initializing the compiler options with external settings
+ */
+ public abstract void initialize(Map settings);
+
+ public abstract char[][] getTaskTags();
+ public abstract char[][] getTaskPriorities();
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ITranslationResult.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ITranslationResult.java
new file mode 100644
index 00000000000..d0fa2cc9884
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ITranslationResult.java
@@ -0,0 +1,65 @@
+/*
+ * Created on 25-Jun-2003
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+
+package org.eclipse.cdt.core.parser;
+
+import org.eclipse.cdt.core.model.ITranslationUnit;
+
+/**
+ * @author vmozgin
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+
+public interface ITranslationResult {
+
+ public abstract IProblem[] getAllProblems();
+
+ /**
+ * Answer the initial translation unit corresponding to the present translation result
+ */
+ public abstract ITranslationUnit getTranslationUnit();
+
+ /**
+ * Answer the initial file name
+ */
+ public abstract char[] getFileName();
+
+ /**
+ * Answer the errors encountered during translation.
+ */
+ public abstract IProblem[] getErrors();
+
+ /**
+ * Answer the problems (errors and warnings) encountered during translation.
+ *
+ * It is intended to be used only once all problems have been detected,
+ * and makes sure the problems slot as the exact size of the number of
+ * problems.
+ */
+ public abstract IProblem[] getProblems();
+
+ /**
+ * Answer the tasks (TO-DO, ...) encountered during translation.
+ *
+ * It is intended to be used only once all problems have been detected,
+ * and makes sure the problems slot as the exact size of the number of
+ * problems.
+ */
+ public abstract IProblem[] getTasks();
+
+ public abstract boolean hasErrors();
+ public abstract boolean hasProblems();
+ public abstract boolean hasSyntaxError();
+ public abstract boolean hasTasks();
+ public abstract boolean hasWarnings();
+
+ public abstract void record(IProblem newProblem, IReferenceContext referenceContext);
+
+ public abstract ITranslationResult tagAsAccepted();
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java
index 358c178caa9..caab0b47ae0 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java
@@ -23,6 +23,7 @@ import org.eclipse.cdt.internal.core.parser.Scanner;
import org.eclipse.cdt.internal.core.parser.ast.full.FullParseASTFactory;
import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory;
+
/**
* @author jcamelon
*
@@ -37,30 +38,45 @@ public class ParserFactory {
return new FullParseASTFactory();
}
- public static IParser createParser( IScanner scanner, IParserCallback callback, ParserMode mode )
+ public static IParser createParser( IScanner scanner, IParserCallback callback, ParserMode mode )
+ {
+ return createParser(scanner, callback, mode, null, null);
+ }
+
+ public static IParser createParser( IScanner scanner, IParserCallback callback, ParserMode mode, IProblemReporter problemReporter, ITranslationResult unitResult )
{
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
IParserCallback ourCallback = (( callback == null) ? new NullSourceElementRequestor() : callback );
- return new Parser( scanner, ourCallback, ourMode );
+ return new Parser( scanner, ourCallback, ourMode, problemReporter, unitResult );
}
-
- public static IScanner createScanner( Reader input, String fileName, Map defns, List inclusions, ParserMode mode )
+
+ public static IScanner createScanner( Reader input, String fileName, Map defns, List inclusions, ParserMode mode )
+ {
+ return createScanner(input, fileName, defns, inclusions, mode, null, null);
+ }
+
+ public static IScanner createScanner( Reader input, String fileName, Map defns, List inclusions, ParserMode mode, IProblemReporter problemReporter, ITranslationResult unitResult )
{
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
- IScanner s = new Scanner( input, fileName, defns );
+ IScanner s = new Scanner( input, fileName, defns, problemReporter, unitResult );
s.setMode( ourMode );
s.overwriteIncludePath(inclusions);
return s;
}
-
- public static IPreprocessor createPreprocessor( Reader input, String fileName, Map defns, List inclusions, ParserMode mode )
+
+ public static IPreprocessor createPreprocessor( Reader input, String fileName, Map defns, List inclusions, ParserMode mode )
+ {
+ return createPreprocessor(input, fileName, defns, inclusions, mode, null, null);
+ }
+
+ public static IPreprocessor createPreprocessor( Reader input, String fileName, Map defns, List inclusions, ParserMode mode, IProblemReporter problemReporter, ITranslationResult unitResult )
{
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
- IPreprocessor s = new Preprocessor( input, fileName, defns );
+ IPreprocessor s = new Preprocessor( input, fileName, defns, problemReporter, unitResult );
s.setMode( ourMode );
s.overwriteIncludePath(inclusions);
- return s;
- }
+ return s;
+ }
public static ILineOffsetReconciler createLineOffsetReconciler( Reader input )
{
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ContextStack.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ContextStack.java
index f88b29e38d7..54b43177314 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ContextStack.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ContextStack.java
@@ -42,6 +42,8 @@ public class ContextStack {
public void updateContext(Reader reader, String filename, int type, IASTInclusion inclusion, ISourceElementRequestor requestor, int macroOffset, int macroLength) throws ScannerException
{
+ int startLine = 1;
+
// If we expand a macro within a macro, then keep offsets of the top-level one,
// as only the top level macro identifier is properly positioned
if (type == IScannerContext.MACROEXPANSION) {
@@ -49,10 +51,12 @@ public class ContextStack {
macroOffset = currentContext.getMacroOffset();
macroLength = currentContext.getMacroLength();
}
+
+ startLine = currentContext.getLine();
}
-
+
undoStack.clear();
- push( new ScannerContext().initialize(reader, filename, type, null, macroOffset, macroLength ), requestor );
+ push( new ScannerContext().initialize(reader, filename, type, null, macroOffset, macroLength, startLine ), requestor );
}
protected void push( IScannerContext context, ISourceElementRequestor requestor ) throws ScannerException
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DefaultErrorHandlingPolicies.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DefaultErrorHandlingPolicies.java
new file mode 100644
index 00000000000..1decbaaf1ba
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DefaultErrorHandlingPolicies.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.parser;
+
+public class DefaultErrorHandlingPolicies {
+
+ /**
+ * Accumulate all problems, then exit without proceeding.
+ *
+ * Typically, the #proceedWithProblems(Problem[]) should
+ * show the problems.
+ *
+ */
+ public static IErrorHandlingPolicy exitAfterAllProblems() {
+ return new IErrorHandlingPolicy() {
+ public boolean stopOnFirstError() {
+ return false;
+ }
+ public boolean proceedOnErrors(){
+ return false;
+ }
+ };
+ }
+
+ /**
+ * Exit without proceeding on the first problem wich appears
+ * to be an error.
+ *
+ */
+ public static IErrorHandlingPolicy exitOnFirstError() {
+ return new IErrorHandlingPolicy() {
+ public boolean stopOnFirstError() {
+ return true;
+ }
+ public boolean proceedOnErrors(){
+ return false;
+ }
+ };
+ }
+
+ /**
+ * Proceed on the first error met.
+ *
+ */
+ public static IErrorHandlingPolicy proceedOnFirstError() {
+ return new IErrorHandlingPolicy() {
+ public boolean stopOnFirstError() {
+ return true;
+ }
+ public boolean proceedOnErrors(){
+ return true;
+ }
+ };
+ }
+
+ /**
+ * Accumulate all problems, then proceed with them.
+ *
+ */
+ public static IErrorHandlingPolicy proceedWithAllProblems() {
+ return new IErrorHandlingPolicy() {
+ public boolean stopOnFirstError() {
+ return false;
+ }
+ public boolean proceedOnErrors(){
+ return true;
+ }
+ };
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IErrorHandlingPolicy.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IErrorHandlingPolicy.java
new file mode 100644
index 00000000000..66e4fac919e
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IErrorHandlingPolicy.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.parser;
+
+/**
+ * Handler policy is responsible to answer the 2 following
+ * questions:
+ * 1. should the handler stop on first problem which appears
+ * to be a real error (that is, not a warning),
+ * 2. should it proceed once it has gathered all problems
+ *
+ * The intent is that one can supply its own policy to implement
+ * some interactive error handling strategy where some UI would
+ * display problems and ask user if he wants to proceed or not.
+ */
+
+public interface IErrorHandlingPolicy {
+ boolean proceedOnErrors();
+ boolean stopOnFirstError();
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IProblemFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IProblemFactory.java
new file mode 100644
index 00000000000..2cd03216bd3
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IProblemFactory.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.parser;
+
+import org.eclipse.cdt.core.parser.IProblem;
+
+import java.util.Locale;
+
+/**
+ * Factory used during translation to build the actual problems
+ * which are handed back in the translation result.
+ *
+ * This allows sharing the internal problem representation with the environment.
+ *
+ * Note: The factory is responsible for computing and storing a localized error message.
+ */
+
+public interface IProblemFactory {
+
+ IProblem createProblem(
+ char[] originatingFileName,
+ int problemId,
+ String[] problemArguments,
+ String[] messageArguments, // shorter versions of the problemArguments
+ int severity,
+ int startPosition,
+ int endPosition,
+ int lineNumber);
+
+ Locale getLocale();
+
+ String getLocalizedMessage(int problemId, String[] messageArguments);
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ITranslationResultRequestor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ITranslationResultRequestor.java
new file mode 100644
index 00000000000..497dbba564d
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ITranslationResultRequestor.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.parser;
+
+import org.eclipse.cdt.core.parser.ITranslationResult;
+
+/**
+ * A callback interface for receiving translation results.
+ */
+public interface ITranslationResultRequestor {
+
+ /**
+ * Accept a translation result.
+ */
+ public void acceptResult(ITranslationResult result);
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java
index 99a82f49a88..9ff44fc00d9 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java
@@ -13,7 +13,9 @@ import org.eclipse.cdt.core.parser.Backtrack;
import org.eclipse.cdt.core.parser.EndOfFile;
import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IParserCallback;
+import org.eclipse.cdt.core.parser.IProblemReporter;
import org.eclipse.cdt.core.parser.IScanner;
+import org.eclipse.cdt.core.parser.ITranslationResult;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ParserFactory;
@@ -34,6 +36,8 @@ import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType;
import org.eclipse.cdt.internal.core.model.Util;
+
+
/**
* This is our first implementation of the IParser interface, serving as a parser for
* ANSI C and C++.
@@ -57,7 +61,10 @@ public class Parser implements IParser
private boolean cppNature = true; // true for C++, false for C
private ISourceElementRequestor requestor = null;
// new callback mechanism
- private IASTFactory astFactory = null; // ast factory
+ private IASTFactory astFactory = null; // ast factory
+
+ private IProblemReporter problemReporter = null;
+ private ITranslationResult unitResult = null;
/**
* This is the single entry point for setting parsePassed to
* false, and also making note what token offset we failed upon.
@@ -78,10 +85,12 @@ public class Parser implements IParser
* @param c IParserCallback instance that will receive callbacks as we parse
* @param quick Are we asking for a high level parse or not?
*/
- public Parser(IScanner s, IParserCallback c, ParserMode m)
+ public Parser(IScanner s, IParserCallback c, ParserMode m, IProblemReporter problemReporter, ITranslationResult unitResult)
{
callback = c;
scanner = s;
+ this.problemReporter = problemReporter;
+ this.unitResult = unitResult;
if (c instanceof ISourceElementRequestor)
setRequestor((ISourceElementRequestor)c);
mode = m;
@@ -90,8 +99,11 @@ public class Parser implements IParser
scanner.setCallback(c);
scanner.setASTFactory(astFactory);
}
+
+ // counter that keeps track of the number of times Parser.parse() is called
private static int parseCount = 0;
- // counter that keeps track of the number of times Parser.parse() is called
+
+
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParser#parse()
*/
@@ -99,6 +111,7 @@ public class Parser implements IParser
{
long startTime = System.currentTimeMillis();
translationUnit();
+ onParseEnd();
// For the debuglog to take place, you have to call
// Util.setDebugging(true);
// Or set debug to true in the core plugin preference
@@ -111,6 +124,11 @@ public class Parser implements IParser
+ (parsePassed ? "" : " - parse failure"));
return parsePassed;
}
+
+ public void onParseEnd() {
+ scanner.onParseEnd();
+ }
+
/**
* This is the top-level entry point into the ANSI C++ grammar.
*
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Preprocessor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Preprocessor.java
index cad991c6070..18dd83e0701 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Preprocessor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Preprocessor.java
@@ -15,8 +15,11 @@ import java.util.Map;
import org.eclipse.cdt.core.parser.EndOfFile;
import org.eclipse.cdt.core.parser.IPreprocessor;
+import org.eclipse.cdt.core.parser.IProblemReporter;
+import org.eclipse.cdt.core.parser.ITranslationResult;
import org.eclipse.cdt.core.parser.ScannerException;
+
/**
* @author jcamelon
*
@@ -28,9 +31,9 @@ public class Preprocessor extends Scanner implements IPreprocessor {
* @param filename
* @param defns
*/
- public Preprocessor(Reader reader, String filename, Map defns) {
- super(reader, filename, defns);
- }
+ public Preprocessor(Reader reader, String filename, Map defns, IProblemReporter problemReporter, ITranslationResult unitResult) {
+ super(reader, filename, defns, problemReporter, unitResult);
+ }
public void process()
{
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 3469fc46e77..21180b747b0 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
@@ -29,10 +29,13 @@ import org.eclipse.cdt.core.parser.EndOfFile;
import org.eclipse.cdt.core.parser.IMacroDescriptor;
import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IParserCallback;
+import org.eclipse.cdt.core.parser.IProblemReporter;
import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IScannerContext;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.IToken;
+import org.eclipse.cdt.core.parser.ITranslationResult;
+import org.eclipse.cdt.core.parser.ITranslationOptions;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ScannerException;
@@ -47,8 +50,8 @@ import org.eclipse.cdt.core.parser.ast.IASTMacro;
*/
public class Scanner implements IScanner {
-
- public Scanner(Reader reader, String filename, Map defns) {
+
+ public Scanner(Reader reader, String filename, Map defns, IProblemReporter problemReporter, ITranslationResult unitResult) {
try {
//this is a hack to get around a sudden EOF experience
contextStack.push(
@@ -66,6 +69,14 @@ public class Scanner implements IScanner {
}
if( defns != null )
definitions.putAll( defns );
+
+
+ this.problemReporter = problemReporter;
+ this.translationResult = unitResult;
+
+ if (problemReporter != null && problemReporter.getOptions() != null) {
+ this.taskTagsInfo = new TaskTagsInfo(problemReporter.getOptions());
+ }
}
@@ -154,7 +165,7 @@ public class Scanner implements IScanner {
int next = getChar();
if (next == '/') {
// single line comment
- skipOverTextUntilNewline();
+ skipOverSinglelineComment();
break;
} else if (next == '*') {
// multiline comment
@@ -497,8 +508,8 @@ public class Scanner implements IScanner {
c = getChar();
if( c == '/' )
{
- while (c != '\n' && c != NOCHAR)
- c = getChar();
+ skipOverSinglelineComment();
+ c = getChar();
continue;
}
else if( c == '*' )
@@ -1316,9 +1327,8 @@ public class Scanner implements IScanner {
c = getChar();
switch (c) {
case '/' :
+ skipOverSinglelineComment();
c = getChar();
- while (c != '\n' && c != NOCHAR)
- c = getChar();
continue;
case '*' :
skipOverMultilineComment();
@@ -1442,9 +1452,8 @@ public class Scanner implements IScanner {
c = getChar();
switch (c) {
case '/' :
- c = getChar();
- while (c != '\n' && c != NOCHAR)
- c = getChar();
+ skipOverSinglelineComment();
+ c = getChar();
continue;
case '*' :
skipOverMultilineComment();
@@ -1651,8 +1660,9 @@ public class Scanner implements IScanner {
new StringReader(expression + ";"),
EXPRESSION,
definitions,
- null, ParserMode.COMPLETE_PARSE );
- IParser parser = ParserFactory.createParser(trial, evaluator, ParserMode.COMPLETE_PARSE );
+ null, ParserMode.COMPLETE_PARSE,
+ problemReporter, translationResult );
+ IParser parser = ParserFactory.createParser(trial, evaluator, ParserMode.COMPLETE_PARSE, problemReporter, translationResult );
parser.expression(null);
expressionEvalResult = evaluator.getResult();
@@ -1688,16 +1698,43 @@ public class Scanner implements IScanner {
}
}
}
+
+ protected void skipOverSinglelineComment() throws ScannerException {
+
+ StringBuffer comment = new StringBuffer("//");
+ int commentOffset = lastContext.getOffset() - lastContext.undoStackSize() - 2;
+ int commentStartLine = lastContext.getLine();
+ int c;
+
+ loop:
+ for (;;) {
+ c = getChar();
+ comment.append((char)c);
+ switch (c) {
+ case NOCHAR :
+ case '\n' :
+ break loop;
+ default :
+ break;
+ }
+ }
+
+ checkTaskTag(comment, commentOffset, commentStartLine);
+ }
protected boolean skipOverMultilineComment() throws ScannerException {
int state = 0;
boolean encounteredNewline = false;
+ StringBuffer comment = new StringBuffer("/*");
+ int commentOffset = lastContext.getOffset() - lastContext.undoStackSize() - 2;
+ int commentStartLine = lastContext.getLine();
// simple state machine to handle multi-line comments
// state 0 == no end of comment in site
// state 1 == encountered *, expecting /
// state 2 == we are no longer in a comment
int c = getChar();
+ comment.append((char)c);
while (state != 2 && c != NOCHAR) {
if (c == '\n')
encounteredNewline = true;
@@ -1715,6 +1752,7 @@ public class Scanner implements IScanner {
break;
}
c = getChar();
+ comment.append((char)c);
}
if (c == NOCHAR) {
@@ -1723,6 +1761,8 @@ public class Scanner implements IScanner {
}
ungetChar(c);
+
+ checkTaskTag(comment, commentOffset, commentStartLine);
return encounteredNewline;
}
@@ -1871,7 +1911,7 @@ public class Scanner implements IScanner {
if( ! replacementString.equals( "" ) )
{
- IScanner helperScanner = ParserFactory.createScanner( new StringReader(replacementString), null, null, null, mode );
+ IScanner helperScanner = ParserFactory.createScanner( new StringReader(replacementString), null, null, null, mode, problemReporter, translationResult );
helperScanner.setTokenizingMacroReplacementList( true );
IToken t = helperScanner.nextToken(false);
@@ -1928,7 +1968,7 @@ public class Scanner implements IScanner {
c = getChar();
if (c == '/') // one line comment
{
- skipOverTextUntilNewline();
+ skipOverSinglelineComment();
addDefinition(key, "");
} else if (c == '*') // multi-line comment
{
@@ -1969,7 +2009,7 @@ public class Scanner implements IScanner {
protected Vector getMacroParameters (String params, boolean forStringizing) throws ScannerException {
- IScanner tokenizer = ParserFactory.createScanner(new StringReader(params), TEXT, definitions, null, mode );
+ IScanner tokenizer = ParserFactory.createScanner(new StringReader(params), TEXT, definitions, null, mode, problemReporter, translationResult );
Vector parameterValues = new Vector();
Token t = null;
String str = new String();
@@ -2205,5 +2245,171 @@ public class Scanner implements IScanner {
*/
public void setASTFactory(IASTFactory f) {
astFactory = f;
- }
+ }
+
+ // task tag support
+ private class TaskTagsInfo {
+ char[][] taskTags = null;
+ char[][] taskPriorities = null;
+
+ class FoundTaskInfo {
+ char[] foundTaskTags = null;
+ char[] foundTaskMessages = null;
+ char[] foundTaskPriorities = null;
+ int foundTaskStartOffset = -1;
+ int foundTaskEndOffset = -1;
+ int foundTaskLine = -1;
+ };
+
+ FoundTaskInfo[] foundTaskInfo = null;
+ int foundTaskCount = 0;
+
+ TaskTagsInfo(ITranslationOptions options) {
+ this.taskTags = options.getTaskTags();
+ this.taskPriorities = options.getTaskPriorities();
+ }
+ }
+
+ IProblemReporter problemReporter = null;
+ ITranslationResult translationResult = null;
+ TaskTagsInfo taskTagsInfo = null;
+
+
+ // check presence of task tags
+ public void checkTaskTag(StringBuffer comment, int commentStart, int commentStartLine) {
+
+ if (this.taskTagsInfo == null) return;
+
+ int commentLength = comment.length();
+ int tagStartLine = commentStartLine;
+ int foundTaskIndex = taskTagsInfo.foundTaskCount;
+ char[][] taskTags = taskTagsInfo.taskTags;
+ char[][] taskPriorities = taskTagsInfo.taskPriorities;
+
+ // only look for newer task tags
+ if (foundTaskIndex > 0) {
+ TaskTagsInfo.FoundTaskInfo lastInfo = taskTagsInfo.foundTaskInfo[foundTaskIndex-1];
+
+ if (lastInfo.foundTaskStartOffset >= commentStart)
+ return;
+ }
+
+ nextChar:
+ for (int i = 0; i < commentLength; i++) {
+ if (comment.charAt(i) == '\n') tagStartLine++;
+
+ int nextPos = -1;
+ char[] tag = null;
+ char[] priority = null;
+ int tagLength = 0;
+
+ // check for tag occurrence
+ nextTag:
+ for (int itag = 0; itag < taskTags.length; itag++) {
+ tag = taskTags[itag];
+ tagLength = tag.length;
+ priority = (taskPriorities != null && itag < taskPriorities.length)
+ ? taskPriorities[itag]
+ : null;
+
+ for (int t = 0; t < tagLength; t++){
+ if (comment.charAt(i+t) != tag[t]) continue nextTag;
+ }
+ nextPos = i + tagLength;
+
+ int fTC = taskTagsInfo.foundTaskCount;
+
+ if (taskTagsInfo.foundTaskInfo == null) {
+ taskTagsInfo.foundTaskInfo = new TaskTagsInfo.FoundTaskInfo[5];
+ } else if (fTC == taskTagsInfo.foundTaskInfo.length) {
+ TaskTagsInfo.FoundTaskInfo[] resizedFTI = new TaskTagsInfo.FoundTaskInfo[fTC*2];
+ System.arraycopy(taskTagsInfo.foundTaskInfo, 0, resizedFTI, 0, fTC);
+ }
+
+ TaskTagsInfo.FoundTaskInfo lastFTI = taskTagsInfo.new FoundTaskInfo();
+
+ lastFTI.foundTaskTags = tag;
+ lastFTI.foundTaskPriorities = priority;
+ lastFTI.foundTaskStartOffset = i;
+ lastFTI.foundTaskLine = tagStartLine;
+
+ taskTagsInfo.foundTaskInfo[fTC] = lastFTI;
+ taskTagsInfo.foundTaskCount++;
+
+ for (int jj=i+1; jj
+ *
+ * @param originatingFileName char[]
+ * @param problemId int
+ * @param arguments String[]
+ * @param severity int
+ * @param startPosition int
+ * @param endPosition int
+ * @param lineNumber int
+ * @return org.eclipse.cdt.core.parser.IProblem
+ */
+ public IProblem createProblem(
+ char[] originatingFileName,
+ int problemId,
+ String[] problemArguments,
+ String[] messageArguments,
+ int severity,
+ int startPosition,
+ int endPosition,
+ int lineNumber) {
+
+ return new DefaultProblem(
+ originatingFileName,
+ this.getLocalizedMessage(problemId, messageArguments),
+ problemId,
+ problemArguments,
+ severity,
+ startPosition,
+ endPosition,
+ lineNumber);
+ }
+
+ /**
+ * Answer the locale used to retrieve the error messages
+ * @return java.util.Locale
+ */
+ public Locale getLocale() {
+ return locale;
+ }
+ public final String getLocalizedMessage(int id, String[] problemArguments) {
+ StringBuffer output = new StringBuffer(80);
+ String message =
+ messageTemplates[(id & IProblem.IgnoreCategoriesMask)];
+ if (message == null) {
+ return "Unable to retrieve the error message for problem id: " //$NON-NLS-1$
+ + (id & IProblem.IgnoreCategoriesMask)
+ + ". Check translation resources."; //$NON-NLS-1$
+ }
+
+ // for compatibility with MessageFormat which eliminates double quotes in original message
+ message = message.replace('\"', '\'');
+
+ int length = message.length();
+ int start = -1, end = length;
+ while (true) {
+ if ((end = message.indexOf('{', start)) > -1) {
+ output.append(message.substring(start + 1, end));
+ if ((start = message.indexOf('}', end)) > -1) {
+ try {
+ output.append(
+ problemArguments[Integer.parseInt(message.substring(end + 1, start))]);
+ } catch (NumberFormatException nfe) {
+ output.append(message.substring(end + 1, start + 1));
+ } catch (ArrayIndexOutOfBoundsException e) {
+ return "Corrupted translation resources for problem id: " //$NON-NLS-1$
+ + (id & IProblem.IgnoreCategoriesMask)
+ + ". Check translation resources."; //$NON-NLS-1$
+ }
+ } else {
+ output.append(message.substring(end, length));
+ break;
+ }
+ } else {
+ output.append(message.substring(start + 1, length));
+ break;
+ }
+ }
+ return output.toString();
+ }
+
+ /**
+ * @param problem org.eclipse.cdt.core.parser.IProblem
+ * @return String
+ */
+ public final String localizedMessage(IProblem problem) {
+ return getLocalizedMessage(problem.getID(), problem.getArguments());
+ }
+
+ /**
+ * This method initializes the MessageTemplates class variable according
+ * to the current Locale.
+ */
+ public static String[] loadMessageTemplates(Locale loc) {
+ ResourceBundle bundle = null;
+ String bundleName = "org.eclipse.cdt.internal.core.parser.problem.messages"; //$NON-NLS-1$
+ try {
+ bundle = ResourceBundle.getBundle(bundleName, loc);
+ } catch(MissingResourceException e) {
+ System.out.println("Missing resource : " + bundleName.replace('.', '/') + ".properties for locale " + loc); //$NON-NLS-1$//$NON-NLS-2$
+ throw e;
+ }
+ String[] templates = new String[500];
+ for (int i = 0, max = templates.length; i < max; i++) {
+ try {
+ templates[i] = bundle.getString(String.valueOf(i));
+ } catch (MissingResourceException e) {
+ // available ID
+ }
+ }
+ return templates;
+ }
+
+ public DefaultProblemFactory() {
+ this(Locale.getDefault());
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/IProblemSeverities.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/IProblemSeverities.java
new file mode 100644
index 00000000000..1bff044b2ea
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/IProblemSeverities.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.parser.problem;
+
+public interface IProblemSeverities {
+
+ final int Ignore = -1;
+
+ final int Error = 0x00001;
+ final int Warning = 0x00002;
+
+ final int Task = 0x10000; // when bit is set: the problem is a task
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/ProblemHandler.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/ProblemHandler.java
new file mode 100644
index 00000000000..5fe4d1f52f6
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/ProblemHandler.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.parser.problem;
+
+import org.eclipse.cdt.core.parser.IProblem;
+import org.eclipse.cdt.core.parser.IReferenceContext;
+import org.eclipse.cdt.core.parser.ITranslationOptions;
+import org.eclipse.cdt.core.parser.ITranslationResult;
+import org.eclipse.cdt.internal.core.parser.IErrorHandlingPolicy;
+import org.eclipse.cdt.internal.core.parser.IProblemFactory;
+
+
+/*
+ * Translation problem handler, responsible to determine whether
+ * a problem is actually a warning or an error (or a task); also will
+ * decide whether the translation task can be processed further or not.
+ *
+ * Behavior : will request its current policy if need to stop on
+ * first error, and if should proceed (persist) with problems.
+ */
+
+public class ProblemHandler {
+
+ public final static String[] NoArgument = new String[0];
+
+ final public IErrorHandlingPolicy policy;
+ public final IProblemFactory problemFactory;
+ private final ITranslationOptions options;
+
+
+ /**
+ * Problem handler can be supplied with a policy to specify
+ * its behavior in error handling. Also see static methods for
+ * built-in policies.
+ *
+ */
+ public ProblemHandler(IErrorHandlingPolicy policy, ITranslationOptions options, IProblemFactory problemFactory) {
+ this.policy = policy;
+ this.problemFactory = problemFactory;
+ this.options = options;
+ }
+
+
+ /**
+ * Given the current configuration, answers which category the problem
+ * falls into:
+ * Error | Warning | Ignore | Task
+ */
+ public int computeSeverity(int problemId) {
+ if (problemId == IProblem.Task) return IProblemSeverities.Task;
+
+ // by default all problems are errors
+ return IProblemSeverities.Error;
+ }
+
+
+ public IProblem createProblem(
+ char[] fileName,
+ int problemId,
+ String[] problemArguments,
+ String[] messageArguments,
+ int severity,
+ int problemStartPosition,
+ int problemEndPosition,
+ int lineNumber,
+ IReferenceContext referenceContext,
+ ITranslationResult unitResult) {
+
+ return problemFactory.createProblem(
+ fileName,
+ problemId,
+ problemArguments,
+ messageArguments,
+ severity,
+ problemStartPosition,
+ problemEndPosition,
+ lineNumber);
+ }
+
+
+ public void handle(
+ int problemId,
+ String[] problemArguments,
+ String[] messageArguments,
+ int severity,
+ int problemStartPosition,
+ int problemEndPosition,
+ int line,
+ IReferenceContext referenceContext,
+ ITranslationResult unitResult) {
+
+ if (severity == IProblemSeverities.Ignore)
+ return;
+
+ IProblem problem =
+ this.createProblem(
+ unitResult.getFileName(),
+ problemId,
+ problemArguments,
+ messageArguments,
+ severity,
+ problemStartPosition,
+ problemEndPosition,
+ line >= 0
+ ? line
+ : 1,
+ referenceContext,
+ unitResult);
+ if (problem == null) return; // problem couldn't be created, ignore
+
+ this.record(problem, unitResult, referenceContext);
+ }
+
+
+ /**
+ * Standard problem handling API, the actual severity (warning/error/ignore) is deducted
+ * from the problem ID and the current translation options.
+ */
+ public void handle(
+ int problemId,
+ String[] problemArguments,
+ String[] messageArguments,
+ int problemStartPosition,
+ int problemEndPosition,
+ int line,
+ IReferenceContext referenceContext,
+ ITranslationResult unitResult) {
+
+ this.handle(
+ problemId,
+ problemArguments,
+ messageArguments,
+ this.computeSeverity(problemId), // severity inferred using the ID
+ problemStartPosition,
+ problemEndPosition,
+ line,
+ referenceContext,
+ unitResult);
+ }
+
+
+ public void record(IProblem problem, ITranslationResult unitResult, IReferenceContext referenceContext) {
+ unitResult.record(problem, referenceContext);
+ }
+
+ public ITranslationOptions getOptions() {
+ return options;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/ProblemReporter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/ProblemReporter.java
new file mode 100644
index 00000000000..e65ba665d9f
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/ProblemReporter.java
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.parser.problem;
+
+import org.eclipse.cdt.core.parser.IProblem;
+import org.eclipse.cdt.core.parser.IProblemReporter;
+import org.eclipse.cdt.core.parser.IReferenceContext;
+import org.eclipse.cdt.core.parser.ITranslationOptions;
+import org.eclipse.cdt.core.parser.ITranslationResult;
+import org.eclipse.cdt.internal.core.parser.IErrorHandlingPolicy;
+import org.eclipse.cdt.internal.core.parser.IProblemFactory;
+
+
+public class ProblemReporter extends ProblemHandler implements IProblemReporter {
+
+ public IReferenceContext referenceContext = null;
+
+ public ProblemReporter(IErrorHandlingPolicy policy, ITranslationOptions options, IProblemFactory problemFactory) {
+ super(policy, options, problemFactory);
+ }
+
+ public void task(String tag, String message, String priority, int start, int end, int line, ITranslationResult result){
+ this.handle(
+ IProblem.Task,
+ new String[] { tag, message, priority/*secret argument that is not surfaced in getMessage()*/},
+ new String[] { tag, message, priority/*secret argument that is not surfaced in getMessage()*/},
+ start,
+ end,
+ line,
+ result);
+ }
+
+ // use this private API when the translation unit result can be found through the
+ // reference context. Otherwise, use the other API taking a problem and a translation result
+ // as arguments
+ private void handle(
+ int problemId,
+ String[] problemArguments,
+ String[] messageArguments,
+ int problemStartPosition,
+ int problemEndPosition,
+ int line){
+
+ this.handle(
+ problemId,
+ problemArguments,
+ messageArguments,
+ problemStartPosition,
+ problemEndPosition,
+ line,
+ referenceContext,
+ referenceContext == null ? null : referenceContext.translationResult());
+ referenceContext = null;
+ }
+
+ // use this private API when the translation unit result can be found through the
+ // reference context. Otherwise, use the other API taking a problem and a translation result
+ // as arguments
+ private void handle(
+ int problemId,
+ String[] problemArguments,
+ String[] messageArguments,
+ int severity,
+ int problemStartPosition,
+ int problemEndPosition,
+ int line){
+
+ this.handle(
+ problemId,
+ problemArguments,
+ messageArguments,
+ severity,
+ problemStartPosition,
+ problemEndPosition,
+ referenceContext,
+ referenceContext == null ? null : referenceContext.translationResult());
+ referenceContext = null;
+ }
+
+ // use this private API when the translation unit result cannot be found through the
+ // reference context.
+ private void handle(
+ int problemId,
+ String[] problemArguments,
+ String[] messageArguments,
+ int problemStartPosition,
+ int problemEndPosition,
+ int line,
+ ITranslationResult unitResult){
+
+ this.handle(
+ problemId,
+ problemArguments,
+ messageArguments,
+ problemStartPosition,
+ problemEndPosition,
+ line,
+ referenceContext,
+ unitResult);
+ referenceContext = null;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/messages.properties b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/messages.properties
new file mode 100644
index 00000000000..89158b26e84
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/messages.properties
@@ -0,0 +1,14 @@
+###############################################################################
+# Copyright (c) 2000, 2003 IBM Corporation 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:
+# IBM Corporation - initial API and implementation
+###############################################################################
+0 = {0}
+
+# Task message: {taskTag} {taskMessage}
+450 = {0} {1}
diff --git a/core/org.eclipse.cdt.core/plugin.properties b/core/org.eclipse.cdt.core/plugin.properties
index 53b857f2830..40e3064f0cf 100644
--- a/core/org.eclipse.cdt.core/plugin.properties
+++ b/core/org.eclipse.cdt.core/plugin.properties
@@ -18,3 +18,5 @@ makebuildmodel.name=Make Builder
ManagedBuildNature.name=Managed C/C++ Build Nature
GeneratedMakefileCBuilder.name=Generated Makefile C/C++ Builder
+
+CTaskName=C/C++ Task
diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml
index 8556b54f880..7fcd93752b1 100644
--- a/core/org.eclipse.cdt.core/plugin.xml
+++ b/core/org.eclipse.cdt.core/plugin.xml
@@ -280,4 +280,9 @@
+ setOptions
.
+ *
+ * Helper constants have been defined on CCorePlugin for each of the option ID and
+ * their possible constant values.
+ *
+ * Note: more options might be added in further releases.
+ *
+ * RECOGNIZED OPTIONS:
+ * TRANSLATION / Define the Automatic Task Tags
+ * When the tag list is not empty, translation will issue a task marker whenever it encounters
+ * one of the corresponding tags inside any comment in C/C++ source code.
+ * Generated task messages will include the tag, and range until the next line separator or comment ending.
+ * Note that tasks messages are trimmed. If a tag is starting with a letter or digit, then it cannot be leaded by
+ * another letter or digit to be recognized ("fooToDo" will not be recognized as a task for tag "ToDo", but "foo#ToDo"
+ * will be detected for either tag "ToDo" or "#ToDo"). Respectively, a tag ending with a letter or digit cannot be followed
+ * by a letter or digit to be recognized ("ToDofoo" will not be recognized as a task for tag "ToDo", but "ToDo:foo" will
+ * be detected either for tag "ToDo" or "ToDo:").
+ * - option id: "org.eclipse.cdt.core.translation.taskTags"
+ * - possible values: { "
+ *
+ * @return a mutable map containing the default settings of all known options
+ * (key type: String
; value type: String
)
+ * @see #setOptions
+ */
+
+ public static HashMap getDefaultOptions()
+ {
+ HashMap defaultOptions = new HashMap(10);
+
+ // see #initializeDefaultPluginPreferences() for changing default settings
+ Preferences preferences = getDefault().getPluginPreferences();
+ HashSet optionNames = CModelManager.OptionNames;
+
+ // get preferences set to their default
+ String[] defaultPropertyNames = preferences.defaultPropertyNames();
+ for (int i = 0; i < defaultPropertyNames.length; i++){
+ String propertyName = defaultPropertyNames[i];
+ if (optionNames.contains(propertyName)) {
+ defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
+ }
+ }
+ // get preferences not set to their default
+ String[] propertyNames = preferences.propertyNames();
+ for (int i = 0; i < propertyNames.length; i++){
+ String propertyName = propertyNames[i];
+ if (optionNames.contains(propertyName)) {
+ defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
+ }
+ }
+ // get encoding through resource plugin
+ defaultOptions.put(CORE_ENCODING, ResourcesPlugin.getEncoding());
+
+ return defaultOptions;
+ }
+
+
+ /**
+ * Initializes the default preferences settings for this plug-in.
+ * TODO: Add all options here
+ */
+ protected void initializeDefaultPluginPreferences()
+ {
+ Preferences preferences = getPluginPreferences();
+ HashSet optionNames = CModelManager.OptionNames;
+
+ // Compiler settings
+ preferences.setDefault(TRANSLATION_TASK_TAGS, DEFAULT_TASK_TAG);
+ optionNames.add(TRANSLATION_TASK_TAGS);
+
+ preferences.setDefault(TRANSLATION_TASK_PRIORITIES, DEFAULT_TASK_PRIORITY);
+ optionNames.add(TRANSLATION_TASK_PRIORITIES);
+ }
+
+ /**
+ * Helper method for returning one option value only. Equivalent to (String)CCorePlugin.getOptions().get(optionName)
+ * Note that it may answer null
if this option does not exist.
+ * getDefaultOptions
.
+ * getDefaultOptions
.
+ * String
; value type: String
)
+ * @see CCorePlugin#getDefaultOptions
+ */
+ public static HashMap getOptions() {
+
+ HashMap options = new HashMap(10);
+
+ // see #initializeDefaultPluginPreferences() for changing default settings
+ Plugin plugin = getDefault();
+ if (plugin != null) {
+ Preferences preferences = plugin.getPluginPreferences();
+ HashSet optionNames = CModelManager.OptionNames;
+
+ // get preferences set to their default
+ String[] defaultPropertyNames = preferences.defaultPropertyNames();
+ for (int i = 0; i < defaultPropertyNames.length; i++){
+ String propertyName = defaultPropertyNames[i];
+ if (optionNames.contains(propertyName)){
+ options.put(propertyName, preferences.getDefaultString(propertyName));
+ }
+ }
+ // get preferences not set to their default
+ String[] propertyNames = preferences.propertyNames();
+ for (int i = 0; i < propertyNames.length; i++){
+ String propertyName = propertyNames[i];
+ if (optionNames.contains(propertyName)){
+ options.put(propertyName, preferences.getString(propertyName).trim());
+ }
+ }
+ // get encoding through resource plugin
+ options.put(CORE_ENCODING, ResourcesPlugin.getEncoding());
+ }
+ return options;
+ }
+
+ /**
+ * Sets the current table of options. All and only the options explicitly included in the given table
+ * are remembered; all previous option settings are forgotten, including ones not explicitly
+ * mentioned.
+ * getDefaultOptions
.
+ * String
; value type: String
),
+ * or null
to reset all options to their default values
+ * @see CCorePlugin#getDefaultOptions
+ */
+ public static void setOptions(HashMap newOptions) {
+
+ // see #initializeDefaultPluginPreferences() for changing default settings
+ Preferences preferences = getDefault().getPluginPreferences();
+
+ if (newOptions == null){
+ newOptions = getDefaultOptions();
+ }
+ Iterator keys = newOptions.keySet().iterator();
+ while (keys.hasNext()){
+ String key = (String)keys.next();
+ if (!CModelManager.OptionNames.contains(key)) continue; // unrecognized option
+ if (key.equals(CORE_ENCODING)) continue; // skipped, contributed by resource prefs
+ String value = (String)newOptions.get(key);
+ preferences.setValue(key, value);
+ }
+
+ // persist options
+ getDefault().savePluginPreferences();
+ }
+
public IConsole getConsole(String id) {
try {
diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog
index 2a2ac8dfaed..26f0a650eaf 100644
--- a/core/org.eclipse.cdt.ui/ChangeLog
+++ b/core/org.eclipse.cdt.ui/ChangeLog
@@ -7,6 +7,9 @@
* src/org/eclipse/cdt/internal/ui/preferences/CProjectPropertyPage.java
* src/org/eclipse/cdt/internal/ui/CPluginResources.properties
+2003-06-26 Victor Mozgin
+ Task tags support in C/C++ comments (initial revision).
+
2003-06-25 John Camelon
Create new interface and support for calculating lineNumber/offset mapping.
Updated IASTClassSpecifier for qualified name query.
diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties
index 3ebf6f408fb..d863eaaca54 100644
--- a/core/org.eclipse.cdt.ui/plugin.properties
+++ b/core/org.eclipse.cdt.ui/plugin.properties
@@ -75,6 +75,9 @@ CApplicationLauncher.label=Executable
CApplicationLauncher.description=Launch a local command
CProblemMarker.name=C Problem
+todoPageName=C/C++ Task Tags
+todoTaskPrefName=Task Tags
+
Editors.DefaultTextEditor = Default Text Editor
AsmEditor.name = Assembly Editor
diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index f9055aa7a2d..600d322a47b 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -316,6 +316,12 @@
class="org.eclipse.cdt.internal.ui.preferences.BuildConsolePreferencePage"
id="org.eclipse.cdt.ui.preferneces.CBuildConsolePreferernces">
+ IRule
for C code scanning.
- * Optimized to partition C documents
- * Is is capable of detecting a pattern which begins with a given starting
- * sequence and ends with a given ending sequence. If the ending sequence is
- * not specified, it can be either end of line, end or file, or both. Additionally,
- * the pattern can be constrained to begin in a certain column.
- */
-public class CMultilineCommentScanner implements IRule {
-
- protected static final int UNDEFINED= -1;
-
- /** The token to be returned on success */
- protected IToken fToken;
-
- /** The pattern's escape character */
- protected char fEscapeCharacter;
- /** Indicates whether end of line termines the pattern */
- protected boolean fBreaksOnEOL;
-
- /**
- * Creates a rule for the given starting and ending sequence.
- * When these sequences are detected the rule will return the specified token.
- * Alternatively, the sequence can also be ended by the end of the line.
- * Any character which follows the given escapeCharacter will be ignored.
- *
- * @param startSequence the pattern's start sequence
- * @param endSequence the pattern's end sequence, null
is a legal value
- * @param token the token which will be returned on success
- * @param escapeCharacter any character following this one will be ignored
- * @param indicates whether the end of the line also termines the pattern
- */
- public CMultilineCommentScanner(IToken token, char escapeCharacter, boolean breaksOnEOL) {
- Assert.isNotNull(token);
-
- fToken= token;
- fEscapeCharacter= escapeCharacter;
- fBreaksOnEOL= breaksOnEOL;
- }
-
- /**
- * Returns whether the end sequence was detected. As the pattern can be considered
- * ended by a line delimiter, the result of this method is true
if the
- * rule breaks on the end of the line, or if the EOF character is read.
- *
- * @param scanner the character scanner to be used
- * @return true
if the end sequence has been detected
- */
- protected boolean endSequenceDetected(ICharacterScanner scanner) {
- int c;
- //char[][] delimiters= scanner.getLegalLineDelimiters();
- while ((c= scanner.read()) != ICharacterScanner.EOF) {
- if (c == fEscapeCharacter) {
- // Skip the escaped character.
- scanner.read();
- } else if (c == '*') {
- c = scanner.read();
- if(c == '/') {
- return true;
- }
- scanner.unread();
- // Check if the specified end sequence has been found.
- //} else if (fBreaksOnEOL) {
- // Check for end of line since it can be used to terminate the pattern.
- //for (int i= 0; i < delimiters.length; i++) {
- // if (c == delimiters[i][0] && sequenceDetected(scanner, delimiters[i], false))
- // return true;
- //}
- }
- }
- scanner.unread();
- return true;
- }
- /*
- * @see IRule#evaluate
- */
- public IToken evaluate(ICharacterScanner scanner) {
-
- int c= scanner.read();
-
- if (c == '/') {
- if((c= scanner.read()) == '*') {
- endSequenceDetected(scanner);
- return fToken;
- }
- scanner.unread();
- }
-
- scanner.unread();
- return Token.UNDEFINED;
- }
- /**
- * Returns whether the next characters to be read by the character scanner
- * are an exact match with the given sequence. No escape characters are allowed
- * within the sequence. If specified the sequence is considered to be found
- * when reading the EOF character.
- *
- * @param scanner the character scanner to be used
- * @param sequence the sequence to be detected
- * @param eofAllowed indicated whether EOF terminates the pattern
- * @return true
if the given sequence has been detected
- */
- protected boolean sequenceDetected(ICharacterScanner scanner, char[] sequence, boolean eofAllowed) {
- for (int i= 1; i < sequence.length; i++) {
- int c= scanner.read();
- if (c == ICharacterScanner.EOF && eofAllowed) {
- return true;
- } else if (c != sequence[i]) {
- // Non-matching character detected, rewind the scanner back to the start.
- scanner.unread();
- for (int j= i-1; j > 0; j--)
- scanner.unread();
- return false;
- }
- }
-
- return true;
- }
- /**
- * Sets a column constraint for this rule. If set, the rule's token
- * will only be returned if the pattern is detected starting at the
- * specified column. If the column is smaller then 0, the column
- * constraint is considered removed.
- *
- * @param column the column in which the pattern starts
- */
- public void setColumnConstraint(int column) {
- if (column < 0)
- column= UNDEFINED;
- //fColumn= column;
- }
-}
-
-
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CPartitionScanner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CPartitionScanner.java
index dc566f237bd..2dc995fe0b5 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CPartitionScanner.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CPartitionScanner.java
@@ -120,7 +120,6 @@ public class CPartitionScanner extends RuleBasedPartitionScanner {
// Add rules for multi-line comments.
rules.add(new MultiLineRule("/*", "*/", comment));
- //rules.add(new CMultilineCommentScanner(comment, (char)0, false));
IPredicateRule[] result= new IPredicateRule[rules.size()];
rules.toArray(result);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CTextTools.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CTextTools.java
index a4509c72122..e6fe8426818 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CTextTools.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CTextTools.java
@@ -8,6 +8,8 @@ package org.eclipse.cdt.internal.ui.text;
import org.eclipse.cdt.internal.ui.text.util.CColorManager;
import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.core.runtime.Preferences;
+
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.rules.DefaultPartitioner;
@@ -23,10 +25,13 @@ import org.eclipse.jface.util.PropertyChangeEvent;
*/
public class CTextTools {
- private class PreferenceListener implements IPropertyChangeListener {
+ private class PreferenceListener implements IPropertyChangeListener, Preferences.IPropertyChangeListener {
public void propertyChange(PropertyChangeEvent event) {
adaptToPreferenceChange(event);
}
+ public void propertyChange(Preferences.PropertyChangeEvent event) {
+ adaptToPreferenceChange(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event.getNewValue()));
+ }
};
/** The color manager */
@@ -38,14 +43,16 @@ public class CTextTools {
/** The C partitions scanner */
private FastCPartitionScanner fPartitionScanner;
/** The Java multiline comment scanner */
- private SingleTokenCScanner fMultilineCommentScanner;
+ private CCommentScanner fMultilineCommentScanner;
/** The Java singleline comment scanner */
- private SingleTokenCScanner fSinglelineCommentScanner;
+ private CCommentScanner fSinglelineCommentScanner;
/** The Java string scanner */
private SingleTokenCScanner fStringScanner;
/** The preference store */
- private IPreferenceStore fPreferenceStore;
+ private IPreferenceStore fPreferenceStore;
+ /** The core preference store */
+ private Preferences fCorePreferenceStore;
/** The preference change listener */
private PreferenceListener fPreferenceListener= new PreferenceListener();
@@ -54,20 +61,33 @@ public class CTextTools {
* Creates a new C text tools collection and eagerly creates
* and initializes all members of this collection.
*/
- public CTextTools(IPreferenceStore store) {
+ public CTextTools(IPreferenceStore store) {
+ this(store, null);
+ }
+
+ /**
+ * Creates a new C text tools collection and eagerly creates
+ * and initializes all members of this collection.
+ */
+ public CTextTools(IPreferenceStore store, Preferences coreStore) {
if(store == null) {
store = CUIPlugin.getDefault().getPreferenceStore();
}
fPreferenceStore = store;
fPreferenceStore.addPropertyChangeListener(fPreferenceListener);
+
+ fCorePreferenceStore= coreStore;
+ if (fCorePreferenceStore != null) {
+ fCorePreferenceStore.addPropertyChangeListener(fPreferenceListener);
+ }
fColorManager= new CColorManager();
fCodeScanner= new CCodeScanner(fColorManager, store);
fCppCodeScanner= new CppCodeScanner(fColorManager, store);
fPartitionScanner= new FastCPartitionScanner();
- fMultilineCommentScanner= new SingleTokenCScanner(fColorManager, store, ICColorConstants.C_MULTI_LINE_COMMENT);
- fSinglelineCommentScanner= new SingleTokenCScanner(fColorManager, store, ICColorConstants.C_SINGLE_LINE_COMMENT);
+ fMultilineCommentScanner= new CCommentScanner(fColorManager, store, coreStore, ICColorConstants.C_MULTI_LINE_COMMENT);
+ fSinglelineCommentScanner= new CCommentScanner(fColorManager, store, coreStore, ICColorConstants.C_SINGLE_LINE_COMMENT);
fStringScanner= new SingleTokenCScanner(fColorManager, store, ICColorConstants.C_STRING);
}
@@ -100,6 +120,12 @@ public class CTextTools {
if (fPreferenceStore != null) {
fPreferenceStore.removePropertyChangeListener(fPreferenceListener);
fPreferenceStore= null;
+
+ if (fCorePreferenceStore != null) {
+ fCorePreferenceStore.removePropertyChangeListener(fPreferenceListener);
+ fCorePreferenceStore= null;
+ }
+
fPreferenceListener= null;
}
}
@@ -151,18 +177,18 @@ public class CTextTools {
}
/**
- * Returns a scanner which is configured to scan Java multiline comments.
+ * Returns a scanner which is configured to scan C multiline comments.
*
- * @return a Java multiline comment scanner
+ * @return a C multiline comment scanner
*/
public RuleBasedScanner getMultilineCommentScanner() {
return fMultilineCommentScanner;
}
/**
- * Returns a scanner which is configured to scan Java singleline comments.
+ * Returns a scanner which is configured to scan C singleline comments.
*
- * @return a Java singleline comment scanner
+ * @return a C singleline comment scanner
*/
public RuleBasedScanner getSinglelineCommentScanner() {
return fSinglelineCommentScanner;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ICColorConstants.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ICColorConstants.java
index 2c324b68f7c..729c1f33b3b 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ICColorConstants.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ICColorConstants.java
@@ -26,8 +26,12 @@ public interface ICColorConstants {
String C_STRING= "c_string"; //$NON-NLS-1$
/* The color key for everthing in C code for which no other color is specified. */
String C_DEFAULT= "c_default"; //$NON-NLS-1$
-
-
+
+ /**
+ * The color key for task tags in C comments
+ * (value "c_comment_task_tag"
).
+ */
+ String TASK_TAG= "c_comment_task_tag"; //$NON-NLS-1$
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java
index e9a25cbaa60..70fe9d0ccf8 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java
@@ -13,7 +13,6 @@ import java.io.InputStreamReader;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICElement;
-import org.eclipse.cdt.core.model.ISourceRange;
import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.resources.FileStorage;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/SWTUtil.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/SWTUtil.java
index 9e0b77b1031..7de94146a04 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/SWTUtil.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/SWTUtil.java
@@ -1,9 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
package org.eclipse.cdt.internal.ui.util;
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DragSource;
@@ -16,7 +22,9 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Widget;
+
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.util.Assert;
@@ -99,8 +107,16 @@ public class SWTUtil {
((GridData)gd).heightHint= getButtonHeigthHint(button);
((GridData)gd).widthHint= getButtonWidthHint(button);
}
- }
+ }
+
+ public static int getTableHeightHint(Table table, int rows) {
+ if (table.getFont().equals(JFaceResources.getDefaultFont()))
+ table.setFont(JFaceResources.getDialogFont());
+ int result= table.getItemHeight() * rows + table.getHeaderHeight();
+ if (table.getLinesVisible())
+ result+= table.getGridLineWidth() * (rows - 1);
+ return result;
+ }
}
-
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/IStatusChangeListener.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/IStatusChangeListener.java
new file mode 100644
index 00000000000..8f0f417e5e8
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/IStatusChangeListener.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.wizards;
+
+import org.eclipse.core.runtime.IStatus;
+
+public interface IStatusChangeListener {
+
+ /**
+ * Notifies this listener that the given status has changed.
+ *
+ * @param status the new status
+ */
+ void statusChanged(IStatus status);
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/dialogfields/ComboDialogField.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/dialogfields/ComboDialogField.java
new file mode 100644
index 00000000000..35d9854dff3
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/dialogfields/ComboDialogField.java
@@ -0,0 +1,225 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.wizards.dialogfields;
+
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+
+/**
+ * Dialog field containing a label and a combo control.
+ */
+public class ComboDialogField extends DialogField {
+
+ private String fText;
+ private int fSelectionIndex;
+ private String[] fItems;
+ private Combo fComboControl;
+ private ModifyListener fModifyListener;
+ private int fFlags;
+
+ public ComboDialogField(int flags) {
+ super();
+ fText= ""; //$NON-NLS-1$
+ fItems= new String[0];
+ fFlags= flags;
+ fSelectionIndex= -1;
+ }
+
+ // ------- layout helpers
+
+ /*
+ * @see DialogField#doFillIntoGrid
+ */
+ public Control[] doFillIntoGrid(Composite parent, int nColumns) {
+ assertEnoughColumns(nColumns);
+
+ Label label= getLabelControl(parent);
+ label.setLayoutData(gridDataForLabel(1));
+ Combo combo= getComboControl(parent);
+ combo.setLayoutData(gridDataForCombo(nColumns - 1));
+
+ return new Control[] { label, combo };
+ }
+
+ /*
+ * @see DialogField#getNumberOfControls
+ */
+ public int getNumberOfControls() {
+ return 2;
+ }
+
+ protected static GridData gridDataForCombo(int span) {
+ GridData gd= new GridData();
+ gd.horizontalAlignment= GridData.FILL;
+ gd.grabExcessHorizontalSpace= false;
+ gd.horizontalSpan= span;
+ return gd;
+ }
+
+ // ------- focus methods
+
+ /*
+ * @see DialogField#setFocus
+ */
+ public boolean setFocus() {
+ if (isOkToUse(fComboControl)) {
+ fComboControl.setFocus();
+ }
+ return true;
+ }
+
+ // ------- ui creation
+
+ /**
+ * Creates or returns the created combo control.
+ * @param parent The parent composite or null
when the widget has
+ * already been created.
+ */
+ public Combo getComboControl(Composite parent) {
+ if (fComboControl == null) {
+ assertCompositeNotNull(parent);
+ fModifyListener= new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ doModifyText(e);
+ }
+ };
+ SelectionListener selectionListener= new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ doSelectionChanged(e);
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) { };
+ };
+
+ fComboControl= new Combo(parent, fFlags);
+ // moved up due to 1GEUNW2
+ fComboControl.setItems(fItems);
+ if (fSelectionIndex != -1) {
+ fComboControl.select(fSelectionIndex);
+ } else {
+ fComboControl.setText(fText);
+ }
+ fComboControl.setFont(parent.getFont());
+ fComboControl.addModifyListener(fModifyListener);
+ fComboControl.addSelectionListener(selectionListener);
+ fComboControl.setEnabled(isEnabled());
+ }
+ return fComboControl;
+ }
+
+ private void doModifyText(ModifyEvent e) {
+ if (isOkToUse(fComboControl)) {
+ fText= fComboControl.getText();
+ fSelectionIndex= fComboControl.getSelectionIndex();
+ }
+ dialogFieldChanged();
+ }
+
+ private void doSelectionChanged(SelectionEvent e) {
+ if (isOkToUse(fComboControl)) {
+ fItems= fComboControl.getItems();
+ fText= fComboControl.getText();
+ fSelectionIndex= fComboControl.getSelectionIndex();
+ }
+ dialogFieldChanged();
+ }
+
+ // ------ enable / disable management
+
+ /*
+ * @see DialogField#updateEnableState
+ */
+ protected void updateEnableState() {
+ super.updateEnableState();
+ if (isOkToUse(fComboControl)) {
+ fComboControl.setEnabled(isEnabled());
+ }
+ }
+
+ // ------ text access
+
+ /**
+ * Gets the combo items.
+ */
+ public String[] getItems() {
+ return fItems;
+ }
+
+ /**
+ * Sets the combo items. Triggers a dialog-changed event.
+ */
+ public void setItems(String[] items) {
+ fItems= items;
+ if (isOkToUse(fComboControl)) {
+ fComboControl.setItems(items);
+ }
+ dialogFieldChanged();
+ }
+
+ /**
+ * Gets the text.
+ */
+ public String getText() {
+ return fText;
+ }
+
+ /**
+ * Sets the text. Triggers a dialog-changed event.
+ */
+ public void setText(String text) {
+ fText= text;
+ if (isOkToUse(fComboControl)) {
+ fComboControl.setText(text);
+ } else {
+ dialogFieldChanged();
+ }
+ }
+
+ /**
+ * Selects an item.
+ */
+ public void selectItem(int index) {
+ if (isOkToUse(fComboControl)) {
+ fComboControl.select(index);
+ } else {
+ if (index >= 0 && index < fItems.length) {
+ fText= fItems[index];
+ fSelectionIndex= index;
+ }
+ }
+ dialogFieldChanged();
+ }
+
+ public int getSelectionIndex() {
+ return fSelectionIndex;
+ }
+
+
+ /**
+ * Sets the text without triggering a dialog-changed event.
+ */
+ public void setTextWithoutUpdate(String text) {
+ fText= text;
+ if (isOkToUse(fComboControl)) {
+ fComboControl.removeModifyListener(fModifyListener);
+ fComboControl.setText(text);
+ fComboControl.addModifyListener(fModifyListener);
+ }
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/dialogfields/SelectionButtonDialogField.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/dialogfields/SelectionButtonDialogField.java
new file mode 100644
index 00000000000..6484096dc2b
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/dialogfields/SelectionButtonDialogField.java
@@ -0,0 +1,192 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.wizards.dialogfields;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+import org.eclipse.cdt.internal.ui.util.SWTUtil;
+
+/**
+ * Dialog Field containing a single button such as a radio or checkbox button.
+ */
+public class SelectionButtonDialogField extends DialogField {
+
+ private Button fButton;
+ private boolean fIsSelected;
+ private DialogField[] fAttachedDialogFields;
+ private int fButtonStyle;
+
+ /**
+ * Creates a selection button.
+ * Allowed button styles: SWT.RADIO, SWT.CHECK, SWT.TOGGLE, SWT.PUSH
+ */
+ public SelectionButtonDialogField(int buttonStyle) {
+ super();
+ fIsSelected= false;
+ fAttachedDialogFields= null;
+ fButtonStyle= buttonStyle;
+ }
+
+ /**
+ * Attaches a field to the selection state of the selection button.
+ * The attached field will be disabled if the selection button is not selected.
+ */
+ public void attachDialogField(DialogField dialogField) {
+ attachDialogFields(new DialogField[] { dialogField });
+ }
+
+ /**
+ * Attaches fields to the selection state of the selection button.
+ * The attached fields will be disabled if the selection button is not selected.
+ */
+ public void attachDialogFields(DialogField[] dialogFields) {
+ fAttachedDialogFields= dialogFields;
+ for (int i= 0; i < dialogFields.length; i++) {
+ dialogFields[i].setEnabled(fIsSelected);
+ }
+ }
+
+ /**
+ * Returns true
is teh gived field is attached to the selection button.
+ */
+ public boolean isAttached(DialogField editor) {
+ if (fAttachedDialogFields != null) {
+ for (int i=0; i < fAttachedDialogFields.length; i++) {
+ if (fAttachedDialogFields[i] == editor) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ // ------- layout helpers
+
+ /*
+ * @see DialogField#doFillIntoGrid
+ */
+ public Control[] doFillIntoGrid(Composite parent, int nColumns) {
+ assertEnoughColumns(nColumns);
+
+ Button button= getSelectionButton(parent);
+ GridData gd= new GridData();
+ gd.horizontalSpan= nColumns;
+ gd.horizontalAlignment= GridData.FILL;
+ if (fButtonStyle == SWT.PUSH) {
+ gd.heightHint = SWTUtil.getButtonHeigthHint(button);
+ gd.widthHint = SWTUtil.getButtonWidthHint(button);
+ }
+
+ button.setLayoutData(gd);
+
+ return new Control[] { button };
+ }
+
+ /*
+ * @see DialogField#getNumberOfControls
+ */
+ public int getNumberOfControls() {
+ return 1;
+ }
+
+ // ------- ui creation
+
+ /**
+ * Returns the selection button widget. When called the first time, the widget will be created.
+ * @param The parent composite when called the first time, or null
+ * after.
+ */
+ public Button getSelectionButton(Composite group) {
+ if (fButton == null) {
+ assertCompositeNotNull(group);
+
+ fButton= new Button(group, fButtonStyle);
+ fButton.setFont(group.getFont());
+ fButton.setText(fLabelText);
+ fButton.setEnabled(isEnabled());
+ fButton.setSelection(fIsSelected);
+ fButton.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ doWidgetSelected(e);
+ }
+ public void widgetSelected(SelectionEvent e) {
+ doWidgetSelected(e);
+ }
+ });
+ }
+ return fButton;
+ }
+
+ private void doWidgetSelected(SelectionEvent e) {
+ if (isOkToUse(fButton)) {
+ changeValue(fButton.getSelection());
+ }
+ }
+
+ private void changeValue(boolean newState) {
+ if (fIsSelected != newState) {
+ fIsSelected= newState;
+ if (fAttachedDialogFields != null) {
+ boolean focusSet= false;
+ for (int i= 0; i < fAttachedDialogFields.length; i++) {
+ fAttachedDialogFields[i].setEnabled(fIsSelected);
+ if (fIsSelected && !focusSet) {
+ focusSet= fAttachedDialogFields[i].setFocus();
+ }
+ }
+ }
+ dialogFieldChanged();
+ } else if (fButtonStyle == SWT.PUSH) {
+ dialogFieldChanged();
+ }
+ }
+
+ // ------ model access
+
+ /**
+ * Returns the selection state of the button.
+ */
+ public boolean isSelected() {
+ return fIsSelected;
+ }
+
+ /**
+ * Sets the selection state of the button.
+ */
+ public void setSelection(boolean selected) {
+ changeValue(selected);
+ if (isOkToUse(fButton)) {
+ fButton.setSelection(selected);
+ }
+ }
+
+ // ------ enable / disable management
+
+ /*
+ * @see DialogField#updateEnableState
+ */
+ protected void updateEnableState() {
+ super.updateEnableState();
+ if (isOkToUse(fButton)) {
+ fButton.setEnabled(isEnabled());
+ }
+ }
+
+
+
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java
index de071355e4f..5454c5dd54f 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java
@@ -9,6 +9,7 @@ import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
+import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.ui.BuildConsoleManager;
@@ -183,7 +184,7 @@ public class CUIPlugin extends AbstractUIPlugin {
*/
public CTextTools getTextTools() {
if (fTextTools == null)
- fTextTools = new CTextTools();
+ fTextTools = new CTextTools(getPreferenceStore(), CCorePlugin.getDefault().getPluginPreferences());
return fTextTools;
}
@@ -192,7 +193,7 @@ public class CUIPlugin extends AbstractUIPlugin {
*/
public AsmTextTools getAsmTextTools() {
if (fAsmTextTools == null)
- fAsmTextTools = new AsmTextTools();
+ fAsmTextTools = new AsmTextTools(getPreferenceStore(), CCorePlugin.getDefault().getPluginPreferences());
return fAsmTextTools;
}
@@ -263,6 +264,8 @@ public class CUIPlugin extends AbstractUIPlugin {
*/
protected void initializeDefaultPreferences(final IPreferenceStore store) {
super.initializeDefaultPreferences(store);
+ PreferenceConstants.initializeDefaultValues(store);
+
runUI(new Runnable() {
public void run() {
CPluginPreferencePage.initDefaults(store);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java
index bdfcba4c30a..3eb5b87630f 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java
@@ -4,7 +4,12 @@
*/
package org.eclipse.cdt.ui;
+import org.eclipse.swt.graphics.RGB;
+
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+
+import org.eclipse.cdt.internal.ui.text.ICColorConstants;
/**
* Preference constants used in the JDT-UI preference store. Clients should only read the
@@ -18,6 +23,12 @@ public class PreferenceConstants {
private PreferenceConstants() {
}
+
+ /**
+ * Preference key suffix for bold text style preference keys.
+ */
+ public static final String EDITOR_BOLD_SUFFIX= "_bold"; //$NON-NLS-1$
+
/**
* A named preference that controls if comment stubs will be added
* automatically to newly created types and methods.
@@ -51,7 +62,58 @@ public class PreferenceConstants {
*
+ * Value is of type String
. A RGB color value encoded as a string
+ * using class PreferenceConverter
+ *
+ * Value is of type Boolean
.
+ *
+ * Value is of type Boolean
.
+ *
+ * Value is of type String
. A RGB color value encoded as a string
+ * using class PreferenceConverter
+ *
+ * Value is of type Boolean
.
+ *