mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-30 21:55:31 +02:00
178386: check-in documentation tool framework plus doxygen implementation
This commit is contained in:
parent
14b1bbaf1e
commit
c113b00476
137 changed files with 6709 additions and 1357 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -51,6 +51,9 @@ import org.eclipse.core.runtime.NullProgressMonitor;
|
|||
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 @@ public class TestSourceReader {
|
|||
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 @@ public class TestSourceReader {
|
|||
* @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
|
||||
*/
|
||||
|
|
|
@ -96,5 +96,5 @@ Require-Bundle: org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
|
|||
org.eclipse.core.filebuffers;bundle-version="[3.2.0,4.0.0)",
|
||||
org.eclipse.core.filesystem;bundle-version="[1.1.0,2.0.0)",
|
||||
org.eclipse.ltk.core.refactoring;bundle-version="3.4.0"
|
||||
Eclipse-LazyStart: true
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2007 QNX Software Systems and others.
|
||||
* Copyright (c) 2000, 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
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core;
|
||||
|
||||
|
@ -15,9 +16,16 @@ import org.eclipse.core.resources.IProject;
|
|||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Models meta-data stored with a CDT project
|
||||
*/
|
||||
public interface ICDescriptor {
|
||||
public ICOwnerInfo getProjectOwner();
|
||||
public String getPlatform();
|
||||
|
||||
/**
|
||||
* @return the associated project
|
||||
*/
|
||||
public IProject getProject();
|
||||
|
||||
public ICExtensionReference[] get(String extensionPoint);
|
||||
|
@ -27,7 +35,18 @@ public interface ICDescriptor {
|
|||
public void remove(ICExtensionReference extension) throws CoreException;
|
||||
public void remove(String extensionPoint) throws CoreException;
|
||||
|
||||
/**
|
||||
* @param id an identifier that uniquely identifies the client
|
||||
* @return a non-null {@link Element} to which client specific meta-data may be attached
|
||||
* @throws CoreException
|
||||
*/
|
||||
public Element getProjectData(String id) throws CoreException;
|
||||
|
||||
/**
|
||||
* Saves any changes made to {@link Element} objects obtained from {@link #getProjectData(String)}
|
||||
* to a CDT defined project meta-data file.
|
||||
* @throws CoreException
|
||||
*/
|
||||
public void saveProjectData() throws CoreException;
|
||||
|
||||
ICConfigurationDescription getConfigurationDescription();
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#Wed Nov 28 11:16:20 CET 2007
|
||||
#Tue Jan 29 13:30:09 GMT 2008
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
|
||||
org.eclipse.jdt.core.compiler.compliance=1.4
|
||||
org.eclipse.jdt.core.compiler.doc.comment.support=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
|
||||
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
|
||||
|
@ -11,6 +12,8 @@ org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=
|
|||
org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
|
||||
org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
|
||||
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.finalParameterBound=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
|
||||
|
@ -19,16 +22,34 @@ org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
|
|||
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
|
||||
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
|
||||
org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public
|
||||
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
|
||||
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingJavadocComments=warning
|
||||
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
|
||||
org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
|
||||
org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning
|
||||
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public
|
||||
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
|
||||
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
|
||||
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.nullReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
|
||||
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
|
||||
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
|
||||
|
@ -41,13 +62,17 @@ org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
|
|||
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLocal=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
||||
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.4
|
||||
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
|
||||
|
|
|
@ -32,10 +32,10 @@
|
|||
<perspectiveExtension
|
||||
targetID="org.eclipse.ui.resourcePerspective">
|
||||
<view
|
||||
id="org.eclipse.cdt.ui.tests.DOMAST.DOMAST"
|
||||
ratio="0.5"
|
||||
relative="org.eclipse.ui.views.TaskList"
|
||||
relationship="right"
|
||||
id="org.eclipse.cdt.ui.tests.DOMAST.DOMAST">
|
||||
relative="org.eclipse.ui.views.TaskList">
|
||||
</view>
|
||||
</perspectiveExtension>
|
||||
</extension>
|
||||
|
@ -115,5 +115,87 @@
|
|||
projectType="org.eclipse.cdt.build.core.buildArtefactType.exe">
|
||||
</template>
|
||||
</extension>
|
||||
|
||||
|
||||
|
||||
<!-- documentation tool comment test owners -->
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.DocCommentOwner">
|
||||
<owner id="org.cdt.test.DCOM1"
|
||||
name="Test comment owner1"
|
||||
singleline="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentViewerConfiguration"
|
||||
multiline="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentViewerConfiguration"
|
||||
/>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.DocCommentOwner">
|
||||
<owner id="org.cdt.test.DCOM2"
|
||||
name="Test comment owner1"
|
||||
singleline="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentViewerConfiguration"
|
||||
multiline="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentViewerConfiguration"
|
||||
/>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.DocCommentOwner">
|
||||
<owner
|
||||
id="org.cdt.test.DCOM3"
|
||||
multiline="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentViewerConfiguration"
|
||||
name="Test comment owner1"
|
||||
singleline="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentViewerConfiguration">
|
||||
</owner>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.DocCommentOwner">
|
||||
<owner
|
||||
id="org.cdt.test.ownerA"
|
||||
multiline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$A"
|
||||
name="name_A"
|
||||
singleline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$A">
|
||||
</owner>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.DocCommentOwner">
|
||||
<owner
|
||||
id="org.cdt.test.ownerB"
|
||||
multiline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$B"
|
||||
name="name_B"
|
||||
singleline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$B">
|
||||
</owner>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.DocCommentOwner">
|
||||
<owner
|
||||
id="org.cdt.test.ownerC"
|
||||
multiline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$C"
|
||||
name="name_C"
|
||||
singleline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$C">
|
||||
</owner>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.DocCommentOwner">
|
||||
<owner
|
||||
id="org.cdt.test.ownerABC"
|
||||
multiline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$ABC"
|
||||
name="name_ABC"
|
||||
singleline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$ABC">
|
||||
</owner>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.DocCommentOwner">
|
||||
<owner
|
||||
id="org.cdt.test.ownerBDFG"
|
||||
multiline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$BDFG"
|
||||
name="name_BDFG"
|
||||
singleline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$BDFG">
|
||||
</owner>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.DocCommentOwner">
|
||||
<owner
|
||||
id="org.cdt.test.ownerPUNC"
|
||||
multiline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$PUNC"
|
||||
name="name_PUNC"
|
||||
singleline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$PUNC">
|
||||
</owner>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
24
core/org.eclipse.cdt.ui.tests/resources/docComments/this.cpp
Normal file
24
core/org.eclipse.cdt.ui.tests/resources/docComments/this.cpp
Normal file
|
@ -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
|
||||
|
|
@ -0,0 +1,244 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* 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.io.IOException;
|
||||
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;
|
||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
|
||||
|
||||
/**
|
||||
* IAutoEditStrategy related tests
|
||||
*/
|
||||
public class AbstractAutoEditTest extends BaseTestCase {
|
||||
|
||||
protected AbstractAutoEditTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class to test the auto-edit strategies on a document.
|
||||
* Split out from CAutoIndentTest.
|
||||
*/
|
||||
protected 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 <code>this</code> 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.
|
||||
*/
|
||||
protected 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());
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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.ArrayList;
|
|||
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.IStatus;
|
|||
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 @@ public class CAutoIndentTest extends BaseTestCase {
|
|||
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 class CAutoIndentTest extends BaseTestCase {
|
|||
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$
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.text;
|
||||
|
||||
|
@ -49,7 +50,7 @@ public class CPartitionerTest extends TestCase {
|
|||
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");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.text;
|
||||
|
||||
|
@ -209,7 +210,7 @@ public class CodeFormatterTest extends BaseUITestCase {
|
|||
|
||||
//int verylooooooooooooooooooooooooooooooooooongname = 0000000000000000000000000000000;
|
||||
|
||||
//int verylooooooooooooooooooooooooooooooooooongname =
|
||||
//int verylooooooooooooooooooooooooooooooooooongname =
|
||||
// 0000000000000000000000000000000;
|
||||
public void testLineWrappingOfInitializerExpression_Bug200961() throws Exception {
|
||||
assertFormatterResult();
|
||||
|
|
|
@ -0,0 +1,609 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* 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 junit.framework.Test;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.Document;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||
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.ui.text.CAutoIndentStrategy;
|
||||
import org.eclipse.cdt.internal.ui.text.CTextTools;
|
||||
|
||||
|
||||
/**
|
||||
* Testing the auto indent strategies.
|
||||
*/
|
||||
public class DefaultCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
|
||||
private HashMap fOptions;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public DefaultCCommentAutoEditStrategyTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return suite(DefaultCCommentAutoEditStrategyTest.class);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.testplugin.util.BaseTestCase#setUp()
|
||||
*/
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
fOptions= CCorePlugin.getOptions();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see junit.framework.TestCase#tearDown()
|
||||
*/
|
||||
protected void tearDown() throws Exception {
|
||||
CCorePlugin.setOptions(fOptions);
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
private AutoEditTester createAutoEditTester() {
|
||||
CTextTools textTools = CUIPlugin.getDefault().getTextTools();
|
||||
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 DefaultMultilineCommentAutoEditStrategy());
|
||||
tester.setAutoEditStrategy(ICPartitions.C_PREPROCESSOR, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null));
|
||||
return tester;
|
||||
}
|
||||
|
||||
public void testIsMultilineNew() throws BadLocationException {
|
||||
DefaultMultilineCommentAutoEditStrategy ds= new DefaultMultilineCommentAutoEditStrategy();
|
||||
CTextTools textTools = CUIPlugin.getDefault().getTextTools();
|
||||
IDocument doc = new Document();
|
||||
textTools.setupCDocument(doc);
|
||||
|
||||
doc.set(" /* ");
|
||||
assertTrue(ds.shouldCloseMultiline(doc, 3));
|
||||
doc.set(" /* \n");
|
||||
assertTrue(ds.shouldCloseMultiline(doc, 3));
|
||||
assertTrue(ds.shouldCloseMultiline(doc, 5));
|
||||
doc.set(" /* \n ");
|
||||
assertTrue(ds.shouldCloseMultiline(doc, 3));
|
||||
assertTrue(ds.shouldCloseMultiline(doc, 6));
|
||||
doc.set(" /* */");
|
||||
assertFalse(ds.shouldCloseMultiline(doc, 5));
|
||||
doc.set(" /* */ ");
|
||||
assertFalse(ds.shouldCloseMultiline(doc, 5));
|
||||
doc.set(" /* \n\n */ ");
|
||||
assertFalse(ds.shouldCloseMultiline(doc, 5));
|
||||
doc.set(" /* \n\n */ \n /*");
|
||||
assertTrue(ds.shouldCloseMultiline(doc, 14));
|
||||
doc.set(" /* \n\n */ \n /* ");
|
||||
assertTrue(ds.shouldCloseMultiline(doc, 14));
|
||||
doc.set(" /* \n\n */ \n /* \n");
|
||||
assertTrue(ds.shouldCloseMultiline(doc, 14));
|
||||
doc.set(" /* /* \n\n */ \n /* \n");
|
||||
assertTrue(ds.shouldCloseMultiline(doc, 3));
|
||||
doc.set(" /* \n/* \n\n */ \n /* \n");
|
||||
assertTrue(ds.shouldCloseMultiline(doc, 3));
|
||||
doc.set(" /* \n\n/* \n\n */ \n /* \n");
|
||||
assertTrue(ds.shouldCloseMultiline(doc, 3));
|
||||
doc.set(" /* \n\n/* \n\n */ \n /* \n");
|
||||
assertTrue(ds.shouldCloseMultiline(doc, 3));
|
||||
doc.set(" /* \n\n */ /* \n\n */ \n /* \n");
|
||||
assertFalse(ds.shouldCloseMultiline(doc, 3));
|
||||
doc.set(" /*\n /*\n * \n * \n */\n");
|
||||
assertFalse(ds.shouldCloseMultiline(doc, 8));
|
||||
}
|
||||
|
||||
// /*X
|
||||
|
||||
// /*
|
||||
// * X
|
||||
// */
|
||||
public void testInsertNewLine1() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
// /*X
|
||||
|
||||
// /*
|
||||
// * X
|
||||
// */
|
||||
public void testInsertNewLine2() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
// class A {}; /*X
|
||||
|
||||
// class A {}; /*
|
||||
// X
|
||||
public void testInsertNewLine3() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
// class A {
|
||||
// /*X
|
||||
// };
|
||||
|
||||
// class A {
|
||||
// /*
|
||||
// * X
|
||||
// */
|
||||
// };
|
||||
public void testInsertNewLine4() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
// class A {
|
||||
// /* X
|
||||
// };
|
||||
|
||||
// class A {
|
||||
// /*
|
||||
// * X
|
||||
// */
|
||||
// };
|
||||
public void testInsertNewLine5() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// class A {
|
||||
// /*X
|
||||
// *
|
||||
// */
|
||||
// };
|
||||
|
||||
// class A {
|
||||
// /*
|
||||
// * X
|
||||
// *
|
||||
// */
|
||||
// };
|
||||
public void testInsertNewLine6() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
// class A {
|
||||
// /*
|
||||
// *X
|
||||
// */
|
||||
// };
|
||||
|
||||
// class A {
|
||||
// /*
|
||||
// *
|
||||
// *X
|
||||
// */
|
||||
// };
|
||||
public void testInsertNewLine7() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
// class A {
|
||||
// /*
|
||||
// *X
|
||||
// */
|
||||
// };
|
||||
|
||||
// class A {
|
||||
// /*
|
||||
// *
|
||||
// *X
|
||||
// */
|
||||
// };
|
||||
public void testInsertNewLine8() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
// class A {
|
||||
// /*
|
||||
// * abcd def ghiX
|
||||
// */
|
||||
// };
|
||||
|
||||
// class A {
|
||||
// /*
|
||||
// * abcd def ghi
|
||||
// * X
|
||||
// */
|
||||
// };
|
||||
public void testInsertNewLine9() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
// class A {
|
||||
// /*
|
||||
// * abcd deXf ghi
|
||||
// */
|
||||
// };
|
||||
|
||||
// class A {
|
||||
// /*
|
||||
// * abcd de
|
||||
// * Xf ghi
|
||||
// */
|
||||
// };
|
||||
public void testInsertNewLine10() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
// class A {
|
||||
// /*
|
||||
// *
|
||||
// */X
|
||||
// };
|
||||
|
||||
// class A {
|
||||
// /*
|
||||
// *
|
||||
// */
|
||||
// X
|
||||
// };
|
||||
public void _testInsertNewLine11() { // this is correct - we're not in a dccaes partition
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
// /*X*/
|
||||
|
||||
// /*
|
||||
// * X
|
||||
// */
|
||||
public void _testInsertNewLine12() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
// class A {
|
||||
// /*Xfoo
|
||||
// };
|
||||
|
||||
// class A {
|
||||
// /*
|
||||
// * X
|
||||
// */foo
|
||||
// };
|
||||
public void testInsertNewLine13() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
// class A {
|
||||
// /*fooX
|
||||
// };
|
||||
|
||||
// class A {
|
||||
// /*foo
|
||||
// * X
|
||||
// */
|
||||
// };
|
||||
public void testInsertNewLine14() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
|
||||
// /*
|
||||
// *
|
||||
// *X
|
||||
|
||||
// /*
|
||||
// *
|
||||
// *
|
||||
// *X
|
||||
public void testInsertNewLine15() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
// /*
|
||||
// *
|
||||
// *Xxx
|
||||
|
||||
// /*
|
||||
// *
|
||||
// *
|
||||
// *Xxx
|
||||
public void testInsertNewLine16() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
// /*
|
||||
// X
|
||||
|
||||
// /*
|
||||
//
|
||||
// X
|
||||
public void testInsertNewLine17() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
// /*
|
||||
// X
|
||||
// */
|
||||
|
||||
// /*
|
||||
//
|
||||
// X
|
||||
// */
|
||||
public void testInsertNewLine18() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
// /*
|
||||
// *
|
||||
// */ /*X
|
||||
|
||||
// /*
|
||||
// *
|
||||
// */ /*
|
||||
// * X
|
||||
// */
|
||||
public void _testInsertNewLine19() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
// /*
|
||||
// /*X
|
||||
// *
|
||||
// */
|
||||
|
||||
// /*
|
||||
// /*
|
||||
// * X
|
||||
// *
|
||||
// */
|
||||
public void testInsertNewLine20() {
|
||||
assertNewLineBehaviour();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// X
|
||||
//
|
||||
// void foo() {}
|
||||
public void testFollowingDeclaration1() {
|
||||
assertDeclarationFollowingX("void foo() {}");
|
||||
}
|
||||
|
||||
// X
|
||||
//
|
||||
// void foo() {}
|
||||
// void bar() {}
|
||||
public void testFollowingDeclaration1b() {
|
||||
assertDeclarationFollowingX("void foo() {}");
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// X
|
||||
// class C {
|
||||
// void foo() {}
|
||||
// };
|
||||
public void testFollowingDeclaration2() {
|
||||
assertDeclarationFollowingX("class C {\n void foo() {}\n };");
|
||||
}
|
||||
|
||||
// class C {
|
||||
// X
|
||||
// void foo() {}
|
||||
// };
|
||||
public void testFollowingDeclaration3() {
|
||||
assertDeclarationFollowingX("void foo() {}");
|
||||
}
|
||||
|
||||
// class C {
|
||||
// void foo() {X}
|
||||
// void bar(int x);
|
||||
// };
|
||||
public void testFollowingDeclaration4() {
|
||||
assertDeclarationFollowingX(null);
|
||||
}
|
||||
|
||||
// class C {
|
||||
// void foo() {} X
|
||||
// void bar(int x);
|
||||
// };
|
||||
public void testFollowingDeclaration4a() {
|
||||
assertDeclarationFollowingX("void bar(int x);");
|
||||
}
|
||||
|
||||
// class C {
|
||||
// void foo()X{}
|
||||
// void bar(int x);
|
||||
// };
|
||||
public void _testFollowingDeclaration4b() { // XXX - this is likely invalid anyhow
|
||||
assertDeclarationFollowingX("void foo(){}"); // (X is just the cursor position)
|
||||
}
|
||||
|
||||
// class C {
|
||||
// void foo()
|
||||
// X
|
||||
// {
|
||||
// int x;
|
||||
// }
|
||||
// void bar(int x);
|
||||
// };
|
||||
public void _testFollowingDeclaration4c() { // XXX - this is likely invalid anyhow
|
||||
assertDeclarationFollowingX("void foo()\n {\n int x;\n }\n"); // (X is just the cursor position)
|
||||
}
|
||||
|
||||
// namespace n1 { X
|
||||
// namespace n2 {
|
||||
// void foo() {}
|
||||
// void bar(int x) {}
|
||||
// class C {
|
||||
// int y;
|
||||
// void baz(int x) {}
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
public void _testFollowingDeclaration5() {
|
||||
assertDeclarationFollowingX("namespace n2 {\n void foo() {}\n void bar(int x) {}\n class C {\n int y;\n void baz(int x) {}\n };\n }");
|
||||
}
|
||||
|
||||
// namespace n1 {
|
||||
// namespace n2 {X
|
||||
// void foo() {}
|
||||
// void bar(int x) {}
|
||||
// class C {
|
||||
// int y;
|
||||
// void baz(int x) {}
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
public void testFollowingDeclaration6() {
|
||||
assertDeclarationFollowingX("void foo() {}");
|
||||
}
|
||||
|
||||
// namespace n1 {
|
||||
// namespace n2 {
|
||||
// void foo() {}X
|
||||
// void bar(int x) {}
|
||||
// class C {
|
||||
// int y;
|
||||
// void baz(int x) {}
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
public void testFollowingDeclaration7() {
|
||||
assertDeclarationFollowingX("void bar(int x) {}");
|
||||
}
|
||||
|
||||
// namespace n1 {
|
||||
// namespace n2 {
|
||||
// void foo() {}
|
||||
// void bar(int x) {}
|
||||
// class C {X
|
||||
// int y;
|
||||
// void baz(int x) {}
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
public void testFollowingDeclaration8() {
|
||||
assertDeclarationFollowingX("int y;");
|
||||
}
|
||||
|
||||
// namespace n1 {
|
||||
// namespace n2 {
|
||||
// void foo() {}
|
||||
// void bar(int x) {}
|
||||
// class C {
|
||||
// int y;X
|
||||
// void baz(int x) {}
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
public void testFollowingDeclaration9() {
|
||||
assertDeclarationFollowingX("void baz(int x) {}");
|
||||
}
|
||||
|
||||
// #define MM void foo()
|
||||
// X
|
||||
// MM {}
|
||||
public void testFollowingDeclaration10() {
|
||||
assertDeclarationFollowingX("MM {}");
|
||||
}
|
||||
|
||||
// #define NAME foo
|
||||
// #define MM(V) void V(int y)
|
||||
// X
|
||||
// MM(NAME) {}
|
||||
public void testFollowingDeclaration11() {
|
||||
assertDeclarationFollowingX("MM(NAME) {}");
|
||||
}
|
||||
|
||||
// #define MAKEFUNC(V) void V()
|
||||
// #define B(V) V
|
||||
// #define C(V) foo ## x
|
||||
// X
|
||||
// MAKEFUNC(B(C(y))) {}
|
||||
public void testFollowingDeclaration12() {
|
||||
assertDeclarationFollowingX("MAKEFUNC(B(C(y))) {}");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rs - the raw signature of the declaration that should be returned
|
||||
* or <code>null</code> 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);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.text;
|
||||
|
||||
|
@ -41,7 +42,7 @@ public class PartitionTokenScannerTest extends TestCase {
|
|||
|
||||
protected void setUp() {
|
||||
fReference= new CPartitionScanner();
|
||||
fTestee= new FastCPartitionScanner(true);
|
||||
fTestee= new FastCPartitionScanner(true, null);
|
||||
}
|
||||
|
||||
// read sample C file
|
||||
|
|
|
@ -7,12 +7,15 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.ui.tests.text;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.ui.tests.text.doctools.DocCommentTestSuite;
|
||||
|
||||
public class TextTestSuite extends TestSuite {
|
||||
|
||||
public static TestSuite suite() {
|
||||
|
@ -22,6 +25,9 @@ public class TextTestSuite extends TestSuite {
|
|||
public TextTestSuite() {
|
||||
super(TextTestSuite.class.getName());
|
||||
|
||||
// documentation tool extension tests
|
||||
addTest(DocCommentTestSuite.suite());
|
||||
|
||||
// partitioning tests
|
||||
addTest(PartitionTokenScannerTest.suite());
|
||||
addTest(CPartitionerTest.suite());
|
||||
|
|
|
@ -0,0 +1,265 @@
|
|||
/*******************************************************************************
|
||||
* 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 testBoundaryConditions1() throws Exception {
|
||||
DocCommentOwnerManager manager= DocCommentOwnerManager.getInstance();
|
||||
assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(null).getID());
|
||||
}
|
||||
|
||||
public void testBoundaryConditions2() throws Exception {
|
||||
try {
|
||||
manager.setWorkspaceCommentOwner(null);
|
||||
fail();
|
||||
} catch(Exception e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testWorkspaceRootLevel() throws Exception {
|
||||
manager.setCommentOwner(projectA.getProject(), null, true);
|
||||
manager.setCommentOwner(projectB.getProject(), null, true);
|
||||
manager.setCommentOwner(projectC.getProject(), null, true);
|
||||
|
||||
manager.setWorkspaceCommentOwner(OWNER_1);
|
||||
|
||||
assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectA.getProject()).getID());
|
||||
assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID());
|
||||
assertEquals(OWNER_1.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_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.setWorkspaceCommentOwner(OWNER_2);
|
||||
|
||||
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_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_2.getID(), manager.getCommentOwner(projectC.getProject()).getID());
|
||||
assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID());
|
||||
assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID());
|
||||
|
||||
manager.setWorkspaceCommentOwner(OWNER_3);
|
||||
|
||||
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_3.getID(), manager.getCommentOwner(projectB.getProject()).getID());
|
||||
assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID());
|
||||
assertEquals(OWNER_3.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());
|
||||
|
||||
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.setWorkspaceCommentOwner(NullDocCommentOwner.INSTANCE);
|
||||
|
||||
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(), null, true);
|
||||
|
||||
assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectA.getProject()).getID());
|
||||
assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID());
|
||||
assertEquals(NullDocCommentOwner.INSTANCE.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(projectC.getProject(), null, true);
|
||||
|
||||
assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectA.getProject()).getID());
|
||||
assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID());
|
||||
assertEquals(NullDocCommentOwner.INSTANCE.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(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectC.getProject()).getID());
|
||||
assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID());
|
||||
assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID());
|
||||
|
||||
manager.setCommentOwner(projectB.getProject(), null, true);
|
||||
|
||||
assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectA.getProject()).getID());
|
||||
assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID());
|
||||
assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID());
|
||||
|
||||
assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectB.getProject()).getID());
|
||||
assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID());
|
||||
assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID());
|
||||
|
||||
assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectC.getProject()).getID());
|
||||
assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID());
|
||||
assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID());
|
||||
|
||||
manager.setWorkspaceCommentOwner(OWNER_1);
|
||||
|
||||
assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectA.getProject()).getID());
|
||||
assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID());
|
||||
assertEquals(OWNER_1.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_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());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,187 @@
|
|||
/*******************************************************************************
|
||||
* 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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.Position;
|
||||
import org.eclipse.jface.text.TextViewer;
|
||||
import org.eclipse.jface.text.source.ISourceViewer;
|
||||
import org.eclipse.jface.text.source.SourceViewer;
|
||||
import org.eclipse.swt.custom.StyleRange;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IEditorReference;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
||||
import org.eclipse.cdt.ui.tests.text.Accessor;
|
||||
import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
|
||||
import org.eclipse.cdt.ui.tests.text.ResourceTestHelper;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class DocCommentHighlightingTest extends BaseUITestCase {
|
||||
private static final DocCommentOwnerManager DCMAN= DocCommentOwnerManager.getInstance();
|
||||
private static final String LINKED_FOLDER= "resources/docComments";
|
||||
private static final String PROJECT= "DocCommentTests";
|
||||
|
||||
// ordered by occurrence
|
||||
private static final int[] normal0= {114, 13};
|
||||
private static final int[] comment1= {129, 18};
|
||||
private static final int[] comment2= {149, 17};
|
||||
private static final int[] comment3= {168, 16};
|
||||
private static final int[] comment4= {184, 18};
|
||||
private static final int[] comment5= {204, 19};
|
||||
private static final int[] comment6= {223, 16};
|
||||
private static final int[] comment7= {241, 17};
|
||||
private static final int[] comment8= {258, 16};
|
||||
private static final int[] comment9= {274, 17};
|
||||
private static final int[] comment10= {293, 18};
|
||||
private static final int[] snormal0= {315, 13};
|
||||
private static final int[] scomment1= {328, 17};
|
||||
private static final int[] scomment2= {345, 16};
|
||||
private static final int[] scomment3= {361, 17};
|
||||
private static final int[] scomment4= {378, 16};
|
||||
private static final int[] scomment5= {394, 18};
|
||||
private static final int[] comment11= {414, 18};
|
||||
private static final int[] scomment6= {433, 16};
|
||||
private static final int[] comment12= {449, 19};
|
||||
private static final int[] scomment7= {469, 17};
|
||||
|
||||
|
||||
private ICProject fCProject;
|
||||
private final String fTestFilename= "/"+PROJECT+"/src/this.cpp";
|
||||
|
||||
private static SourceViewer fSourceViewer;
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(DocCommentHighlightingTest.class);
|
||||
}
|
||||
|
||||
public DocCommentHighlightingTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
fCProject= EditorTestHelper.createCProject(PROJECT, LINKED_FOLDER);
|
||||
|
||||
AbstractTextEditor fEditor= (CEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(fTestFilename), true);
|
||||
fSourceViewer= EditorTestHelper.getSourceViewer(fEditor);
|
||||
assertTrue(EditorTestHelper.joinReconciler(fSourceViewer, 0, 10000, 100));
|
||||
}
|
||||
|
||||
protected void tearDown () throws Exception {
|
||||
EditorTestHelper.closeAllEditors();
|
||||
|
||||
if (fCProject != null)
|
||||
CProjectHelper.delete(fCProject);
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected List/*<Position>*/ findRangesColored(RGB rgb) {
|
||||
List result= new ArrayList();
|
||||
IEditorPart p= get();
|
||||
ISourceViewer vw= ((CEditor)p).getViewer();
|
||||
Accessor a= new Accessor(vw, TextViewer.class);
|
||||
StyledText st= (StyledText) a.get("fTextWidget");
|
||||
StyleRange[] rgs= st.getStyleRanges();
|
||||
for(int i=0; i<rgs.length; i++) {
|
||||
if(rgs[i].foreground != null && rgs[i].foreground.getRGB().equals(rgb)) {
|
||||
result.add(new Position(rgs[i].start, rgs[i].length));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected IEditorPart get(){
|
||||
IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
||||
if(window!=null) {
|
||||
if(window.getActivePage()!=null) {
|
||||
IEditorReference[] es= window.getActivePage().getEditorReferences();
|
||||
for(int i=0; i<es.length; i++) {
|
||||
IEditorPart part= es[i].getEditor(false);
|
||||
if(part != null)
|
||||
return part;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List/*<Position>*/ mkPositions(int[][] raw) {
|
||||
List result= new ArrayList();
|
||||
for(int i=0; i<raw.length; i++) {
|
||||
Assert.assertEquals(2, raw[i].length);
|
||||
result.add(new Position(raw[i][0], raw[i][1]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void testDCOM_A() throws BadLocationException, InterruptedException {
|
||||
DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerA"), true);
|
||||
runEventQueue(1000);
|
||||
List/*<Position>*/ expected= mkPositions(new int[][] {comment1, scomment1});
|
||||
assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB));
|
||||
}
|
||||
|
||||
public void testDCOM_B() throws BadLocationException, InterruptedException {
|
||||
DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerB"), true);
|
||||
runEventQueue(1000);
|
||||
List/*<Position>*/ expected= mkPositions(new int[][] {comment2, scomment2});
|
||||
assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB));
|
||||
}
|
||||
|
||||
public void testDCOM_C() throws BadLocationException, InterruptedException {
|
||||
DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerC"), true);
|
||||
runEventQueue(1000);
|
||||
List/*<Position>*/ expected= mkPositions(new int[][] {comment3, scomment3});
|
||||
assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB));
|
||||
}
|
||||
|
||||
public void testDCOM_ABC() throws BadLocationException, InterruptedException {
|
||||
DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerABC"), true);
|
||||
runEventQueue(1000);
|
||||
List/*<Position>*/ expected= mkPositions(new int[][] {comment1, comment2, comment3, scomment1, scomment2, scomment3});
|
||||
assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB));
|
||||
}
|
||||
|
||||
public void testDCOM_BDFG() throws BadLocationException, InterruptedException {
|
||||
DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerBDFG"), true);
|
||||
runEventQueue(1000);
|
||||
List/*<Position>*/ expected= mkPositions(new int[][] {comment2, comment4, comment6, comment7, comment8, scomment2});
|
||||
assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB));
|
||||
}
|
||||
|
||||
public void testDCOM_PUNC() throws BadLocationException, InterruptedException {
|
||||
DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerPUNC"), true);
|
||||
runEventQueue(1000);
|
||||
List/*<Position>*/ expected= mkPositions(new int[][] {comment9, comment10, scomment4, scomment5, comment11, comment12, scomment7});
|
||||
assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*******************************************************************************
|
||||
* 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 org.eclipse.cdt.ui.tests.text.doctools.doxygen.DoxygenCCommentAutoEditStrategyTest;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
public class DocCommentTestSuite extends TestSuite {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new DocCommentTestSuite();
|
||||
}
|
||||
|
||||
public DocCommentTestSuite() {
|
||||
super(DocCommentTestSuite.class.getName());
|
||||
|
||||
addTest(CommentOwnerManagerTests.suite());
|
||||
addTest(DocCommentHighlightingTest.suite());
|
||||
addTest(DoxygenCCommentAutoEditStrategyTest.suite());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/*******************************************************************************
|
||||
* 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 org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.preference.PreferenceConverter;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IAutoEditStrategy;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
|
||||
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 TestGenericTagConfiguration extends AbstractGenericTagDocCommentViewerConfiguration {
|
||||
public static final RGB DEFAULTRGB= new RGB(63, 95, 191);
|
||||
|
||||
protected char[] fCommentMarkers;
|
||||
|
||||
public TestGenericTagConfiguration(String commentMarkers, String tags, String tagMarkers, String defaultToken, String tagToken) {
|
||||
super(mkTags(tags.split("(\\s)*,(\\s)*")), tagMarkers.toCharArray(), defaultToken, tagToken);
|
||||
IPreferenceStore cuis= CUIPlugin.getDefault().getPreferenceStore();
|
||||
PreferenceConverter.setDefault(cuis, defaultToken, DEFAULTRGB);
|
||||
PreferenceConverter.setDefault(cuis, tagToken, new RGB(127, 159, 191));
|
||||
fCommentMarkers= commentMarkers.toCharArray();
|
||||
}
|
||||
|
||||
public IAutoEditStrategy createAutoEditStrategy() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static GenericDocTag[] mkTags(String[] tagNames) {
|
||||
GenericDocTag[] tags= new GenericDocTag[tagNames.length];
|
||||
for(int i=0; i<tagNames.length; i++) {
|
||||
tags[i]= new GenericDocTag(tagNames[i], "no description");
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
public boolean isDocumentationComment(IDocument doc, int offset, int length) {
|
||||
try {
|
||||
if(offset+2 < doc.getLength()) {
|
||||
char c= doc.getChar(offset+2);
|
||||
for(int i=0; i<fCommentMarkers.length; i++)
|
||||
if(c == fCommentMarkers[i])
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
} catch(BadLocationException ble) {
|
||||
CUIPlugin.getDefault().log(ble);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class A extends TestGenericTagConfiguration {
|
||||
public A() {super("A", "", "@", "test.token.A.default", "test.token.A.tag");}
|
||||
}
|
||||
|
||||
public static class B extends TestGenericTagConfiguration {
|
||||
public B() {super("B", "", "@", "test.token.B.default", "test.token.B.tag");}
|
||||
}
|
||||
|
||||
public static class C extends TestGenericTagConfiguration {
|
||||
public C() {super("C", "", "@", "test.token.C.default", "test.token.C.tag");}
|
||||
}
|
||||
|
||||
public static class ABC extends TestGenericTagConfiguration {
|
||||
public ABC() {super("ABC", "", "@", "test.token.ABC.default", "test.token.ABC.tag");}
|
||||
}
|
||||
|
||||
public static class BDFG extends TestGenericTagConfiguration {
|
||||
public BDFG() {super("BDFG", "", "@", "test.token.BDFG.default", "test.token.BDFG.tag");}
|
||||
}
|
||||
|
||||
public static class PUNC extends TestGenericTagConfiguration {
|
||||
public PUNC() {super("!*#", "", "@", "test.token.BDFG.default", "test.token.BDFG.tag");}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,378 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* 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.doctools.doxygen;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.Document;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.tests.text.DefaultCCommentAutoEditStrategyTest;
|
||||
import org.eclipse.cdt.ui.text.ICPartitions;
|
||||
import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy;
|
||||
import org.eclipse.cdt.ui.text.doctools.doxygen.DoxygenMultilineAutoEditStrategy;
|
||||
|
||||
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.CAutoIndentStrategy;
|
||||
import org.eclipse.cdt.internal.ui.text.CTextTools;
|
||||
|
||||
|
||||
/**
|
||||
* Testing the auto indent strategies.
|
||||
*/
|
||||
public class DoxygenCCommentAutoEditStrategyTest extends DefaultCCommentAutoEditStrategyTest {
|
||||
private HashMap fOptions;
|
||||
protected ICProject fCProject;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public DoxygenCCommentAutoEditStrategyTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return suite(DoxygenCCommentAutoEditStrategyTest.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
fCProject= CProjectHelper.createCCProject("test"+System.currentTimeMillis(), null);
|
||||
fOptions= CCorePlugin.getOptions();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see junit.framework.TestCase#tearDown()
|
||||
*/
|
||||
protected void tearDown() throws Exception {
|
||||
CProjectHelper.delete(fCProject);
|
||||
CCorePlugin.setOptions(fOptions);
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
private AutoEditTester createAutoEditTester() {
|
||||
CTextTools textTools = CUIPlugin.getDefault().getTextTools();
|
||||
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 DefaultMultilineCommentAutoEditStrategy());
|
||||
tester.setAutoEditStrategy(ICPartitions.C_PREPROCESSOR, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null));
|
||||
return tester;
|
||||
}
|
||||
|
||||
// /**X
|
||||
// void foo() {}
|
||||
|
||||
// /**
|
||||
// * X
|
||||
// */
|
||||
// void foo() {}
|
||||
public void testAutoDocCommentContent1() throws CoreException {
|
||||
assertAutoEditBehaviour();
|
||||
}
|
||||
|
||||
// /** X
|
||||
// void foo() {}
|
||||
|
||||
// /**
|
||||
// * X
|
||||
// */
|
||||
// void foo() {}
|
||||
public void testAutoDocCommentContent2() throws CoreException {
|
||||
assertAutoEditBehaviour();
|
||||
}
|
||||
|
||||
// /**X
|
||||
// int foo_bar() {}
|
||||
|
||||
// /**
|
||||
// * X
|
||||
// * @return
|
||||
// */
|
||||
// int foo_bar() {}
|
||||
public void testAutoDocCommentContent3() throws CoreException {
|
||||
assertAutoEditBehaviour();
|
||||
}
|
||||
|
||||
// /** X
|
||||
// int foo_bar() {}
|
||||
|
||||
// /**
|
||||
// * X
|
||||
// * @return
|
||||
// */
|
||||
// int foo_bar() {}
|
||||
public void testAutoDocCommentContent4() throws CoreException {
|
||||
assertAutoEditBehaviour();
|
||||
}
|
||||
|
||||
// /**X
|
||||
// *
|
||||
// */
|
||||
// int foo_bar() {}
|
||||
|
||||
// /**
|
||||
// * X
|
||||
// *
|
||||
// */
|
||||
// int foo_bar() {}
|
||||
public void testAutoDocCommentContent5() throws CoreException {
|
||||
assertAutoEditBehaviour();
|
||||
}
|
||||
|
||||
// /**X
|
||||
// void foo_bar(int x) {}
|
||||
|
||||
// /**
|
||||
// * X
|
||||
// * @param x
|
||||
// */
|
||||
// void foo_bar(int x) {}
|
||||
public void testAutoDocCommentContent6() throws CoreException {
|
||||
assertAutoEditBehaviour();
|
||||
}
|
||||
|
||||
// class A {}; class B {};
|
||||
// /**X
|
||||
// C* bar_baz(A a, B b, int c) {}
|
||||
|
||||
// class A {}; class B {};
|
||||
// /**
|
||||
// * X
|
||||
// * @param a
|
||||
// * @param b
|
||||
// * @param c
|
||||
// * @return
|
||||
// */
|
||||
// C* bar_baz(A a, B b, int c) {}
|
||||
public void testAutoDocCommentContent7() throws CoreException {
|
||||
assertAutoEditBehaviour();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * namespace
|
||||
// */
|
||||
// namespace NS {
|
||||
// class A {
|
||||
// private:
|
||||
// /*
|
||||
// * TODO
|
||||
// */
|
||||
// /*!
|
||||
// * class
|
||||
// */
|
||||
// class B {
|
||||
// public:
|
||||
// /**
|
||||
// *
|
||||
// */
|
||||
// void foo() {}
|
||||
// /*!X
|
||||
// A bar(A as[], B bs[]) {}
|
||||
// };
|
||||
// };
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * namespace
|
||||
// */
|
||||
// namespace NS {
|
||||
// class A {
|
||||
// private:
|
||||
// /*
|
||||
// * TODO
|
||||
// */
|
||||
// /*!
|
||||
// * class
|
||||
// */
|
||||
// class B {
|
||||
// public:
|
||||
// /**
|
||||
// *
|
||||
// */
|
||||
// void foo() {}
|
||||
// /*!
|
||||
// * X
|
||||
// * @param as
|
||||
// * @param bs
|
||||
// * @return
|
||||
// */
|
||||
// A bar(A as[], B bs[]) {}
|
||||
// };
|
||||
// };
|
||||
// }
|
||||
public void testAutoDocCommentContent8() throws CoreException {
|
||||
assertAutoEditBehaviour();
|
||||
}
|
||||
|
||||
// void foo_bar(int x)
|
||||
// /**X
|
||||
// {}
|
||||
|
||||
// void foo_bar(int x)
|
||||
// /**
|
||||
// * X
|
||||
// * @param x
|
||||
// */
|
||||
// {}
|
||||
public void _testAutoDocCommentContent9() throws CoreException {
|
||||
assertAutoEditBehaviour();
|
||||
// TODO - desired behaviour when there is a comment preceding the declaration
|
||||
// needs defining
|
||||
}
|
||||
|
||||
// void foo_bar(int x)
|
||||
// {
|
||||
// /**X
|
||||
// }
|
||||
|
||||
// void foo_bar(int x)
|
||||
// {
|
||||
// /**
|
||||
// * X
|
||||
// * @param x
|
||||
// */
|
||||
// }
|
||||
public void _testAutoDocCommentContent10() throws CoreException {
|
||||
assertAutoEditBehaviour();
|
||||
// TODO - desired behaviour when there is a comment preceding the declaration
|
||||
// or when there is a comment after the signature but before the brace, both need defining
|
||||
}
|
||||
|
||||
// /*!X
|
||||
// enum A { B, C };
|
||||
|
||||
// /*!
|
||||
// * X
|
||||
// */
|
||||
// enum A { B, C };
|
||||
public void testAutoDocCommentContent11() throws CoreException {
|
||||
assertAutoEditBehaviour();
|
||||
}
|
||||
|
||||
// /**X
|
||||
// enum A { B,
|
||||
// C };
|
||||
|
||||
// /**
|
||||
// * X
|
||||
// */
|
||||
// enum A { B,//!< B
|
||||
// C }; //!< C
|
||||
public void testAutoDocCommentContent13() throws CoreException {
|
||||
assertAutoEditBehaviour();
|
||||
}
|
||||
|
||||
// /**X
|
||||
// enum A { B,
|
||||
// C };//!< C
|
||||
|
||||
// /**
|
||||
// * X
|
||||
// */
|
||||
// enum A { B,//!< B
|
||||
// C };//!< C
|
||||
public void testAutoDocCommentContent14() throws CoreException {
|
||||
assertAutoEditBehaviour();
|
||||
}
|
||||
|
||||
// /**X
|
||||
// enum A { B,//!< B
|
||||
// C };
|
||||
|
||||
// /**
|
||||
// * X
|
||||
// */
|
||||
// enum A { B,//!< B
|
||||
// C };//!< C
|
||||
public void testAutoDocCommentContent15() throws CoreException {
|
||||
assertAutoEditBehaviour();
|
||||
}
|
||||
|
||||
// /**X
|
||||
// enum A { B,
|
||||
// C };
|
||||
|
||||
// /**
|
||||
// * X
|
||||
// */
|
||||
// enum A { B,//!< B
|
||||
// C }; //!< C
|
||||
public void _testAutoDocCommentContent16() throws CoreException {
|
||||
/*
|
||||
* Indenting in the presence of tabs is not handled at the moment.
|
||||
*/
|
||||
assertAutoEditBehaviour();
|
||||
}
|
||||
|
||||
protected void assertAutoEditBehaviour() throws CoreException {
|
||||
CTextTools textTools = CUIPlugin.getDefault().getTextTools();
|
||||
final 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", "");
|
||||
|
||||
|
||||
DoxygenMultilineAutoEditStrategy ds= new DoxygenMultilineAutoEditStrategy() {
|
||||
public IASTTranslationUnit getAST() {
|
||||
final IFile file= fCProject.getProject().getFile("testContent.cpp");
|
||||
try {
|
||||
TestSourceReader.createFile(fCProject.getProject(), "testContent.cpp", doc.get());
|
||||
String id = CoreModel.getRegistedContentTypeId(file.getProject(), file.getName());
|
||||
return new TranslationUnit(fCProject, file, id).getAST();
|
||||
} catch(CoreException ce) {
|
||||
assertTrue("Could not get test content AST", false);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -34,6 +34,7 @@ Export-Package: org.eclipse.cdt.internal.corext;x-internal:=true,
|
|||
org.eclipse.cdt.internal.ui.text.asm;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.text.c.hover;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.text.contentassist;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.text.doctools;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.text.folding;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.text.template;x-internal:=true,
|
||||
org.eclipse.cdt.internal.ui.text.util;x-internal:=true,
|
||||
|
@ -59,6 +60,9 @@ Export-Package: org.eclipse.cdt.internal.corext;x-internal:=true,
|
|||
org.eclipse.cdt.ui.text,
|
||||
org.eclipse.cdt.ui.text.c.hover,
|
||||
org.eclipse.cdt.ui.text.contentassist,
|
||||
org.eclipse.cdt.ui.text.doctools,
|
||||
org.eclipse.cdt.ui.text.doctools.generic,
|
||||
org.eclipse.cdt.ui.text.doctools.doxygen,
|
||||
org.eclipse.cdt.ui.text.folding,
|
||||
org.eclipse.cdt.ui.wizards,
|
||||
org.eclipse.cdt.ui.wizards.conversion,
|
||||
|
|
|
@ -16,9 +16,11 @@ bin.includes = about.html,\
|
|||
templates/,\
|
||||
.,\
|
||||
META-INF/,\
|
||||
.options
|
||||
.options,\
|
||||
doxygenTags.csv
|
||||
src.includes = about.html,\
|
||||
schema/
|
||||
schema/,\
|
||||
doxygenTags.csv
|
||||
javadoc.packages = org.eclipse.cdt.ui.*,\
|
||||
org.eclipse.cdt.ui.wizards.*,\
|
||||
org.eclipse.cdt.ui.wizards.conversion.*
|
||||
|
|
116
core/org.eclipse.cdt.ui/doxygenTags.csv
Normal file
116
core/org.eclipse.cdt.ui/doxygenTags.csv
Normal file
|
@ -0,0 +1,116 @@
|
|||
a,,
|
||||
addindex,,
|
||||
addtogroup,,
|
||||
anchor,,
|
||||
arg,,
|
||||
attention,,
|
||||
author,,
|
||||
b,,
|
||||
brief,,
|
||||
bug,,
|
||||
c,,
|
||||
callgraph,,
|
||||
callergraph,,
|
||||
category,,
|
||||
class,,
|
||||
code,,
|
||||
cond,,
|
||||
copydoc,,
|
||||
date,,
|
||||
def,,
|
||||
defgroup,,
|
||||
deprecated,,
|
||||
details,,
|
||||
dir,,
|
||||
dontinclude,,
|
||||
dot,,
|
||||
dotfile,,
|
||||
e,,
|
||||
else,,
|
||||
elseif,,
|
||||
em,,
|
||||
endcode,,
|
||||
endcond,,
|
||||
enddot,,
|
||||
endhtmlonly,,
|
||||
endif,,
|
||||
endlatexonly,,
|
||||
endlink,,
|
||||
endmanonly,,
|
||||
endmsc,,
|
||||
endverbatim,,
|
||||
endxmlonly,,
|
||||
enum,,
|
||||
example,,
|
||||
exception,,
|
||||
f$,,
|
||||
f[,,
|
||||
f],,
|
||||
file,,
|
||||
fn,,
|
||||
hideinitializer,,
|
||||
htmlinclude,,
|
||||
htmlonly,,
|
||||
if,,
|
||||
ifnot,,
|
||||
image,,
|
||||
include,,
|
||||
includelineno,,
|
||||
ingroup,,
|
||||
internal,,
|
||||
invariant,,
|
||||
interface,,
|
||||
latexonly,,
|
||||
li,,
|
||||
line,,
|
||||
link,,
|
||||
mainpage,,
|
||||
manonly,,
|
||||
msc,,
|
||||
n,,
|
||||
name,,
|
||||
namespace,,
|
||||
nosubgrouping,,
|
||||
note,,
|
||||
overload,,
|
||||
p,,
|
||||
package,,
|
||||
page,,
|
||||
par,,
|
||||
paragraph,,
|
||||
param,,
|
||||
post,,
|
||||
pre,,
|
||||
property,,
|
||||
protocol,,
|
||||
ref,,
|
||||
relates,,
|
||||
relatesalso,,
|
||||
remarks,,
|
||||
return,,
|
||||
retval,,
|
||||
sa,,
|
||||
section,,
|
||||
see,,
|
||||
showinitializer,,
|
||||
since,,
|
||||
skip,,
|
||||
skipline,,
|
||||
struct,,
|
||||
subpage,,
|
||||
subsection,,
|
||||
subsubsection,,
|
||||
test,,
|
||||
throw,,
|
||||
todo,,
|
||||
typedef,,
|
||||
union,,
|
||||
until,,
|
||||
var,,
|
||||
verbatim,,
|
||||
verbinclude,,
|
||||
version,,
|
||||
warning,,
|
||||
weakgroup,,
|
||||
xmlonly,,
|
||||
xrefitem,,
|
|
|
@ -449,3 +449,5 @@ toggleMarkOccurrences.tooltip= Toggle Mark Occurrences
|
|||
toggleMarkOccurrences.description= Toggles mark occurrences in C/C++ editors
|
||||
|
||||
OccurrenceAnnotation.label= C/C++ Occurrences
|
||||
|
||||
DocCommentOwner.name = DocCommentOwner
|
|
@ -23,6 +23,7 @@
|
|||
<extension-point id="ConfigManager" name="%ConfigManager" schema="schema/ConfigManager.exsd"/>
|
||||
<extension-point id="HelpInfo" name="%HelpInfo" schema="schema/HelpInfo.exsd"/>
|
||||
<extension-point id="quickFixProcessors" name="%quickFixProcessorExtensionPoint" schema="schema/quickFixProcessors.exsd"/>
|
||||
<extension-point id="DocCommentOwner" name="%DocCommentOwner.name" schema="schema/DocCommentOwner.exsd"/>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.core.runtime.adapters">
|
||||
|
@ -770,6 +771,11 @@
|
|||
class="org.eclipse.cdt.internal.ui.preferences.WorkInProgressPreferencePage"
|
||||
id="org.eclipse.cdt.ui.preferneces.WorkInProgressPreferencePage">
|
||||
</page-->
|
||||
<page
|
||||
class="org.eclipse.cdt.ui.templateengine.pages.TemplatePreferencePage"
|
||||
name="%TemplatePreferencePage.name"
|
||||
category="org.eclipse.cdt.ui.preferences.CPluginPreferencePage"
|
||||
id="org.eclipse.cdt.core.templateengine.shareddefaults"/>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.editorActions">
|
||||
|
@ -1944,7 +1950,11 @@
|
|||
point="org.eclipse.core.runtime.preferences">
|
||||
<initializer class="org.eclipse.cdt.ui.CUIPreferenceInitializer"/>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.core.runtime.preferences">
|
||||
<initializer class="org.eclipse.cdt.ui.text.doctools.doxygen.DoxygenHelper"/>
|
||||
</extension>
|
||||
|
||||
<!-- Default folding -->
|
||||
<extension
|
||||
point= "org.eclipse.cdt.ui.foldingStructureProviders">
|
||||
|
@ -2447,16 +2457,6 @@
|
|||
name="%exportWizard.CDTCategory.name">
|
||||
</category>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.ui.preferencePages">
|
||||
<page
|
||||
class="org.eclipse.cdt.ui.templateengine.pages.TemplatePreferencePage"
|
||||
name="%TemplatePreferencePage.name"
|
||||
category="org.eclipse.cdt.ui.preferences.CPluginPreferencePage"
|
||||
id="org.eclipse.cdt.core.templateengine.shareddefaults"/>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
id="TemplateEngineWizard"
|
||||
name="%Template.Engine.Wizard"
|
||||
|
@ -2475,6 +2475,30 @@
|
|||
markerType="org.eclipse.cdt.core.problem">
|
||||
</updater>
|
||||
</extension>
|
||||
<extension
|
||||
id="doccomment.multiline"
|
||||
point="org.eclipse.cdt.ui.completionProposalComputer">
|
||||
<completionProposalComputer
|
||||
activate="true"
|
||||
categoryId="org.eclipse.cdt.ui.parserProposalCategory"
|
||||
class="org.eclipse.cdt.internal.ui.text.doctools.DocCommentMultilineProposalComputer">
|
||||
<partition
|
||||
type="__c_multiline_doc_comment">
|
||||
</partition>
|
||||
</completionProposalComputer>
|
||||
</extension>
|
||||
<extension
|
||||
id="doccomment.singleline"
|
||||
point="org.eclipse.cdt.ui.completionProposalComputer">
|
||||
<completionProposalComputer
|
||||
activate="true"
|
||||
categoryId="org.eclipse.cdt.ui.parserProposalCategory"
|
||||
class="org.eclipse.cdt.internal.ui.text.doctools.DocCommentSinglelineProposalComputer">
|
||||
<partition
|
||||
type="__c_singleline_doc_comment">
|
||||
</partition>
|
||||
</completionProposalComputer>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.CHelpProvider">
|
||||
<provider
|
||||
|
@ -2482,5 +2506,14 @@
|
|||
id="org.eclipse.cdt.ui.provider1">
|
||||
</provider>
|
||||
</extension>
|
||||
|
||||
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.DocCommentOwner">
|
||||
<owner
|
||||
id="org.eclipse.cdt.ui.doxygen"
|
||||
name="Doxygen"
|
||||
multiline="org.eclipse.cdt.ui.text.doctools.doxygen.DoxygenMultilineConfiguration"
|
||||
singleline="org.eclipse.cdt.ui.text.doctools.doxygen.DoxygenSingleConfiguration">
|
||||
</owner>
|
||||
</extension>
|
||||
</plugin>
|
||||
|
|
166
core/org.eclipse.cdt.ui/schema/DocCommentOwner.exsd
Normal file
166
core/org.eclipse.cdt.ui/schema/DocCommentOwner.exsd
Normal file
|
@ -0,0 +1,166 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Schema file written by PDE -->
|
||||
<schema targetNamespace="org.eclipse.cdt.ui">
|
||||
<annotation>
|
||||
<appInfo>
|
||||
<meta.schema plugin="org.eclipse.cdt.ui" id="DocCommentOwner" name="DocCommentOwner"/>
|
||||
</appInfo>
|
||||
<documentation>
|
||||
This extension point allows contribution of document comment detection, presentation and editing behaviours to the CDT editor.<p>
|
||||
|
||||
Where C and C++ define single and multiline comments, there is no corresponding language level definition of distinguished comments recognized by documentation tools. A list of these is available here: <a href="http://en.wikipedia.org/wiki/Comparison_of_documentation_generators">Wikipedia Comparison of Documentation Generators</a><p>
|
||||
|
||||
The customization for single and multi-line comments is handled by two contributed implementations of the same interface <ul><li><code>org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration</code></ul>
|
||||
The javadoc for this interface describes the individual editor features that can be contributed.<p>
|
||||
|
||||
A level of understanding of the eclipse and CDT editor infrastructure is needed in order to contribute to this extension point. A good starting point is to look at the GenericDocTag classes in the package - see the API Information section below.
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<element name="extension">
|
||||
<complexType>
|
||||
<choice>
|
||||
<element ref="owner"/>
|
||||
</choice>
|
||||
<attribute name="point" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="id" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="name" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
<appInfo>
|
||||
<meta.attribute translatable="true"/>
|
||||
</appInfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="owner">
|
||||
<complexType>
|
||||
<attribute name="id" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
a globally unique ID representing this owner.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="name" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
a human readable name for the CDT UI
|
||||
</documentation>
|
||||
<appInfo>
|
||||
<meta.attribute translatable="true"/>
|
||||
</appInfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="multiline" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
The comment viewer configuration that should be used for detection, presentation and editing of C/C++ multiline comments
|
||||
</documentation>
|
||||
<appInfo>
|
||||
<meta.attribute kind="java" basedOn=":org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration"/>
|
||||
</appInfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="singleline" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
The comment viewer configuration that should be used for detection, presentation and editing of C/C++ singleline comments
|
||||
</documentation>
|
||||
<appInfo>
|
||||
<meta.attribute kind="java" basedOn=":org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration"/>
|
||||
</appInfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<annotation>
|
||||
<appInfo>
|
||||
<meta.section type="since"/>
|
||||
</appInfo>
|
||||
<documentation>
|
||||
5.0
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<annotation>
|
||||
<appInfo>
|
||||
<meta.section type="examples"/>
|
||||
</appInfo>
|
||||
<documentation>
|
||||
<pre>
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.DocCommentOwner">
|
||||
<owner
|
||||
id="org.eclipse.cdt.ui.doxygen"
|
||||
name="Doxygen"
|
||||
multiline="org.eclipse.cdt.ui.text.doctools.doxygen.DoxygenMultilineConfiguration"
|
||||
singleline="org.eclipse.cdt.ui.text.doctools.doxygen.DoxygenSingleConfiguration">
|
||||
</owner>
|
||||
</extension>
|
||||
</pre>
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<annotation>
|
||||
<appInfo>
|
||||
<meta.section type="apiInfo"/>
|
||||
</appInfo>
|
||||
<documentation>
|
||||
<br>
|
||||
The javadoc is considered the primary source of information for plug-in implementors. Only a light outline is given here<p>
|
||||
Key interfaces are:
|
||||
<ul>
|
||||
<li>org.eclipse.cdt.ui.text.doctools.IDocCommentOwner
|
||||
<li>org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration
|
||||
<li>org.eclipse.cdt.ui.text.doctools.IDocCommentOwnershipListener
|
||||
</ul>
|
||||
|
||||
Key implementations are:
|
||||
<ul>
|
||||
<li>the implementations in package org.eclipse.cdt.ui.text.doctools.generic
|
||||
</ul>
|
||||
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<annotation>
|
||||
<appInfo>
|
||||
<meta.section type="implementation"/>
|
||||
</appInfo>
|
||||
<documentation>
|
||||
An abstract implementation of some key interfaces is given in the package <code>org.eclipse.cdt.ui.text.doctools.generic</code>
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<annotation>
|
||||
<appInfo>
|
||||
<meta.section type="copyright"/>
|
||||
</appInfo>
|
||||
<documentation>
|
||||
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
|
||||
<a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
</schema>
|
|
@ -115,6 +115,10 @@ and must have a public 0-argument constructor.
|
|||
</enumeration>
|
||||
<enumeration value="__c_preprocessor">
|
||||
</enumeration>
|
||||
<enumeration value="__c_multiline_doc_comment">
|
||||
</enumeration>
|
||||
<enumeration value="__c_singleline_doc_comment">
|
||||
</enumeration>
|
||||
</restriction>
|
||||
</simpleType>
|
||||
</attribute>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.compare;
|
||||
|
@ -134,7 +135,7 @@ abstract class AbstractMergeViewer extends TextMergeViewer {
|
|||
}
|
||||
|
||||
protected IDocumentPartitioner getDocumentPartitioner() {
|
||||
return CUIPlugin.getDefault().getTextTools().createDocumentPartitioner();
|
||||
return CUIPlugin.getDefault().getTextTools().createDocumentPartitioner(null);
|
||||
}
|
||||
|
||||
protected void configureTextViewer(TextViewer textViewer) {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
* QNX Software System
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.compare;
|
||||
|
||||
|
@ -160,7 +161,7 @@ public class CStructureCreator extends StructureCreator {
|
|||
* @see org.eclipse.compare.structuremergeviewer.StructureCreator#getDocumentPartitioner()
|
||||
*/
|
||||
protected IDocumentPartitioner getDocumentPartitioner() {
|
||||
return CUIPlugin.getDefault().getTextTools().createDocumentPartitioner();
|
||||
return CUIPlugin.getDefault().getTextTools().createDocumentPartitioner(null);
|
||||
}
|
||||
|
||||
private static String readString(IStreamContentAccessor sa) throws CoreException {
|
||||
|
|
|
@ -1,25 +1,31 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2006 QNX Software Systems and others.
|
||||
* Copyright (c) 2002, 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.CTextTools;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
|
||||
import org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension;
|
||||
import org.eclipse.core.filebuffers.LocationKind;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.CTextTools;
|
||||
|
||||
/**
|
||||
* CDocumentSetupParticipant
|
||||
*/
|
||||
public class CDocumentSetupParticipant implements IDocumentSetupParticipant {
|
||||
public class CDocumentSetupParticipant implements IDocumentSetupParticipant, IDocumentSetupParticipantExtension {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -30,8 +36,14 @@ public class CDocumentSetupParticipant implements IDocumentSetupParticipant {
|
|||
* @see org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.eclipse.jface.text.IDocument)
|
||||
*/
|
||||
public void setup(IDocument document) {
|
||||
CTextTools tools= CUIPlugin.getDefault().getTextTools();
|
||||
tools.setupCDocument(document);
|
||||
setup(document, null, null);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension#setup(org.eclipse.jface.text.IDocument, org.eclipse.core.runtime.IPath, org.eclipse.core.filebuffers.LocationKind)
|
||||
*/
|
||||
public void setup(IDocument document, IPath location, LocationKind locationKind) {
|
||||
CTextTools tools= CUIPlugin.getDefault().getTextTools();
|
||||
tools.setupCDocument(document, location, locationKind);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2008 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
|
||||
|
@ -9,30 +9,29 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
* QNX Software System
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.editor.asm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.text.rules.EndOfLineRule;
|
||||
import org.eclipse.jface.text.rules.IRule;
|
||||
import org.eclipse.jface.text.rules.Token;
|
||||
import org.eclipse.jface.text.rules.IToken;
|
||||
import org.eclipse.jface.text.rules.WhitespaceRule;
|
||||
import org.eclipse.jface.text.rules.WordPatternRule;
|
||||
import org.eclipse.jface.text.rules.WordRule;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
|
||||
import org.eclipse.cdt.core.model.IAsmLanguage;
|
||||
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
|
||||
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
|
||||
import org.eclipse.cdt.internal.ui.text.IColorManager;
|
||||
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
|
||||
|
||||
|
||||
/**
|
||||
/*
|
||||
* An assembly code scanner.
|
||||
*/
|
||||
public final class AsmCodeScanner extends AbstractCScanner {
|
||||
|
@ -50,27 +49,15 @@ public final class AsmCodeScanner extends AbstractCScanner {
|
|||
/**
|
||||
* Creates an assembly code scanner.
|
||||
*/
|
||||
public AsmCodeScanner(IColorManager manager, IPreferenceStore store, IAsmLanguage asmLanguage) {
|
||||
super(manager, store);
|
||||
public AsmCodeScanner(ITokenStoreFactory factory, IAsmLanguage asmLanguage) {
|
||||
super(factory.createTokenStore(fgTokenProperties));
|
||||
fAsmLanguage= asmLanguage;
|
||||
initialize();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see AbstractCScanner#getTokenProperties()
|
||||
*/
|
||||
protected String[] getTokenProperties() {
|
||||
return fgTokenProperties;
|
||||
setRules(createRules());
|
||||
}
|
||||
|
||||
/*
|
||||
* @see AbstractCScanner#createRules()
|
||||
*/
|
||||
protected List createRules() {
|
||||
|
||||
List rules= new ArrayList();
|
||||
|
||||
Token token;
|
||||
protected List<IRule> createRules() {
|
||||
IToken token;
|
||||
List<IRule> rules= new ArrayList<IRule>();
|
||||
|
||||
// Add rule(s) for single line comments
|
||||
token= getToken(ICColorConstants.C_SINGLE_LINE_COMMENT);
|
||||
|
@ -82,7 +69,7 @@ public final class AsmCodeScanner extends AbstractCScanner {
|
|||
// Add generic whitespace rule.
|
||||
rules.add(new WhitespaceRule(new CWhitespaceDetector()));
|
||||
|
||||
final Token other= getToken(ICColorConstants.C_DEFAULT);
|
||||
final IToken other= getToken(ICColorConstants.C_DEFAULT);
|
||||
|
||||
// Add rule for labels
|
||||
token= getToken(ICColorConstants.ASM_LABEL);
|
||||
|
@ -105,13 +92,4 @@ public final class AsmCodeScanner extends AbstractCScanner {
|
|||
setDefaultReturnToken(other);
|
||||
return rules;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see AbstractCScanner#adaptToPreferenceChange(PropertyChangeEvent)
|
||||
*/
|
||||
public void adaptToPreferenceChange(PropertyChangeEvent event) {
|
||||
if (super.affectsBehavior(event)) {
|
||||
super.adaptToPreferenceChange(event);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.editor.asm;
|
||||
|
||||
|
@ -14,18 +15,17 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.text.rules.EndOfLineRule;
|
||||
import org.eclipse.jface.text.rules.IRule;
|
||||
import org.eclipse.jface.text.rules.Token;
|
||||
import org.eclipse.jface.text.rules.IToken;
|
||||
import org.eclipse.jface.text.rules.WhitespaceRule;
|
||||
|
||||
import org.eclipse.cdt.core.model.IAsmLanguage;
|
||||
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
|
||||
import org.eclipse.cdt.internal.ui.text.CHeaderRule;
|
||||
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
|
||||
import org.eclipse.cdt.internal.ui.text.IColorManager;
|
||||
import org.eclipse.cdt.internal.ui.text.PreprocessorRule;
|
||||
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
|
||||
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
|
||||
|
@ -37,12 +37,12 @@ import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
|
|||
*/
|
||||
public class AsmPreprocessorScanner extends AbstractCScanner {
|
||||
|
||||
/** Properties for tokens. */
|
||||
/** Properties for tokens. */
|
||||
private static final String[] fgTokenProperties= {
|
||||
ICColorConstants.C_SINGLE_LINE_COMMENT,
|
||||
ICColorConstants.PP_DIRECTIVE,
|
||||
ICColorConstants.C_STRING,
|
||||
ICColorConstants.PP_HEADER,
|
||||
ICColorConstants.PP_HEADER,
|
||||
ICColorConstants.PP_DEFAULT,
|
||||
};
|
||||
|
||||
|
@ -50,31 +50,27 @@ public class AsmPreprocessorScanner extends AbstractCScanner {
|
|||
|
||||
/**
|
||||
* Create a preprocessor directive scanner.
|
||||
*
|
||||
* @param colorManager
|
||||
* @param store
|
||||
* @param factory
|
||||
* @param asmLanguage
|
||||
*/
|
||||
public AsmPreprocessorScanner(IColorManager colorManager, IPreferenceStore store, IAsmLanguage asmLanguage) {
|
||||
super(colorManager, store);
|
||||
public AsmPreprocessorScanner(ITokenStoreFactory factory, IAsmLanguage asmLanguage) {
|
||||
super(factory.createTokenStore(fgTokenProperties));
|
||||
Assert.isNotNull(asmLanguage);
|
||||
fAsmLanguage= asmLanguage;
|
||||
initialize();
|
||||
setRules(createRules());
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.ui.text.AbstractCScanner#createRules()
|
||||
/**
|
||||
* Creates rules used in this RulesBasedScanner
|
||||
*/
|
||||
protected List createRules() {
|
||||
protected List<IRule> createRules() {
|
||||
List<IRule> rules= new ArrayList<IRule>();
|
||||
IToken defaultToken= getToken(ICColorConstants.PP_DEFAULT);
|
||||
IToken token;
|
||||
|
||||
Token defaultToken= getToken(ICColorConstants.PP_DEFAULT);
|
||||
|
||||
List rules= new ArrayList();
|
||||
Token token;
|
||||
|
||||
// Add generic white space rule.
|
||||
rules.add(new WhitespaceRule(new CWhitespaceDetector()));
|
||||
|
||||
|
||||
token= getToken(ICColorConstants.PP_DIRECTIVE);
|
||||
PreprocessorRule preprocessorRule= new PreprocessorRule(new CWordDetector(), defaultToken, getToken(ICColorConstants.C_SINGLE_LINE_COMMENT));
|
||||
String[] ppKeywords= fAsmLanguage.getPreprocessorKeywords();
|
||||
|
@ -88,27 +84,19 @@ public class AsmPreprocessorScanner extends AbstractCScanner {
|
|||
preprocessorRule.addWord("##", token); //$NON-NLS-1$
|
||||
rules.add(preprocessorRule);
|
||||
|
||||
token = getToken(ICColorConstants.PP_HEADER);
|
||||
CHeaderRule headerRule = new CHeaderRule(token);
|
||||
rules.add(headerRule);
|
||||
token = getToken(ICColorConstants.PP_HEADER);
|
||||
CHeaderRule headerRule = new CHeaderRule(token);
|
||||
rules.add(headerRule);
|
||||
|
||||
token = getToken(ICColorConstants.C_SINGLE_LINE_COMMENT);
|
||||
IRule lineCommentRule= new EndOfLineRule("#", token); //$NON-NLS-1$
|
||||
rules.add(lineCommentRule);
|
||||
token = getToken(ICColorConstants.C_SINGLE_LINE_COMMENT);
|
||||
IRule lineCommentRule= new EndOfLineRule("#", token); //$NON-NLS-1$
|
||||
rules.add(lineCommentRule);
|
||||
|
||||
// token = getToken(ICColorConstants.C_MULTI_LINE_COMMENT);
|
||||
// IRule blockCommentRule = new MultiLineRule("/*", "*/", token, '\\'); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// rules.add(blockCommentRule);
|
||||
|
||||
setDefaultReturnToken(defaultToken);
|
||||
// token = getToken(ICColorConstants.C_MULTI_LINE_COMMENT);
|
||||
// IRule blockCommentRule = new MultiLineRule("/*", "*/", token, '\\'); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// rules.add(blockCommentRule);
|
||||
|
||||
setDefaultReturnToken(defaultToken);
|
||||
return rules;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.ui.text.AbstractCScanner#getTokenProperties()
|
||||
*/
|
||||
protected String[] getTokenProperties() {
|
||||
return fgTokenProperties;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2007 QNX Software Systems and others.
|
||||
* Copyright (c) 2000, 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
|
||||
|
@ -44,6 +44,8 @@ import org.eclipse.cdt.core.model.LanguageManager;
|
|||
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.ITokenStore;
|
||||
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
|
||||
import org.eclipse.cdt.internal.ui.text.CCommentScanner;
|
||||
|
@ -52,6 +54,7 @@ import org.eclipse.cdt.internal.ui.text.ICColorConstants;
|
|||
import org.eclipse.cdt.internal.ui.text.IColorManager;
|
||||
import org.eclipse.cdt.internal.ui.text.PartitionDamager;
|
||||
import org.eclipse.cdt.internal.ui.text.SingleTokenCScanner;
|
||||
import org.eclipse.cdt.internal.ui.text.TokenStore;
|
||||
|
||||
|
||||
public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
||||
|
@ -123,9 +126,9 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
|
|||
* 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);
|
||||
fMultilineCommentScanner= new CCommentScanner(getTokenStoreFactory(), ICColorConstants.C_MULTI_LINE_COMMENT);
|
||||
fSinglelineCommentScanner= new CCommentScanner(getTokenStoreFactory(), ICColorConstants.C_SINGLE_LINE_COMMENT);
|
||||
fStringScanner= new SingleTokenCScanner(getTokenStoreFactory(), ICColorConstants.C_STRING);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -167,10 +170,10 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
|
|||
}
|
||||
AbstractCScanner scanner= null;
|
||||
if (language instanceof IAsmLanguage) {
|
||||
scanner= new AsmPreprocessorScanner(getColorManager(), fPreferenceStore, (IAsmLanguage)language);
|
||||
scanner= new AsmPreprocessorScanner(getTokenStoreFactory(), (IAsmLanguage)language);
|
||||
}
|
||||
if (scanner == null) {
|
||||
scanner= new AsmPreprocessorScanner(getColorManager(), fPreferenceStore, AssemblyLanguage.getDefault());
|
||||
scanner= new AsmPreprocessorScanner(getTokenStoreFactory(), AssemblyLanguage.getDefault());
|
||||
}
|
||||
fPreprocessorScanner= scanner;
|
||||
return fPreprocessorScanner;
|
||||
|
@ -187,14 +190,14 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
|
|||
RuleBasedScanner scanner= null;
|
||||
if (language instanceof IAsmLanguage) {
|
||||
IAsmLanguage asmLang= (IAsmLanguage)language;
|
||||
scanner = new AsmCodeScanner(getColorManager(), fPreferenceStore, asmLang);
|
||||
scanner = new AsmCodeScanner(getTokenStoreFactory(), asmLang);
|
||||
} else if (language != null) {
|
||||
ILanguageUI languageUI = (ILanguageUI)language.getAdapter(ILanguageUI.class);
|
||||
if (languageUI != null)
|
||||
scanner = languageUI.getCodeScanner();
|
||||
}
|
||||
if (scanner == null) {
|
||||
scanner = new AsmCodeScanner(getColorManager(), fPreferenceStore, AssemblyLanguage.getDefault());
|
||||
scanner = new AsmCodeScanner(getTokenStoreFactory(), AssemblyLanguage.getDefault());
|
||||
}
|
||||
if (scanner instanceof AbstractCScanner) {
|
||||
fCodeScanner= (AbstractCScanner)scanner;
|
||||
|
@ -373,6 +376,13 @@ public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration
|
|||
fPreprocessorScanner= null;
|
||||
}
|
||||
|
||||
private ITokenStoreFactory getTokenStoreFactory() {
|
||||
return new ITokenStoreFactory() {
|
||||
public ITokenStore createTokenStore(String[] propertyColorNames) {
|
||||
return new TokenStore(getColorManager(), fPreferenceStore, propertyColorNames);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2008 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
|
||||
|
@ -9,6 +9,7 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
* QNX Software System
|
||||
* Wind River Systems, Inc.
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.editor.asm;
|
||||
|
||||
|
@ -20,11 +21,13 @@ import org.eclipse.jface.util.PropertyChangeEvent;
|
|||
|
||||
import org.eclipse.cdt.core.model.AssemblyLanguage;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.ui.text.ITokenStore;
|
||||
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.CCommentScanner;
|
||||
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
|
||||
import org.eclipse.cdt.internal.ui.text.SingleTokenCScanner;
|
||||
import org.eclipse.cdt.internal.ui.text.TokenStore;
|
||||
import org.eclipse.cdt.internal.ui.text.util.CColorManager;
|
||||
|
||||
|
||||
|
@ -77,20 +80,23 @@ public class AsmTextTools {
|
|||
* and initializes all members of this collection.
|
||||
*/
|
||||
public AsmTextTools(IPreferenceStore store, Preferences coreStore) {
|
||||
if(store == null) {
|
||||
store = CUIPlugin.getDefault().getPreferenceStore();
|
||||
}
|
||||
|
||||
fColorManager= new CColorManager();
|
||||
fCodeScanner= new AsmCodeScanner(fColorManager, store, AssemblyLanguage.getDefault());
|
||||
fPreprocessorScanner= new AsmPreprocessorScanner(fColorManager, store, AssemblyLanguage.getDefault());
|
||||
fPreferenceStore = store != null ? store : CUIPlugin.getDefault().getPreferenceStore();
|
||||
fColorManager= new CColorManager();
|
||||
|
||||
ITokenStoreFactory factory= new ITokenStoreFactory() {
|
||||
public ITokenStore createTokenStore(String[] propertyColorNames) {
|
||||
return new TokenStore(fColorManager, fPreferenceStore, propertyColorNames);
|
||||
}
|
||||
};
|
||||
|
||||
fMultilineCommentScanner= new CCommentScanner(fColorManager, store, coreStore, ICColorConstants.C_MULTI_LINE_COMMENT);
|
||||
fSinglelineCommentScanner= new CCommentScanner(fColorManager, store, coreStore, ICColorConstants.C_SINGLE_LINE_COMMENT);
|
||||
fStringScanner= new SingleTokenCScanner(fColorManager, store, ICColorConstants.C_STRING);
|
||||
fCodeScanner= new AsmCodeScanner(factory, AssemblyLanguage.getDefault());
|
||||
fPreprocessorScanner= new AsmPreprocessorScanner(factory, AssemblyLanguage.getDefault());
|
||||
fMultilineCommentScanner= new CCommentScanner(factory, coreStore, ICColorConstants.C_MULTI_LINE_COMMENT);
|
||||
fSinglelineCommentScanner= new CCommentScanner(factory, coreStore, ICColorConstants.C_SINGLE_LINE_COMMENT);
|
||||
fStringScanner= new SingleTokenCScanner(factory, ICColorConstants.C_STRING);
|
||||
|
||||
fPreferenceStore = store;
|
||||
store.addPropertyChangeListener(fPreferenceListener);
|
||||
// listener must be registered after initializing scanners
|
||||
fPreferenceStore.addPropertyChangeListener(fPreferenceListener);
|
||||
|
||||
fCorePreferenceStore= coreStore;
|
||||
if (fCorePreferenceStore != null) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2008 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
|
||||
|
@ -7,7 +7,8 @@
|
|||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Anton Leherbauer (Wind River Systems
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.preferences;
|
||||
|
@ -17,6 +18,7 @@ import java.io.IOException;
|
|||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
import org.eclipse.jface.preference.ColorSelector;
|
||||
|
@ -341,7 +343,7 @@ class CEditorColoringConfigurationBlock extends AbstractConfigurationBlock {
|
|||
/**
|
||||
* Highlighting color list
|
||||
*/
|
||||
private final java.util.List fListModel= new ArrayList();
|
||||
private final java.util.List<HighlightingColorListItem> fListModel= new ArrayList<HighlightingColorListItem>();
|
||||
/**
|
||||
* Highlighting color list viewer
|
||||
*/
|
||||
|
@ -394,13 +396,12 @@ class CEditorColoringConfigurationBlock extends AbstractConfigurationBlock {
|
|||
}
|
||||
|
||||
private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys() {
|
||||
|
||||
ArrayList overlayKeys= new ArrayList();
|
||||
List<OverlayPreferenceStore.OverlayKey> overlayKeys= new ArrayList<OverlayPreferenceStore.OverlayKey>();
|
||||
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ENABLED));
|
||||
|
||||
for (int i= 0, n= fListModel.size(); i < n; i++) {
|
||||
HighlightingColorListItem item= (HighlightingColorListItem) fListModel.get(i);
|
||||
HighlightingColorListItem item= fListModel.get(i);
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, item.getColorKey()));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, item.getBoldKey()));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, item.getItalicKey()));
|
||||
|
@ -788,7 +789,6 @@ class CEditorColoringConfigurationBlock extends AbstractConfigurationBlock {
|
|||
}
|
||||
|
||||
private Control createPreviewer(Composite parent) {
|
||||
|
||||
IPreferenceStore generalTextStore= EditorsUI.getPreferenceStore();
|
||||
IPreferenceStore store= new ChainedPreferenceStore(new IPreferenceStore[] { getPreferenceStore(), generalTextStore });
|
||||
fPreviewViewer = new CSourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, store);
|
||||
|
@ -801,7 +801,7 @@ class CEditorColoringConfigurationBlock extends AbstractConfigurationBlock {
|
|||
|
||||
String content= loadPreviewContentFromFile("ColorSettingPreviewCode.txt"); //$NON-NLS-1$
|
||||
IDocument document= new Document(content);
|
||||
CUIPlugin.getDefault().getTextTools().setupCDocumentPartitioner(document, ICPartitions.C_PARTITIONING);
|
||||
CUIPlugin.getDefault().getTextTools().setupCDocumentPartitioner(document, ICPartitions.C_PARTITIONING, null);
|
||||
fPreviewViewer.setDocument(document);
|
||||
|
||||
installSemanticHighlighting();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2008 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
|
||||
|
@ -9,11 +9,13 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
* QNX Software System
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.preferences;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.jface.layout.GridDataFactory;
|
||||
import org.eclipse.jface.preference.ColorSelector;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.preference.PreferenceConverter;
|
||||
|
@ -37,10 +39,15 @@ import org.eclipse.ui.PlatformUI;
|
|||
import org.eclipse.ui.dialogs.PreferencesUtil;
|
||||
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
import org.eclipse.cdt.ui.dialogs.DocCommentOwnerComposite;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
|
||||
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.preferences.OverlayPreferenceStore.OverlayKey;
|
||||
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
|
||||
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
|
||||
|
||||
/*
|
||||
* The page for setting the editor options.
|
||||
|
@ -60,14 +67,14 @@ public class CEditorPreferencePage extends AbstractPreferencePage implements IWo
|
|||
private List fAppearanceColorList;
|
||||
private ColorSelector fAppearanceColorEditor;
|
||||
private Button fAppearanceColorDefault;
|
||||
|
||||
|
||||
private DocCommentOwnerComposite fDocCommentOwnerComposite;
|
||||
|
||||
public CEditorPreferencePage() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys() {
|
||||
ArrayList overlayKeys = new ArrayList();
|
||||
ArrayList<OverlayKey> overlayKeys = new ArrayList<OverlayKey>();
|
||||
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, CEditor.SUB_WORD_NAVIGATION));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, CEditor.MATCHING_BRACKETS_COLOR));
|
||||
|
@ -117,8 +124,8 @@ public class CEditorPreferencePage extends AbstractPreferencePage implements IWo
|
|||
}
|
||||
|
||||
private Control createAppearancePage(Composite parent) {
|
||||
|
||||
Composite behaviorComposite = new Composite(parent, SWT.NONE);
|
||||
Composite behaviorComposite= ControlFactory.createGroup(parent, PreferencesMessages.CEditorPreferencePage_GeneralAppearanceGroupTitle, 1);
|
||||
|
||||
GridLayout layout = new GridLayout();
|
||||
layout.numColumns = 2;
|
||||
behaviorComposite.setLayout(layout);
|
||||
|
@ -269,8 +276,17 @@ public class CEditorPreferencePage extends AbstractPreferencePage implements IWo
|
|||
|
||||
createHeader(parent);
|
||||
|
||||
ControlFactory.createEmptySpace(parent, 2);
|
||||
createAppearancePage(parent);
|
||||
|
||||
ControlFactory.createEmptySpace(parent, 2);
|
||||
|
||||
String dsc= PreferencesMessages.CEditorPreferencePage_SelectDocToolDescription;
|
||||
String msg= PreferencesMessages.CEditorPreferencePage_WorkspaceDefaultLabel;
|
||||
IDocCommentOwner workspaceOwner= DocCommentOwnerManager.getInstance().getWorkspaceCommentOwner();
|
||||
fDocCommentOwnerComposite= new DocCommentOwnerComposite(parent, workspaceOwner, dsc, msg);
|
||||
fDocCommentOwnerComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true,false).create());
|
||||
|
||||
initialize();
|
||||
|
||||
return parent;
|
||||
|
@ -291,6 +307,14 @@ public class CEditorPreferencePage extends AbstractPreferencePage implements IWo
|
|||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.ui.preferences.AbstractPreferencePage#performOk()
|
||||
*/
|
||||
public boolean performOk() {
|
||||
DocCommentOwnerManager.getInstance().setWorkspaceCommentOwner(fDocCommentOwnerComposite.getSelectedDocCommentOwner());
|
||||
return super.performOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the default colors.
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2008 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,6 +8,7 @@
|
|||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.preferences;
|
||||
|
||||
|
@ -409,7 +410,7 @@ public class CodeTemplateBlock extends OptionsConfigurationBlock {
|
|||
|
||||
IDocument document= new Document();
|
||||
CTextTools tools= CUIPlugin.getDefault().getTextTools();
|
||||
tools.setupCDocumentPartitioner(document, ICPartitions.C_PARTITIONING);
|
||||
tools.setupCDocumentPartitioner(document, ICPartitions.C_PARTITIONING, null);
|
||||
IPreferenceStore store= CUIPlugin.getDefault().getCombinedPreferenceStore();
|
||||
SourceViewer viewer= new CSourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, store);
|
||||
CodeTemplateSourceViewerConfiguration configuration= new CodeTemplateSourceViewerConfiguration(tools.getColorManager(), store, null, fTemplateProcessor);
|
||||
|
@ -442,7 +443,7 @@ public class CodeTemplateBlock extends OptionsConfigurationBlock {
|
|||
}
|
||||
|
||||
protected TemplatePersistenceData[] getCodeTemplatesOfCategory(boolean isComment) {
|
||||
ArrayList res= new ArrayList();
|
||||
ArrayList<TemplatePersistenceData> res= new ArrayList<TemplatePersistenceData>();
|
||||
TemplatePersistenceData[] templates= fTemplateStore.getTemplateData();
|
||||
for (int i= 0; i < templates.length; i++) {
|
||||
TemplatePersistenceData curr= templates[i];
|
||||
|
@ -452,7 +453,7 @@ public class CodeTemplateBlock extends OptionsConfigurationBlock {
|
|||
res.add(curr);
|
||||
}
|
||||
}
|
||||
return (TemplatePersistenceData[]) res.toArray(new TemplatePersistenceData[res.size()]);
|
||||
return res.toArray(new TemplatePersistenceData[res.size()]);
|
||||
}
|
||||
|
||||
private TemplatePersistenceData[] getTemplatesOfContextType(TemplateContextType contextType) {
|
||||
|
@ -460,7 +461,7 @@ public class CodeTemplateBlock extends OptionsConfigurationBlock {
|
|||
}
|
||||
|
||||
protected TemplatePersistenceData[] getTemplatesOfContextType(String contextTypeId) {
|
||||
ArrayList res= new ArrayList();
|
||||
ArrayList<TemplatePersistenceData> res= new ArrayList<TemplatePersistenceData>();
|
||||
TemplatePersistenceData[] templates= fTemplateStore.getTemplateData();
|
||||
for (int i= 0; i < templates.length; i++) {
|
||||
TemplatePersistenceData curr= templates[i];
|
||||
|
@ -468,7 +469,7 @@ public class CodeTemplateBlock extends OptionsConfigurationBlock {
|
|||
res.add(curr);
|
||||
}
|
||||
}
|
||||
return (TemplatePersistenceData[]) res.toArray(new TemplatePersistenceData[res.size()]);
|
||||
return res.toArray(new TemplatePersistenceData[res.size()]);
|
||||
}
|
||||
|
||||
protected ContextTypeRegistry getFileTemplateContextRegistry() {
|
||||
|
@ -489,14 +490,14 @@ public class CodeTemplateBlock extends OptionsConfigurationBlock {
|
|||
|
||||
protected TemplateContextType[] getFileTemplateContextTypes() {
|
||||
Iterator iter= getFileTemplateContextRegistry().contextTypes();
|
||||
ArrayList result= new ArrayList();
|
||||
ArrayList<TemplateContextType> result= new ArrayList<TemplateContextType>();
|
||||
while (iter.hasNext()) {
|
||||
TemplateContextType contextType= (TemplateContextType)iter.next();
|
||||
if (getTemplatesOfContextType(contextType).length > 0) {
|
||||
result.add(contextType);
|
||||
}
|
||||
}
|
||||
return (TemplateContextType[]) result.toArray(new TemplateContextType[0]);
|
||||
return result.toArray(new TemplateContextType[0]);
|
||||
}
|
||||
|
||||
protected static boolean canAdd(List selected) {
|
||||
|
@ -693,7 +694,7 @@ public class CodeTemplateBlock extends OptionsConfigurationBlock {
|
|||
}
|
||||
|
||||
private void export(List selected) {
|
||||
Set datas= new HashSet();
|
||||
Set<Object> datas= new HashSet<Object>();
|
||||
for (int i= 0; i < selected.size(); i++) {
|
||||
Object curr= selected.get(i);
|
||||
if (curr instanceof TemplatePersistenceData) {
|
||||
|
@ -713,7 +714,7 @@ public class CodeTemplateBlock extends OptionsConfigurationBlock {
|
|||
datas.addAll(Arrays.asList(cat));
|
||||
}
|
||||
}
|
||||
export((TemplatePersistenceData[]) datas.toArray(new TemplatePersistenceData[datas.size()]));
|
||||
export(datas.toArray(new TemplatePersistenceData[datas.size()]));
|
||||
}
|
||||
|
||||
private void export(TemplatePersistenceData[] templates) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2008 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
|
||||
|
@ -73,6 +73,7 @@ import org.eclipse.swt.widgets.Text;
|
|||
import org.eclipse.swt.widgets.Widget;
|
||||
import org.eclipse.ui.ActiveShellExpression;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.handlers.IHandlerActivation;
|
||||
import org.eclipse.ui.handlers.IHandlerService;
|
||||
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
|
||||
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
|
||||
|
@ -155,8 +156,8 @@ class EditTemplateDialog extends StatusDialog {
|
|||
|
||||
private StatusInfo fValidationStatus;
|
||||
private boolean fSuppressError= true; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=4354
|
||||
private Map fGlobalActions= new HashMap(10);
|
||||
private List fSelectionActions = new ArrayList(3);
|
||||
private Map<String, TextViewerAction> fGlobalActions= new HashMap<String, TextViewerAction>(10);
|
||||
private List<String> fSelectionActions = new ArrayList<String>(3);
|
||||
private String[][] fContextTypes;
|
||||
|
||||
private ContextTypeRegistry fContextTypeRegistry;
|
||||
|
@ -187,7 +188,7 @@ class EditTemplateDialog extends StatusDialog {
|
|||
|
||||
// String delim= new Document().getLegalLineDelimiters()[0];
|
||||
|
||||
List contexts= new ArrayList();
|
||||
List<String[]> contexts= new ArrayList<String[]>();
|
||||
for (Iterator it= registry.contextTypes(); it.hasNext();) {
|
||||
TemplateContextType type= (TemplateContextType) it.next();
|
||||
// TODO cppdoc? doxygen?
|
||||
|
@ -196,13 +197,11 @@ class EditTemplateDialog extends StatusDialog {
|
|||
// else
|
||||
contexts.add(0, new String[] { type.getId(), type.getName(), "" }); //$NON-NLS-1$
|
||||
}
|
||||
Collections.sort(contexts, new Comparator() {
|
||||
public int compare(Object o1, Object o2) {
|
||||
String[] lhs= (String[]) o1;
|
||||
String[] rhs= (String[]) o2;
|
||||
return lhs[1].compareTo(rhs[1]);
|
||||
Collections.sort(contexts, new Comparator<String[]>() {
|
||||
public int compare(String[] s1, String[] s2) {
|
||||
return s1[1].compareTo(s2[1]);
|
||||
}});
|
||||
fContextTypes= (String[][]) contexts.toArray(new String[contexts.size()][]);
|
||||
fContextTypes= contexts.toArray(new String[contexts.size()][]);
|
||||
|
||||
fValidationStatus= new StatusInfo();
|
||||
|
||||
|
@ -413,7 +412,7 @@ class EditTemplateDialog extends StatusDialog {
|
|||
String prefix= getPrefix();
|
||||
IDocument document= new Document(prefix + fTemplate.getPattern());
|
||||
CTextTools tools= CUIPlugin.getDefault().getTextTools();
|
||||
tools.setupCDocumentPartitioner(document, ICPartitions.C_PARTITIONING);
|
||||
tools.setupCDocumentPartitioner(document, ICPartitions.C_PARTITIONING, null);
|
||||
IPreferenceStore store= CUIPlugin.getDefault().getCombinedPreferenceStore();
|
||||
SourceViewer viewer= new CSourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, store);
|
||||
CodeTemplateSourceViewerConfiguration configuration= new CodeTemplateSourceViewerConfiguration(tools.getColorManager(), store, null, fTemplateProcessor);
|
||||
|
@ -475,7 +474,7 @@ class EditTemplateDialog extends StatusDialog {
|
|||
}
|
||||
|
||||
private void initializeActions() {
|
||||
final ArrayList handlerActivations= new ArrayList(3);
|
||||
final ArrayList<IHandlerActivation> handlerActivations= new ArrayList<IHandlerActivation>(3);
|
||||
final IHandlerService handlerService= (IHandlerService) PlatformUI.getWorkbench().getAdapter(IHandlerService.class);
|
||||
getShell().addDisposeListener(new DisposeListener() {
|
||||
public void widgetDisposed(DisposeEvent e) {
|
||||
|
@ -536,28 +535,28 @@ class EditTemplateDialog extends StatusDialog {
|
|||
|
||||
private void fillContextMenu(IMenuManager menu) {
|
||||
menu.add(new GroupMarker(ITextEditorActionConstants.GROUP_UNDO));
|
||||
menu.appendToGroup(ITextEditorActionConstants.GROUP_UNDO, (IAction) fGlobalActions.get(ITextEditorActionConstants.UNDO));
|
||||
menu.appendToGroup(ITextEditorActionConstants.GROUP_UNDO, (IAction) fGlobalActions.get(ITextEditorActionConstants.REDO));
|
||||
menu.appendToGroup(ITextEditorActionConstants.GROUP_UNDO, fGlobalActions.get(ITextEditorActionConstants.UNDO));
|
||||
menu.appendToGroup(ITextEditorActionConstants.GROUP_UNDO, fGlobalActions.get(ITextEditorActionConstants.REDO));
|
||||
|
||||
menu.add(new Separator(ITextEditorActionConstants.GROUP_EDIT));
|
||||
menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, (IAction) fGlobalActions.get(ITextEditorActionConstants.CUT));
|
||||
menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, (IAction) fGlobalActions.get(ITextEditorActionConstants.COPY));
|
||||
menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, (IAction) fGlobalActions.get(ITextEditorActionConstants.PASTE));
|
||||
menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, (IAction) fGlobalActions.get(ITextEditorActionConstants.SELECT_ALL));
|
||||
menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, fGlobalActions.get(ITextEditorActionConstants.CUT));
|
||||
menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, fGlobalActions.get(ITextEditorActionConstants.COPY));
|
||||
menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, fGlobalActions.get(ITextEditorActionConstants.PASTE));
|
||||
menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, fGlobalActions.get(ITextEditorActionConstants.SELECT_ALL));
|
||||
|
||||
menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
|
||||
menu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, (IAction) fGlobalActions.get("ContentAssistProposal")); //$NON-NLS-1$
|
||||
menu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fGlobalActions.get("ContentAssistProposal")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
||||
protected void updateSelectionDependentActions() {
|
||||
Iterator iterator= fSelectionActions.iterator();
|
||||
Iterator<String> iterator= fSelectionActions.iterator();
|
||||
while (iterator.hasNext())
|
||||
updateAction((String)iterator.next());
|
||||
updateAction(iterator.next());
|
||||
}
|
||||
|
||||
protected void updateAction(String actionId) {
|
||||
IAction action= (IAction) fGlobalActions.get(actionId);
|
||||
IAction action= fGlobalActions.get(actionId);
|
||||
if (action instanceof IUpdate)
|
||||
((IUpdate) action).update();
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
* Anton Leherbauer (Wind River Systems)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Sergey Prigogin (Google)
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.preferences;
|
||||
|
||||
|
@ -181,9 +182,12 @@ public final class PreferencesMessages extends NLS {
|
|||
public static String CEditorPreferencePage_closeBraces;
|
||||
public static String CEditorPreferencePage_wrapStrings;
|
||||
public static String CEditorPreferencePage_escapeStrings;
|
||||
public static String CEditorPreferencePage_GeneralAppearanceGroupTitle;
|
||||
public static String CEditorPreferencePage_SelectDocToolDescription;
|
||||
public static String CEditorPreferencePage_smartPaste;
|
||||
|
||||
public static String CEditorPreferencePage_typing_smartTab;
|
||||
public static String CEditorPreferencePage_WorkspaceDefaultLabel;
|
||||
|
||||
public static String SmartTypingConfigurationBlock_autoclose_title;
|
||||
public static String SmartTypingConfigurationBlock_tabs_title;
|
||||
|
|
|
@ -10,9 +10,10 @@
|
|||
# Anton Leherbauer (Wind River Systems)
|
||||
# Markus Schorn (Wind River Systems)
|
||||
# Sergey Prigogin (Google)
|
||||
# Andrew Ferguson (Symbian)
|
||||
###############################################################################
|
||||
|
||||
CEditorPreferencePage_link=C/C++ Editor Preferences. Note that some preferences may be set on the <a href="org.eclipse.ui.preferencePages.GeneralTextEditor">Text Editors</a> preference page.
|
||||
CEditorPreferencePage_link=C/C++ Editor Preferences. General preferences may be set via <a href="org.eclipse.ui.preferencePages.GeneralTextEditor">Text Editors</a>.
|
||||
CEditorPreferencePage_link_tooltip=Show the shared text editor preferences
|
||||
|
||||
CEditorPreferencePage_colors=Synta&x
|
||||
|
@ -191,9 +192,12 @@ CEditorPreferencePage_closeAngularBrackets=<A&ngle> brackets
|
|||
CEditorPreferencePage_closeBraces={B&races}
|
||||
CEditorPreferencePage_wrapStrings=&Wrap automatically
|
||||
CEditorPreferencePage_escapeStrings=Escape text w&hen pasting into a string literal
|
||||
CEditorPreferencePage_GeneralAppearanceGroupTitle=General appearance
|
||||
CEditorPreferencePage_SelectDocToolDescription=Select the documentation tool to be used to determine editor behaviors when no project preference overrides exist
|
||||
CEditorPreferencePage_smartPaste=Adjust &indentation
|
||||
|
||||
CEditorPreferencePage_typing_smartTab= &Tab key indents the current line
|
||||
CEditorPreferencePage_WorkspaceDefaultLabel=Workspace default:
|
||||
|
||||
# Code Formatting
|
||||
CodeFormatterPreferencePage_title=Code Style
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2008 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
|
||||
|
@ -9,6 +9,7 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
* Sergey Prigogin, Google
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.preferences.formatter;
|
||||
|
||||
|
@ -110,7 +111,7 @@ public abstract class CPreview {
|
|||
CTextTools tools= CUIPlugin.getDefault().getTextTools();
|
||||
fPreviewDocument= new Document();
|
||||
fWorkingValues= workingValues;
|
||||
tools.setupCDocumentPartitioner( fPreviewDocument, ICPartitions.C_PARTITIONING);
|
||||
tools.setupCDocumentPartitioner(fPreviewDocument, ICPartitions.C_PARTITIONING, null);
|
||||
|
||||
PreferenceStore prioritizedSettings= new PreferenceStore();
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2008 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,96 @@
|
|||
* 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.
|
||||
* <p>
|
||||
* This scanner stores the color defined by the color preference key into
|
||||
* the color manager under the same key.
|
||||
* </p>
|
||||
* <p>
|
||||
* Preference color key + {@link PreferenceConstants#EDITOR_BOLD_SUFFIX} are used
|
||||
* to retrieve whether the token is rendered in bold.
|
||||
* </p>
|
||||
* <p>
|
||||
* Preference color key + {@link PreferenceConstants#EDITOR_ITALIC_SUFFIX} are used
|
||||
* to retrieve whether the token is rendered in italic.
|
||||
* </p>
|
||||
* <p>
|
||||
* Preference color key + {@link PreferenceConstants#EDITOR_STRIKETHROUGH_SUFFIX} are used
|
||||
* to retrieve whether the token is rendered in strikethrough.
|
||||
* </p>
|
||||
* <p>
|
||||
* Preference color key + {@link PreferenceConstants#EDITOR_UNDERLINE_SUFFIX} are used
|
||||
* to retrieve whether the token is rendered in underline.
|
||||
* </p>
|
||||
* 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 are <code>true</code>,
|
||||
* iff the corresponding token should be rendered bold.
|
||||
*/
|
||||
private String[] fPropertyNamesBold;
|
||||
/**
|
||||
* Preference keys for boolean preferences which are <code>true</code>,
|
||||
* iff the corresponding token should be rendered italic.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
private String[] fPropertyNamesItalic;
|
||||
/**
|
||||
* Preference keys for boolean preferences which are <code>true</code>,
|
||||
* iff the corresponding token should be rendered strikethrough.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
private String[] fPropertyNamesStrikethrough;
|
||||
/**
|
||||
* Preference keys for boolean preferences which are <code>true</code>,
|
||||
* 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.
|
||||
* <p>
|
||||
* The preference key is used access the color in the preference
|
||||
* store and in the color manager.
|
||||
* </p>
|
||||
* <p>
|
||||
* Preference key + {@link PreferenceConstants#EDITOR_BOLD_SUFFIX} is used
|
||||
* to retrieve whether the token is rendered in bold.
|
||||
* </p>
|
||||
* <p>
|
||||
* Preference key + {@link PreferenceConstants#EDITOR_ITALIC_SUFFIX} is used
|
||||
* to retrieve whether the token is rendered in italic.
|
||||
* </p>
|
||||
* <p>
|
||||
* Preference key + {@link PreferenceConstants#EDITOR_UNDERLINE_SUFFIX} is used
|
||||
* to retrieve whether the token is rendered underlined.
|
||||
* </p>
|
||||
* <p>
|
||||
* Preference key + {@link PreferenceConstants#EDITOR_STRIKETHROUGH_SUFFIX} is used
|
||||
* to retrieve whether the token is rendered stricken out.
|
||||
* </p>
|
||||
*/
|
||||
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<IPropertyChangeParticipant> pcps;
|
||||
final protected ITokenStore fTokenStore;
|
||||
|
||||
public AbstractCScanner(ITokenStore tokenStore, int size) {
|
||||
this(tokenStore);
|
||||
setBufferSize(size);
|
||||
}
|
||||
|
||||
protected String getBoldKey(String colorKey) {
|
||||
return colorKey + PreferenceConstants.EDITOR_BOLD_SUFFIX;
|
||||
}
|
||||
|
||||
protected String getItalicKey(String colorKey) {
|
||||
return colorKey + PreferenceConstants.EDITOR_ITALIC_SUFFIX;
|
||||
public AbstractCScanner(ITokenStore tokenStore) {
|
||||
fTokenStore= tokenStore;
|
||||
pcps= new ArrayList<IPropertyChangeParticipant>();
|
||||
}
|
||||
|
||||
protected String getStrikethroughKey(String colorKey) {
|
||||
return colorKey + PreferenceConstants.EDITOR_STRIKETHROUGH_SUFFIX;
|
||||
protected void addPropertyChangeParticipant(IPropertyChangeParticipant participant) {
|
||||
pcps.add(participant);
|
||||
}
|
||||
|
||||
protected String getUnderlineKey(String colorKey) {
|
||||
return colorKey + PreferenceConstants.EDITOR_UNDERLINE_SUFFIX;
|
||||
}
|
||||
|
||||
public IToken nextToken() {
|
||||
if (fNeedsLazyColorLoading)
|
||||
resolveProxyAttributes();
|
||||
return super.nextToken();
|
||||
}
|
||||
|
||||
private void resolveProxyAttributes() {
|
||||
if (fNeedsLazyColorLoading && Display.getCurrent() != null) {
|
||||
for (int i= 0; i < fPropertyNamesColor.length; i++) {
|
||||
addToken(fPropertyNamesColor[i], fPropertyNamesBold[i], fPropertyNamesItalic[i], fPropertyNamesStrikethrough[i], fPropertyNamesUnderline[i]);
|
||||
}
|
||||
fNeedsLazyColorLoading= false;
|
||||
}
|
||||
}
|
||||
|
||||
private void addTokenWithProxyAttribute(String colorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) {
|
||||
fTokenMap.put(colorKey, new Token(createTextAttribute(null, boldKey, italicKey, strikethroughKey, underlineKey)));
|
||||
}
|
||||
|
||||
private void addToken(String colorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) {
|
||||
if (fColorManager != null && colorKey != null && fColorManager.getColor(colorKey) == null) {
|
||||
RGB rgb= PreferenceConverter.getColor(fPreferenceStore, colorKey);
|
||||
if (fColorManager instanceof IColorManagerExtension) {
|
||||
IColorManagerExtension ext= (IColorManagerExtension) fColorManager;
|
||||
ext.unbindColor(colorKey);
|
||||
ext.bindColor(colorKey, rgb);
|
||||
}
|
||||
}
|
||||
|
||||
if (!fNeedsLazyColorLoading)
|
||||
fTokenMap.put(colorKey, new Token(createTextAttribute(colorKey, boldKey, italicKey, strikethroughKey, underlineKey)));
|
||||
else {
|
||||
Token token= ((Token)fTokenMap.get(colorKey));
|
||||
if (token != null)
|
||||
token.setData(createTextAttribute(colorKey, boldKey, italicKey, strikethroughKey, underlineKey));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a text attribute based on the given color, bold, italic, strikethrough and underline preference keys.
|
||||
*
|
||||
* @param colorKey the color preference key
|
||||
* @param boldKey the bold preference key
|
||||
* @param italicKey the italic preference key
|
||||
* @param strikethroughKey the strikethrough preference key
|
||||
* @param underlineKey the italic preference key
|
||||
* @return the created text attribute
|
||||
* @since 3.0
|
||||
* Convenience method for setting the scanner rules with a list rather
|
||||
* than an array.
|
||||
* @param rules
|
||||
*/
|
||||
private TextAttribute createTextAttribute(String colorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) {
|
||||
Color color= null;
|
||||
if (colorKey != null)
|
||||
color= fColorManager.getColor(colorKey);
|
||||
|
||||
int style= fPreferenceStore.getBoolean(boldKey) ? SWT.BOLD : SWT.NORMAL;
|
||||
if (fPreferenceStore.getBoolean(italicKey))
|
||||
style |= SWT.ITALIC;
|
||||
|
||||
if (fPreferenceStore.getBoolean(strikethroughKey))
|
||||
style |= TextAttribute.STRIKETHROUGH;
|
||||
|
||||
if (fPreferenceStore.getBoolean(underlineKey))
|
||||
style |= TextAttribute.UNDERLINE;
|
||||
|
||||
return new TextAttribute(color, null, style);
|
||||
}
|
||||
|
||||
protected Token getToken(String key) {
|
||||
if (fNeedsLazyColorLoading)
|
||||
resolveProxyAttributes();
|
||||
return (Token) fTokenMap.get(key);
|
||||
}
|
||||
|
||||
private void initializeRules() {
|
||||
List rules= createRules();
|
||||
if (rules != null) {
|
||||
public final void setRules(List<IRule> rules) {
|
||||
if(rules==null) {
|
||||
setRules((IRule[])null);
|
||||
} else {
|
||||
IRule[] result= new IRule[rules.size()];
|
||||
rules.toArray(result);
|
||||
setRules(result);
|
||||
setRules(result);
|
||||
}
|
||||
}
|
||||
|
||||
private int indexOf(String property) {
|
||||
if (property != null) {
|
||||
int length= fPropertyNamesColor.length;
|
||||
for (int i= 0; i < length; i++) {
|
||||
if (property.equals(fPropertyNamesColor[i]) || property.equals(fPropertyNamesBold[i]) || property.equals(fPropertyNamesItalic[i]) || property.equals(fPropertyNamesStrikethrough[i]) || property.equals(fPropertyNamesUnderline[i]))
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public boolean affectsBehavior(PropertyChangeEvent event) {
|
||||
return indexOf(event.getProperty()) >= 0;
|
||||
}
|
||||
|
||||
public void adaptToPreferenceChange(PropertyChangeEvent event) {
|
||||
String p= event.getProperty();
|
||||
int index= indexOf(p);
|
||||
Token token= getToken(fPropertyNamesColor[index]);
|
||||
if (fPropertyNamesColor[index].equals(p))
|
||||
adaptToColorChange(token, event);
|
||||
else if (fPropertyNamesBold[index].equals(p))
|
||||
adaptToStyleChange(token, event, SWT.BOLD);
|
||||
else if (fPropertyNamesItalic[index].equals(p))
|
||||
adaptToStyleChange(token, event, SWT.ITALIC);
|
||||
else if (fPropertyNamesStrikethrough[index].equals(p))
|
||||
adaptToStyleChange(token, event, TextAttribute.STRIKETHROUGH);
|
||||
else if (fPropertyNamesUnderline[index].equals(p))
|
||||
adaptToStyleChange(token, event, TextAttribute.UNDERLINE);
|
||||
}
|
||||
|
||||
private void adaptToColorChange(Token token, PropertyChangeEvent event) {
|
||||
RGB rgb= null;
|
||||
|
||||
Object value= event.getNewValue();
|
||||
if (value instanceof RGB)
|
||||
rgb= (RGB) value;
|
||||
else if (value instanceof String)
|
||||
rgb= StringConverter.asRGB((String) value);
|
||||
|
||||
if (rgb != null) {
|
||||
|
||||
String property= event.getProperty();
|
||||
Color color= fColorManager.getColor(property);
|
||||
|
||||
if ((color == null || !rgb.equals(color.getRGB())) && fColorManager instanceof IColorManagerExtension) {
|
||||
IColorManagerExtension ext= (IColorManagerExtension) fColorManager;
|
||||
|
||||
ext.unbindColor(property);
|
||||
ext.bindColor(property, rgb);
|
||||
|
||||
color= fColorManager.getColor(property);
|
||||
}
|
||||
|
||||
Object data= token.getData();
|
||||
if (data instanceof TextAttribute) {
|
||||
TextAttribute oldAttr= (TextAttribute) data;
|
||||
token.setData(new TextAttribute(color, oldAttr.getBackground(), oldAttr.getStyle()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void adaptToStyleChange(Token token, PropertyChangeEvent event, int styleAttribute) {
|
||||
boolean eventValue= false;
|
||||
Object value= event.getNewValue();
|
||||
if (value instanceof Boolean)
|
||||
eventValue= ((Boolean) value).booleanValue();
|
||||
else if (IPreferenceStore.TRUE.equals(value))
|
||||
eventValue= true;
|
||||
|
||||
Object data= token.getData();
|
||||
if (data instanceof TextAttribute) {
|
||||
TextAttribute oldAttr= (TextAttribute) data;
|
||||
boolean activeValue= (oldAttr.getStyle() & styleAttribute) == styleAttribute;
|
||||
if (activeValue != eventValue)
|
||||
token.setData(new TextAttribute(oldAttr.getForeground(), oldAttr.getBackground(), eventValue ? oldAttr.getStyle() | styleAttribute : oldAttr.getStyle() & ~styleAttribute));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns the preference store.
|
||||
*
|
||||
* @return the preference store.
|
||||
*
|
||||
* @since 3.0
|
||||
/*
|
||||
* @see org.eclipse.jface.text.rules.RuleBasedScanner#nextToken()
|
||||
*/
|
||||
protected IPreferenceStore getPreferenceStore() {
|
||||
return fPreferenceStore;
|
||||
public IToken nextToken() {
|
||||
fTokenStore.ensureTokensInitialised();
|
||||
return super.nextToken();
|
||||
}
|
||||
}
|
||||
|
||||
public IToken getToken(String key) {
|
||||
return fTokenStore.getToken(key);
|
||||
}
|
||||
|
||||
public IPreferenceStore getPreferenceStore() {
|
||||
return fTokenStore.getPreferenceStore();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.IPropertyChangeParticipant#adaptToPreferenceChange(org.eclipse.jface.util.PropertyChangeEvent)
|
||||
*/
|
||||
public void adaptToPreferenceChange(PropertyChangeEvent event) {
|
||||
if(fTokenStore.affectsBehavior(event)) {
|
||||
fTokenStore.adaptToPreferenceChange(event);
|
||||
}
|
||||
for(Iterator i= pcps.iterator(); i.hasNext(); ) {
|
||||
((IPropertyChangeParticipant)i.next()).adaptToPreferenceChange(event);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.IPropertyChangeParticipant#affectsBehavior(org.eclipse.jface.util.PropertyChangeEvent)
|
||||
*/
|
||||
public boolean affectsBehavior(PropertyChangeEvent event) {
|
||||
boolean result= fTokenStore.affectsBehavior(event);
|
||||
for(Iterator i= pcps.iterator(); !result && i.hasNext(); ) {
|
||||
result |= ((IPropertyChangeParticipant)i.next()).affectsBehavior(event);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -9,7 +9,8 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
* QNX Software System
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Sergey Prigogin, Google
|
||||
* Sergey Prigogin (Google)
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.text;
|
||||
|
||||
|
@ -44,7 +45,6 @@ import org.eclipse.cdt.internal.ui.editor.IndentUtil;
|
|||
* 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 +1120,20 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
|
|||
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();
|
||||
|
|
|
@ -9,19 +9,20 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
* QNX Software System
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* 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.Token;
|
||||
import org.eclipse.jface.text.rules.IRule;
|
||||
import org.eclipse.jface.text.rules.IToken;
|
||||
import org.eclipse.jface.text.rules.WhitespaceRule;
|
||||
import org.eclipse.jface.text.rules.WordRule;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
|
||||
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,31 +46,22 @@ public final class CCodeScanner extends AbstractCScanner {
|
|||
|
||||
/**
|
||||
* Creates a C/C++ code scanner.
|
||||
*
|
||||
* @param manager the color manager
|
||||
* @param store the reference store
|
||||
* @param factory
|
||||
* @param keywords the keywords defined by the language dialect
|
||||
*/
|
||||
public CCodeScanner(IColorManager manager, IPreferenceStore store, ICLanguageKeywords keywords) {
|
||||
super(manager, store);
|
||||
public CCodeScanner(ITokenStoreFactory factory, ICLanguageKeywords keywords) {
|
||||
super(factory.createTokenStore(fgTokenProperties));
|
||||
fKeywords= keywords;
|
||||
initialize();
|
||||
setRules(createRules());
|
||||
}
|
||||
|
||||
/*
|
||||
* @see AbstractCScanner#getTokenProperties()
|
||||
*/
|
||||
protected String[] getTokenProperties() {
|
||||
return fgTokenProperties;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @see AbstractCScanner#createRules()
|
||||
*/
|
||||
protected List createRules() {
|
||||
protected List<IRule> createRules() {
|
||||
|
||||
List rules= new ArrayList();
|
||||
Token token;
|
||||
List<IRule> rules= new ArrayList<IRule>();
|
||||
IToken token;
|
||||
|
||||
// Add generic white space rule.
|
||||
rules.add(new WhitespaceRule(new CWhitespaceDetector()));
|
||||
|
@ -105,13 +97,4 @@ public final class CCodeScanner extends AbstractCScanner {
|
|||
setDefaultReturnToken(getToken(ICColorConstants.C_DEFAULT));
|
||||
return rules;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see AbstractCScanner#adaptToPreferenceChange(PropertyChangeEvent)
|
||||
*/
|
||||
public void adaptToPreferenceChange(PropertyChangeEvent event) {
|
||||
if (super.affectsBehavior(event)) {
|
||||
super.adaptToPreferenceChange(event);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2008 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,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.jface.text.rules.IRule;
|
||||
|
||||
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 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 boolean isWordStart(char c) {
|
||||
return Character.isLetter(c);
|
||||
}
|
||||
public CCommentScanner(ITokenStoreFactory tokenStoreFactory, Preferences coreStore, String defaultTokenProperty) {
|
||||
this(tokenStoreFactory, coreStore, defaultTokenProperty, new String[] { defaultTokenProperty, TASK_TAG_KEY });
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
private CCommentScanner(ITokenStoreFactory tokenStoreFactory, Preferences coreStore, String defaultTokenProperty, String[] tokenProperties) {
|
||||
super(tokenStoreFactory.createTokenStore(tokenProperties));
|
||||
fCorePreferenceStore= coreStore;
|
||||
setRules(createRules(defaultTokenProperty));
|
||||
}
|
||||
|
||||
protected List<IRule> 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((IRule)taskTagRule);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,26 +46,22 @@ public class CPreprocessorScanner extends AbstractCScanner {
|
|||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.ui.text.AbstractCScanner#createRules()
|
||||
*/
|
||||
protected List createRules() {
|
||||
protected List<IRule> createRules() {
|
||||
IToken defaultToken= getToken(ICColorConstants.PP_DEFAULT);
|
||||
|
||||
Token defaultToken= getToken(ICColorConstants.PP_DEFAULT);
|
||||
|
||||
List rules= new ArrayList();
|
||||
Token token;
|
||||
List<IRule> rules= new ArrayList<IRule>();
|
||||
IToken token;
|
||||
|
||||
// Add generic white space rule.
|
||||
rules.add(new WhitespaceRule(new CWhitespaceDetector()));
|
||||
|
@ -110,12 +107,4 @@ public class CPreprocessorScanner extends AbstractCScanner {
|
|||
setDefaultReturnToken(defaultToken);
|
||||
return rules;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.ui.text.AbstractCScanner#getTokenProperties()
|
||||
*/
|
||||
protected String[] getTokenProperties() {
|
||||
return fgTokenProperties;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ 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 +79,12 @@ import org.eclipse.cdt.ui.CElementContentProvider;
|
|||
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 +98,7 @@ import org.eclipse.cdt.internal.ui.text.c.hover.CMacroExpansionInformationProvid
|
|||
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 +120,11 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
@ -146,24 +155,6 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
initializeScanners();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -184,10 +175,10 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
}
|
||||
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 +241,12 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
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 +263,29 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
|
||||
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,7 +300,33 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
|
||||
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
|
||||
*/
|
||||
|
@ -310,14 +337,14 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
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 +374,12 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
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 +443,46 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
*/
|
||||
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 +497,7 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
* @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 +557,12 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
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 +585,7 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
* @see SourceViewerConfiguration#getTabWidth(ISourceViewer)
|
||||
*/
|
||||
public int getTabWidth(ISourceViewer sourceViewer) {
|
||||
return CodeFormatterUtil.getTabWidth(getProject());
|
||||
return CodeFormatterUtil.getTabWidth(getCProject());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -536,7 +594,7 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
* @return the indent width
|
||||
*/
|
||||
public int getIndentWidth(ISourceViewer sourceViewer) {
|
||||
return CodeFormatterUtil.getIndentWidth(getProject());
|
||||
return CodeFormatterUtil.getIndentWidth(getCProject());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -546,7 +604,7 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
* @return <code>true</code> if spaces should be used for indentation
|
||||
*/
|
||||
public boolean useSpacesOnly(ISourceViewer sourceViewer) {
|
||||
ICProject project= getProject();
|
||||
ICProject project= getCProject();
|
||||
String option;
|
||||
if (project == null)
|
||||
option= CCorePlugin.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR);
|
||||
|
@ -628,7 +686,10 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
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
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -645,8 +706,8 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -739,10 +800,10 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
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))
|
||||
|
@ -858,9 +919,11 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
*/
|
||||
public void resetScanners() {
|
||||
fCodeScanner= null;
|
||||
fMultilineDocCommentScanner= null;
|
||||
fSinglelineDocCommentScanner= null;
|
||||
fPreprocessorScanner= null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates macro exploration presenter.
|
||||
* @param sourceViewer
|
||||
|
@ -898,5 +961,21 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
|||
};
|
||||
return conrolCreator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the IProject associated with this CSourceViewerConfiguration, or null if
|
||||
* no IProject could be determined
|
||||
*/
|
||||
private IProject getProject() {
|
||||
ICProject cproject= getCProject();
|
||||
return cproject!=null ? cproject.getProject() :null;
|
||||
}
|
||||
|
||||
}
|
||||
private ITokenStoreFactory getTokenStoreFactory() {
|
||||
return new ITokenStoreFactory() {
|
||||
public ITokenStore createTokenStore(String[] propertyColorNames) {
|
||||
return new TokenStore(getColorManager(), fPreferenceStore, propertyColorNames);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2008 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
|
||||
|
@ -9,9 +9,14 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
* QNX Software System
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.text;
|
||||
|
||||
import org.eclipse.core.filebuffers.LocationKind;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Preferences;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
|
@ -26,7 +31,11 @@ import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
|
|||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.text.ICPartitions;
|
||||
import org.eclipse.cdt.ui.text.ITokenStore;
|
||||
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
|
||||
import org.eclipse.cdt.internal.ui.text.util.CColorManager;
|
||||
|
||||
|
||||
|
@ -35,14 +44,14 @@ import org.eclipse.cdt.internal.ui.text.util.CColorManager;
|
|||
* its clients.
|
||||
*/
|
||||
public class CTextTools {
|
||||
|
||||
|
||||
private class PreferenceListener implements IPropertyChangeListener, Preferences.IPropertyChangeListener {
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
adaptToPreferenceChange(event);
|
||||
}
|
||||
public void propertyChange(Preferences.PropertyChangeEvent event) {
|
||||
adaptToPreferenceChange(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event.getNewValue()));
|
||||
}
|
||||
public void propertyChange(Preferences.PropertyChangeEvent event) {
|
||||
adaptToPreferenceChange(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event.getNewValue()));
|
||||
}
|
||||
}
|
||||
|
||||
/** The color manager */
|
||||
|
@ -64,57 +73,60 @@ public class CTextTools {
|
|||
|
||||
/** The preference store */
|
||||
private IPreferenceStore fPreferenceStore;
|
||||
/** The core preference store */
|
||||
private Preferences fCorePreferenceStore;
|
||||
/** The core preference store */
|
||||
private Preferences fCorePreferenceStore;
|
||||
/** The preference change listener */
|
||||
private PreferenceListener fPreferenceListener= new PreferenceListener();
|
||||
/** The document partitioning used for the C partitioner */
|
||||
private String fDocumentPartitioning = ICPartitions.C_PARTITIONING;
|
||||
|
||||
/**
|
||||
* Creates a new C text tools collection and eagerly creates
|
||||
* and initializes all members of this collection.
|
||||
*/
|
||||
public CTextTools(IPreferenceStore store) {
|
||||
this(store, null, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new C text tools collection and eagerly creates
|
||||
* and initializes all members of this collection.
|
||||
*/
|
||||
public CTextTools(IPreferenceStore store, Preferences coreStore) {
|
||||
this(store, coreStore, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new C text tools collection and eagerly creates
|
||||
* and initializes all members of this collection.
|
||||
*/
|
||||
public CTextTools(IPreferenceStore store, Preferences coreStore, boolean autoDisposeOnDisplayDispose) {
|
||||
if(store == null) {
|
||||
store = CUIPlugin.getDefault().getPreferenceStore();
|
||||
}
|
||||
fColorManager= new CColorManager(autoDisposeOnDisplayDispose);
|
||||
fCodeScanner= new CCodeScanner(fColorManager, store, GCCLanguage.getDefault());
|
||||
fCppCodeScanner= new CCodeScanner(fColorManager, store, GPPLanguage.getDefault());
|
||||
|
||||
fMultilineCommentScanner= new CCommentScanner(fColorManager, store, coreStore, ICColorConstants.C_MULTI_LINE_COMMENT);
|
||||
fSinglelineCommentScanner= new CCommentScanner(fColorManager, store, coreStore, ICColorConstants.C_SINGLE_LINE_COMMENT);
|
||||
fStringScanner= new SingleTokenCScanner(fColorManager, store, ICColorConstants.C_STRING);
|
||||
fCPreprocessorScanner= new CPreprocessorScanner(fColorManager, store, GCCLanguage.getDefault());
|
||||
fCppPreprocessorScanner= new CPreprocessorScanner(fColorManager, store, GPPLanguage.getDefault());
|
||||
|
||||
fPreferenceStore = store;
|
||||
fPreferenceStore.addPropertyChangeListener(fPreferenceListener);
|
||||
|
||||
fCorePreferenceStore= coreStore;
|
||||
if (fCorePreferenceStore != null) {
|
||||
fCorePreferenceStore.addPropertyChangeListener(fPreferenceListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new C text tools collection and eagerly creates
|
||||
* and initializes all members of this collection.
|
||||
*/
|
||||
public CTextTools(IPreferenceStore store) {
|
||||
this(store, null, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new C text tools collection and eagerly creates
|
||||
* and initializes all members of this collection.
|
||||
*/
|
||||
public CTextTools(IPreferenceStore store, Preferences coreStore) {
|
||||
this(store, coreStore, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new C text tools collection and eagerly creates
|
||||
* and initializes all members of this collection.
|
||||
*/
|
||||
public CTextTools(IPreferenceStore store, Preferences coreStore, boolean autoDisposeOnDisplayDispose) {
|
||||
fPreferenceStore = store != null ? store : CUIPlugin.getDefault().getPreferenceStore();
|
||||
fColorManager= new CColorManager(autoDisposeOnDisplayDispose);
|
||||
|
||||
ITokenStoreFactory factory= new ITokenStoreFactory() {
|
||||
public ITokenStore createTokenStore(String[] propertyColorNames) {
|
||||
return new TokenStore(getColorManager(), fPreferenceStore, propertyColorNames);
|
||||
}
|
||||
};
|
||||
|
||||
fMultilineCommentScanner= new CCommentScanner(factory, coreStore, ICColorConstants.C_MULTI_LINE_COMMENT);
|
||||
fSinglelineCommentScanner= new CCommentScanner(factory, coreStore, ICColorConstants.C_SINGLE_LINE_COMMENT);
|
||||
fCodeScanner= new CCodeScanner(factory, GCCLanguage.getDefault());
|
||||
fCppCodeScanner= new CCodeScanner(factory, GPPLanguage.getDefault());
|
||||
|
||||
fStringScanner= new SingleTokenCScanner(factory, ICColorConstants.C_STRING);
|
||||
fCPreprocessorScanner= new CPreprocessorScanner(factory, GCCLanguage.getDefault());
|
||||
fCppPreprocessorScanner= new CPreprocessorScanner(factory, GPPLanguage.getDefault());
|
||||
|
||||
fPreferenceStore.addPropertyChangeListener(fPreferenceListener);
|
||||
|
||||
fCorePreferenceStore= coreStore;
|
||||
if (fCorePreferenceStore != null) {
|
||||
fCorePreferenceStore.addPropertyChangeListener(fPreferenceListener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new C text tools collection and eagerly creates
|
||||
* and initializes all members of this collection.
|
||||
|
@ -122,83 +134,75 @@ public class CTextTools {
|
|||
public CTextTools() {
|
||||
this((IPreferenceStore)null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disposes all members of this tools collection.
|
||||
*/
|
||||
public void dispose() {
|
||||
|
||||
|
||||
fCodeScanner= null;
|
||||
fMultilineCommentScanner= null;
|
||||
fSinglelineCommentScanner= null;
|
||||
fStringScanner= null;
|
||||
|
||||
|
||||
if (fColorManager != null) {
|
||||
fColorManager.dispose();
|
||||
fColorManager= null;
|
||||
}
|
||||
|
||||
|
||||
if (fPreferenceStore != null) {
|
||||
fPreferenceStore.removePropertyChangeListener(fPreferenceListener);
|
||||
fPreferenceStore= null;
|
||||
|
||||
if (fCorePreferenceStore != null) {
|
||||
fCorePreferenceStore.removePropertyChangeListener(fPreferenceListener);
|
||||
fCorePreferenceStore= null;
|
||||
}
|
||||
|
||||
|
||||
if (fCorePreferenceStore != null) {
|
||||
fCorePreferenceStore.removePropertyChangeListener(fPreferenceListener);
|
||||
fCorePreferenceStore= null;
|
||||
}
|
||||
|
||||
fPreferenceListener= null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the color manager.
|
||||
*/
|
||||
public CColorManager getColorManager() {
|
||||
return fColorManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the code scanner used.
|
||||
*/
|
||||
public RuleBasedScanner getCCodeScanner() {
|
||||
return fCodeScanner;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the code scanner used.
|
||||
*/
|
||||
public RuleBasedScanner getCppCodeScanner() {
|
||||
return fCppCodeScanner;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a scanner which is configured to scan
|
||||
* C-specific partitions, which are multi-line comments,
|
||||
* and regular C source code.
|
||||
*
|
||||
* @param owner may be null
|
||||
* @return a C partition scanner
|
||||
*/
|
||||
public IPartitionTokenScanner getPartitionScanner() {
|
||||
return new FastCPartitionScanner();
|
||||
public IPartitionTokenScanner getPartitionScanner(IDocCommentOwner owner) {
|
||||
return new FastCPartitionScanner(owner);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the document provider used.
|
||||
*/
|
||||
public IDocumentPartitioner createDocumentPartitioner() {
|
||||
|
||||
String[] types= new String[] {
|
||||
ICPartitions.C_MULTI_LINE_COMMENT,
|
||||
ICPartitions.C_SINGLE_LINE_COMMENT,
|
||||
ICPartitions.C_STRING,
|
||||
ICPartitions.C_CHARACTER,
|
||||
ICPartitions.C_PREPROCESSOR
|
||||
};
|
||||
|
||||
return new FastCPartitioner(getPartitionScanner(), types);
|
||||
public IDocumentPartitioner createDocumentPartitioner(IDocCommentOwner owner) {
|
||||
return new FastCPartitioner(getPartitionScanner(owner), ICPartitions.ALL_CPARTITIONS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a scanner which is configured to scan C multiline comments.
|
||||
*
|
||||
|
@ -216,7 +220,7 @@ public class CTextTools {
|
|||
public RuleBasedScanner getSinglelineCommentScanner() {
|
||||
return fSinglelineCommentScanner;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a scanner which is configured to scan C strings.
|
||||
*
|
||||
|
@ -243,7 +247,7 @@ public class CTextTools {
|
|||
public RuleBasedScanner getCppPreprocessorScanner() {
|
||||
return fCppPreprocessorScanner;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the preference change encoded by the given event
|
||||
* changes the behavior of one its contained components.
|
||||
|
@ -253,13 +257,13 @@ public class CTextTools {
|
|||
*/
|
||||
public boolean affectsBehavior(PropertyChangeEvent event) {
|
||||
return fCodeScanner.affectsBehavior(event) ||
|
||||
fCppCodeScanner.affectsBehavior(event) ||
|
||||
fMultilineCommentScanner.affectsBehavior(event) ||
|
||||
fSinglelineCommentScanner.affectsBehavior(event) ||
|
||||
fStringScanner.affectsBehavior(event) ||
|
||||
fCPreprocessorScanner.affectsBehavior(event);
|
||||
fCppCodeScanner.affectsBehavior(event) ||
|
||||
fMultilineCommentScanner.affectsBehavior(event) ||
|
||||
fSinglelineCommentScanner.affectsBehavior(event) ||
|
||||
fStringScanner.affectsBehavior(event) ||
|
||||
fCPreprocessorScanner.affectsBehavior(event);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adapts the behavior of the contained components to the change
|
||||
* encoded in the given event.
|
||||
|
@ -286,12 +290,13 @@ public class CTextTools {
|
|||
/**
|
||||
* Sets up the document partitioner for the given document for the given partitioning.
|
||||
*
|
||||
* @param document the document to be set up
|
||||
* @param partitioning the document partitioning
|
||||
* @since 3.0
|
||||
* @param document
|
||||
* @param partitioning
|
||||
* @param owner may be null
|
||||
* @since 5.0
|
||||
*/
|
||||
public void setupCDocumentPartitioner(IDocument document, String partitioning) {
|
||||
IDocumentPartitioner partitioner= createDocumentPartitioner();
|
||||
public void setupCDocumentPartitioner(IDocument document, String partitioning, IDocCommentOwner owner) {
|
||||
IDocumentPartitioner partitioner= createDocumentPartitioner(owner);
|
||||
if (document instanceof IDocumentExtension3) {
|
||||
IDocumentExtension3 extension3= (IDocumentExtension3) document;
|
||||
extension3.setDocumentPartitioner(partitioning, partitioner);
|
||||
|
@ -300,7 +305,20 @@ public class CTextTools {
|
|||
}
|
||||
partitioner.connect(document);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets up the given document for the default partitioning.
|
||||
*
|
||||
* @param document the document to be set up
|
||||
* @param location the path of the resource backing the document. May be null.
|
||||
* @param locationKind the type of path specified above. May be null.
|
||||
* @since 3.0
|
||||
*/
|
||||
public void setupCDocument(IDocument document, IPath location, LocationKind locationKind) {
|
||||
IDocCommentOwner owner= getDocumentationCommentOwner(location, locationKind);
|
||||
setupCDocumentPartitioner(document, fDocumentPartitioning, owner);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the given document for the default partitioning.
|
||||
*
|
||||
|
@ -308,7 +326,7 @@ public class CTextTools {
|
|||
* @since 3.0
|
||||
*/
|
||||
public void setupCDocument(IDocument document) {
|
||||
setupCDocumentPartitioner(document, fDocumentPartitioning);
|
||||
setupCDocumentPartitioner(document, fDocumentPartitioning, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -329,5 +347,19 @@ public class CTextTools {
|
|||
public void setDocumentPartitioning(String documentPartitioning) {
|
||||
fDocumentPartitioning = documentPartitioning;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param location
|
||||
* @param locationKind
|
||||
* @return the documentation comment owner mapped to the specified location. If there is
|
||||
* no mapping, or the <code>location</code>/<code>locationKind</code> 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
* QNX Software System
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.text;
|
||||
|
||||
|
@ -21,6 +22,7 @@ import org.eclipse.jface.text.rules.IToken;
|
|||
import org.eclipse.jface.text.rules.Token;
|
||||
|
||||
import org.eclipse.cdt.ui.text.ICPartitions;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -38,6 +40,8 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa
|
|||
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 +69,14 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa
|
|||
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 +87,21 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa
|
|||
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,13 +547,18 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa
|
|||
}
|
||||
|
||||
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)) {
|
||||
|
@ -550,15 +569,14 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa
|
|||
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 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa
|
|||
|
||||
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 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa
|
|||
* @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 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa
|
|||
* @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 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.text;
|
||||
|
||||
|
@ -16,6 +17,7 @@ import org.eclipse.jface.text.rules.FastPartitioner;
|
|||
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 +46,30 @@ public class FastCPartitioner extends FastPartitioner {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000 2005 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2008 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,42 +8,36 @@
|
|||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* QNX Software System
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.text;
|
||||
|
||||
import java.util.List;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.rules.IRule;
|
||||
import org.eclipse.jface.text.rules.IToken;
|
||||
import org.eclipse.jface.text.rules.Token;
|
||||
|
||||
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final class SingleTokenCScanner extends AbstractCScanner{
|
||||
|
||||
public final class SingleTokenCScanner extends AbstractCScanner {
|
||||
private String fProperty;
|
||||
private int position, end;
|
||||
private int size;
|
||||
protected IToken fDefaultReturnToken;
|
||||
private String[] fProperty;
|
||||
|
||||
public SingleTokenCScanner(IColorManager manager, IPreferenceStore store, String property) {
|
||||
super(manager, store, 20);
|
||||
fProperty= new String[] { property };
|
||||
initialize();
|
||||
public SingleTokenCScanner(ITokenStoreFactory factory, String property) {
|
||||
super(factory.createTokenStore(new String[] {property}), 20);
|
||||
fProperty= property;
|
||||
setRules(createRules());
|
||||
}
|
||||
|
||||
/*
|
||||
* @see AbstractCScanner#getTokenProperties()
|
||||
*/
|
||||
protected String[] getTokenProperties() {
|
||||
return fProperty;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see AbstractCScanner#createRules()
|
||||
*/
|
||||
protected List createRules() {
|
||||
fDefaultReturnToken= getToken(fProperty[0]);
|
||||
protected List<IRule> createRules() {
|
||||
fDefaultReturnToken= getToken(fProperty);
|
||||
setDefaultReturnToken(fDefaultReturnToken);
|
||||
return null;
|
||||
}
|
||||
|
@ -51,9 +45,6 @@ public final class SingleTokenCScanner extends AbstractCScanner{
|
|||
/**
|
||||
* setRange -- sets the range to be scanned
|
||||
*/
|
||||
|
||||
private int position, end;
|
||||
private int size;
|
||||
public void setRange(IDocument document, int offset, int length) {
|
||||
|
||||
super.setRange(document, offset, length);
|
||||
|
@ -61,13 +52,13 @@ public final class SingleTokenCScanner extends AbstractCScanner{
|
|||
size = length;
|
||||
end = offset + length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next token in the document.
|
||||
*
|
||||
* @return the next token in the document
|
||||
*/
|
||||
public IToken nextToken() {
|
||||
|
||||
fTokenOffset = position;
|
||||
|
||||
if(position < end) {
|
||||
|
@ -81,30 +72,6 @@ public final class SingleTokenCScanner extends AbstractCScanner{
|
|||
public int getTokenLength() {
|
||||
return size;
|
||||
}
|
||||
|
||||
//public int getTokenOffset() {
|
||||
// return position;
|
||||
//}
|
||||
/* while (true) {
|
||||
|
||||
fTokenOffset= fOffset;
|
||||
fColumn= UNDEFINED;
|
||||
|
||||
if (fRules != null) {
|
||||
for (int i= 0; i < fRules.length; i++) {
|
||||
token= (fRules[i].evaluate(this));
|
||||
if (!token.isUndefined())
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
||||
if (read() == EOF)
|
||||
return Token.EOF;
|
||||
else
|
||||
return fDefaultReturnToken;
|
||||
}
|
||||
} */
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,275 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2008 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
|
||||
* Andrew Ferguson (Symbian) - refactored to TokenStore (previously part of AbstractCScanner)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.text;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
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.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.text.ITokenStore;
|
||||
|
||||
|
||||
/**
|
||||
* Maintains a pool of tokens identified by a String ID.
|
||||
* Supports styles per token.
|
||||
* Updates token instances on property changes.
|
||||
*/
|
||||
|
||||
public class TokenStore implements ITokenStore {
|
||||
private IColorManager fColorManager;
|
||||
private IPreferenceStore fPreferenceStore;
|
||||
|
||||
private Map<String, IToken> fTokenMap= new HashMap<String, IToken>();
|
||||
private String[] fPropertyNamesColor;
|
||||
|
||||
private boolean fNeedsLazyColorLoading;
|
||||
|
||||
/**
|
||||
* Maintains tokens for a specified set of property keys. Automatically also
|
||||
* copes with bold, italic, strike-through and underlined versions of the key.
|
||||
* @param manager the IColorManager to retrieve token colors from
|
||||
* @param store the {@link IPreferenceStore} to fetch property preferences from
|
||||
*/
|
||||
public TokenStore(IColorManager manager, IPreferenceStore store, String[] propertyNamesColor) {
|
||||
fColorManager= manager;
|
||||
fPreferenceStore= store;
|
||||
|
||||
fPropertyNamesColor= propertyNamesColor;
|
||||
|
||||
fNeedsLazyColorLoading= Display.getCurrent() == null;
|
||||
for (int i= 0; i < fPropertyNamesColor.length; i++) {
|
||||
if(fPropertyNamesColor[i].endsWith(PreferenceConstants.EDITOR_BOLD_SUFFIX)
|
||||
|| fPropertyNamesColor[i].endsWith(PreferenceConstants.EDITOR_ITALIC_SUFFIX)
|
||||
|| fPropertyNamesColor[i].endsWith(PreferenceConstants.EDITOR_STRIKETHROUGH_SUFFIX)
|
||||
|| fPropertyNamesColor[i].endsWith(PreferenceConstants.EDITOR_UNDERLINE_SUFFIX)) {
|
||||
throw new IllegalArgumentException(); // XXX
|
||||
}
|
||||
if (fNeedsLazyColorLoading)
|
||||
addTokenWithProxyAttribute(fPropertyNamesColor[i]);
|
||||
else
|
||||
addToken(fPropertyNamesColor[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* In the case where at the time of IToken construction, the Display was not
|
||||
* ready to construct colors.
|
||||
*/
|
||||
public void ensureTokensInitialised() {
|
||||
if (fNeedsLazyColorLoading && Display.getCurrent() != null) {
|
||||
for (int i= 0; i < fPropertyNamesColor.length; i++) {
|
||||
addToken(fPropertyNamesColor[i]);
|
||||
}
|
||||
fNeedsLazyColorLoading= false;
|
||||
}
|
||||
}
|
||||
|
||||
private void addTokenWithProxyAttribute(String colorKey) {
|
||||
fTokenMap.put(colorKey, new Token(createTextAttribute(colorKey, true)));
|
||||
}
|
||||
|
||||
private void addToken(String colorKey) {
|
||||
if (fColorManager != null && colorKey != null && fColorManager.getColor(colorKey) == null) {
|
||||
RGB rgb= PreferenceConverter.getColor(fPreferenceStore, colorKey);
|
||||
if (fColorManager instanceof IColorManagerExtension) {
|
||||
IColorManagerExtension ext= (IColorManagerExtension) fColorManager;
|
||||
ext.unbindColor(colorKey);
|
||||
ext.bindColor(colorKey, rgb);
|
||||
}
|
||||
}
|
||||
|
||||
if (!fNeedsLazyColorLoading)
|
||||
fTokenMap.put(colorKey, new Token(createTextAttribute(colorKey, false)));
|
||||
else {
|
||||
Token token= ((Token)fTokenMap.get(colorKey));
|
||||
if (token != null)
|
||||
token.setData(createTextAttribute(colorKey, false));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a text attribute based on the given color, bold, italic, strikethrough and underline preference keys.
|
||||
*
|
||||
* @param colorKey the color preference key
|
||||
* @param boldKey the bold preference key
|
||||
* @param italicKey the italic preference key
|
||||
* @param strikethroughKey the strikethrough preference key
|
||||
* @param underlineKey the italic preference key
|
||||
* @return the created text attribute
|
||||
* @since 3.0
|
||||
*/
|
||||
private TextAttribute createTextAttribute(String colorKey, boolean isNull) {
|
||||
Color color= null;
|
||||
if (!isNull)
|
||||
color= fColorManager.getColor(colorKey);
|
||||
|
||||
String boldKey= colorKey + PreferenceConstants.EDITOR_BOLD_SUFFIX;
|
||||
String italicKey= colorKey + PreferenceConstants.EDITOR_ITALIC_SUFFIX;
|
||||
String strikethroughKey= colorKey + PreferenceConstants.EDITOR_STRIKETHROUGH_SUFFIX;
|
||||
String underlineKey= colorKey + PreferenceConstants.EDITOR_UNDERLINE_SUFFIX;
|
||||
|
||||
int style= fPreferenceStore.getBoolean(boldKey) ? SWT.BOLD : SWT.NORMAL;
|
||||
if (fPreferenceStore.getBoolean(italicKey))
|
||||
style |= SWT.ITALIC;
|
||||
|
||||
if (fPreferenceStore.getBoolean(strikethroughKey))
|
||||
style |= TextAttribute.STRIKETHROUGH;
|
||||
|
||||
if (fPreferenceStore.getBoolean(underlineKey))
|
||||
style |= TextAttribute.UNDERLINE;
|
||||
|
||||
return new TextAttribute(color, null, style);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.ui.text.ITokenStore#getToken(java.lang.String)
|
||||
*/
|
||||
public IToken getToken(String key) {
|
||||
return getTokenInner(key);
|
||||
}
|
||||
|
||||
private Token getTokenInner(String key) {
|
||||
ensureTokensInitialised();
|
||||
return (Token) fTokenMap.get(key);
|
||||
}
|
||||
|
||||
private int indexOf(String property) {
|
||||
if (property != null) {
|
||||
int length= fPropertyNamesColor.length;
|
||||
for (int i= 0; i < length; i++) {
|
||||
if (property.startsWith(fPropertyNamesColor[i])) {
|
||||
int pLength= property.length();
|
||||
if(fPropertyNamesColor[i].length() < pLength) {
|
||||
String end= property.substring(fPropertyNamesColor[i].length());
|
||||
if (end.equals(PreferenceConstants.EDITOR_BOLD_SUFFIX)
|
||||
|| end.equals(PreferenceConstants.EDITOR_ITALIC_SUFFIX)
|
||||
|| end.equals(PreferenceConstants.EDITOR_STRIKETHROUGH_SUFFIX)
|
||||
|| end.equals(PreferenceConstants.EDITOR_UNDERLINE_SUFFIX)) {
|
||||
return i;
|
||||
}
|
||||
} else if (fPropertyNamesColor[i].equals(property)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.ui.IPropertyChangeParticipant#affectsBehavior(org.eclipse.jface.util.PropertyChangeEvent)
|
||||
*/
|
||||
public boolean affectsBehavior(PropertyChangeEvent event) {
|
||||
return indexOf(event.getProperty()) >= 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.ui.IPropertyChangeParticipant#adaptToPreferenceChange(org.eclipse.jface.util.PropertyChangeEvent)
|
||||
*/
|
||||
public void adaptToPreferenceChange(PropertyChangeEvent event) {
|
||||
String property= event.getProperty();
|
||||
int i= indexOf(property);
|
||||
if (property.startsWith(fPropertyNamesColor[i])) {
|
||||
Token token= getTokenInner(fPropertyNamesColor[i]);
|
||||
if(property.length() == fPropertyNamesColor[i].length()) {
|
||||
adaptToColorChange(token, event);
|
||||
} else {
|
||||
String end= property.substring(fPropertyNamesColor[i].length());
|
||||
if (end.equals(PreferenceConstants.EDITOR_BOLD_SUFFIX)) {
|
||||
adaptToStyleChange(token, event, SWT.BOLD);
|
||||
} else if (end.equals(PreferenceConstants.EDITOR_ITALIC_SUFFIX)) {
|
||||
adaptToStyleChange(token, event, SWT.ITALIC);
|
||||
} else if (end.equals(PreferenceConstants.EDITOR_STRIKETHROUGH_SUFFIX)) {
|
||||
adaptToStyleChange(token, event, TextAttribute.STRIKETHROUGH);
|
||||
} else if (end.equals(PreferenceConstants.EDITOR_UNDERLINE_SUFFIX)) {
|
||||
adaptToStyleChange(token, event, TextAttribute.UNDERLINE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void adaptToColorChange(Token token, PropertyChangeEvent event) {
|
||||
RGB rgb= null;
|
||||
|
||||
Object value= event.getNewValue();
|
||||
if (value instanceof RGB)
|
||||
rgb= (RGB) value;
|
||||
else if (value instanceof String)
|
||||
rgb= StringConverter.asRGB((String) value);
|
||||
|
||||
if (rgb != null) {
|
||||
|
||||
String property= event.getProperty();
|
||||
Color color= fColorManager.getColor(property);
|
||||
|
||||
if ((color == null || !rgb.equals(color.getRGB())) && fColorManager instanceof IColorManagerExtension) {
|
||||
IColorManagerExtension ext= (IColorManagerExtension) fColorManager;
|
||||
|
||||
ext.unbindColor(property);
|
||||
ext.bindColor(property, rgb);
|
||||
|
||||
color= fColorManager.getColor(property);
|
||||
}
|
||||
|
||||
Object data= token.getData();
|
||||
if (data instanceof TextAttribute) {
|
||||
TextAttribute oldAttr= (TextAttribute) data;
|
||||
token.setData(new TextAttribute(color, oldAttr.getBackground(), oldAttr.getStyle()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void adaptToStyleChange(Token token, PropertyChangeEvent event, int styleAttribute) {
|
||||
boolean eventValue= false;
|
||||
Object value= event.getNewValue();
|
||||
if (value instanceof Boolean)
|
||||
eventValue= ((Boolean) value).booleanValue();
|
||||
else if (IPreferenceStore.TRUE.equals(value))
|
||||
eventValue= true;
|
||||
|
||||
Object data= token.getData();
|
||||
if (data instanceof TextAttribute) {
|
||||
TextAttribute oldAttr= (TextAttribute) data;
|
||||
boolean activeValue= (oldAttr.getStyle() & styleAttribute) == styleAttribute;
|
||||
if (activeValue != eventValue)
|
||||
token.setData(new TextAttribute(oldAttr.getForeground(), oldAttr.getBackground(), eventValue ? oldAttr.getStyle() | styleAttribute : oldAttr.getStyle() & ~styleAttribute));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the preference store.
|
||||
*
|
||||
* @return the preference store.
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
public IPreferenceStore getPreferenceStore() {
|
||||
return fPreferenceStore;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
/*******************************************************************************
|
||||
* 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 java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.IWorkingCopyManager;
|
||||
import org.eclipse.cdt.ui.text.contentassist.ContentAssistInvocationContext;
|
||||
import org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration;
|
||||
|
||||
|
||||
abstract class AbstractDocCommentProposalComputer implements ICompletionProposalComputer {
|
||||
|
||||
protected abstract IDocCommentViewerConfiguration getConfiguration(IDocCommentOwner owner);
|
||||
|
||||
protected final IDocCommentViewerConfiguration getConfiguration() {
|
||||
IResource resource= getResource();
|
||||
IDocCommentOwner owner= DocCommentOwnerManager.getInstance().getCommentOwner(resource);
|
||||
return getConfiguration(owner);
|
||||
}
|
||||
|
||||
public List computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
|
||||
return getConfiguration().createProposalComputer().computeCompletionProposals(context, monitor);
|
||||
}
|
||||
|
||||
public List computeContextInformation(
|
||||
ContentAssistInvocationContext context, IProgressMonitor monitor) {
|
||||
return getConfiguration().createProposalComputer().computeContextInformation(context, monitor);
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return getConfiguration().createProposalComputer().getErrorMessage();
|
||||
}
|
||||
|
||||
public void sessionEnded() {
|
||||
// XXX
|
||||
}
|
||||
|
||||
public void sessionStarted() {
|
||||
// XXX
|
||||
}
|
||||
|
||||
|
||||
private static IResource getResource() {
|
||||
ITranslationUnit tu= getTranslationUnit();
|
||||
return tu.getResource();
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/*******************************************************************************
|
||||
* 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 DocCommentMultilineProposalComputer extends AbstractDocCommentProposalComputer {
|
||||
protected IDocCommentViewerConfiguration getConfiguration(IDocCommentOwner owner) {
|
||||
return owner.getMultilineConfiguration();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,257 @@
|
|||
/*******************************************************************************
|
||||
* 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 java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IExtension;
|
||||
import org.eclipse.core.runtime.IExtensionPoint;
|
||||
import org.eclipse.core.runtime.IExtensionRegistry;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.osgi.service.prefs.Preferences;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwnershipListener;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration;
|
||||
|
||||
/**
|
||||
* This class manages which IDocCommentOwner's are available in the run-time, and how they map to resources
|
||||
* in projects.
|
||||
* @since 5.0
|
||||
*/
|
||||
public class DocCommentOwnerManager {
|
||||
/** Constants for attributes/elements from the DocCommentOwner extension point */
|
||||
private static final String ELEMENT_OWNER = "owner"; //$NON-NLS-1$
|
||||
private static final String ATTRKEY_OWNER_ID = "id"; //$NON-NLS-1$
|
||||
private static final String ATTRKEY_OWNER_NAME = "name"; //$NON-NLS-1$
|
||||
private static final String ATTRKEY_OWNER_SINGLELINE = "singleline"; //$NON-NLS-1$
|
||||
private static final String ATTRKEY_OWNER_MULTILINE = "multiline"; //$NON-NLS-1$
|
||||
|
||||
private static final String QUALIFIER= CCorePlugin.PLUGIN_ID;
|
||||
private static final String WORKSPACE_DOC_TOOL_NODE= "doctool"; //$NON-NLS-1$
|
||||
private static final String PREFKEY_WORKSPACE_DEFAULT= "workspace.default"; //$NON-NLS-1$
|
||||
|
||||
private static DocCommentOwnerManager singleton;
|
||||
|
||||
public static DocCommentOwnerManager getInstance() {
|
||||
return singleton==null ? singleton= new DocCommentOwnerManager() : singleton;
|
||||
}
|
||||
|
||||
private Map<String, IDocCommentOwner> fOwners;
|
||||
private IDocCommentOwner fWorkspaceOwner;
|
||||
private Map<IProject, ProjectMap> prj2map= new HashMap<IProject, ProjectMap>();
|
||||
private static List<IDocCommentOwnershipListener> fListeners;
|
||||
|
||||
private DocCommentOwnerManager() {
|
||||
fOwners= getCommentOwnerExtensions();
|
||||
fListeners= new ArrayList<IDocCommentOwnershipListener>();
|
||||
|
||||
Preferences prefs= new InstanceScope().getNode(QUALIFIER).node(WORKSPACE_DOC_TOOL_NODE);
|
||||
String id= prefs.get(PREFKEY_WORKSPACE_DEFAULT, NullDocCommentOwner.INSTANCE.getID());
|
||||
fWorkspaceOwner= getOwner(id);
|
||||
if(fWorkspaceOwner == null) {
|
||||
// this could occur if a plug-in is no longer available
|
||||
fWorkspaceOwner= NullDocCommentOwner.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param project a non-null project
|
||||
* @return whether the specified project defines any documentation owner association
|
||||
*/
|
||||
public boolean projectDefinesOwnership(IProject project) {
|
||||
return !getProjectMap(project).isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param owner the non-null doc-comment owner
|
||||
*/
|
||||
public void setWorkspaceCommentOwner(IDocCommentOwner owner) {
|
||||
if(owner == null)
|
||||
throw new IllegalArgumentException();
|
||||
IDocCommentOwner old= fWorkspaceOwner;
|
||||
fWorkspaceOwner= owner;
|
||||
|
||||
Preferences prefs= new InstanceScope().getNode(QUALIFIER).node(WORKSPACE_DOC_TOOL_NODE);
|
||||
prefs.put(PREFKEY_WORKSPACE_DEFAULT, owner.getID());
|
||||
|
||||
fireWorkspaceOwnershipChanged(old, fWorkspaceOwner);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the doc comment owner associated with the workspace. If non
|
||||
* is set, the {@link NullDocCommentOwner} is returned.
|
||||
*/
|
||||
public IDocCommentOwner getWorkspaceCommentOwner() {
|
||||
return fWorkspaceOwner;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param resource May be null.
|
||||
* @return a non-null IDocCommentOwner. If the resource was null, the {@link NullDocCommentOwner} is returned.
|
||||
*/
|
||||
public IDocCommentOwner getCommentOwner(IResource resource) {
|
||||
if(resource==null)
|
||||
return NullDocCommentOwner.INSTANCE;
|
||||
|
||||
if(ResourcesPlugin.getWorkspace().getRoot().equals(resource))
|
||||
return getWorkspaceCommentOwner();
|
||||
|
||||
ProjectMap pm= getProjectMap(resource);
|
||||
String ownerID= pm.getOwnerID(resource);
|
||||
IDocCommentOwner result= getOwner(ownerID);
|
||||
return result == null ? fWorkspaceOwner : result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @return the {@link IDocCommentOwner} with the specified id, or null
|
||||
*/
|
||||
public IDocCommentOwner getOwner(String id) {
|
||||
if(NullDocCommentOwner.INSTANCE.getID().equals(id)) {
|
||||
return NullDocCommentOwner.INSTANCE;
|
||||
}
|
||||
return fOwners.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource a non-null resource to map a comment owner to
|
||||
* @param owner the new owner to assign, or null to inherit the parent's mapping
|
||||
* @param removeSubMappings if the resource is an {@link IContainer}, then remove any mappings
|
||||
* children have. <em>This is currently unimplemented.</em>
|
||||
*/
|
||||
/*
|
||||
* Note - this implementation currently ignores removeSubMappings.
|
||||
*/
|
||||
public void setCommentOwner(IResource resource, IDocCommentOwner owner, boolean removeSubMappings) {
|
||||
Assert.isNotNull(resource);
|
||||
|
||||
if(ResourcesPlugin.getWorkspace().getRoot().equals(resource)) {
|
||||
setWorkspaceCommentOwner(owner);
|
||||
return;
|
||||
}
|
||||
|
||||
ProjectMap pm= getProjectMap(resource);
|
||||
IDocCommentOwner old= getCommentOwner(resource);
|
||||
pm.setCommentOwner(resource, owner);
|
||||
IDocCommentOwner n3w= getCommentOwner(resource);
|
||||
fireOwnershipChanged(resource, removeSubMappings, old, n3w);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return any comment owners registered against the extension point. This does not include
|
||||
* the null comment processor.
|
||||
*/
|
||||
public IDocCommentOwner[] getRegisteredOwners() {
|
||||
return fOwners.values().toArray(new IDocCommentOwner[fOwners.values().size()]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param listener registers a listener for doc-comment ownership events
|
||||
*/
|
||||
public void addListener(IDocCommentOwnershipListener listener) {
|
||||
if(!fListeners.contains(listener)) {
|
||||
fListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param listener removes a listener from those registered for doc-comment ownership events
|
||||
*/
|
||||
public void removeListener(IDocCommentOwnershipListener listener) {
|
||||
fListeners.add(listener);
|
||||
}
|
||||
|
||||
/*
|
||||
* Utilities
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param resource a non-null resource
|
||||
* @return the cached (or newly obtained) ProjectMap for the resources
|
||||
* associated project.
|
||||
*/
|
||||
private ProjectMap getProjectMap(IResource resource) {
|
||||
Assert.isNotNull(resource);
|
||||
IProject project= resource.getProject();
|
||||
|
||||
if(!prj2map.containsKey(project)) {
|
||||
prj2map.put(project, new ProjectMap(project));
|
||||
}
|
||||
|
||||
return prj2map.get(project);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a map of ID to {@link IDocCommentOwner} for comment owners registered
|
||||
* via the DocCommentOwner extension point
|
||||
*/
|
||||
private static Map<String, IDocCommentOwner> getCommentOwnerExtensions() {
|
||||
Map<String, IDocCommentOwner> result= new HashMap<String, IDocCommentOwner>();
|
||||
|
||||
IExtensionRegistry registry = Platform.getExtensionRegistry();
|
||||
IExtensionPoint indexProviders = registry.getExtensionPoint(CUIPlugin.ID_COMMENT_OWNER);
|
||||
IExtension[] extensions = indexProviders.getExtensions();
|
||||
for(int i=0; i<extensions.length; i++) {
|
||||
IExtension extension = extensions[i];
|
||||
try {
|
||||
IConfigurationElement[] ce = extension.getConfigurationElements();
|
||||
for(int j=0; j<ce.length; j++) {
|
||||
if(ce[j].getName().equals(ELEMENT_OWNER)) {
|
||||
IDocCommentViewerConfiguration multi = (IDocCommentViewerConfiguration) ce[j].createExecutableExtension(ATTRKEY_OWNER_MULTILINE);
|
||||
IDocCommentViewerConfiguration single = (IDocCommentViewerConfiguration) ce[j].createExecutableExtension(ATTRKEY_OWNER_SINGLELINE);
|
||||
String id= ce[j].getAttribute(ATTRKEY_OWNER_ID);
|
||||
String name= ce[j].getAttribute(ATTRKEY_OWNER_NAME);
|
||||
if(result.put(id, new DocCommentOwner(id, name, multi, single))!=null) {
|
||||
String msg= MessageFormat.format(Messages.DocCommentOwnerManager_DuplicateMapping0, id);
|
||||
CCorePlugin.log(new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID, msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(CoreException ce) {
|
||||
CCorePlugin.log(ce);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void fireOwnershipChanged(IResource resource, boolean recursive, IDocCommentOwner old, IDocCommentOwner n3w) {
|
||||
for(Iterator i= fListeners.iterator(); i.hasNext();) {
|
||||
((IDocCommentOwnershipListener)i.next()).ownershipChanged(resource, recursive, old, n3w);
|
||||
}
|
||||
}
|
||||
|
||||
private void fireWorkspaceOwnershipChanged(IDocCommentOwner old, IDocCommentOwner n3w) {
|
||||
for(Iterator i= fListeners.iterator(); i.hasNext();) {
|
||||
((IDocCommentOwnershipListener)i.next()).workspaceOwnershipChanged(old, n3w);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/*******************************************************************************
|
||||
* 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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*******************************************************************************
|
||||
* 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 java.net.URL;
|
||||
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentSimpleDictionary;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.spelling.engine.AbstractSpellDictionary;
|
||||
import org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellDictionary;
|
||||
|
||||
/**
|
||||
* Adapter from interim public {@link IDocCommentSimpleDictionary} to internal {@link ISpellDictionary}
|
||||
*/
|
||||
public class DocCommentSpellDictionary extends AbstractSpellDictionary {
|
||||
|
||||
protected IDocCommentSimpleDictionary fDict;
|
||||
|
||||
/**
|
||||
* @param dict
|
||||
*/
|
||||
public DocCommentSpellDictionary(IDocCommentSimpleDictionary dict) {
|
||||
Assert.isNotNull(dict);
|
||||
fDict= dict;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.ui.text.spelling.engine.AbstractSpellDictionary#getName()
|
||||
*/
|
||||
protected final URL getURL() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.text.spelling.engine.AbstractSpellDictionary#load(java.net.URL)
|
||||
*/
|
||||
protected synchronized boolean load(final URL url) {
|
||||
unload();
|
||||
|
||||
String[] words= fDict.getAdditionalWords();
|
||||
for(int i=0; i<words.length; i++)
|
||||
hashWord(words[i]);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,179 @@
|
|||
/*******************************************************************************
|
||||
* 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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IEditorReference;
|
||||
import org.eclipse.ui.IFileEditorInput;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.progress.WorkbenchJob;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwnershipListener;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput;
|
||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
|
||||
|
||||
/**
|
||||
* Listens to change in doc-comment ownership and reinitializes
|
||||
* the editors (or a safe superset of) that need reopening.
|
||||
*/
|
||||
public class EditorReopener implements IDocCommentOwnershipListener {
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.text.doctools.IDocCommentOwnershipListener#ownershipChanged(org.eclipse.core.resources.IResource, boolean, org.eclipse.cdt.ui.text.doctools.IDocCommentOwner, org.eclipse.cdt.ui.text.doctools.IDocCommentOwner)
|
||||
*/
|
||||
public void ownershipChanged(IResource resource, boolean recursive,
|
||||
IDocCommentOwner old, IDocCommentOwner newOwner) {
|
||||
IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
||||
if(window!=null) {
|
||||
try {
|
||||
IEditorPart[] parts= getEditorsToRepon(window, resource);
|
||||
if(queryIfNeeded(window.getShell(), parts)) {
|
||||
reopenEditors(window, parts);
|
||||
}
|
||||
} catch(CoreException ce) {
|
||||
CCorePlugin.log(ce);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.text.doctools.IDocCommentOwnershipListener#workspaceOwnershipChanged(org.eclipse.cdt.ui.text.doctools.IDocCommentOwner, org.eclipse.cdt.ui.text.doctools.IDocCommentOwner)
|
||||
*/
|
||||
public void workspaceOwnershipChanged(IDocCommentOwner old, IDocCommentOwner newOwner) {
|
||||
IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
||||
if(window!=null) {
|
||||
try {
|
||||
IEditorPart[] parts= getEditorsToRepon(window, null);
|
||||
if(queryIfNeeded(window.getShell(), parts)) {
|
||||
reopenEditors(window, parts);
|
||||
}
|
||||
} catch(CoreException ce) {
|
||||
CCorePlugin.log(ce);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param window
|
||||
* @param resource may be null to indicate all CDT editors should be reopened
|
||||
* @return an array of {@link IEditorPart} objects that might need to be reinitialized
|
||||
* based on doc-comment ownership of the specified resource changing
|
||||
*/
|
||||
/*
|
||||
* This could be smarter in determining smaller sets of editors to re-open
|
||||
*/
|
||||
private IEditorPart[] getEditorsToRepon(IWorkbenchWindow window, IResource resource) {
|
||||
List<IEditorPart> needReopening= new ArrayList<IEditorPart>();
|
||||
if(window.getActivePage()!=null) {
|
||||
IEditorReference[] es= window.getActivePage().getEditorReferences();
|
||||
for(int i=0; i<es.length; i++) {
|
||||
IEditorPart part= es[i].getEditor(false);
|
||||
if(part!=null) {
|
||||
IEditorInput iei= part.getEditorInput();
|
||||
if(resource!=null) {
|
||||
if(iei instanceof IFileEditorInput) {
|
||||
IFile file= ((IFileEditorInput) iei).getFile();
|
||||
IProject project= resource.getProject();
|
||||
if(file.getProject().equals(project) && CoreModel.hasCNature(project)) {
|
||||
needReopening.add(part);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(iei instanceof ITranslationUnitEditorInput || iei instanceof IFileEditorInput) {
|
||||
needReopening.add(part);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return needReopening.toArray(new IEditorPart[needReopening.size()]);
|
||||
}
|
||||
|
||||
private boolean queryIfNeeded(Shell shell, IEditorPart[] editorParts) throws CoreException {
|
||||
boolean anyUnsaved= false;
|
||||
for(int j=0; j<editorParts.length; j++)
|
||||
if(editorParts[j].isSaveOnCloseNeeded())
|
||||
anyUnsaved= true;
|
||||
|
||||
boolean saveAndReopen= !anyUnsaved;
|
||||
if(anyUnsaved) {
|
||||
String title= Messages.EditorReopener_ShouldSave_Title;
|
||||
String msg= Messages.EditorReopener_ShouldSave_Message;
|
||||
|
||||
if (MessageDialog.openQuestion(shell, title, msg))
|
||||
saveAndReopen= true;
|
||||
}
|
||||
return saveAndReopen;
|
||||
}
|
||||
|
||||
private void reopenEditors(final IWorkbenchWindow window, final IEditorPart[] editorParts) throws CoreException {
|
||||
WorkbenchJob job= new WorkbenchJob(Messages.EditorReopener_ReopenJobStart) {
|
||||
public IStatus runInUIThread(IProgressMonitor monitor) {
|
||||
IEditorPart oldActive= window.getActivePage().getActiveEditor();
|
||||
IEditorPart newActive= null;
|
||||
|
||||
for(int j=0; j<editorParts.length; j++) {
|
||||
IEditorPart oldPart= editorParts[j];
|
||||
oldPart.doSave(new NullProgressMonitor());
|
||||
window.getActivePage().closeEditor(oldPart, false);
|
||||
IEditorInput oldInput= oldPart.getEditorInput();
|
||||
|
||||
try {
|
||||
IEditorPart newPart= null;
|
||||
if(oldInput instanceof IFileEditorInput) {
|
||||
newPart= EditorUtility.openInEditor(((IFileEditorInput)oldInput).getFile());
|
||||
} else if(oldInput instanceof ExternalEditorInput) {
|
||||
ExternalEditorInput eei= (ExternalEditorInput) oldInput;
|
||||
ICElement element= CoreModel.getDefault().create(eei.getMarkerResource());
|
||||
newPart= EditorUtility.openInEditor(eei.getPath(null), element);
|
||||
}
|
||||
if(oldPart == oldActive)
|
||||
newActive= newPart;
|
||||
} catch(PartInitException pie) {
|
||||
CCorePlugin.log(pie);
|
||||
} catch(CModelException cme) {
|
||||
CCorePlugin.log(cme);
|
||||
}
|
||||
}
|
||||
|
||||
if(newActive != null) {
|
||||
window.getActivePage().activate(newActive);
|
||||
}
|
||||
return new Status(IStatus.OK, CUIPlugin.PLUGIN_ID, Messages.EditorReopener_ReopenJobComplete);
|
||||
}
|
||||
};
|
||||
job.schedule();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*******************************************************************************
|
||||
* 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.osgi.util.NLS;
|
||||
|
||||
public class Messages extends NLS {
|
||||
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.text.doctools.messages"; //$NON-NLS-1$
|
||||
public static String DocCommentOwnerManager_DuplicateMapping0;
|
||||
public static String EditorReopener_ReopenJobComplete;
|
||||
public static String EditorReopener_ReopenJobStart;
|
||||
public static String EditorReopener_ShouldSave_Message;
|
||||
public static String EditorReopener_ShouldSave_Title;
|
||||
public static String NullDocCommentOwner_Name;
|
||||
static {
|
||||
// initialize resource bundle
|
||||
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||
}
|
||||
|
||||
private Messages() {
|
||||
}
|
||||
}
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/*******************************************************************************
|
||||
* 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.jface.text.IAutoEditStrategy;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.ITextDoubleClickStrategy;
|
||||
|
||||
import org.eclipse.cdt.ui.text.ICTokenScanner;
|
||||
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
|
||||
import org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentDictionary;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration;
|
||||
|
||||
public class NullDocCommentViewerConfiguration implements IDocCommentViewerConfiguration {
|
||||
public static final IDocCommentViewerConfiguration INSTANCE= new NullDocCommentViewerConfiguration();
|
||||
|
||||
public NullDocCommentViewerConfiguration() {
|
||||
}
|
||||
|
||||
public IAutoEditStrategy createAutoEditStrategy() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICTokenScanner createCommentScanner(ITokenStoreFactory tokenStoreFactory) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ITextDoubleClickStrategy createDoubleClickStrategy() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICompletionProposalComputer createProposalComputer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isDocumentationComment(IDocument doc, int offset, int length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public IDocCommentDictionary getSpellingDictionary() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,178 @@
|
|||
/*******************************************************************************
|
||||
* 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 java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.ICDescriptor;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
|
||||
|
||||
/**
|
||||
* A ProjectMap is an internal abstraction which
|
||||
* <ul>
|
||||
* <li>Maintains mappings from project relative paths to comment-owner ID's
|
||||
* <li>Manages persistence of these mappings to the .cproject file.
|
||||
* </ul>
|
||||
* for a particular {@link IProject}
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
class ProjectMap {
|
||||
/** .cproject xml element/attribute names **/
|
||||
private static final String ATTRVAL_STORAGEID= "org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"; //$NON-NLS-1$
|
||||
private static final String ELEMENT_DOC_COMMENT_OWNER = "doc-comment-owner"; //$NON-NLS-1$
|
||||
private static final String ATTRKEY_DCO_ID = "id"; //$NON-NLS-1$
|
||||
private static final String ELEMENT_PATH = "path"; //$NON-NLS-1$
|
||||
private static final String ATTRKEY_PATH_VALUE = "value"; //$NON-NLS-1$
|
||||
|
||||
private IProject fProject;
|
||||
private Map<IPath, String> fMap;
|
||||
|
||||
/**
|
||||
* Loads the project map
|
||||
* @param project
|
||||
*/
|
||||
public ProjectMap(IProject project) {
|
||||
try {
|
||||
fMap= load(project);
|
||||
} catch(CoreException ce) {
|
||||
CUIPlugin.getDefault().log(ce);
|
||||
fMap= new HashMap<IPath, String>();
|
||||
}
|
||||
fProject= project;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id of the doc comment owner mapped to the resource specified, or null
|
||||
* if no owner is mapped within this project. Ownership is inherited from parents and
|
||||
* may be overridden.
|
||||
* @param resource
|
||||
* @return possibly null
|
||||
*/
|
||||
public String getOwnerID(IResource resource) {
|
||||
String id= null;
|
||||
if(resource!=null) {
|
||||
for(IPath p= resource.getProjectRelativePath(); ; p= p.removeLastSegments(1)) {
|
||||
if(fMap.containsKey(p)) {
|
||||
id= fMap.get(p);
|
||||
break;
|
||||
}
|
||||
if(p.isEmpty())
|
||||
break;
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new (or updates the existing) mapping associating the specified
|
||||
* {@link IDocCommentOwner} with the specified {@link IResource}
|
||||
* @param resource the non-null resource to create an association for
|
||||
* @param owner the owner to associate the resource with, or <code>null</code> 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<IPath, String> load(IProject project) throws CoreException {
|
||||
Map<IPath, String> result= new HashMap<IPath, String>();
|
||||
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; i<commentOwners.getLength(); i++) {
|
||||
Element node= (Element) commentOwners.item(i);
|
||||
Node commentOwnerIDNode= node.getAttributes().getNamedItem(ATTRKEY_DCO_ID);
|
||||
|
||||
if(commentOwnerIDNode != null) {
|
||||
String commentOwnerID= commentOwnerIDNode.getNodeValue();
|
||||
|
||||
NodeList paths= node.getElementsByTagName(ELEMENT_PATH);
|
||||
for(int j=0; j<paths.getLength(); j++) {
|
||||
Node path= paths.item(i);
|
||||
Node pathValue= path.getAttributes().getNamedItem(ATTRKEY_PATH_VALUE);
|
||||
if(pathValue != null) {
|
||||
result.put(Path.fromPortableString(pathValue.getNodeValue()), commentOwnerID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the map to the .cproject file
|
||||
*/
|
||||
public void save() throws CoreException {
|
||||
ICDescriptor pd= CCorePlugin.getDefault().getCProjectDescription(fProject, true);
|
||||
|
||||
// remove current associations
|
||||
Element data= pd.getProjectData(ATTRVAL_STORAGEID);
|
||||
NodeList nl= data.getChildNodes();
|
||||
for(int i=0; i<nl.getLength(); i++) {
|
||||
Node node= nl.item(i);
|
||||
if(node.getNodeType()== Node.ELEMENT_NODE) {
|
||||
data.removeChild(node);
|
||||
}
|
||||
}
|
||||
|
||||
// invert and persist associations
|
||||
for(Iterator i= fMap.values().iterator(); i.hasNext();) {
|
||||
String cid= (String) i.next();
|
||||
Element commentNode= data.getOwnerDocument().createElement(ELEMENT_DOC_COMMENT_OWNER);
|
||||
commentNode.setAttribute(ATTRKEY_DCO_ID, cid);
|
||||
for(Iterator j= fMap.keySet().iterator(); j.hasNext(); ) {
|
||||
IPath path= (IPath) j.next();
|
||||
String ccid= fMap.get(path);
|
||||
if(cid.equals(ccid)) {
|
||||
Element pathNode= data.getOwnerDocument().createElement(ELEMENT_PATH);
|
||||
pathNode.setAttribute(ATTRKEY_PATH_VALUE, path.toPortableString());
|
||||
commentNode.appendChild(pathNode);
|
||||
}
|
||||
}
|
||||
data.appendChild(commentNode);
|
||||
}
|
||||
pd.saveProjectData();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
DocCommentOwnerManager_DuplicateMapping0=More than one DocCommentOwner extension is registered for ID {0}
|
||||
EditorReopener_ReopenJobComplete=Re-initializing editors complete
|
||||
EditorReopener_ReopenJobStart=Re-initializing editors
|
||||
EditorReopener_ShouldSave_Message=To react to this change, its necessary to reinitialize some unsaved editors. If you continue they will be saved automatically and reopened. Continue?
|
||||
EditorReopener_ShouldSave_Title=Unsaved editors need reopening
|
||||
NullDocCommentOwner_Name=None
|
|
@ -10,6 +10,7 @@
|
|||
* Anton Leherbauer (Wind River Systems)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Elazar Leibovich (IDF) - Code folding of compound statements (bug 174597)
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.text.folding;
|
||||
|
@ -168,7 +169,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
|
||||
private ISourceReference fFirstType;
|
||||
private boolean fHasHeaderComment;
|
||||
private LinkedHashMap fMap= new LinkedHashMap();
|
||||
private LinkedHashMap<CProjectionAnnotation,Position> fMap= new LinkedHashMap<CProjectionAnnotation,Position>();
|
||||
private IASTTranslationUnit fAST;
|
||||
|
||||
FoldingStructureComputationContext(IDocument document, ProjectionAnnotationModel model, boolean allowCollapsing) {
|
||||
|
@ -840,9 +841,9 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
fSelectionListener= null;
|
||||
}
|
||||
|
||||
Map additions= new HashMap();
|
||||
List deletions= new ArrayList();
|
||||
List updates= new ArrayList();
|
||||
Map<CProjectionAnnotation,Position> additions= new HashMap<CProjectionAnnotation,Position>();
|
||||
List<CProjectionAnnotation> deletions= new ArrayList<CProjectionAnnotation>();
|
||||
List<CProjectionAnnotation> updates= new ArrayList<CProjectionAnnotation>();
|
||||
|
||||
computeFoldingStructure(ctx);
|
||||
Map updated= ctx.fMap;
|
||||
|
@ -923,12 +924,13 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
* result is that more annotations are changed and fewer get
|
||||
* deleted/re-added.
|
||||
*/
|
||||
private void match(List deletions, Map additions, List changes, FoldingStructureComputationContext ctx) {
|
||||
private void match(List<CProjectionAnnotation> deletions, Map additions,
|
||||
List<CProjectionAnnotation> changes, FoldingStructureComputationContext ctx) {
|
||||
if (deletions.isEmpty() || (additions.isEmpty() && changes.isEmpty()))
|
||||
return;
|
||||
|
||||
List newDeletions= new ArrayList();
|
||||
List newChanges= new ArrayList();
|
||||
List<CProjectionAnnotation> newDeletions= new ArrayList<CProjectionAnnotation>();
|
||||
List<CProjectionAnnotation> newChanges= new ArrayList<CProjectionAnnotation>();
|
||||
|
||||
Iterator deletionIterator= deletions.iterator();
|
||||
while (deletionIterator.hasNext()) {
|
||||
|
@ -1014,7 +1016,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
|
||||
private Map computeCurrentStructure(FoldingStructureComputationContext ctx) {
|
||||
boolean includeBranches= fPreprocessorBranchFoldingEnabled && ctx.fAST != null;
|
||||
Map map= new HashMap();
|
||||
Map<Object, List<Tuple>> map= new HashMap<Object, List<Tuple>>();
|
||||
ProjectionAnnotationModel model= ctx.getModel();
|
||||
Iterator e= model.getAnnotationIterator();
|
||||
while (e.hasNext()) {
|
||||
|
@ -1026,22 +1028,21 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
}
|
||||
Position position= model.getPosition(cAnnotation);
|
||||
Assert.isNotNull(position);
|
||||
List list= (List) map.get(cAnnotation.getElement());
|
||||
List<Tuple> list= map.get(cAnnotation.getElement());
|
||||
if (list == null) {
|
||||
list= new ArrayList(2);
|
||||
list= new ArrayList<Tuple>(2);
|
||||
map.put(cAnnotation.getElement(), list);
|
||||
}
|
||||
list.add(new Tuple(cAnnotation, position));
|
||||
}
|
||||
}
|
||||
|
||||
Comparator comparator= new Comparator() {
|
||||
public int compare(Object o1, Object o2) {
|
||||
return ((Tuple) o1).position.getOffset() - ((Tuple) o2).position.getOffset();
|
||||
Comparator<Tuple> comparator= new Comparator<Tuple>() {
|
||||
public int compare(Tuple t1, Tuple t2) {
|
||||
return t1.position.getOffset() - t2.position.getOffset();
|
||||
}
|
||||
};
|
||||
for (Iterator it= map.values().iterator(); it.hasNext();) {
|
||||
List list= (List) it.next();
|
||||
for(List<Tuple> list : map.values()) {
|
||||
Collections.sort(list, comparator);
|
||||
}
|
||||
return map;
|
||||
|
@ -1116,7 +1117,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
* @param ctx
|
||||
*/
|
||||
private void computeStatementFoldingStructure(IASTTranslationUnit ast, FoldingStructureComputationContext ctx) {
|
||||
final Stack iral = new Stack();
|
||||
final Stack<ModifiableRegionExtra> iral= new Stack<ModifiableRegionExtra>();
|
||||
ast.accept(new ASTVisitor() {
|
||||
{
|
||||
shouldVisitStatements = true;
|
||||
|
@ -1181,7 +1182,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
if (!(tmpstmt instanceof IASTCaseStatement || tmpstmt instanceof IASTDefaultStatement)) {
|
||||
if (!pushedMR) return PROCESS_SKIP;
|
||||
IASTFileLocation tmpfl = tmpstmt.getFileLocation();
|
||||
tmpmr = (ModifiableRegionExtra) iral.peek();
|
||||
tmpmr = iral.peek();
|
||||
tmpmr.setLength(tmpfl.getNodeLength()+tmpfl.getNodeOffset()-tmpmr.getOffset());
|
||||
if (tmpstmt instanceof IASTBreakStatement) pushedMR = false;
|
||||
continue;
|
||||
|
@ -1243,7 +1244,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
}
|
||||
});
|
||||
while (!iral.empty()) {
|
||||
ModifiableRegionExtra mr = (ModifiableRegionExtra) iral.pop();
|
||||
ModifiableRegionExtra mr = iral.pop();
|
||||
IRegion aligned = alignRegion(mr, ctx,mr.inclusive);
|
||||
if (aligned != null) {
|
||||
Position alignedPos= new Position(aligned.getOffset(), aligned.getLength());
|
||||
|
@ -1286,8 +1287,8 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
*/
|
||||
private void computePreprocessorFoldingStructure(IASTTranslationUnit ast,
|
||||
FoldingStructureComputationContext ctx, String fileName) {
|
||||
List branches = new ArrayList();
|
||||
Stack branchStack = new Stack();
|
||||
List<Branch> branches = new ArrayList<Branch>();
|
||||
Stack<Branch> branchStack = new Stack<Branch>();
|
||||
|
||||
IASTPreprocessorStatement[] preprocStmts = ast.getAllPreprocessorStatements();
|
||||
|
||||
|
@ -1315,7 +1316,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
// #else without #if
|
||||
continue;
|
||||
}
|
||||
Branch branch= (Branch)branchStack.pop();
|
||||
Branch branch= branchStack.pop();
|
||||
IASTPreprocessorElseStatement elseStmt = (IASTPreprocessorElseStatement)statement;
|
||||
branchStack.push(new Branch(stmtLocation.getNodeOffset(), elseStmt.taken()));
|
||||
branch.setEndOffset(stmtLocation.getNodeOffset());
|
||||
|
@ -1325,7 +1326,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
// #elif without #if
|
||||
continue;
|
||||
}
|
||||
Branch branch= (Branch)branchStack.pop();
|
||||
Branch branch= branchStack.pop();
|
||||
IASTPreprocessorElifStatement elifStmt = (IASTPreprocessorElifStatement) statement;
|
||||
branchStack.push(new Branch(stmtLocation.getNodeOffset(), elifStmt.taken()));
|
||||
branch.setEndOffset(stmtLocation.getNodeOffset());
|
||||
|
@ -1335,7 +1336,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
// #endif without #if
|
||||
continue;
|
||||
}
|
||||
Branch branch= (Branch)branchStack.pop();
|
||||
Branch branch= branchStack.pop();
|
||||
branch.setEndOffset(stmtLocation.getNodeOffset() + stmtLocation.getNodeLength());
|
||||
branch.setInclusive(true);
|
||||
branches.add(branch);
|
||||
|
@ -1379,12 +1380,13 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
IDocument doc= ctx.getDocument();
|
||||
int startLine = -1;
|
||||
int endLine = -1;
|
||||
List comments= new ArrayList();
|
||||
List<Tuple> comments= new ArrayList<Tuple>();
|
||||
ModifiableRegion commentRange = new ModifiableRegion();
|
||||
for (int i = 0; i < partitions.length; i++) {
|
||||
ITypedRegion partition = partitions[i];
|
||||
boolean singleLine= false;
|
||||
if (ICPartitions.C_MULTI_LINE_COMMENT.equals(partition.getType())) {
|
||||
if (ICPartitions.C_MULTI_LINE_COMMENT.equals(partition.getType())
|
||||
|| ICPartitions.C_MULTI_LINE_DOC_COMMENT.equals(partition.getType())) {
|
||||
Position position= createCommentPosition(alignRegion(partition, ctx, true));
|
||||
if (position != null) {
|
||||
if (startLine >= 0 && endLine - startLine >= fMinCommentLines) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2008 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,6 +8,7 @@
|
|||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Sergey Prigogin (Google)
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.text.spelling;
|
||||
|
@ -15,6 +16,8 @@ package org.eclipse.cdt.internal.ui.text.spelling;
|
|||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IDocumentExtension3;
|
||||
import org.eclipse.jface.text.IDocumentPartitioner;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.ITypedRegion;
|
||||
import org.eclipse.jface.text.TextUtilities;
|
||||
|
@ -25,9 +28,15 @@ import org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector;
|
|||
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.text.ICPartitions;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentDictionary;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentSimpleDictionary;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.CTextTools;
|
||||
import org.eclipse.cdt.internal.ui.text.FastCPartitioner;
|
||||
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentSpellDictionary;
|
||||
import org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellChecker;
|
||||
import org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellDictionary;
|
||||
import org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellEventListener;
|
||||
|
||||
/**
|
||||
|
@ -40,8 +49,19 @@ public class CSpellingEngine extends SpellingEngine {
|
|||
protected void check(IDocument document, IRegion[] regions, ISpellChecker checker, ISpellingProblemCollector collector, IProgressMonitor monitor) {
|
||||
ISpellEventListener listener= new SpellEventListener(collector, document);
|
||||
boolean isIgnoringStringLiterals= SpellingPreferences.isIgnoreStringLiterals();
|
||||
|
||||
ISpellDictionary toRemove= null;
|
||||
try {
|
||||
checker.addListener(listener);
|
||||
|
||||
IDocCommentOwner owner= null;
|
||||
if(document instanceof IDocumentExtension3) {
|
||||
IDocumentPartitioner partitioner= ((IDocumentExtension3)document).getDocumentPartitioner(ICPartitions.C_PARTITIONING);
|
||||
if(partitioner instanceof FastCPartitioner) {
|
||||
owner= ((FastCPartitioner)partitioner).getDocCommentOwner();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
for (int i= 0; i < regions.length; i++) {
|
||||
IRegion region= regions[i];
|
||||
|
@ -57,6 +77,22 @@ public class CSpellingEngine extends SpellingEngine {
|
|||
if (isIgnoringStringLiterals && type.equals(ICPartitions.C_STRING))
|
||||
continue;
|
||||
|
||||
if(owner!=null) {
|
||||
IDocCommentDictionary dict= null;
|
||||
|
||||
if (type.equals(ICPartitions.C_MULTI_LINE_DOC_COMMENT)) {
|
||||
dict= owner.getMultilineConfiguration().getSpellingDictionary();
|
||||
} else if (type.equals(ICPartitions.C_SINGLE_LINE_DOC_COMMENT)) {
|
||||
dict= owner.getSinglelineConfiguration().getSpellingDictionary();
|
||||
}
|
||||
|
||||
if(dict instanceof IDocCommentSimpleDictionary) {
|
||||
ISpellDictionary sd= new DocCommentSpellDictionary((IDocCommentSimpleDictionary)dict);
|
||||
checker.addDictionary(sd);
|
||||
toRemove= sd;
|
||||
}
|
||||
}
|
||||
|
||||
if (type.equals(ICPartitions.C_PREPROCESSOR)) {
|
||||
CTextTools textTools = CUIPlugin.getDefault().getTextTools();
|
||||
RuleBasedScanner scanner = textTools.getCppPreprocessorScanner();
|
||||
|
@ -101,12 +137,19 @@ public class CSpellingEngine extends SpellingEngine {
|
|||
!type.equals(ICPartitions.C_CHARACTER)) {
|
||||
checker.execute(new SpellCheckIterator(document, partition, checker.getLocale()));
|
||||
}
|
||||
|
||||
if(toRemove != null) {
|
||||
checker.removeDictionary(toRemove);
|
||||
toRemove= null;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (BadLocationException x) {
|
||||
CUIPlugin.getDefault().log(x);
|
||||
}
|
||||
} finally {
|
||||
if(toRemove!=null)
|
||||
checker.removeDictionary(toRemove);
|
||||
checker.removeListener(listener);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,6 +88,8 @@ import org.eclipse.cdt.internal.ui.editor.asm.AsmTextTools;
|
|||
import org.eclipse.cdt.internal.ui.text.CTextTools;
|
||||
import org.eclipse.cdt.internal.ui.text.PreferencesAdapter;
|
||||
import org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverDescriptor;
|
||||
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
|
||||
import org.eclipse.cdt.internal.ui.text.doctools.EditorReopener;
|
||||
import org.eclipse.cdt.internal.ui.text.folding.CFoldingStructureProviderRegistry;
|
||||
import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry;
|
||||
import org.eclipse.cdt.internal.ui.util.ProblemMarkerManager;
|
||||
|
@ -102,6 +104,8 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
public static final String CVIEW_ID = PLUGIN_ID + ".CView"; //$NON-NLS-1$
|
||||
public static final String C_PROBLEMMARKER = PLUGIN_CORE_ID + ".problem"; //$NON-NLS-1$
|
||||
|
||||
public static final String ID_COMMENT_OWNER= PLUGIN_ID+".DocCommentOwner"; //$NON-NLS-1$
|
||||
|
||||
public static final String ID_INCLUDE_BROWSER= PLUGIN_ID + ".includeBrowser"; //$NON-NLS-1$
|
||||
public static final String ID_CALL_HIERARCHY= PLUGIN_ID + ".callHierarchy"; //$NON-NLS-1$
|
||||
public static final String ID_TYPE_HIERARCHY = PLUGIN_ID + ".typeHierarchy"; //$NON-NLS-1$
|
||||
|
@ -237,11 +241,11 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
}
|
||||
|
||||
public static String getFormattedString(String key, String arg) {
|
||||
return MessageFormat.format(getResourceString(key), new String[] { arg });
|
||||
return MessageFormat.format(getResourceString(key), arg);
|
||||
}
|
||||
|
||||
public static String getFormattedString(String key, String[] args) {
|
||||
return MessageFormat.format(getResourceString(key), args);
|
||||
return MessageFormat.format(getResourceString(key), (Object[]) args);
|
||||
}
|
||||
|
||||
public static ResourceBundle getResourceBundle() {
|
||||
|
@ -349,7 +353,7 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
private CTextTools fTextTools;
|
||||
private AsmTextTools fAsmTextTools;
|
||||
private ProblemMarkerManager fProblemMarkerManager;
|
||||
private Map fBuildConsoleManagers;
|
||||
private Map<String, BuildConsoleManager> fBuildConsoleManagers;
|
||||
private ResourceAdapterFactory fResourceAdapterFactory;
|
||||
private CElementAdapterFactory fCElementAdapterFactory;
|
||||
|
||||
|
@ -387,7 +391,7 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
fgCPlugin = this;
|
||||
fDocumentProvider = null;
|
||||
fTextTools = null;
|
||||
fBuildConsoleManagers = new HashMap();
|
||||
fBuildConsoleManagers = new HashMap<String, BuildConsoleManager>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -445,7 +449,7 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
* @return IBuildConsoleManager
|
||||
*/
|
||||
public IBuildConsoleManager getConsoleManager(String name, String id) {
|
||||
BuildConsoleManager manager = (BuildConsoleManager)fBuildConsoleManagers.get(id);
|
||||
BuildConsoleManager manager = fBuildConsoleManagers.get(id);
|
||||
if (manager == null ) {
|
||||
manager = new BuildConsoleManager();
|
||||
fBuildConsoleManagers.put(id, manager);
|
||||
|
@ -454,7 +458,7 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
return manager;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
public void start(BundleContext context) throws Exception {
|
||||
|
@ -475,6 +479,8 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
getASTProvider();
|
||||
CDTContextActivator.getInstance().install();
|
||||
|
||||
DocCommentOwnerManager.getInstance().addListener(new EditorReopener());
|
||||
|
||||
// start make-ui plugin, such that it can check for project conversions.
|
||||
Job job= new Job(Messages.CUIPlugin_jobStartMakeUI) {
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
|
@ -619,8 +625,8 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
* @return an array of all dirty editor parts.
|
||||
*/
|
||||
public static IEditorPart[] getDirtyEditors() {
|
||||
Set inputs= new HashSet();
|
||||
List result= new ArrayList(0);
|
||||
Set<IEditorInput> inputs= new HashSet<IEditorInput>();
|
||||
List<IEditorPart> result= new ArrayList<IEditorPart>(0);
|
||||
IWorkbench workbench= getDefault().getWorkbench();
|
||||
IWorkbenchWindow[] windows= workbench.getWorkbenchWindows();
|
||||
for (int i= 0; i < windows.length; i++) {
|
||||
|
@ -637,13 +643,13 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
}
|
||||
}
|
||||
}
|
||||
return (IEditorPart[])result.toArray(new IEditorPart[result.size()]);
|
||||
return result.toArray(new IEditorPart[result.size()]);
|
||||
}
|
||||
/**
|
||||
* Returns an array of all instanciated editors.
|
||||
*/
|
||||
public static IEditorPart[] getInstanciatedEditors() {
|
||||
List result= new ArrayList(0);
|
||||
List<IEditorPart> result= new ArrayList<IEditorPart>(0);
|
||||
IWorkbench workbench= getDefault().getWorkbench();
|
||||
IWorkbenchWindow[] windows= workbench.getWorkbenchWindows();
|
||||
for (int windowIndex= 0; windowIndex < windows.length; windowIndex++) {
|
||||
|
@ -657,7 +663,7 @@ public class CUIPlugin extends AbstractUIPlugin {
|
|||
}
|
||||
}
|
||||
}
|
||||
return (IEditorPart[])result.toArray(new IEditorPart[result.size()]);
|
||||
return result.toArray(new IEditorPart[result.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
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);
|
||||
}
|
|
@ -13,8 +13,10 @@ package org.eclipse.cdt.ui;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.INamespace;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
|
||||
|
@ -42,11 +44,11 @@ public class NamespacesGrouping extends CElementGrouping {
|
|||
* @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object)
|
||||
*/
|
||||
public Object[] getChildren(Object object) {
|
||||
ArrayList list = new ArrayList();
|
||||
List<ICElement> list = new ArrayList<ICElement>();
|
||||
for (int i = 0; i < fNamespaces.length; ++i) {
|
||||
INamespace nspace = fNamespaces[i];
|
||||
try {
|
||||
Object[] objs = nspace.getChildren();
|
||||
ICElement[] objs = nspace.getChildren();
|
||||
list.addAll(Arrays.asList(objs));
|
||||
} catch (CModelException e) {
|
||||
//
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* IBM Corporation
|
||||
* Markus Schorn - initial API and implementation
|
||||
* IBM Corporation
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.ui.dialogs;
|
||||
|
@ -37,6 +38,12 @@ public class DialogsMessages extends NLS {
|
|||
public static String CacheSizeBlock_indexDatabaseCache;
|
||||
public static String CacheSizeBlock_limitRelativeToMaxHeapSize;
|
||||
|
||||
public static String DocCommentOwnerBlock_DocToolLabel;
|
||||
public static String DocCommentOwnerBlock_EnableProjectSpecificSettings;
|
||||
public static String DocCommentOwnerBlock_SelectDocToolDescription;
|
||||
public static String DocCommentOwnerCombo_None;
|
||||
public static String DocCommentOwnerComposite_DocumentationToolGroupTitle;
|
||||
|
||||
static {
|
||||
// initialize resource bundle
|
||||
NLS.initializeMessages(BUNDLE_NAME, DialogsMessages.class);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
###############################################################################
|
||||
# Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
# Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are made available under the terms of the Eclipse Public License v1.0
|
||||
# which accompanies this distribution, and is available at
|
||||
|
@ -8,6 +8,7 @@
|
|||
# Contributors:
|
||||
# Markus Schorn (Wind River Systems)
|
||||
# IBM Corporation
|
||||
# Andrew Ferguson (Symbian)
|
||||
###############################################################################
|
||||
PreferenceScopeBlock_enableProjectSettings=Enable project specific settings
|
||||
PreferenceScopeBlock_storeWithProject=Store settings with project
|
||||
|
@ -22,6 +23,11 @@ CacheSizeBlock_limitRelativeToMaxHeapSize=Limit relative to the maximum heap siz
|
|||
CacheSizeBlock_absoluteLimit=Absolute Limit:
|
||||
CacheSizeBlock_MB=MB
|
||||
CacheSizeBlock_headerFileCache=Header file cache (used by full indexer and refactoring):
|
||||
DocCommentOwnerBlock_DocToolLabel=Documentation tool:
|
||||
DocCommentOwnerBlock_EnableProjectSpecificSettings=Enable project specific settings
|
||||
DocCommentOwnerBlock_SelectDocToolDescription=Select the documentation tool to be used to determine editor behaviors in this project
|
||||
DocCommentOwnerCombo_None=None
|
||||
DocCommentOwnerComposite_DocumentationToolGroupTitle=Documentation tool comments
|
||||
IndexerStrategyBlock_strategyGroup=Indexing strategy
|
||||
IndexerStrategyBlock_autoUpdate=Automatically update the index
|
||||
IndexerBlock_fixedBuildConfig=Use a fixed build configuration
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
/*******************************************************************************
|
||||
* 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.dialogs;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.layout.GridDataFactory;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Link;
|
||||
import org.eclipse.ui.dialogs.PreferencesUtil;
|
||||
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
|
||||
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
|
||||
|
||||
/**
|
||||
* Project property page for setting documentation comment owner.
|
||||
* <em>This class is not intended for use outside of CDT</em>
|
||||
*/
|
||||
public class DocCommentOwnerBlock extends AbstractCOptionPage {
|
||||
private static String EDITOR_PREF_PAGE_ID= "org.eclipse.cdt.ui.preferences.CEditorPreferencePage"; //$NON-NLS-1$
|
||||
|
||||
protected DocCommentOwnerComposite fDocComboComposite;
|
||||
protected DocCommentOwnerManager fManager;
|
||||
|
||||
protected Button fCheckbox;
|
||||
protected Link fLink;
|
||||
|
||||
public DocCommentOwnerBlock() {
|
||||
fManager= DocCommentOwnerManager.getInstance();
|
||||
}
|
||||
|
||||
void handleCheckBox() {
|
||||
fDocComboComposite.setEnabled(fCheckbox.getSelection());
|
||||
fLink.setVisible(!fCheckbox.getSelection());
|
||||
}
|
||||
|
||||
public void createControl(final Composite parent) {
|
||||
Composite pane= new Composite(parent, SWT.NONE);
|
||||
pane.setLayout(new GridLayout(2, true));
|
||||
pane.setLayoutData(GridDataFactory.fillDefaults().grab(true,false).span(2, 1).create());
|
||||
|
||||
setControl(pane);
|
||||
|
||||
fCheckbox= ControlFactory.createCheckBox(pane, DialogsMessages.DocCommentOwnerBlock_EnableProjectSpecificSettings);
|
||||
fCheckbox.setLayoutData(GridDataFactory.fillDefaults().grab(true,false).create());
|
||||
fCheckbox.addSelectionListener(new SelectionAdapter(){
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
handleCheckBox();
|
||||
}
|
||||
});
|
||||
|
||||
fLink= new Link(pane, SWT.NONE);
|
||||
fLink.setText(DialogsMessages.PreferenceScopeBlock_preferenceLink);
|
||||
fLink.setLayoutData(GridDataFactory.fillDefaults().align(GridData.CENTER, GridData.BEGINNING).grab(true,false).create());
|
||||
fLink.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
PreferencesUtil.createPreferenceDialogOn(parent.getShell(), EDITOR_PREF_PAGE_ID, null, null).open();
|
||||
}
|
||||
});
|
||||
|
||||
String dsc= DialogsMessages.DocCommentOwnerBlock_SelectDocToolDescription;
|
||||
String msg= DialogsMessages.DocCommentOwnerBlock_DocToolLabel;
|
||||
|
||||
IDocCommentOwner prjOwner= DocCommentOwnerManager.getInstance().getCommentOwner(getProject());
|
||||
fDocComboComposite= new DocCommentOwnerComposite(pane, prjOwner, dsc, msg);
|
||||
fDocComboComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true,false).span(2, 1).create());
|
||||
|
||||
fCheckbox.setSelection(fManager.projectDefinesOwnership(getProject()));
|
||||
handleCheckBox();
|
||||
}
|
||||
|
||||
public void performApply(IProgressMonitor monitor) throws CoreException {
|
||||
if(!fCheckbox.getSelection())
|
||||
fManager.setCommentOwner(getProject(), null, true);
|
||||
else {
|
||||
IDocCommentOwner newOwner= fDocComboComposite.getSelectedDocCommentOwner();
|
||||
IProject p= getProject();
|
||||
fManager.setCommentOwner(p, newOwner, true);
|
||||
}
|
||||
}
|
||||
|
||||
public IProject getProject() {
|
||||
ICOptionContainer container = getContainer();
|
||||
if (container != null){
|
||||
if (container instanceof ICOptionContainerExtension) {
|
||||
try {
|
||||
return ((ICOptionContainerExtension) container).getProjectHandle();
|
||||
}
|
||||
catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return container.getProject();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void performDefaults() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/*******************************************************************************
|
||||
* 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.dialogs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
|
||||
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
|
||||
import org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentOwner;
|
||||
|
||||
/**
|
||||
* Manages the population and selection of the doc-comment {@link Combo} box
|
||||
* <em>This class is not intended for use outside of CDT</em>
|
||||
*/
|
||||
public class DocCommentOwnerCombo extends Composite {
|
||||
protected Combo fCombo;
|
||||
protected IDocCommentOwner fOwners[], fInitialOwner;
|
||||
|
||||
public DocCommentOwnerCombo(Composite parent, int style, IDocCommentOwner initialOwner) {
|
||||
super(parent, style);
|
||||
setLayout(new GridLayout());
|
||||
fInitialOwner= initialOwner;
|
||||
fOwners= getNontestOwners();
|
||||
createControl(this);
|
||||
}
|
||||
|
||||
public IDocCommentOwner getSelectedDocCommentOwner() {
|
||||
int index= fCombo.getSelectionIndex();
|
||||
return index == 0 ? NullDocCommentOwner.INSTANCE : fOwners[index-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the list of registered doc-comment owners, filtering out those from the
|
||||
* test plug-in.
|
||||
*/
|
||||
private static IDocCommentOwner[] getNontestOwners() {
|
||||
List<IDocCommentOwner> result= new ArrayList<IDocCommentOwner>();
|
||||
for(IDocCommentOwner owner : DocCommentOwnerManager.getInstance().getRegisteredOwners()) {
|
||||
if(owner.getID().indexOf(".test.")==-1) //$NON-NLS-1$
|
||||
result.add(owner);
|
||||
}
|
||||
return result.toArray(new IDocCommentOwner[result.size()]);
|
||||
}
|
||||
|
||||
public void createControl(Composite parent) {
|
||||
String[] items= new String[fOwners.length+1];
|
||||
items[0]= DialogsMessages.DocCommentOwnerCombo_None;
|
||||
for(int i=0; i<fOwners.length; i++) {
|
||||
items[i+1]= fOwners[i].getName();
|
||||
}
|
||||
fCombo = ControlFactory.createSelectCombo(parent, items, DialogsMessages.DocCommentOwnerCombo_None);
|
||||
selectInCombo(fInitialOwner);
|
||||
}
|
||||
|
||||
public void selectInCombo(IDocCommentOwner owner) {
|
||||
for(int i=0; i<fOwners.length; i++) {
|
||||
if(fOwners[i].getID().equals(owner.getID())) {
|
||||
fCombo.select(i+1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
fCombo.select(0);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
fCombo.setEnabled(enabled);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*******************************************************************************
|
||||
* 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.dialogs;
|
||||
|
||||
import org.eclipse.jface.layout.GridDataFactory;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Group;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
|
||||
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
|
||||
|
||||
/**
|
||||
* <em>This class is not intended for use outside of CDT</em>
|
||||
*/
|
||||
public class DocCommentOwnerComposite extends Composite {
|
||||
protected DocCommentOwnerCombo fDocCombo;
|
||||
protected Label desc, comboLabel;
|
||||
protected Group group;
|
||||
|
||||
public DocCommentOwnerComposite(Composite parent, IDocCommentOwner initialOwner, String description, String label) {
|
||||
super(parent, SWT.NONE);
|
||||
GridLayout gl= new GridLayout();
|
||||
gl.marginHeight= gl.marginWidth= 0;
|
||||
setLayout(gl);
|
||||
|
||||
group = ControlFactory.createGroup(this, DialogsMessages.DocCommentOwnerComposite_DocumentationToolGroupTitle, 2);
|
||||
group.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
|
||||
|
||||
desc= new Label(group, SWT.WRAP);
|
||||
GridData gd = GridDataFactory.fillDefaults().grab(false, false).span(2, 1).create();
|
||||
gd.widthHint= 150;
|
||||
desc.setText(description);
|
||||
desc.setLayoutData(gd);
|
||||
|
||||
comboLabel= new Label(group, SWT.NONE);
|
||||
comboLabel.setText(label);
|
||||
|
||||
fDocCombo= new DocCommentOwnerCombo(group, SWT.NONE, initialOwner) {};
|
||||
gd = GridDataFactory.fillDefaults().grab(true, false).create();
|
||||
fDocCombo.setLayoutData(gd);
|
||||
}
|
||||
|
||||
public IDocCommentOwner getSelectedDocCommentOwner() {
|
||||
return fDocCombo.getSelectedDocCommentOwner();
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
desc.setEnabled(enabled);
|
||||
comboLabel.setEnabled(enabled);
|
||||
fDocCombo.setEnabled(enabled);
|
||||
group.setEnabled(enabled);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2007 Intel Corporation and others
|
||||
* Copyright (c) 2005, 2008 Intel 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
|
||||
|
@ -7,16 +7,71 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Intel Corporation - initial API and implementation
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.newui;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Preferences;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.ui.dialogs.PropertyPage;
|
||||
|
||||
public class Page_head_general extends PropertyPage {
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.ui.dialogs.DocCommentOwnerBlock;
|
||||
import org.eclipse.cdt.ui.dialogs.ICOptionContainer;
|
||||
|
||||
public class Page_head_general extends PropertyPage implements ICOptionContainer {
|
||||
private DocCommentOwnerBlock fDocBlock;
|
||||
private boolean isProjectLevel;
|
||||
|
||||
protected Control createContents(Composite parent) {
|
||||
isProjectLevel= getProject() != null;
|
||||
if(isProjectLevel) {
|
||||
fDocBlock= new DocCommentOwnerBlock();
|
||||
fDocBlock.setContainer(this);
|
||||
fDocBlock.createControl(parent);
|
||||
}
|
||||
noDefaultAndApplyButton();
|
||||
return parent;
|
||||
}
|
||||
|
||||
protected void performDefaults() {
|
||||
if(isProjectLevel) {
|
||||
fDocBlock.performDefaults();
|
||||
}
|
||||
super.performDefaults();
|
||||
}
|
||||
|
||||
public boolean performOk() {
|
||||
if(isProjectLevel) {
|
||||
try {
|
||||
fDocBlock.performApply(new NullProgressMonitor());
|
||||
} catch(CoreException ce) {
|
||||
CCorePlugin.log(ce);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public IProject getProject(){
|
||||
IProject project= null;
|
||||
IAdaptable elem = getElement();
|
||||
if (elem instanceof IProject) {
|
||||
project= (IProject) elem;
|
||||
} else if (elem != null) {
|
||||
project= (IProject) elem.getAdapter(IProject.class);
|
||||
}
|
||||
return project;
|
||||
}
|
||||
|
||||
public Preferences getPreferences() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void updateContainer() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2008 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
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.text;
|
||||
|
||||
|
@ -23,7 +24,7 @@ public interface ICPartitions {
|
|||
String C_PARTITIONING= "___c_partitioning"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The identifier of the single-line end comment partition content type.
|
||||
* The identifier of the single-line comment partition content type.
|
||||
*/
|
||||
String C_SINGLE_LINE_COMMENT= "__c_singleline_comment"; //$NON-NLS-1$
|
||||
|
||||
|
@ -46,4 +47,30 @@ public interface ICPartitions {
|
|||
* The identifier of the C preprocessor partition content type.
|
||||
*/
|
||||
String C_PREPROCESSOR= "__c_preprocessor"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The identifier of the single-line documentation tool comment partition content type.
|
||||
* @since 5.0
|
||||
*/
|
||||
String C_SINGLE_LINE_DOC_COMMENT= "__c_singleline_doc_comment"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The identifier multi-line comment documentation tool partition content type.
|
||||
* @since 5.0
|
||||
*/
|
||||
String C_MULTI_LINE_DOC_COMMENT= "__c_multiline_doc_comment"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* All defined CDT editor partitions
|
||||
* @since 5.0
|
||||
*/
|
||||
String[] ALL_CPARTITIONS= {
|
||||
ICPartitions.C_MULTI_LINE_COMMENT,
|
||||
ICPartitions.C_SINGLE_LINE_COMMENT,
|
||||
ICPartitions.C_STRING,
|
||||
ICPartitions.C_CHARACTER,
|
||||
ICPartitions.C_PREPROCESSOR,
|
||||
ICPartitions.C_SINGLE_LINE_DOC_COMMENT,
|
||||
ICPartitions.C_MULTI_LINE_DOC_COMMENT
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
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 {
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.text.rules.IToken;
|
||||
|
||||
import org.eclipse.cdt.ui.IPropertyChangeParticipant;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
|
||||
/**
|
||||
* An ITokenStore manages a set of tokens for a specified set of color property identifiers. Responsibilities include
|
||||
* <ul>
|
||||
* <li> Reacting to changes to preferences in a specified {@link IPreferenceStore}
|
||||
* <li> Managing whether further styles (bold, italic, strikethrough, underline) should be applied
|
||||
* <li> Coping with
|
||||
* </ul>
|
||||
*
|
||||
* ITokenStore assumes style preferences are stored under the following names
|
||||
* <p>
|
||||
* Preference color key + {@link PreferenceConstants#EDITOR_BOLD_SUFFIX} are used
|
||||
* to retrieve whether the token is rendered in bold.
|
||||
* </p>
|
||||
* <p>
|
||||
* Preference color key + {@link PreferenceConstants#EDITOR_ITALIC_SUFFIX} are used
|
||||
* to retrieve whether the token is rendered in italic.
|
||||
* </p>
|
||||
* <p>
|
||||
* Preference color key + {@link PreferenceConstants#EDITOR_STRIKETHROUGH_SUFFIX} are used
|
||||
* to retrieve whether the token is rendered in strikethrough.
|
||||
* </p>
|
||||
* <p>
|
||||
* Preference color key + {@link PreferenceConstants#EDITOR_UNDERLINE_SUFFIX} are used
|
||||
* to retrieve whether the token is rendered in underline.
|
||||
* </p>
|
||||
*
|
||||
* @see ITokenStoreFactory
|
||||
* @since 5.0
|
||||
*/
|
||||
public interface ITokenStore extends IPropertyChangeParticipant {
|
||||
/**
|
||||
* Ensures any IToken objects that will be <em>or have been</em> 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 in case this token store was originally initialized before a display was available.
|
||||
*/
|
||||
IToken getToken(String property);
|
||||
|
||||
/**
|
||||
* @return The preference store used to read token styling preferences from.
|
||||
*/
|
||||
IPreferenceStore getPreferenceStore();
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2008 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
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Sergey Prigogin (Google)
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.text;
|
||||
|
||||
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.core.CCorePreferenceConstants;
|
||||
import org.eclipse.cdt.ui.IPropertyChangeParticipant;
|
||||
|
||||
/**
|
||||
*
|
||||
* Which words should be recognized as task tags is specified under {@link CCorePreferenceConstants#TODO_TASK_TAGS} as a
|
||||
* comma delimited list.
|
||||
*
|
||||
* @see CCorePreferenceConstants#TODO_TASK_TAGS
|
||||
* @since 5.0
|
||||
*/
|
||||
public final class TaskTagRule extends WordRule implements IPropertyChangeParticipant {
|
||||
private static class TaskTagDetector implements IWordDetector {
|
||||
public boolean isWordStart(char c) {
|
||||
return Character.isLetter(c);
|
||||
}
|
||||
public boolean isWordPart(char c) {
|
||||
return Character.isLetter(c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for extracting a list of words that should be recognized as
|
||||
* task labels from an {@link IPreferenceStore} and a backup {@link Preferences}
|
||||
* @param preferenceStore
|
||||
* @param corePreferences
|
||||
* @return a list of words that should be recognized as task labels in the format
|
||||
* expected by TaskTagRule
|
||||
*/
|
||||
public static String getTaskWords(IPreferenceStore preferenceStore, Preferences corePreferences) {
|
||||
String result= null;
|
||||
if (preferenceStore.contains(CCorePreferenceConstants.TODO_TASK_TAGS)) {
|
||||
result= preferenceStore.getString(CCorePreferenceConstants.TODO_TASK_TAGS);
|
||||
} else if (corePreferences != null) {
|
||||
result= corePreferences.getString(CCorePreferenceConstants.TODO_TASK_TAGS);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private IToken fToken;
|
||||
|
||||
/**
|
||||
* Creates a new task tag rule
|
||||
* @param token the token to return for words recognized as task tags
|
||||
* @param taskWords a comma delimited list of words to recognize as task tags
|
||||
*/
|
||||
public TaskTagRule(IToken token, String taskWords) {
|
||||
super(new TaskTagDetector(), Token.UNDEFINED);
|
||||
fToken= token;
|
||||
if( taskWords!= null) {
|
||||
addTaskTags(taskWords);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the current list of words that should be
|
||||
* recognized as task tags.
|
||||
*/
|
||||
public void clearTaskTags() {
|
||||
fWords.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds tags from the specified string as task tags.
|
||||
* @param value a comma delimited list of words to recognize as task tags
|
||||
*/
|
||||
public void addTaskTags(String value) {
|
||||
String[] tasks= value.split(","); //$NON-NLS-1$
|
||||
for (int i= 0; i < tasks.length; i++) {
|
||||
if (tasks[i].length() > 0) {
|
||||
addWord(tasks[i], fToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.IPropertyChangeParticipant#affectsBehavior(org.eclipse.jface.util.PropertyChangeEvent)
|
||||
*/
|
||||
public boolean affectsBehavior(PropertyChangeEvent event) {
|
||||
return event.getProperty().equals(CCorePreferenceConstants.TODO_TASK_TAGS);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.IPropertyChangeParticipant#adaptToPreferenceChange(org.eclipse.jface.util.PropertyChangeEvent)
|
||||
*/
|
||||
public void adaptToPreferenceChange(PropertyChangeEvent event) {
|
||||
if (event.getProperty().equals(CCorePreferenceConstants.TODO_TASK_TAGS)) {
|
||||
Object value= event.getNewValue();
|
||||
|
||||
if (value instanceof String) {
|
||||
clearTaskTags();
|
||||
addTaskTags((String) value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,386 @@
|
|||
/*******************************************************************************
|
||||
* 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 java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.DocumentCommand;
|
||||
import org.eclipse.jface.text.DocumentRewriteSession;
|
||||
import org.eclipse.jface.text.DocumentRewriteSessionType;
|
||||
import org.eclipse.jface.text.IAutoEditStrategy;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IDocumentExtension4;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.ITypedRegion;
|
||||
import org.eclipse.jface.text.Region;
|
||||
import org.eclipse.jface.text.TextUtilities;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.IWorkingCopyManager;
|
||||
import org.eclipse.cdt.ui.text.ICPartitions;
|
||||
|
||||
/**
|
||||
* This class provides default behaviours for multi-line comment auto-editing.
|
||||
*
|
||||
* This class is intended to be sub-classed.
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrategy {
|
||||
protected static final String MULTILINE_START = "/*"; //$NON-NLS-1$#
|
||||
protected static final String MULTILINE_MID = " * "; //$NON-NLS-1$
|
||||
protected static final String MULTILINE_END = "*/"; //$NON-NLS-1$
|
||||
|
||||
public DefaultMultilineCommentAutoEditStrategy() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.text.IAutoEditStrategy#customizeDocumentCommand(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.DocumentCommand)
|
||||
*/
|
||||
public void customizeDocumentCommand(IDocument doc, DocumentCommand cmd) {
|
||||
if(doc instanceof IDocumentExtension4) {
|
||||
IDocumentExtension4 ext4= (IDocumentExtension4) doc;
|
||||
DocumentRewriteSession drs= ext4.startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED_SMALL);
|
||||
try {
|
||||
if (cmd.length == 0 && cmd.text != null && endsWithDelimiter(doc, cmd.text))
|
||||
customizeDocumentAfterNewLine(doc, cmd);
|
||||
else if ("/".equals(cmd.text)) { //$NON-NLS-1$
|
||||
customizeDocumentForMultilineCommentEnd(doc, cmd);
|
||||
}
|
||||
} finally {
|
||||
ext4.stopRewriteSession(drs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This implements a rule that when in a multiline comment context typing a forward slash with
|
||||
* one white space after the "*" will move eliminate the whitespace.
|
||||
* @param doc
|
||||
* @param command
|
||||
*/
|
||||
protected void customizeDocumentForMultilineCommentEnd(IDocument doc, DocumentCommand command) {
|
||||
if (command.offset < 2 || doc.getLength() == 0) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if ("* ".equals(doc.get(command.offset - 2, 2))) { //$NON-NLS-1$
|
||||
// modify document command
|
||||
command.length++;
|
||||
command.offset--;
|
||||
}
|
||||
} catch (BadLocationException excp) {
|
||||
// stop work
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the indentation of the previous line and adds a star.
|
||||
* If the comment just started on this line adds also a blank.
|
||||
*
|
||||
* @param doc the document to work on
|
||||
* @param c the command to deal with
|
||||
*/
|
||||
public void customizeDocumentAfterNewLine(IDocument doc, final DocumentCommand c) {
|
||||
int offset= c.offset;
|
||||
if (offset == -1 || doc.getLength() == 0)
|
||||
return;
|
||||
|
||||
final StringBuffer buf= new StringBuffer(c.text);
|
||||
try {
|
||||
// find start of line
|
||||
IRegion line= doc.getLineInformationOfOffset(c.offset);
|
||||
int lineStart= line.getOffset();
|
||||
int firstNonWS= findEndOfWhiteSpaceAt(doc, lineStart, c.offset);
|
||||
|
||||
IRegion prefix= findPrefixRange(doc, line);
|
||||
String indentation= doc.get(prefix.getOffset(), prefix.getLength());
|
||||
int lengthToAdd= Math.min(offset - prefix.getOffset(), prefix.getLength());
|
||||
buf.append(indentation.substring(0, lengthToAdd));
|
||||
|
||||
boolean commentAtStart= firstNonWS < c.offset && doc.getChar(firstNonWS) == '/';
|
||||
if (commentAtStart) {
|
||||
// comment started on this line
|
||||
buf.append(MULTILINE_MID);
|
||||
}
|
||||
|
||||
c.shiftsCaret= false;
|
||||
c.caretOffset= c.offset + buf.length();
|
||||
|
||||
if(commentAtStart && shouldCloseMultiline(doc, c.offset)) {
|
||||
try {
|
||||
doc.replace(c.offset, 0, indentation+" "+MULTILINE_END); // close the comment in order to parse //$NON-NLS-1$
|
||||
buf.append("\n"); //$NON-NLS-1$
|
||||
|
||||
// as we are auto-closing, the comment becomes eligible for auto-doc'ing
|
||||
IASTDeclaration dec= findFollowingDeclaration(getAST(), offset);
|
||||
|
||||
// TODO - it is also needed to support auto-tagging when closing a comment
|
||||
// within a function declaration. See DoxygenCCommentAutoEditStrategyTest._testAutoDocCommentContent9()
|
||||
// and DoxygenCCommentAutoEditStrategyTest._testAutoDocCommentContent10()
|
||||
|
||||
if(dec!=null) {
|
||||
ITypedRegion partition= TextUtilities.getPartition(doc, ICPartitions.C_PARTITIONING /* this! */, offset, false);
|
||||
StringBuffer content= customizeAfterNewLineForDeclaration(doc, dec, partition);
|
||||
buf.append(indent(content, indentation + MULTILINE_MID));
|
||||
}
|
||||
|
||||
} catch(BadLocationException ble) {
|
||||
ble.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
c.text= buf.toString();
|
||||
|
||||
} catch (BadLocationException excp) {
|
||||
// stop work
|
||||
}
|
||||
}
|
||||
|
||||
protected StringBuffer customizeAfterNewLineForDeclaration(IDocument doc, IASTDeclaration dec, ITypedRegion region) {
|
||||
return new StringBuffer();
|
||||
}
|
||||
|
||||
/*
|
||||
* Utilities
|
||||
*/
|
||||
|
||||
/**
|
||||
* Locates the {@link IASTDeclaration} most immediately following the specified offset
|
||||
* @param unit the translation unit, or null (in which case the result will also be null)
|
||||
* @param offset the offset to begin the search from
|
||||
* @return the {@link IASTDeclaration} most immediately following the specified offset, or null if there
|
||||
* is no {@link IASTDeclaration}
|
||||
*/
|
||||
public static IASTDeclaration findFollowingDeclaration(IASTTranslationUnit unit, final int offset) {
|
||||
final IASTDeclaration[] dec= new IASTDeclaration[1];
|
||||
final ASTVisitor av= new ASTVisitor() {
|
||||
{
|
||||
shouldVisitTranslationUnit= true;
|
||||
shouldVisitDeclarations= true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds the
|
||||
*/
|
||||
IASTDeclaration stopWhenLeaving;
|
||||
|
||||
public int visit(IASTDeclaration declaration) {
|
||||
IASTNodeLocation[] locs= declaration.getNodeLocations();
|
||||
if(locs.length>0) {
|
||||
for(int i=0; i<locs.length; i++) {
|
||||
IASTNodeLocation loc= locs[i];
|
||||
|
||||
int candidateOffset= loc.getNodeOffset();
|
||||
int candidateEndOffset= candidateOffset+loc.getNodeLength();
|
||||
|
||||
if(offset <= candidateOffset) {
|
||||
dec[0]= declaration;
|
||||
return PROCESS_ABORT;
|
||||
}
|
||||
|
||||
boolean candidateEnclosesOffset= (offset >= candidateOffset) && (offset < candidateEndOffset);
|
||||
if(candidateEnclosesOffset) {
|
||||
stopWhenLeaving= declaration;
|
||||
}
|
||||
}
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
public int leave(IASTDeclaration declaration) {
|
||||
if(declaration==stopWhenLeaving)
|
||||
return PROCESS_ABORT;
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
|
||||
if(unit!=null) {
|
||||
unit.accept(av);
|
||||
}
|
||||
return dec[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ast unit for the active editor, or null if there is no active editor, or
|
||||
* the ast could not be obtained.
|
||||
*/
|
||||
public IASTTranslationUnit getAST() {
|
||||
final ITranslationUnit unit= getTranslationUnit();
|
||||
try {
|
||||
if(unit!=null) {
|
||||
IASTTranslationUnit ast= unit.getAST(null, ITranslationUnit.AST_SKIP_ALL_HEADERS);
|
||||
return ast;
|
||||
}
|
||||
} catch(CModelException ce) {
|
||||
CCorePlugin.log(ce);
|
||||
} catch(CoreException ce) {
|
||||
CCorePlugin.log(ce);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assuming the offset is within a multi-line comment, returns a guess as to
|
||||
* whether the enclosing multi-line comment is a new comment. The result is undefined if
|
||||
* the offset does not occur within a multi-line comment.
|
||||
*
|
||||
* @param document the document
|
||||
* @param offset the offset
|
||||
* @return <code>true</code> if the comment should be closed, <code>false</code> 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
|
||||
* <code>document</code>. The prefix greedily matches the following regex
|
||||
* pattern: <code>\w*\*\w*</code>, that is, any number of whitespace
|
||||
* characters, followed by an asterix ('*'), followed by any number of
|
||||
* whitespace characters.
|
||||
*
|
||||
* @param document the document to which <code>line</code> refers
|
||||
* @param line the line from which to extract the prefix range
|
||||
* @return an <code>IRegion</code> 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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* This interface is a place-holder for the future. Clients should implement the most
|
||||
* appropriate sub-interface (provided by CDT). Currently {@link IDocCommentSimpleDictionary} is
|
||||
* the only provided sub-interface, but it is expected a more subtle way of integrating spell-checking
|
||||
* will be available in the future.
|
||||
* @since 5.0
|
||||
*/
|
||||
public interface IDocCommentDictionary {}
|
|
@ -0,0 +1,50 @@
|
|||
/*******************************************************************************
|
||||
* 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} to
|
||||
* the CDT c/c++ editor.<p>
|
||||
*
|
||||
* In future it may also provide a point for providing
|
||||
* <ul>
|
||||
* <li>access an implementation of a documentation comment validation mechanism
|
||||
* <li>owner specific preference/property pages
|
||||
* <li>information for code generation e.g. default single and multi-line comment
|
||||
* delimiting prefix/post-fixes
|
||||
* </ul>
|
||||
*
|
||||
* <em>This interface is not intended to be implemented externally to CDT.</em>
|
||||
* @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();
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*******************************************************************************
|
||||
* 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 at a particular resource level.
|
||||
* @param resource the resource the ownership has changed for
|
||||
* @param submappingsRemoved whether child resource mappings have been removed
|
||||
* @param oldOwner the previous document comment owner
|
||||
* @param newOwner the new document comment owner
|
||||
*/
|
||||
public void ownershipChanged(IResource resource, boolean submappingsRemoved, IDocCommentOwner oldOwner, IDocCommentOwner newOwner);
|
||||
|
||||
/**
|
||||
* Called when workspace-scope document comment owner changes.
|
||||
* @param oldOwner the previous document comment owner
|
||||
* @param newOwner the new document comment owner
|
||||
*/
|
||||
public void workspaceOwnershipChanged(IDocCommentOwner oldOwner, IDocCommentOwner newOwner);
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* This interface is a simplified means of obtaining spelling support.
|
||||
* @since 5.0
|
||||
*/
|
||||
public interface IDocCommentSimpleDictionary extends IDocCommentDictionary {
|
||||
/**
|
||||
* @return an array of words that should be regarded as correct. These
|
||||
* words will be considered in addition to those provided by existing dictionaries.
|
||||
*/
|
||||
public String[] getAdditionalWords();
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*******************************************************************************
|
||||
* 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.jface.text.IAutoEditStrategy;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.ITextDoubleClickStrategy;
|
||||
|
||||
import org.eclipse.cdt.ui.text.ICPartitions;
|
||||
import org.eclipse.cdt.ui.text.ICTokenScanner;
|
||||
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
|
||||
import org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer;
|
||||
|
||||
/**
|
||||
* An IDocCommentViewerConfiguration aggregates a collection of editor tools that can be contributed to
|
||||
* the CDT editor. The tools will be active for CEditor partitions of type {@link ICPartitions#C_MULTI_LINE_DOC_COMMENT} or
|
||||
* {@link ICPartitions#C_SINGLE_LINE_DOC_COMMENT} when the {@link IDocCommentOwner} this instance originated from is active.
|
||||
*
|
||||
* @see org.eclipse.jface.text.source.SourceViewerConfiguration (in analogy to)
|
||||
* @since 5.0
|
||||
*/
|
||||
public interface IDocCommentViewerConfiguration {
|
||||
/**
|
||||
* @param doc the document to examine
|
||||
* @param offset the offset of the start of the region (inclusive)
|
||||
* @param length the length of the region to examine
|
||||
* @return whether the region specified is a documentation comment handled by this viewer configuration
|
||||
*/
|
||||
boolean isDocumentationComment(IDocument doc, int offset, int length);
|
||||
|
||||
/**
|
||||
* @return a ICTokenScanner for tokenising/coloring the appropriate comment region. May return null.
|
||||
*/
|
||||
ICTokenScanner createCommentScanner(ITokenStoreFactory tokenStoreFactory);
|
||||
|
||||
/**
|
||||
* @return an auto edit strategy suitable for the appropriate comment region. May return null
|
||||
* in the case where no auto-edit-strategy is required.
|
||||
*/
|
||||
IAutoEditStrategy createAutoEditStrategy();
|
||||
|
||||
/**
|
||||
* @return a double click strategy suitable for the associated comment-region. May return null in
|
||||
* the case where no double-click-strategy is required.
|
||||
*/
|
||||
ITextDoubleClickStrategy createDoubleClickStrategy();
|
||||
|
||||
/**
|
||||
* @return a completion proposal computer suitable for the associated comment-region. May return null in
|
||||
* the case where no proposal-computer is required.
|
||||
*/
|
||||
ICompletionProposalComputer createProposalComputer();
|
||||
|
||||
/**
|
||||
* @return a {@link IDocCommentDictionary} suitable for spell-checking. May return null
|
||||
* in the case where no additional dictionary is required.
|
||||
*/
|
||||
IDocCommentDictionary getSpellingDictionary();
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*******************************************************************************
|
||||
* 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.doxygen;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.runtime.FileLocator;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.preference.PreferenceConverter;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.text.doctools.generic.GenericDocTag;
|
||||
|
||||
/**
|
||||
* Makes available information for Doxygen support.
|
||||
*
|
||||
* <em>This class is not intended to be sub-classed by clients</em>
|
||||
* @since 5.0
|
||||
*/
|
||||
public class DoxygenHelper extends AbstractPreferenceInitializer {
|
||||
private static final IPath TAGS_CSV= new Path("doxygenTags.csv"); //$NON-NLS-1$
|
||||
private static GenericDocTag[] fTags;
|
||||
|
||||
public static final String DOXYGEN_TAG_RECOGNIZED= "org.eclipse.cdt.internal.ui.text.doctools.doxygen.recognizedTag"; //$NON-NLS-1$
|
||||
public static final String DOXYGEN_SINGLE_TOKEN= "org.eclipse.cdt.internal.ui.text.doctools.doxygen.single"; //$NON-NLS-1$
|
||||
public static final String DOXYGEN_MULTI_TOKEN= "org.eclipse.cdt.internal.ui.text.doctools.doxygen.multi"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* @return The tags which are understood by default by the doxygen tool.
|
||||
*/
|
||||
public static GenericDocTag[] getDoxygenTags() {
|
||||
if(fTags==null) {
|
||||
try {
|
||||
List<GenericDocTag> temp= new ArrayList<GenericDocTag>();
|
||||
InputStream is= FileLocator.openStream(CUIPlugin.getDefault().getBundle(), TAGS_CSV, false);
|
||||
BufferedReader br= new BufferedReader(new InputStreamReader(is));
|
||||
StringBuffer content= new StringBuffer();
|
||||
for(String line= br.readLine(); line!=null; line= br.readLine()) {
|
||||
content.append(line+"\n"); //$NON-NLS-1$
|
||||
}
|
||||
String[] values= content.toString().split("(\\s)*,(\\s)*"); //$NON-NLS-1$
|
||||
|
||||
for(int i=0; i+1<values.length; i+=2) {
|
||||
temp.add(new GenericDocTag(values[i], values[i+1]));
|
||||
}
|
||||
fTags= temp.toArray(new GenericDocTag[temp.size()]);
|
||||
} catch(IOException ioe) {
|
||||
fTags= new GenericDocTag[0];
|
||||
CCorePlugin.log(ioe);
|
||||
}
|
||||
}
|
||||
return fTags;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
|
||||
*/
|
||||
@Override
|
||||
public void initializeDefaultPreferences() {
|
||||
IPreferenceStore cuis= CUIPlugin.getDefault().getPreferenceStore();
|
||||
PreferenceConverter.setDefault(cuis, DoxygenHelper.DOXYGEN_MULTI_TOKEN, new RGB(63, 95, 191));
|
||||
PreferenceConverter.setDefault(cuis, DoxygenHelper.DOXYGEN_SINGLE_TOKEN, new RGB(63, 95, 191));
|
||||
PreferenceConverter.setDefault(cuis, DoxygenHelper.DOXYGEN_TAG_RECOGNIZED, new RGB(127, 159, 191));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,206 @@
|
|||
/*******************************************************************************
|
||||
* 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.doxygen;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IAutoEditStrategy;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.ITypedRegion;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
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.IASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy;
|
||||
|
||||
/**
|
||||
* {@link IAutoEditStrategy} for adding Doxygen tags for comments.
|
||||
*
|
||||
* <em>This class is not intended to be sub-classed by clients</em>
|
||||
* @since 5.0
|
||||
*/
|
||||
public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAutoEditStrategy {
|
||||
private static final String SINGLELINE_COMMENT_PRECEDING = "//!< "; //$NON-NLS-1$
|
||||
private static final String PARAM = "@param "; //$NON-NLS-1$
|
||||
private static final String RETURN = "@return\n"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public DoxygenMultilineAutoEditStrategy() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the comment content to add to the documentation comment.
|
||||
* @param decls The parameter declarations to describe
|
||||
* @return a buffer containing the comment content to generate to describe the parameters of
|
||||
* the specified {@link IASTParameterDeclaration} objects.
|
||||
*/
|
||||
protected StringBuffer paramTags(IASTParameterDeclaration[] decls) {
|
||||
StringBuffer result= new StringBuffer();
|
||||
for(int i=0; i<decls.length; i++) {
|
||||
IASTDeclarator dtor= decls[i].getDeclarator();
|
||||
result.append(PARAM+dtor.getName()+"\n"); //$NON-NLS-1$
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the comment content to describe the return tag
|
||||
*/
|
||||
protected StringBuffer returnTag() {
|
||||
return new StringBuffer(RETURN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param def the function definition to analyze
|
||||
* @return the parameter declarations for the specified function definition
|
||||
*/
|
||||
protected IASTParameterDeclaration[] getParameterDecls(IASTFunctionDefinition def) {
|
||||
IASTParameterDeclaration[] result;
|
||||
IASTFunctionDeclarator decl= def.getDeclarator();
|
||||
if (decl instanceof IASTStandardFunctionDeclarator) {
|
||||
IASTStandardFunctionDeclarator standardFunctionDecl= (IASTStandardFunctionDeclarator)decl;
|
||||
result= standardFunctionDecl.getParameters();
|
||||
} else /*if (def instanceof ICASTKnRFunctionDeclarator) {
|
||||
ICASTKnRFunctionDeclarator knrDeclarator= (ICASTKnRFunctionDeclarator)decl;
|
||||
result= knrDeclarator.getParameterDeclarations();
|
||||
} else */{
|
||||
result= new IASTParameterDeclaration[0];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy#customizeAfterNewLineForDeclaration(org.eclipse.jface.text.IDocument, org.eclipse.cdt.core.dom.ast.IASTDeclaration, org.eclipse.jface.text.ITypedRegion)
|
||||
*/
|
||||
public StringBuffer customizeAfterNewLineForDeclaration(IDocument doc, IASTDeclaration dec, ITypedRegion partition) {
|
||||
StringBuffer result= new StringBuffer();
|
||||
|
||||
while(dec instanceof ICPPASTTemplateDeclaration) /* if? */
|
||||
dec= ((ICPPASTTemplateDeclaration)dec).getDeclaration();
|
||||
|
||||
if(dec instanceof IASTFunctionDefinition) {
|
||||
IASTFunctionDefinition fd= (IASTFunctionDefinition) dec;
|
||||
result.append(paramTags(getParameterDecls(fd)));
|
||||
|
||||
IASTDeclSpecifier ds= fd.getDeclSpecifier();
|
||||
boolean hasReturn= true;
|
||||
if(ds instanceof IASTSimpleDeclSpecifier) {
|
||||
IASTSimpleDeclSpecifier sds= (IASTSimpleDeclSpecifier) ds;
|
||||
if(sds.getType()==IASTSimpleDeclSpecifier.t_void) {
|
||||
hasReturn= false;
|
||||
}
|
||||
}
|
||||
if(hasReturn) {
|
||||
result.append(returnTag());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
if(dec instanceof IASTSimpleDeclaration && ((IASTSimpleDeclaration)dec).getDeclSpecifier() instanceof IASTCompositeTypeSpecifier) {
|
||||
return result;
|
||||
}
|
||||
|
||||
try {
|
||||
alterDoc(doc, dec);
|
||||
} catch(BadLocationException ble) {
|
||||
/*ignore*/
|
||||
}
|
||||
|
||||
return new StringBuffer();
|
||||
}
|
||||
|
||||
/*
|
||||
* Add post-declaration comments to enumerators, after initializing a doc-comment on an enumeration
|
||||
*/
|
||||
private void alterDoc(IDocument doc, IASTDeclaration dec) throws BadLocationException {
|
||||
if(dec instanceof IASTSimpleDeclaration && ((IASTSimpleDeclaration)dec).getDeclSpecifier() instanceof IASTEnumerationSpecifier) {
|
||||
IASTEnumerationSpecifier spc= (IASTEnumerationSpecifier) ((IASTSimpleDeclaration)dec).getDeclSpecifier();
|
||||
IASTEnumerator[] enms= spc.getEnumerators();
|
||||
|
||||
class Entry {
|
||||
final int offset, length;
|
||||
StringBuilder comment;
|
||||
Entry(int offset, int length, String comment) {
|
||||
this.offset= offset;
|
||||
this.length= length;
|
||||
this.comment= new StringBuilder(comment);
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return offset;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Entry) {
|
||||
Entry other= (Entry) obj;
|
||||
return offset == other.offset;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
boolean noCollisions= true;
|
||||
LinkedHashSet<Entry> entries= new LinkedHashSet<Entry>();
|
||||
for(IASTEnumerator enumerator : enms) {
|
||||
IASTNodeLocation[] locs= enumerator.getName().getNodeLocations();
|
||||
if(locs.length==1) {
|
||||
int nodeOffset= locs[0].getNodeOffset()+locs[0].getNodeLength();
|
||||
String cmt= SINGLELINE_COMMENT_PRECEDING+enumerator.getName();
|
||||
IRegion line= doc.getLineInformationOfOffset(nodeOffset);
|
||||
if(!doc.get(line.getOffset(), line.getLength()).contains("//")) { //$NON-NLS-1$
|
||||
noCollisions &= entries.add(new Entry(line.getOffset(),line.getLength(), cmt));
|
||||
}
|
||||
} else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Only auto-insert comments if each enumerator is declared on a unique line
|
||||
*/
|
||||
if(noCollisions) {
|
||||
int max= Integer.MIN_VALUE;
|
||||
for(Entry e : entries) {
|
||||
if(e.length > max)
|
||||
max= e.length;
|
||||
}
|
||||
|
||||
int addedLength=0;
|
||||
for(Entry e : entries) {
|
||||
// pad with whitespace
|
||||
int toAdd= max-e.length;
|
||||
for(int j=0; j<toAdd; j++) {
|
||||
e.comment.insert(0, " "); //$NON-NLS-1$
|
||||
}
|
||||
doc.replace(e.offset+e.length+addedLength, 0, e.comment.toString());
|
||||
addedLength+= e.comment.length();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*******************************************************************************
|
||||
* 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.doxygen;
|
||||
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
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.IDocCommentViewerConfiguration;
|
||||
import org.eclipse.cdt.ui.text.doctools.generic.AbstractGenericTagDocCommentViewerConfiguration;
|
||||
import org.eclipse.cdt.ui.text.doctools.generic.GenericDocTag;
|
||||
|
||||
/**
|
||||
* {@link IDocCommentViewerConfiguration} implementation for doxygen multi-line documentation comments.
|
||||
* <em>This class may be sub-classed by clients</em>
|
||||
* @since 5.0
|
||||
*/
|
||||
public class DoxygenMultilineConfiguration extends AbstractGenericTagDocCommentViewerConfiguration {
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public DoxygenMultilineConfiguration() {
|
||||
super(DoxygenHelper.getDoxygenTags(), new char[] {'@','\\'}, DoxygenHelper.DOXYGEN_MULTI_TOKEN, DoxygenHelper.DOXYGEN_TAG_RECOGNIZED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor intended for use by sub-classes.
|
||||
* @param tags a non-null array of tags this configuration should recognize
|
||||
* @param tagMarkers a non-null array of characters used to prefix the tags (e.g. @ or \)
|
||||
* @param defaultToken the default scanner token id
|
||||
* @param tagToken the scanner token to use to mark used by this configuration
|
||||
* @see AbstractGenericTagDocCommentViewerConfiguration
|
||||
*/
|
||||
protected DoxygenMultilineConfiguration(GenericDocTag[] tags, char[] tagMarkers, String defaultToken, String tagToken) {
|
||||
super(tags, tagMarkers, defaultToken, tagToken);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration#createAutoEditStrategy()
|
||||
*/
|
||||
public IAutoEditStrategy createAutoEditStrategy() {
|
||||
return new DoxygenMultilineAutoEditStrategy();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration#isDocumentationComment(org.eclipse.jface.text.IDocument, int, int)
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*******************************************************************************
|
||||
* 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.doxygen;
|
||||
|
||||
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.IDocCommentViewerConfiguration;
|
||||
import org.eclipse.cdt.ui.text.doctools.generic.AbstractGenericTagDocCommentViewerConfiguration;
|
||||
import org.eclipse.cdt.ui.text.doctools.generic.GenericDocTag;
|
||||
|
||||
/**
|
||||
* {@link IDocCommentViewerConfiguration} implementation for doxygen single-line documentation comments.
|
||||
* <em>This class may be sub-classed by clients</em>
|
||||
* @since 5.0
|
||||
*/
|
||||
public class DoxygenSingleConfiguration extends AbstractGenericTagDocCommentViewerConfiguration {
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public DoxygenSingleConfiguration() {
|
||||
super(DoxygenHelper.getDoxygenTags(), new char[] {'@','\\'}, DoxygenHelper.DOXYGEN_SINGLE_TOKEN, DoxygenHelper.DOXYGEN_TAG_RECOGNIZED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor intended for use by sub-classes.
|
||||
* @param tags a non-null array of tags this configuration should recognize
|
||||
* @param tagMarkers a non-null array of characters used to prefix the tags (e.g. @ or \)
|
||||
* @param defaultToken the default scanner token id
|
||||
* @param tagToken the scanner token to use to mark used by this configuration
|
||||
*/
|
||||
protected DoxygenSingleConfiguration(GenericDocTag[] tags, char[] tagMarkers, String defaultToken, String tagToken) {
|
||||
super(tags, tagMarkers, defaultToken, tagToken);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration#createAutoEditStrategy()
|
||||
*/
|
||||
public IAutoEditStrategy createAutoEditStrategy() {
|
||||
return new DefaultIndentLineAutoEditStrategy();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration#isDocumentationComment(org.eclipse.jface.text.IDocument, int, int)
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*******************************************************************************
|
||||
* 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 org.eclipse.jface.text.ITextDoubleClickStrategy;
|
||||
|
||||
import org.eclipse.cdt.ui.text.ICTokenScanner;
|
||||
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
|
||||
import org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentDictionary;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentSimpleDictionary;
|
||||
import org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration;
|
||||
|
||||
/**
|
||||
* An abstract base-class for documentation tool contributions using the 'generic tag' framework
|
||||
* @since 5.0
|
||||
*/
|
||||
public abstract class AbstractGenericTagDocCommentViewerConfiguration implements IDocCommentViewerConfiguration {
|
||||
protected GenericDocTag[] fTags;
|
||||
protected char[] fTagMarkers;
|
||||
|
||||
protected ITextDoubleClickStrategy fDCStrategy;
|
||||
protected ICompletionProposalComputer fCPComputer;
|
||||
protected String fDefaultToken;
|
||||
protected String fTagToken;
|
||||
protected IDocCommentSimpleDictionary fDictionary;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param tags a non-null array of tags this configuration should recognize
|
||||
* @param tagMarkers a non-null array of characters used to prefix the tags (e.g. @ or \)
|
||||
* @param defaultToken the default scanner token id
|
||||
* @param tagToken the scanner token to use to mark used by this configuration
|
||||
*/
|
||||
public AbstractGenericTagDocCommentViewerConfiguration(GenericDocTag[] tags, char[] tagMarkers, String defaultToken, String tagToken) {
|
||||
fTags= tags;
|
||||
fTagMarkers= tagMarkers;
|
||||
fDCStrategy= new GenericTagDoubleClickStrategy(tagMarkers);
|
||||
fCPComputer= new GenericTagCompletionProposalComputer(fTags, tagMarkers);
|
||||
fDefaultToken= defaultToken;
|
||||
fTagToken= tagToken;
|
||||
fDictionary= new GenericTagSimpleDictionary(fTags, fTagMarkers);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration#createCommentScanner(org.eclipse.cdt.ui.text.ITokenStoreFactory, java.lang.String)
|
||||
*/
|
||||
public ICTokenScanner createCommentScanner(ITokenStoreFactory tokenStoreFactory) {
|
||||
return new GenericTagCommentScanner(fTags, fTagMarkers, tokenStoreFactory, fDefaultToken, fTagToken);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration#createDoubleClickStrategy()
|
||||
*/
|
||||
public ITextDoubleClickStrategy createDoubleClickStrategy() {
|
||||
return fDCStrategy;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration#createProposalComputer()
|
||||
*/
|
||||
public ICompletionProposalComputer createProposalComputer() {
|
||||
return fCPComputer;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration#getSpellingDictionary()
|
||||
*/
|
||||
public IDocCommentDictionary getSpellingDictionary() {
|
||||
return fDictionary;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Record class for a generic documentation tool tag.
|
||||
* @since 5.0
|
||||
*/
|
||||
public class GenericDocTag {
|
||||
protected final String name, description;
|
||||
|
||||
/**
|
||||
* Create a tag
|
||||
* @param name
|
||||
* @param description
|
||||
*/
|
||||
public GenericDocTag(String name, String description) {
|
||||
this.name= name;
|
||||
this.description= description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tag name (without any prefix e.g. no at or backslash)
|
||||
*/
|
||||
public String getTagName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a human readable description of the tag. May be null.
|
||||
*/
|
||||
public String getTagDescription() {
|
||||
return description;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/*******************************************************************************
|
||||
* 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. It is assumed this will be
|
||||
* used within a single-line or multi-line comment context.
|
||||
* @since 5.0
|
||||
*/
|
||||
public class GenericTagCommentScanner extends BufferedRuleBasedScanner implements ICTokenScanner {
|
||||
protected TaskTagRule fTaskTagRule;
|
||||
protected Preferences fCorePreferenceStore;
|
||||
protected String fDefaultTokenProperty;
|
||||
protected String fTagToken;
|
||||
|
||||
protected GenericDocTag[] fTags;
|
||||
protected char[] fTagMarkers;
|
||||
protected ITokenStore fTokenStore;
|
||||
|
||||
/**
|
||||
* @param tags the tags to be recognized and highlighted by this scanner
|
||||
* @param tagMarkers the character prefixes that denote the start of a tag
|
||||
* @param tokenStoreFactory the token store factory used to store tokens
|
||||
* @param docToken the token id associated with the enclosing comment
|
||||
* @param tagToken the token id associated with highlighting any recognized tags
|
||||
*/
|
||||
public GenericTagCommentScanner(GenericDocTag[] tags, char[] tagMarkers, ITokenStoreFactory tokenStoreFactory, String docToken, String tagToken) {
|
||||
Assert.isNotNull(tags);
|
||||
Assert.isNotNull(tagMarkers);
|
||||
|
||||
fTags= tags;
|
||||
fTagMarkers= tagMarkers;
|
||||
fTagToken= tagToken;
|
||||
|
||||
fTokenStore= tokenStoreFactory.createTokenStore(mkArray(docToken, tagToken));
|
||||
fDefaultTokenProperty= docToken;
|
||||
|
||||
setRules(createRules());
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.text.rules.RuleBasedScanner#nextToken()
|
||||
*/
|
||||
public IToken nextToken() {
|
||||
fTokenStore.ensureTokensInitialised();
|
||||
return super.nextToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the rules to use in this scanner
|
||||
*/
|
||||
protected IRule[] createRules() {
|
||||
List<IRule> result= new ArrayList<IRule>();
|
||||
|
||||
class TagDetector implements IWordDetector {
|
||||
public boolean isWordStart(char c) {
|
||||
for(int i=0; i<fTagMarkers.length; i++)
|
||||
if(fTagMarkers[i] == c)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
public boolean isWordPart(char c) {
|
||||
return c == '.' || Character.isJavaIdentifierPart(c);
|
||||
}
|
||||
}
|
||||
|
||||
WordRule wr= new WordRule(new TagDetector(), fTokenStore.getToken(fDefaultTokenProperty));
|
||||
for(int i=0; i<fTags.length; i++) {
|
||||
String wd= fTags[i].getTagName();
|
||||
for(int j=0; j<fTagMarkers.length; j++) {
|
||||
wr.addWord(fTagMarkers[j]+wd, fTokenStore.getToken(fTagToken));
|
||||
}
|
||||
}
|
||||
result.add(wr);
|
||||
|
||||
// Add rule for Task Tags.
|
||||
String taskWords= TaskTagRule.getTaskWords(fTokenStore.getPreferenceStore(), fCorePreferenceStore);
|
||||
fTaskTagRule= new TaskTagRule(fTokenStore.getToken(PreferenceConstants.EDITOR_TASK_TAG_COLOR), taskWords);
|
||||
result.add(fTaskTagRule);
|
||||
|
||||
setDefaultReturnToken(fTokenStore.getToken(fDefaultTokenProperty));
|
||||
|
||||
return result.toArray(new IRule[result.size()]);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.ui.text.AbstractJavaScanner#affectsBehavior(org.eclipse.jface.util.PropertyChangeEvent)
|
||||
*/
|
||||
public boolean affectsBehavior(PropertyChangeEvent event) {
|
||||
return fTaskTagRule.affectsBehavior(event) || fTokenStore.affectsBehavior(event);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.ui.text.AbstractJavaScanner#adaptToPreferenceChange(org.eclipse.jface.util.PropertyChangeEvent)
|
||||
*/
|
||||
public void adaptToPreferenceChange(PropertyChangeEvent event) {
|
||||
if (fTokenStore.affectsBehavior(event)) {
|
||||
fTokenStore.adaptToPreferenceChange(event);
|
||||
}
|
||||
fTaskTagRule.adaptToPreferenceChange(event);
|
||||
}
|
||||
|
||||
private static String[] mkArray(String defaultTokenProperty, String tagToken) {
|
||||
return new String[] { defaultTokenProperty, tagToken, PreferenceConstants.EDITOR_TASK_TAG_COLOR };
|
||||
}
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
/*******************************************************************************
|
||||
* 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.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.ITypedRegion;
|
||||
import org.eclipse.jface.text.TextUtilities;
|
||||
|
||||
import org.eclipse.cdt.ui.text.ICCompletionProposal;
|
||||
import org.eclipse.cdt.ui.text.ICPartitions;
|
||||
import org.eclipse.cdt.ui.text.contentassist.ContentAssistInvocationContext;
|
||||
import org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.contentassist.CCompletionProposal;
|
||||
|
||||
/**
|
||||
* CompletionProposalComputer based on a specified set of GenericTag objects.
|
||||
* @since 5.0
|
||||
*/
|
||||
public class GenericTagCompletionProposalComputer implements ICompletionProposalComputer {
|
||||
protected GenericDocTag[] tags;
|
||||
protected char[] tagMarkers;
|
||||
|
||||
/**
|
||||
* Constructs a proposal computer for the specified tags
|
||||
* @param tags
|
||||
*/
|
||||
public GenericTagCompletionProposalComputer(GenericDocTag[] tags, char[] tagMarkers) {
|
||||
this.tags= tags;
|
||||
this.tagMarkers= tagMarkers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param c the character to test
|
||||
* @return whether the specified character is a tag prefix marker
|
||||
*/
|
||||
protected boolean isTagMarker(char c) {
|
||||
for(char candidate : tagMarkers)
|
||||
if(c == candidate)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#computeCompletionProposals(org.eclipse.cdt.ui.text.contentassist.ContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public List computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
|
||||
IDocument doc= context.getDocument();
|
||||
int ivcOffset= context.getInvocationOffset();
|
||||
try {
|
||||
ITypedRegion tr= TextUtilities.getPartition(doc, ICPartitions.C_PARTITIONING, ivcOffset, false);
|
||||
int firstNonWS= ivcOffset;
|
||||
while(firstNonWS-1> tr.getOffset() && !Character.isWhitespace(doc.get(firstNonWS-1, 1).charAt(0)))
|
||||
firstNonWS--;
|
||||
String prefix= doc.get(firstNonWS, ivcOffset-firstNonWS);
|
||||
if(prefix.length()>0 && isTagMarker(prefix.charAt(0))) {
|
||||
List<ICCompletionProposal> proposals= new ArrayList<ICCompletionProposal>();
|
||||
char tagMarker= prefix.charAt(0);
|
||||
for(int i=0; i<tags.length; i++) {
|
||||
String tag= tags[i].getTagName();
|
||||
if(tag.toLowerCase().startsWith(prefix.substring(1).toLowerCase())) {
|
||||
CCompletionProposal proposal= new CCompletionProposal(tagMarker+tag, ivcOffset-prefix.length(), prefix.length(), null, tagMarker+tag, 1, context.getViewer());
|
||||
String description= tags[i].getTagDescription();
|
||||
if(description!=null && description.length()>0) {
|
||||
proposal.setAdditionalProposalInfo(description);
|
||||
}
|
||||
proposals.add(proposal);
|
||||
}
|
||||
}
|
||||
return proposals;
|
||||
}
|
||||
} catch(BadLocationException ble) {
|
||||
// offset is zero, ignore
|
||||
}
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#computeContextInformation(org.eclipse.cdt.ui.text.contentassist.ContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public List computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) {
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#getErrorMessage()
|
||||
*/
|
||||
public String getErrorMessage() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#sessionEnded()
|
||||
*/
|
||||
public void sessionEnded() {}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#sessionStarted()
|
||||
*/
|
||||
public void sessionStarted() {}
|
||||
}
|
|
@ -0,0 +1,258 @@
|
|||
/*******************************************************************************
|
||||
* 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 com.ibm.icu.text.BreakIterator;
|
||||
import java.text.CharacterIterator;
|
||||
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.ITextDoubleClickStrategy;
|
||||
import org.eclipse.jface.text.ITextViewer;
|
||||
import org.eclipse.jface.text.Region;
|
||||
|
||||
/**
|
||||
* A double-click strategy for words starting with specified tag markers.
|
||||
* @since 5.0
|
||||
*/
|
||||
/*
|
||||
* Cloned and tweaked from JDT's javadoc double click strategy
|
||||
*/
|
||||
public class GenericTagDoubleClickStrategy implements ITextDoubleClickStrategy {
|
||||
protected char[] fTagMarkers;
|
||||
|
||||
/**
|
||||
* A double-click strategy that additionally understands tag markers form part of a
|
||||
* selectable word.
|
||||
* @param tagMarkers the set of characters to additionally consider part of a word
|
||||
*/
|
||||
public GenericTagDoubleClickStrategy(char[] tagMarkers) {
|
||||
fTagMarkers= new char[tagMarkers.length];
|
||||
System.arraycopy(tagMarkers, 0, fTagMarkers, 0, tagMarkers.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements a character iterator that works directly on
|
||||
* instances of <code>IDocument</code>. Used to collaborate with
|
||||
* the break iterator.
|
||||
*
|
||||
* @see IDocument
|
||||
* @since 2.0
|
||||
*/
|
||||
static class DocumentCharacterIterator implements CharacterIterator {
|
||||
|
||||
/** Document to iterate over. */
|
||||
private IDocument fDocument;
|
||||
/** Start offset of iteration. */
|
||||
private int fOffset= -1;
|
||||
/** End offset of iteration. */
|
||||
private int fEndOffset= -1;
|
||||
/** Current offset of iteration. */
|
||||
private int fIndex= -1;
|
||||
|
||||
/** Creates a new document iterator. */
|
||||
public DocumentCharacterIterator() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures this document iterator with the document section to be visited.
|
||||
*
|
||||
* @param document the document to be iterated
|
||||
* @param iteratorRange the range in the document to be iterated
|
||||
*/
|
||||
public void setDocument(IDocument document, IRegion iteratorRange) {
|
||||
fDocument= document;
|
||||
fOffset= iteratorRange.getOffset();
|
||||
fEndOffset= fOffset + iteratorRange.getLength();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see CharacterIterator#first()
|
||||
*/
|
||||
public char first() {
|
||||
fIndex= fOffset;
|
||||
return current();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see CharacterIterator#last()
|
||||
*/
|
||||
public char last() {
|
||||
fIndex= fOffset < fEndOffset ? fEndOffset -1 : fEndOffset;
|
||||
return current();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see CharacterIterator#current()
|
||||
*/
|
||||
public char current() {
|
||||
if (fOffset <= fIndex && fIndex < fEndOffset) {
|
||||
try {
|
||||
return fDocument.getChar(fIndex);
|
||||
} catch (BadLocationException x) {
|
||||
}
|
||||
}
|
||||
return DONE;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see CharacterIterator#next()
|
||||
*/
|
||||
public char next() {
|
||||
++fIndex;
|
||||
int end= getEndIndex();
|
||||
if (fIndex >= end) {
|
||||
fIndex= end;
|
||||
return DONE;
|
||||
}
|
||||
return current();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see CharacterIterator#previous()
|
||||
*/
|
||||
public char previous() {
|
||||
if (fIndex == fOffset)
|
||||
return DONE;
|
||||
|
||||
if (fIndex > fOffset)
|
||||
-- fIndex;
|
||||
|
||||
return current();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see CharacterIterator#setIndex(int)
|
||||
*/
|
||||
public char setIndex(int index) {
|
||||
fIndex= index;
|
||||
return current();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see CharacterIterator#getBeginIndex()
|
||||
*/
|
||||
public int getBeginIndex() {
|
||||
return fOffset;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see CharacterIterator#getEndIndex()
|
||||
*/
|
||||
public int getEndIndex() {
|
||||
return fEndOffset;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see CharacterIterator#getIndex()
|
||||
*/
|
||||
public int getIndex() {
|
||||
return fIndex;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see CharacterIterator#clone()
|
||||
*/
|
||||
public Object clone() {
|
||||
DocumentCharacterIterator i= new DocumentCharacterIterator();
|
||||
i.fDocument= fDocument;
|
||||
i.fIndex= fIndex;
|
||||
i.fOffset= fOffset;
|
||||
i.fEndOffset= fEndOffset;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The document character iterator used by this strategy.
|
||||
* @since 2.0
|
||||
*/
|
||||
private DocumentCharacterIterator fDocIter= new DocumentCharacterIterator();
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.text.ITextDoubleClickStrategy#doubleClicked(org.eclipse.jface.text.ITextViewer)
|
||||
*/
|
||||
public void doubleClicked(ITextViewer text) {
|
||||
|
||||
int position= text.getSelectedRange().x;
|
||||
|
||||
if (position < 0)
|
||||
return;
|
||||
|
||||
IRegion word= getWordRegion(text.getDocument(), position);
|
||||
|
||||
if (word != null)
|
||||
text.setSelectedRange(word.getOffset(), word.getLength());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a region describing the word around <code>position</code>.
|
||||
*
|
||||
* @param document the document
|
||||
* @param position the offset around which to return the word
|
||||
* @return the word's region, or <code>null</code> 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<fTagMarkers.length; i++) {
|
||||
if(c == fTagMarkers[i])
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*******************************************************************************
|
||||
* 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 org.eclipse.cdt.ui.text.doctools.IDocCommentSimpleDictionary;
|
||||
|
||||
/**
|
||||
* An implementation of a simple dictionary to allow the spelling engine
|
||||
* to not flag documentation tool tags.
|
||||
* @since 5.0
|
||||
*/
|
||||
public class GenericTagSimpleDictionary implements IDocCommentSimpleDictionary {
|
||||
protected String[] fTags;
|
||||
|
||||
/**
|
||||
* @param tags the tags that should be recognized as correct
|
||||
* @param tagMarkers the characters that may delimit the start of a tag
|
||||
*/
|
||||
public GenericTagSimpleDictionary(GenericDocTag[] tags, char[] tagMarkers) {
|
||||
fTags= new String[tags.length];
|
||||
|
||||
for(int j=0; j<tags.length; j++) {
|
||||
fTags[j]= tags[j].getTagName();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an array of non-null words to be added to the dictionary when spell-checking
|
||||
*/
|
||||
public String[] getAdditionalWords() {
|
||||
return fTags;
|
||||
}
|
||||
}
|
|
@ -44,7 +44,7 @@ To select project properties, right click a project and select <b>Properties</b>
|
|||
<li><a href="cdt_u_prop_build_toolchain.htm">Tool chain editor page</a>
|
||||
<li><a href="cdt_u_prop_build_variables.htm">Variables page</a>
|
||||
</ul>
|
||||
<li>Project Properties, C/C++ General category
|
||||
<li>Project Properties, <a href="cdt_u_prop_general.htm">C/C++ General category</a>
|
||||
<ul type="disc">
|
||||
<li><a href="cdt_u_prop_general_doc.htm">Documentation page</a>
|
||||
<li><a href="cdt_u_prop_general_exp.htm">Export Settings page</a>
|
||||
|
|
|
@ -45,6 +45,13 @@
|
|||
<td><dt>Color</dt></td>
|
||||
<td>Specifies the color in which to display the selected item.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><dt>Documentation tool comments</dt></td>
|
||||
<td>Specifies which documentation tool should be used to determine editor presentation and behaviors. This
|
||||
enables editor features such as content-assist, documentation comment generation and syntax highlighting. The particular
|
||||
tool selected here will be used for files that are not associated with a project, or where no project level preference has
|
||||
been set.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
|
|
@ -43,8 +43,8 @@
|
|||
width="143" height="21"><br>
|
||||
|
||||
<ul>
|
||||
<li>Project Properties, C/C++ General category - <a href="cdt_u_prop_general_lng.htm">Language Mapping page</a>
|
||||
<li>File Properties, C/C++ General category - <a href="cdt_u_fileprop_lng.htm">Language Mapping page</a>
|
||||
<li>Project Properties, <a href="cdt_u_prop_general.htm">C/C++ General category</a> - <a href="cdt_u_prop_general_lng.htm">Language Mapping page</a>
|
||||
<li>File Properties, <a href="cdt_u_prop_general.htm">C/C++ General category</a> - <a href="cdt_u_fileprop_lng.htm">Language Mapping page</a>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<ul type="disc">
|
||||
<li><a href="cdt_u_language_mapping_pref.htm">Language Mapping page</a>
|
||||
</ul>
|
||||
<li>Project Properties, C/C++ General category
|
||||
<li>Project Properties, <a href="cdt_u_prop_general.htm">C/C++ General category</a>
|
||||
<ul type="disc">
|
||||
<li><a href="cdt_u_prop_general_lng.htm">Language Mapping page</a>
|
||||
</ul>
|
||||
|
|
|
@ -70,7 +70,7 @@ Customizes the tools and tool options used in your build configuration.
|
|||
<li><a href="cdt_u_prop_build_toolchain.htm">Tool chain editor page</a>
|
||||
<li><a href="cdt_u_prop_build_variables.htm">Variables page</a>
|
||||
</ul>
|
||||
<li>Project Properties, C/C++ General category
|
||||
<li>Project Properties, <a href="cdt_u_prop_general.htm">C/C++ General category</a>
|
||||
<ul type="disc">
|
||||
<li><a href="cdt_u_prop_general_doc.htm">Documentation page</a>
|
||||
<li><a href="cdt_u_prop_general_exp.htm">Export Settings page</a>
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue