locationKind
is not available, the
+ * workspace default is returned.
+ */
+ private IDocCommentOwner getDocumentationCommentOwner(IPath location, LocationKind locationKind) {
+ if(location!=null && LocationKind.IFILE.equals(locationKind)) {
+ IFile file= ResourcesPlugin.getWorkspace().getRoot().getFile(location);
+ return DocCommentOwnerManager.getInstance().getCommentOwner(file);
+ }
+ return DocCommentOwnerManager.getInstance().getWorkspaceCommentOwner();
+ }
}
Index: src/org/eclipse/cdt/internal/ui/text/CCommentAutoIndentStrategy.java
===================================================================
RCS file: src/org/eclipse/cdt/internal/ui/text/CCommentAutoIndentStrategy.java
diff -N src/org/eclipse/cdt/internal/ui/text/CCommentAutoIndentStrategy.java
--- src/org/eclipse/cdt/internal/ui/text/CCommentAutoIndentStrategy.java 3 Jul 2006 13:01:44 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,122 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * QNX Software System
- * Anton Leherbauer (Wind River Systems) - Fixed bug 48339
- *******************************************************************************/
-package org.eclipse.cdt.internal.ui.text;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
-import org.eclipse.jface.text.DocumentCommand;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-
-/**
- * Auto indent strategy for C/C++ multiline comments
- */
-public class CCommentAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
-
- public CCommentAutoIndentStrategy() {
- }
-
- /**
- * Returns whether the text ends with one of the given search strings.
- */
- private boolean endsWithDelimiter(IDocument d, String txt) {
- String[] delimiters= d.getLegalLineDelimiters();
-
- for (int i= 0; i < delimiters.length; i++) {
- if (txt.endsWith(delimiters[i]))
- return true;
- }
-
- return false;
- }
-
- /**
- * Copies the indentation of the previous line and adds a star.
- * If the comment just started on this line adds also a blank.
- *
- * @param d the document to work on
- * @param c the command to deal with
- */
- static void commentIndentAfterNewLine(IDocument d, DocumentCommand c) {
-
- if (c.offset == -1 || d.getLength() == 0)
- return;
-
- try {
- // find start of line
- IRegion info= d.getLineInformationOfOffset(c.offset);
- int start= info.getOffset();
-
- // find white spaces
- int end= findEndOfWhiteSpaceAt(d, start, c.offset);
-
- StringBuffer buf= new StringBuffer(c.text);
- if (end >= start) { // 1GEYL1R: ITPJUI:ALL - java doc edit smartness not work for class comments
- // append to input
- buf.append(d.get(start, end - start));
- if (end < c.offset) {
- if (d.getChar(end) == '/') {
- // comment started on this line
- buf.append(" * "); //$NON-NLS-1$
- } else if (d.getChar(end) == '*') {
- buf.append("* "); //$NON-NLS-1$
- }
- }
- }
-
-
- c.text= buf.toString();
-
- } catch (BadLocationException excp) {
- // stop work
- }
- }
-
- static int findEndOfWhiteSpaceAt(IDocument document, int offset, int end) throws BadLocationException {
- while (offset < end) {
- char c= document.getChar(offset);
- if (c != ' ' && c != '\t') {
- return offset;
- }
- offset++;
- }
- return end;
- }
-
- static void commentIndentForCommentEnd(IDocument d, DocumentCommand c) {
- if (c.offset < 2 || d.getLength() == 0) {
- return;
- }
- try {
- if ("* ".equals(d.get(c.offset - 2, 2))) { //$NON-NLS-1$
- // modify document command
- c.length++;
- c.offset--;
- }
- } catch (BadLocationException excp) {
- // stop work
- }
- }
-
- /*
- * @see IAutoIndentStrategy#customizeDocumentCommand
- */
- public void customizeDocumentCommand(IDocument d, DocumentCommand c) {
- if (c.length == 0 && c.text != null && endsWithDelimiter(d, c.text))
- commentIndentAfterNewLine(d, c);
- else if ("/".equals(c.text)) { //$NON-NLS-1$
- commentIndentForCommentEnd(d, c);
- }
- }
-}
-
Index: src/org/eclipse/cdt/internal/ui/text/CCommentScanner.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCommentScanner.java,v
retrieving revision 1.10
diff -u -r1.10 CCommentScanner.java
--- src/org/eclipse/cdt/internal/ui/text/CCommentScanner.java 30 May 2007 11:08:06 -0000 1.10
+++ src/org/eclipse/cdt/internal/ui/text/CCommentScanner.java 23 Jan 2008 15:41:43 -0000
@@ -8,152 +8,49 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Anton Leherbauer (Wind River Systems)
+ * Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text;
-
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
-import java.util.StringTokenizer;
-import org.eclipse.cdt.core.CCorePreferenceConstants;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.text.rules.IToken;
-import org.eclipse.jface.text.rules.IWordDetector;
-import org.eclipse.jface.text.rules.Token;
-import org.eclipse.jface.text.rules.WordRule;
-import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.cdt.ui.PreferenceConstants;
+import org.eclipse.cdt.ui.text.ITokenStoreFactory;
+import org.eclipse.cdt.ui.text.TaskTagRule;
/**
- * CCommentScanner.java
+ * Default token-scanner used for plain (non-documentation-comment) single and multi-line comments, with awareness of
+ * task tags.
*/
-public class CCommentScanner extends AbstractCScanner
-{
- private static class TaskTagDetector implements IWordDetector {
-
- public boolean isWordStart(char c) {
- return Character.isLetter(c);
- }
-
- public boolean isWordPart(char c) {
- return Character.isLetter(c);
- }
- }
-
- private class TaskTagRule extends WordRule {
-
- private IToken fToken;
-
- public TaskTagRule(IToken token) {
- super(new TaskTagDetector(), Token.UNDEFINED);
- fToken= token;
- }
-
- public void clearTaskTags() {
- fWords.clear();
- }
-
- public void addTaskTags(String value) {
- String[] tasks= split(value, ","); //$NON-NLS-1$
- for (int i= 0; i < tasks.length; i++) {
- if (tasks[i].length() > 0) {
- addWord(tasks[i], fToken);
- }
- }
- }
-
- private String[] split(String value, String delimiters) {
- StringTokenizer tokenizer= new StringTokenizer(value, delimiters);
- int size= tokenizer.countTokens();
- String[] tokens= new String[size];
- for (int i = 0; i < size; i++)
- tokens[i] = tokenizer.nextToken();
- return tokens;
- }
- }
-
- private static final String TODO_TASK_TAGS= CCorePreferenceConstants.TODO_TASK_TAGS;
- protected static final String TASK_TAG= ICColorConstants.TASK_TAG;
-
- private TaskTagRule fTaskTagRule;
- private Preferences fCorePreferenceStore;
- private String fDefaultTokenProperty;
- private String[] fTokenProperties;
-
- public CCommentScanner(IColorManager manager, IPreferenceStore store, String defaultTokenProperty) {
- this(manager, store, null, defaultTokenProperty, new String[] { defaultTokenProperty, TASK_TAG });
- }
-
- public CCommentScanner(IColorManager manager, IPreferenceStore store, Preferences coreStore, String defaultTokenProperty) {
- this(manager, store, coreStore, defaultTokenProperty, new String[] { defaultTokenProperty, TASK_TAG });
- }
-
- public CCommentScanner(IColorManager manager, IPreferenceStore store, Preferences coreStore, String defaultTokenProperty, String[] tokenProperties) {
- super(manager, store);
-
- fCorePreferenceStore= coreStore;
- fDefaultTokenProperty= defaultTokenProperty;
- fTokenProperties= tokenProperties;
-
- initialize();
- }
-
- /*
- * @see AbstractCScanner#createRules()
- */
- protected List createRules() {
- List list= new ArrayList();
-
- String tasks= null;
- if (getPreferenceStore().contains(TODO_TASK_TAGS)) {
- tasks= getPreferenceStore().getString(TODO_TASK_TAGS);
- } else if (fCorePreferenceStore != null) {
- tasks= fCorePreferenceStore.getString(TODO_TASK_TAGS);
- }
-
- if (tasks != null) {
- // Add rule for Task Tags.
- fTaskTagRule= new TaskTagRule(getToken(TASK_TAG));
- fTaskTagRule.addTaskTags(tasks);
- list.add(fTaskTagRule);
- }
-
- setDefaultReturnToken(getToken(fDefaultTokenProperty));
-
- return list;
- }
-
- /*
- * @see org.eclipse.cdt.internal.ui.text.AbstractJavaScanner#affectsBehavior(org.eclipse.jface.util.PropertyChangeEvent)
- */
- public boolean affectsBehavior(PropertyChangeEvent event) {
- return event.getProperty().equals(TODO_TASK_TAGS) || super.affectsBehavior(event);
- }
-
- /*
- * @see org.eclipse.cdt.internal.ui.text.AbstractJavaScanner#adaptToPreferenceChange(org.eclipse.jface.util.PropertyChangeEvent)
- */
- public void adaptToPreferenceChange(PropertyChangeEvent event) {
- if (fTaskTagRule != null && event.getProperty().equals(TODO_TASK_TAGS)) {
- Object value= event.getNewValue();
-
- if (value instanceof String) {
- fTaskTagRule.clearTaskTags();
- fTaskTagRule.addTaskTags((String) value);
- }
-
- } else if (super.affectsBehavior(event)) {
- super.adaptToPreferenceChange(event);
- }
- }
-
- /*
- * @see org.eclipse.cdt.internal.ui.text.AbstractJavaScanner#getTokenProperties()
- */
- protected String[] getTokenProperties() {
- return fTokenProperties;
- }
-
+public class CCommentScanner extends AbstractCScanner {
+ private static String TASK_TAG_KEY= PreferenceConstants.EDITOR_TASK_TAG_COLOR;
+ private Preferences fCorePreferenceStore;
+
+ public CCommentScanner(ITokenStoreFactory tokenStoreFactory, String defaultTokenProperty) {
+ this(tokenStoreFactory, null, defaultTokenProperty, new String[] { defaultTokenProperty, TASK_TAG_KEY });
+ }
+
+ public CCommentScanner(ITokenStoreFactory tokenStoreFactory, Preferences coreStore, String defaultTokenProperty) {
+ this(tokenStoreFactory, coreStore, defaultTokenProperty, new String[] { defaultTokenProperty, TASK_TAG_KEY });
+ }
+
+ private CCommentScanner(ITokenStoreFactory tokenStoreFactory, Preferences coreStore, String defaultTokenProperty, String[] tokenProperties) {
+ super(tokenStoreFactory.createTokenStore(tokenProperties));
+ fCorePreferenceStore= coreStore;
+ setRules(createRules(defaultTokenProperty));
+ }
+
+ protected List createRules(String defaultTokenProperty) {
+ setDefaultReturnToken(getToken(defaultTokenProperty));
+
+ IPreferenceStore store= fTokenStore.getPreferenceStore();
+ String taskWords= TaskTagRule.getTaskWords(store, fCorePreferenceStore);
+ TaskTagRule taskTagRule= new TaskTagRule(getToken(TASK_TAG_KEY), taskWords);
+ addPropertyChangeParticipant(taskTagRule);
+ return Collections.singletonList(taskTagRule);
+ }
}
Index: src/org/eclipse/cdt/internal/ui/text/CSourceViewerConfiguration.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CSourceViewerConfiguration.java,v
retrieving revision 1.70
diff -u -r1.70 CSourceViewerConfiguration.java
--- src/org/eclipse/cdt/internal/ui/text/CSourceViewerConfiguration.java 18 Jan 2008 15:54:17 -0000 1.70
+++ src/org/eclipse/cdt/internal/ui/text/CSourceViewerConfiguration.java 23 Jan 2008 15:41:43 -0000
@@ -11,12 +11,15 @@
* Anton Leherbauer (Wind River Systems)
* Sergey Prigogin (Google)
* Markus Schorn (Wind River Systems)
+ * Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text;
import java.util.Arrays;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -77,6 +80,12 @@
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.ILanguageUI;
import org.eclipse.cdt.ui.text.ICPartitions;
+import org.eclipse.cdt.ui.text.ICTokenScanner;
+import org.eclipse.cdt.ui.text.ITokenStore;
+import org.eclipse.cdt.ui.text.ITokenStoreFactory;
+import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy;
+import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
+import org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration;
import org.eclipse.cdt.internal.corext.util.CodeFormatterUtil;
@@ -90,6 +99,7 @@
import org.eclipse.cdt.internal.ui.text.contentassist.CContentAssistProcessor;
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
import org.eclipse.cdt.internal.ui.text.correction.CCorrectionAssistant;
+import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
import org.eclipse.cdt.internal.ui.typehierarchy.THInformationControl;
import org.eclipse.cdt.internal.ui.typehierarchy.THInformationProvider;
@@ -111,11 +121,11 @@
/**
* The C multi-line comment scanner.
*/
- private AbstractCScanner fMultilineCommentScanner;
+ private ICTokenScanner fMultilineDocCommentScanner;
/**
* The C single-line comment scanner.
*/
- private AbstractCScanner fSinglelineCommentScanner;
+ private ICTokenScanner fSinglelineDocCommentScanner;
/**
* The C string scanner.
*/
@@ -147,24 +157,6 @@
}
/**
- * Returns the C multi-line comment scanner for this configuration.
- *
- * @return the C multi-line comment scanner
- */
- protected RuleBasedScanner getMultilineCommentScanner() {
- return fMultilineCommentScanner;
- }
-
- /**
- * Returns the C single-line comment scanner for this configuration.
- *
- * @return the C single-line comment scanner
- */
- protected RuleBasedScanner getSinglelineCommentScanner() {
- return fSinglelineCommentScanner;
- }
-
- /**
* Returns the C string scanner for this configuration.
*
* @return the C string scanner
@@ -184,10 +176,10 @@
}
AbstractCScanner scanner= null;
if (language instanceof ICLanguageKeywords) {
- scanner= new CPreprocessorScanner(getColorManager(), fPreferenceStore, (ICLanguageKeywords)language);
+ scanner= new CPreprocessorScanner(getTokenStoreFactory(), (ICLanguageKeywords)language);
}
if (scanner == null) {
- scanner= new CPreprocessorScanner(getColorManager(), fPreferenceStore, GPPLanguage.getDefault());
+ scanner= new CPreprocessorScanner(getTokenStoreFactory(), GPPLanguage.getDefault());
}
fPreprocessorScanner= scanner;
return fPreprocessorScanner;
@@ -250,14 +242,12 @@
presenter.setSizeConstraints(50, 20, true, false);
return presenter;
}
-
+
/**
* Initializes the scanners.
*/
private void initializeScanners() {
- fMultilineCommentScanner= new CCommentScanner(getColorManager(), fPreferenceStore, ICColorConstants.C_MULTI_LINE_COMMENT);
- fSinglelineCommentScanner= new CCommentScanner(getColorManager(), fPreferenceStore, ICColorConstants.C_SINGLE_LINE_COMMENT);
- fStringScanner= new SingleTokenCScanner(getColorManager(), fPreferenceStore, ICColorConstants.C_STRING);
+ fStringScanner= new SingleTokenCScanner(getTokenStoreFactory(), ICColorConstants.C_STRING);
}
/**
@@ -274,17 +264,29 @@
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
-
- //TextAttribute attr = new TextAttribute(manager.getColor(ICColorConstants.C_DEFAULT));
- dr= new DefaultDamagerRepairer(getSinglelineCommentScanner());
+ dr= new DefaultDamagerRepairer(new CCommentScanner(getTokenStoreFactory(), ICColorConstants.C_SINGLE_LINE_COMMENT));
reconciler.setDamager(dr, ICPartitions.C_SINGLE_LINE_COMMENT);
reconciler.setRepairer(dr, ICPartitions.C_SINGLE_LINE_COMMENT);
-
- dr= new DefaultDamagerRepairer(getMultilineCommentScanner());
+
+ dr= new DefaultDamagerRepairer(new CCommentScanner(getTokenStoreFactory(), ICColorConstants.C_MULTI_LINE_COMMENT));
reconciler.setDamager(dr, ICPartitions.C_MULTI_LINE_COMMENT);
reconciler.setRepairer(dr, ICPartitions.C_MULTI_LINE_COMMENT);
-
+
+ ICTokenScanner docCommentSingleScanner= getSinglelineDocCommentScanner(getProject());
+ if(docCommentSingleScanner!=null) {
+ dr= new DefaultDamagerRepairer(docCommentSingleScanner);
+ reconciler.setDamager(dr, ICPartitions.C_SINGLE_LINE_DOC_COMMENT);
+ reconciler.setRepairer(dr, ICPartitions.C_SINGLE_LINE_DOC_COMMENT);
+ }
+
+ ICTokenScanner docCommentMultiScanner= getMultilineDocCommentScanner(getProject());
+ if(docCommentMultiScanner!=null) {
+ dr= new DefaultDamagerRepairer(docCommentMultiScanner);
+ reconciler.setDamager(dr, ICPartitions.C_MULTI_LINE_DOC_COMMENT);
+ reconciler.setRepairer(dr, ICPartitions.C_MULTI_LINE_DOC_COMMENT);
+ }
+
dr= new DefaultDamagerRepairer(getStringScanner());
reconciler.setDamager(dr, ICPartitions.C_STRING);
reconciler.setRepairer(dr, ICPartitions.C_STRING);
@@ -299,8 +301,34 @@
return reconciler;
}
+
+ /**
+ * Returns the C multi-line comment scanner for this configuration.
+ *
+ * @return the C multi-line comment scanner
+ */
+ protected ICTokenScanner getMultilineDocCommentScanner(IResource resource) {
+ if (fMultilineDocCommentScanner == null) {
+ IDocCommentViewerConfiguration owner= DocCommentOwnerManager.getInstance().getCommentOwner(resource).getMultilineConfiguration();
+ fMultilineDocCommentScanner= owner.createCommentScanner(getTokenStoreFactory());
+ }
+ return fMultilineDocCommentScanner;
+ }
/**
+ * Returns the C single-line comment scanner for this configuration.
+ *
+ * @return the C single-line comment scanner
+ */
+ protected ICTokenScanner getSinglelineDocCommentScanner(IResource resource) {
+ if (fSinglelineDocCommentScanner == null) {
+ IDocCommentViewerConfiguration owner= DocCommentOwnerManager.getInstance().getCommentOwner(resource).getSinglelineConfiguration();
+ fSinglelineDocCommentScanner= owner.createCommentScanner(getTokenStoreFactory());
+ }
+ return fSinglelineDocCommentScanner;
+ }
+
+ /**
* @return the code scanner for the given language
*/
protected RuleBasedScanner getCodeScanner(ILanguage language) {
@@ -310,14 +338,14 @@
RuleBasedScanner scanner= null;
if (language instanceof ICLanguageKeywords) {
ICLanguageKeywords cLang= (ICLanguageKeywords)language;
- scanner = new CCodeScanner(getColorManager(), fPreferenceStore, cLang);
+ scanner = new CCodeScanner(getTokenStoreFactory(), cLang);
} else if (language != null) {
ILanguageUI languageUI = (ILanguageUI)language.getAdapter(ILanguageUI.class);
if (languageUI != null)
scanner = languageUI.getCodeScanner();
}
if (scanner == null) {
- scanner = new CCodeScanner(getColorManager(), fPreferenceStore, GPPLanguage.getDefault());
+ scanner = new CCodeScanner(getTokenStoreFactory(), GPPLanguage.getDefault());
}
if (scanner instanceof AbstractCScanner) {
fCodeScanner= (AbstractCScanner)scanner;
@@ -347,6 +375,12 @@
processor = new CContentAssistProcessor(getEditor(), sourceViewer, assistant, ICPartitions.C_SINGLE_LINE_COMMENT);
assistant.setContentAssistProcessor(processor, ICPartitions.C_SINGLE_LINE_COMMENT);
+ processor = new CContentAssistProcessor(getEditor(), sourceViewer, assistant, ICPartitions.C_MULTI_LINE_DOC_COMMENT);
+ assistant.setContentAssistProcessor(processor, ICPartitions.C_MULTI_LINE_DOC_COMMENT);
+
+ processor = new CContentAssistProcessor(getEditor(), sourceViewer, assistant, ICPartitions.C_SINGLE_LINE_DOC_COMMENT);
+ assistant.setContentAssistProcessor(processor, ICPartitions.C_SINGLE_LINE_DOC_COMMENT);
+
processor = new CContentAssistProcessor(getEditor(), sourceViewer, assistant, ICPartitions.C_STRING);
assistant.setContentAssistProcessor(processor, ICPartitions.C_STRING);
@@ -410,26 +444,46 @@
*/
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
String partitioning= getConfiguredDocumentPartitioning(sourceViewer);
+
+ IDocCommentOwner owner= DocCommentOwnerManager.getInstance().getCommentOwner(getProject());
+ IAutoEditStrategy single= owner.getSinglelineConfiguration().createAutoEditStrategy();
+ IAutoEditStrategy multi= owner.getMultilineConfiguration().createAutoEditStrategy();
+
+ IAutoEditStrategy[] NONE= new IAutoEditStrategy[0];
+
if (ICPartitions.C_MULTI_LINE_COMMENT.equals(contentType))
- return new IAutoEditStrategy[] { new CCommentAutoIndentStrategy() };
+ return new IAutoEditStrategy[] { new DefaultMultilineCommentAutoEditStrategy() };
+ if (ICPartitions.C_SINGLE_LINE_DOC_COMMENT.equals(contentType))
+ return single!=null ? new IAutoEditStrategy[] {single} : NONE;
+ else if (ICPartitions.C_MULTI_LINE_DOC_COMMENT.equals(contentType))
+ return multi!=null? new IAutoEditStrategy[] {multi} : NONE;
else if (ICPartitions.C_STRING.equals(contentType))
- return new IAutoEditStrategy[] { /*new SmartSemicolonAutoEditStrategy(partitioning),*/ new CStringAutoIndentStrategy(partitioning, getProject()) };
+ return new IAutoEditStrategy[] { /*new SmartSemicolonAutoEditStrategy(partitioning),*/ new CStringAutoIndentStrategy(partitioning, getCProject()) };
else
- return new IAutoEditStrategy[] { new CAutoIndentStrategy(partitioning, getProject()) };
+ return new IAutoEditStrategy[] { new CAutoIndentStrategy(partitioning, getCProject()) };
}
-
+
/**
* @see SourceViewerConfiguration#getDoubleClickStrategy(ISourceViewer, String)
*/
public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
if (ICPartitions.C_MULTI_LINE_COMMENT.equals(contentType) ||
- ICPartitions.C_SINGLE_LINE_COMMENT.equals(contentType))
+ ICPartitions.C_SINGLE_LINE_COMMENT.equals(contentType)) {
return new DefaultTextDoubleClickStrategy();
- else if (ICPartitions.C_STRING.equals(contentType) ||
- ICPartitions.C_CHARACTER.equals(contentType))
+ } else if (ICPartitions.C_SINGLE_LINE_DOC_COMMENT.equals(contentType)) {
+ IDocCommentOwner owner= DocCommentOwnerManager.getInstance().getCommentOwner(getProject());
+ ITextDoubleClickStrategy single= owner.getSinglelineConfiguration().createDoubleClickStrategy();
+ return single != null ? single : new DefaultTextDoubleClickStrategy();
+ } else if(ICPartitions.C_MULTI_LINE_DOC_COMMENT.equals(contentType)) {
+ IDocCommentOwner owner= DocCommentOwnerManager.getInstance().getCommentOwner(getProject());
+ ITextDoubleClickStrategy multi= owner.getMultilineConfiguration().createDoubleClickStrategy();
+ return multi!=null ? multi : new DefaultTextDoubleClickStrategy();
+ } else if (ICPartitions.C_STRING.equals(contentType) ||
+ ICPartitions.C_CHARACTER.equals(contentType)) {
return new CStringDoubleClickSelector(getConfiguredDocumentPartitioning(sourceViewer));
- else if (ICPartitions.C_PREPROCESSOR.equals(contentType))
+ } else if (ICPartitions.C_PREPROCESSOR.equals(contentType)) {
return new CStringDoubleClickSelector(getConfiguredDocumentPartitioning(sourceViewer), new CDoubleClickSelector());
+ }
return new CDoubleClickSelector();
}
@@ -444,7 +498,7 @@
* @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
*/
public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
- ICProject project= getProject();
+ ICProject project= getCProject();
final int tabWidth= CodeFormatterUtil.getTabWidth(project);
final int indentWidth= CodeFormatterUtil.getIndentWidth(project);
boolean allowTabs= tabWidth <= indentWidth;
@@ -504,7 +558,12 @@
return new String(spaceChars);
}
- private ICProject getProject() {
+ /**
+ * Returns the ICProject associated with this CSourceViewerConfiguration, or null if
+ * no ICProject could be determined
+ * @return
+ */
+ private ICProject getCProject() {
ITextEditor editor= getEditor();
if (editor == null)
return null;
@@ -527,7 +586,7 @@
* @see SourceViewerConfiguration#getTabWidth(ISourceViewer)
*/
public int getTabWidth(ISourceViewer sourceViewer) {
- return CodeFormatterUtil.getTabWidth(getProject());
+ return CodeFormatterUtil.getTabWidth(getCProject());
}
/**
@@ -603,7 +662,10 @@
ICPartitions.C_SINGLE_LINE_COMMENT,
ICPartitions.C_STRING,
ICPartitions.C_CHARACTER,
- ICPartitions.C_PREPROCESSOR};
+ ICPartitions.C_PREPROCESSOR,
+ ICPartitions.C_SINGLE_LINE_DOC_COMMENT,
+ ICPartitions.C_MULTI_LINE_DOC_COMMENT
+ };
}
/**
@@ -620,8 +682,8 @@
}
public boolean affectsBehavior(PropertyChangeEvent event) {
- if (fMultilineCommentScanner.affectsBehavior(event)
- || fSinglelineCommentScanner.affectsBehavior(event)
+ if ((fMultilineDocCommentScanner != null && fMultilineDocCommentScanner.affectsBehavior(event))
+ || (fSinglelineDocCommentScanner != null && fSinglelineDocCommentScanner.affectsBehavior(event))
|| fStringScanner.affectsBehavior(event)) {
return true;
}
@@ -714,10 +776,10 @@
public void handlePropertyChangeEvent(PropertyChangeEvent event) {
if (fCodeScanner != null && fCodeScanner.affectsBehavior(event))
fCodeScanner.adaptToPreferenceChange(event);
- if (fMultilineCommentScanner.affectsBehavior(event))
- fMultilineCommentScanner.adaptToPreferenceChange(event);
- if (fSinglelineCommentScanner.affectsBehavior(event))
- fSinglelineCommentScanner.adaptToPreferenceChange(event);
+ if (fMultilineDocCommentScanner!=null && fMultilineDocCommentScanner.affectsBehavior(event))
+ fMultilineDocCommentScanner.adaptToPreferenceChange(event);
+ if (fSinglelineDocCommentScanner!=null && fSinglelineDocCommentScanner.affectsBehavior(event))
+ fSinglelineDocCommentScanner.adaptToPreferenceChange(event);
if (fStringScanner.affectsBehavior(event))
fStringScanner.adaptToPreferenceChange(event);
if (fPreprocessorScanner != null && fPreprocessorScanner.affectsBehavior(event))
@@ -833,9 +895,11 @@
*/
public void resetScanners() {
fCodeScanner= null;
+ fMultilineDocCommentScanner= null;
+ fSinglelineDocCommentScanner= null;
fPreprocessorScanner= null;
}
-
+
/**
* Creates macro exploration presenter.
* @param sourceViewer
@@ -873,6 +937,20 @@
};
return conrolCreator;
}
+
+ private IProject getProject() {
+ ICProject cproject= getCProject();
+ if(cproject!=null) {
+ return cproject.getProject();
+ }
+ return null;
+ }
-
-}
+ private ITokenStoreFactory getTokenStoreFactory() {
+ return new ITokenStoreFactory() {
+ public ITokenStore createTokenStore(String[] propertyColorNames) {
+ return new TokenStore(getColorManager(), fPreferenceStore, propertyColorNames);
+ }
+ };
+ }
+}
\ No newline at end of file
Index: src/org/eclipse/cdt/internal/ui/text/CPreprocessorScanner.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CPreprocessorScanner.java,v
retrieving revision 1.5
diff -u -r1.5 CPreprocessorScanner.java
--- src/org/eclipse/cdt/internal/ui/text/CPreprocessorScanner.java 21 Jan 2008 13:58:32 -0000 1.5
+++ src/org/eclipse/cdt/internal/ui/text/CPreprocessorScanner.java 23 Jan 2008 15:41:43 -0000
@@ -7,20 +7,21 @@
*
* Contributors:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
+ * Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.PatternRule;
-import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WhitespaceRule;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.cdt.core.model.ICLanguageKeywords;
+import org.eclipse.cdt.ui.text.ITokenStoreFactory;
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
@@ -45,15 +46,12 @@
/**
* Creates a C/C++ preprocessor scanner.
- *
- * @param manager the color manager
- * @param store the preference store
* @param keywords the keywords defined by the language dialect
*/
- public CPreprocessorScanner(IColorManager manager, IPreferenceStore store, ICLanguageKeywords keywords) {
- super(manager, store);
+ public CPreprocessorScanner(ITokenStoreFactory factory, ICLanguageKeywords keywords) {
+ super(factory.createTokenStore(fgTokenProperties));
fKeywords= keywords;
- initialize();
+ setRules(createRules());
}
/*
@@ -61,10 +59,10 @@
*/
protected List createRules() {
- Token defaultToken= getToken(ICColorConstants.PP_DEFAULT);
+ IToken defaultToken= getToken(ICColorConstants.PP_DEFAULT);
List rules= new ArrayList();
- Token token;
+ IToken token;
// Add generic white space rule.
rules.add(new WhitespaceRule(new CWhitespaceDetector()));
@@ -110,12 +108,4 @@
setDefaultReturnToken(defaultToken);
return rules;
}
-
- /*
- * @see org.eclipse.cdt.internal.ui.text.AbstractCScanner#getTokenProperties()
- */
- protected String[] getTokenProperties() {
- return fgTokenProperties;
- }
-
}
Index: src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java,v
retrieving revision 1.19
diff -u -r1.19 CAutoIndentStrategy.java
--- src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java 15 Jan 2008 13:10:05 -0000 1.19
+++ src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java 23 Jan 2008 15:41:43 -0000
@@ -44,7 +44,6 @@
* Auto indent strategy sensitive to brackets.
*/
public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
- private static final String MULTILINE_COMMENT_CLOSE = "*/"; //$NON-NLS-1$
/** The line comment introducer. Value is "{@value}" */
private static final String LINE_COMMENT= "//"; //$NON-NLS-1$
// private static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION = new GCCScannerExtensionConfiguration();
@@ -1120,43 +1119,20 @@
super.customizeDocumentCommand(d, c);
return;
}
-
- if (c.length == 0 && c.text != null && isLineDelimiter(d, c.text)) {
- if (isAppendToOpenMultilineComment(d, c)) {
- // special case: multi-line comment at end of document (bug 48339)
- CCommentAutoIndentStrategy.commentIndentAfterNewLine(d, c);
- } else {
- smartIndentAfterNewLine(d, c);
- }
- } else if ("/".equals(c.text) && isAppendToOpenMultilineComment(d, c)) { //$NON-NLS-1$
- // special case: multi-line comment at end of document (bug 48339)
- CCommentAutoIndentStrategy.commentIndentForCommentEnd(d, c);
+
+ /*
+ * I removed the workaround for 48339 as I believe the recent changes to
+ * FastCPartitioner are enough to fix this.
+ */
+ boolean isNewLine= c.length == 0 && c.text != null && isLineDelimiter(d, c.text);
+ if (isNewLine) {
+ smartIndentAfterNewLine(d, c);
} else if (c.text.length() == 1) {
smartIndentOnKeypress(d, c);
} else if (c.text.length() > 1 && getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SMART_PASTE)) {
smartPaste(d, c); // no smart backspace for paste
}
}
-
- /**
- * Check, if the command appends to an open multi-line comment.
- * @param d the document
- * @param c the document command
- * @return true, if the command appends to an open multi-line comment.
- */
- private boolean isAppendToOpenMultilineComment(IDocument d, DocumentCommand c) {
- if (d.getLength() >= 2 && c.offset == d.getLength()) {
- try {
- String contentType = TextUtilities.getContentType(d, fPartitioning, c.offset - 1, false);
- if (ICPartitions.C_MULTI_LINE_COMMENT.equals(contentType)) {
- return !d.get(c.offset - 2, 2).equals(MULTILINE_COMMENT_CLOSE);
- }
- } catch (BadLocationException exc) {
- // see below
- }
- }
- return false;
- }
private static IPreferenceStore getPreferenceStore() {
return CUIPlugin.getDefault().getCombinedPreferenceStore();
Index: src/org/eclipse/cdt/internal/ui/text/FastCPartitionScanner.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/FastCPartitionScanner.java,v
retrieving revision 1.11
diff -u -r1.11 FastCPartitionScanner.java
--- src/org/eclipse/cdt/internal/ui/text/FastCPartitionScanner.java 21 Jan 2008 13:58:32 -0000 1.11
+++ src/org/eclipse/cdt/internal/ui/text/FastCPartitionScanner.java 23 Jan 2008 15:41:43 -0000
@@ -21,6 +21,7 @@
import org.eclipse.jface.text.rules.Token;
import org.eclipse.cdt.ui.text.ICPartitions;
+import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
/**
@@ -38,6 +39,8 @@
private static final int PREPROCESSOR= 5;
private static final int PREPROCESSOR_MULTI_LINE_COMMENT= 6;
private static final int PREPROCESSOR_STRING= 7;
+ private static final int SINGLE_LINE_DOC_COMMENT= 8;
+ private static final int MULTI_LINE_DOC_COMMENT= 9;
// beginning of prefixes and postfixes
private static final int NONE= 0;
@@ -65,11 +68,14 @@
private int fPrefixLength;
/** Indicate whether current char is first non-whitespace char on the line*/
private boolean fFirstCharOnLine= true;
-
+ /** An optional (possibly null) comment owner for detecting documentation-comments **/
+ private IDocCommentOwner fOwner;
+
// emulate CPartitionScanner
private final boolean fEmulate;
private int fCCodeOffset;
private int fCCodeLength;
+ private IDocument fDocument;
private final IToken[] fTokens= new IToken[] {
new Token(null),
@@ -80,14 +86,21 @@
new Token(C_PREPROCESSOR),
new Token(C_MULTI_LINE_COMMENT),
new Token(C_PREPROCESSOR),
+ new Token(C_SINGLE_LINE_DOC_COMMENT),
+ new Token(C_MULTI_LINE_DOC_COMMENT)
};
- public FastCPartitionScanner(boolean emulate) {
+ public FastCPartitionScanner(boolean emulate, IDocCommentOwner owner) {
fEmulate= emulate;
+ fOwner= owner;
}
+ public FastCPartitionScanner(IDocCommentOwner owner) {
+ this(false, owner);
+ }
+
public FastCPartitionScanner() {
- this(false);
+ this(false, null);
}
/*
@@ -533,14 +546,20 @@
}
private final IToken postFix(int state) {
+ return postFix(state, CCODE);
+ }
+
+ private final IToken postFix(int state, int newState) {
fTokenLength++;
fLast= NONE;
- fState= CCODE;
+ fState= newState;
fPrefixLength= 0;
- return fTokens[state];
+ return fTokens[interceptTokenState(state)];
}
+
private final IToken preFix(int state, int newState, int last, int prefixLength) {
+
// emulate CPartitionScanner
if (fEmulate && state == CCODE && (fTokenLength - getLastLength(fLast) > 0)) {
fTokenLength -= getLastLength(fLast);
@@ -550,15 +569,14 @@
fState= newState;
fPrefixLength= prefixLength;
fLast= last;
- return fTokens[state];
+ return fTokens[interceptTokenState(state)];
} else {
fTokenLength -= getLastLength(fLast);
fLast= last;
fPrefixLength= prefixLength;
- IToken token= fTokens[state];
fState= newState;
- return token;
+ return fTokens[interceptTokenState(state)];
}
}
@@ -581,7 +599,13 @@
else if (contentType.equals(C_PREPROCESSOR))
return PREPROCESSOR;
-
+
+ else if (contentType.equals(C_SINGLE_LINE_DOC_COMMENT))
+ return SINGLE_LINE_COMMENT; // intentionally non-doc state: the state machine is doc-comment unaware
+
+ else if (contentType.equals(C_MULTI_LINE_DOC_COMMENT))
+ return MULTI_LINE_COMMENT; // intentionally non-doc state: the state machine is doc-comment unaware
+
else
return CCODE;
}
@@ -590,7 +614,7 @@
* @see IPartitionTokenScanner#setPartialRange(IDocument, int, int, String, int)
*/
public void setPartialRange(IDocument document, int offset, int length, String contentType, int partitionOffset) {
-
+ fDocument= document;
fScanner.setRange(document, offset, length);
fTokenOffset= partitionOffset;
fTokenLength= 0;
@@ -622,7 +646,7 @@
* @see ITokenScanner#setRange(IDocument, int, int)
*/
public void setRange(IDocument document, int offset, int length) {
-
+ fDocument= document;
fScanner.setRange(document, offset, length);
fTokenOffset= offset;
fTokenLength= 0;
@@ -658,4 +682,30 @@
return fTokenOffset;
}
+ private int interceptTokenState(int proposedTokenState) {
+ if(fOwner!=null) {
+ switch(proposedTokenState) {
+ case MULTI_LINE_COMMENT:
+ if(fOwner.getMultilineConfiguration().isDocumentationComment(fDocument, fTokenOffset, fTokenLength))
+ return MULTI_LINE_DOC_COMMENT;
+ break;
+
+ case SINGLE_LINE_COMMENT:
+ if(fOwner.getSinglelineConfiguration().isDocumentationComment(fDocument, fTokenOffset, fTokenLength))
+ return SINGLE_LINE_DOC_COMMENT;
+ break;
+
+ }
+ }
+ return proposedTokenState;
+ }
+
+ /**
+ * @return the DocCommentOwner associated with this partition scanner, or null
+ * if there is no owner.
+ * @since 5.0
+ */
+ public IDocCommentOwner getDocCommentOwner() {
+ return fOwner;
+ }
}
Index: src/org/eclipse/cdt/internal/ui/text/FastCPartitioner.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/FastCPartitioner.java,v
retrieving revision 1.2
diff -u -r1.2 FastCPartitioner.java
--- src/org/eclipse/cdt/internal/ui/text/FastCPartitioner.java 16 Oct 2007 11:38:54 -0000 1.2
+++ src/org/eclipse/cdt/internal/ui/text/FastCPartitioner.java 23 Jan 2008 15:41:43 -0000
@@ -16,6 +16,7 @@
import org.eclipse.jface.text.rules.IPartitionTokenScanner;
import org.eclipse.cdt.ui.text.ICPartitions;
+import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
/**
* A slightly adapted FastPartitioner.
@@ -44,10 +45,30 @@
if (fDocument.getChar(offset - 1) != '\n') {
return region;
}
+ } else if (ICPartitions.C_MULTI_LINE_DOC_COMMENT.equals(region.getType())) {
+ if (!fDocument.get(offset - 2, 2).equals("*/")) { //$NON-NLS-1$
+ return region;
+ }
+ } else if (ICPartitions.C_SINGLE_LINE_DOC_COMMENT.equals(region .getType())) {
+ if (fDocument.getChar(offset - 1) != '\n') {
+ return region;
+ }
}
} catch (BadLocationException exc) {
}
}
return super.getPartition(offset, preferOpenPartitions);
}
+
+ /**
+ * @return the DocCommentOwner associated with this partition scanner, or null
+ * if there is no owner.
+ * @since 5.0
+ */
+ public IDocCommentOwner getDocCommentOwner() {
+ if(fScanner instanceof FastCPartitionScanner) {
+ return ((FastCPartitionScanner)fScanner).getDocCommentOwner();
+ }
+ return null;
+ }
}
Index: src/org/eclipse/cdt/internal/ui/text/AbstractCScanner.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractCScanner.java,v
retrieving revision 1.6
diff -u -r1.6 AbstractCScanner.java
--- src/org/eclipse/cdt/internal/ui/text/AbstractCScanner.java 27 Sep 2006 14:38:33 -0000 1.6
+++ src/org/eclipse/cdt/internal/ui/text/AbstractCScanner.java 23 Jan 2008 15:41:43 -0000
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,358 +8,99 @@
* Contributors:
* IBM Corporation - initial API and implementation
* QNX Software System
+ * Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text;
-
-import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferenceConverter;
-import org.eclipse.jface.resource.StringConverter;
-import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
-import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.widgets.Display;
-
-import org.eclipse.cdt.ui.PreferenceConstants;
+import org.eclipse.cdt.ui.IPropertyChangeParticipant;
+import org.eclipse.cdt.ui.text.ICTokenScanner;
+import org.eclipse.cdt.ui.text.ITokenStore;
/**
- * Initialized with a color manager and a preference store, its subclasses are
- * only responsible for providing a list of preference keys for based on which tokens
- * are generated and to use this tokens to define the rules controlling this scanner.
- * - * This scanner stores the color defined by the color preference key into - * the color manager under the same key. - *
- *- * Preference color key + {@link PreferenceConstants#EDITOR_BOLD_SUFFIX} are used - * to retrieve whether the token is rendered in bold. - *
- *- * Preference color key + {@link PreferenceConstants#EDITOR_ITALIC_SUFFIX} are used - * to retrieve whether the token is rendered in italic. - *
- *- * Preference color key + {@link PreferenceConstants#EDITOR_STRIKETHROUGH_SUFFIX} are used - * to retrieve whether the token is rendered in strikethrough. - *
- *- * Preference color key + {@link PreferenceConstants#EDITOR_UNDERLINE_SUFFIX} are used - * to retrieve whether the token is rendered in underline. - *
+ * Convenience implementation. */ -public abstract class AbstractCScanner extends BufferedRuleBasedScanner { - - - private IColorManager fColorManager; - private IPreferenceStore fPreferenceStore; - - private Map fTokenMap= new HashMap(); - private String[] fPropertyNamesColor; - /** - * Preference keys for boolean preferences which aretrue
,
- * iff the corresponding token should be rendered bold.
- */
- private String[] fPropertyNamesBold;
- /**
- * Preference keys for boolean preferences which are true
,
- * iff the corresponding token should be rendered italic.
- *
- * @since 4.0
- */
- private String[] fPropertyNamesItalic;
- /**
- * Preference keys for boolean preferences which are true
,
- * iff the corresponding token should be rendered strikethrough.
- *
- * @since 4.0
- */
- private String[] fPropertyNamesStrikethrough;
- /**
- * Preference keys for boolean preferences which are true
,
- * iff the corresponding token should be rendered underline.
- *
- * @since 4.0
- */
- private String[] fPropertyNamesUnderline;
-
-
- private boolean fNeedsLazyColorLoading;
-
- /**
- * Returns an array of preference keys which define the tokens
- * used in the rules of this scanner.
- * - * The preference key is used access the color in the preference - * store and in the color manager. - *
- *- * Preference key + {@link PreferenceConstants#EDITOR_BOLD_SUFFIX} is used - * to retrieve whether the token is rendered in bold. - *
- *- * Preference key + {@link PreferenceConstants#EDITOR_ITALIC_SUFFIX} is used - * to retrieve whether the token is rendered in italic. - *
- *- * Preference key + {@link PreferenceConstants#EDITOR_UNDERLINE_SUFFIX} is used - * to retrieve whether the token is rendered underlined. - *
- *- * Preference key + {@link PreferenceConstants#EDITOR_STRIKETHROUGH_SUFFIX} is used - * to retrieve whether the token is rendered stricken out. - *
- */ - abstract protected String[] getTokenProperties(); - - /** - * Creates the list of rules controlling this scanner. - */ - abstract protected List createRules(); - - - /** - * Creates an abstract C scanner. - */ - public AbstractCScanner(IColorManager manager, IPreferenceStore store) { - super(); - fColorManager= manager; - fPreferenceStore= store; - } - - /** - * Creates an abstract C scanner. - */ - public AbstractCScanner(IColorManager manager, IPreferenceStore store, int bufsize) { - super(bufsize); - fColorManager= manager; - fPreferenceStore= store; - } - - /** - * Must be called after the constructor has been called. - */ - public final void initialize() { - - fPropertyNamesColor= getTokenProperties(); - int length= fPropertyNamesColor.length; - fPropertyNamesBold= new String[length]; - fPropertyNamesItalic= new String[length]; - fPropertyNamesStrikethrough= new String[length]; - fPropertyNamesUnderline= new String[length]; - - for (int i= 0; i < length; i++) { - fPropertyNamesBold[i]= getBoldKey(fPropertyNamesColor[i]); - fPropertyNamesItalic[i]= getItalicKey(fPropertyNamesColor[i]); - fPropertyNamesStrikethrough[i]= getStrikethroughKey(fPropertyNamesColor[i]); - fPropertyNamesUnderline[i]= getUnderlineKey(fPropertyNamesColor[i]); - } - - fNeedsLazyColorLoading= Display.getCurrent() == null; - for (int i= 0; i < length; i++) { - if (fNeedsLazyColorLoading) - addTokenWithProxyAttribute(fPropertyNamesColor[i], fPropertyNamesBold[i], fPropertyNamesItalic[i], fPropertyNamesStrikethrough[i], fPropertyNamesUnderline[i]); - else - addToken(fPropertyNamesColor[i], fPropertyNamesBold[i], fPropertyNamesItalic[i], fPropertyNamesStrikethrough[i], fPropertyNamesUnderline[i]); - } - - initializeRules(); - } +public abstract class AbstractCScanner extends BufferedRuleBasedScanner implements ICTokenScanner { + private List/*true
if the comment should be closed, false
if not
+ */
+ /*
+ * Adapted from JDT
+ */
+ public boolean shouldCloseMultiline(IDocument document, int offset) {
+ try {
+ IRegion line= document.getLineInformationOfOffset(offset);
+ ITypedRegion partition= TextUtilities.getPartition(document, ICPartitions.C_PARTITIONING, offset, false);
+ int partitionEnd= partition.getOffset() + partition.getLength();
+ if (line.getOffset() >= partitionEnd)
+ return false;
+
+ String comment= document.get(partition.getOffset(), partition.getLength());
+ if (comment.indexOf(MULTILINE_START, offset - partition.getOffset()) != -1)
+ return true; // enclosed another comment -> probably a new comment
+
+ if (document.getLength() == partitionEnd) {
+ return !comment.endsWith(MULTILINE_END);
+ }
+
+ return false;
+
+ } catch (BadLocationException e) {
+ return false;
+ }
+ }
+
+ /**
+ * @return the ITranslationUnit for the active editor, or null if no active
+ * editor could be found.
+ */
+ /*
+ * Cloned from JDT
+ */
+ protected static ITranslationUnit getTranslationUnit() {
+ IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (window == null)
+ return null;
+
+ IWorkbenchPage page= window.getActivePage();
+ if (page == null)
+ return null;
+
+ IEditorPart editor= page.getActiveEditor();
+ if (editor == null)
+ return null;
+
+ IWorkingCopyManager manager= CUIPlugin.getDefault().getWorkingCopyManager();
+ ITranslationUnit unit= manager.getWorkingCopy(editor.getEditorInput());
+ if (unit == null)
+ return null;
+
+ return unit;
+ }
+
+ /**
+ * Returns a new buffer with the specified indent string inserted at the beginning
+ * of each line in the specified input buffer
+ * @param buffer
+ * @param indent
+ */
+ protected static final StringBuffer indent(StringBuffer buffer, String indent) {
+ StringBuffer result= new StringBuffer();
+ BufferedReader br= new BufferedReader(new StringReader(buffer.toString()));
+ try {
+ for(String line= br.readLine(); line!=null; line= br.readLine()) {
+ result.append(indent + line + "\n"); //$NON-NLS-1$
+ }
+ } catch(IOException ioe) {
+ throw new AssertionError(); // we can't get IO errors from a string backed reader
+ }
+ return result;
+ }
+
+ /**
+ * Returns the offset of the first non-whitespace character in the specified document, searching
+ * right/downward from the specified start offset up to the specified end offset. If there is
+ * no nonwhitespace then the end offset is returned.
+ * @param document
+ * @param offset
+ * @param end
+ * @throws BadLocationException
+ */
+ protected static int findEndOfWhiteSpaceAt(IDocument document, int offset, int end) throws BadLocationException {
+ while (offset < end) {
+ char c= document.getChar(offset);
+ if (c != ' ' && c != '\t') {
+ return offset;
+ }
+ offset++;
+ }
+ return end;
+ }
+
+ /**
+ * Returns the range of the Javadoc prefix on the given line in
+ * document
. The prefix greedily matches the following regex
+ * pattern: \w*\*\w*
, that is, any number of whitespace
+ * characters, followed by an asterix ('*'), followed by any number of
+ * whitespace characters.
+ *
+ * @param document the document to which line
refers
+ * @param line the line from which to extract the prefix range
+ * @return an IRegion
describing the range of the prefix on
+ * the given line
+ * @throws BadLocationException if accessing the document fails
+ */
+ protected static IRegion findPrefixRange(IDocument document, IRegion line) throws BadLocationException {
+ int lineOffset= line.getOffset();
+ int lineEnd= lineOffset + line.getLength();
+ int indentEnd= findEndOfWhiteSpaceAt(document, lineOffset, lineEnd);
+ if (indentEnd < lineEnd && document.getChar(indentEnd) == '*') {
+ indentEnd++;
+ while (indentEnd < lineEnd && document.getChar(indentEnd) != ' ')
+ indentEnd++;
+ while (indentEnd < lineEnd && document.getChar(indentEnd) == ' ')
+ indentEnd++;
+ }
+ return new Region(lineOffset, indentEnd - lineOffset);
+ }
+
+ /**
+ * Returns whether the text ends with one of the specified IDocument object's
+ * legal line delimiters.
+ */
+ protected static boolean endsWithDelimiter(IDocument d, String txt) {
+ String[] delimiters= d.getLegalLineDelimiters();
+ for (int i= 0; i < delimiters.length; i++) {
+ if (txt.endsWith(delimiters[i]))
+ return true;
+ }
+ return false;
+ }
+}
Index: src/org/eclipse/cdt/ui/text/ICTokenScanner.java
===================================================================
RCS file: src/org/eclipse/cdt/ui/text/ICTokenScanner.java
diff -N src/org/eclipse/cdt/ui/text/ICTokenScanner.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/ui/text/ICTokenScanner.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Symbian Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andrew Ferguson (Symbian) - Initial implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.text;
+
+import org.eclipse.jface.text.rules.ITokenScanner;
+import org.eclipse.cdt.ui.IPropertyChangeParticipant;
+
+/**
+ * Interface for CDT Scanners. Scanners used in CDT must additionally be
+ * IPropertyChangeParticipant's.
+ *
+ * @since 5.0
+ */
+public interface ICTokenScanner extends ITokenScanner, IPropertyChangeParticipant {
+}
Index: src/org/eclipse/cdt/internal/ui/text/doctools/docpp/DocppSingleConfiguration.java
===================================================================
RCS file: src/org/eclipse/cdt/internal/ui/text/doctools/docpp/DocppSingleConfiguration.java
diff -N src/org/eclipse/cdt/internal/ui/text/doctools/docpp/DocppSingleConfiguration.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/internal/ui/text/doctools/docpp/DocppSingleConfiguration.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,40 @@
+package org.eclipse.cdt.internal.ui.text.doctools.docpp;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.text.doctools.generic.AbstractGenericTagDocCommentViewerConfiguration;
+import org.eclipse.cdt.ui.text.doctools.generic.GenericDocTag;
+
+public class DocppSingleConfiguration extends AbstractGenericTagDocCommentViewerConfiguration {
+ GenericDocTag[] tags;
+
+ public DocppSingleConfiguration() {
+ super(DocppHelper.getDocPPTags(), new char[] {'@','\\'}, DocppHelper.DOCPP_SINGLE_TOKEN, DocppHelper.DOCPP_TAG_RECOGNIZED);
+ }
+
+ public IAutoEditStrategy createAutoEditStrategy() {
+ return new DefaultIndentLineAutoEditStrategy();
+ }
+
+ public boolean isDocumentationComment(IDocument doc, int offset, int length) {
+ try {
+ if(offset+2 < doc.getLength()) {
+ char c= doc.getChar(offset+2);
+ if(c == '@') {
+ if(offset + 3 < doc.getLength()) {
+ char d= doc.getChar(offset+3);
+ return d == '{' || d == '}';
+ }
+ }
+ return c == '/';
+ }
+ } catch(BadLocationException ble) {
+ CUIPlugin.getDefault().log(ble);
+ }
+ return false;
+ }
+}
Index: src/org/eclipse/cdt/internal/ui/text/doctools/doxygen/DoxygenMultilineConfiguration.java
===================================================================
RCS file: src/org/eclipse/cdt/internal/ui/text/doctools/doxygen/DoxygenMultilineConfiguration.java
diff -N src/org/eclipse/cdt/internal/ui/text/doctools/doxygen/DoxygenMultilineConfiguration.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/internal/ui/text/doctools/doxygen/DoxygenMultilineConfiguration.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,31 @@
+package org.eclipse.cdt.internal.ui.text.doctools.doxygen;
+
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.text.doctools.generic.AbstractGenericTagDocCommentViewerConfiguration;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+
+public class DoxygenMultilineConfiguration extends AbstractGenericTagDocCommentViewerConfiguration {
+
+ public DoxygenMultilineConfiguration() {
+ super(DoxygenHelper.getDoxygenTags(), new char[] {'@','\\'}, DoxygenHelper.DOXYGEN_MULTI_TOKEN, DoxygenHelper.DOXYGEN_TAG_RECOGNIZED);
+ }
+
+ public IAutoEditStrategy createAutoEditStrategy() {
+ return new DoxygenMultilineAutoEditStrategy();
+ }
+
+ public boolean isDocumentationComment(IDocument doc, int offset, int length) {
+ try {
+ if(offset+2 < doc.getLength()) {
+ char c= doc.getChar(offset+2);
+ return c == '*' || c == '!';
+ }
+ } catch(BadLocationException ble) {
+ CUIPlugin.getDefault().log(ble);
+ }
+ return false;
+ }
+}
Index: src/org/eclipse/cdt/internal/ui/text/doctools/NullDocCommentOwner.java
===================================================================
RCS file: src/org/eclipse/cdt/internal/ui/text/doctools/NullDocCommentOwner.java
diff -N src/org/eclipse/cdt/internal/ui/text/doctools/NullDocCommentOwner.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/internal/ui/text/doctools/NullDocCommentOwner.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Symbian Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andrew Ferguson (Symbian) - Initial implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.text.doctools;
+
+import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
+
+public final class NullDocCommentOwner extends DocCommentOwner {
+ private static final String ID = "org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentOwner"; //$NON-NLS-1$
+ public static final IDocCommentOwner INSTANCE= new NullDocCommentOwner();
+ private NullDocCommentOwner() {
+ super(
+ ID,
+ Messages.NullDocCommentOwner_Name,
+ NullDocCommentViewerConfiguration.INSTANCE,
+ NullDocCommentViewerConfiguration.INSTANCE
+ );
+ }
+}
Index: src/org/eclipse/cdt/internal/ui/text/doctools/DocCommentSinglelineProposalComputer.java
===================================================================
RCS file: src/org/eclipse/cdt/internal/ui/text/doctools/DocCommentSinglelineProposalComputer.java
diff -N src/org/eclipse/cdt/internal/ui/text/doctools/DocCommentSinglelineProposalComputer.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/internal/ui/text/doctools/DocCommentSinglelineProposalComputer.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Symbian Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andrew Ferguson (Symbian) - Initial implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.text.doctools;
+
+import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
+import org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration;
+
+
+public class DocCommentSinglelineProposalComputer extends AbstractDocCommentProposalComputer {
+ protected IDocCommentViewerConfiguration getConfiguration(IDocCommentOwner owner) {
+ return owner.getSinglelineConfiguration();
+ }
+}
Index: src/org/eclipse/cdt/ui/text/ITokenStoreFactory.java
===================================================================
RCS file: src/org/eclipse/cdt/ui/text/ITokenStoreFactory.java
diff -N src/org/eclipse/cdt/ui/text/ITokenStoreFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/ui/text/ITokenStoreFactory.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Symbian Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andrew Ferguson (Symbian) - Initial implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.text;
+
+/**
+ * A means of obtaining ITokenStore objects
+ * @since 5.0
+ */
+public interface ITokenStoreFactory {
+ /**
+ * @param propertyColorNames
+ * @return a token store object initialized with the specified propertyColorNames
+ */
+ public ITokenStore createTokenStore(String[] propertyColorNames);
+}
Index: src/org/eclipse/cdt/internal/ui/text/doctools/docpp/DocppMultilineAutoEditStrategy.java
===================================================================
RCS file: src/org/eclipse/cdt/internal/ui/text/doctools/docpp/DocppMultilineAutoEditStrategy.java
diff -N src/org/eclipse/cdt/internal/ui/text/doctools/docpp/DocppMultilineAutoEditStrategy.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/internal/ui/text/doctools/docpp/DocppMultilineAutoEditStrategy.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,80 @@
+package org.eclipse.cdt.internal.ui.text.doctools.docpp;
+
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITypedRegion;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
+import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy;
+
+/**
+ * {@link IAutoEditStrategy} for adding Docpp tags for comments.
+ */
+public class DocppMultilineAutoEditStrategy extends DefaultMultilineCommentAutoEditStrategy {
+ private static final String PARAM = "@param "; //$NON-NLS-1$
+ private static final String RETURN = "@return\n"; //$NON-NLS-1$
+
+ protected StringBuffer paramTags(IASTParameterDeclaration[] decls) {
+ StringBuffer result= new StringBuffer();
+ for(int i=0; i+ * Preference color key + {@link PreferenceConstants#EDITOR_BOLD_SUFFIX} are used + * to retrieve whether the token is rendered in bold. + *
+ *+ * Preference color key + {@link PreferenceConstants#EDITOR_ITALIC_SUFFIX} are used + * to retrieve whether the token is rendered in italic. + *
+ *+ * Preference color key + {@link PreferenceConstants#EDITOR_STRIKETHROUGH_SUFFIX} are used + * to retrieve whether the token is rendered in strikethrough. + *
+ *+ * Preference color key + {@link PreferenceConstants#EDITOR_UNDERLINE_SUFFIX} are used + * to retrieve whether the token is rendered in underline. + *
+ * + * @see ITokenStoreFactory + * @since 5.0 + */ +public interface ITokenStore extends IPropertyChangeParticipant { + /** + * Ensures any IToken objects that will be or have been returned are + * initialized for display. + */ + void ensureTokensInitialised(); + + /** + * @param property + * @return a token for the specified property. The Token may not be suitable for use if the + * current Display is null. Clients should call ITokenStoreFactory#ensureTokensInitialised() at the + * point of token use. // TODO - I've not yet determined when this is necessary + */ + IToken getToken(String property); + + /** + * @return The preference store used to read token styling preferences from. + */ + IPreferenceStore getPreferenceStore(); +} Index: src/org/eclipse/cdt/internal/ui/text/doctools/DocCommentOwner.java =================================================================== RCS file: src/org/eclipse/cdt/internal/ui/text/doctools/DocCommentOwner.java diff -N src/org/eclipse/cdt/internal/ui/text/doctools/DocCommentOwner.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/cdt/internal/ui/text/doctools/DocCommentOwner.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2008 Symbian Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.text.doctools; + +import org.eclipse.core.runtime.Assert; + +import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner; +import org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration; + +/** + * Internal implementation of IDocCommentOwner + */ +public class DocCommentOwner implements IDocCommentOwner { + private final String id; + private final String name; + private final IDocCommentViewerConfiguration multi, single; + + public DocCommentOwner(String id, String name, IDocCommentViewerConfiguration multi, IDocCommentViewerConfiguration single) { + Assert.isNotNull(id); Assert.isNotNull(name); Assert.isNotNull(multi); Assert.isNotNull(single); + this.id= id; + this.name= name; + this.multi= multi; + this.single= single; + } + + /* + * @see org.eclipse.cdt.ui.text.ICCommentOwner#getID() + */ + public String getID() { + return id; + } + + /* + * @see org.eclipse.cdt.ui.text.ICCommentOwner#getName() + */ + public String getName() { + return name; + } + + /* + * @see org.eclipse.cdt.ui.text.ICCommentOwner#getMultilineConfiguration() + */ + public IDocCommentViewerConfiguration getMultilineConfiguration() { + return multi; + } + + /* + * @see org.eclipse.cdt.ui.text.ICCommentOwner#getSinglelineConfiguration() + */ + public IDocCommentViewerConfiguration getSinglelineConfiguration() { + return single; + } +} Index: src/org/eclipse/cdt/ui/IPropertyChangeParticipant.java =================================================================== RCS file: src/org/eclipse/cdt/ui/IPropertyChangeParticipant.java diff -N src/org/eclipse/cdt/ui/IPropertyChangeParticipant.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/cdt/ui/IPropertyChangeParticipant.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial Implementation + *******************************************************************************/ +package org.eclipse.cdt.ui; + +import org.eclipse.jface.util.PropertyChangeEvent; + +/** + * Implemented by classes which can optionally participate in property + * change events, and report whether an event would affect them without + * adapting to it. + * + * @since 5.0 + */ +public interface IPropertyChangeParticipant { + /** + * @param event + * @return true if the specified event will affect the participant's + * behaviour in a way it determines potential clients could act upon. + */ + public boolean affectsBehavior(PropertyChangeEvent event); + + /** + * Performs any necessary to adapt the participant to the specified event. + * @param event + */ + public void adaptToPreferenceChange(PropertyChangeEvent event); +} Index: src/org/eclipse/cdt/ui/text/doctools/IDocCommentOwner.java =================================================================== RCS file: src/org/eclipse/cdt/ui/text/doctools/IDocCommentOwner.java diff -N src/org/eclipse/cdt/ui/text/doctools/IDocCommentOwner.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/cdt/ui/text/doctools/IDocCommentOwner.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2008 Symbian Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.text.doctools; + +/** + * A comment owner provides {@link IDocCommentViewerConfiguration} ov + * the CDT c/c++ editor. + * + * This interface is not intended to be implemented externally to CDT. + * @since 5.0 + */ +public interface IDocCommentOwner { + /** + * @return the non-null unique identifier for this comment owner. If contributed via the + * extension point, the ID corresponds to that in plugin.xml. + */ + String getID(); + + /** + * @return a non-null human-readable name for this comment owner. If contributed via plugin.xml + * this name can be localized using the plug-in externalization mechanism. + */ + String getName(); + + /** + * @return a non-null {@link IDocCommentViewerConfiguration} suitable for a multi-line comment context + */ + IDocCommentViewerConfiguration getMultilineConfiguration(); + + /** + * @return a non-null {@link IDocCommentViewerConfiguration} suitable for a single-line comment context + */ + IDocCommentViewerConfiguration getSinglelineConfiguration(); +} Index: src/org/eclipse/cdt/ui/text/doctools/IDocCommentOwnershipListener.java =================================================================== RCS file: src/org/eclipse/cdt/ui/text/doctools/IDocCommentOwnershipListener.java diff -N src/org/eclipse/cdt/ui/text/doctools/IDocCommentOwnershipListener.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/cdt/ui/text/doctools/IDocCommentOwnershipListener.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2008 Symbian Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.text.doctools; + +import org.eclipse.core.resources.IResource; + + +/** + * Implemented by clients interested in documentation comment ownership change events. These are generated + * when the association between resource or workspace and documentation comment owner is set. + * @since 5.0 + */ +public interface IDocCommentOwnershipListener { + /** + * Called when document comment ownership has changed. + * @param resource + * @param submappingsRemoved + * @param old + * @param newOwner + */ + public void ownershipChanged(IResource resource, boolean submappingsRemoved, IDocCommentOwner old, IDocCommentOwner newOwner); + + /** + * TODO + * @param old + * @param newOwner + */ + public void workspaceOwnershipChanged(IDocCommentOwner old, IDocCommentOwner newOwner); +} Index: src/org/eclipse/cdt/ui/text/doctools/generic/GenericTagCommentScanner.java =================================================================== RCS file: src/org/eclipse/cdt/ui/text/doctools/generic/GenericTagCommentScanner.java diff -N src/org/eclipse/cdt/ui/text/doctools/generic/GenericTagCommentScanner.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/cdt/ui/text/doctools/generic/GenericTagCommentScanner.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2008 Symbian Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.text.doctools.generic; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.Preferences; +import org.eclipse.jface.text.rules.BufferedRuleBasedScanner; +import org.eclipse.jface.text.rules.IRule; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.IWordDetector; +import org.eclipse.jface.text.rules.WordRule; +import org.eclipse.jface.util.PropertyChangeEvent; + +import org.eclipse.cdt.ui.PreferenceConstants; +import org.eclipse.cdt.ui.text.ICTokenScanner; +import org.eclipse.cdt.ui.text.ITokenStore; +import org.eclipse.cdt.ui.text.ITokenStoreFactory; +import org.eclipse.cdt.ui.text.TaskTagRule; + +/** + * ICTokenScanner which recognizes a specified set of tags, starting with a specified name + */ +public class GenericTagCommentScanner extends BufferedRuleBasedScanner implements ICTokenScanner { + private TaskTagRule fTaskTagRule; + private Preferences fCorePreferenceStore; + private String fDefaultTokenProperty; + private String fTagToken; + + private GenericDocTag[] fTags; + private char[] fTagMarkers; + private ITokenStore fTokenStore; + + private static String[] mkArray(String defaultTokenProperty, String tagToken) { + return new String[] { defaultTokenProperty, tagToken, PreferenceConstants.EDITOR_TASK_TAG_COLOR }; + } + + /** + * @param tokenStoreFactory + * @param docToken + * @param tagToken + * @param tags + * @param tagMarkers + */ + public GenericTagCommentScanner(ITokenStoreFactory tokenStoreFactory, String docToken, String tagToken, GenericDocTag[] tags, char[] tagMarkers) { + Assert.isNotNull(tags); + fTags= tags; + fTagMarkers= tagMarkers; + fTagToken= tagToken; + + fTokenStore= tokenStoreFactory.createTokenStore(mkArray(docToken, tagToken)); + fCorePreferenceStore= null; // TODO + fDefaultTokenProperty= docToken; + + setRules(createRules()); + } + + public IToken nextToken() { + fTokenStore.ensureTokensInitialised(); + return super.nextToken(); + } + + protected IRule[] createRules() { + List result= new ArrayList(); + + class TagDetector implements IWordDetector { + public boolean isWordStart(char c) { + return c == '@' || c == '\\'; + } + public boolean isWordPart(char c) { + return c == '.' || Character.isJavaIdentifierPart(c); + } + } + + WordRule wr= new WordRule(new TagDetector(), fTokenStore.getToken(fDefaultTokenProperty)); + for(int i=0; inull
to ensure there
+ * is no association.
+ */
+ public void setCommentOwner(IResource resource, IDocCommentOwner owner) {
+ Assert.isNotNull(resource);
+ if(ResourcesPlugin.getWorkspace().getRoot().equals(resource))
+ throw new IllegalStateException();
+ if(owner!=null) {
+ fMap.put(resource.getProjectRelativePath(), owner.getID());
+ } else {
+ fMap.remove(resource.getProjectRelativePath());
+ }
+ try {
+ save();
+ } catch(CoreException ce) {
+ CUIPlugin.getDefault().log(ce);
+ }
+ }
+
+ public boolean isEmpty() {
+ return fMap.isEmpty();
+ }
+
+ private static Map load(IProject project) throws CoreException {
+ Map result= new HashMap();
+ ICDescriptor pd= CCorePlugin.getDefault().getCProjectDescription(project, true);
+ Element e= pd.getProjectData(ATTRVAL_STORAGEID);
+ if(e.hasChildNodes()) {
+ NodeList commentOwners= e.getElementsByTagName(ELEMENT_DOC_COMMENT_OWNER);
+ for(int i=0; iposition
.
+ *
+ * @param document the document
+ * @param position the offset around which to return the word
+ * @return the word's region, or null
for no selection
+ */
+ private IRegion getWordRegion(IDocument document, int position) {
+ try {
+
+ IRegion line= document.getLineInformationOfOffset(position);
+ if (position == line.getOffset() + line.getLength())
+ return null;
+
+ fDocIter.setDocument(document, line);
+
+ BreakIterator breakIter= BreakIterator.getWordInstance();
+ breakIter.setText(fDocIter);
+
+ int start= breakIter.preceding(position);
+ if (start == BreakIterator.DONE)
+ start= line.getOffset();
+
+ int end= breakIter.following(position);
+ if (end == BreakIterator.DONE)
+ end= line.getOffset() + line.getLength();
+
+ if (breakIter.isBoundary(position)) {
+ if (end - position > position- start)
+ start= position;
+ else
+ end= position;
+ }
+
+ if (start > 0 && isTagMarker(document.getChar(start - 1)) && Character.isJavaIdentifierPart(document.getChar(start))
+ && (start == 1 || Character.isWhitespace(document.getChar(start - 2)) || document.getChar(start - 2) == '{')) {
+ // double click after @ident
+ start--;
+ } else if (end == position && end == start + 1 && end < line.getOffset() + line.getLength() && document.getChar(end) == '@') {
+ // double click before " @ident"
+ return getWordRegion(document, position + 1);
+ }
+
+ if (start == end)
+ return null;
+ return new Region(start, end - start);
+
+ } catch (BadLocationException x) {
+ return null;
+ }
+ }
+
+
+ protected boolean isTagMarker(char c) {
+ for(int i=0; i
+ *
+ * Note that when participants implement this interface, the original method from
+ * {@link IDocumentSetupParticipant} will never be called.
+ *
+ * @see org.eclipse.core.filebuffers.IDocumentSetupParticipant
+ * @since 3.4
+ */
+public interface IDocumentSetupParticipantExtension {
+
+ /**
+ * Sets up the document to be ready for use by a text file buffer.
+ *
+ * @param document the document to be set up
+ * @param location a path of the resource backing the new document. May be null.
+ * @param locationKind the LocationKind of the location specified. May be null.
+ */
+ void setup(IDocument document, IPath location, LocationKind locationKind);
+}
#P org.eclipse.cdt.core.tests
Index: suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java,v
retrieving revision 1.16
diff -u -r1.16 TestSourceReader.java
--- suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java 7 Dec 2007 10:33:25 -0000 1.16
+++ suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java 23 Jan 2008 15:41:47 -0000
@@ -51,6 +51,9 @@
import org.eclipse.core.runtime.Path;
import org.osgi.framework.Bundle;
+/**
+ * Utilities for reading test source code from plug-in .java sources
+ */
public class TestSourceReader {
/**
@@ -85,7 +88,7 @@
List contents = new ArrayList();
StringBuffer content = new StringBuffer();
for(String line = br.readLine(); line!=null; line = br.readLine()) {
- line = line.trim();
+ line = line.replaceFirst("^\\s*", ""); // replace leading whitespace, preserve trailing
if(line.startsWith("//")) {
content.append(line.substring(2)+"\n");
} else {
@@ -113,7 +116,7 @@
* @param lookfor string to be searched for
* @param fullPath full path of the workspace file
* @return the offset or -1
- * @throws CoreException
+ * @throws Exception
* @throws UnsupportedEncodingException
* @since 4.0
*/
#P org.eclipse.cdt.ui.tests
Index: ui/org/eclipse/cdt/ui/tests/text/TextTestSuite.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/TextTestSuite.java,v
retrieving revision 1.17
diff -u -r1.17 TextTestSuite.java
--- ui/org/eclipse/cdt/ui/tests/text/TextTestSuite.java 11 Jan 2008 15:54:42 -0000 1.17
+++ ui/org/eclipse/cdt/ui/tests/text/TextTestSuite.java 23 Jan 2008 15:41:48 -0000
@@ -13,6 +13,8 @@
import junit.framework.TestSuite;
+import org.eclipse.cdt.ui.tests.text.doctools.DocCommentTestSuite;
+
public class TextTestSuite extends TestSuite {
public static TestSuite suite() {
@@ -22,6 +24,9 @@
public TextTestSuite() {
super(TextTestSuite.class.getName());
+ // documentation tool extension tests
+ addTest(DocCommentTestSuite.suite());
+
// partitioning tests
addTest(PartitionTokenScannerTest.suite());
addTest(CPartitionerTest.suite());
Index: ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java,v
retrieving revision 1.15
diff -u -r1.15 CAutoIndentTest.java
--- ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java 15 Jan 2008 13:10:06 -0000 1.15
+++ ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java 23 Jan 2008 15:41:47 -0000
@@ -8,6 +8,7 @@
* Contributors:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
* Sergey Prigogin, Google
+ * Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text;
@@ -16,7 +17,6 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -26,214 +26,22 @@
import org.eclipse.core.runtime.Plugin;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.DocumentCommand;
-import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.TextUtilities;
import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.ICPartitions;
+import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy;
import org.eclipse.cdt.internal.formatter.DefaultCodeFormatterOptions;
import org.eclipse.cdt.internal.ui.text.CAutoIndentStrategy;
-import org.eclipse.cdt.internal.ui.text.CCommentAutoIndentStrategy;
import org.eclipse.cdt.internal.ui.text.CTextTools;
/**
* Testing the auto indent strategies.
*/
-public class CAutoIndentTest extends BaseTestCase {
-
- /**
- * Helper class to test the auto-edit strategies on a document.
- */
- static class AutoEditTester {
-
- private Map fStrategyMap = new HashMap();
- private IDocument fDoc;
- private String fPartitioning;
- private int fCaretOffset;
-
- public AutoEditTester(IDocument doc, String partitioning) {
- super();
- fDoc = doc;
- fPartitioning = partitioning;
- }
-
- public void setAutoEditStrategy(String contentType, IAutoEditStrategy aes) {
- fStrategyMap.put(contentType, aes);
- }
-
- public IAutoEditStrategy getAutoEditStrategy(String contentType) {
- return (IAutoEditStrategy)fStrategyMap.get(contentType);
- }
-
- /**
- * Empties the document, and returns the caret to the origin (0,0)
- */
- public void reset() {
- try {
- goTo(0,0);
- fDoc.set("");
- } catch(BadLocationException ble) {
- fail(ble.getMessage());
- }
- }
-
- public void type(String text) throws BadLocationException {
- for (int i = 0; i < text.length(); ++i) {
- type(text.charAt(i));
- }
- }
-
- public void type(char c) throws BadLocationException {
- TestDocumentCommand command = new TestDocumentCommand(fCaretOffset, 0, new String(new char[] { c }));
- customizeDocumentCommand(command);
- fCaretOffset = command.exec(fDoc);
- }
-
- private void customizeDocumentCommand(TestDocumentCommand command) throws BadLocationException {
- IAutoEditStrategy aes = getAutoEditStrategy(getContentType());
- if (aes != null) {
- aes.customizeDocumentCommand(fDoc, command);
- }
- }
-
- public void type(int offset, String text) throws BadLocationException {
- fCaretOffset = offset;
- type(text);
- }
-
- public void type(int offset, char c) throws BadLocationException {
- fCaretOffset = offset;
- type(c);
- }
-
- public void paste(String text) throws BadLocationException {
- TestDocumentCommand command = new TestDocumentCommand(fCaretOffset, 0, text);
- customizeDocumentCommand(command);
- fCaretOffset = command.exec(fDoc);
- }
-
- public void paste(int offset, String text) throws BadLocationException {
- fCaretOffset = offset;
- paste(text);
- }
-
- public void backspace(int n) throws BadLocationException {
- for (int i = 0; i < n; ++i) {
- backspace();
- }
- }
-
- public void backspace() throws BadLocationException {
- TestDocumentCommand command = new TestDocumentCommand(fCaretOffset - 1, 1, ""); //$NON-NLS-1$
- customizeDocumentCommand(command);
- fCaretOffset = command.exec(fDoc);
- }
-
- public int getCaretOffset() {
- return fCaretOffset;
- }
-
- public int setCaretOffset(int offset) {
- fCaretOffset = offset;
- if (fCaretOffset < 0)
- fCaretOffset = 0;
- else if (fCaretOffset > fDoc.getLength())
- fCaretOffset = fDoc.getLength();
- return fCaretOffset;
- }
-
- /**
- * Moves caret right or left by the given number of characters.
- *
- * @param shift Move distance.
- * @return New caret offset.
- */
- public int moveCaret(int shift) {
- return setCaretOffset(fCaretOffset + shift);
- }
-
- public int goTo(int line) throws BadLocationException {
- fCaretOffset = fDoc.getLineOffset(line);
- return fCaretOffset;
- }
-
- public int goTo(int line, int column) throws BadLocationException {
- if (column < 0 || column > fDoc.getLineLength(line)) {
- throw new BadLocationException("No column " + column + " in line " + line); //$NON-NLS-1$ $NON-NLS-2$
- }
- fCaretOffset = fDoc.getLineOffset(line) + column;
- return fCaretOffset;
- }
-
- public int getCaretLine() throws BadLocationException {
- return fDoc.getLineOfOffset(fCaretOffset);
- }
-
- public int getCaretColumn() throws BadLocationException {
- IRegion region = fDoc.getLineInformationOfOffset(fCaretOffset);
- return fCaretOffset - region.getOffset();
- }
-
- public char getChar() throws BadLocationException {
- return getChar(0);
- }
-
- public char getChar(int i) throws BadLocationException {
- return fDoc.getChar(fCaretOffset+i);
- }
-
- public String getLine() throws BadLocationException {
- return getLine(0);
- }
-
- public String getLine(int i) throws BadLocationException {
- IRegion region = fDoc.getLineInformation(getCaretLine() + i);
- return fDoc.get(region.getOffset(), region.getLength());
- }
-
- public String getContentType() throws BadLocationException {
- return getContentType(0);
- }
-
- public String getContentType(int i) throws BadLocationException {
- return TextUtilities.getContentType(fDoc, fPartitioning, fCaretOffset + i, false);
- }
- }
-
- /**
- * A DocumentCommand with public constructor and exec method.
- */
- static class TestDocumentCommand extends DocumentCommand {
-
- public TestDocumentCommand(int offset, int length, String text) {
- super();
- doit = true;
- this.text = text;
-
- this.offset = offset;
- this.length = length;
-
- owner = null;
- caretOffset = -1;
- }
-
- /**
- * Returns new caret position.
- */
- public int exec(IDocument doc) throws BadLocationException {
- doc.replace(offset, length, text);
- return caretOffset != -1 ?
- caretOffset :
- offset + (text == null ? 0 : text.length());
- }
- }
+public class CAutoIndentTest extends AbstractAutoEditTest {
private HashMap fOptions;
private List fStatusLog;
@@ -289,8 +97,9 @@
IDocument doc = new Document();
textTools.setupCDocument(doc);
AutoEditTester tester = new AutoEditTester(doc, ICPartitions.C_PARTITIONING);
+
tester.setAutoEditStrategy(IDocument.DEFAULT_CONTENT_TYPE, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null));
- tester.setAutoEditStrategy(ICPartitions.C_MULTI_LINE_COMMENT, new CCommentAutoIndentStrategy());
+ tester.setAutoEditStrategy(ICPartitions.C_MULTI_LINE_COMMENT, new DefaultMultilineCommentAutoEditStrategy());
tester.setAutoEditStrategy(ICPartitions.C_PREPROCESSOR, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null));
return tester;
}
@@ -385,7 +194,7 @@
public void testCCommentAutoIndent() throws BadLocationException {
AutoEditTester tester = createAutoEditTester(); //$NON-NLS-1$
tester.type("/*\n"); //$NON-NLS-1$
- assertEquals(ICPartitions.C_MULTI_LINE_COMMENT, tester.getContentType(-1));
+ assertEquals(ICPartitions.C_MULTI_LINE_COMMENT, tester.getContentType(tester.getCaretOffset()-1));
assertEquals(1, tester.getCaretLine());
assertEquals(3, tester.getCaretColumn());
assertEquals(" * ", tester.getLine()); //$NON-NLS-1$
Index: ui/org/eclipse/cdt/ui/tests/text/PartitionTokenScannerTest.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/PartitionTokenScannerTest.java,v
retrieving revision 1.4
diff -u -r1.4 PartitionTokenScannerTest.java
--- ui/org/eclipse/cdt/ui/tests/text/PartitionTokenScannerTest.java 14 Jun 2007 20:10:15 -0000 1.4
+++ ui/org/eclipse/cdt/ui/tests/text/PartitionTokenScannerTest.java 23 Jan 2008 15:41:48 -0000
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 QNX Software Systems and others.
+ * Copyright (c) 2005, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -41,7 +41,7 @@
protected void setUp() {
fReference= new CPartitionScanner();
- fTestee= new FastCPartitionScanner(true);
+ fTestee= new FastCPartitionScanner(true, null);
}
// read sample C file
Index: ui/org/eclipse/cdt/ui/tests/text/CPartitionerTest.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CPartitionerTest.java,v
retrieving revision 1.3
diff -u -r1.3 CPartitionerTest.java
--- ui/org/eclipse/cdt/ui/tests/text/CPartitionerTest.java 21 Jan 2008 13:58:34 -0000 1.3
+++ ui/org/eclipse/cdt/ui/tests/text/CPartitionerTest.java 23 Jan 2008 15:41:47 -0000
@@ -49,7 +49,7 @@
fTextTools= new CTextTools(new PreferenceStore());
fDocument= new Document();
- IDocumentPartitioner partitioner= fTextTools.createDocumentPartitioner();
+ IDocumentPartitioner partitioner= fTextTools.createDocumentPartitioner(null);
partitioner.connect(fDocument);
fDocument.setDocumentPartitioner(partitioner);
fDocument.set("xxx\n/*xxx*/\nxxx\n/**xxx*/\nxxx\n/**/\nxxx\n/***/\nxxx");
Index: ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java,v
retrieving revision 1.12
diff -u -r1.12 CodeFormatterTest.java
--- ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java 7 Jan 2008 16:06:20 -0000 1.12
+++ ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java 23 Jan 2008 15:41:48 -0000
@@ -209,7 +209,7 @@
//int verylooooooooooooooooooooooooooooooooooongname = 0000000000000000000000000000000;
- //int verylooooooooooooooooooooooooooooooooooongname =
+ //int verylooooooooooooooooooooooooooooooooooongname =
// 0000000000000000000000000000000;
public void testLineWrappingOfInitializerExpression_Bug200961() throws Exception {
assertFormatterResult();
Index: plugin.xml
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt/all/org.eclipse.cdt.ui.tests/plugin.xml,v
retrieving revision 1.40
diff -u -r1.40 plugin.xml
--- plugin.xml 25 Oct 2007 14:45:39 -0000 1.40
+++ plugin.xml 23 Jan 2008 15:41:47 -0000
@@ -32,10 +32,10 @@
null
if no declaration should be returned.
+ */
+ protected void assertDeclarationFollowingX(String rs) {
+ try {
+ ICProject cproject= CProjectHelper.createCCProject("test"+System.currentTimeMillis(), "bin");
+ try {
+ String init= getTestContents1()[0].toString();
+ int caretInit= init.indexOf('X');
+ init= init.replaceFirst("X", "");
+ IFile file= TestSourceReader.createFile(cproject.getProject(), "this.cpp", init);
+ IASTTranslationUnit ast= TestSourceReader.createIndexBasedAST(null, cproject, file);
+ assertNotNull(ast);
+ IASTDeclaration decl= DefaultMultilineCommentAutoEditStrategy.findFollowingDeclaration(ast, caretInit);
+ if(rs!=null) {
+ assertNotNull(decl);
+ assertEquals(rs, decl.getRawSignature());
+ } else {
+ assertNull(decl);
+ }
+ } finally {
+ if(cproject!=null) {
+ cproject.getProject().delete(true, NPM);
+ }
+ }
+ } catch(CoreException ce) {
+ fail(ce.getMessage());
+ }
+ }
+
+ protected void assertNewLineBehaviour() {
+ DefaultMultilineCommentAutoEditStrategy ds= new DefaultMultilineCommentAutoEditStrategy();
+ CTextTools textTools = CUIPlugin.getDefault().getTextTools();
+ IDocument doc = new Document();
+ textTools.setupCDocument(doc);
+
+ StringBuffer[] raw= getTestContents();
+ String init= raw[0].toString(), expected= raw[1].toString();
+
+ int caretInit= init.indexOf('X');
+ init= init.replaceFirst("X", "");
+
+ int caretExpected= expected.indexOf('X');
+ expected= expected.replaceFirst("X", "");
+
+ doc.set(init);
+ int caretActual= -1;
+ try {
+ TestDocumentCommand dc= new TestDocumentCommand(caretInit, 0, "\n");
+ ds.customizeDocumentCommand(doc, dc);
+ caretActual= dc.exec(doc);
+ } catch(BadLocationException ble) {
+ fail(ble.getMessage());
+ }
+ String actual= doc.get();
+ assertEquals(expected, actual);
+ assertEquals(caretExpected, caretActual);
+ }
+
+ protected StringBuffer[] getTestContents() {
+ try {
+ return TestSourceReader.getContentsForTest(CTestPlugin.getDefault().getBundle(), "ui", this.getClass(), getName(), 2);
+ } catch(IOException ioe) {
+ fail(ioe.getMessage());
+ }
+ return null;
+ }
+
+ protected StringBuffer[] getTestContents1() {
+ try {
+ return TestSourceReader.getContentsForTest(CTestPlugin.getDefault().getBundle(), "ui", this.getClass(), getName(), 1);
+ } catch(IOException ioe) {
+ fail(ioe.getMessage());
+ }
+ return null;
+ }
+}
Index: resources/docComments/this.cpp
===================================================================
RCS file: resources/docComments/this.cpp
diff -N resources/docComments/this.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ resources/docComments/this.cpp 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,24 @@
+// N.B: Character positions in this file are hard-coded into expected results in
+// DocCommentHightlightTest.
+
+/* normal0 */
+/*A comment1___ */
+/*B comment2__ */
+/*C comment3_ *//*D comment4___ */
+/*E comment5____ *//*F comment6_ */
+/*G comment7
+*//*F comment8_ *//*! __comment9 */
+/**
+comment10
+*/
+
+// snormal0
+//A scomment1__
+//B scomment2_
+//C scomment3__
+//! _scomment4
+//* scomment5___
+
+/*# comment11_ #*/ // scomment6__
+/*# comment12__ #*/ //# __scomment7
+
Index: ui/org/eclipse/cdt/ui/tests/text/AbstractAutoEditTest.java
===================================================================
RCS file: ui/org/eclipse/cdt/ui/tests/text/AbstractAutoEditTest.java
diff -N ui/org/eclipse/cdt/ui/tests/text/AbstractAutoEditTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ui/org/eclipse/cdt/ui/tests/text/AbstractAutoEditTest.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,223 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Anton Leherbauer (Wind River Systems) - initial API and implementation
+ * Sergey Prigogin, Google
+ * Andrew Ferguson (Symbian)
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.text;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.TextUtilities;
+
+import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
+
+/**
+ * IAutoEditStrategy related tests
+ */
+public class AbstractAutoEditTest extends BaseTestCase {
+
+ AbstractAutoEditTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Helper class to test the auto-edit strategies on a document.
+ * Split out from CAutoIndentTest.
+ */
+ static class AutoEditTester {
+
+ private Map fStrategyMap = new HashMap();
+ IDocument fDoc;
+ private String fPartitioning;
+ private int fCaretOffset;
+
+ public AutoEditTester(IDocument doc, String partitioning) {
+ super();
+ fDoc = doc;
+ fPartitioning = partitioning;
+ }
+
+ public void setAutoEditStrategy(String contentType, IAutoEditStrategy aes) {
+ fStrategyMap.put(contentType, aes);
+ }
+
+ public IAutoEditStrategy getAutoEditStrategy(String contentType) {
+ return (IAutoEditStrategy)fStrategyMap.get(contentType);
+ }
+
+ /**
+ * Empties the document, and returns the caret to the origin (0,0)
+ * @return this
for method chaining
+ */
+ public AutoEditTester reset() {
+ try {
+ goTo(0,0);
+ fDoc.set("");
+ } catch(BadLocationException ble) {
+ fail(ble.getMessage());
+ }
+ return this;
+ }
+
+ public void type(String text) throws BadLocationException {
+ for (int i = 0; i < text.length(); ++i) {
+ type(text.charAt(i));
+ }
+ }
+
+ public void type(char c) throws BadLocationException {
+ TestDocumentCommand command = new TestDocumentCommand(fCaretOffset, 0, new String(new char[] { c }));
+ customizeDocumentCommand(command);
+ fCaretOffset = command.exec(fDoc);
+ }
+
+ private void customizeDocumentCommand(TestDocumentCommand command) throws BadLocationException {
+ IAutoEditStrategy aes = getAutoEditStrategy(getContentType(command.offset));
+ if (aes != null) {
+ aes.customizeDocumentCommand(fDoc, command);
+ }
+ }
+
+ public void type(int offset, String text) throws BadLocationException {
+ fCaretOffset = offset;
+ type(text);
+ }
+
+ public void type(int offset, char c) throws BadLocationException {
+ fCaretOffset = offset;
+ type(c);
+ }
+
+ public void paste(String text) throws BadLocationException {
+ TestDocumentCommand command = new TestDocumentCommand(fCaretOffset, 0, text);
+ customizeDocumentCommand(command);
+ fCaretOffset = command.exec(fDoc);
+ }
+
+ public void paste(int offset, String text) throws BadLocationException {
+ fCaretOffset = offset;
+ paste(text);
+ }
+
+ public void backspace(int n) throws BadLocationException {
+ for (int i = 0; i < n; ++i) {
+ backspace();
+ }
+ }
+
+ public void backspace() throws BadLocationException {
+ TestDocumentCommand command = new TestDocumentCommand(fCaretOffset - 1, 1, ""); //$NON-NLS-1$
+ customizeDocumentCommand(command);
+ fCaretOffset = command.exec(fDoc);
+ }
+
+ public int getCaretOffset() {
+ return fCaretOffset;
+ }
+
+ public int setCaretOffset(int offset) {
+ fCaretOffset = offset;
+ if (fCaretOffset < 0)
+ fCaretOffset = 0;
+ else if (fCaretOffset > fDoc.getLength())
+ fCaretOffset = fDoc.getLength();
+ return fCaretOffset;
+ }
+
+ /**
+ * Moves caret right or left by the given number of characters.
+ *
+ * @param shift Move distance.
+ * @return New caret offset.
+ */
+ public int moveCaret(int shift) {
+ return setCaretOffset(fCaretOffset + shift);
+ }
+
+ public int goTo(int line) throws BadLocationException {
+ fCaretOffset = fDoc.getLineOffset(line);
+ return fCaretOffset;
+ }
+
+ public int goTo(int line, int column) throws BadLocationException {
+ if (column < 0 || column > fDoc.getLineLength(line)) {
+ throw new BadLocationException("No column " + column + " in line " + line); //$NON-NLS-1$ $NON-NLS-2$
+ }
+ fCaretOffset = fDoc.getLineOffset(line) + column;
+ return fCaretOffset;
+ }
+
+ public int getCaretLine() throws BadLocationException {
+ return fDoc.getLineOfOffset(fCaretOffset);
+ }
+
+ public int getCaretColumn() throws BadLocationException {
+ IRegion region = fDoc.getLineInformationOfOffset(fCaretOffset);
+ return fCaretOffset - region.getOffset();
+ }
+
+ public char getChar() throws BadLocationException {
+ return getChar(0);
+ }
+
+ public char getChar(int i) throws BadLocationException {
+ return fDoc.getChar(fCaretOffset+i);
+ }
+
+ public String getLine() throws BadLocationException {
+ return getLine(0);
+ }
+
+ public String getLine(int i) throws BadLocationException {
+ IRegion region = fDoc.getLineInformation(getCaretLine() + i);
+ return fDoc.get(region.getOffset(), region.getLength());
+ }
+
+ public String getContentType(int offset) throws BadLocationException {
+ return TextUtilities.getContentType(fDoc, fPartitioning, offset, true);
+ }
+ }
+
+ /**
+ * A DocumentCommand with public constructor and exec method.
+ */
+ static class TestDocumentCommand extends DocumentCommand {
+
+ public TestDocumentCommand(int offset, int length, String text) {
+ super();
+ doit = true;
+ this.text = text;
+
+ this.offset = offset;
+ this.length = length;
+
+ owner = null;
+ caretOffset = -1;
+ }
+
+ /**
+ * @param doc
+ * @return the new caret position.
+ * @throws BadLocationException
+ */
+ public int exec(IDocument doc) throws BadLocationException {
+ doc.replace(offset, length, text);
+ return caretOffset != -1 ?
+ caretOffset :
+ offset + (text == null ? 0 : text.length());
+ }
+ }
+}
Index: ui/org/eclipse/cdt/ui/tests/text/doctools/CommentOwnerManagerTests.java
===================================================================
RCS file: ui/org/eclipse/cdt/ui/tests/text/doctools/CommentOwnerManagerTests.java
diff -N ui/org/eclipse/cdt/ui/tests/text/doctools/CommentOwnerManagerTests.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ui/org/eclipse/cdt/ui/tests/text/doctools/CommentOwnerManagerTests.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Symbian Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andrew Ferguson (Symbian) - Initial implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.text.doctools;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.testplugin.CProjectHelper;
+import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
+import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
+
+import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
+import org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentOwner;
+
+/**
+ * Test comment ownership mapping
+ */
+public class CommentOwnerManagerTests extends BaseTestCase {
+ IDocCommentOwner OWNER_1;
+ IDocCommentOwner OWNER_2;
+ IDocCommentOwner OWNER_3;
+ DocCommentOwnerManager manager;
+
+ ICProject projectA, projectB, projectC;
+
+ protected void setUp() throws Exception {
+ manager= DocCommentOwnerManager.getInstance();
+
+ projectA= CProjectHelper.createCCProject("projectA", null);
+ projectB= CProjectHelper.createCCProject("projectB", null);
+ projectC= CProjectHelper.createCCProject("projectC", null);
+
+ IDocCommentOwner[] owners= manager.getRegisteredOwners();
+ OWNER_1= manager.getOwner("org.cdt.test.DCOM1");
+ OWNER_2= manager.getOwner("org.cdt.test.DCOM2");
+ OWNER_3= manager.getOwner("org.cdt.test.DCOM3");
+ }
+
+ protected void tearDown() throws Exception {
+ if(projectA != null) {
+ CProjectHelper.delete(projectA);
+ }
+ if(projectB != null) {
+ CProjectHelper.delete(projectB);
+ }
+ if(projectC != null) {
+ CProjectHelper.delete(projectC);
+ }
+ }
+
+ public static Test suite() {
+ return new TestSuite(CommentOwnerManagerTests.class);
+ }
+
+ public void testProjectLevel() throws Exception {
+ manager.setCommentOwner(projectA.getProject(), OWNER_3, true);
+ manager.setCommentOwner(projectB.getProject(), OWNER_2, true);
+ manager.setCommentOwner(projectC.getProject(), OWNER_1, true);
+
+ assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectA.getProject()).getID());
+ assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID());
+ assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID());
+
+ assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject()).getID());
+ assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID());
+ assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID());
+
+ assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject()).getID());
+ assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID());
+ assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID());
+
+ manager.setCommentOwner(projectA.getProject(), OWNER_2, true);
+ manager.setCommentOwner(projectB.getProject(), OWNER_1, true);
+ manager.setCommentOwner(projectC.getProject(), OWNER_3, true);
+
+ assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject()).getID());
+ assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID());
+ assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID());
+
+ assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject()).getID());
+ assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID());
+ assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID());
+
+ assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject()).getID());
+ assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID());
+ assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID());
+
+ projectA.getProject().close(NPM);
+ projectB.getProject().close(NPM);
+ projectC.getProject().close(NPM);
+
+ projectA.getProject().open(NPM);
+ projectB.getProject().open(NPM);
+ projectC.getProject().open(NPM);
+
+ assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject()).getID());
+ assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID());
+ assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID());
+
+ assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject()).getID());
+ assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID());
+ assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID());
+
+ assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject()).getID());
+ assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID());
+ assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID());
+ }
+
+ public void testBoundaryConditions() throws Exception {
+ DocCommentOwnerManager manager= DocCommentOwnerManager.getInstance();
+ assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(null).getID());
+ }
+
+ public void testWorkspaceRootLevel() throws Exception {
+ // TODO
+ }
+}