View | Details | Raw Unified | Return to bug 208881 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/core/filebuffers/tests/FileBuffersTestSuite.java (-1 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Andrew Ferguson (Symbian)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
12
12
package org.eclipse.core.filebuffers.tests;
13
package org.eclipse.core.filebuffers.tests;
Lines 38-43 Link Here
38
		suite.addTestSuite(FileStoreFileBuffersForExternalFiles.class);
39
		suite.addTestSuite(FileStoreFileBuffersForExternalFiles.class);
39
		suite.addTestSuite(FileStoreFileBuffersForNonExistingExternalFiles.class);
40
		suite.addTestSuite(FileStoreFileBuffersForNonExistingExternalFiles.class);
40
		suite.addTestSuite(FileStoreFileBuffersForNonExistingWorkspaceFiles.class);
41
		suite.addTestSuite(FileStoreFileBuffersForNonExistingWorkspaceFiles.class);
42
		
43
		suite.addTestSuite(TextFileManagerDocCreationTests.class);
44
		suite.addTestSuite(ResourceTextFileManagerDocCreationTests.class);
41
		//$JUnit-END$
45
		//$JUnit-END$
42
		return suite;
46
		return suite;
43
	}
47
	}
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 1-7 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %Plugin.name
3
Bundle-Name: %Plugin.name
4
Bundle-SymbolicName: org.eclipse.core.filebuffers.tests
4
Bundle-SymbolicName: org.eclipse.core.filebuffers.tests;singleton:=true
5
Bundle-Version: 3.4.0.qualifier
5
Bundle-Version: 3.4.0.qualifier
6
Bundle-ClassPath: filebufferstests.jar
6
Bundle-ClassPath: filebufferstests.jar
7
Bundle-Activator: org.eclipse.core.filebuffers.tests.FileBuffersTestPlugin
7
Bundle-Activator: org.eclipse.core.filebuffers.tests.FileBuffersTestPlugin
(-)build.properties (-1 / +2 lines)
Lines 13-19 Link Here
13
               about.html,\
13
               about.html,\
14
               testResources/,\
14
               testResources/,\
15
               *.jar,\
15
               *.jar,\
16
               META-INF/
16
               META-INF/,\
17
               plugin.xml
17
18
18
src.includes = about.html
19
src.includes = about.html
19
20
(-)src/org/eclipse/core/filebuffers/tests/ResourceTextFileManagerDocCreationTests.java (+35 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.core.filebuffers.tests;
12
13
import org.eclipse.core.filebuffers.LocationKind;
14
import org.eclipse.core.internal.filebuffers.ResourceTextFileBufferManager;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.core.runtime.Path;
18
19
public class ResourceTextFileManagerDocCreationTests extends AbstractFileBufferDocCreationTests {
20
	protected void setUp() throws Exception {
21
		fManager= new ResourceTextFileBufferManager();
22
	}
23
	
24
	protected void assertDocumentContent(String expectedContent, String fullPath, LocationKind locKind) {
25
		assertEquals(expectedContent, fManager.createEmptyDocument(new Path(fullPath), locKind).get());
26
		if(locKind.equals(LocationKind.IFILE)) {
27
			IFile file= ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fullPath));
28
			assertEquals(expectedContent, ((ResourceTextFileBufferManager)fManager).createEmptyDocument(file).get());
29
		}
30
	}
31
	
32
	protected LocationKind[] getSupportLocationKinds() {
33
		return new LocationKind[] {LocationKind.IFILE, LocationKind.LOCATION, LocationKind.NORMALIZE};
34
	}
35
}
(-)plugin.xml (+75 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.2"?>
3
<!--
4
  -
5
  - Register IDocumentSetupParticipants against names and extensions that won't interfere with
6
  - normal operation.
7
  -
8
  -->
9
<plugin>
10
<!-- IDocumentSetupParticipant -->
11
   <extension point="org.eclipse.core.filebuffers.documentSetup">
12
      <participant
13
            class="org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants$TestDSP1"
14
            extensions="111foo">
15
      </participant>
16
   </extension>
17
   <extension point="org.eclipse.core.filebuffers.documentSetup">
18
      <participant
19
            class="org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants$TestDSP2"
20
            fileNames="111fooname,111fooname.111foo">
21
      </participant>
22
   </extension>  
23
   <extension point="org.eclipse.core.filebuffers.documentSetup">
24
      <participant
25
            class="org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants$TestDSP3"
26
            extensions="111foo"
27
            fileNames="111fooname,111fooname.111foo">
28
      </participant>
29
   </extension>
30
   
31
   <!-- IDocumentSetupParticipantExtension ignoring hint -->
32
   <extension point="org.eclipse.core.filebuffers.documentSetup">
33
      <participant
34
            class="org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants$TestDSP4"
35
            extensions="222foo">
36
      </participant>
37
   </extension>
38
   <extension point="org.eclipse.core.filebuffers.documentSetup">
39
      <participant
40
            class="org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants$TestDSP5"
41
            fileNames="222fooname,222fooname.222foo">
42
      </participant>
43
   </extension>
44
   <extension point="org.eclipse.core.filebuffers.documentSetup">
45
      <participant
46
            class="org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants$TestDSP6"
47
            extensions="222foo"
48
            fileNames="222fooname,222fooname.222foo">
49
      </participant>
50
   </extension>
51
   
52
   <!-- IDocumentSetupPartcipantExtension selectively picking up hint -->
53
   <extension point="org.eclipse.core.filebuffers.documentSetup">
54
      <participant
55
            class="org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants$TestDSP7"
56
            extensions="333foo"
57
            fileNames="333fooname,333fooname.333foo">
58
      </participant>
59
   </extension>
60
   <extension point="org.eclipse.core.filebuffers.documentSetup">
61
      <participant
62
            class="org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants$TestDSP8"
63
            extensions="444foo"
64
            fileNames="444fooname,444fooname.444foo">
65
      </participant>
66
   </extension>
67
   <extension point="org.eclipse.core.filebuffers.documentSetup">
68
      <participant
69
            class="org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants$TestDSP9"
70
            extensions="555foo"
71
            fileNames="555fooname,555fooname.555foo">
72
      </participant>
73
   </extension>
74
</plugin>
75
 
(-)src/org/eclipse/core/filebuffers/tests/TextFileManagerDocCreationTests.java (+32 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.core.filebuffers.tests;
12
13
import org.eclipse.core.filebuffers.LocationKind;
14
import org.eclipse.core.internal.filebuffers.TextFileBufferManager;
15
16
public class TextFileManagerDocCreationTests extends AbstractFileBufferDocCreationTests {
17
	protected void setUp() throws Exception {
18
		fManager= new TextFileBufferManager();
19
	}
20
	
21
	protected void assertDocumentContent(String expectedContent, String path,
22
			LocationKind locKind) {
23
		if(!locKind.equals(LocationKind.IFILE)) {
24
			/**  {@link TextFileBufferManager} does not deal with {@link LocationKind#IFILE} */
25
			super.assertDocumentContent(expectedContent, path, locKind);
26
		}
27
	}
28
	
29
	protected LocationKind[] getSupportLocationKinds() {
30
		return new LocationKind[] {LocationKind.LOCATION, LocationKind.NORMALIZE};
31
	}
32
}
(-)src/org/eclipse/core/filebuffers/tests/MockDocumentSetupParticipants.java (+87 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.core.filebuffers.tests;
12
13
import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
14
import org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension;
15
import org.eclipse.core.filebuffers.LocationKind;
16
import org.eclipse.core.runtime.Assert;
17
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.jface.text.BadLocationException;
19
import org.eclipse.jface.text.IDocument;
20
21
/**
22
 * Holds {@link IDocumentSetupParticipant}'s for registering against fictional
23
 * document extensions for test purposes.
24
 */
25
public class MockDocumentSetupParticipants {
26
	/**
27
	 * An {@link IDocumentSetupParticipant} which stamps its name
28
	 * into the document being setup for integration test purposes.
29
	 */
30
	static abstract class AbstractTestDSP implements IDocumentSetupParticipant {
31
		/*
32
		 * @see org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.eclipse.jface.text.IDocument)
33
		 */
34
		public void setup(IDocument document) {
35
			append(document, getClass()+"\n");
36
		}
37
	}
38
	
39
	static abstract class AbstractTestDSPExtension extends AbstractTestDSP implements IDocumentSetupParticipant, IDocumentSetupParticipantExtension {
40
		/*
41
		 * @see org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension#setup(org.eclipse.jface.text.IDocument, org.eclipse.core.runtime.IPath, org.eclipse.core.filebuffers.LocationKind)
42
		 */
43
		public void setup(IDocument document, IPath location, LocationKind locationKind) {
44
			append(document, getClass()+"%%EXTENSION\n");
45
		}
46
	}
47
	
48
	public static class TestDSP1 extends AbstractTestDSP {}
49
	public static class TestDSP2 extends AbstractTestDSP {}
50
	public static class TestDSP3 extends AbstractTestDSP {}
51
	
52
	public static class TestDSP4 extends AbstractTestDSPExtension {}
53
	public static class TestDSP5 extends AbstractTestDSPExtension {}
54
	public static class TestDSP6 extends AbstractTestDSPExtension {}
55
	
56
	public static class TestDSP7 extends AbstractTestDSPExtension {
57
		public void setup(IDocument document, IPath location, LocationKind locationKind) {
58
			if(location!=null && LocationKind.IFILE.equals(locationKind)) {
59
				append(document, new StringBuffer(location.toPortableString()).reverse().toString());
60
			}
61
		}
62
	}
63
	
64
	public static class TestDSP8 extends AbstractTestDSPExtension {
65
		public void setup(IDocument document, IPath location, LocationKind locationKind) {
66
			if(location!=null && LocationKind.LOCATION.equals(locationKind)) {
67
				append(document, new StringBuffer(location.toPortableString()).reverse().toString());
68
			}
69
		}
70
	}
71
	
72
	public static class TestDSP9 extends AbstractTestDSPExtension {
73
		public void setup(IDocument document, IPath location, LocationKind locationKind) {
74
			if(location!=null && LocationKind.NORMALIZE.equals(locationKind)) {
75
				append(document, new StringBuffer(location.toPortableString()).reverse().toString());
76
			}
77
		}
78
	}
79
	
80
	private static void append(IDocument document, String string) {
81
		try {
82
			document.replace(document.getLength(), 0, string);
83
		} catch(BadLocationException ble) {
84
			Assert.isTrue(false);
85
		}
86
	}
87
}
(-)src/org/eclipse/core/filebuffers/tests/AbstractFileBufferDocCreationTests.java (+134 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.core.filebuffers.tests;
12
13
import java.util.Arrays;
14
import java.util.HashSet;
15
import java.util.Set;
16
17
import junit.framework.TestCase;
18
19
import org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension;
20
import org.eclipse.core.filebuffers.ITextFileBufferManager;
21
import org.eclipse.core.filebuffers.LocationKind;
22
import org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants.TestDSP1;
23
import org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants.TestDSP2;
24
import org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants.TestDSP3;
25
import org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants.TestDSP4;
26
import org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants.TestDSP5;
27
import org.eclipse.core.filebuffers.tests.MockDocumentSetupParticipants.TestDSP6;
28
import org.eclipse.core.runtime.Path;
29
import org.eclipse.jface.text.IDocument;
30
31
public abstract class AbstractFileBufferDocCreationTests extends TestCase {
32
	protected ITextFileBufferManager fManager;
33
	
34
	
35
	public void testCreateDocumentPartipants_FileExt() {
36
		assertParticipantsInvoked("anything.111foo", new Class[] {TestDSP1.class, TestDSP3.class});
37
	}
38
	
39
	public void testCreateDocumentPartipants_Name() {
40
		assertParticipantsInvoked("111fooname", new Class[] {TestDSP2.class, TestDSP3.class});
41
	}
42
	
43
	public void testCreateDocumentPartipants_FileExt_Name() {
44
		assertParticipantsInvoked("111fooname.111foo", new Class[] {TestDSP1.class, TestDSP2.class, TestDSP3.class});
45
	}
46
	
47
	public void testCreateDocumentPartipants_FileExt_Extension() {
48
		assertParticipantsInvoked("anything.222foo", new Class[] {TestDSP4.class, TestDSP6.class});
49
	}
50
	
51
	public void testCreateDocumentPartipants_Name_Extension() {
52
		assertParticipantsInvoked("222fooname", new Class[] {TestDSP5.class, TestDSP6.class});
53
	}
54
	
55
	public void testCreateDocumentPartipants_FileExt_Name_Extension() {
56
		assertParticipantsInvoked("222fooname.222foo", new Class[] {TestDSP4.class, TestDSP5.class, TestDSP6.class});
57
	}
58
	
59
	public void testDocumentSetupParticipantExtension_1() {
60
		assertDocumentContent("emanoof333/p/", "/p/333fooname", LocationKind.IFILE);
61
		assertDocumentContent("oof333.emanoof333/p/", "/p/333fooname.333foo", LocationKind.IFILE);
62
		assertDocumentContent("oof333.gnihtyna/p/", "/p/anything.333foo", LocationKind.IFILE);
63
		
64
		assertDocumentContent("", "333fooname", LocationKind.LOCATION);
65
		assertDocumentContent("", "333fooname.333foo", LocationKind.LOCATION);
66
		assertDocumentContent("", "anything.333foo", LocationKind.LOCATION);
67
		
68
		assertDocumentContent("", "333fooname", LocationKind.NORMALIZE);
69
		assertDocumentContent("", "333fooname.333foo", LocationKind.NORMALIZE);
70
		assertDocumentContent("", "anything.333foo", LocationKind.NORMALIZE);
71
	}
72
	
73
	public void testDocumentSetupParticipantExtension_2() {
74
		assertDocumentContent("", "/p/444fooname", LocationKind.IFILE);
75
		assertDocumentContent("", "/p/444fooname.444foo", LocationKind.IFILE);
76
		assertDocumentContent("", "/p/anything.444foo", LocationKind.IFILE);
77
		
78
		assertDocumentContent("emanoof444", "444fooname", LocationKind.LOCATION);
79
		assertDocumentContent("oof444.emanoof444", "444fooname.444foo", LocationKind.LOCATION);
80
		assertDocumentContent("oof444.gnihtyna", "anything.444foo", LocationKind.LOCATION);
81
		
82
		assertDocumentContent("", "444fooname", LocationKind.NORMALIZE);
83
		assertDocumentContent("", "444fooname.444foo", LocationKind.NORMALIZE);
84
		assertDocumentContent("", "anything.444foo", LocationKind.NORMALIZE);
85
	}
86
	
87
	public void testDocumentSetupParticipantExtension_3() {
88
		assertDocumentContent("", "/p/555fooname", LocationKind.IFILE);
89
		assertDocumentContent("", "/p/555fooname.555foo", LocationKind.IFILE);
90
		assertDocumentContent("", "/p/anything.555foo", LocationKind.IFILE);
91
		
92
		assertDocumentContent("", "555fooname", LocationKind.LOCATION);
93
		assertDocumentContent("", "555fooname.555foo", LocationKind.LOCATION);
94
		assertDocumentContent("", "anything.555foo", LocationKind.LOCATION);
95
		
96
		assertDocumentContent("emanoof555", "555fooname", LocationKind.NORMALIZE);
97
		assertDocumentContent("oof555.emanoof555", "555fooname.555foo", LocationKind.NORMALIZE);
98
		assertDocumentContent("oof555.gnihtyna", "anything.555foo", LocationKind.NORMALIZE);
99
	}
100
	
101
	/* Utilities */
102
	
103
	private void assertParticipantsInvoked(String path, Class[] expectedDSPsArray) {
104
		LocationKind[] lks= getSupportLocationKinds();
105
		for(int i=0; i<lks.length; i++) {
106
			IDocument document= fManager.createEmptyDocument(new Path(path), lks[i]);		
107
			String content= document.get();
108
			Set expectedDSPs= new HashSet(Arrays.asList(toString(expectedDSPsArray)));
109
			Set actualDSPs= new HashSet(Arrays.asList(content.split("\n")));
110
			assertEquals(expectedDSPs, actualDSPs);
111
		}
112
	}
113
	
114
	abstract protected LocationKind[] getSupportLocationKinds();
115
	
116
	protected void assertDocumentContent(String expectedContent, String path, LocationKind locKind) {
117
		assertEquals(expectedContent, fManager.createEmptyDocument(new Path(path), locKind).get());
118
	}
119
	
120
	private static String[] toString(Class[] clss) {
121
		String[] result= new String[clss.length];
122
		for(int i=0; i<result.length; i++) {
123
			String s= null;
124
			if(clss[i]!=null) {
125
				s= clss[i].toString();
126
				if(IDocumentSetupParticipantExtension.class.isAssignableFrom(clss[i])) {
127
					s+= "%%EXTENSION";
128
				}
129
			}
130
			result[i]= s;
131
		}
132
		return result;
133
	}
134
}
(-)src/org/eclipse/cdt/core/ICDescriptor.java (-1 / +19 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 QNX Software Systems and others.
2
 * Copyright (c) 2000, 2008 QNX Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 15-23 Link Here
15
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.CoreException;
16
import org.w3c.dom.Element;
16
import org.w3c.dom.Element;
17
17
18
/**
19
 * Models meta-data stored with a CDT project
20
 */
18
public interface ICDescriptor {
21
public interface ICDescriptor {
19
	public ICOwnerInfo getProjectOwner();
22
	public ICOwnerInfo getProjectOwner();
20
	public String getPlatform();
23
	public String getPlatform();
24
	
25
	/**
26
	 * @return the associated project
27
	 */
21
	public IProject getProject();
28
	public IProject getProject();
22
	
29
	
23
	public ICExtensionReference[] get(String extensionPoint);
30
	public ICExtensionReference[] get(String extensionPoint);
Lines 27-33 Link Here
27
	public void remove(ICExtensionReference extension) throws CoreException;
34
	public void remove(ICExtensionReference extension) throws CoreException;
28
	public void remove(String extensionPoint) throws CoreException;
35
	public void remove(String extensionPoint) throws CoreException;
29
	
36
	
37
	/**
38
	 * @param id an identifier that uniquely identifies the client
39
	 * @return a non-null {@link Element} to which client specific meta-data may be attached
40
	 * @throws CoreException
41
	 */
30
	public Element getProjectData(String id) throws CoreException;
42
	public Element getProjectData(String id) throws CoreException;
43
	
44
	/**
45
	 * Saves any changes made to {@link Element} objects obtained from {@link #getProjectData(String)}
46
	 * to a CDT defined project meta-data file.
47
	 * @throws CoreException
48
	 */
31
	public void saveProjectData() throws CoreException;
49
	public void saveProjectData() throws CoreException;
32
	
50
	
33
	ICConfigurationDescription getConfigurationDescription();
51
	ICConfigurationDescription getConfigurationDescription();
(-)src/org/eclipse/cdt/internal/ui/text/SingleTokenCScanner.java (-6 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 8-35 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     QNX Software System
10
 *     QNX Software System
11
 *     Andrew Ferguson (Symbian)
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.cdt.internal.ui.text;
13
package org.eclipse.cdt.internal.ui.text;
13
14
14
import java.util.List;
15
import java.util.List;
15
import org.eclipse.jface.preference.IPreferenceStore;
16
16
import org.eclipse.jface.text.IDocument;
17
import org.eclipse.jface.text.IDocument;
17
import org.eclipse.jface.text.rules.IToken;
18
import org.eclipse.jface.text.rules.IToken;
18
import org.eclipse.jface.text.rules.Token;
19
import org.eclipse.jface.text.rules.Token;
19
20
21
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
22
20
23
21
/**
24
/**
22
 * 
25
 * 
23
 */
26
 */
24
public final class SingleTokenCScanner extends AbstractCScanner{
27
public final class SingleTokenCScanner extends AbstractCScanner {
25
	
28
	
26
	protected IToken fDefaultReturnToken;
29
	protected IToken fDefaultReturnToken;
27
	private String[] fProperty;
30
	private String[] fProperty;
28
	
31
	
29
	public SingleTokenCScanner(IColorManager manager, IPreferenceStore store, String property) {
32
	public SingleTokenCScanner(ITokenStoreFactory factory, String property) {
30
		super(manager, store, 20);
33
		super(factory.createTokenStore(new String[] {property}), 20);
31
		fProperty= new String[] { property };
34
		fProperty= new String[] { property };
32
		initialize();
35
		setRules(createRules());
33
	}
36
	}
34
37
35
	/*
38
	/*
(-)src/org/eclipse/cdt/internal/ui/text/CCodeScanner.java (-27 / +9 lines)
Lines 9-27 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     QNX Software System
10
 *     QNX Software System
11
 *     Anton Leherbauer (Wind River Systems)
11
 *     Anton Leherbauer (Wind River Systems)
12
 *     Andrew Ferguson (Symbian)
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.cdt.internal.ui.text;
14
package org.eclipse.cdt.internal.ui.text;
14
15
15
import java.util.ArrayList;
16
import java.util.ArrayList;
16
import java.util.List;
17
import java.util.List;
17
18
18
import org.eclipse.jface.preference.IPreferenceStore;
19
import org.eclipse.jface.text.rules.IToken;
19
import org.eclipse.jface.text.rules.Token;
20
import org.eclipse.jface.text.rules.WhitespaceRule;
20
import org.eclipse.jface.text.rules.WhitespaceRule;
21
import org.eclipse.jface.text.rules.WordRule;
21
import org.eclipse.jface.text.rules.WordRule;
22
import org.eclipse.jface.util.PropertyChangeEvent;
23
22
24
import org.eclipse.cdt.core.model.ICLanguageKeywords;
23
import org.eclipse.cdt.core.model.ICLanguageKeywords;
24
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
25
25
26
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
26
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
27
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
27
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
Lines 45-75 Link Here
45
45
46
	/**
46
	/**
47
	 * Creates a C/C++ code scanner.
47
	 * Creates a C/C++ code scanner.
48
	 * 
48
	 * @param factory 
49
     * @param manager  the color manager
50
     * @param store  the reference store
51
     * @param keywords  the keywords defined by the language dialect
49
     * @param keywords  the keywords defined by the language dialect
52
	 */
50
	 */
53
	public CCodeScanner(IColorManager manager, IPreferenceStore store, ICLanguageKeywords keywords) {
51
	public CCodeScanner(ITokenStoreFactory factory, ICLanguageKeywords keywords) {
54
		super(manager, store);
52
		super(factory.createTokenStore(fgTokenProperties));
55
		fKeywords= keywords;
53
		fKeywords= keywords;
56
		initialize();
54
		setRules(createRules());
57
	}
55
	}
58
56
	
59
	/*
60
	 * @see AbstractCScanner#getTokenProperties()
61
	 */
62
	protected String[] getTokenProperties() {
63
		return fgTokenProperties;
64
	}
65
66
	/*
57
	/*
67
	 * @see AbstractCScanner#createRules()
58
	 * @see AbstractCScanner#createRules()
68
	 */
59
	 */
69
	protected List createRules() {
60
	protected List createRules() {
70
				
61
				
71
		List rules= new ArrayList();		
62
		List rules= new ArrayList();		
72
		Token token;
63
		IToken token;
73
		
64
		
74
		// Add generic white space rule.
65
		// Add generic white space rule.
75
		rules.add(new WhitespaceRule(new CWhitespaceDetector()));
66
		rules.add(new WhitespaceRule(new CWhitespaceDetector()));
Lines 105-117 Link Here
105
		setDefaultReturnToken(getToken(ICColorConstants.C_DEFAULT));
96
		setDefaultReturnToken(getToken(ICColorConstants.C_DEFAULT));
106
		return rules;
97
		return rules;
107
	}
98
	}
108
109
	/*
110
	 * @see AbstractCScanner#adaptToPreferenceChange(PropertyChangeEvent)
111
	 */
112
	public void adaptToPreferenceChange(PropertyChangeEvent event) {
113
		if (super.affectsBehavior(event)) {
114
			super.adaptToPreferenceChange(event);
115
		}
116
	}
117
}
99
}
(-)src/org/eclipse/cdt/internal/ui/text/CTextTools.java (-83 / +115 lines)
Lines 9-17 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     QNX Software System
10
 *     QNX Software System
11
 *     Anton Leherbauer (Wind River Systems)
11
 *     Anton Leherbauer (Wind River Systems)
12
 *     Andrew Ferguson (Symbian)
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.cdt.internal.ui.text;
14
package org.eclipse.cdt.internal.ui.text;
14
15
16
import org.eclipse.core.filebuffers.LocationKind;
17
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.ResourcesPlugin;
19
import org.eclipse.core.runtime.IPath;
15
import org.eclipse.core.runtime.Preferences;
20
import org.eclipse.core.runtime.Preferences;
16
import org.eclipse.jface.preference.IPreferenceStore;
21
import org.eclipse.jface.preference.IPreferenceStore;
17
import org.eclipse.jface.text.IDocument;
22
import org.eclipse.jface.text.IDocument;
Lines 26-32 Link Here
26
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
31
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
27
import org.eclipse.cdt.ui.CUIPlugin;
32
import org.eclipse.cdt.ui.CUIPlugin;
28
import org.eclipse.cdt.ui.text.ICPartitions;
33
import org.eclipse.cdt.ui.text.ICPartitions;
34
import org.eclipse.cdt.ui.text.ITokenStore;
35
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
36
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
29
37
38
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
30
import org.eclipse.cdt.internal.ui.text.util.CColorManager;
39
import org.eclipse.cdt.internal.ui.text.util.CColorManager;
31
40
32
41
Lines 35-48 Link Here
35
 * its clients.
44
 * its clients.
36
 */
45
 */
37
public class CTextTools {
46
public class CTextTools {
38
	
47
39
	private class PreferenceListener implements IPropertyChangeListener, Preferences.IPropertyChangeListener {
48
	private class PreferenceListener implements IPropertyChangeListener, Preferences.IPropertyChangeListener {
40
		public void propertyChange(PropertyChangeEvent event) {
49
		public void propertyChange(PropertyChangeEvent event) {
41
			adaptToPreferenceChange(event);
50
			adaptToPreferenceChange(event);
42
		}
51
		}
43
        public void propertyChange(Preferences.PropertyChangeEvent event) {
52
		public void propertyChange(Preferences.PropertyChangeEvent event) {
44
            adaptToPreferenceChange(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event.getNewValue()));
53
			adaptToPreferenceChange(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event.getNewValue()));
45
        }
54
		}
46
	}
55
	}
47
56
48
	/** The color manager */
57
	/** The color manager */
Lines 64-120 Link Here
64
73
65
	/** The preference store */
74
	/** The preference store */
66
	private IPreferenceStore fPreferenceStore;
75
	private IPreferenceStore fPreferenceStore;
67
    /** The core preference store */
76
	/** The core preference store */
68
    private Preferences fCorePreferenceStore;	
77
	private Preferences fCorePreferenceStore;	
69
	/** The preference change listener */
78
	/** The preference change listener */
70
	private PreferenceListener fPreferenceListener= new PreferenceListener();
79
	private PreferenceListener fPreferenceListener= new PreferenceListener();
71
	/** The document partitioning used for the C partitioner */
80
	/** The document partitioning used for the C partitioner */
72
	private String fDocumentPartitioning = ICPartitions.C_PARTITIONING;
81
	private String fDocumentPartitioning = ICPartitions.C_PARTITIONING;
73
	
82
83
	/**
84
	 * Creates a new C text tools collection and eagerly creates 
85
	 * and initializes all members of this collection.
86
	 */
87
	public CTextTools(IPreferenceStore store) {
88
		this(store, null, true);
89
	}
90
74
	/**
91
	/**
75
	 * Creates a new C text tools collection and eagerly creates 
92
	 * Creates a new C text tools collection and eagerly creates 
76
	 * and initializes all members of this collection.
93
	 * and initializes all members of this collection.
77
	 */
94
	 */
78
    public CTextTools(IPreferenceStore store) {
95
	public CTextTools(IPreferenceStore store, Preferences coreStore) {
79
        this(store, null, true);
96
		this(store, coreStore, true);
80
    }
97
	}
81
    
98
82
	/**
99
	/**
83
	 * Creates a new C text tools collection and eagerly creates 
100
	 * Creates a new C text tools collection and eagerly creates 
84
	 * and initializes all members of this collection.
101
	 * and initializes all members of this collection.
85
	 */
102
	 */
86
    public CTextTools(IPreferenceStore store, Preferences coreStore) {
87
        this(store, coreStore, true);
88
    }
89
    
90
    /**
91
     * Creates a new C text tools collection and eagerly creates 
92
     * and initializes all members of this collection.
93
     */
94
	public CTextTools(IPreferenceStore store, Preferences coreStore, boolean autoDisposeOnDisplayDispose) {
103
	public CTextTools(IPreferenceStore store, Preferences coreStore, boolean autoDisposeOnDisplayDispose) {
95
		if(store == null) {
104
		fPreferenceStore = store != null ? store : CUIPlugin.getDefault().getPreferenceStore();
96
			store = CUIPlugin.getDefault().getPreferenceStore();
97
		}
98
		fColorManager= new CColorManager(autoDisposeOnDisplayDispose);
105
		fColorManager= new CColorManager(autoDisposeOnDisplayDispose);
99
		fCodeScanner= new CCodeScanner(fColorManager, store, GCCLanguage.getDefault());
100
		fCppCodeScanner= new CCodeScanner(fColorManager, store, GPPLanguage.getDefault());
101
		
102
		fMultilineCommentScanner= new CCommentScanner(fColorManager, store, coreStore, ICColorConstants.C_MULTI_LINE_COMMENT);
103
		fSinglelineCommentScanner= new CCommentScanner(fColorManager, store, coreStore, ICColorConstants.C_SINGLE_LINE_COMMENT);
104
		fStringScanner= new SingleTokenCScanner(fColorManager, store, ICColorConstants.C_STRING);
105
		fCPreprocessorScanner= new CPreprocessorScanner(fColorManager, store, GCCLanguage.getDefault());
106
		fCppPreprocessorScanner= new CPreprocessorScanner(fColorManager, store, GPPLanguage.getDefault());
107
106
108
		fPreferenceStore = store;
107
		ITokenStoreFactory factory= new ITokenStoreFactory() {
108
			public ITokenStore createTokenStore(String[] propertyColorNames) {
109
				return new TokenStore(getColorManager(), fPreferenceStore, propertyColorNames);
110
			}
111
		};
112
113
		fMultilineCommentScanner= new CCommentScanner(factory, coreStore, ICColorConstants.C_MULTI_LINE_COMMENT);
114
		fSinglelineCommentScanner= new CCommentScanner(factory, coreStore, ICColorConstants.C_SINGLE_LINE_COMMENT);
115
		fCodeScanner= new CCodeScanner(factory, GCCLanguage.getDefault());
116
		fCppCodeScanner= new CCodeScanner(factory, GPPLanguage.getDefault());
117
118
		fStringScanner= new SingleTokenCScanner(factory, ICColorConstants.C_STRING);
119
		fCPreprocessorScanner= new CPreprocessorScanner(factory, GCCLanguage.getDefault());
120
		fCppPreprocessorScanner= new CPreprocessorScanner(factory, GPPLanguage.getDefault());
121
109
		fPreferenceStore.addPropertyChangeListener(fPreferenceListener);
122
		fPreferenceStore.addPropertyChangeListener(fPreferenceListener);
110
        
123
111
        fCorePreferenceStore= coreStore;
124
		fCorePreferenceStore= coreStore;
112
        if (fCorePreferenceStore != null) {
125
		if (fCorePreferenceStore != null) {
113
            fCorePreferenceStore.addPropertyChangeListener(fPreferenceListener);
126
			fCorePreferenceStore.addPropertyChangeListener(fPreferenceListener);
114
        }
127
		}
115
		
116
	}
128
	}
117
	
129
118
	/**
130
	/**
119
	 * Creates a new C text tools collection and eagerly creates 
131
	 * Creates a new C text tools collection and eagerly creates 
120
	 * and initializes all members of this collection.
132
	 * and initializes all members of this collection.
Lines 122-204 Link Here
122
	public CTextTools() {
134
	public CTextTools() {
123
		this((IPreferenceStore)null);
135
		this((IPreferenceStore)null);
124
	}
136
	}
125
	
137
126
	/**
138
	/**
127
	 * Disposes all members of this tools collection.
139
	 * Disposes all members of this tools collection.
128
	 */
140
	 */
129
	public void dispose() {
141
	public void dispose() {
130
		
142
131
		fCodeScanner= null;
143
		fCodeScanner= null;
132
		fMultilineCommentScanner= null;
144
		fMultilineCommentScanner= null;
133
		fSinglelineCommentScanner= null;
145
		fSinglelineCommentScanner= null;
134
		fStringScanner= null;
146
		fStringScanner= null;
135
		
147
136
		if (fColorManager != null) {
148
		if (fColorManager != null) {
137
			fColorManager.dispose();
149
			fColorManager.dispose();
138
			fColorManager= null;
150
			fColorManager= null;
139
		}
151
		}
140
		
152
141
		if (fPreferenceStore != null) {
153
		if (fPreferenceStore != null) {
142
			fPreferenceStore.removePropertyChangeListener(fPreferenceListener);
154
			fPreferenceStore.removePropertyChangeListener(fPreferenceListener);
143
			fPreferenceStore= null;
155
			fPreferenceStore= null;
144
            
156
145
            if (fCorePreferenceStore != null) {
157
			if (fCorePreferenceStore != null) {
146
                fCorePreferenceStore.removePropertyChangeListener(fPreferenceListener);
158
				fCorePreferenceStore.removePropertyChangeListener(fPreferenceListener);
147
                fCorePreferenceStore= null;
159
				fCorePreferenceStore= null;
148
            }
160
			}
149
            
161
150
			fPreferenceListener= null;
162
			fPreferenceListener= null;
151
		}
163
		}
152
	}
164
	}
153
	
165
154
	/**
166
	/**
155
	 * Gets the color manager.
167
	 * Gets the color manager.
156
	 */
168
	 */
157
	public CColorManager getColorManager() {
169
	public CColorManager getColorManager() {
158
		return fColorManager;
170
		return fColorManager;
159
	}
171
	}
160
	
172
161
	/**
173
	/**
162
	 * Gets the code scanner used.
174
	 * Gets the code scanner used.
163
	 */
175
	 */
164
	public RuleBasedScanner getCCodeScanner() {
176
	public RuleBasedScanner getCCodeScanner() {
165
		return fCodeScanner;
177
		return fCodeScanner;
166
	}
178
	}
167
	
179
168
	/**
180
	/**
169
	 * Gets the code scanner used.
181
	 * Gets the code scanner used.
170
	 */
182
	 */
171
	public RuleBasedScanner getCppCodeScanner() {
183
	public RuleBasedScanner getCppCodeScanner() {
172
		return fCppCodeScanner;
184
		return fCppCodeScanner;
173
	}
185
	}
174
	
186
175
	/**
187
	/**
176
	 * Returns a scanner which is configured to scan 
188
	 * Returns a scanner which is configured to scan 
177
	 * C-specific partitions, which are multi-line comments,
189
	 * C-specific partitions, which are multi-line comments,
178
	 * and regular C source code.
190
	 * and regular C source code.
179
	 *
191
	 *
192
	 * @param owner may be null
180
	 * @return a C partition scanner
193
	 * @return a C partition scanner
181
	 */
194
	 */
182
	public IPartitionTokenScanner getPartitionScanner() {
195
	public IPartitionTokenScanner getPartitionScanner(IDocCommentOwner owner) {
183
		return new FastCPartitionScanner();
196
		return new FastCPartitionScanner(owner);
184
	}
197
	}
185
	
198
186
	/**
199
	/**
187
	 * Gets the document provider used.
200
	 * Gets the document provider used.
188
	 */
201
	 */
189
	public IDocumentPartitioner createDocumentPartitioner() {
202
	public IDocumentPartitioner createDocumentPartitioner(IDocCommentOwner owner) {
190
		
203
		return new FastCPartitioner(getPartitionScanner(owner), ICPartitions.ALL_CPARTITIONS);
191
		String[] types= new String[] {
192
			ICPartitions.C_MULTI_LINE_COMMENT,
193
			ICPartitions.C_SINGLE_LINE_COMMENT,
194
			ICPartitions.C_STRING,
195
			ICPartitions.C_CHARACTER,
196
			ICPartitions.C_PREPROCESSOR
197
		};
198
		
199
		return new FastCPartitioner(getPartitionScanner(), types);
200
	}
204
	}
201
	
205
202
	/**
206
	/**
203
	 * Returns a scanner which is configured to scan C multiline comments.
207
	 * Returns a scanner which is configured to scan C multiline comments.
204
	 *
208
	 *
Lines 216-222 Link Here
216
	public RuleBasedScanner getSinglelineCommentScanner() {
220
	public RuleBasedScanner getSinglelineCommentScanner() {
217
		return fSinglelineCommentScanner;
221
		return fSinglelineCommentScanner;
218
	}
222
	}
219
	
223
220
	/**
224
	/**
221
	 * Returns a scanner which is configured to scan C strings.
225
	 * Returns a scanner which is configured to scan C strings.
222
	 *
226
	 *
Lines 243-249 Link Here
243
	public RuleBasedScanner getCppPreprocessorScanner() {
247
	public RuleBasedScanner getCppPreprocessorScanner() {
244
		return fCppPreprocessorScanner;
248
		return fCppPreprocessorScanner;
245
	}
249
	}
246
	
250
247
	/**
251
	/**
248
	 * Determines whether the preference change encoded by the given event
252
	 * Determines whether the preference change encoded by the given event
249
	 * changes the behavior of one its contained components.
253
	 * changes the behavior of one its contained components.
Lines 253-265 Link Here
253
	 */
257
	 */
254
	public boolean affectsBehavior(PropertyChangeEvent event) {
258
	public boolean affectsBehavior(PropertyChangeEvent event) {
255
		return  fCodeScanner.affectsBehavior(event) ||
259
		return  fCodeScanner.affectsBehavior(event) ||
256
					fCppCodeScanner.affectsBehavior(event) ||
260
		fCppCodeScanner.affectsBehavior(event) ||
257
					fMultilineCommentScanner.affectsBehavior(event) ||
261
		fMultilineCommentScanner.affectsBehavior(event) ||
258
					fSinglelineCommentScanner.affectsBehavior(event) ||
262
		fSinglelineCommentScanner.affectsBehavior(event) ||
259
					fStringScanner.affectsBehavior(event) ||
263
		fStringScanner.affectsBehavior(event) ||
260
					fCPreprocessorScanner.affectsBehavior(event);
264
		fCPreprocessorScanner.affectsBehavior(event);
261
	}
265
	}
262
	
266
263
	/**
267
	/**
264
	 * Adapts the behavior of the contained components to the change
268
	 * Adapts the behavior of the contained components to the change
265
	 * encoded in the given event.
269
	 * encoded in the given event.
Lines 286-297 Link Here
286
	/**
290
	/**
287
	 * Sets up the document partitioner for the given document for the given partitioning.
291
	 * Sets up the document partitioner for the given document for the given partitioning.
288
	 * 
292
	 * 
289
	 * @param document the document to be set up
293
	 * @param document
290
	 * @param partitioning the document partitioning
294
	 * @param partitioning
291
	 * @since 3.0
295
	 * @param owner may be null
296
	 * @since 5.0
292
	 */
297
	 */
293
	public void setupCDocumentPartitioner(IDocument document, String partitioning) {
298
	public void setupCDocumentPartitioner(IDocument document, String partitioning, IDocCommentOwner owner) {
294
		IDocumentPartitioner partitioner= createDocumentPartitioner();
299
		IDocumentPartitioner partitioner= createDocumentPartitioner(owner);
295
		if (document instanceof IDocumentExtension3) {
300
		if (document instanceof IDocumentExtension3) {
296
			IDocumentExtension3 extension3= (IDocumentExtension3) document;
301
			IDocumentExtension3 extension3= (IDocumentExtension3) document;
297
			extension3.setDocumentPartitioner(partitioning, partitioner);
302
			extension3.setDocumentPartitioner(partitioning, partitioner);
Lines 300-306 Link Here
300
		}
305
		}
301
		partitioner.connect(document);
306
		partitioner.connect(document);
302
	}
307
	}
303
	
308
309
	/**
310
	 * Sets up the given document for the default partitioning.
311
	 * 
312
	 * @param document the document to be set up
313
	 * @param location the path of the resource backing the document. May be null.
314
	 * @param locationKind the type of path specified above. May be null.
315
	 * @since 3.0
316
	 */
317
	public void setupCDocument(IDocument document, IPath location, LocationKind locationKind) {
318
		IDocCommentOwner owner= getDocumentationCommentOwner(location, locationKind);
319
		setupCDocumentPartitioner(document, fDocumentPartitioning, owner);
320
	}
321
304
	/**
322
	/**
305
	 * Sets up the given document for the default partitioning.
323
	 * Sets up the given document for the default partitioning.
306
	 * 
324
	 * 
Lines 308-314 Link Here
308
	 * @since 3.0
326
	 * @since 3.0
309
	 */
327
	 */
310
	public void setupCDocument(IDocument document) {
328
	public void setupCDocument(IDocument document) {
311
		setupCDocumentPartitioner(document, fDocumentPartitioning);
329
		setupCDocumentPartitioner(document, fDocumentPartitioning, null);
312
	}
330
	}
313
331
314
	/**
332
	/**
Lines 329-333 Link Here
329
	public void setDocumentPartitioning(String documentPartitioning) {
347
	public void setDocumentPartitioning(String documentPartitioning) {
330
		fDocumentPartitioning = documentPartitioning;
348
		fDocumentPartitioning = documentPartitioning;
331
	}
349
	}
332
350
	
351
	/**
352
	 * @param location
353
	 * @param locationKind
354
	 * @return the documentation comment owner mapped to the specified location. If there is
355
	 * no mapping, or the <code>location</code>/<code>locationKind</code> is not available, the
356
	 * workspace default is returned.
357
	 */
358
	private IDocCommentOwner getDocumentationCommentOwner(IPath location, LocationKind locationKind) {
359
		if(location!=null && LocationKind.IFILE.equals(locationKind)) {
360
			IFile file= ResourcesPlugin.getWorkspace().getRoot().getFile(location);
361
			return DocCommentOwnerManager.getInstance().getCommentOwner(file);
362
		}
363
		return DocCommentOwnerManager.getInstance().getWorkspaceCommentOwner();
364
	}
333
}
365
}
(-)src/org/eclipse/cdt/internal/ui/text/CCommentAutoIndentStrategy.java (-122 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     QNX Software System
11
 *     Anton Leherbauer (Wind River Systems) - Fixed bug 48339
12
 *******************************************************************************/
13
package org.eclipse.cdt.internal.ui.text;
14
15
import org.eclipse.jface.text.BadLocationException;
16
import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
17
import org.eclipse.jface.text.DocumentCommand;
18
import org.eclipse.jface.text.IDocument;
19
import org.eclipse.jface.text.IRegion;
20
21
/**
22
 * Auto indent strategy for C/C++ multiline comments
23
 */
24
public class CCommentAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
25
26
	public CCommentAutoIndentStrategy() {
27
	}
28
29
	/**
30
	 * Returns whether the text ends with one of the given search strings.
31
	 */
32
	private boolean endsWithDelimiter(IDocument d, String txt) {
33
		String[] delimiters= d.getLegalLineDelimiters();
34
		
35
		for (int i= 0; i < delimiters.length; i++) {
36
			if (txt.endsWith(delimiters[i]))
37
				return true;
38
		}
39
		
40
		return false;
41
	}
42
43
	/**
44
	 * Copies the indentation of the previous line and adds a star.
45
	 * If the comment just started on this line adds also a blank.
46
	 *
47
	 * @param d the document to work on
48
	 * @param c the command to deal with
49
	 */
50
	static void commentIndentAfterNewLine(IDocument d, DocumentCommand c) {
51
		
52
		if (c.offset == -1 || d.getLength() == 0)
53
			return;
54
			
55
		try {
56
			// find start of line
57
			IRegion info= d.getLineInformationOfOffset(c.offset);
58
			int start= info.getOffset();
59
				
60
			// find white spaces
61
			int end= findEndOfWhiteSpaceAt(d, start, c.offset);
62
							
63
			StringBuffer buf= new StringBuffer(c.text);
64
			if (end >= start) {	// 1GEYL1R: ITPJUI:ALL - java doc edit smartness not work for class comments
65
				// append to input
66
				buf.append(d.get(start, end - start));				
67
				if (end < c.offset) {
68
					if (d.getChar(end) == '/') {
69
						// comment started on this line
70
						buf.append(" * ");	 //$NON-NLS-1$
71
					} else if (d.getChar(end) == '*') {
72
						buf.append("* "); //$NON-NLS-1$
73
					}
74
				}			
75
			}
76
77
			
78
			c.text= buf.toString();
79
				
80
		} catch (BadLocationException excp) {
81
			// stop work
82
		}	
83
	}	
84
	
85
	static int findEndOfWhiteSpaceAt(IDocument document, int offset, int end) throws BadLocationException {
86
		while (offset < end) {
87
			char c= document.getChar(offset);
88
			if (c != ' ' && c != '\t') {
89
				return offset;
90
			}
91
			offset++;
92
		}
93
		return end;
94
	}
95
96
	static void commentIndentForCommentEnd(IDocument d, DocumentCommand c) {
97
		if (c.offset < 2 || d.getLength() == 0) {
98
			return;
99
		}
100
		try {
101
			if ("* ".equals(d.get(c.offset - 2, 2))) { //$NON-NLS-1$
102
				// modify document command
103
				c.length++;
104
				c.offset--;
105
			}					
106
		} catch (BadLocationException excp) {
107
			// stop work
108
		}
109
	}
110
111
	/*
112
	 * @see IAutoIndentStrategy#customizeDocumentCommand
113
	 */
114
	public void customizeDocumentCommand(IDocument d, DocumentCommand c) {
115
		if (c.length == 0 && c.text != null && endsWithDelimiter(d, c.text))
116
			commentIndentAfterNewLine(d, c);
117
		else if ("/".equals(c.text)) { //$NON-NLS-1$
118
			commentIndentForCommentEnd(d, c);
119
		}
120
	}
121
}
122
(-)src/org/eclipse/cdt/internal/ui/text/CCommentScanner.java (-137 / +34 lines)
Lines 8-159 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Anton Leherbauer (Wind River Systems)
10
 *     Anton Leherbauer (Wind River Systems)
11
 *     Andrew Ferguson (Symbian)
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.cdt.internal.ui.text;
13
package org.eclipse.cdt.internal.ui.text;
13
14
14
15
import java.util.Collections;
15
import java.util.ArrayList;
16
import java.util.List;
16
import java.util.List;
17
import java.util.StringTokenizer;
18
17
19
import org.eclipse.cdt.core.CCorePreferenceConstants;
20
import org.eclipse.core.runtime.Preferences;
18
import org.eclipse.core.runtime.Preferences;
21
import org.eclipse.jface.preference.IPreferenceStore;
19
import org.eclipse.jface.preference.IPreferenceStore;
22
import org.eclipse.jface.text.rules.IToken;
23
import org.eclipse.jface.text.rules.IWordDetector;
24
import org.eclipse.jface.text.rules.Token;
25
import org.eclipse.jface.text.rules.WordRule;
26
import org.eclipse.jface.util.PropertyChangeEvent;
27
20
21
import org.eclipse.cdt.ui.PreferenceConstants;
22
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
23
import org.eclipse.cdt.ui.text.TaskTagRule;
28
24
29
/**
25
/**
30
 * CCommentScanner.java
26
 * Default token-scanner used for plain (non-documentation-comment) single and multi-line comments, with awareness of
27
 * task tags.
31
 */
28
 */
32
public class CCommentScanner extends AbstractCScanner
29
public class CCommentScanner extends AbstractCScanner {
33
{
30
	private static String TASK_TAG_KEY= PreferenceConstants.EDITOR_TASK_TAG_COLOR;
34
    private static class TaskTagDetector implements IWordDetector {
31
	private Preferences fCorePreferenceStore;
35
32
		
36
        public boolean isWordStart(char c) {
33
	public CCommentScanner(ITokenStoreFactory tokenStoreFactory, String defaultTokenProperty) {
37
            return Character.isLetter(c);
34
		this(tokenStoreFactory, null, defaultTokenProperty, new String[] { defaultTokenProperty, TASK_TAG_KEY });
38
        }
35
	}
39
36
40
        public boolean isWordPart(char c) {
37
	public CCommentScanner(ITokenStoreFactory tokenStoreFactory, Preferences coreStore, String defaultTokenProperty) {
41
            return Character.isLetter(c);
38
		this(tokenStoreFactory, coreStore, defaultTokenProperty, new String[] { defaultTokenProperty, TASK_TAG_KEY });
42
        }
39
	}
43
    }
40
44
41
	private CCommentScanner(ITokenStoreFactory tokenStoreFactory, Preferences coreStore, String defaultTokenProperty, String[] tokenProperties) {
45
    private class TaskTagRule extends WordRule {
42
		super(tokenStoreFactory.createTokenStore(tokenProperties));
46
43
		fCorePreferenceStore= coreStore;
47
        private IToken fToken;
44
		setRules(createRules(defaultTokenProperty));
48
45
	}
49
        public TaskTagRule(IToken token) {
46
50
            super(new TaskTagDetector(), Token.UNDEFINED);
47
	 protected List createRules(String defaultTokenProperty) {
51
            fToken= token;
48
		 setDefaultReturnToken(getToken(defaultTokenProperty));
52
        }
49
		 
53
    
50
		 IPreferenceStore store= fTokenStore.getPreferenceStore();
54
        public void clearTaskTags() {
51
		 String taskWords= TaskTagRule.getTaskWords(store, fCorePreferenceStore);
55
            fWords.clear();
52
		 TaskTagRule taskTagRule= new TaskTagRule(getToken(TASK_TAG_KEY), taskWords);
56
        }
53
		 addPropertyChangeParticipant(taskTagRule);
57
    
54
		 return Collections.singletonList(taskTagRule);
58
        public void addTaskTags(String value) {
55
	 }
59
            String[] tasks= split(value, ","); //$NON-NLS-1$
60
            for (int i= 0; i < tasks.length; i++) {
61
                if (tasks[i].length() > 0) {
62
                    addWord(tasks[i], fToken);
63
                }
64
            }
65
        }
66
        
67
        private String[] split(String value, String delimiters) {
68
            StringTokenizer tokenizer= new StringTokenizer(value, delimiters);
69
            int size= tokenizer.countTokens();
70
            String[] tokens= new String[size];
71
            for (int i = 0; i < size; i++)
72
                tokens[i] = tokenizer.nextToken();
73
            return tokens;
74
        }
75
    }
76
    
77
    private static final String TODO_TASK_TAGS= CCorePreferenceConstants.TODO_TASK_TAGS;    
78
    protected static final String TASK_TAG= ICColorConstants.TASK_TAG;
79
80
    private TaskTagRule fTaskTagRule;
81
    private Preferences fCorePreferenceStore;
82
    private String fDefaultTokenProperty;
83
    private String[] fTokenProperties;
84
85
    public CCommentScanner(IColorManager manager, IPreferenceStore store, String defaultTokenProperty) {
86
        this(manager, store, null, defaultTokenProperty, new String[] { defaultTokenProperty, TASK_TAG });
87
    }
88
89
    public CCommentScanner(IColorManager manager, IPreferenceStore store, Preferences coreStore, String defaultTokenProperty) {
90
        this(manager, store, coreStore, defaultTokenProperty, new String[] { defaultTokenProperty, TASK_TAG });
91
    }
92
    
93
    public CCommentScanner(IColorManager manager, IPreferenceStore store, Preferences coreStore, String defaultTokenProperty, String[] tokenProperties) {
94
        super(manager, store);
95
        
96
        fCorePreferenceStore= coreStore;
97
        fDefaultTokenProperty= defaultTokenProperty;
98
        fTokenProperties= tokenProperties;
99
100
        initialize();
101
    }
102
103
    /*
104
     * @see AbstractCScanner#createRules()
105
     */
106
    protected List createRules() {
107
        List list= new ArrayList();
108
        
109
        String tasks= null;
110
        if (getPreferenceStore().contains(TODO_TASK_TAGS)) {
111
            tasks= getPreferenceStore().getString(TODO_TASK_TAGS);
112
        } else if (fCorePreferenceStore != null) {
113
            tasks= fCorePreferenceStore.getString(TODO_TASK_TAGS);
114
        }
115
        
116
        if (tasks != null) {
117
            // Add rule for Task Tags.
118
            fTaskTagRule= new TaskTagRule(getToken(TASK_TAG));
119
            fTaskTagRule.addTaskTags(tasks);
120
            list.add(fTaskTagRule);
121
        }
122
123
        setDefaultReturnToken(getToken(fDefaultTokenProperty));
124
125
        return list;
126
    }
127
128
    /*
129
     * @see org.eclipse.cdt.internal.ui.text.AbstractJavaScanner#affectsBehavior(org.eclipse.jface.util.PropertyChangeEvent)
130
     */
131
    public boolean affectsBehavior(PropertyChangeEvent event) {
132
        return event.getProperty().equals(TODO_TASK_TAGS) || super.affectsBehavior(event);
133
    }
134
135
    /*
136
     * @see org.eclipse.cdt.internal.ui.text.AbstractJavaScanner#adaptToPreferenceChange(org.eclipse.jface.util.PropertyChangeEvent)
137
     */
138
    public void adaptToPreferenceChange(PropertyChangeEvent event) {
139
        if (fTaskTagRule != null && event.getProperty().equals(TODO_TASK_TAGS)) {
140
            Object value= event.getNewValue();
141
142
            if (value instanceof String) {
143
                fTaskTagRule.clearTaskTags();
144
                fTaskTagRule.addTaskTags((String) value);
145
            }
146
            
147
        } else if (super.affectsBehavior(event)) {
148
            super.adaptToPreferenceChange(event);
149
        }
150
    }
151
152
    /*
153
     * @see org.eclipse.cdt.internal.ui.text.AbstractJavaScanner#getTokenProperties()
154
     */
155
    protected String[] getTokenProperties() {
156
        return fTokenProperties;
157
    }
158
159
}
56
}
(-)src/org/eclipse/cdt/internal/ui/text/CSourceViewerConfiguration.java (-55 / +133 lines)
Lines 11-22 Link Here
11
 *     Anton Leherbauer (Wind River Systems)
11
 *     Anton Leherbauer (Wind River Systems)
12
 *     Sergey Prigogin (Google)
12
 *     Sergey Prigogin (Google)
13
 *     Markus Schorn (Wind River Systems)
13
 *     Markus Schorn (Wind River Systems)
14
 *     Andrew Ferguson (Symbian)
14
 *******************************************************************************/
15
 *******************************************************************************/
15
package org.eclipse.cdt.internal.ui.text;
16
package org.eclipse.cdt.internal.ui.text;
16
17
17
import java.util.Arrays;
18
import java.util.Arrays;
18
19
19
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IProject;
22
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IPath;
24
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.NullProgressMonitor;
25
import org.eclipse.core.runtime.NullProgressMonitor;
Lines 77-82 Link Here
77
import org.eclipse.cdt.ui.CUIPlugin;
80
import org.eclipse.cdt.ui.CUIPlugin;
78
import org.eclipse.cdt.ui.ILanguageUI;
81
import org.eclipse.cdt.ui.ILanguageUI;
79
import org.eclipse.cdt.ui.text.ICPartitions;
82
import org.eclipse.cdt.ui.text.ICPartitions;
83
import org.eclipse.cdt.ui.text.ICTokenScanner;
84
import org.eclipse.cdt.ui.text.ITokenStore;
85
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
86
import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy;
87
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
88
import org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration;
80
89
81
import org.eclipse.cdt.internal.corext.util.CodeFormatterUtil;
90
import org.eclipse.cdt.internal.corext.util.CodeFormatterUtil;
82
91
Lines 90-95 Link Here
90
import org.eclipse.cdt.internal.ui.text.contentassist.CContentAssistProcessor;
99
import org.eclipse.cdt.internal.ui.text.contentassist.CContentAssistProcessor;
91
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
100
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
92
import org.eclipse.cdt.internal.ui.text.correction.CCorrectionAssistant;
101
import org.eclipse.cdt.internal.ui.text.correction.CCorrectionAssistant;
102
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
93
import org.eclipse.cdt.internal.ui.typehierarchy.THInformationControl;
103
import org.eclipse.cdt.internal.ui.typehierarchy.THInformationControl;
94
import org.eclipse.cdt.internal.ui.typehierarchy.THInformationProvider;
104
import org.eclipse.cdt.internal.ui.typehierarchy.THInformationProvider;
95
105
Lines 111-121 Link Here
111
	/**
121
	/**
112
	 * The C multi-line comment scanner.
122
	 * The C multi-line comment scanner.
113
	 */
123
	 */
114
	private AbstractCScanner fMultilineCommentScanner;
124
	private ICTokenScanner fMultilineDocCommentScanner;
115
	/**
125
	/**
116
	 * The C single-line comment scanner.
126
	 * The C single-line comment scanner.
117
	 */
127
	 */
118
	private AbstractCScanner fSinglelineCommentScanner;
128
	private ICTokenScanner fSinglelineDocCommentScanner;
119
	/**
129
	/**
120
	 * The C string scanner.
130
	 * The C string scanner.
121
	 */
131
	 */
Lines 147-170 Link Here
147
	}
157
	}
148
158
149
	/**
159
	/**
150
	 * Returns the C multi-line comment scanner for this configuration.
151
	 *
152
	 * @return the C multi-line comment scanner
153
	 */
154
	protected RuleBasedScanner getMultilineCommentScanner() {
155
		return fMultilineCommentScanner;
156
	}
157
158
	/**
159
	 * Returns the C single-line comment scanner for this configuration.
160
	 *
161
	 * @return the C single-line comment scanner
162
	 */
163
	protected RuleBasedScanner getSinglelineCommentScanner() {
164
		return fSinglelineCommentScanner;
165
	}
166
167
	/**
168
	 * Returns the C string scanner for this configuration.
160
	 * Returns the C string scanner for this configuration.
169
	 *
161
	 *
170
	 * @return the C string scanner
162
	 * @return the C string scanner
Lines 184-193 Link Here
184
		}
176
		}
185
		AbstractCScanner scanner= null;
177
		AbstractCScanner scanner= null;
186
		if (language instanceof ICLanguageKeywords) {
178
		if (language instanceof ICLanguageKeywords) {
187
			scanner= new CPreprocessorScanner(getColorManager(), fPreferenceStore, (ICLanguageKeywords)language);
179
			scanner= new CPreprocessorScanner(getTokenStoreFactory(), (ICLanguageKeywords)language);
188
		}
180
		}
189
		if (scanner == null) {
181
		if (scanner == null) {
190
			scanner= new CPreprocessorScanner(getColorManager(), fPreferenceStore, GPPLanguage.getDefault());
182
			scanner= new CPreprocessorScanner(getTokenStoreFactory(), GPPLanguage.getDefault());
191
		}
183
		}
192
		fPreprocessorScanner= scanner;
184
		fPreprocessorScanner= scanner;
193
		return fPreprocessorScanner;
185
		return fPreprocessorScanner;
Lines 250-263 Link Here
250
        presenter.setSizeConstraints(50, 20, true, false);
242
        presenter.setSizeConstraints(50, 20, true, false);
251
        return presenter;
243
        return presenter;
252
    }
244
    }
253
245
    
254
	/**
246
	/**
255
	 * Initializes the scanners.
247
	 * Initializes the scanners.
256
	 */
248
	 */
257
	private void initializeScanners() {
249
	private void initializeScanners() {
258
		fMultilineCommentScanner= new CCommentScanner(getColorManager(), fPreferenceStore, ICColorConstants.C_MULTI_LINE_COMMENT);
250
		fStringScanner= new SingleTokenCScanner(getTokenStoreFactory(), ICColorConstants.C_STRING);
259
		fSinglelineCommentScanner= new CCommentScanner(getColorManager(), fPreferenceStore, ICColorConstants.C_SINGLE_LINE_COMMENT);
260
		fStringScanner= new SingleTokenCScanner(getColorManager(), fPreferenceStore, ICColorConstants.C_STRING);
261
	}
251
	}
262
252
263
    /**
253
    /**
Lines 274-290 Link Here
274
264
275
		reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
265
		reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
276
		reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
266
		reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
277
278
		//TextAttribute attr = new TextAttribute(manager.getColor(ICColorConstants.C_DEFAULT));
279
		
267
		
280
		dr= new DefaultDamagerRepairer(getSinglelineCommentScanner());		
268
		dr= new DefaultDamagerRepairer(new CCommentScanner(getTokenStoreFactory(),  ICColorConstants.C_SINGLE_LINE_COMMENT));
281
		reconciler.setDamager(dr, ICPartitions.C_SINGLE_LINE_COMMENT);
269
		reconciler.setDamager(dr, ICPartitions.C_SINGLE_LINE_COMMENT);
282
		reconciler.setRepairer(dr, ICPartitions.C_SINGLE_LINE_COMMENT);
270
		reconciler.setRepairer(dr, ICPartitions.C_SINGLE_LINE_COMMENT);
283
		
271
284
		dr= new DefaultDamagerRepairer(getMultilineCommentScanner());		
272
		dr= new DefaultDamagerRepairer(new CCommentScanner(getTokenStoreFactory(),  ICColorConstants.C_MULTI_LINE_COMMENT));
285
		reconciler.setDamager(dr, ICPartitions.C_MULTI_LINE_COMMENT);
273
		reconciler.setDamager(dr, ICPartitions.C_MULTI_LINE_COMMENT);
286
		reconciler.setRepairer(dr, ICPartitions.C_MULTI_LINE_COMMENT);
274
		reconciler.setRepairer(dr, ICPartitions.C_MULTI_LINE_COMMENT);
287
275
		
276
		ICTokenScanner docCommentSingleScanner= getSinglelineDocCommentScanner(getProject());
277
		if(docCommentSingleScanner!=null) {
278
			dr= new DefaultDamagerRepairer(docCommentSingleScanner);
279
			reconciler.setDamager(dr, ICPartitions.C_SINGLE_LINE_DOC_COMMENT);
280
			reconciler.setRepairer(dr, ICPartitions.C_SINGLE_LINE_DOC_COMMENT);
281
		}
282
	
283
		ICTokenScanner docCommentMultiScanner= getMultilineDocCommentScanner(getProject());
284
		if(docCommentMultiScanner!=null) {
285
			dr= new DefaultDamagerRepairer(docCommentMultiScanner);
286
			reconciler.setDamager(dr, ICPartitions.C_MULTI_LINE_DOC_COMMENT);
287
			reconciler.setRepairer(dr, ICPartitions.C_MULTI_LINE_DOC_COMMENT);
288
		}
289
		
288
		dr= new DefaultDamagerRepairer(getStringScanner());
290
		dr= new DefaultDamagerRepairer(getStringScanner());
289
		reconciler.setDamager(dr, ICPartitions.C_STRING);
291
		reconciler.setDamager(dr, ICPartitions.C_STRING);
290
		reconciler.setRepairer(dr, ICPartitions.C_STRING);
292
		reconciler.setRepairer(dr, ICPartitions.C_STRING);
Lines 299-306 Link Here
299
		
301
		
300
		return reconciler;
302
		return reconciler;
301
	}
303
	}
304
      
305
	/**
306
	 * Returns the C multi-line comment scanner for this configuration.
307
	 *
308
	 * @return the C multi-line comment scanner
309
	 */
310
	protected ICTokenScanner getMultilineDocCommentScanner(IResource resource) {
311
		if (fMultilineDocCommentScanner == null) {
312
			IDocCommentViewerConfiguration owner= DocCommentOwnerManager.getInstance().getCommentOwner(resource).getMultilineConfiguration();
313
			fMultilineDocCommentScanner= owner.createCommentScanner(getTokenStoreFactory());
314
		}
315
		return fMultilineDocCommentScanner;
316
	}
302
317
303
	/**
318
	/**
319
	 * Returns the C single-line comment scanner for this configuration.
320
	 *
321
	 * @return the C single-line comment scanner
322
	 */
323
	protected ICTokenScanner getSinglelineDocCommentScanner(IResource resource) {
324
		if (fSinglelineDocCommentScanner == null) {
325
			IDocCommentViewerConfiguration owner= DocCommentOwnerManager.getInstance().getCommentOwner(resource).getSinglelineConfiguration();		
326
			fSinglelineDocCommentScanner= owner.createCommentScanner(getTokenStoreFactory());
327
		}
328
		return fSinglelineDocCommentScanner;
329
	}
330
    
331
	/**
304
	 * @return the code scanner for the given language
332
	 * @return the code scanner for the given language
305
	 */
333
	 */
306
	protected RuleBasedScanner getCodeScanner(ILanguage language) {
334
	protected RuleBasedScanner getCodeScanner(ILanguage language) {
Lines 310-323 Link Here
310
		RuleBasedScanner scanner= null;
338
		RuleBasedScanner scanner= null;
311
		if (language instanceof ICLanguageKeywords) {
339
		if (language instanceof ICLanguageKeywords) {
312
			ICLanguageKeywords cLang= (ICLanguageKeywords)language;
340
			ICLanguageKeywords cLang= (ICLanguageKeywords)language;
313
			scanner = new CCodeScanner(getColorManager(), fPreferenceStore, cLang);
341
			scanner = new CCodeScanner(getTokenStoreFactory(), cLang);
314
		} else if (language != null) {
342
		} else if (language != null) {
315
			ILanguageUI languageUI = (ILanguageUI)language.getAdapter(ILanguageUI.class);
343
			ILanguageUI languageUI = (ILanguageUI)language.getAdapter(ILanguageUI.class);
316
			if (languageUI != null)
344
			if (languageUI != null)
317
				scanner = languageUI.getCodeScanner();
345
				scanner = languageUI.getCodeScanner();
318
		}
346
		}
319
		if (scanner == null) {
347
		if (scanner == null) {
320
			scanner = new CCodeScanner(getColorManager(), fPreferenceStore, GPPLanguage.getDefault());
348
			scanner = new CCodeScanner(getTokenStoreFactory(), GPPLanguage.getDefault());
321
		}
349
		}
322
		if (scanner instanceof AbstractCScanner) {
350
		if (scanner instanceof AbstractCScanner) {
323
			fCodeScanner= (AbstractCScanner)scanner;
351
			fCodeScanner= (AbstractCScanner)scanner;
Lines 347-352 Link Here
347
		processor = new CContentAssistProcessor(getEditor(), sourceViewer, assistant, ICPartitions.C_SINGLE_LINE_COMMENT);
375
		processor = new CContentAssistProcessor(getEditor(), sourceViewer, assistant, ICPartitions.C_SINGLE_LINE_COMMENT);
348
		assistant.setContentAssistProcessor(processor, ICPartitions.C_SINGLE_LINE_COMMENT);
376
		assistant.setContentAssistProcessor(processor, ICPartitions.C_SINGLE_LINE_COMMENT);
349
377
378
		processor = new CContentAssistProcessor(getEditor(), sourceViewer, assistant, ICPartitions.C_MULTI_LINE_DOC_COMMENT);
379
		assistant.setContentAssistProcessor(processor, ICPartitions.C_MULTI_LINE_DOC_COMMENT);
380
381
		processor = new CContentAssistProcessor(getEditor(), sourceViewer, assistant, ICPartitions.C_SINGLE_LINE_DOC_COMMENT);
382
		assistant.setContentAssistProcessor(processor, ICPartitions.C_SINGLE_LINE_DOC_COMMENT);
383
350
		processor = new CContentAssistProcessor(getEditor(), sourceViewer, assistant, ICPartitions.C_STRING);
384
		processor = new CContentAssistProcessor(getEditor(), sourceViewer, assistant, ICPartitions.C_STRING);
351
		assistant.setContentAssistProcessor(processor, ICPartitions.C_STRING);
385
		assistant.setContentAssistProcessor(processor, ICPartitions.C_STRING);
352
386
Lines 410-435 Link Here
410
	 */
444
	 */
411
	public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
445
	public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
412
		String partitioning= getConfiguredDocumentPartitioning(sourceViewer);
446
		String partitioning= getConfiguredDocumentPartitioning(sourceViewer);
447
		
448
		IDocCommentOwner owner= DocCommentOwnerManager.getInstance().getCommentOwner(getProject());
449
		IAutoEditStrategy single= owner.getSinglelineConfiguration().createAutoEditStrategy();
450
		IAutoEditStrategy multi= owner.getMultilineConfiguration().createAutoEditStrategy();
451
		
452
		IAutoEditStrategy[] NONE= new IAutoEditStrategy[0];
453
		
413
		if (ICPartitions.C_MULTI_LINE_COMMENT.equals(contentType))
454
		if (ICPartitions.C_MULTI_LINE_COMMENT.equals(contentType))
414
			return new IAutoEditStrategy[] { new CCommentAutoIndentStrategy() };
455
			return new IAutoEditStrategy[] { new DefaultMultilineCommentAutoEditStrategy() };
456
		if (ICPartitions.C_SINGLE_LINE_DOC_COMMENT.equals(contentType))
457
			return single!=null ? new IAutoEditStrategy[] {single} : NONE;
458
		else if (ICPartitions.C_MULTI_LINE_DOC_COMMENT.equals(contentType))
459
			return multi!=null? new IAutoEditStrategy[] {multi} : NONE;
415
		else if (ICPartitions.C_STRING.equals(contentType))
460
		else if (ICPartitions.C_STRING.equals(contentType))
416
			return new IAutoEditStrategy[] { /*new SmartSemicolonAutoEditStrategy(partitioning),*/ new CStringAutoIndentStrategy(partitioning, getProject()) };
461
			return new IAutoEditStrategy[] { /*new SmartSemicolonAutoEditStrategy(partitioning),*/ new CStringAutoIndentStrategy(partitioning, getCProject()) };
417
		else
462
		else
418
			return new IAutoEditStrategy[] { new CAutoIndentStrategy(partitioning, getProject()) };
463
			return new IAutoEditStrategy[] { new CAutoIndentStrategy(partitioning, getCProject()) };
419
	}
464
	}
420
465
	
421
	/**
466
	/**
422
	 * @see SourceViewerConfiguration#getDoubleClickStrategy(ISourceViewer, String)
467
	 * @see SourceViewerConfiguration#getDoubleClickStrategy(ISourceViewer, String)
423
	 */
468
	 */
424
	public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
469
	public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
425
		if (ICPartitions.C_MULTI_LINE_COMMENT.equals(contentType) ||
470
		if (ICPartitions.C_MULTI_LINE_COMMENT.equals(contentType) ||
426
				ICPartitions.C_SINGLE_LINE_COMMENT.equals(contentType))
471
				ICPartitions.C_SINGLE_LINE_COMMENT.equals(contentType)) {
427
			return new DefaultTextDoubleClickStrategy();
472
			return new DefaultTextDoubleClickStrategy();
428
		else if (ICPartitions.C_STRING.equals(contentType) ||
473
		} else if (ICPartitions.C_SINGLE_LINE_DOC_COMMENT.equals(contentType)) {
429
				ICPartitions.C_CHARACTER.equals(contentType))
474
			IDocCommentOwner owner= DocCommentOwnerManager.getInstance().getCommentOwner(getProject());
475
			ITextDoubleClickStrategy single= owner.getSinglelineConfiguration().createDoubleClickStrategy();
476
			return single != null ? single : new DefaultTextDoubleClickStrategy();
477
		} else if(ICPartitions.C_MULTI_LINE_DOC_COMMENT.equals(contentType)) {
478
			IDocCommentOwner owner= DocCommentOwnerManager.getInstance().getCommentOwner(getProject());
479
			ITextDoubleClickStrategy multi= owner.getMultilineConfiguration().createDoubleClickStrategy();
480
			return multi!=null ? multi : new DefaultTextDoubleClickStrategy();
481
		} else if (ICPartitions.C_STRING.equals(contentType) ||
482
				ICPartitions.C_CHARACTER.equals(contentType)) {
430
			return new CStringDoubleClickSelector(getConfiguredDocumentPartitioning(sourceViewer));
483
			return new CStringDoubleClickSelector(getConfiguredDocumentPartitioning(sourceViewer));
431
		else if (ICPartitions.C_PREPROCESSOR.equals(contentType))
484
		} else if (ICPartitions.C_PREPROCESSOR.equals(contentType)) {
432
			return new CStringDoubleClickSelector(getConfiguredDocumentPartitioning(sourceViewer), new CDoubleClickSelector());
485
			return new CStringDoubleClickSelector(getConfiguredDocumentPartitioning(sourceViewer), new CDoubleClickSelector());
486
		}
433
		return new CDoubleClickSelector();
487
		return new CDoubleClickSelector();
434
	}
488
	}
435
489
Lines 444-450 Link Here
444
	 * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
498
	 * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
445
	 */
499
	 */
446
	public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
500
	public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
447
		ICProject project= getProject();
501
		ICProject project= getCProject();
448
		final int tabWidth= CodeFormatterUtil.getTabWidth(project);
502
		final int tabWidth= CodeFormatterUtil.getTabWidth(project);
449
		final int indentWidth= CodeFormatterUtil.getIndentWidth(project);
503
		final int indentWidth= CodeFormatterUtil.getIndentWidth(project);
450
		boolean allowTabs= tabWidth <= indentWidth;
504
		boolean allowTabs= tabWidth <= indentWidth;
Lines 504-510 Link Here
504
		return new String(spaceChars);
558
		return new String(spaceChars);
505
	}
559
	}
506
560
507
	private ICProject getProject() {
561
	/**
562
	 * Returns the ICProject associated with this CSourceViewerConfiguration, or null if
563
	 * no ICProject could be determined
564
	 * @return
565
	 */
566
	private ICProject getCProject() {
508
		ITextEditor editor= getEditor();
567
		ITextEditor editor= getEditor();
509
		if (editor == null)
568
		if (editor == null)
510
			return null;
569
			return null;
Lines 527-533 Link Here
527
	 * @see SourceViewerConfiguration#getTabWidth(ISourceViewer)
586
	 * @see SourceViewerConfiguration#getTabWidth(ISourceViewer)
528
	 */
587
	 */
529
	public int getTabWidth(ISourceViewer sourceViewer) {
588
	public int getTabWidth(ISourceViewer sourceViewer) {
530
		return CodeFormatterUtil.getTabWidth(getProject());
589
		return CodeFormatterUtil.getTabWidth(getCProject());
531
	}
590
	}
532
591
533
	/**
592
	/**
Lines 603-609 Link Here
603
				ICPartitions.C_SINGLE_LINE_COMMENT,
662
				ICPartitions.C_SINGLE_LINE_COMMENT,
604
				ICPartitions.C_STRING,
663
				ICPartitions.C_STRING,
605
				ICPartitions.C_CHARACTER,
664
				ICPartitions.C_CHARACTER,
606
				ICPartitions.C_PREPROCESSOR};
665
				ICPartitions.C_PREPROCESSOR,
666
				ICPartitions.C_SINGLE_LINE_DOC_COMMENT,
667
				ICPartitions.C_MULTI_LINE_DOC_COMMENT
668
		};
607
	}
669
	}
608
	
670
	
609
	/**
671
	/**
Lines 620-627 Link Here
620
	}
682
	}
621
	
683
	
622
	public boolean affectsBehavior(PropertyChangeEvent event) {
684
	public boolean affectsBehavior(PropertyChangeEvent event) {
623
		if (fMultilineCommentScanner.affectsBehavior(event)
685
		if ((fMultilineDocCommentScanner != null && fMultilineDocCommentScanner.affectsBehavior(event))
624
			|| fSinglelineCommentScanner.affectsBehavior(event)
686
			|| (fSinglelineDocCommentScanner != null && fSinglelineDocCommentScanner.affectsBehavior(event))
625
			|| fStringScanner.affectsBehavior(event)) {
687
			|| fStringScanner.affectsBehavior(event)) {
626
			return true;
688
			return true;
627
		}
689
		}
Lines 714-723 Link Here
714
	public void handlePropertyChangeEvent(PropertyChangeEvent event) {
776
	public void handlePropertyChangeEvent(PropertyChangeEvent event) {
715
		if (fCodeScanner != null && fCodeScanner.affectsBehavior(event))
777
		if (fCodeScanner != null && fCodeScanner.affectsBehavior(event))
716
			fCodeScanner.adaptToPreferenceChange(event);
778
			fCodeScanner.adaptToPreferenceChange(event);
717
		if (fMultilineCommentScanner.affectsBehavior(event))
779
		if (fMultilineDocCommentScanner!=null && fMultilineDocCommentScanner.affectsBehavior(event))
718
			fMultilineCommentScanner.adaptToPreferenceChange(event);
780
			fMultilineDocCommentScanner.adaptToPreferenceChange(event);
719
		if (fSinglelineCommentScanner.affectsBehavior(event))
781
		if (fSinglelineDocCommentScanner!=null && fSinglelineDocCommentScanner.affectsBehavior(event))
720
			fSinglelineCommentScanner.adaptToPreferenceChange(event);
782
			fSinglelineDocCommentScanner.adaptToPreferenceChange(event);
721
		if (fStringScanner.affectsBehavior(event))
783
		if (fStringScanner.affectsBehavior(event))
722
			fStringScanner.adaptToPreferenceChange(event);
784
			fStringScanner.adaptToPreferenceChange(event);
723
		if (fPreprocessorScanner != null && fPreprocessorScanner.affectsBehavior(event))
785
		if (fPreprocessorScanner != null && fPreprocessorScanner.affectsBehavior(event))
Lines 833-841 Link Here
833
	 */
895
	 */
834
	public void resetScanners() {
896
	public void resetScanners() {
835
		fCodeScanner= null;
897
		fCodeScanner= null;
898
		fMultilineDocCommentScanner= null;
899
		fSinglelineDocCommentScanner= null;
836
		fPreprocessorScanner= null;
900
		fPreprocessorScanner= null;
837
	}
901
	}
838
902
	
839
	/**
903
	/**
840
	 * Creates macro exploration presenter.
904
	 * Creates macro exploration presenter.
841
	 * @param sourceViewer
905
	 * @param sourceViewer
Lines 873-878 Link Here
873
        };
937
        };
874
        return conrolCreator;
938
        return conrolCreator;
875
    }
939
    }
940
	
941
	private IProject getProject() {
942
		ICProject cproject= getCProject();
943
		if(cproject!=null) {
944
			return cproject.getProject();
945
		}
946
		return null;
947
	}
876
948
877
949
	private ITokenStoreFactory getTokenStoreFactory() {
878
}
950
		return new ITokenStoreFactory() {
951
			public ITokenStore createTokenStore(String[] propertyColorNames) {
952
				return new TokenStore(getColorManager(), fPreferenceStore, propertyColorNames);
953
			}
954
		};
955
	}
956
}
(-)src/org/eclipse/cdt/internal/ui/text/CPreprocessorScanner.java (-18 / +8 lines)
Lines 7-26 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
9
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
10
 *     Andrew Ferguson (Symbian)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.text;
12
package org.eclipse.cdt.internal.ui.text;
12
13
13
import java.util.ArrayList;
14
import java.util.ArrayList;
14
import java.util.List;
15
import java.util.List;
15
16
16
import org.eclipse.jface.preference.IPreferenceStore;
17
import org.eclipse.jface.text.rules.IRule;
17
import org.eclipse.jface.text.rules.IRule;
18
import org.eclipse.jface.text.rules.IToken;
18
import org.eclipse.jface.text.rules.PatternRule;
19
import org.eclipse.jface.text.rules.PatternRule;
19
import org.eclipse.jface.text.rules.Token;
20
import org.eclipse.jface.text.rules.WhitespaceRule;
20
import org.eclipse.jface.text.rules.WhitespaceRule;
21
import org.eclipse.jface.text.rules.WordRule;
21
import org.eclipse.jface.text.rules.WordRule;
22
22
23
import org.eclipse.cdt.core.model.ICLanguageKeywords;
23
import org.eclipse.cdt.core.model.ICLanguageKeywords;
24
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
24
25
25
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
26
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
26
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
27
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
Lines 45-59 Link Here
45
	
46
	
46
	/**
47
	/**
47
	 * Creates a C/C++ preprocessor scanner.
48
	 * Creates a C/C++ preprocessor scanner.
48
	 * 
49
     * @param manager the color manager
50
     * @param store  the preference store
51
     * @param keywords  the keywords defined by the language dialect
49
     * @param keywords  the keywords defined by the language dialect
52
	 */
50
	 */
53
	public CPreprocessorScanner(IColorManager manager, IPreferenceStore store, ICLanguageKeywords keywords) {
51
	public CPreprocessorScanner(ITokenStoreFactory factory, ICLanguageKeywords keywords) {
54
		super(manager, store);
52
		super(factory.createTokenStore(fgTokenProperties));
55
		fKeywords= keywords;
53
		fKeywords= keywords;
56
		initialize();
54
		setRules(createRules());
57
	}
55
	}
58
56
59
	/*
57
	/*
Lines 61-70 Link Here
61
	 */
59
	 */
62
	protected List createRules() {
60
	protected List createRules() {
63
61
64
		Token defaultToken= getToken(ICColorConstants.PP_DEFAULT);
62
		IToken defaultToken= getToken(ICColorConstants.PP_DEFAULT);
65
63
66
		List rules= new ArrayList();		
64
		List rules= new ArrayList();		
67
		Token token;
65
		IToken token;
68
		
66
		
69
		// Add generic white space rule.
67
		// Add generic white space rule.
70
		rules.add(new WhitespaceRule(new CWhitespaceDetector()));
68
		rules.add(new WhitespaceRule(new CWhitespaceDetector()));
Lines 110-121 Link Here
110
        setDefaultReturnToken(defaultToken);
108
        setDefaultReturnToken(defaultToken);
111
		return rules;
109
		return rules;
112
	}
110
	}
113
114
	/*
115
	 * @see org.eclipse.cdt.internal.ui.text.AbstractCScanner#getTokenProperties()
116
	 */
117
	protected String[] getTokenProperties() {
118
		return fgTokenProperties;
119
	}
120
121
}
111
}
(-)src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java (-32 / +8 lines)
Lines 44-50 Link Here
44
 * Auto indent strategy sensitive to brackets.
44
 * Auto indent strategy sensitive to brackets.
45
 */
45
 */
46
public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
46
public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
47
	private static final String MULTILINE_COMMENT_CLOSE = "*/"; //$NON-NLS-1$
48
	/** The line comment introducer. Value is "{@value}" */
47
	/** The line comment introducer. Value is "{@value}" */
49
	private static final String LINE_COMMENT= "//"; //$NON-NLS-1$
48
	private static final String LINE_COMMENT= "//"; //$NON-NLS-1$
50
//	private static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION = new GCCScannerExtensionConfiguration();
49
//	private static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION = new GCCScannerExtensionConfiguration();
Lines 1120-1162 Link Here
1120
			super.customizeDocumentCommand(d, c);
1119
			super.customizeDocumentCommand(d, c);
1121
			return;
1120
			return;
1122
		}
1121
		}
1123
1122
		
1124
		if (c.length == 0 && c.text != null && isLineDelimiter(d, c.text)) {
1123
		/*
1125
			if (isAppendToOpenMultilineComment(d, c)) {
1124
         * I removed the workaround for 48339 as I believe the recent changes to 
1126
				// special case: multi-line comment at end of document (bug 48339)
1125
         * FastCPartitioner are enough to fix this.
1127
				CCommentAutoIndentStrategy.commentIndentAfterNewLine(d, c);
1126
         */
1128
			} else {
1127
		boolean isNewLine= c.length == 0 && c.text != null && isLineDelimiter(d, c.text);
1129
				smartIndentAfterNewLine(d, c);
1128
		if (isNewLine) {
1130
			}
1129
			smartIndentAfterNewLine(d, c);
1131
		} else if ("/".equals(c.text) && isAppendToOpenMultilineComment(d, c)) { //$NON-NLS-1$
1132
			// special case: multi-line comment at end of document (bug 48339)
1133
			CCommentAutoIndentStrategy.commentIndentForCommentEnd(d, c);
1134
		} else if (c.text.length() == 1) {
1130
		} else if (c.text.length() == 1) {
1135
			smartIndentOnKeypress(d, c);
1131
			smartIndentOnKeypress(d, c);
1136
		} else if (c.text.length() > 1 && getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SMART_PASTE)) {
1132
		} else if (c.text.length() > 1 && getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SMART_PASTE)) {
1137
			smartPaste(d, c); // no smart backspace for paste
1133
			smartPaste(d, c); // no smart backspace for paste
1138
		}
1134
		}
1139
	}
1135
	}
1140
	
1141
	/**
1142
	 * Check, if the command appends to an open multi-line comment.
1143
	 * @param d  the document
1144
	 * @param c  the document command
1145
	 * @return true, if the command appends to an open multi-line comment.
1146
	 */
1147
	private boolean isAppendToOpenMultilineComment(IDocument d, DocumentCommand c) {
1148
		if (d.getLength() >= 2 && c.offset == d.getLength()) {
1149
			try {
1150
				String contentType = TextUtilities.getContentType(d, fPartitioning, c.offset - 1, false);
1151
				if (ICPartitions.C_MULTI_LINE_COMMENT.equals(contentType)) {
1152
					return !d.get(c.offset - 2, 2).equals(MULTILINE_COMMENT_CLOSE);
1153
				}
1154
			} catch (BadLocationException exc) {
1155
				// see below
1156
			}
1157
		}
1158
		return false;
1159
	}
1160
1136
1161
	private static IPreferenceStore getPreferenceStore() {
1137
	private static IPreferenceStore getPreferenceStore() {
1162
		return CUIPlugin.getDefault().getCombinedPreferenceStore();
1138
		return CUIPlugin.getDefault().getCombinedPreferenceStore();
(-)src/org/eclipse/cdt/internal/ui/text/FastCPartitionScanner.java (-11 / +61 lines)
Lines 21-26 Link Here
21
import org.eclipse.jface.text.rules.Token;
21
import org.eclipse.jface.text.rules.Token;
22
22
23
import org.eclipse.cdt.ui.text.ICPartitions;
23
import org.eclipse.cdt.ui.text.ICPartitions;
24
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
24
25
25
26
26
/**
27
/**
Lines 38-43 Link Here
38
	private static final int PREPROCESSOR= 5;
39
	private static final int PREPROCESSOR= 5;
39
	private static final int PREPROCESSOR_MULTI_LINE_COMMENT= 6;
40
	private static final int PREPROCESSOR_MULTI_LINE_COMMENT= 6;
40
	private static final int PREPROCESSOR_STRING= 7;
41
	private static final int PREPROCESSOR_STRING= 7;
42
	private static final int SINGLE_LINE_DOC_COMMENT= 8;
43
	private static final int MULTI_LINE_DOC_COMMENT= 9;
41
	
44
	
42
	// beginning of prefixes and postfixes
45
	// beginning of prefixes and postfixes
43
	private static final int NONE= 0;
46
	private static final int NONE= 0;
Lines 65-75 Link Here
65
	private int fPrefixLength;
68
	private int fPrefixLength;
66
	/** Indicate whether current char is first non-whitespace char on the line*/
69
	/** Indicate whether current char is first non-whitespace char on the line*/
67
	private boolean fFirstCharOnLine= true;
70
	private boolean fFirstCharOnLine= true;
68
71
	/** An optional (possibly null) comment owner for detecting documentation-comments **/
72
	private IDocCommentOwner fOwner;
73
	
69
	// emulate CPartitionScanner
74
	// emulate CPartitionScanner
70
	private final boolean fEmulate;
75
	private final boolean fEmulate;
71
	private int fCCodeOffset;
76
	private int fCCodeOffset;
72
	private int fCCodeLength;
77
	private int fCCodeLength;
78
	private IDocument fDocument;
73
	
79
	
74
	private final IToken[] fTokens= new IToken[] {
80
	private final IToken[] fTokens= new IToken[] {
75
		new Token(null),
81
		new Token(null),
Lines 80-93 Link Here
80
		new Token(C_PREPROCESSOR),
86
		new Token(C_PREPROCESSOR),
81
		new Token(C_MULTI_LINE_COMMENT),
87
		new Token(C_MULTI_LINE_COMMENT),
82
		new Token(C_PREPROCESSOR),
88
		new Token(C_PREPROCESSOR),
89
		new Token(C_SINGLE_LINE_DOC_COMMENT),
90
		new Token(C_MULTI_LINE_DOC_COMMENT)
83
	};
91
	};
84
92
85
	public FastCPartitionScanner(boolean emulate) {
93
	public FastCPartitionScanner(boolean emulate, IDocCommentOwner owner) {
86
	    fEmulate= emulate;
94
	    fEmulate= emulate;
95
	    fOwner= owner;
87
	}
96
	}
88
97
98
	public FastCPartitionScanner(IDocCommentOwner owner) {
99
	    this(false, owner);
100
	}
101
	
89
	public FastCPartitionScanner() {
102
	public FastCPartitionScanner() {
90
	    this(false);
103
	    this(false, null);
91
	}
104
	}
92
105
93
	/*
106
	/*
Lines 533-546 Link Here
533
	}
546
	}
534
	
547
	
535
	private final IToken postFix(int state) {
548
	private final IToken postFix(int state) {
549
		return postFix(state, CCODE);
550
	}
551
	
552
	private final IToken postFix(int state, int newState) {
536
		fTokenLength++;
553
		fTokenLength++;
537
		fLast= NONE;
554
		fLast= NONE;
538
		fState= CCODE;
555
		fState= newState;
539
		fPrefixLength= 0;		
556
		fPrefixLength= 0;		
540
		return fTokens[state];
557
		return fTokens[interceptTokenState(state)];
541
	}
558
	}
542
559
560
543
	private final IToken preFix(int state, int newState, int last, int prefixLength) {
561
	private final IToken preFix(int state, int newState, int last, int prefixLength) {
562
		
544
		// emulate CPartitionScanner
563
		// emulate CPartitionScanner
545
		if (fEmulate && state == CCODE && (fTokenLength - getLastLength(fLast) > 0)) {
564
		if (fEmulate && state == CCODE && (fTokenLength - getLastLength(fLast) > 0)) {
546
			fTokenLength -= getLastLength(fLast);
565
			fTokenLength -= getLastLength(fLast);
Lines 550-564 Link Here
550
			fState= newState;
569
			fState= newState;
551
			fPrefixLength= prefixLength;
570
			fPrefixLength= prefixLength;
552
			fLast= last;
571
			fLast= last;
553
			return fTokens[state];
572
			return fTokens[interceptTokenState(state)];
554
573
555
		} else {
574
		} else {
556
			fTokenLength -= getLastLength(fLast);
575
			fTokenLength -= getLastLength(fLast);
557
			fLast= last;
576
			fLast= last;
558
			fPrefixLength= prefixLength;
577
			fPrefixLength= prefixLength;
559
			IToken token= fTokens[state];
560
			fState= newState;
578
			fState= newState;
561
			return token;
579
			return fTokens[interceptTokenState(state)];
562
		}
580
		}
563
	}
581
	}
564
582
Lines 581-587 Link Here
581
599
582
		else if (contentType.equals(C_PREPROCESSOR))
600
		else if (contentType.equals(C_PREPROCESSOR))
583
			return PREPROCESSOR;
601
			return PREPROCESSOR;
584
			
602
		
603
		else if (contentType.equals(C_SINGLE_LINE_DOC_COMMENT))
604
			return SINGLE_LINE_COMMENT; // intentionally non-doc state: the state machine is doc-comment unaware
605
606
		else if (contentType.equals(C_MULTI_LINE_DOC_COMMENT))
607
			return MULTI_LINE_COMMENT; // intentionally non-doc state: the state machine is doc-comment unaware
608
		
585
		else
609
		else
586
			return CCODE;
610
			return CCODE;
587
	}
611
	}
Lines 590-596 Link Here
590
	 * @see IPartitionTokenScanner#setPartialRange(IDocument, int, int, String, int)
614
	 * @see IPartitionTokenScanner#setPartialRange(IDocument, int, int, String, int)
591
	 */
615
	 */
592
	public void setPartialRange(IDocument document, int offset, int length, String contentType, int partitionOffset) {
616
	public void setPartialRange(IDocument document, int offset, int length, String contentType, int partitionOffset) {
593
617
		fDocument= document;
594
		fScanner.setRange(document, offset, length);
618
		fScanner.setRange(document, offset, length);
595
		fTokenOffset= partitionOffset;
619
		fTokenOffset= partitionOffset;
596
		fTokenLength= 0;
620
		fTokenLength= 0;
Lines 622-628 Link Here
622
	 * @see ITokenScanner#setRange(IDocument, int, int)
646
	 * @see ITokenScanner#setRange(IDocument, int, int)
623
	 */
647
	 */
624
	public void setRange(IDocument document, int offset, int length) {
648
	public void setRange(IDocument document, int offset, int length) {
625
649
		fDocument= document;
626
		fScanner.setRange(document, offset, length);
650
		fScanner.setRange(document, offset, length);
627
		fTokenOffset= offset;
651
		fTokenOffset= offset;
628
		fTokenLength= 0;		
652
		fTokenLength= 0;		
Lines 658-661 Link Here
658
		return fTokenOffset;
682
		return fTokenOffset;
659
	}
683
	}
660
684
685
	private int interceptTokenState(int proposedTokenState) {
686
		if(fOwner!=null) {
687
			switch(proposedTokenState) {
688
			case MULTI_LINE_COMMENT: 
689
				if(fOwner.getMultilineConfiguration().isDocumentationComment(fDocument, fTokenOffset, fTokenLength))
690
					return MULTI_LINE_DOC_COMMENT;
691
				break;
692
693
			case SINGLE_LINE_COMMENT:
694
				if(fOwner.getSinglelineConfiguration().isDocumentationComment(fDocument, fTokenOffset, fTokenLength))
695
					return SINGLE_LINE_DOC_COMMENT;
696
				break;
697
698
			}
699
		}
700
		return proposedTokenState;
701
	}
702
	
703
	/**
704
	 * @return the DocCommentOwner associated with this partition scanner, or null
705
	 * if there is no owner.
706
	 * @since 5.0
707
	 */
708
	public IDocCommentOwner getDocCommentOwner() {
709
		return fOwner;
710
	}
661
}
711
}
(-)src/org/eclipse/cdt/internal/ui/text/FastCPartitioner.java (+21 lines)
Lines 16-21 Link Here
16
import org.eclipse.jface.text.rules.IPartitionTokenScanner;
16
import org.eclipse.jface.text.rules.IPartitionTokenScanner;
17
17
18
import org.eclipse.cdt.ui.text.ICPartitions;
18
import org.eclipse.cdt.ui.text.ICPartitions;
19
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
19
20
20
/**
21
/**
21
 * A slightly adapted FastPartitioner.
22
 * A slightly adapted FastPartitioner.
Lines 44-53 Link Here
44
					if (fDocument.getChar(offset - 1) != '\n') {
45
					if (fDocument.getChar(offset - 1) != '\n') {
45
						return region;
46
						return region;
46
					}
47
					}
48
				} else if (ICPartitions.C_MULTI_LINE_DOC_COMMENT.equals(region.getType())) {
49
					if (!fDocument.get(offset - 2, 2).equals("*/")) { //$NON-NLS-1$
50
						return region;
51
					}
52
				} else if (ICPartitions.C_SINGLE_LINE_DOC_COMMENT.equals(region .getType())) {
53
					if (fDocument.getChar(offset - 1) != '\n') {
54
						return region;
55
					}
47
				}
56
				}
48
			} catch (BadLocationException exc) {
57
			} catch (BadLocationException exc) {
49
			}
58
			}
50
		}
59
		}
51
		return super.getPartition(offset, preferOpenPartitions);
60
		return super.getPartition(offset, preferOpenPartitions);
52
	}
61
	}
62
	
63
	/**
64
	 * @return the DocCommentOwner associated with this partition scanner, or null
65
	 * if there is no owner.
66
	 * @since 5.0
67
	 */
68
	public IDocCommentOwner getDocCommentOwner() {
69
		if(fScanner instanceof FastCPartitionScanner) {
70
			return ((FastCPartitionScanner)fScanner).getDocCommentOwner();
71
		}
72
		return null;
73
	}
53
}
74
}
(-)src/org/eclipse/cdt/internal/ui/text/AbstractCScanner.java (-320 / +61 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 8-365 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     QNX Software System
10
 *     QNX Software System
11
 *     Andrew Ferguson (Symbian)
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.cdt.internal.ui.text;
13
package org.eclipse.cdt.internal.ui.text;
13
14
14
15
import java.util.ArrayList;
15
import java.util.HashMap;
16
import java.util.Iterator;
16
import java.util.List;
17
import java.util.List;
17
import java.util.Map;
18
18
19
import org.eclipse.jface.preference.IPreferenceStore;
19
import org.eclipse.jface.preference.IPreferenceStore;
20
import org.eclipse.jface.preference.PreferenceConverter;
21
import org.eclipse.jface.resource.StringConverter;
22
import org.eclipse.jface.text.TextAttribute;
23
import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
20
import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
24
import org.eclipse.jface.text.rules.IRule;
21
import org.eclipse.jface.text.rules.IRule;
25
import org.eclipse.jface.text.rules.IToken;
22
import org.eclipse.jface.text.rules.IToken;
26
import org.eclipse.jface.text.rules.Token;
27
import org.eclipse.jface.util.PropertyChangeEvent;
23
import org.eclipse.jface.util.PropertyChangeEvent;
28
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.graphics.Color;
30
import org.eclipse.swt.graphics.RGB;
31
import org.eclipse.swt.widgets.Display;
32
33
import org.eclipse.cdt.ui.PreferenceConstants;
34
24
25
import org.eclipse.cdt.ui.IPropertyChangeParticipant;
26
import org.eclipse.cdt.ui.text.ICTokenScanner;
27
import org.eclipse.cdt.ui.text.ITokenStore;
35
28
36
/**
29
/**
37
 * Initialized with a color manager and a preference store, its subclasses are
30
 * Convenience implementation.
38
 * only responsible for providing a list of preference keys for based on which tokens
39
 * are generated and to use this tokens to define the rules controlling this scanner.
40
 * <p>
41
 * This scanner stores the color defined by the color preference key into
42
 * the color manager under the same key.
43
 * </p>
44
 * <p>
45
 * Preference color key + {@link PreferenceConstants#EDITOR_BOLD_SUFFIX} are used
46
 * to retrieve whether the token is rendered in bold.
47
 * </p>
48
 * <p>
49
 * Preference color key + {@link PreferenceConstants#EDITOR_ITALIC_SUFFIX} are used
50
 * to retrieve whether the token is rendered in italic.
51
 * </p>
52
 * <p>
53
 * Preference color key + {@link PreferenceConstants#EDITOR_STRIKETHROUGH_SUFFIX} are used
54
 * to retrieve whether the token is rendered in strikethrough.
55
 * </p>
56
 * <p>
57
 * Preference color key + {@link PreferenceConstants#EDITOR_UNDERLINE_SUFFIX} are used
58
 * to retrieve whether the token is rendered in underline.
59
 * </p>
60
 */
31
 */
61
public abstract class AbstractCScanner extends BufferedRuleBasedScanner {
32
public abstract class AbstractCScanner extends BufferedRuleBasedScanner implements ICTokenScanner {
62
33
	private List/*<IPropertyChangeParticipant*/ pcps;
63
34
	final protected ITokenStore fTokenStore;
64
	private IColorManager fColorManager;
65
	private IPreferenceStore fPreferenceStore;
66
67
	private Map fTokenMap= new HashMap();
68
	private String[] fPropertyNamesColor;
69
	/**
70
	 * Preference keys for boolean preferences which are <code>true</code>,
71
	 * iff the corresponding token should be rendered bold.
72
	 */
73
	private String[] fPropertyNamesBold;
74
	/**
75
	 * Preference keys for boolean preferences which are <code>true</code>,
76
	 * iff the corresponding token should be rendered italic.
77
	 *
78
	 * @since 4.0
79
	 */
80
	private String[] fPropertyNamesItalic;
81
	/**
82
	 * Preference keys for boolean preferences which are <code>true</code>,
83
	 * iff the corresponding token should be rendered strikethrough.
84
	 *
85
	 * @since 4.0
86
	 */
87
	private String[] fPropertyNamesStrikethrough;
88
	/**
89
	 * Preference keys for boolean preferences which are <code>true</code>,
90
	 * iff the corresponding token should be rendered underline.
91
	 *
92
	 * @since 4.0
93
	 */
94
	private String[] fPropertyNamesUnderline;
95
96
97
	private boolean fNeedsLazyColorLoading;
98
99
	/**
100
	 * Returns an array of preference keys which define the tokens
101
	 * used in the rules of this scanner.
102
	 * <p>
103
	 * The preference key is used access the color in the preference
104
	 * store and in the color manager.
105
	 * </p>
106
	 * <p>
107
	 * Preference key + {@link PreferenceConstants#EDITOR_BOLD_SUFFIX} is used
108
	 * to retrieve whether the token is rendered in bold.
109
	 * </p>
110
	 * <p>
111
	 * Preference key + {@link PreferenceConstants#EDITOR_ITALIC_SUFFIX} is used
112
	 * to retrieve whether the token is rendered in italic.
113
	 * </p>
114
	 * <p>
115
	 * Preference key + {@link PreferenceConstants#EDITOR_UNDERLINE_SUFFIX} is used
116
	 * to retrieve whether the token is rendered underlined.
117
	 * </p>
118
	 * <p>
119
	 * Preference key + {@link PreferenceConstants#EDITOR_STRIKETHROUGH_SUFFIX} is used
120
	 * to retrieve whether the token is rendered stricken out.
121
	 * </p>
122
	 */
123
	abstract protected String[] getTokenProperties();
124
125
	/**
126
	 * Creates the list of rules controlling this scanner.
127
	 */
128
	abstract protected List createRules();
129
130
131
	/**
132
	 * Creates an abstract C scanner.
133
	 */
134
	public AbstractCScanner(IColorManager manager, IPreferenceStore store) {
135
		super();
136
		fColorManager= manager;
137
		fPreferenceStore= store;
138
	}
139
140
	/**
141
	 * Creates an abstract C scanner.
142
	 */
143
	public AbstractCScanner(IColorManager manager, IPreferenceStore store, int bufsize) {
144
		super(bufsize);
145
		fColorManager= manager;
146
		fPreferenceStore= store;
147
	}
148
149
	/**
150
	 * Must be called after the constructor has been called.
151
	 */
152
	public final void initialize() {
153
154
		fPropertyNamesColor= getTokenProperties();
155
		int length= fPropertyNamesColor.length;
156
		fPropertyNamesBold= new String[length];
157
		fPropertyNamesItalic= new String[length];
158
		fPropertyNamesStrikethrough= new String[length];
159
		fPropertyNamesUnderline= new String[length];
160
161
		for (int i= 0; i < length; i++) {
162
			fPropertyNamesBold[i]= getBoldKey(fPropertyNamesColor[i]);
163
			fPropertyNamesItalic[i]= getItalicKey(fPropertyNamesColor[i]);
164
			fPropertyNamesStrikethrough[i]= getStrikethroughKey(fPropertyNamesColor[i]);
165
			fPropertyNamesUnderline[i]= getUnderlineKey(fPropertyNamesColor[i]);
166
		}
167
		
168
		fNeedsLazyColorLoading= Display.getCurrent() == null;
169
		for (int i= 0; i < length; i++) {
170
			if (fNeedsLazyColorLoading)
171
				addTokenWithProxyAttribute(fPropertyNamesColor[i], fPropertyNamesBold[i], fPropertyNamesItalic[i], fPropertyNamesStrikethrough[i], fPropertyNamesUnderline[i]);
172
			else
173
				addToken(fPropertyNamesColor[i], fPropertyNamesBold[i], fPropertyNamesItalic[i], fPropertyNamesStrikethrough[i], fPropertyNamesUnderline[i]);
174
		}
175
176
		initializeRules();
177
	}
178
	
35
	
179
	protected String getBoldKey(String colorKey) {
36
	public AbstractCScanner(ITokenStore tokenStore, int size) {
180
		return colorKey + PreferenceConstants.EDITOR_BOLD_SUFFIX;
37
		this(tokenStore);
181
	}
38
		setBufferSize(size);
182
183
	protected String getItalicKey(String colorKey) {
184
		return colorKey + PreferenceConstants.EDITOR_ITALIC_SUFFIX;
185
	}
39
	}
186
	
40
	
187
	protected String getStrikethroughKey(String colorKey) {
41
	public AbstractCScanner(ITokenStore tokenStore) {
188
		return colorKey + PreferenceConstants.EDITOR_STRIKETHROUGH_SUFFIX;
42
		fTokenStore= tokenStore;
43
		pcps= new ArrayList/*<IPropertyChangeParticipant*/();
189
	}
44
	}
190
	
45
	
191
	protected String getUnderlineKey(String colorKey) {
46
	protected void addPropertyChangeParticipant(IPropertyChangeParticipant participant) {
192
		return colorKey + PreferenceConstants.EDITOR_UNDERLINE_SUFFIX;
47
		pcps.add(participant);
193
	}
48
	}
194
	
49
	
195
	public IToken nextToken() {
196
		if (fNeedsLazyColorLoading)
197
			resolveProxyAttributes();
198
		return super.nextToken();
199
	}
200
201
	private void resolveProxyAttributes() {
202
		if (fNeedsLazyColorLoading && Display.getCurrent() != null) {
203
			for (int i= 0; i < fPropertyNamesColor.length; i++) {
204
				addToken(fPropertyNamesColor[i], fPropertyNamesBold[i], fPropertyNamesItalic[i], fPropertyNamesStrikethrough[i], fPropertyNamesUnderline[i]);
205
			}
206
			fNeedsLazyColorLoading= false;
207
		}
208
	}
209
210
	private void addTokenWithProxyAttribute(String colorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) {
211
		fTokenMap.put(colorKey, new Token(createTextAttribute(null, boldKey, italicKey, strikethroughKey, underlineKey)));
212
	}
213
214
	private void addToken(String colorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) {
215
		if (fColorManager != null && colorKey != null && fColorManager.getColor(colorKey) == null) {
216
			RGB rgb= PreferenceConverter.getColor(fPreferenceStore, colorKey);
217
			if (fColorManager instanceof IColorManagerExtension) {
218
				IColorManagerExtension ext= (IColorManagerExtension) fColorManager;
219
				ext.unbindColor(colorKey);
220
				ext.bindColor(colorKey, rgb);
221
			}
222
		}
223
224
		if (!fNeedsLazyColorLoading)
225
			fTokenMap.put(colorKey, new Token(createTextAttribute(colorKey, boldKey, italicKey, strikethroughKey, underlineKey)));
226
		else {
227
			Token token= ((Token)fTokenMap.get(colorKey));
228
			if (token != null)
229
				token.setData(createTextAttribute(colorKey, boldKey, italicKey, strikethroughKey, underlineKey));
230
		}
231
	}
232
233
	/**
50
	/**
234
	 * Create a text attribute based on the given color, bold, italic, strikethrough and underline preference keys.
51
	 * Convenience method for setting the scanner rules with a list rather
235
	 *
52
	 * than an array.
236
	 * @param colorKey the color preference key
53
	 * @param rules
237
	 * @param boldKey the bold preference key
54
	 */
238
	 * @param italicKey the italic preference key
55
	public final void setRules(List/*<IRule>*/ rules) {
239
	 * @param strikethroughKey the strikethrough preference key
56
		if(rules==null) {
240
	 * @param underlineKey the italic preference key
57
			setRules((IRule[])null);
241
	 * @return the created text attribute
58
		} else {
242
	 * @since 3.0
243
	 */
244
	private TextAttribute createTextAttribute(String colorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) {
245
		Color color= null;
246
		if (colorKey != null)
247
			color= fColorManager.getColor(colorKey);
248
249
		int style= fPreferenceStore.getBoolean(boldKey) ? SWT.BOLD : SWT.NORMAL;
250
		if (fPreferenceStore.getBoolean(italicKey))
251
			style |= SWT.ITALIC;
252
253
		if (fPreferenceStore.getBoolean(strikethroughKey))
254
			style |= TextAttribute.STRIKETHROUGH;
255
256
		if (fPreferenceStore.getBoolean(underlineKey))
257
			style |= TextAttribute.UNDERLINE;
258
259
		return new TextAttribute(color, null, style);
260
	}
261
262
	protected Token getToken(String key) {
263
		if (fNeedsLazyColorLoading)
264
			resolveProxyAttributes();
265
		return (Token) fTokenMap.get(key);
266
	}
267
268
	private void initializeRules() {
269
		List rules= createRules();
270
		if (rules != null) {
271
			IRule[] result= new IRule[rules.size()];
59
			IRule[] result= new IRule[rules.size()];
272
			rules.toArray(result);
60
			rules.toArray(result);
273
			setRules(result);
61
			setRules(result);		
274
		}
62
		}
275
	}
63
	}
276
64
277
	private int indexOf(String property) {
65
	/*
278
		if (property != null) {
66
	 * (non-Javadoc)
279
			int length= fPropertyNamesColor.length;
67
	 * @see org.eclipse.jface.text.rules.RuleBasedScanner#nextToken()
280
			for (int i= 0; i < length; i++) {
68
	 */
281
				if (property.equals(fPropertyNamesColor[i]) || property.equals(fPropertyNamesBold[i]) || property.equals(fPropertyNamesItalic[i]) || property.equals(fPropertyNamesStrikethrough[i]) || property.equals(fPropertyNamesUnderline[i]))
69
	public IToken nextToken() {
282
					return i;
70
		fTokenStore.ensureTokensInitialised();
283
			}
71
		return super.nextToken();
284
		}
285
		return -1;
286
	}
72
	}
287
73
	
288
	public boolean affectsBehavior(PropertyChangeEvent event) {
74
	public IToken getToken(String key) {
289
		return indexOf(event.getProperty()) >= 0;
75
		return fTokenStore.getToken(key);
290
	}
76
	}
291
77
	
292
	public void adaptToPreferenceChange(PropertyChangeEvent event) {
78
	public IPreferenceStore getPreferenceStore() {
293
		String p= event.getProperty();
79
		return fTokenStore.getPreferenceStore();
294
		int index= indexOf(p);
295
		Token token= getToken(fPropertyNamesColor[index]);
296
		if (fPropertyNamesColor[index].equals(p))
297
			adaptToColorChange(token, event);
298
		else if (fPropertyNamesBold[index].equals(p))
299
			adaptToStyleChange(token, event, SWT.BOLD);
300
		else if (fPropertyNamesItalic[index].equals(p))
301
			adaptToStyleChange(token, event, SWT.ITALIC);
302
		else if (fPropertyNamesStrikethrough[index].equals(p))
303
			adaptToStyleChange(token, event, TextAttribute.STRIKETHROUGH);
304
		else if (fPropertyNamesUnderline[index].equals(p))
305
			adaptToStyleChange(token, event, TextAttribute.UNDERLINE);
306
	}
80
	}
307
81
308
	private void adaptToColorChange(Token token, PropertyChangeEvent event) {
82
	/*
309
		RGB rgb= null;
83
	 * (non-Javadoc)
310
84
	 * @see org.eclipse.cdt.ui.IPropertyChangeParticipant#adaptToPreferenceChange(org.eclipse.jface.util.PropertyChangeEvent)
311
		Object value= event.getNewValue();
85
	 */
312
		if (value instanceof RGB)
86
	public void adaptToPreferenceChange(PropertyChangeEvent event) {
313
			rgb= (RGB) value;
87
		if(fTokenStore.affectsBehavior(event)) {
314
		else if (value instanceof String)
88
			fTokenStore.adaptToPreferenceChange(event);
315
			rgb= StringConverter.asRGB((String) value);
316
317
		if (rgb != null) {
318
319
			String property= event.getProperty();
320
			Color color= fColorManager.getColor(property);
321
322
			if ((color == null || !rgb.equals(color.getRGB())) && fColorManager instanceof IColorManagerExtension) {
323
				IColorManagerExtension ext= (IColorManagerExtension) fColorManager;
324
325
			 	ext.unbindColor(property);
326
			 	ext.bindColor(property, rgb);
327
328
				color= fColorManager.getColor(property);
329
			}
330
331
			Object data= token.getData();
332
			if (data instanceof TextAttribute) {
333
				TextAttribute oldAttr= (TextAttribute) data;
334
				token.setData(new TextAttribute(color, oldAttr.getBackground(), oldAttr.getStyle()));
335
			}
336
		}
89
		}
337
	}
90
		for(Iterator i= pcps.iterator(); i.hasNext(); ) {
338
91
			((IPropertyChangeParticipant)i.next()).adaptToPreferenceChange(event);
339
	private void adaptToStyleChange(Token token, PropertyChangeEvent event, int styleAttribute) {
340
		boolean eventValue= false;
341
		Object value= event.getNewValue();
342
		if (value instanceof Boolean)
343
			eventValue= ((Boolean) value).booleanValue();
344
		else if (IPreferenceStore.TRUE.equals(value))
345
			eventValue= true;
346
347
		Object data= token.getData();
348
		if (data instanceof TextAttribute) {
349
			TextAttribute oldAttr= (TextAttribute) data;
350
			boolean activeValue= (oldAttr.getStyle() & styleAttribute) == styleAttribute;
351
			if (activeValue != eventValue)
352
				token.setData(new TextAttribute(oldAttr.getForeground(), oldAttr.getBackground(), eventValue ? oldAttr.getStyle() | styleAttribute : oldAttr.getStyle() & ~styleAttribute));
353
		}
92
		}
354
	}
93
	}
355
	/**
94
356
	 * Returns the preference store.
95
	/*
357
	 *
96
	 * (non-Javadoc)
358
	 * @return the preference store.
97
	 * @see org.eclipse.cdt.ui.IPropertyChangeParticipant#affectsBehavior(org.eclipse.jface.util.PropertyChangeEvent)
359
	 *
360
	 * @since 3.0
361
	 */
98
	 */
362
	protected IPreferenceStore getPreferenceStore() {
99
	public boolean affectsBehavior(PropertyChangeEvent event) {
363
		return fPreferenceStore;
100
		boolean result= fTokenStore.affectsBehavior(event);
101
		for(Iterator i= pcps.iterator(); !result && i.hasNext(); ) {
102
			result |= ((IPropertyChangeParticipant)i.next()).affectsBehavior(event);
103
		}
104
		return result;
364
	}
105
	}
365
}
106
}
(-)src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties (-1 / +4 lines)
Lines 12-18 Link Here
12
#     Sergey Prigogin (Google)
12
#     Sergey Prigogin (Google)
13
###############################################################################
13
###############################################################################
14
14
15
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.
15
CEditorPreferencePage_link=C/C++ Editor Preferences. General preferences may be set via <a href="org.eclipse.ui.preferencePages.GeneralTextEditor">Text Editors</a>.
16
CEditorPreferencePage_link_tooltip=Show the shared text editor preferences
16
CEditorPreferencePage_link_tooltip=Show the shared text editor preferences
17
17
18
CEditorPreferencePage_colors=Synta&x
18
CEditorPreferencePage_colors=Synta&x
Lines 191-199 Link Here
191
CEditorPreferencePage_closeBraces={B&races}
191
CEditorPreferencePage_closeBraces={B&races}
192
CEditorPreferencePage_wrapStrings=&Wrap automatically
192
CEditorPreferencePage_wrapStrings=&Wrap automatically
193
CEditorPreferencePage_escapeStrings=Escape text w&hen pasting into a string literal
193
CEditorPreferencePage_escapeStrings=Escape text w&hen pasting into a string literal
194
CEditorPreferencePage_GeneralAppearanceGroupTitle=General appearance
195
CEditorPreferencePage_SelectDocToolDescription=Select the documentation tool to be used to determine editor behaviors when no project preference overrides exist
194
CEditorPreferencePage_smartPaste=Adjust &indentation
196
CEditorPreferencePage_smartPaste=Adjust &indentation
195
197
196
CEditorPreferencePage_typing_smartTab= &Tab key indents the current line
198
CEditorPreferencePage_typing_smartTab= &Tab key indents the current line
199
CEditorPreferencePage_WorkspaceDefaultLabel=Workspace default:
197
200
198
# Code Formatting
201
# Code Formatting
199
CodeFormatterPreferencePage_title=Code Style
202
CodeFormatterPreferencePage_title=Code Style
(-)src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java (+3 lines)
Lines 181-189 Link Here
181
	public static String CEditorPreferencePage_closeBraces;
181
	public static String CEditorPreferencePage_closeBraces;
182
	public static String CEditorPreferencePage_wrapStrings;
182
	public static String CEditorPreferencePage_wrapStrings;
183
	public static String CEditorPreferencePage_escapeStrings;
183
	public static String CEditorPreferencePage_escapeStrings;
184
	public static String CEditorPreferencePage_GeneralAppearanceGroupTitle;
185
	public static String CEditorPreferencePage_SelectDocToolDescription;
184
	public static String CEditorPreferencePage_smartPaste;
186
	public static String CEditorPreferencePage_smartPaste;
185
187
186
	public static String CEditorPreferencePage_typing_smartTab;
188
	public static String CEditorPreferencePage_typing_smartTab;
189
	public static String CEditorPreferencePage_WorkspaceDefaultLabel;
187
190
188
	public static String SmartTypingConfigurationBlock_autoclose_title;
191
	public static String SmartTypingConfigurationBlock_autoclose_title;
189
	public static String SmartTypingConfigurationBlock_tabs_title;
192
	public static String SmartTypingConfigurationBlock_tabs_title;
(-)src/org/eclipse/cdt/internal/ui/preferences/CEditorColoringConfigurationBlock.java (-1 / +1 lines)
Lines 801-807 Link Here
801
		
801
		
802
		String content= loadPreviewContentFromFile("ColorSettingPreviewCode.txt"); //$NON-NLS-1$
802
		String content= loadPreviewContentFromFile("ColorSettingPreviewCode.txt"); //$NON-NLS-1$
803
		IDocument document= new Document(content);
803
		IDocument document= new Document(content);
804
		CUIPlugin.getDefault().getTextTools().setupCDocumentPartitioner(document, ICPartitions.C_PARTITIONING);
804
		CUIPlugin.getDefault().getTextTools().setupCDocumentPartitioner(document, ICPartitions.C_PARTITIONING, null);
805
		fPreviewViewer.setDocument(document);
805
		fPreviewViewer.setDocument(document);
806
	
806
	
807
		installSemanticHighlighting();
807
		installSemanticHighlighting();
(-)src/org/eclipse/cdt/internal/ui/preferences/CodeTemplateBlock.java (-1 / +1 lines)
Lines 409-415 Link Here
409
		
409
		
410
		IDocument document= new Document();
410
		IDocument document= new Document();
411
		CTextTools tools= CUIPlugin.getDefault().getTextTools();
411
		CTextTools tools= CUIPlugin.getDefault().getTextTools();
412
		tools.setupCDocumentPartitioner(document, ICPartitions.C_PARTITIONING);
412
		tools.setupCDocumentPartitioner(document, ICPartitions.C_PARTITIONING, null);
413
		IPreferenceStore store= CUIPlugin.getDefault().getCombinedPreferenceStore();
413
		IPreferenceStore store= CUIPlugin.getDefault().getCombinedPreferenceStore();
414
		SourceViewer viewer= new CSourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, store);
414
		SourceViewer viewer= new CSourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, store);
415
		CodeTemplateSourceViewerConfiguration configuration= new CodeTemplateSourceViewerConfiguration(tools.getColorManager(), store, null, fTemplateProcessor);
415
		CodeTemplateSourceViewerConfiguration configuration= new CodeTemplateSourceViewerConfiguration(tools.getColorManager(), store, null, fTemplateProcessor);
(-)src/org/eclipse/cdt/internal/ui/preferences/EditTemplateDialog.java (-1 / +1 lines)
Lines 413-419 Link Here
413
		String prefix= getPrefix();
413
		String prefix= getPrefix();
414
		IDocument document= new Document(prefix + fTemplate.getPattern());
414
		IDocument document= new Document(prefix + fTemplate.getPattern());
415
		CTextTools tools= CUIPlugin.getDefault().getTextTools();
415
		CTextTools tools= CUIPlugin.getDefault().getTextTools();
416
		tools.setupCDocumentPartitioner(document, ICPartitions.C_PARTITIONING);
416
		tools.setupCDocumentPartitioner(document, ICPartitions.C_PARTITIONING, null);
417
		IPreferenceStore store= CUIPlugin.getDefault().getCombinedPreferenceStore();
417
		IPreferenceStore store= CUIPlugin.getDefault().getCombinedPreferenceStore();
418
		SourceViewer viewer= new CSourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, store);
418
		SourceViewer viewer= new CSourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, store);
419
		CodeTemplateSourceViewerConfiguration configuration= new CodeTemplateSourceViewerConfiguration(tools.getColorManager(), store, null, fTemplateProcessor);
419
		CodeTemplateSourceViewerConfiguration configuration= new CodeTemplateSourceViewerConfiguration(tools.getColorManager(), store, null, fTemplateProcessor);
(-)src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java (-4 / +28 lines)
Lines 14-19 Link Here
14
14
15
import java.util.ArrayList;
15
import java.util.ArrayList;
16
16
17
import org.eclipse.jface.layout.GridDataFactory;
17
import org.eclipse.jface.preference.ColorSelector;
18
import org.eclipse.jface.preference.ColorSelector;
18
import org.eclipse.jface.preference.IPreferenceStore;
19
import org.eclipse.jface.preference.IPreferenceStore;
19
import org.eclipse.jface.preference.PreferenceConverter;
20
import org.eclipse.jface.preference.PreferenceConverter;
Lines 37-46 Link Here
37
import org.eclipse.ui.dialogs.PreferencesUtil;
38
import org.eclipse.ui.dialogs.PreferencesUtil;
38
39
39
import org.eclipse.cdt.ui.PreferenceConstants;
40
import org.eclipse.cdt.ui.PreferenceConstants;
41
import org.eclipse.cdt.ui.dialogs.DocCommentOwnerComposite;
42
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
43
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
40
44
41
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
45
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
42
import org.eclipse.cdt.internal.ui.editor.CEditor;
46
import org.eclipse.cdt.internal.ui.editor.CEditor;
43
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
47
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
48
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
44
49
45
/*
50
/*
46
 * The page for setting the editor options.
51
 * The page for setting the editor options.
Lines 60-67 Link Here
60
	private List fAppearanceColorList;
65
	private List fAppearanceColorList;
61
	private ColorSelector fAppearanceColorEditor;
66
	private ColorSelector fAppearanceColorEditor;
62
	private Button fAppearanceColorDefault;
67
	private Button fAppearanceColorDefault;
63
68
	private DocCommentOwnerComposite fDocCommentOwnerComposite;
64
69
	
65
	public CEditorPreferencePage() {
70
	public CEditorPreferencePage() {
66
		super();
71
		super();
67
	}
72
	}
Lines 117-124 Link Here
117
	}
122
	}
118
123
119
	private Control createAppearancePage(Composite parent) {
124
	private Control createAppearancePage(Composite parent) {
120
125
		Composite behaviorComposite= ControlFactory.createGroup(parent, PreferencesMessages.CEditorPreferencePage_GeneralAppearanceGroupTitle, 1);
121
		Composite behaviorComposite = new Composite(parent, SWT.NONE);
126
		
127
		// Composite behaviorComposite = new Composite(parent, SWT.NONE);
122
		GridLayout layout = new GridLayout();
128
		GridLayout layout = new GridLayout();
123
		layout.numColumns = 2;
129
		layout.numColumns = 2;
124
		behaviorComposite.setLayout(layout);
130
		behaviorComposite.setLayout(layout);
Lines 216-221 Link Here
216
				PreferenceConverter.setValue(fOverlayStore, key, fAppearanceColorEditor.getColorValue());
222
				PreferenceConverter.setValue(fOverlayStore, key, fAppearanceColorEditor.getColorValue());
217
			}
223
			}
218
		});
224
		});
225
		
219
		return behaviorComposite;
226
		return behaviorComposite;
220
	}
227
	}
221
228
Lines 269-276 Link Here
269
276
270
		createHeader(parent);
277
		createHeader(parent);
271
278
279
		ControlFactory.createEmptySpace(parent, 2);
272
		createAppearancePage(parent);
280
		createAppearancePage(parent);
273
281
282
		ControlFactory.createEmptySpace(parent, 2);
283
		
284
		String dsc= PreferencesMessages.CEditorPreferencePage_SelectDocToolDescription;
285
		String msg= PreferencesMessages.CEditorPreferencePage_WorkspaceDefaultLabel;
286
		IDocCommentOwner workspaceOwner= DocCommentOwnerManager.getInstance().getWorkspaceCommentOwner();
287
		fDocCommentOwnerComposite= new DocCommentOwnerComposite(parent, workspaceOwner, dsc, msg);
288
		fDocCommentOwnerComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true,false).create());
289
		
274
		initialize();
290
		initialize();
275
291
276
		return parent;
292
		return parent;
Lines 291-296 Link Here
291
		});
307
		});
292
	}
308
	}
293
309
310
	/*
311
	 * @see org.eclipse.cdt.internal.ui.preferences.AbstractPreferencePage#performOk()
312
	 */
313
	public boolean performOk() {
314
		DocCommentOwnerManager.getInstance().setWorkspaceCommentOwner(fDocCommentOwnerComposite.getSelectedDocCommentOwner());
315
		return super.performOk();
316
	}
317
294
	/**
318
	/**
295
	 * Initializes the default colors.
319
	 * Initializes the default colors.
296
	 */
320
	 */
(-)src/org/eclipse/cdt/internal/ui/compare/CStructureCreator.java (-1 / +1 lines)
Lines 157-163 Link Here
157
	 * @see org.eclipse.compare.structuremergeviewer.StructureCreator#getDocumentPartitioner()
157
	 * @see org.eclipse.compare.structuremergeviewer.StructureCreator#getDocumentPartitioner()
158
	 */
158
	 */
159
	protected IDocumentPartitioner getDocumentPartitioner() {
159
	protected IDocumentPartitioner getDocumentPartitioner() {
160
		return CUIPlugin.getDefault().getTextTools().createDocumentPartitioner();
160
		return CUIPlugin.getDefault().getTextTools().createDocumentPartitioner(null);
161
	}
161
	}
162
	
162
	
163
	private static String readString(IStreamContentAccessor sa) throws CoreException {
163
	private static String readString(IStreamContentAccessor sa) throws CoreException {
(-)src/org/eclipse/cdt/internal/ui/compare/AbstractMergeViewer.java (-1 / +1 lines)
Lines 134-140 Link Here
134
	}
134
	}
135
135
136
	protected IDocumentPartitioner getDocumentPartitioner() {
136
	protected IDocumentPartitioner getDocumentPartitioner() {
137
		return CUIPlugin.getDefault().getTextTools().createDocumentPartitioner();
137
		return CUIPlugin.getDefault().getTextTools().createDocumentPartitioner(null);
138
	}
138
	}
139
139
140
	protected void configureTextViewer(TextViewer textViewer) {
140
	protected void configureTextViewer(TextViewer textViewer) {
(-)META-INF/MANIFEST.MF (+4 lines)
Lines 34-39 Link Here
34
 org.eclipse.cdt.internal.ui.text.asm;x-internal:=true,
34
 org.eclipse.cdt.internal.ui.text.asm;x-internal:=true,
35
 org.eclipse.cdt.internal.ui.text.c.hover;x-internal:=true,
35
 org.eclipse.cdt.internal.ui.text.c.hover;x-internal:=true,
36
 org.eclipse.cdt.internal.ui.text.contentassist;x-internal:=true,
36
 org.eclipse.cdt.internal.ui.text.contentassist;x-internal:=true,
37
 org.eclipse.cdt.internal.ui.text.doctools;x-internal:=true,
38
 org.eclipse.cdt.internal.ui.text.doctools.doxygen;x-internal:=true,
37
 org.eclipse.cdt.internal.ui.text.folding;x-internal:=true,
39
 org.eclipse.cdt.internal.ui.text.folding;x-internal:=true,
38
 org.eclipse.cdt.internal.ui.text.template;x-internal:=true,
40
 org.eclipse.cdt.internal.ui.text.template;x-internal:=true,
39
 org.eclipse.cdt.internal.ui.text.util;x-internal:=true,
41
 org.eclipse.cdt.internal.ui.text.util;x-internal:=true,
Lines 59-64 Link Here
59
 org.eclipse.cdt.ui.text,
61
 org.eclipse.cdt.ui.text,
60
 org.eclipse.cdt.ui.text.c.hover,
62
 org.eclipse.cdt.ui.text.c.hover,
61
 org.eclipse.cdt.ui.text.contentassist,
63
 org.eclipse.cdt.ui.text.contentassist,
64
 org.eclipse.cdt.ui.text.doctools,
65
 org.eclipse.cdt.ui.text.doctools.generic,
62
 org.eclipse.cdt.ui.text.folding,
66
 org.eclipse.cdt.ui.text.folding,
63
 org.eclipse.cdt.ui.wizards,
67
 org.eclipse.cdt.ui.wizards,
64
 org.eclipse.cdt.ui.wizards.conversion,
68
 org.eclipse.cdt.ui.wizards.conversion,
(-)src/org/eclipse/cdt/internal/ui/editor/asm/AsmCodeScanner.java (-27 / +10 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 9-38 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     QNX Software System
10
 *     QNX Software System
11
 *     Anton Leherbauer (Wind River Systems)
11
 *     Anton Leherbauer (Wind River Systems)
12
 *     Andrew Ferguson (Symbian)
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.cdt.internal.ui.editor.asm;
14
package org.eclipse.cdt.internal.ui.editor.asm;
14
15
15
import java.util.ArrayList;
16
import java.util.ArrayList;
16
import java.util.List;
17
import java.util.List;
17
18
18
import org.eclipse.jface.preference.IPreferenceStore;
19
import org.eclipse.jface.text.rules.EndOfLineRule;
19
import org.eclipse.jface.text.rules.EndOfLineRule;
20
import org.eclipse.jface.text.rules.IRule;
20
import org.eclipse.jface.text.rules.IRule;
21
import org.eclipse.jface.text.rules.Token;
21
import org.eclipse.jface.text.rules.IToken;
22
import org.eclipse.jface.text.rules.WhitespaceRule;
22
import org.eclipse.jface.text.rules.WhitespaceRule;
23
import org.eclipse.jface.text.rules.WordPatternRule;
23
import org.eclipse.jface.text.rules.WordPatternRule;
24
import org.eclipse.jface.text.rules.WordRule;
24
import org.eclipse.jface.text.rules.WordRule;
25
import org.eclipse.jface.util.PropertyChangeEvent;
26
25
27
import org.eclipse.cdt.core.model.IAsmLanguage;
26
import org.eclipse.cdt.core.model.IAsmLanguage;
27
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
28
28
29
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
29
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
30
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
30
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
31
import org.eclipse.cdt.internal.ui.text.IColorManager;
32
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
31
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
33
32
34
33
35
/**
34
/*
36
 * An assembly code scanner.
35
 * An assembly code scanner.
37
 */
36
 */
38
public final class AsmCodeScanner extends AbstractCScanner {
37
public final class AsmCodeScanner extends AbstractCScanner {
Lines 50-66 Link Here
50
	/**
49
	/**
51
	 * Creates an assembly code scanner.
50
	 * Creates an assembly code scanner.
52
	 */
51
	 */
53
	public AsmCodeScanner(IColorManager manager, IPreferenceStore store, IAsmLanguage asmLanguage) {
52
	public AsmCodeScanner(ITokenStoreFactory factory, IAsmLanguage asmLanguage) {
54
		super(manager, store);
53
		super(factory.createTokenStore(fgTokenProperties));
55
		fAsmLanguage= asmLanguage;
54
		fAsmLanguage= asmLanguage;
56
		initialize();
55
		setRules(createRules());
57
	}
58
	
59
	/*
60
	 * @see AbstractCScanner#getTokenProperties()
61
	 */
62
	protected String[] getTokenProperties() {
63
		return fgTokenProperties;
64
	}
56
	}
65
57
66
	/*
58
	/*
Lines 70-76 Link Here
70
				
62
				
71
		List rules= new ArrayList();		
63
		List rules= new ArrayList();		
72
		
64
		
73
		Token token;
65
		IToken token;
74
66
75
		// Add rule(s) for single line comments
67
		// Add rule(s) for single line comments
76
		token= getToken(ICColorConstants.C_SINGLE_LINE_COMMENT);
68
		token= getToken(ICColorConstants.C_SINGLE_LINE_COMMENT);
Lines 82-88 Link Here
82
		// Add generic whitespace rule.
74
		// Add generic whitespace rule.
83
		rules.add(new WhitespaceRule(new CWhitespaceDetector()));
75
		rules.add(new WhitespaceRule(new CWhitespaceDetector()));
84
76
85
		final Token other= getToken(ICColorConstants.C_DEFAULT);		
77
		final IToken other= getToken(ICColorConstants.C_DEFAULT);		
86
78
87
		// Add rule for labels
79
		// Add rule for labels
88
		token= getToken(ICColorConstants.ASM_LABEL);
80
		token= getToken(ICColorConstants.ASM_LABEL);
Lines 105-117 Link Here
105
		setDefaultReturnToken(other);
97
		setDefaultReturnToken(other);
106
		return rules;
98
		return rules;
107
	}
99
	}
108
109
	/*
110
	 * @see AbstractCScanner#adaptToPreferenceChange(PropertyChangeEvent)
111
	 */
112
	public void adaptToPreferenceChange(PropertyChangeEvent event) {
113
		if (super.affectsBehavior(event)) {
114
			super.adaptToPreferenceChange(event);
115
		}
116
	}
117
}
100
}
(-)src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextTools.java (-15 / +21 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 9-14 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     QNX Software System
10
 *     QNX Software System
11
 *     Wind River Systems, Inc.
11
 *     Wind River Systems, Inc.
12
 *     Andrew Ferguson (Symbian)
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.cdt.internal.ui.editor.asm;
14
package org.eclipse.cdt.internal.ui.editor.asm;
14
15
Lines 20-30 Link Here
20
21
21
import org.eclipse.cdt.core.model.AssemblyLanguage;
22
import org.eclipse.cdt.core.model.AssemblyLanguage;
22
import org.eclipse.cdt.ui.CUIPlugin;
23
import org.eclipse.cdt.ui.CUIPlugin;
23
24
import org.eclipse.cdt.ui.text.ITokenStore;
25
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
24
26
25
import org.eclipse.cdt.internal.ui.text.CCommentScanner;
27
import org.eclipse.cdt.internal.ui.text.CCommentScanner;
26
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
28
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
27
import org.eclipse.cdt.internal.ui.text.SingleTokenCScanner;
29
import org.eclipse.cdt.internal.ui.text.SingleTokenCScanner;
30
import org.eclipse.cdt.internal.ui.text.TokenStore;
28
import org.eclipse.cdt.internal.ui.text.util.CColorManager;
31
import org.eclipse.cdt.internal.ui.text.util.CColorManager;
29
32
30
33
Lines 77-96 Link Here
77
     * and initializes all members of this collection.
80
     * and initializes all members of this collection.
78
     */
81
     */
79
    public AsmTextTools(IPreferenceStore store, Preferences coreStore) {
82
    public AsmTextTools(IPreferenceStore store, Preferences coreStore) {
80
		if(store == null) {
83
    	fPreferenceStore = store != null ? store : CUIPlugin.getDefault().getPreferenceStore();
81
			store = CUIPlugin.getDefault().getPreferenceStore();
84
    	fColorManager= new CColorManager();
82
		}
85
    	
83
        
86
		ITokenStoreFactory factory= new ITokenStoreFactory() {
84
		fColorManager= new CColorManager();
87
			public ITokenStore createTokenStore(String[] propertyColorNames) {
85
		fCodeScanner= new AsmCodeScanner(fColorManager, store, AssemblyLanguage.getDefault());
88
				return new TokenStore(fColorManager, fPreferenceStore, propertyColorNames);
86
		fPreprocessorScanner= new AsmPreprocessorScanner(fColorManager, store, AssemblyLanguage.getDefault());
89
			}
87
90
		};
88
        fMultilineCommentScanner= new CCommentScanner(fColorManager, store, coreStore, ICColorConstants.C_MULTI_LINE_COMMENT);
91
89
        fSinglelineCommentScanner= new CCommentScanner(fColorManager, store, coreStore, ICColorConstants.C_SINGLE_LINE_COMMENT);
92
		fCodeScanner= new AsmCodeScanner(factory, AssemblyLanguage.getDefault());
90
		fStringScanner= new SingleTokenCScanner(fColorManager, store, ICColorConstants.C_STRING);
93
		fPreprocessorScanner= new AsmPreprocessorScanner(factory, AssemblyLanguage.getDefault());
94
        fMultilineCommentScanner= new CCommentScanner(factory, coreStore, ICColorConstants.C_MULTI_LINE_COMMENT);
95
        fSinglelineCommentScanner= new CCommentScanner(factory, coreStore, ICColorConstants.C_SINGLE_LINE_COMMENT);
96
		fStringScanner= new SingleTokenCScanner(factory, ICColorConstants.C_STRING);
91
97
92
        fPreferenceStore = store;
98
		// listener must be registered after initializing scanners
93
		store.addPropertyChangeListener(fPreferenceListener);
99
        fPreferenceStore.addPropertyChangeListener(fPreferenceListener);
94
        
100
        
95
        fCorePreferenceStore= coreStore;
101
        fCorePreferenceStore= coreStore;
96
        if (fCorePreferenceStore != null) {
102
        if (fCorePreferenceStore != null) {
(-)src/org/eclipse/cdt/internal/ui/editor/asm/AsmPreprocessorScanner.java (-24 / +13 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
2
 * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
9
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
10
 *     Andrew Ferguson (Symbian)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.editor.asm;
12
package org.eclipse.cdt.internal.ui.editor.asm;
12
13
Lines 14-31 Link Here
14
import java.util.List;
15
import java.util.List;
15
16
16
import org.eclipse.core.runtime.Assert;
17
import org.eclipse.core.runtime.Assert;
17
import org.eclipse.jface.preference.IPreferenceStore;
18
import org.eclipse.jface.text.rules.EndOfLineRule;
18
import org.eclipse.jface.text.rules.EndOfLineRule;
19
import org.eclipse.jface.text.rules.IRule;
19
import org.eclipse.jface.text.rules.IRule;
20
import org.eclipse.jface.text.rules.Token;
20
import org.eclipse.jface.text.rules.IToken;
21
import org.eclipse.jface.text.rules.WhitespaceRule;
21
import org.eclipse.jface.text.rules.WhitespaceRule;
22
22
23
import org.eclipse.cdt.core.model.IAsmLanguage;
23
import org.eclipse.cdt.core.model.IAsmLanguage;
24
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
24
25
25
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
26
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
26
import org.eclipse.cdt.internal.ui.text.CHeaderRule;
27
import org.eclipse.cdt.internal.ui.text.CHeaderRule;
27
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
28
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
28
import org.eclipse.cdt.internal.ui.text.IColorManager;
29
import org.eclipse.cdt.internal.ui.text.PreprocessorRule;
29
import org.eclipse.cdt.internal.ui.text.PreprocessorRule;
30
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
30
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
31
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
31
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
Lines 50-76 Link Here
50
50
51
	/**
51
	/**
52
	 * Create a preprocessor directive scanner.
52
	 * Create a preprocessor directive scanner.
53
	 * 
53
	 * @param factory
54
	 * @param colorManager
54
     * @param asmLanguage
55
	 * @param store
56
	 * @param asmLanguage
57
	 */
55
	 */
58
	public AsmPreprocessorScanner(IColorManager colorManager, IPreferenceStore store, IAsmLanguage asmLanguage) {
56
	public AsmPreprocessorScanner(ITokenStoreFactory factory, IAsmLanguage asmLanguage) {
59
		super(colorManager, store);
57
		super(factory.createTokenStore(fgTokenProperties));
60
		Assert.isNotNull(asmLanguage);
58
		Assert.isNotNull(asmLanguage);
61
		fAsmLanguage= asmLanguage;
59
		fAsmLanguage= asmLanguage;
62
		initialize();
60
		setRules(createRules());
63
	}
61
	}
64
62
65
	/*
63
	/**
66
	 * @see org.eclipse.cdt.internal.ui.text.AbstractCScanner#createRules()
64
	 * Creates rules used in this RulesBasedScanner
67
	 */
65
	 */
68
	protected List createRules() {
66
	protected List createRules() {
69
67
		IToken defaultToken= getToken(ICColorConstants.PP_DEFAULT);
70
		Token defaultToken= getToken(ICColorConstants.PP_DEFAULT);
71
68
72
		List rules= new ArrayList();		
69
		List rules= new ArrayList();		
73
		Token token;
70
		IToken token;
74
		
71
		
75
		// Add generic white space rule.
72
		// Add generic white space rule.
76
		rules.add(new WhitespaceRule(new CWhitespaceDetector()));
73
		rules.add(new WhitespaceRule(new CWhitespaceDetector()));
Lines 103-114 Link Here
103
        setDefaultReturnToken(defaultToken);
100
        setDefaultReturnToken(defaultToken);
104
		return rules;
101
		return rules;
105
	}
102
	}
106
107
	/*
108
	 * @see org.eclipse.cdt.internal.ui.text.AbstractCScanner#getTokenProperties()
109
	 */
110
	protected String[] getTokenProperties() {
111
		return fgTokenProperties;
112
	}
113
114
}
103
}
(-)src/org/eclipse/cdt/internal/ui/editor/asm/AsmSourceViewerConfiguration.java (-8 / +18 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 QNX Software Systems and others.
2
 * Copyright (c) 2000, 2008 QNX Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 44-49 Link Here
44
import org.eclipse.cdt.ui.CUIPlugin;
44
import org.eclipse.cdt.ui.CUIPlugin;
45
import org.eclipse.cdt.ui.ILanguageUI;
45
import org.eclipse.cdt.ui.ILanguageUI;
46
import org.eclipse.cdt.ui.text.ICPartitions;
46
import org.eclipse.cdt.ui.text.ICPartitions;
47
import org.eclipse.cdt.ui.text.ITokenStore;
48
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
47
49
48
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
50
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
49
import org.eclipse.cdt.internal.ui.text.CCommentScanner;
51
import org.eclipse.cdt.internal.ui.text.CCommentScanner;
Lines 52-57 Link Here
52
import org.eclipse.cdt.internal.ui.text.IColorManager;
54
import org.eclipse.cdt.internal.ui.text.IColorManager;
53
import org.eclipse.cdt.internal.ui.text.PartitionDamager;
55
import org.eclipse.cdt.internal.ui.text.PartitionDamager;
54
import org.eclipse.cdt.internal.ui.text.SingleTokenCScanner;
56
import org.eclipse.cdt.internal.ui.text.SingleTokenCScanner;
57
import org.eclipse.cdt.internal.ui.text.TokenStore;
55
58
56
59
57
public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration {
60
public class AsmSourceViewerConfiguration extends TextSourceViewerConfiguration {
Lines 123-131 Link Here
123
	 * Initializes the scanners.
126
	 * Initializes the scanners.
124
	 */
127
	 */
125
	private void initializeScanners() {
128
	private void initializeScanners() {
126
		fMultilineCommentScanner= new CCommentScanner(getColorManager(), fPreferenceStore, ICColorConstants.C_MULTI_LINE_COMMENT);
129
		fMultilineCommentScanner= new CCommentScanner(getTokenStoreFactory(), ICColorConstants.C_MULTI_LINE_COMMENT);
127
		fSinglelineCommentScanner= new CCommentScanner(getColorManager(), fPreferenceStore, ICColorConstants.C_SINGLE_LINE_COMMENT);
130
		fSinglelineCommentScanner= new CCommentScanner(getTokenStoreFactory(), ICColorConstants.C_SINGLE_LINE_COMMENT);
128
		fStringScanner= new SingleTokenCScanner(getColorManager(), fPreferenceStore, ICColorConstants.C_STRING);
131
		fStringScanner= new SingleTokenCScanner(getTokenStoreFactory(), ICColorConstants.C_STRING);
129
	}
132
	}
130
133
131
	/**
134
	/**
Lines 167-176 Link Here
167
		}
170
		}
168
		AbstractCScanner scanner= null;
171
		AbstractCScanner scanner= null;
169
		if (language instanceof IAsmLanguage) {
172
		if (language instanceof IAsmLanguage) {
170
			scanner= new AsmPreprocessorScanner(getColorManager(), fPreferenceStore, (IAsmLanguage)language);
173
			scanner= new AsmPreprocessorScanner(getTokenStoreFactory(), (IAsmLanguage)language);
171
		}
174
		}
172
		if (scanner == null) {
175
		if (scanner == null) {
173
			scanner= new AsmPreprocessorScanner(getColorManager(), fPreferenceStore, AssemblyLanguage.getDefault());
176
			scanner= new AsmPreprocessorScanner(getTokenStoreFactory(), AssemblyLanguage.getDefault());
174
		}
177
		}
175
		fPreprocessorScanner= scanner;
178
		fPreprocessorScanner= scanner;
176
		return fPreprocessorScanner;
179
		return fPreprocessorScanner;
Lines 187-200 Link Here
187
		RuleBasedScanner scanner= null;
190
		RuleBasedScanner scanner= null;
188
		if (language instanceof IAsmLanguage) {
191
		if (language instanceof IAsmLanguage) {
189
			IAsmLanguage asmLang= (IAsmLanguage)language;
192
			IAsmLanguage asmLang= (IAsmLanguage)language;
190
			scanner = new AsmCodeScanner(getColorManager(), fPreferenceStore, asmLang);
193
			scanner = new AsmCodeScanner(getTokenStoreFactory(), asmLang);
191
		} else if (language != null) {
194
		} else if (language != null) {
192
			ILanguageUI languageUI = (ILanguageUI)language.getAdapter(ILanguageUI.class);
195
			ILanguageUI languageUI = (ILanguageUI)language.getAdapter(ILanguageUI.class);
193
			if (languageUI != null)
196
			if (languageUI != null)
194
				scanner = languageUI.getCodeScanner();
197
				scanner = languageUI.getCodeScanner();
195
		}
198
		}
196
		if (scanner == null) {
199
		if (scanner == null) {
197
			scanner = new AsmCodeScanner(getColorManager(), fPreferenceStore, AssemblyLanguage.getDefault());
200
			scanner = new AsmCodeScanner(getTokenStoreFactory(), AssemblyLanguage.getDefault());
198
		}
201
		}
199
		if (scanner instanceof AbstractCScanner) {
202
		if (scanner instanceof AbstractCScanner) {
200
			fCodeScanner= (AbstractCScanner)scanner;
203
			fCodeScanner= (AbstractCScanner)scanner;
Lines 373-378 Link Here
373
		fPreprocessorScanner= null;
376
		fPreprocessorScanner= null;
374
	}
377
	}
375
378
379
	private ITokenStoreFactory getTokenStoreFactory() {
380
		return new ITokenStoreFactory() {
381
			public ITokenStore createTokenStore(String[] propertyColorNames) {
382
				return new TokenStore(getColorManager(), fPreferenceStore, propertyColorNames);
383
			}
384
		};
385
	}
376
}
386
}
377
387
378
388
(-)src/org/eclipse/cdt/ui/dialogs/DialogsMessages.properties (+5 lines)
Lines 22-27 Link Here
22
CacheSizeBlock_absoluteLimit=Absolute Limit:
22
CacheSizeBlock_absoluteLimit=Absolute Limit:
23
CacheSizeBlock_MB=MB
23
CacheSizeBlock_MB=MB
24
CacheSizeBlock_headerFileCache=Header file cache (used by full indexer and refactoring):
24
CacheSizeBlock_headerFileCache=Header file cache (used by full indexer and refactoring):
25
DocCommentOwnerBlock_DocToolLabel=Documentation tool:
26
DocCommentOwnerBlock_EnableProjectSpecificSettings=Enable project specific settings
27
DocCommentOwnerBlock_SelectDocToolDescription=Select the documentation tool to be used to determine editor behaviors in this project
28
DocCommentOwnerCombo_None=None
29
DocCommentOwnerComposite_DocumentationToolGroupTitle=Documentation tool comments
25
IndexerStrategyBlock_strategyGroup=Indexing strategy
30
IndexerStrategyBlock_strategyGroup=Indexing strategy
26
IndexerStrategyBlock_autoUpdate=Automatically update the index
31
IndexerStrategyBlock_autoUpdate=Automatically update the index
27
IndexerBlock_fixedBuildConfig=Use a fixed build configuration
32
IndexerBlock_fixedBuildConfig=Use a fixed build configuration
(-)src/org/eclipse/cdt/ui/dialogs/DialogsMessages.java (+6 lines)
Lines 37-42 Link Here
37
	public static String CacheSizeBlock_indexDatabaseCache;
37
	public static String CacheSizeBlock_indexDatabaseCache;
38
	public static String CacheSizeBlock_limitRelativeToMaxHeapSize;
38
	public static String CacheSizeBlock_limitRelativeToMaxHeapSize;
39
	
39
	
40
	public static String DocCommentOwnerBlock_DocToolLabel;
41
	public static String DocCommentOwnerBlock_EnableProjectSpecificSettings;
42
	public static String DocCommentOwnerBlock_SelectDocToolDescription;
43
	public static String DocCommentOwnerCombo_None;
44
	public static String DocCommentOwnerComposite_DocumentationToolGroupTitle;
45
40
	static {
46
	static {
41
		// initialize resource bundle
47
		// initialize resource bundle
42
		NLS.initializeMessages(BUNDLE_NAME, DialogsMessages.class);
48
		NLS.initializeMessages(BUNDLE_NAME, DialogsMessages.class);
(-)plugin.xml (-11 / +55 lines)
Lines 23-28 Link Here
23
   <extension-point id="ConfigManager" name="%ConfigManager" schema="schema/ConfigManager.exsd"/>
23
   <extension-point id="ConfigManager" name="%ConfigManager" schema="schema/ConfigManager.exsd"/>
24
   <extension-point id="HelpInfo" name="%HelpInfo" schema="schema/HelpInfo.exsd"/>
24
   <extension-point id="HelpInfo" name="%HelpInfo" schema="schema/HelpInfo.exsd"/>
25
   <extension-point id="quickFixProcessors" name="%quickFixProcessorExtensionPoint" schema="schema/quickFixProcessors.exsd"/>
25
   <extension-point id="quickFixProcessors" name="%quickFixProcessorExtensionPoint" schema="schema/quickFixProcessors.exsd"/>
26
   <extension-point id="DocCommentOwner" name="%extension-point.name.0" schema="schema/DocCommentOwner.exsd"/>
26
27
27
   <extension
28
   <extension
28
         point="org.eclipse.core.runtime.adapters">
29
         point="org.eclipse.core.runtime.adapters">
Lines 770-775 Link Here
770
            class="org.eclipse.cdt.internal.ui.preferences.WorkInProgressPreferencePage"
771
            class="org.eclipse.cdt.internal.ui.preferences.WorkInProgressPreferencePage"
771
            id="org.eclipse.cdt.ui.preferneces.WorkInProgressPreferencePage">
772
            id="org.eclipse.cdt.ui.preferneces.WorkInProgressPreferencePage">
772
      </page-->
773
      </page-->
774
      <page
775
            class="org.eclipse.cdt.ui.templateengine.pages.TemplatePreferencePage"
776
            name="%TemplatePreferencePage.name"
777
            category="org.eclipse.cdt.ui.preferences.CPluginPreferencePage"
778
            id="org.eclipse.cdt.core.templateengine.shareddefaults"/>
779
      <page
780
            category="org.eclipse.cdt.ui.preferences.CEditorPreferencePage"
781
            class="org.eclipse.cdt.ui.text.doctools.DocToolsPreferencePage"
782
            id="org.eclipse.cdt.ui.text.doctools.prefpage"
783
            name="Doc. Comments"/>
773
   </extension>
784
   </extension>
774
   <extension
785
   <extension
775
         point="org.eclipse.ui.editorActions">
786
         point="org.eclipse.ui.editorActions">
Lines 2434-2449 Link Here
2434
           name="%exportWizard.CDTCategory.name">
2445
           name="%exportWizard.CDTCategory.name">
2435
     </category>
2446
     </category>
2436
  </extension>
2447
  </extension>
2437
2438
   <extension
2439
         point="org.eclipse.ui.preferencePages">
2440
      <page
2441
            class="org.eclipse.cdt.ui.templateengine.pages.TemplatePreferencePage"
2442
            name="%TemplatePreferencePage.name"
2443
            category="org.eclipse.cdt.ui.preferences.CPluginPreferencePage"
2444
            id="org.eclipse.cdt.core.templateengine.shareddefaults"/>
2445
   </extension>
2446
  
2447
   <extension
2448
   <extension
2448
            id="TemplateEngineWizard"
2449
            id="TemplateEngineWizard"
2449
            name="%Template.Engine.Wizard"
2450
            name="%Template.Engine.Wizard"
Lines 2463-2473 Link Here
2463
      </updater>
2464
      </updater>
2464
   </extension>
2465
   </extension>
2465
   <extension
2466
   <extension
2467
         id="id1"
2468
         point="org.eclipse.cdt.ui.completionProposalComputer">
2469
      <completionProposalComputer
2470
            activate="true"
2471
            categoryId="org.eclipse.cdt.ui.parserProposalCategory"
2472
            class="org.eclipse.cdt.internal.ui.text.doctools.DocCommentMultilineProposalComputer">
2473
         <partition
2474
               type="__c_multiline_doc_comment">
2475
         </partition>
2476
      </completionProposalComputer>
2477
   </extension>
2478
   <extension
2479
         id="id2"
2480
         point="org.eclipse.cdt.ui.completionProposalComputer">
2481
      <completionProposalComputer
2482
            activate="true"
2483
            categoryId="org.eclipse.cdt.ui.parserProposalCategory"
2484
            class="org.eclipse.cdt.internal.ui.text.doctools.DocCommentSinglelineProposalComputer">
2485
         <partition
2486
               type="__c_singleline_doc_comment">
2487
         </partition>
2488
      </completionProposalComputer>
2489
   </extension>
2490
   <extension
2466
         point="org.eclipse.cdt.ui.CHelpProvider">
2491
         point="org.eclipse.cdt.ui.CHelpProvider">
2467
      <provider
2492
      <provider
2468
            class="org.eclipse.cdt.internal.ui.help.CHelpProvider"
2493
            class="org.eclipse.cdt.internal.ui.help.CHelpProvider"
2469
            id="org.eclipse.cdt.ui.provider1">
2494
            id="org.eclipse.cdt.ui.provider1">
2470
      </provider>
2495
      </provider>
2471
   </extension>
2496
   </extension>
2472
 
2497
   
2498
   <!-- -->
2499
   <extension
2500
         point="org.eclipse.cdt.ui.DocCommentOwner">
2501
      <owner
2502
            id="org.eclipse.cdt.ui.doxygen"
2503
            name="Doxygen"
2504
            multiline="org.eclipse.cdt.internal.ui.text.doctools.doxygen.DoxygenMultilineConfiguration"
2505
            singleline="org.eclipse.cdt.internal.ui.text.doctools.doxygen.DoxygenSingleConfiguration">
2506
      </owner>
2507
   </extension>
2508
   <extension
2509
         point="org.eclipse.cdt.ui.DocCommentOwner">
2510
      <owner
2511
            id="org.eclipse.cdt.ui.docpp"
2512
            name="Doc++"
2513
            multiline="org.eclipse.cdt.internal.ui.text.doctools.docpp.DocppMultilineConfiguration"
2514
            singleline="org.eclipse.cdt.internal.ui.text.doctools.docpp.DocppSingleConfiguration">
2515
      </owner>
2516
   </extension>
2473
 </plugin>
2517
 </plugin>
(-)plugin.properties (+2 lines)
Lines 447-449 Link Here
447
toggleMarkOccurrences.description= Toggles mark occurrences in C/C++ editors
447
toggleMarkOccurrences.description= Toggles mark occurrences in C/C++ editors
448
448
449
OccurrenceAnnotation.label= C/C++ Occurrences
449
OccurrenceAnnotation.label= C/C++ Occurrences
450
451
extension-point.name.0 = DocCommentOwner
(-)src/org/eclipse/cdt/internal/ui/text/spelling/CSpellingEngine.java (+42 lines)
Lines 15-20 Link Here
15
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.jface.text.BadLocationException;
16
import org.eclipse.jface.text.BadLocationException;
17
import org.eclipse.jface.text.IDocument;
17
import org.eclipse.jface.text.IDocument;
18
import org.eclipse.jface.text.IDocumentExtension3;
19
import org.eclipse.jface.text.IDocumentPartitioner;
18
import org.eclipse.jface.text.IRegion;
20
import org.eclipse.jface.text.IRegion;
19
import org.eclipse.jface.text.ITypedRegion;
21
import org.eclipse.jface.text.ITypedRegion;
20
import org.eclipse.jface.text.TextUtilities;
22
import org.eclipse.jface.text.TextUtilities;
Lines 25-33 Link Here
25
27
26
import org.eclipse.cdt.ui.CUIPlugin;
28
import org.eclipse.cdt.ui.CUIPlugin;
27
import org.eclipse.cdt.ui.text.ICPartitions;
29
import org.eclipse.cdt.ui.text.ICPartitions;
30
import org.eclipse.cdt.ui.text.doctools.IDocCommentDictionary;
31
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
32
import org.eclipse.cdt.ui.text.doctools.IDocCommentSimpleDictionary;
28
33
29
import org.eclipse.cdt.internal.ui.text.CTextTools;
34
import org.eclipse.cdt.internal.ui.text.CTextTools;
35
import org.eclipse.cdt.internal.ui.text.FastCPartitioner;
36
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentSpellDictionary;
30
import org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellChecker;
37
import org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellChecker;
38
import org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellDictionary;
31
import org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellEventListener;
39
import org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellEventListener;
32
40
33
/**
41
/**
Lines 40-47 Link Here
40
	protected void check(IDocument document, IRegion[] regions, ISpellChecker checker, ISpellingProblemCollector collector, IProgressMonitor monitor) {
48
	protected void check(IDocument document, IRegion[] regions, ISpellChecker checker, ISpellingProblemCollector collector, IProgressMonitor monitor) {
41
		ISpellEventListener listener= new SpellEventListener(collector, document);
49
		ISpellEventListener listener= new SpellEventListener(collector, document);
42
		boolean isIgnoringStringLiterals= SpellingPreferences.isIgnoreStringLiterals();
50
		boolean isIgnoringStringLiterals= SpellingPreferences.isIgnoreStringLiterals();
51
		
52
		ISpellDictionary toRemove= null;
43
		try {
53
		try {
44
			checker.addListener(listener);
54
			checker.addListener(listener);
55
			
56
			IDocCommentOwner owner= null;
57
			if(document instanceof IDocumentExtension3) {
58
				IDocumentPartitioner partitioner= ((IDocumentExtension3)document).getDocumentPartitioner(ICPartitions.C_PARTITIONING);
59
					if(partitioner instanceof FastCPartitioner) {
60
						owner= ((FastCPartitioner)partitioner).getDocCommentOwner();
61
					}
62
			}
63
			
45
			try {
64
			try {
46
				for (int i= 0; i < regions.length; i++) {
65
				for (int i= 0; i < regions.length; i++) {
47
					IRegion region= regions[i];
66
					IRegion region= regions[i];
Lines 57-62 Link Here
57
						if (isIgnoringStringLiterals && type.equals(ICPartitions.C_STRING))
76
						if (isIgnoringStringLiterals && type.equals(ICPartitions.C_STRING))
58
							continue;
77
							continue;
59
78
79
						if(owner!=null) {
80
							IDocCommentDictionary dict= null;
81
							
82
							if (type.equals(ICPartitions.C_MULTI_LINE_DOC_COMMENT)) {
83
								dict= owner.getMultilineConfiguration().getSpellingDictionary();
84
							} else if (type.equals(ICPartitions.C_SINGLE_LINE_DOC_COMMENT)) {
85
								dict= owner.getSinglelineConfiguration().getSpellingDictionary();
86
							}
87
							
88
							if(dict instanceof IDocCommentSimpleDictionary) {
89
								ISpellDictionary sd= new DocCommentSpellDictionary((IDocCommentSimpleDictionary)dict);
90
								checker.addDictionary(sd);
91
								toRemove= sd;
92
							}
93
						}
94
						
60
						if (type.equals(ICPartitions.C_PREPROCESSOR)) {
95
						if (type.equals(ICPartitions.C_PREPROCESSOR)) {
61
							CTextTools textTools = CUIPlugin.getDefault().getTextTools();
96
							CTextTools textTools = CUIPlugin.getDefault().getTextTools();
62
							RuleBasedScanner scanner = textTools.getCppPreprocessorScanner();
97
							RuleBasedScanner scanner = textTools.getCppPreprocessorScanner();
Lines 101-112 Link Here
101
								!type.equals(ICPartitions.C_CHARACTER)) {
136
								!type.equals(ICPartitions.C_CHARACTER)) {
102
							checker.execute(new SpellCheckIterator(document, partition, checker.getLocale()));
137
							checker.execute(new SpellCheckIterator(document, partition, checker.getLocale()));
103
						}
138
						}
139
						
140
						if(toRemove != null) {
141
							checker.removeDictionary(toRemove);
142
							toRemove= null;
143
						}
104
					}
144
					}
105
				}
145
				}
106
			} catch (BadLocationException x) {
146
			} catch (BadLocationException x) {
107
				CUIPlugin.getDefault().log(x);
147
				CUIPlugin.getDefault().log(x);
108
			}
148
			}
109
		} finally {
149
		} finally {
150
			if(toRemove!=null)
151
				checker.removeDictionary(toRemove);
110
			checker.removeListener(listener);
152
			checker.removeListener(listener);
111
		}
153
		}
112
	}
154
	}
(-)src/org/eclipse/cdt/internal/ui/editor/CDocumentSetupParticipant.java (-5 / +16 lines)
Lines 11-25 Link Here
11
11
12
package org.eclipse.cdt.internal.ui.editor;
12
package org.eclipse.cdt.internal.ui.editor;
13
13
14
import org.eclipse.cdt.internal.ui.text.CTextTools;
15
import org.eclipse.cdt.ui.CUIPlugin;
16
import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
14
import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
15
import org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension;
16
import org.eclipse.core.filebuffers.LocationKind;
17
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.jface.text.IDocument;
18
import org.eclipse.jface.text.IDocument;
18
19
20
import org.eclipse.cdt.ui.CUIPlugin;
21
22
import org.eclipse.cdt.internal.ui.text.CTextTools;
23
19
/**
24
/**
20
 * CDocumentSetupParticipant
25
 * CDocumentSetupParticipant
21
 */
26
 */
22
public class CDocumentSetupParticipant implements IDocumentSetupParticipant {
27
public class CDocumentSetupParticipant implements IDocumentSetupParticipant, IDocumentSetupParticipantExtension {
23
	/**
28
	/**
24
	 * 
29
	 * 
25
	 */
30
	 */
Lines 30-37 Link Here
30
	 * @see org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.eclipse.jface.text.IDocument)
35
	 * @see org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.eclipse.jface.text.IDocument)
31
	 */
36
	 */
32
	public void setup(IDocument document) {
37
	public void setup(IDocument document) {
38
		setup(document, null, null);
39
	}
40
	
41
	/*
42
	 * @see org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension#setup(org.eclipse.jface.text.IDocument, org.eclipse.core.runtime.IPath, org.eclipse.core.filebuffers.LocationKind)
43
	 */
44
	public void setup(IDocument document, IPath location, LocationKind locationKind) {
33
		CTextTools tools= CUIPlugin.getDefault().getTextTools();
45
		CTextTools tools= CUIPlugin.getDefault().getTextTools();
34
		tools.setupCDocument(document);
46
		tools.setupCDocument(document, location, locationKind);
35
	}
47
	}
36
37
}
48
}
(-)src/org/eclipse/cdt/internal/ui/preferences/formatter/CPreview.java (-1 / +1 lines)
Lines 110-116 Link Here
110
		CTextTools tools= CUIPlugin.getDefault().getTextTools();
110
		CTextTools tools= CUIPlugin.getDefault().getTextTools();
111
		fPreviewDocument= new Document();
111
		fPreviewDocument= new Document();
112
		fWorkingValues= workingValues;
112
		fWorkingValues= workingValues;
113
		tools.setupCDocumentPartitioner( fPreviewDocument, ICPartitions.C_PARTITIONING);	
113
		tools.setupCDocumentPartitioner(fPreviewDocument, ICPartitions.C_PARTITIONING, null);	
114
		
114
		
115
		PreferenceStore prioritizedSettings= new PreferenceStore();
115
		PreferenceStore prioritizedSettings= new PreferenceStore();
116
		
116
		
(-)src/org/eclipse/cdt/ui/CUIPlugin.java (+6 lines)
Lines 88-93 Link Here
88
import org.eclipse.cdt.internal.ui.text.CTextTools;
88
import org.eclipse.cdt.internal.ui.text.CTextTools;
89
import org.eclipse.cdt.internal.ui.text.PreferencesAdapter;
89
import org.eclipse.cdt.internal.ui.text.PreferencesAdapter;
90
import org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverDescriptor;
90
import org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverDescriptor;
91
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
92
import org.eclipse.cdt.internal.ui.text.doctools.EditorReopener;
91
import org.eclipse.cdt.internal.ui.text.folding.CFoldingStructureProviderRegistry;
93
import org.eclipse.cdt.internal.ui.text.folding.CFoldingStructureProviderRegistry;
92
import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry;
94
import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry;
93
import org.eclipse.cdt.internal.ui.util.ProblemMarkerManager;
95
import org.eclipse.cdt.internal.ui.util.ProblemMarkerManager;
Lines 102-107 Link Here
102
	public static final String CVIEW_ID = PLUGIN_ID + ".CView"; //$NON-NLS-1$
104
	public static final String CVIEW_ID = PLUGIN_ID + ".CView"; //$NON-NLS-1$
103
	public static final String C_PROBLEMMARKER = PLUGIN_CORE_ID + ".problem"; //$NON-NLS-1$
105
	public static final String C_PROBLEMMARKER = PLUGIN_CORE_ID + ".problem"; //$NON-NLS-1$
104
106
107
	public static final String ID_COMMENT_OWNER= PLUGIN_ID+".DocCommentOwner"; //$NON-NLS-1$
108
	
105
    public static final String ID_INCLUDE_BROWSER= PLUGIN_ID + ".includeBrowser"; //$NON-NLS-1$
109
    public static final String ID_INCLUDE_BROWSER= PLUGIN_ID + ".includeBrowser"; //$NON-NLS-1$
106
    public static final String ID_CALL_HIERARCHY= PLUGIN_ID + ".callHierarchy"; //$NON-NLS-1$
110
    public static final String ID_CALL_HIERARCHY= PLUGIN_ID + ".callHierarchy"; //$NON-NLS-1$
107
	public static final String ID_TYPE_HIERARCHY = PLUGIN_ID + ".typeHierarchy"; //$NON-NLS-1$
111
	public static final String ID_TYPE_HIERARCHY = PLUGIN_ID + ".typeHierarchy"; //$NON-NLS-1$
Lines 475-480 Link Here
475
		getASTProvider();
479
		getASTProvider();
476
		CDTContextActivator.getInstance().install();
480
		CDTContextActivator.getInstance().install();
477
		
481
		
482
		DocCommentOwnerManager.getInstance().addListener(new EditorReopener());
483
		
478
		// start make-ui plugin, such that it can check for project conversions.
484
		// start make-ui plugin, such that it can check for project conversions.
479
		Job job= new Job(Messages.CUIPlugin_jobStartMakeUI) {
485
		Job job= new Job(Messages.CUIPlugin_jobStartMakeUI) {
480
			protected IStatus run(IProgressMonitor monitor) {
486
			protected IStatus run(IProgressMonitor monitor) {
(-)src/org/eclipse/cdt/ui/text/ICPartitions.java (-1 / +25 lines)
Lines 23-29 Link Here
23
	String C_PARTITIONING= "___c_partitioning";  //$NON-NLS-1$
23
	String C_PARTITIONING= "___c_partitioning";  //$NON-NLS-1$
24
24
25
	/**
25
	/**
26
	 * The identifier of the single-line end comment partition content type.
26
	 * The identifier of the single-line comment partition content type.
27
	 */
27
	 */
28
	String C_SINGLE_LINE_COMMENT= "__c_singleline_comment"; //$NON-NLS-1$
28
	String C_SINGLE_LINE_COMMENT= "__c_singleline_comment"; //$NON-NLS-1$
29
29
Lines 46-49 Link Here
46
	 * The identifier of the C preprocessor partition content type.
46
	 * The identifier of the C preprocessor partition content type.
47
	 */
47
	 */
48
	String C_PREPROCESSOR= "__c_preprocessor";  //$NON-NLS-1$
48
	String C_PREPROCESSOR= "__c_preprocessor";  //$NON-NLS-1$
49
	
50
	/**
51
	 * The identifier of the single-line documentation tool comment partition content type.
52
	 */
53
	String C_SINGLE_LINE_DOC_COMMENT= "__c_singleline_doc_comment"; //$NON-NLS-1$
54
55
	/**
56
	 * The identifier multi-line comment documentation tool partition content type.
57
	 */
58
	String C_MULTI_LINE_DOC_COMMENT= "__c_multiline_doc_comment"; //$NON-NLS-1$
59
	
60
	/**
61
	 * 
62
	 * @since 5.0
63
	 */
64
	String[] ALL_CPARTITIONS= {
65
			ICPartitions.C_MULTI_LINE_COMMENT,
66
			ICPartitions.C_SINGLE_LINE_COMMENT,
67
			ICPartitions.C_STRING,
68
			ICPartitions.C_CHARACTER,
69
			ICPartitions.C_PREPROCESSOR,
70
			ICPartitions.C_SINGLE_LINE_DOC_COMMENT,
71
			ICPartitions.C_MULTI_LINE_DOC_COMMENT
72
	};
49
}
73
}
(-)src/org/eclipse/cdt/ui/newui/Page_head_general.java (-2 / +57 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 Intel Corporation and others
2
 * Copyright (c) 2005, 2008 Intel Corporation and others
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-22 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Intel Corporation - initial API and implementation
9
 *     Intel Corporation - initial API and implementation
10
 *     Andrew Ferguson (Symbian)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.cdt.ui.newui;
12
package org.eclipse.cdt.ui.newui;
12
13
14
import org.eclipse.core.resources.IProject;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.core.runtime.NullProgressMonitor;
18
import org.eclipse.core.runtime.Preferences;
13
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Composite;
14
import org.eclipse.swt.widgets.Control;
20
import org.eclipse.swt.widgets.Control;
15
import org.eclipse.ui.dialogs.PropertyPage;
21
import org.eclipse.ui.dialogs.PropertyPage;
16
22
17
public class Page_head_general extends PropertyPage {
23
import org.eclipse.cdt.core.CCorePlugin;
24
import org.eclipse.cdt.ui.dialogs.DocCommentOwnerBlock;
25
import org.eclipse.cdt.ui.dialogs.ICOptionContainer;
26
27
public class Page_head_general extends PropertyPage implements ICOptionContainer {
28
	private DocCommentOwnerBlock fDocBlock;
29
	private boolean isProjectLevel;
30
	
18
	protected Control createContents(Composite parent) {
31
	protected Control createContents(Composite parent) {
32
		isProjectLevel= getElement() instanceof IProject;
33
		if(isProjectLevel) {
34
			fDocBlock= new DocCommentOwnerBlock();
35
			fDocBlock.setContainer(this);
36
			fDocBlock.createControl(parent);
37
		}
19
		noDefaultAndApplyButton();
38
		noDefaultAndApplyButton();
20
		return parent;
39
		return parent;
21
	}
40
	}
41
	
42
	protected void performDefaults() {
43
		if(isProjectLevel) {
44
			fDocBlock.performDefaults();
45
		}
46
		super.performDefaults();
47
	}
48
	
49
	public boolean performOk() {
50
		if(isProjectLevel) {
51
			try {
52
				fDocBlock.performApply(new NullProgressMonitor());
53
			} catch(CoreException ce) {
54
				CCorePlugin.log(ce);
55
			}
56
		}
57
		return true;
58
	}
59
60
	public IProject getProject(){
61
		IProject project= null;
62
		IAdaptable elem = getElement();
63
		if (elem instanceof IProject) {
64
			project= (IProject) elem;
65
		} else if (elem != null) {
66
			project= (IProject) elem.getAdapter(IProject.class);
67
		}
68
		return project;
69
	}
70
71
	public Preferences getPreferences() {
72
		throw new UnsupportedOperationException();
73
	}
74
75
	public void updateContainer() {
76
	}
22
}
77
}
(-)schema/completionProposalComputer.exsd (+4 lines)
Lines 115-120 Link Here
115
                  </enumeration>
115
                  </enumeration>
116
                  <enumeration value="__c_preprocessor">
116
                  <enumeration value="__c_preprocessor">
117
                  </enumeration>
117
                  </enumeration>
118
                  <enumeration value="__c_multiline_doc_comment">
119
                  </enumeration>
120
                  <enumeration value="__c_singleline_doc_comment">
121
                  </enumeration>
118
               </restriction>
122
               </restriction>
119
            </simpleType>
123
            </simpleType>
120
         </attribute>
124
         </attribute>
(-)src/org/eclipse/cdt/ui/text/doctools/generic/GenericTagCompletionProposalComputer.java (+104 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.text.doctools.generic;
12
13
import java.util.ArrayList;
14
import java.util.Collections;
15
import java.util.List;
16
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.jface.text.BadLocationException;
19
import org.eclipse.jface.text.IDocument;
20
import org.eclipse.jface.text.ITypedRegion;
21
import org.eclipse.jface.text.TextUtilities;
22
23
import org.eclipse.cdt.ui.text.ICPartitions;
24
import org.eclipse.cdt.ui.text.contentassist.ContentAssistInvocationContext;
25
import org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer;
26
27
import org.eclipse.cdt.internal.ui.text.contentassist.CCompletionProposal;
28
29
/**
30
 * CompletionProposalComputer based on a specified set of GenericTag objects.
31
 */
32
public class GenericTagCompletionProposalComputer implements ICompletionProposalComputer {
33
	char[] tagMarkers;
34
	
35
	GenericDocTag[] tags;
36
	
37
	public GenericTagCompletionProposalComputer(GenericDocTag[] tags) {
38
		this.tags= tags;
39
		this.tagMarkers= new char[] {'@','\\'};
40
	}
41
	
42
	protected boolean isTagMarker(char c) {
43
		for(int i=0; i<tagMarkers.length; i++)
44
			if(c == tagMarkers[i])
45
				return true;
46
		return false;
47
	}
48
	
49
	
50
	public List computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
51
		IDocument doc= context.getDocument();
52
		int ivcOffset= context.getInvocationOffset();
53
		try {
54
			ITypedRegion tr= TextUtilities.getPartition(doc, ICPartitions.C_PARTITIONING, ivcOffset, false);
55
			int firstNonWS= ivcOffset;
56
			while(firstNonWS-1> tr.getOffset() && !Character.isWhitespace(doc.get(firstNonWS-1, 1).charAt(0)))
57
				firstNonWS--;
58
			String prefix= doc.get(firstNonWS, ivcOffset-firstNonWS);
59
			if(prefix.length()>0 && isTagMarker(prefix.charAt(0))) {
60
				List proposals= new ArrayList();
61
				char tagMarker= prefix.charAt(0);
62
				for(int i=0; i<tags.length; i++) {
63
					String tag= tags[i].getTagName();
64
					if(tag.toLowerCase().startsWith(prefix.substring(1).toLowerCase())) {						
65
						CCompletionProposal proposal= new CCompletionProposal(tagMarker+tag, ivcOffset-prefix.length(), prefix.length(), null, tagMarker+tag, 1, context.getViewer()); 
66
						String description= tags[i].getTagDescription();
67
						if(description!=null && !description.equals("")) { //$NON-NLS-1$
68
							proposal.setAdditionalProposalInfo(description);
69
						}
70
						proposals.add(proposal);
71
					}
72
				}
73
				return proposals;
74
			}
75
		} catch(BadLocationException ble) {
76
			// offset is zero, ignore
77
		}
78
		return new ArrayList();
79
	}
80
81
	/*
82
	 * @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#computeContextInformation(org.eclipse.cdt.ui.text.contentassist.ContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
83
	 */
84
	public List computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) {
85
		return Collections.EMPTY_LIST;
86
	}
87
88
	/*
89
	 * @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#getErrorMessage()
90
	 */
91
	public String getErrorMessage() {
92
		return null;
93
	}
94
95
	/*
96
	 * @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#sessionEnded()
97
	 */
98
	public void sessionEnded() {}
99
	
100
	/*
101
	 * @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#sessionStarted()
102
	 */
103
	public void sessionStarted() {}
104
}
(-)src/org/eclipse/cdt/ui/text/doctools/DefaultMultilineCommentAutoEditStrategy.java (+381 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.text.doctools;
12
13
import java.io.BufferedReader;
14
import java.io.IOException;
15
import java.io.StringReader;
16
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.jface.text.BadLocationException;
19
import org.eclipse.jface.text.DocumentCommand;
20
import org.eclipse.jface.text.DocumentRewriteSession;
21
import org.eclipse.jface.text.DocumentRewriteSessionType;
22
import org.eclipse.jface.text.IAutoEditStrategy;
23
import org.eclipse.jface.text.IDocument;
24
import org.eclipse.jface.text.IDocumentExtension4;
25
import org.eclipse.jface.text.IRegion;
26
import org.eclipse.jface.text.ITypedRegion;
27
import org.eclipse.jface.text.Region;
28
import org.eclipse.jface.text.TextUtilities;
29
import org.eclipse.ui.IEditorPart;
30
import org.eclipse.ui.IWorkbenchPage;
31
import org.eclipse.ui.IWorkbenchWindow;
32
import org.eclipse.ui.PlatformUI;
33
34
import org.eclipse.cdt.core.CCorePlugin;
35
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
36
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
37
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
38
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
39
import org.eclipse.cdt.core.model.CModelException;
40
import org.eclipse.cdt.core.model.ITranslationUnit;
41
import org.eclipse.cdt.ui.CUIPlugin;
42
import org.eclipse.cdt.ui.IWorkingCopyManager;
43
import org.eclipse.cdt.ui.text.ICPartitions;
44
45
/**
46
 * This class provides default behaviours for multi-line comment auto-editing.
47
 * 
48
 * This class is intended to be sub-classed.
49
 * 
50
 * @since 5.0
51
 */
52
public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrategy {
53
	protected static final String MULTILINE_START = "/*"; //$NON-NLS-1$#
54
	protected static final String MULTILINE_MID = " * "; //$NON-NLS-1$
55
	protected static final String MULTILINE_END = "*/"; //$NON-NLS-1$
56
	
57
	public DefaultMultilineCommentAutoEditStrategy() {
58
	}
59
	
60
	/**
61
	 * @see org.eclipse.jface.text.IAutoEditStrategy#customizeDocumentCommand(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.DocumentCommand)
62
	 */
63
	public void customizeDocumentCommand(IDocument doc, DocumentCommand cmd) {
64
		if(doc instanceof IDocumentExtension4) {
65
			IDocumentExtension4 ext4= (IDocumentExtension4) doc;
66
			DocumentRewriteSession drs= ext4.startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED_SMALL);
67
			try {
68
				if (cmd.length == 0 && cmd.text != null && endsWithDelimiter(doc, cmd.text))
69
					customizeDocumentAfterNewLine(doc, cmd);
70
				else if ("/".equals(cmd.text)) { //$NON-NLS-1$
71
					customizeDocumentForMultilineCommentEnd(doc, cmd);
72
				}
73
			} finally {
74
				ext4.stopRewriteSession(drs);
75
			}
76
		}
77
	}
78
	
79
	/**
80
	 * This implements a rule that when in a multiline comment context typing a forward slash with
81
	 * one white space after the "*" will move eliminate the whitespace.
82
	 * @param doc
83
	 * @param command
84
	 */
85
	protected void customizeDocumentForMultilineCommentEnd(IDocument doc, DocumentCommand command) {
86
		if (command.offset < 2 || doc.getLength() == 0) {
87
			return;
88
		}
89
		try {
90
			if ("* ".equals(doc.get(command.offset - 2, 2))) { //$NON-NLS-1$
91
				// modify document command
92
				command.length++;
93
				command.offset--;
94
			}					
95
		} catch (BadLocationException excp) {
96
			// stop work
97
		}
98
	}
99
	
100
	/**
101
	 * Copies the indentation of the previous line and adds a star.
102
	 * If the comment just started on this line adds also a blank.
103
	 *
104
	 * @param doc the document to work on
105
	 * @param c the command to deal with
106
	 */
107
	public void customizeDocumentAfterNewLine(IDocument doc, final DocumentCommand c) {
108
		int offset= c.offset;
109
		if (offset == -1 || doc.getLength() == 0)
110
			return;
111
		
112
		final StringBuffer buf= new StringBuffer(c.text);
113
		try {
114
			// find start of line
115
			IRegion line= doc.getLineInformationOfOffset(c.offset);
116
			int lineStart= line.getOffset();
117
			int firstNonWS= findEndOfWhiteSpaceAt(doc, lineStart, c.offset);
118
119
			IRegion prefix= findPrefixRange(doc, line);
120
			String indentation= doc.get(prefix.getOffset(), prefix.getLength());
121
			int lengthToAdd= Math.min(offset - prefix.getOffset(), prefix.getLength());
122
			buf.append(indentation.substring(0, lengthToAdd));
123
			
124
			boolean commentAtStart= firstNonWS < c.offset && doc.getChar(firstNonWS) == '/'; 
125
			if (commentAtStart) {
126
				// comment started on this line
127
				buf.append(MULTILINE_MID);
128
			}
129
130
			c.shiftsCaret= false;
131
			c.caretOffset= c.offset + buf.length();
132
133
			if(commentAtStart && shouldCloseMultiline(doc, c.offset)) {
134
				try {
135
					doc.replace(c.offset, 0, indentation+" "+MULTILINE_END); // close the comment in order to parse //$NON-NLS-1$
136
					buf.append("\n"); //$NON-NLS-1$
137
					
138
					// as we are autoclosing, the comment becomes eligable for auto-doc'ing
139
					IASTDeclaration dec= findFollowingDeclaration(getAST(), offset);
140
					if(dec!=null) {
141
						ITypedRegion partition= TextUtilities.getPartition(doc, ICPartitions.C_PARTITIONING /* this! */, offset, false);
142
						StringBuffer content= customizeAfterNewLineForDeclaration(doc, dec, partition);
143
						buf.append(indent(content, indentation + MULTILINE_MID));
144
					}
145
146
				} catch(BadLocationException ble) {
147
					ble.printStackTrace();
148
				}
149
			}
150
151
			c.text= buf.toString();
152
153
		} catch (BadLocationException excp) {
154
			// stop work
155
		}	
156
	}
157
158
	protected StringBuffer customizeAfterNewLineForDeclaration(IDocument doc, IASTDeclaration dec, ITypedRegion region) {
159
		return new StringBuffer();
160
	}
161
	
162
	/*
163
	 * Utilities
164
	 */
165
	
166
	/**
167
	 * Locates the {@link IASTDeclaration} most immediately following the specified offset
168
	 * @param unit the translation unit, or null (in which case the result will also be null)
169
	 * @param offset the offset to begin the search from
170
	 * @return the {@link IASTDeclaration} most immediately following the specified offset, or null if there
171
	 * is no {@link IASTDeclaration}
172
	 */
173
	public static IASTDeclaration findFollowingDeclaration(IASTTranslationUnit unit, final int offset) {
174
		final IASTDeclaration[] dec= new IASTDeclaration[1];
175
		final ASTVisitor av= new ASTVisitor() {
176
			{
177
				shouldVisitTranslationUnit= true;
178
				shouldVisitDeclarations= true;
179
			}
180
			
181
			/**
182
			 * Holds the 
183
			 */
184
			IASTDeclaration stopWhenLeaving;
185
			
186
			public int visit(IASTDeclaration declaration) {
187
				IASTNodeLocation[] locs= declaration.getNodeLocations();
188
				if(locs.length>0) {
189
					for(int i=0; i<locs.length; i++) {
190
						IASTNodeLocation loc= locs[i];
191
192
						int candidateOffset= loc.getNodeOffset();
193
						int candidateEndOffset= candidateOffset+loc.getNodeLength();
194
						
195
						if(offset <= candidateOffset) {
196
							dec[0]= declaration;
197
							return PROCESS_ABORT;
198
						}
199
						
200
						boolean candidateEnclosesOffset= (offset >= candidateOffset) && (offset < candidateEndOffset);
201
						if(candidateEnclosesOffset) {
202
							stopWhenLeaving= declaration;
203
						}
204
					}
205
				}
206
				return PROCESS_CONTINUE;
207
			}
208
			public int leave(IASTDeclaration declaration) {
209
				if(declaration==stopWhenLeaving) 
210
					return PROCESS_ABORT;
211
				return PROCESS_CONTINUE;
212
			}
213
		};
214
		
215
		if(unit!=null) {
216
			unit.accept(av);
217
		}
218
		return dec[0];
219
	}
220
	
221
	/**
222
	 * @return the ast unit for the active editor, or null if there is no active editor, or
223
	 * the ast could not be obtained.
224
	 */
225
	public static IASTTranslationUnit getAST() {
226
		final ITranslationUnit unit= getTranslationUnit();
227
		try {
228
			if(unit!=null) {
229
				IASTTranslationUnit ast= unit.getAST(null, ITranslationUnit.AST_SKIP_ALL_HEADERS);
230
				return ast;
231
			}
232
		} catch(CModelException ce) {
233
			CCorePlugin.log(ce);
234
		} catch(CoreException ce) {
235
			CCorePlugin.log(ce);
236
		}
237
		return null;
238
	}
239
240
	/**
241
	 * Assuming the offset is within a multi-line comment, returns a guess as to
242
	 * whether the enclosing multi-line comment is a new comment. The result is undefined if
243
	 * the offset does not occur within a multi-line comment.
244
	 *
245
	 * @param document the document
246
	 * @param offset the offset
247
	 * @return <code>true</code> if the comment should be closed, <code>false</code> if not
248
	 */
249
	/*
250
	 * Adapted from JDT
251
	 */
252
	public boolean shouldCloseMultiline(IDocument document, int offset) {
253
		try {
254
			IRegion line= document.getLineInformationOfOffset(offset);
255
			ITypedRegion partition= TextUtilities.getPartition(document, ICPartitions.C_PARTITIONING, offset, false);
256
			int partitionEnd= partition.getOffset() + partition.getLength();
257
			if (line.getOffset() >= partitionEnd)
258
				return false;
259
260
			String comment= document.get(partition.getOffset(), partition.getLength());
261
			if (comment.indexOf(MULTILINE_START, offset - partition.getOffset()) != -1) 
262
				return true; // enclosed another comment -> probably a new comment
263
264
			if (document.getLength() == partitionEnd) {
265
				return !comment.endsWith(MULTILINE_END);
266
			}
267
			
268
			return false;
269
270
		} catch (BadLocationException e) {
271
			return false;
272
		}
273
	}
274
275
	/**
276
	 * @return the ITranslationUnit for the active editor, or null if no active
277
	 * editor could be found.
278
	 */
279
	/*
280
	 * Cloned from JDT
281
	 */
282
	protected static ITranslationUnit getTranslationUnit() {
283
		IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
284
		if (window == null)
285
			return null;
286
287
		IWorkbenchPage page= window.getActivePage();
288
		if (page == null)
289
			return null;
290
291
		IEditorPart editor= page.getActiveEditor();
292
		if (editor == null)
293
			return null;
294
295
		IWorkingCopyManager manager= CUIPlugin.getDefault().getWorkingCopyManager();
296
		ITranslationUnit unit= manager.getWorkingCopy(editor.getEditorInput());
297
		if (unit == null)
298
			return null;
299
300
		return unit;
301
	}
302
	
303
	/**
304
	 * Returns a new buffer with the specified indent string inserted at the beginning
305
	 * of each line in the specified input buffer
306
	 * @param buffer
307
	 * @param indent
308
	 */
309
	protected static final StringBuffer indent(StringBuffer buffer, String indent) {
310
		StringBuffer result= new StringBuffer();
311
		BufferedReader br= new BufferedReader(new StringReader(buffer.toString()));
312
		try {
313
			for(String line= br.readLine(); line!=null; line= br.readLine()) {
314
				result.append(indent + line + "\n"); //$NON-NLS-1$
315
			}
316
		} catch(IOException ioe) {
317
			throw new AssertionError(); // we can't get IO errors from a string backed reader
318
		}
319
		return result;
320
	}
321
	
322
	/**
323
	 * Returns the offset of the first non-whitespace character in the specified document, searching
324
	 * right/downward from the specified start offset up to the specified end offset. If there is
325
	 * no nonwhitespace then the end offset is returned.
326
	 * @param document
327
	 * @param offset
328
	 * @param end
329
	 * @throws BadLocationException
330
	 */
331
	protected static int findEndOfWhiteSpaceAt(IDocument document, int offset, int end) throws BadLocationException {
332
		while (offset < end) {
333
			char c= document.getChar(offset);
334
			if (c != ' ' && c != '\t') {
335
				return offset;
336
			}
337
			offset++;
338
		}
339
		return end;
340
	}
341
	
342
	/**
343
	 * Returns the range of the Javadoc prefix on the given line in
344
	 * <code>document</code>. The prefix greedily matches the following regex
345
	 * pattern: <code>\w*\*\w*</code>, that is, any number of whitespace
346
	 * characters, followed by an asterix ('*'), followed by any number of
347
	 * whitespace characters.
348
	 *
349
	 * @param document the document to which <code>line</code> refers
350
	 * @param line the line from which to extract the prefix range
351
	 * @return an <code>IRegion</code> describing the range of the prefix on
352
	 *         the given line
353
	 * @throws BadLocationException if accessing the document fails
354
	 */
355
	protected static IRegion findPrefixRange(IDocument document, IRegion line) throws BadLocationException {
356
		int lineOffset= line.getOffset();
357
		int lineEnd= lineOffset + line.getLength();
358
		int indentEnd= findEndOfWhiteSpaceAt(document, lineOffset, lineEnd);
359
		if (indentEnd < lineEnd && document.getChar(indentEnd) == '*') {
360
			indentEnd++;
361
			while (indentEnd < lineEnd && document.getChar(indentEnd) != ' ')
362
				indentEnd++;
363
			while (indentEnd < lineEnd && document.getChar(indentEnd) == ' ')
364
				indentEnd++;
365
		}
366
		return new Region(lineOffset, indentEnd - lineOffset);
367
	}
368
	
369
	/**
370
	 * Returns whether the text ends with one of the specified IDocument object's
371
	 * legal line delimiters.
372
	 */
373
	protected static boolean endsWithDelimiter(IDocument d, String txt) {
374
		String[] delimiters= d.getLegalLineDelimiters();
375
		for (int i= 0; i < delimiters.length; i++) {
376
			if (txt.endsWith(delimiters[i]))
377
				return true;
378
		}
379
		return false;
380
	}
381
}
(-)src/org/eclipse/cdt/ui/text/ICTokenScanner.java (+23 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.text;
12
13
import org.eclipse.jface.text.rules.ITokenScanner;
14
import org.eclipse.cdt.ui.IPropertyChangeParticipant;
15
16
/**
17
 * Interface for CDT Scanners. Scanners used in CDT must additionally be
18
 * IPropertyChangeParticipant's.
19
 *
20
 * @since 5.0
21
 */
22
public interface ICTokenScanner extends ITokenScanner, IPropertyChangeParticipant {
23
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/docpp/DocppSingleConfiguration.java (+40 lines)
Added Link Here
1
package org.eclipse.cdt.internal.ui.text.doctools.docpp;
2
3
import org.eclipse.jface.text.BadLocationException;
4
import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
5
import org.eclipse.jface.text.IAutoEditStrategy;
6
import org.eclipse.jface.text.IDocument;
7
8
import org.eclipse.cdt.ui.CUIPlugin;
9
import org.eclipse.cdt.ui.text.doctools.generic.AbstractGenericTagDocCommentViewerConfiguration;
10
import org.eclipse.cdt.ui.text.doctools.generic.GenericDocTag;
11
12
public class DocppSingleConfiguration extends AbstractGenericTagDocCommentViewerConfiguration {
13
	GenericDocTag[] tags;
14
	
15
	public DocppSingleConfiguration() {
16
		super(DocppHelper.getDocPPTags(), new char[] {'@','\\'}, DocppHelper.DOCPP_SINGLE_TOKEN, DocppHelper.DOCPP_TAG_RECOGNIZED);
17
	}
18
		
19
	public IAutoEditStrategy createAutoEditStrategy() {
20
		return new DefaultIndentLineAutoEditStrategy();
21
	}
22
	
23
	public boolean isDocumentationComment(IDocument doc, int offset, int length) {
24
		try {
25
			if(offset+2 < doc.getLength()) {
26
				char c= doc.getChar(offset+2);
27
				if(c == '@') {
28
					if(offset + 3 < doc.getLength()) {
29
						char d= doc.getChar(offset+3); 
30
						return d == '{' || d == '}';
31
					}
32
				}
33
				return c == '/';
34
			}
35
		} catch(BadLocationException ble) {
36
			CUIPlugin.getDefault().log(ble);
37
		}
38
		return false;
39
	}
40
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/doxygen/DoxygenMultilineConfiguration.java (+31 lines)
Added Link Here
1
package org.eclipse.cdt.internal.ui.text.doctools.doxygen;
2
3
import org.eclipse.cdt.ui.CUIPlugin;
4
import org.eclipse.cdt.ui.text.doctools.generic.AbstractGenericTagDocCommentViewerConfiguration;
5
6
import org.eclipse.jface.text.BadLocationException;
7
import org.eclipse.jface.text.IAutoEditStrategy;
8
import org.eclipse.jface.text.IDocument;
9
10
public class DoxygenMultilineConfiguration extends AbstractGenericTagDocCommentViewerConfiguration {
11
	
12
	public DoxygenMultilineConfiguration() {
13
		super(DoxygenHelper.getDoxygenTags(), new char[] {'@','\\'}, DoxygenHelper.DOXYGEN_MULTI_TOKEN, DoxygenHelper.DOXYGEN_TAG_RECOGNIZED);
14
	}
15
	
16
	public IAutoEditStrategy createAutoEditStrategy() {
17
		return new DoxygenMultilineAutoEditStrategy();
18
	}
19
	
20
	public boolean isDocumentationComment(IDocument doc, int offset, int length) {
21
		try {
22
			if(offset+2 < doc.getLength()) {
23
				char c= doc.getChar(offset+2);
24
				return c == '*' || c == '!';
25
			}
26
		} catch(BadLocationException ble) {
27
			CUIPlugin.getDefault().log(ble);
28
		}
29
		return false;
30
	}
31
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/NullDocCommentOwner.java (+26 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.text.doctools;
12
13
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
14
15
public final class NullDocCommentOwner extends DocCommentOwner {
16
	private static final String ID = "org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentOwner"; //$NON-NLS-1$
17
	public static final IDocCommentOwner INSTANCE= new NullDocCommentOwner();
18
	private NullDocCommentOwner() {
19
		super(
20
			ID,
21
			Messages.NullDocCommentOwner_Name,
22
			NullDocCommentViewerConfiguration.INSTANCE,
23
			NullDocCommentViewerConfiguration.INSTANCE
24
			);
25
	}
26
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/DocCommentSinglelineProposalComputer.java (+21 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.text.doctools;
12
13
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
14
import org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration;
15
16
17
public class DocCommentSinglelineProposalComputer extends AbstractDocCommentProposalComputer {
18
	protected IDocCommentViewerConfiguration getConfiguration(IDocCommentOwner owner) {
19
		return owner.getSinglelineConfiguration();
20
	}
21
}
(-)src/org/eclipse/cdt/ui/text/ITokenStoreFactory.java (+23 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.text;
12
13
/**
14
 * A means of obtaining ITokenStore objects
15
 * @since 5.0
16
 */
17
public interface ITokenStoreFactory {
18
	/**
19
	 * @param propertyColorNames
20
	 * @return a token store object initialized with the specified propertyColorNames
21
	 */
22
	public ITokenStore createTokenStore(String[] propertyColorNames);
23
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/docpp/DocppMultilineAutoEditStrategy.java (+80 lines)
Added Link Here
1
package org.eclipse.cdt.internal.ui.text.doctools.docpp;
2
3
import org.eclipse.jface.text.IAutoEditStrategy;
4
import org.eclipse.jface.text.IDocument;
5
import org.eclipse.jface.text.ITypedRegion;
6
7
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
8
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
9
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
10
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
11
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
12
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
13
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
14
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
15
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
16
import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy;
17
18
/**
19
 * {@link IAutoEditStrategy} for adding Docpp tags for comments.
20
 */
21
public class DocppMultilineAutoEditStrategy extends DefaultMultilineCommentAutoEditStrategy {
22
	private static final String PARAM = "@param "; //$NON-NLS-1$
23
	private static final String RETURN = "@return\n"; //$NON-NLS-1$
24
25
	protected StringBuffer paramTags(IASTParameterDeclaration[] decls) {
26
		StringBuffer result= new StringBuffer();
27
		for(int i=0; i<decls.length; i++) {
28
			IASTDeclarator dtor= decls[i].getDeclarator();
29
			result.append(PARAM+dtor.getName()+"\n"); //$NON-NLS-1$
30
		}
31
		return result;
32
	}
33
	
34
	protected StringBuffer returnTag() {
35
		return new StringBuffer(RETURN);
36
	}
37
	
38
	protected IASTParameterDeclaration[] getParameterDecls(IASTFunctionDefinition def) {
39
		IASTParameterDeclaration[] result;
40
		IASTFunctionDeclarator decl= def.getDeclarator();
41
		if (decl instanceof IASTStandardFunctionDeclarator) {
42
			IASTStandardFunctionDeclarator standardFunctionDecl= (IASTStandardFunctionDeclarator)decl;
43
			result= standardFunctionDecl.getParameters();
44
		} else /*if (def instanceof ICASTKnRFunctionDeclarator) {
45
			ICASTKnRFunctionDeclarator knrDeclarator= (ICASTKnRFunctionDeclarator)decl;
46
			result= knrDeclarator.getParameterDeclarations();
47
		} else */{
48
			result= new IASTParameterDeclaration[0];
49
		}
50
		return result;
51
	}
52
	
53
	public StringBuffer customizeAfterNewLineForDeclaration(IDocument doc, IASTDeclaration dec, ITypedRegion partition) {
54
		StringBuffer result= new StringBuffer();
55
		
56
		while(dec instanceof ICPPASTTemplateDeclaration) /* if? */
57
			dec= ((ICPPASTTemplateDeclaration)dec).getDeclaration(); 
58
		
59
		if(dec instanceof IASTFunctionDefinition) {
60
			IASTFunctionDefinition fd= (IASTFunctionDefinition) dec;
61
			result.append(paramTags(getParameterDecls(fd)));
62
			
63
			IASTDeclSpecifier ds= fd.getDeclSpecifier();
64
			boolean hasReturn= true;
65
			if(ds instanceof IASTSimpleDeclSpecifier) {
66
				IASTSimpleDeclSpecifier sds= (IASTSimpleDeclSpecifier) ds;
67
				if(sds.getType()==IASTSimpleDeclSpecifier.t_void) {
68
					hasReturn= false;
69
				}
70
			}
71
			if(hasReturn) {
72
				result.append(returnTag());
73
			}
74
			
75
			return result;
76
		}
77
		
78
		return new StringBuffer();
79
	}
80
}
(-)src/org/eclipse/cdt/ui/text/doctools/IDocCommentSimpleDictionary.java (+23 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.text.doctools;
12
13
/**
14
 * This interface is a simplified means of obtaining spelling support. 
15
 * @since 5.0
16
 */
17
public interface IDocCommentSimpleDictionary extends IDocCommentDictionary {
18
	/**
19
	 * @return an array of words that should be regarded as correct. These
20
	 * words will be considered in addition to those provided by existing dictionaries.
21
	 */
22
	public String[] getAdditionalWords();
23
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/Messages.java (+29 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.text.doctools;
12
13
import org.eclipse.osgi.util.NLS;
14
15
public class Messages extends NLS {
16
	private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.text.doctools.messages"; //$NON-NLS-1$
17
	public static String EditorReopener_ReopenJobComplete;
18
	public static String EditorReopener_ReopenJobStart;
19
	public static String EditorReopener_ShouldSave_Message;
20
	public static String EditorReopener_ShouldSave_Title;
21
	public static String NullDocCommentOwner_Name;
22
	static {
23
		// initialize resource bundle
24
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
25
	}
26
27
	private Messages() {
28
	}
29
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/doxygen/DoxygenSingleConfiguration.java (+34 lines)
Added Link Here
1
package org.eclipse.cdt.internal.ui.text.doctools.doxygen;
2
3
import org.eclipse.cdt.ui.CUIPlugin;
4
import org.eclipse.cdt.ui.text.doctools.generic.AbstractGenericTagDocCommentViewerConfiguration;
5
import org.eclipse.cdt.ui.text.doctools.generic.GenericDocTag;
6
7
import org.eclipse.jface.text.BadLocationException;
8
import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
9
import org.eclipse.jface.text.IAutoEditStrategy;
10
import org.eclipse.jface.text.IDocument;
11
12
public class DoxygenSingleConfiguration extends AbstractGenericTagDocCommentViewerConfiguration {
13
	GenericDocTag[] tags;
14
	
15
	public DoxygenSingleConfiguration() {
16
		super(DoxygenHelper.getDoxygenTags(), new char[] {'@','\\'}, DoxygenHelper.DOXYGEN_SINGLE_TOKEN, DoxygenHelper.DOXYGEN_TAG_RECOGNIZED);
17
	}
18
		
19
	public IAutoEditStrategy createAutoEditStrategy() {
20
		return new DefaultIndentLineAutoEditStrategy();
21
	}
22
	
23
	public boolean isDocumentationComment(IDocument doc, int offset, int length) {
24
		try {
25
			if(offset+2 < doc.getLength()) {
26
				char c= doc.getChar(offset+2);
27
				return c == '/' || c == '!';
28
			}
29
		} catch(BadLocationException ble) {
30
			CUIPlugin.getDefault().log(ble);
31
		}
32
		return false;
33
	}
34
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/DocCommentOwnerManager.java (+250 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.text.doctools;
12
13
import java.util.ArrayList;
14
import java.util.HashMap;
15
import java.util.Iterator;
16
import java.util.List;
17
import java.util.Map;
18
19
import org.eclipse.core.resources.IContainer;
20
import org.eclipse.core.resources.IProject;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.resources.ResourcesPlugin;
23
import org.eclipse.core.runtime.Assert;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IConfigurationElement;
26
import org.eclipse.core.runtime.IExtension;
27
import org.eclipse.core.runtime.IExtensionPoint;
28
import org.eclipse.core.runtime.IExtensionRegistry;
29
import org.eclipse.core.runtime.Platform;
30
import org.eclipse.core.runtime.preferences.InstanceScope;
31
import org.osgi.service.prefs.Preferences;
32
33
import org.eclipse.cdt.core.CCorePlugin;
34
import org.eclipse.cdt.ui.CUIPlugin;
35
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
36
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwnershipListener;
37
import org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration;
38
39
/**
40
 * This class manages which IDocCommentOwner's are available in the run-time, and how they map to resources
41
 * in projects.
42
 */
43
public class DocCommentOwnerManager {
44
	/** Constants for attributes/elements from the DocCommentOwner extension point */
45
	private static final String ELEMENT_OWNER = "owner"; //$NON-NLS-1$
46
	private static final String ATTRKEY_OWNER_ID = "id"; //$NON-NLS-1$
47
	private static final String ATTRKEY_OWNER_NAME = "name"; //$NON-NLS-1$
48
	private static final String ATTRKEY_OWNER_SINGLELINE = "singleline"; //$NON-NLS-1$
49
	private static final String ATTRKEY_OWNER_MULTILINE = "multiline"; //$NON-NLS-1$
50
51
	private static final String QUALIFIER= CCorePlugin.PLUGIN_ID;
52
	private static final String WORKSPACE_DOC_TOOL_NODE= "doctool"; //$NON-NLS-1$
53
	private static final String PREFKEY_WORKSPACE_DEFAULT= "workspace.default"; //$NON-NLS-1$
54
	
55
	private static DocCommentOwnerManager singleton;
56
57
	public static DocCommentOwnerManager getInstance() {
58
		return singleton==null ? singleton= new DocCommentOwnerManager() : singleton;
59
	}
60
61
	private Map/*<String, IDocCommentOwner>*/ fOwners;
62
	private IDocCommentOwner fWorkspaceOwner;
63
	private Map prj2map= new HashMap();
64
	private static List fListeners;
65
66
	private DocCommentOwnerManager() {
67
		fOwners= getCommentOwnerExtensions();
68
		fListeners= new ArrayList();
69
70
		Preferences prefs= new InstanceScope().getNode(QUALIFIER).node(WORKSPACE_DOC_TOOL_NODE);
71
		String id= prefs.get(PREFKEY_WORKSPACE_DEFAULT, NullDocCommentOwner.INSTANCE.getID());
72
		fWorkspaceOwner= getOwner(id);
73
		if(fWorkspaceOwner == null) {
74
			// this could occur if a plug-in is no longer available
75
			fWorkspaceOwner= NullDocCommentOwner.INSTANCE;
76
		}
77
	}
78
79
	/**
80
	 * @param project a non-null project
81
	 * @return whether the specified project defines any documentation owner association 
82
	 */
83
	public boolean projectDefinesOwnership(IProject project) {
84
		return !getProjectMap(project).isEmpty();
85
	}
86
87
	/**
88
	 * @param owner the non-null doc-comment owner
89
	 */
90
	public void setWorkspaceCommentOwner(IDocCommentOwner owner) {
91
		if(owner == null)
92
			throw new IllegalArgumentException();
93
		IDocCommentOwner old= fWorkspaceOwner;
94
		fWorkspaceOwner= owner;
95
96
		Preferences prefs= new InstanceScope().getNode(QUALIFIER).node(WORKSPACE_DOC_TOOL_NODE);
97
		prefs.put(PREFKEY_WORKSPACE_DEFAULT, owner.getID());
98
99
		fireWorkspaceOwnershipChanged(old, fWorkspaceOwner);
100
	}
101
102
	/**
103
	 * @return the doc comment owner associated with the workspace. If non
104
	 * is set, the {@link NullDocCommentOwner} is returned.
105
	 */
106
	public IDocCommentOwner getWorkspaceCommentOwner() {
107
		return fWorkspaceOwner;
108
	}
109
110
	/**
111
	 * 
112
	 * @param resource May be null.
113
	 * @return a non-null IDocCommentOwner. If the resource was null, the {@link NullDocCommentOwner} is returned.
114
	 */
115
	public IDocCommentOwner getCommentOwner(IResource resource) {
116
		if(resource==null)
117
			return NullDocCommentOwner.INSTANCE;
118
119
		if(ResourcesPlugin.getWorkspace().getRoot().equals(resource))
120
			return getWorkspaceCommentOwner();
121
122
		ProjectMap pm= getProjectMap(resource);
123
		String ownerID= pm.getOwnerID(resource);
124
		IDocCommentOwner result= getOwner(ownerID);
125
		return result == null ? fWorkspaceOwner : result;
126
	}
127
128
	/**
129
	 * @param id
130
	 * @return the {@link IDocCommentOwner} with the specified id, or null
131
	 */
132
	public IDocCommentOwner getOwner(String id) {
133
		if(NullDocCommentOwner.INSTANCE.getID().equals(id)) {
134
			return NullDocCommentOwner.INSTANCE;
135
		}
136
		return (IDocCommentOwner) fOwners.get(id);
137
	}
138
139
	/**
140
	 * @param resource a non-null resource to map a comment owner to
141
	 * @param owner the new owner to assign, or null to inherit the parent's mapping
142
	 * @param removeSubMappings if the resource is an {@link IContainer}, then remove any mappings
143
	 * children have. <em>This is currently unimplemented.</em>
144
	 */
145
	/*
146
	 * Note - this implementation currently ignores removeSubMappings.
147
	 */
148
	public void setCommentOwner(IResource resource, IDocCommentOwner owner, boolean removeSubMappings) {
149
		Assert.isNotNull(resource);
150
151
		if(ResourcesPlugin.getWorkspace().getRoot().equals(resource)) {
152
			setWorkspaceCommentOwner(owner);
153
			return;
154
		}
155
156
		ProjectMap pm= getProjectMap(resource);
157
		IDocCommentOwner old= getCommentOwner(resource);
158
		pm.setCommentOwner(resource, owner);
159
		IDocCommentOwner n3w= getCommentOwner(resource);
160
		fireOwnershipChanged(resource, removeSubMappings, old, n3w);
161
	}
162
163
	/**
164
	 * @return any comment owners registered against the extension point. This does not include
165
	 * the null comment processor.
166
	 */
167
	public IDocCommentOwner[] getRegisteredOwners() {
168
		return (IDocCommentOwner[]) fOwners.values().toArray(new IDocCommentOwner[fOwners.values().size()]);
169
	}
170
171
172
	/**
173
	 * @param listener registers a listener for doc-comment ownership events
174
	 */
175
	public void addListener(IDocCommentOwnershipListener listener) {
176
		if(!fListeners.contains(listener)) {
177
			fListeners.add(listener);
178
		}
179
	}
180
181
	/**
182
	 * @param listener removes a listener from those registered for doc-comment ownership events
183
	 */
184
	public void removeListener(IDocCommentOwnershipListener listener) {
185
		fListeners.add(listener);
186
	}
187
188
	/*
189
	 * Utilities
190
	 */
191
192
	/**
193
	 * @param resource a non-null resource
194
	 * @return the cached (or newly obtained) ProjectMap for the resources
195
	 * associated project.
196
	 */
197
	private ProjectMap getProjectMap(IResource resource) {
198
		Assert.isNotNull(resource);
199
		IProject project= resource.getProject();
200
201
		if(!prj2map.containsKey(project)) {
202
			prj2map.put(project, new ProjectMap(project));
203
		}
204
205
		return (ProjectMap) prj2map.get(project);
206
	}
207
208
	/**
209
	 * @return a map of ID to {@link IDocCommentOwner} for comment owners registered
210
	 * via the DocCommentOwner extension point
211
	 */
212
	private static Map getCommentOwnerExtensions() {
213
		Map result= new HashMap();
214
215
		IExtensionRegistry registry = Platform.getExtensionRegistry();
216
		IExtensionPoint indexProviders = registry.getExtensionPoint(CUIPlugin.ID_COMMENT_OWNER);
217
		IExtension[] extensions = indexProviders.getExtensions();
218
		for(int i=0; i<extensions.length; i++) {
219
			IExtension extension = extensions[i];
220
			try {
221
				IConfigurationElement[] ce = extension.getConfigurationElements();
222
				for(int j=0; j<ce.length; j++) {
223
					if(ce[j].getName().equals(ELEMENT_OWNER)) { 
224
						IDocCommentViewerConfiguration multi = (IDocCommentViewerConfiguration) ce[j].createExecutableExtension(ATTRKEY_OWNER_MULTILINE);
225
						IDocCommentViewerConfiguration single = (IDocCommentViewerConfiguration) ce[j].createExecutableExtension(ATTRKEY_OWNER_SINGLELINE);
226
						String id= ce[j].getAttribute(ATTRKEY_OWNER_ID);
227
						String name= ce[j].getAttribute(ATTRKEY_OWNER_NAME);
228
						result.put(id, new DocCommentOwner(id, name, multi, single));						
229
					}
230
				}
231
			} catch(CoreException ce) {
232
				CCorePlugin.log(ce);
233
			}
234
		}
235
236
		return result;
237
	}
238
239
	private void fireOwnershipChanged(IResource resource, boolean recursive, IDocCommentOwner old, IDocCommentOwner n3w) {
240
		for(Iterator i= fListeners.iterator(); i.hasNext();) {
241
			((IDocCommentOwnershipListener)i.next()).ownershipChanged(resource, recursive, old, n3w);
242
		}
243
	}
244
245
	private void fireWorkspaceOwnershipChanged(IDocCommentOwner old, IDocCommentOwner n3w) {
246
		for(Iterator i= fListeners.iterator(); i.hasNext();) {
247
			((IDocCommentOwnershipListener)i.next()).workspaceOwnershipChanged(old, n3w);
248
		}
249
	}
250
}
(-)src/org/eclipse/cdt/ui/text/ITokenStore.java (+67 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.text;
12
13
import org.eclipse.jface.preference.IPreferenceStore;
14
import org.eclipse.jface.text.rules.IToken;
15
16
import org.eclipse.cdt.ui.IPropertyChangeParticipant;
17
import org.eclipse.cdt.ui.PreferenceConstants;
18
19
/**
20
 * An ITokenStore manages a set of tokens for a specified set of color property identifiers. Responsibilities include
21
 * <ul>
22
 * <li> Reacting to changes to preferences in a specified {@link IPreferenceStore}
23
 * <li> Managing whether further styles (bold, italic, strikethrough, underline) should be applied
24
 * <li> Coping with 
25
 * </ul>
26
 * 
27
 * ITokenStore assumes style preferences are stored under the following names
28
 * <p>
29
 * Preference color key + {@link PreferenceConstants#EDITOR_BOLD_SUFFIX} are used
30
 * to retrieve whether the token is rendered in bold.
31
 * </p>
32
 * <p>
33
 * Preference color key + {@link PreferenceConstants#EDITOR_ITALIC_SUFFIX} are used
34
 * to retrieve whether the token is rendered in italic.
35
 * </p>
36
 * <p>
37
 * Preference color key + {@link PreferenceConstants#EDITOR_STRIKETHROUGH_SUFFIX} are used
38
 * to retrieve whether the token is rendered in strikethrough.
39
 * </p>
40
 * <p>
41
 * Preference color key + {@link PreferenceConstants#EDITOR_UNDERLINE_SUFFIX} are used
42
 * to retrieve whether the token is rendered in underline.
43
 * </p>
44
 *
45
 * @see ITokenStoreFactory
46
 * @since 5.0
47
 */
48
public interface ITokenStore extends IPropertyChangeParticipant {
49
	/**
50
	 * Ensures any IToken objects that will be <em>or have been</em> returned are
51
     * initialized for display.
52
	 */
53
	void ensureTokensInitialised();
54
	
55
	/**
56
	 * @param property
57
	 * @return a token for the specified property. The Token may not be suitable for use if the
58
	 * current Display is null. Clients should call ITokenStoreFactory#ensureTokensInitialised() at the
59
	 * point of token use. // TODO - I've not yet determined when this is necessary
60
	 */
61
	IToken getToken(String property);
62
	
63
	/**
64
	 * @return The preference store used to read token styling preferences from.
65
	 */
66
	IPreferenceStore getPreferenceStore();
67
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/DocCommentOwner.java (+61 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.text.doctools;
12
13
import org.eclipse.core.runtime.Assert;
14
15
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
16
import org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration;
17
18
/**
19
 * Internal implementation of IDocCommentOwner
20
 */
21
public class DocCommentOwner implements IDocCommentOwner {
22
	private final String id;
23
	private final String name;
24
	private final IDocCommentViewerConfiguration multi, single;
25
	
26
	public DocCommentOwner(String id, String name, IDocCommentViewerConfiguration multi, IDocCommentViewerConfiguration single) {
27
		Assert.isNotNull(id); Assert.isNotNull(name); Assert.isNotNull(multi); Assert.isNotNull(single);
28
		this.id= id;
29
		this.name= name;
30
		this.multi= multi;
31
		this.single= single;
32
	}
33
	
34
	/*
35
	 * @see org.eclipse.cdt.ui.text.ICCommentOwner#getID()
36
	 */
37
	public String getID() {
38
		return id;
39
	}
40
	
41
	/*
42
	 * @see org.eclipse.cdt.ui.text.ICCommentOwner#getName()
43
	 */
44
	public String getName() {
45
		return name;
46
	}
47
	
48
	/*
49
	 * @see org.eclipse.cdt.ui.text.ICCommentOwner#getMultilineConfiguration()
50
	 */
51
	public IDocCommentViewerConfiguration getMultilineConfiguration() {
52
		return multi;
53
	}
54
	
55
	/*
56
	 * @see org.eclipse.cdt.ui.text.ICCommentOwner#getSinglelineConfiguration()
57
	 */
58
	public IDocCommentViewerConfiguration getSinglelineConfiguration() {
59
		return single;
60
	}
61
}
(-)src/org/eclipse/cdt/ui/IPropertyChangeParticipant.java (+35 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial Implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui;
12
13
import org.eclipse.jface.util.PropertyChangeEvent;
14
15
/**
16
 * Implemented by classes which can optionally participate in property
17
 * change events, and report whether an event would affect them without
18
 * adapting to it.
19
 * 
20
 * @since 5.0
21
 */
22
public interface IPropertyChangeParticipant {
23
	/**
24
	 * @param event
25
	 * @return true if the specified event will affect the participant's
26
	 * behaviour in a way it determines potential clients could act upon.
27
	 */
28
	public boolean affectsBehavior(PropertyChangeEvent event);
29
	
30
	/**
31
	 * Performs any necessary to adapt the participant to the specified event.
32
	 * @param event
33
	 */
34
	public void adaptToPreferenceChange(PropertyChangeEvent event);
35
}
(-)src/org/eclipse/cdt/ui/text/doctools/IDocCommentOwner.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.text.doctools;
12
13
/**
14
 * A comment owner provides {@link IDocCommentViewerConfiguration} ov
15
 * the CDT c/c++ editor.
16
 * 
17
 * This interface is not intended to be implemented externally to CDT.
18
 * @since 5.0
19
 */
20
public interface IDocCommentOwner {
21
	/**
22
	 * @return the non-null unique identifier for this comment owner. If contributed via the
23
	 * extension point, the ID corresponds to that in plugin.xml. 
24
	 */
25
	String getID();
26
	
27
	/**
28
	 * @return a non-null human-readable name for this comment owner. If contributed via plugin.xml
29
	 * this name can be localized using the plug-in externalization mechanism.
30
	 */
31
	String getName();
32
33
	/**
34
	 * @return a non-null {@link IDocCommentViewerConfiguration} suitable for a multi-line comment context
35
	 */
36
	IDocCommentViewerConfiguration getMultilineConfiguration();
37
	
38
	/**
39
	 * @return a non-null {@link IDocCommentViewerConfiguration} suitable for a single-line comment context
40
	 */
41
	IDocCommentViewerConfiguration getSinglelineConfiguration();
42
}
(-)src/org/eclipse/cdt/ui/text/doctools/IDocCommentOwnershipListener.java (+37 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.text.doctools;
12
13
import org.eclipse.core.resources.IResource;
14
15
16
/**
17
 * Implemented by clients interested in documentation comment ownership change events. These are generated
18
 * when the association between resource or workspace and documentation comment owner is set.
19
 * @since 5.0
20
 */
21
public interface IDocCommentOwnershipListener {
22
	/**
23
	 * Called when document comment ownership has changed.
24
	 * @param resource
25
	 * @param submappingsRemoved
26
	 * @param old
27
	 * @param newOwner
28
	 */
29
	public void ownershipChanged(IResource resource, boolean submappingsRemoved, IDocCommentOwner old, IDocCommentOwner newOwner);
30
	
31
	/**
32
	 * TODO 
33
	 * @param old
34
	 * @param newOwner
35
	 */
36
	public void workspaceOwnershipChanged(IDocCommentOwner old, IDocCommentOwner newOwner);
37
}
(-)src/org/eclipse/cdt/ui/text/doctools/generic/GenericTagCommentScanner.java (+120 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.text.doctools.generic;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
import org.eclipse.core.runtime.Assert;
17
import org.eclipse.core.runtime.Preferences;
18
import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
19
import org.eclipse.jface.text.rules.IRule;
20
import org.eclipse.jface.text.rules.IToken;
21
import org.eclipse.jface.text.rules.IWordDetector;
22
import org.eclipse.jface.text.rules.WordRule;
23
import org.eclipse.jface.util.PropertyChangeEvent;
24
25
import org.eclipse.cdt.ui.PreferenceConstants;
26
import org.eclipse.cdt.ui.text.ICTokenScanner;
27
import org.eclipse.cdt.ui.text.ITokenStore;
28
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
29
import org.eclipse.cdt.ui.text.TaskTagRule;
30
31
/**
32
 * ICTokenScanner which recognizes a specified set of tags, starting with a specified name
33
 */
34
public class GenericTagCommentScanner extends BufferedRuleBasedScanner implements ICTokenScanner {
35
	private TaskTagRule fTaskTagRule;
36
	private Preferences fCorePreferenceStore;
37
	private String fDefaultTokenProperty;
38
	private String fTagToken;
39
	
40
	private GenericDocTag[] fTags;
41
	private char[] fTagMarkers;
42
	private ITokenStore fTokenStore;
43
	
44
	private static String[] mkArray(String defaultTokenProperty, String tagToken) {
45
		return new String[] { defaultTokenProperty, tagToken, PreferenceConstants.EDITOR_TASK_TAG_COLOR };
46
	}
47
	
48
	/**
49
	 * @param tokenStoreFactory
50
	 * @param docToken
51
	 * @param tagToken
52
	 * @param tags
53
	 * @param tagMarkers
54
	 */
55
	public GenericTagCommentScanner(ITokenStoreFactory tokenStoreFactory, String docToken, String tagToken, GenericDocTag[] tags, char[] tagMarkers) {
56
		Assert.isNotNull(tags);
57
		fTags= tags;
58
		fTagMarkers= tagMarkers;
59
		fTagToken= tagToken;
60
		
61
		fTokenStore= tokenStoreFactory.createTokenStore(mkArray(docToken, tagToken));
62
		fCorePreferenceStore= null; // TODO
63
		fDefaultTokenProperty= docToken;
64
		
65
		setRules(createRules());
66
	}
67
68
	public IToken nextToken() {
69
		fTokenStore.ensureTokensInitialised();
70
		return super.nextToken();
71
	}
72
	
73
	protected IRule[] createRules() {
74
		List result= new ArrayList();
75
76
		class TagDetector implements IWordDetector {
77
			public boolean isWordStart(char c) {
78
				return c == '@' || c == '\\';
79
			}
80
			public boolean isWordPart(char c) {
81
				return c == '.' || Character.isJavaIdentifierPart(c);
82
			}
83
		}
84
85
		WordRule wr= new WordRule(new TagDetector(), fTokenStore.getToken(fDefaultTokenProperty));
86
		for(int i=0; i<fTags.length; i++) {
87
			String wd= fTags[i].getTagName();
88
			for(int j=0; j<fTagMarkers.length; j++) {
89
				wr.addWord(fTagMarkers[j]+wd, fTokenStore.getToken(fTagToken));
90
			}
91
		}
92
		result.add(wr);
93
94
		// Add rule for Task Tags.
95
		String taskWords= TaskTagRule.getTaskWords(fTokenStore.getPreferenceStore(), fCorePreferenceStore);
96
		fTaskTagRule= new TaskTagRule(fTokenStore.getToken(PreferenceConstants.EDITOR_TASK_TAG_COLOR), taskWords);
97
		result.add(fTaskTagRule);
98
99
		setDefaultReturnToken(fTokenStore.getToken(fDefaultTokenProperty));
100
101
		return (IRule[]) result.toArray(new IRule[result.size()]);
102
	}
103
104
	/*
105
	 * @see org.eclipse.cdt.internal.ui.text.AbstractJavaScanner#affectsBehavior(org.eclipse.jface.util.PropertyChangeEvent)
106
	 */
107
	public boolean affectsBehavior(PropertyChangeEvent event) {
108
		return fTaskTagRule.affectsBehavior(event) || fTokenStore.affectsBehavior(event);
109
	}
110
111
	/*
112
	 * @see org.eclipse.cdt.internal.ui.text.AbstractJavaScanner#adaptToPreferenceChange(org.eclipse.jface.util.PropertyChangeEvent)
113
	 */
114
	public void adaptToPreferenceChange(PropertyChangeEvent event) {
115
		if (fTokenStore.affectsBehavior(event)) {
116
			fTokenStore.adaptToPreferenceChange(event);
117
		}
118
		fTaskTagRule.adaptToPreferenceChange(event);
119
	}
120
}
(-)src/org/eclipse/cdt/ui/text/doctools/generic/GenericDocTag.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.text.doctools.generic;
12
13
/**
14
 * Record class for a generic documentation tool tag
15
 */
16
public class GenericDocTag {
17
	private final String name, description;
18
	
19
	/**
20
	 * Create a tag
21
	 * @param name
22
	 * @param description
23
	 */
24
	public GenericDocTag(String name, String description) {
25
		this.name= name;
26
		this.description= description;
27
	}
28
	
29
	/**
30
	 * @return the tag name (without any prefix i.e. no at or backslash)
31
	 */
32
	public String getTagName() {
33
		return name;
34
	}
35
	
36
	/**
37
	 * @return a human readable description of the tag. May be null.
38
	 */
39
	public String getTagDescription() {
40
		return description;
41
	}
42
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/AbstractDocCommentProposalComputer.java (+88 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.text.doctools;
12
13
import java.util.List;
14
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.ui.IEditorPart;
18
import org.eclipse.ui.IWorkbenchPage;
19
import org.eclipse.ui.IWorkbenchWindow;
20
import org.eclipse.ui.PlatformUI;
21
22
import org.eclipse.cdt.core.model.ITranslationUnit;
23
import org.eclipse.cdt.ui.CUIPlugin;
24
import org.eclipse.cdt.ui.IWorkingCopyManager;
25
import org.eclipse.cdt.ui.text.contentassist.ContentAssistInvocationContext;
26
import org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer;
27
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
28
import org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration;
29
30
31
abstract class AbstractDocCommentProposalComputer implements ICompletionProposalComputer {
32
	
33
	protected abstract IDocCommentViewerConfiguration getConfiguration(IDocCommentOwner owner);
34
	
35
	protected final IDocCommentViewerConfiguration getConfiguration() {
36
		IResource resource= getResource();
37
		IDocCommentOwner owner= DocCommentOwnerManager.getInstance().getCommentOwner(resource);
38
		return getConfiguration(owner);
39
	}
40
	
41
	public List computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
42
		return getConfiguration().createProposalComputer().computeCompletionProposals(context, monitor);
43
	}
44
45
	public List computeContextInformation(
46
			ContentAssistInvocationContext context, IProgressMonitor monitor) {
47
		return getConfiguration().createProposalComputer().computeContextInformation(context, monitor);
48
	}
49
50
	public String getErrorMessage() {
51
		return getConfiguration().createProposalComputer().getErrorMessage();
52
	}
53
54
	public void sessionEnded() {
55
		// XXX
56
	}
57
58
	public void sessionStarted() {
59
		// XXX
60
	}
61
	
62
	
63
	private static IResource getResource() {
64
		ITranslationUnit tu= getTranslationUnit();
65
		return tu.getResource();
66
	}
67
	
68
	private static ITranslationUnit getTranslationUnit() {
69
		IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
70
		if (window == null)
71
			return null;
72
73
		IWorkbenchPage page= window.getActivePage();
74
		if (page == null)
75
			return null;
76
77
		IEditorPart editor= page.getActiveEditor();
78
		if (editor == null)
79
			return null;
80
81
		IWorkingCopyManager manager= CUIPlugin.getDefault().getWorkingCopyManager();
82
		ITranslationUnit unit= manager.getWorkingCopy(editor.getEditorInput());
83
		if (unit == null)
84
			return null;
85
86
		return unit;
87
	}
88
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/ProjectMap.java (+178 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.text.doctools;
12
13
import java.util.HashMap;
14
import java.util.Iterator;
15
import java.util.Map;
16
17
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.resources.ResourcesPlugin;
20
import org.eclipse.core.runtime.Assert;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.Path;
24
import org.w3c.dom.Element;
25
import org.w3c.dom.Node;
26
import org.w3c.dom.NodeList;
27
28
import org.eclipse.cdt.core.CCorePlugin;
29
import org.eclipse.cdt.core.ICDescriptor;
30
import org.eclipse.cdt.ui.CUIPlugin;
31
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
32
33
/**
34
 * A ProjectMap is an internal abstraction which
35
 * <ul>
36
 * <li>Maintains mappings from project relative paths to comment-owner ID's
37
 * <li>Manages persistence of these mappings to the .cproject file.
38
 * </ul>
39
 * for a particular {@link IProject}
40
 * 
41
 * @since 5.0
42
 */
43
class ProjectMap {
44
	/** .cproject xml element/attribute names **/
45
	private static final String ATTRVAL_STORAGEID= "org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"; //$NON-NLS-1$
46
	private static final String ELEMENT_DOC_COMMENT_OWNER = "doc-comment-owner"; //$NON-NLS-1$
47
	private static final String ATTRKEY_DCO_ID = "id"; //$NON-NLS-1$
48
	private static final String ELEMENT_PATH = "path"; //$NON-NLS-1$
49
	private static final String ATTRKEY_PATH_VALUE = "value"; //$NON-NLS-1$
50
	
51
	private IProject fProject;
52
	private Map/*<IPath, String>*/ fMap;
53
	
54
	/**
55
	 * Loads the project map
56
	 * @param project
57
	 */
58
	public ProjectMap(IProject project) {
59
		try {
60
			fMap= load(project);
61
		} catch(CoreException ce) {
62
			CUIPlugin.getDefault().log(ce);
63
			fMap= new HashMap();
64
		}
65
		fProject= project;
66
	}
67
	
68
	/**
69
	 * Returns the id of the doc comment owner mapped to the resource specified, or null
70
	 * if no owner is mapped within this project. Ownership is inherited from parents and
71
	 *  may be overridden. 
72
	 * @param resource
73
	 * @return possibly null
74
	 */
75
	public String getOwnerID(IResource resource) {
76
		String id= null;
77
		if(resource!=null) {
78
			for(IPath p= resource.getProjectRelativePath(); ; p= p.removeLastSegments(1)) {
79
				if(fMap.containsKey(p)) {
80
					id= (String) fMap.get(p);
81
					break;
82
				}
83
				if(p.isEmpty())
84
					break;
85
			}
86
		}
87
		return id;
88
	}
89
90
	/**
91
	 * Creates a new (or updates the existing) mapping associating the specified
92
	 * {@link IDocCommentOwner} with the specified {@link IResource}
93
	 * @param resource the non-null resource to create an association for
94
	 * @param owner the owner to associate the resource with, or <code>null</code> to ensure there
95
	 * is no association.
96
	 */
97
	public void setCommentOwner(IResource resource, IDocCommentOwner owner) {
98
		Assert.isNotNull(resource);
99
		if(ResourcesPlugin.getWorkspace().getRoot().equals(resource))
100
			throw new IllegalStateException();
101
		if(owner!=null) {
102
			fMap.put(resource.getProjectRelativePath(), owner.getID());
103
		} else {
104
			fMap.remove(resource.getProjectRelativePath());
105
		}
106
		try {
107
			save();
108
		} catch(CoreException ce) {
109
			CUIPlugin.getDefault().log(ce);
110
		}
111
	}
112
113
	public boolean isEmpty() {
114
		return fMap.isEmpty();
115
	}
116
	
117
	private static Map load(IProject project) throws CoreException {
118
		Map result= new HashMap();
119
		ICDescriptor pd= CCorePlugin.getDefault().getCProjectDescription(project, true);
120
		Element e= pd.getProjectData(ATTRVAL_STORAGEID);
121
		if(e.hasChildNodes()) {
122
			NodeList commentOwners= e.getElementsByTagName(ELEMENT_DOC_COMMENT_OWNER);
123
			for(int i=0; i<commentOwners.getLength(); i++) {
124
				Element node= (Element) commentOwners.item(i);
125
				Node commentOwnerIDNode= node.getAttributes().getNamedItem(ATTRKEY_DCO_ID);
126
127
				if(commentOwnerIDNode != null) {
128
					String commentOwnerID= commentOwnerIDNode.getNodeValue();
129
130
					NodeList paths= node.getElementsByTagName(ELEMENT_PATH);
131
					for(int j=0; j<paths.getLength(); j++) {
132
						Node path= paths.item(i);
133
						Node pathValue= path.getAttributes().getNamedItem(ATTRKEY_PATH_VALUE);
134
						if(pathValue != null) {
135
							result.put(Path.fromPortableString(pathValue.getNodeValue()), commentOwnerID);
136
						}
137
					}
138
				}
139
			}
140
		}
141
		return result;
142
	}
143
144
	/**
145
	 * Write the map to the .cproject file
146
	 */
147
	public void save() throws CoreException {
148
		ICDescriptor pd= CCorePlugin.getDefault().getCProjectDescription(fProject, true);
149
150
		// remove current associations
151
		Element data= pd.getProjectData(ATTRVAL_STORAGEID);
152
		NodeList nl= data.getChildNodes();
153
		for(int i=0; i<nl.getLength(); i++) {
154
			Node node= nl.item(i);
155
			if(node.getNodeType()== Node.ELEMENT_NODE) {
156
				data.removeChild(node);
157
			}
158
		}
159
160
		// invert and persist associations
161
		for(Iterator i= fMap.values().iterator(); i.hasNext();) {
162
			String cid= (String) i.next();
163
			Element commentNode= data.getOwnerDocument().createElement(ELEMENT_DOC_COMMENT_OWNER);
164
			commentNode.setAttribute(ATTRKEY_DCO_ID, cid);
165
			for(Iterator j= fMap.keySet().iterator(); j.hasNext(); ) {
166
				IPath path= (IPath) j.next();
167
				String ccid= (String) fMap.get(path);
168
				if(cid.equals(ccid)) {
169
					Element pathNode= data.getOwnerDocument().createElement(ELEMENT_PATH);
170
					pathNode.setAttribute(ATTRKEY_PATH_VALUE, path.toPortableString());
171
					commentNode.appendChild(pathNode);
172
				}
173
			}
174
			data.appendChild(commentNode);
175
		}
176
		pd.saveProjectData();
177
	}
178
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/doxygen/tags.csv (+116 lines)
Added Link Here
1
a,,
2
addindex,,
3
addtogroup,,
4
anchor,,
5
arg,,
6
attention,,
7
author,,
8
b,,
9
brief,,
10
bug,,
11
c,,
12
callgraph,,
13
callergraph,,
14
category,,
15
class,,
16
code,,
17
cond,,
18
copydoc,,
19
date,,
20
def,,
21
defgroup,,
22
deprecated,,
23
details,,
24
dir,,
25
dontinclude,,
26
dot,,
27
dotfile,,
28
e,,
29
else,,
30
elseif,,
31
em,,
32
endcode,,
33
endcond,,
34
enddot,,
35
endhtmlonly,,
36
endif,,
37
endlatexonly,,
38
endlink,,
39
endmanonly,,
40
endmsc,,
41
endverbatim,,
42
endxmlonly,,
43
enum,,
44
example,,
45
exception,,
46
f$,,
47
f[,,
48
f],,
49
file,,
50
fn,,
51
hideinitializer,,
52
htmlinclude,,
53
htmlonly,,
54
if,,
55
ifnot,,
56
image,,
57
include,,
58
includelineno,,
59
ingroup,,
60
internal,,
61
invariant,,
62
interface,,
63
latexonly,,
64
li,,
65
line,,
66
link,,
67
mainpage,,
68
manonly,,
69
msc,,
70
n,,
71
name,,
72
namespace,,
73
nosubgrouping,,
74
note,,
75
overload,,
76
p,,
77
package,,
78
page,,
79
par,,
80
paragraph,,
81
param,,
82
post,,
83
pre,,
84
property,,
85
protocol,,
86
ref,,
87
relates,,
88
relatesalso,,
89
remarks,,
90
return,,
91
retval,,
92
sa,,
93
section,,
94
see,,
95
showinitializer,,
96
since,,
97
skip,,
98
skipline,,
99
struct,,
100
subpage,,
101
subsection,,
102
subsubsection,,
103
test,,
104
throw,,
105
todo,,
106
typedef,,
107
union,,
108
until,,
109
var,,
110
verbatim,,
111
verbinclude,,
112
version,,
113
warning,,
114
weakgroup,,
115
xmlonly,,
116
xrefitem,,
(-)src/org/eclipse/cdt/ui/text/doctools/generic/GenericTagDoubleClickStrategy.java (+254 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.text.doctools.generic;
12
13
import com.ibm.icu.text.BreakIterator;
14
import java.text.CharacterIterator;
15
16
import org.eclipse.jface.text.BadLocationException;
17
import org.eclipse.jface.text.IDocument;
18
import org.eclipse.jface.text.IRegion;
19
import org.eclipse.jface.text.ITextDoubleClickStrategy;
20
import org.eclipse.jface.text.ITextViewer;
21
import org.eclipse.jface.text.Region;
22
23
/**
24
 * Cloned and tweaked from JDT's javadoc double click strategy
25
 */
26
public class GenericTagDoubleClickStrategy implements ITextDoubleClickStrategy {
27
	protected final char[] fTagMarkers;
28
	
29
	/**
30
	 * A double-click strategy that additionally understands tag markers form part of a
31
	 * selectable word.
32
	 * @param tagMarkers the set of characters to additionally consider part of a word
33
	 */
34
	public GenericTagDoubleClickStrategy(char[] tagMarkers) {
35
		fTagMarkers= new char[tagMarkers.length];
36
		System.arraycopy(tagMarkers, 0, fTagMarkers, 0, tagMarkers.length);
37
	}
38
	
39
	/**
40
	 * Implements a character iterator that works directly on
41
	 * instances of <code>IDocument</code>. Used to collaborate with
42
	 * the break iterator.
43
	 *
44
	 * @see IDocument
45
	 * @since 2.0
46
	 */
47
	static class DocumentCharacterIterator implements CharacterIterator {
48
49
		/** Document to iterate over. */
50
		private IDocument fDocument;
51
		/** Start offset of iteration. */
52
		private int fOffset= -1;
53
		/** End offset of iteration. */
54
		private int fEndOffset= -1;
55
		/** Current offset of iteration. */
56
		private int fIndex= -1;
57
58
		/** Creates a new document iterator. */
59
		public DocumentCharacterIterator() {
60
		}
61
62
		/**
63
		 * Configures this document iterator with the document section to be visited.
64
		 *
65
		 * @param document the document to be iterated
66
		 * @param iteratorRange the range in the document to be iterated
67
		 */
68
		public void setDocument(IDocument document, IRegion iteratorRange) {
69
			fDocument= document;
70
			fOffset= iteratorRange.getOffset();
71
			fEndOffset= fOffset + iteratorRange.getLength();
72
		}
73
74
		/*
75
		 * @see CharacterIterator#first()
76
		 */
77
		public char first() {
78
			fIndex= fOffset;
79
			return current();
80
		}
81
82
		/*
83
		 * @see CharacterIterator#last()
84
		 */
85
		public char last() {
86
			fIndex= fOffset < fEndOffset ? fEndOffset -1 : fEndOffset;
87
			return current();
88
		}
89
90
		/*
91
		 * @see CharacterIterator#current()
92
		 */
93
		public char current() {
94
			if (fOffset <= fIndex && fIndex < fEndOffset) {
95
				try {
96
					return fDocument.getChar(fIndex);
97
				} catch (BadLocationException x) {
98
				}
99
			}
100
			return DONE;
101
		}
102
103
		/*
104
		 * @see CharacterIterator#next()
105
		 */
106
		public char next() {
107
			++fIndex;
108
			int end= getEndIndex();
109
			if (fIndex >= end) {
110
				fIndex= end;
111
				return DONE;
112
			}
113
			return current();
114
		}
115
116
		/*
117
		 * @see CharacterIterator#previous()
118
		 */
119
		public char previous() {
120
			if (fIndex == fOffset)
121
				return DONE;
122
123
			if (fIndex > fOffset)
124
				-- fIndex;
125
126
			return current();
127
		}
128
129
		/*
130
		 * @see CharacterIterator#setIndex(int)
131
		 */
132
		public char setIndex(int index) {
133
			fIndex= index;
134
			return current();
135
		}
136
137
		/*
138
		 * @see CharacterIterator#getBeginIndex()
139
		 */
140
		public int getBeginIndex() {
141
			return fOffset;
142
		}
143
144
		/*
145
		 * @see CharacterIterator#getEndIndex()
146
		 */
147
		public int getEndIndex() {
148
			return fEndOffset;
149
		}
150
151
		/*
152
		 * @see CharacterIterator#getIndex()
153
		 */
154
		public int getIndex() {
155
			return fIndex;
156
		}
157
158
		/*
159
		 * @see CharacterIterator#clone()
160
		 */
161
		public Object clone() {
162
			DocumentCharacterIterator i= new DocumentCharacterIterator();
163
			i.fDocument= fDocument;
164
			i.fIndex= fIndex;
165
			i.fOffset= fOffset;
166
			i.fEndOffset= fEndOffset;
167
			return i;
168
		}
169
	}
170
171
172
	/**
173
	 * The document character iterator used by this strategy.
174
	 * @since 2.0
175
	 */
176
	private DocumentCharacterIterator fDocIter= new DocumentCharacterIterator();
177
178
	/*
179
	 * @see org.eclipse.jface.text.ITextDoubleClickStrategy#doubleClicked(org.eclipse.jface.text.ITextViewer)
180
	 */
181
	public void doubleClicked(ITextViewer text) {
182
183
		int position= text.getSelectedRange().x;
184
185
		if (position < 0)
186
			return;
187
188
		IRegion word= getWordRegion(text.getDocument(), position);
189
190
		if (word != null)
191
			text.setSelectedRange(word.getOffset(), word.getLength());
192
	}
193
194
	/**
195
	 * Returns a region describing the word around <code>position</code>.
196
	 *
197
	 * @param document the document
198
	 * @param position the offset around which to return the word
199
	 * @return the word's region, or <code>null</code> for no selection
200
	 */
201
	private IRegion getWordRegion(IDocument document, int position) {
202
		try {
203
204
			IRegion line= document.getLineInformationOfOffset(position);
205
			if (position == line.getOffset() + line.getLength())
206
				return null;
207
208
			fDocIter.setDocument(document, line);
209
210
			BreakIterator breakIter= BreakIterator.getWordInstance();
211
			breakIter.setText(fDocIter);
212
213
			int start= breakIter.preceding(position);
214
			if (start == BreakIterator.DONE)
215
				start= line.getOffset();
216
217
			int end= breakIter.following(position);
218
			if (end == BreakIterator.DONE)
219
				end= line.getOffset() + line.getLength();
220
221
			if (breakIter.isBoundary(position)) {
222
				if (end - position > position- start)
223
					start= position;
224
				else
225
					end= position;
226
			}
227
228
			if (start > 0 && isTagMarker(document.getChar(start - 1)) && Character.isJavaIdentifierPart(document.getChar(start))
229
					&& (start == 1 || Character.isWhitespace(document.getChar(start - 2)) || document.getChar(start - 2) == '{')) {
230
				// double click after @ident
231
				start--;
232
			} else if (end == position && end == start + 1 && end < line.getOffset() + line.getLength() && document.getChar(end) == '@') {
233
				// double click before " @ident"
234
				return getWordRegion(document, position + 1);
235
			}
236
237
			if (start == end)
238
				return null;
239
			return new Region(start, end - start);
240
241
		} catch (BadLocationException x) {
242
			return null;
243
		}
244
	}
245
246
247
	protected boolean isTagMarker(char c) {
248
		for(int i=0; i<fTagMarkers.length; i++) {
249
			if(c == fTagMarkers[i])
250
				return true;
251
		}
252
		return false;
253
	}
254
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/docpp/DocppMultilineConfiguration.java (+37 lines)
Added Link Here
1
package org.eclipse.cdt.internal.ui.text.doctools.docpp;
2
3
import org.eclipse.jface.text.BadLocationException;
4
import org.eclipse.jface.text.IAutoEditStrategy;
5
import org.eclipse.jface.text.IDocument;
6
7
import org.eclipse.cdt.ui.CUIPlugin;
8
import org.eclipse.cdt.ui.text.doctools.generic.AbstractGenericTagDocCommentViewerConfiguration;
9
10
public class DocppMultilineConfiguration extends AbstractGenericTagDocCommentViewerConfiguration {
11
	
12
	public DocppMultilineConfiguration() {
13
		super(DocppHelper.getDocPPTags(), new char[] {'@','\\'}, DocppHelper.DOCPP_MULTI_TOKEN, DocppHelper.DOCPP_TAG_RECOGNIZED);
14
	}
15
	
16
	public IAutoEditStrategy createAutoEditStrategy() {
17
		return new DocppMultilineAutoEditStrategy();
18
	}
19
	
20
	public boolean isDocumentationComment(IDocument doc, int offset, int length) {
21
		try {
22
			if(offset+2 < doc.getLength()) {
23
				char c= doc.getChar(offset+2);
24
				if(c == '@') {
25
					if(offset + 3 < doc.getLength()) {
26
						char d= doc.getChar(offset+3); 
27
						return d == '{' || d == '}';
28
					}
29
				}
30
				return c == '*';
31
			}
32
		} catch(BadLocationException ble) {
33
			CUIPlugin.getDefault().log(ble);
34
		}
35
		return false;
36
	}
37
}
(-)src/org/eclipse/cdt/ui/text/doctools/IDocCommentViewerConfiguration.java (+67 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.text.doctools;
12
13
import org.eclipse.jface.text.IAutoEditStrategy;
14
import org.eclipse.jface.text.IDocument;
15
import org.eclipse.jface.text.ITextDoubleClickStrategy;
16
17
import org.eclipse.cdt.ui.text.ICPartitions;
18
import org.eclipse.cdt.ui.text.ICTokenScanner;
19
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
20
import org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer;
21
22
/**
23
 * An IDocCommentViewerConfiguration aggregates a collection of editor tools that can be contributed to
24
 * the CDT editor. The tools will be active for CEditor partitions of type {@link ICPartitions#C_MULTI_LINE_DOC_COMMENT} or 
25
 * {@link ICPartitions#C_SINGLE_LINE_DOC_COMMENT} when the {@link IDocCommentOwner} this instance originated from is active.
26
 * 
27
 * @see org.eclipse.jface.text.source.SourceViewerConfiguration (in analogy to)
28
 * @since 5.0
29
 */
30
public interface IDocCommentViewerConfiguration {
31
	/**
32
	 * @param doc the document to examine
33
	 * @param offset the offset of the start of the region (inclusive)
34
	 * @param length the length of the region to examine
35
	 * @return whether the region specified is a documentation comment handled by this viewer configuration
36
	 */
37
	boolean isDocumentationComment(IDocument doc, int offset, int length);
38
	
39
	/**
40
	 * @return a ICTokenScanner for tokenising/coloring the appropriate comment region. May return null.
41
	 */
42
	ICTokenScanner createCommentScanner(ITokenStoreFactory tokenStoreFactory);
43
	
44
	/**
45
	 * @return an auto edit strategy suitable for the appropriate comment region. May return null
46
	 * in the case where no auto-edit-strategy is required.
47
	 */
48
	IAutoEditStrategy createAutoEditStrategy();
49
	
50
	/**
51
	 * @return a double click strategy suitable for the associated comment-region. May return null in
52
	 * the case where no double-click-strategy is required.
53
	 */
54
	ITextDoubleClickStrategy createDoubleClickStrategy();
55
	
56
	/**
57
	 * @return a completion proposal computer suitable for the associated comment-region. May return null in
58
	 * the case where no proposal-computer is required.
59
	 */
60
	ICompletionProposalComputer createProposalComputer();
61
	
62
	/**
63
	 * @return a {@link IDocCommentDictionary} suitable for spell-checking. May return null
64
	 * in the case where no additional dictionary is required.
65
	 */
66
	IDocCommentDictionary getSpellingDictionary();
67
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/doxygen/DoxygenMultilineAutoEditStrategy.java (+158 lines)
Added Link Here
1
package org.eclipse.cdt.internal.ui.text.doctools.doxygen;
2
3
import java.util.ArrayList;
4
import java.util.List;
5
6
import org.eclipse.jface.text.BadLocationException;
7
import org.eclipse.jface.text.IAutoEditStrategy;
8
import org.eclipse.jface.text.IDocument;
9
import org.eclipse.jface.text.IRegion;
10
import org.eclipse.jface.text.ITypedRegion;
11
12
import org.eclipse.cdt.core.CCorePlugin;
13
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
14
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
15
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
16
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
17
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
18
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
19
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
20
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
21
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
22
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
23
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
24
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
25
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
26
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
27
import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy;
28
29
/**
30
 * {@link IAutoEditStrategy} for adding Doxygen tags for comments.
31
 */
32
public class DoxygenMultilineAutoEditStrategy extends DefaultMultilineCommentAutoEditStrategy {
33
	private static final String SINGLELINE_COMMENT_PRECEDING = "//!< "; //$NON-NLS-1$
34
	private static final String PARAM = "@param "; //$NON-NLS-1$
35
	private static final String RETURN = "@return\n"; //$NON-NLS-1$
36
37
	protected StringBuffer paramTags(IASTParameterDeclaration[] decls) {
38
		StringBuffer result= new StringBuffer();
39
		for(int i=0; i<decls.length; i++) {
40
			IASTDeclarator dtor= decls[i].getDeclarator();
41
			result.append(PARAM+dtor.getName()+"\n"); //$NON-NLS-1$
42
		}
43
		return result;
44
	}
45
46
	protected StringBuffer returnTag() {
47
		return new StringBuffer(RETURN);
48
	}
49
50
	protected IASTParameterDeclaration[] getParameterDecls(IASTFunctionDefinition def) {
51
		IASTParameterDeclaration[] result;
52
		IASTFunctionDeclarator decl= def.getDeclarator();
53
		if (decl instanceof IASTStandardFunctionDeclarator) {
54
			IASTStandardFunctionDeclarator standardFunctionDecl= (IASTStandardFunctionDeclarator)decl;
55
			result= standardFunctionDecl.getParameters();
56
		} else /*if (def instanceof ICASTKnRFunctionDeclarator) {
57
			ICASTKnRFunctionDeclarator knrDeclarator= (ICASTKnRFunctionDeclarator)decl;
58
			result= knrDeclarator.getParameterDeclarations();
59
		} else */{
60
			result= new IASTParameterDeclaration[0];
61
		}
62
		return result;
63
	}
64
65
	public StringBuffer customizeAfterNewLineForDeclaration(IDocument doc, IASTDeclaration dec, ITypedRegion partition) {
66
		StringBuffer result= new StringBuffer();
67
68
		while(dec instanceof ICPPASTTemplateDeclaration) /* if? */
69
			dec= ((ICPPASTTemplateDeclaration)dec).getDeclaration(); 
70
71
		if(dec instanceof IASTFunctionDefinition) {
72
			IASTFunctionDefinition fd= (IASTFunctionDefinition) dec;
73
			result.append(paramTags(getParameterDecls(fd)));
74
75
			IASTDeclSpecifier ds= fd.getDeclSpecifier();
76
			boolean hasReturn= true;
77
			if(ds instanceof IASTSimpleDeclSpecifier) {
78
				IASTSimpleDeclSpecifier sds= (IASTSimpleDeclSpecifier) ds;
79
				if(sds.getType()==IASTSimpleDeclSpecifier.t_void) {
80
					hasReturn= false;
81
				}
82
			}
83
			if(hasReturn) {
84
				result.append(returnTag());
85
			}
86
87
			return result;
88
		}
89
90
		if(dec instanceof IASTSimpleDeclaration && ((IASTSimpleDeclaration)dec).getDeclSpecifier() instanceof IASTCompositeTypeSpecifier) {
91
			// result.append("@publishedAll");
92
			return result;
93
		}
94
95
96
		try {
97
			alterDoc(doc, dec);
98
		} catch(BadLocationException ble) {}
99
100
		return new StringBuffer();
101
	}
102
103
	/*
104
	 * Prototype code for adding post-declaration comments to enumerators, after initialiting a doc-comment
105
	 * on an enumeration
106
	 */
107
	private void alterDoc(IDocument doc, IASTDeclaration dec) throws BadLocationException {
108
		if(dec instanceof IASTSimpleDeclaration && ((IASTSimpleDeclaration)dec).getDeclSpecifier() instanceof IASTEnumerationSpecifier) {
109
			IASTEnumerationSpecifier spc= (IASTEnumerationSpecifier)  ((IASTSimpleDeclaration)dec).getDeclSpecifier();
110
			IASTEnumerator[] enms= spc.getEnumerators();
111
112
			class Entry {
113
				final int offset, length;
114
				String comment;
115
				Entry(int offset, int length, String comment) {
116
					this.offset= offset;
117
					this.length= length;
118
					this.comment= comment;
119
				}
120
			}
121
122
			List entries= new ArrayList();
123
			for(int i=0; i<enms.length; i++) {
124
				IASTNodeLocation[] locs= (enms[i].getName().getNodeLocations());
125
				if(locs.length==1) {
126
					int offset2= locs[0].getNodeOffset()+locs[0].getNodeLength();
127
					System.out.println(offset2);
128
					String cmt= SINGLELINE_COMMENT_PRECEDING+enms[i].getName();
129
					IRegion region= doc.getLineInformationOfOffset(offset2);
130
					entries.add(new Entry(region.getOffset(),region.getLength(), cmt));
131
				} else {
132
					// TODO
133
					CCorePlugin.log("TODO"); //$NON-NLS-1$
134
				}
135
			}
136
137
			int max= Integer.MIN_VALUE;
138
			for(int i=0; i<entries.size(); i++) {
139
				Entry e= (Entry) entries.get(i);
140
				if(e.length > max)
141
					max= e.length;
142
			}
143
144
145
			int addedLength2=0;
146
			for(int i=0; i<entries.size(); i++) {
147
				Entry e= (Entry) entries.get(i);
148
				// pad with whitespace
149
				int toAdd= max-e.length;
150
				for(int j=0; j<toAdd; j++) {
151
					e.comment= " "+e.comment; //$NON-NLS-1$
152
				}
153
				doc.replace(e.offset+e.length+addedLength2, 0, e.comment);
154
				addedLength2+= e.comment.length();
155
			}
156
		}
157
	}
158
}
(-)src/org/eclipse/cdt/internal/ui/text/TokenStore.java (+275 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     QNX Software System
11
 *     Andrew Ferguson (Symbian) - refactored to TokenStore (previously part of AbstractCScanner)
12
 *******************************************************************************/
13
package org.eclipse.cdt.internal.ui.text;
14
15
16
import java.util.HashMap;
17
import java.util.Map;
18
19
import org.eclipse.jface.preference.IPreferenceStore;
20
import org.eclipse.jface.preference.PreferenceConverter;
21
import org.eclipse.jface.resource.StringConverter;
22
import org.eclipse.jface.text.TextAttribute;
23
import org.eclipse.jface.text.rules.IToken;
24
import org.eclipse.jface.text.rules.Token;
25
import org.eclipse.jface.util.PropertyChangeEvent;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.graphics.Color;
28
import org.eclipse.swt.graphics.RGB;
29
import org.eclipse.swt.widgets.Display;
30
31
import org.eclipse.cdt.ui.PreferenceConstants;
32
import org.eclipse.cdt.ui.text.ITokenStore;
33
34
35
/**
36
 * Maintains a pool of tokens identified by a String ID.
37
 * Supports styles per token.
38
 * Updates token instances on property changes.
39
 */
40
41
public class TokenStore implements ITokenStore {
42
	private IColorManager fColorManager;
43
	private IPreferenceStore fPreferenceStore;
44
45
	private Map fTokenMap= new HashMap();
46
	private String[] fPropertyNamesColor;
47
48
	private boolean fNeedsLazyColorLoading;
49
	
50
	/**
51
	 * Maintains tokens for a specified set of property keys. Automatically also
52
	 * copes with bold, italic, strikethrough and underlined versions of the key.
53
	 * @param manager the IColorManager to retrieve token colors from
54
	 * @param store the {@link IPreferenceStore} to fetch property preferences from
55
	 */
56
	public TokenStore(IColorManager manager, IPreferenceStore store, String[] propertyNamesColor) {
57
		fColorManager= manager;
58
		fPreferenceStore= store;
59
	
60
		fPropertyNamesColor= propertyNamesColor;
61
62
		fNeedsLazyColorLoading= Display.getCurrent() == null;
63
		for (int i= 0; i < fPropertyNamesColor.length; i++) {			
64
			if(fPropertyNamesColor[i].endsWith(PreferenceConstants.EDITOR_BOLD_SUFFIX)
65
					|| fPropertyNamesColor[i].endsWith(PreferenceConstants.EDITOR_ITALIC_SUFFIX)
66
					|| fPropertyNamesColor[i].endsWith(PreferenceConstants.EDITOR_STRIKETHROUGH_SUFFIX)
67
					|| fPropertyNamesColor[i].endsWith(PreferenceConstants.EDITOR_UNDERLINE_SUFFIX)) {
68
				throw new IllegalArgumentException(); // XXX
69
			}
70
			if (fNeedsLazyColorLoading)
71
				addTokenWithProxyAttribute(fPropertyNamesColor[i]);
72
			else
73
				addToken(fPropertyNamesColor[i]);
74
		}
75
	}
76
	
77
	/**
78
	 * In the case where at the time of IToken construction, the Display was not
79
	 * ready to construct colors. 
80
	 */
81
	public void ensureTokensInitialised() {
82
		if (fNeedsLazyColorLoading && Display.getCurrent() != null) {
83
			for (int i= 0; i < fPropertyNamesColor.length; i++) {
84
				addToken(fPropertyNamesColor[i]);
85
			}
86
			fNeedsLazyColorLoading= false;
87
		}
88
	}
89
90
	private void addTokenWithProxyAttribute(String colorKey) {
91
		fTokenMap.put(colorKey, new Token(createTextAttribute(colorKey, true)));
92
	}
93
94
	private void addToken(String colorKey) {
95
		if (fColorManager != null && colorKey != null && fColorManager.getColor(colorKey) == null) {
96
			RGB rgb= PreferenceConverter.getColor(fPreferenceStore, colorKey);
97
			if (fColorManager instanceof IColorManagerExtension) {
98
				IColorManagerExtension ext= (IColorManagerExtension) fColorManager;
99
				ext.unbindColor(colorKey);
100
				ext.bindColor(colorKey, rgb);
101
			}
102
		}
103
104
		if (!fNeedsLazyColorLoading)
105
			fTokenMap.put(colorKey, new Token(createTextAttribute(colorKey, false)));
106
		else {
107
			Token token= ((Token)fTokenMap.get(colorKey));
108
			if (token != null)
109
				token.setData(createTextAttribute(colorKey, false));
110
		}
111
	}
112
113
	/**
114
	 * Create a text attribute based on the given color, bold, italic, strikethrough and underline preference keys.
115
	 *
116
	 * @param colorKey the color preference key
117
	 * @param boldKey the bold preference key
118
	 * @param italicKey the italic preference key
119
	 * @param strikethroughKey the strikethrough preference key
120
	 * @param underlineKey the italic preference key
121
	 * @return the created text attribute
122
	 * @since 3.0
123
	 */
124
	private TextAttribute createTextAttribute(String colorKey, boolean isNull) {
125
		Color color= null;
126
		if (!isNull)
127
			color= fColorManager.getColor(colorKey);
128
129
		String boldKey= colorKey + PreferenceConstants.EDITOR_BOLD_SUFFIX;
130
		String italicKey= colorKey + PreferenceConstants.EDITOR_ITALIC_SUFFIX;
131
		String strikethroughKey= colorKey + PreferenceConstants.EDITOR_STRIKETHROUGH_SUFFIX;
132
		String underlineKey= colorKey + PreferenceConstants.EDITOR_UNDERLINE_SUFFIX;
133
		
134
		int style= fPreferenceStore.getBoolean(boldKey) ? SWT.BOLD : SWT.NORMAL;
135
		if (fPreferenceStore.getBoolean(italicKey))
136
			style |= SWT.ITALIC;
137
138
		if (fPreferenceStore.getBoolean(strikethroughKey))
139
			style |= TextAttribute.STRIKETHROUGH;
140
141
		if (fPreferenceStore.getBoolean(underlineKey))
142
			style |= TextAttribute.UNDERLINE;
143
144
		return new TextAttribute(color, null, style);
145
	}
146
147
	/*
148
	 * (non-Javadoc)
149
	 * @see org.eclipse.cdt.ui.text.ITokenStore#getToken(java.lang.String)
150
	 */
151
	public IToken getToken(String key) {
152
		return getTokenInner(key);
153
	}
154
	
155
	private Token getTokenInner(String key) {
156
		ensureTokensInitialised();
157
		return (Token) fTokenMap.get(key);
158
	}
159
160
	private int indexOf(String property) {
161
		if (property != null) {
162
			int length= fPropertyNamesColor.length;
163
			for (int i= 0; i < length; i++) {
164
				if (property.startsWith(fPropertyNamesColor[i])) {
165
					int pLength= property.length();
166
					if(fPropertyNamesColor[i].length() < pLength) {
167
						String end= property.substring(fPropertyNamesColor[i].length());
168
						if (end.equals(PreferenceConstants.EDITOR_BOLD_SUFFIX)
169
							|| end.equals(PreferenceConstants.EDITOR_ITALIC_SUFFIX)
170
							|| end.equals(PreferenceConstants.EDITOR_STRIKETHROUGH_SUFFIX)
171
							|| end.equals(PreferenceConstants.EDITOR_UNDERLINE_SUFFIX)) {
172
							return i;						
173
						}
174
					} else if (fPropertyNamesColor[i].equals(property)) {
175
						return i;
176
					}
177
				}
178
			}
179
		}
180
		return -1;
181
	}
182
183
	/*
184
	 * (non-Javadoc)
185
	 * @see org.eclipse.cdt.ui.IPropertyChangeParticipant#affectsBehavior(org.eclipse.jface.util.PropertyChangeEvent)
186
	 */
187
	public boolean affectsBehavior(PropertyChangeEvent event) {
188
		return indexOf(event.getProperty()) >= 0;
189
	}
190
191
	/*
192
	 * (non-Javadoc)
193
	 * @see org.eclipse.cdt.ui.IPropertyChangeParticipant#adaptToPreferenceChange(org.eclipse.jface.util.PropertyChangeEvent)
194
	 */
195
	public void adaptToPreferenceChange(PropertyChangeEvent event) {
196
		String property= event.getProperty();
197
		int i= indexOf(property);
198
		if (property.startsWith(fPropertyNamesColor[i])) {
199
			Token token= getTokenInner(fPropertyNamesColor[i]);
200
			if(property.length() == fPropertyNamesColor[i].length()) {
201
				adaptToColorChange(token, event);
202
			} else {
203
				String end= property.substring(fPropertyNamesColor[i].length());				
204
				if (end.equals(PreferenceConstants.EDITOR_BOLD_SUFFIX)) {
205
					adaptToStyleChange(token, event, SWT.BOLD);
206
				} else if (end.equals(PreferenceConstants.EDITOR_ITALIC_SUFFIX)) {
207
					adaptToStyleChange(token, event, SWT.ITALIC);
208
				} else if (end.equals(PreferenceConstants.EDITOR_STRIKETHROUGH_SUFFIX)) {
209
					adaptToStyleChange(token, event, TextAttribute.STRIKETHROUGH);
210
				} else if (end.equals(PreferenceConstants.EDITOR_UNDERLINE_SUFFIX)) {
211
					adaptToStyleChange(token, event, TextAttribute.UNDERLINE);
212
				}
213
			}
214
		}
215
	}
216
217
	private void adaptToColorChange(Token token, PropertyChangeEvent event) {
218
		RGB rgb= null;
219
220
		Object value= event.getNewValue();
221
		if (value instanceof RGB)
222
			rgb= (RGB) value;
223
		else if (value instanceof String)
224
			rgb= StringConverter.asRGB((String) value);
225
226
		if (rgb != null) {
227
228
			String property= event.getProperty();
229
			Color color= fColorManager.getColor(property);
230
231
			if ((color == null || !rgb.equals(color.getRGB())) && fColorManager instanceof IColorManagerExtension) {
232
				IColorManagerExtension ext= (IColorManagerExtension) fColorManager;
233
234
			 	ext.unbindColor(property);
235
			 	ext.bindColor(property, rgb);
236
237
				color= fColorManager.getColor(property);
238
			}
239
240
			Object data= token.getData();
241
			if (data instanceof TextAttribute) {
242
				TextAttribute oldAttr= (TextAttribute) data;
243
				token.setData(new TextAttribute(color, oldAttr.getBackground(), oldAttr.getStyle()));
244
			}
245
		}
246
	}
247
248
	private void adaptToStyleChange(Token token, PropertyChangeEvent event, int styleAttribute) {
249
		boolean eventValue= false;
250
		Object value= event.getNewValue();
251
		if (value instanceof Boolean)
252
			eventValue= ((Boolean) value).booleanValue();
253
		else if (IPreferenceStore.TRUE.equals(value))
254
			eventValue= true;
255
256
		Object data= token.getData();
257
		if (data instanceof TextAttribute) {
258
			TextAttribute oldAttr= (TextAttribute) data;
259
			boolean activeValue= (oldAttr.getStyle() & styleAttribute) == styleAttribute;
260
			if (activeValue != eventValue)
261
				token.setData(new TextAttribute(oldAttr.getForeground(), oldAttr.getBackground(), eventValue ? oldAttr.getStyle() | styleAttribute : oldAttr.getStyle() & ~styleAttribute));
262
		}
263
	}
264
	
265
	/**
266
	 * Returns the preference store.
267
	 *
268
	 * @return the preference store.
269
	 *
270
	 * @since 3.0
271
	 */
272
	public IPreferenceStore getPreferenceStore() {
273
		return fPreferenceStore;
274
	}
275
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/doxygen/DoxygenHelper.java (+65 lines)
Added Link Here
1
package org.eclipse.cdt.internal.ui.text.doctools.doxygen;
2
import java.io.BufferedReader;
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.io.InputStreamReader;
6
import java.util.ArrayList;
7
import java.util.List;
8
9
import org.eclipse.core.runtime.FileLocator;
10
import org.eclipse.core.runtime.IPath;
11
import org.eclipse.core.runtime.Path;
12
import org.eclipse.jface.preference.IPreferenceStore;
13
import org.eclipse.jface.preference.PreferenceConverter;
14
import org.eclipse.swt.graphics.RGB;
15
16
import org.eclipse.cdt.ui.CUIPlugin;
17
import org.eclipse.cdt.ui.text.doctools.generic.GenericDocTag;
18
19
/**
20
 * Controls the life-cycle of the Doxygen comment editor support
21
 */
22
public class DoxygenHelper {
23
	/*
24
	 * TODO - This is a temporary location
25
	 */
26
	private static final IPath TAGS_CSV= new Path("src/org/eclipse/cdt/internal/ui/text/doctools/doxygen/tags.csv"); //$NON-NLS-1$
27
	
28
	static {
29
		// TODO - I'll find a legitimate place to do this
30
		IPreferenceStore cuis= CUIPlugin.getDefault().getPreferenceStore();
31
		PreferenceConverter.setDefault(cuis, DoxygenHelper.DOXYGEN_MULTI_TOKEN, new RGB(63, 95, 191));
32
		PreferenceConverter.setDefault(cuis, DoxygenHelper.DOXYGEN_SINGLE_TOKEN, new RGB(63, 95, 191));
33
		PreferenceConverter.setDefault(cuis, DoxygenHelper.DOXYGEN_TAG_RECOGNIZED, new RGB(127, 159, 191));
34
	}
35
	
36
	
37
	private static GenericDocTag[] tags;
38
	public static final String DOXYGEN_TAG_RECOGNIZED= "org.eclipse.cdt.internal.ui.text.doctools.doxygen.recognizedTag"; //$NON-NLS-1$
39
	public static final String DOXYGEN_SINGLE_TOKEN= "org.eclipse.cdt.internal.ui.text.doctools.doxygen.single"; //$NON-NLS-1$
40
	public static final String DOXYGEN_MULTI_TOKEN= "org.eclipse.cdt.internal.ui.text.doctools.doxygen.multi"; //$NON-NLS-1$
41
	
42
	public static GenericDocTag[] getDoxygenTags() {
43
		if(tags==null) {
44
			try {
45
				List temp= new ArrayList();
46
				InputStream is= FileLocator.openStream(CUIPlugin.getDefault().getBundle(), TAGS_CSV, false);
47
				BufferedReader br= new BufferedReader(new InputStreamReader(is));
48
				StringBuffer content= new StringBuffer();
49
				for(String line= br.readLine(); line!=null; line= br.readLine()) {
50
					content.append(line+"\n"); //$NON-NLS-1$
51
				}
52
				String[] values= content.toString().split("(\\s)*,(\\s)*"); //$NON-NLS-1$
53
				
54
				for(int i=0; i+1<values.length; i+=2) {
55
					temp.add(new GenericDocTag(values[i], values[i+1]));
56
				}
57
				tags= (GenericDocTag[]) temp.toArray(new GenericDocTag[temp.size()]);
58
			} catch(IOException ioe) {
59
				
60
			}
61
				
62
		}
63
		return tags;
64
	}
65
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/EditorReopener.java (+179 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.text.doctools;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.NullProgressMonitor;
23
import org.eclipse.core.runtime.Status;
24
import org.eclipse.jface.dialogs.MessageDialog;
25
import org.eclipse.swt.widgets.Shell;
26
import org.eclipse.ui.IEditorInput;
27
import org.eclipse.ui.IEditorPart;
28
import org.eclipse.ui.IEditorReference;
29
import org.eclipse.ui.IFileEditorInput;
30
import org.eclipse.ui.IWorkbenchWindow;
31
import org.eclipse.ui.PartInitException;
32
import org.eclipse.ui.PlatformUI;
33
import org.eclipse.ui.progress.WorkbenchJob;
34
35
import org.eclipse.cdt.core.CCorePlugin;
36
import org.eclipse.cdt.core.model.CModelException;
37
import org.eclipse.cdt.core.model.CoreModel;
38
import org.eclipse.cdt.core.model.ICElement;
39
import org.eclipse.cdt.ui.CUIPlugin;
40
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
41
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwnershipListener;
42
43
import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput;
44
import org.eclipse.cdt.internal.ui.util.EditorUtility;
45
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
46
47
/**
48
 * Listens to change in doc-comment ownership and reinitializes
49
 * the editors (or a safe superset of) that need reopening.
50
 */
51
public class EditorReopener implements IDocCommentOwnershipListener {
52
53
	/*
54
	 * @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)
55
	 */
56
	public void ownershipChanged(IResource resource, boolean recursive,
57
			IDocCommentOwner old, IDocCommentOwner newOwner) {
58
		IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
59
		if(window!=null) {
60
			try {
61
				IEditorPart[] parts= getEditorsToRepon(window, resource);
62
				if(queryIfNeeded(window.getShell(), parts)) {
63
					reopenEditors(window, parts);
64
				}
65
			} catch(CoreException ce) {
66
				CCorePlugin.log(ce);
67
			}
68
		}
69
	}
70
71
	/*
72
	 * @see org.eclipse.cdt.ui.text.doctools.IDocCommentOwnershipListener#workspaceOwnershipChanged(org.eclipse.cdt.ui.text.doctools.IDocCommentOwner, org.eclipse.cdt.ui.text.doctools.IDocCommentOwner)
73
	 */
74
	public void workspaceOwnershipChanged(IDocCommentOwner old, IDocCommentOwner newOwner) {
75
		IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
76
		if(window!=null) {
77
			try {
78
				IEditorPart[] parts= getEditorsToRepon(window, null);
79
				if(queryIfNeeded(window.getShell(), parts)) {
80
					reopenEditors(window, parts);
81
				}
82
			} catch(CoreException ce) {
83
				CCorePlugin.log(ce);
84
			}
85
		}
86
	}
87
88
	/**
89
	 * @param window
90
	 * @param resource may be null to indicate all CDT editors should be reopened
91
	 * @return an array of {@link IEditorPart} objects that might need to be reinitialized
92
	 * based on doc-comment ownership of the specified resource changing
93
	 */
94
	/*
95
	 * This could be smarter in determining smaller sets of editors to re-open
96
	 */
97
	private IEditorPart[] getEditorsToRepon(IWorkbenchWindow window, IResource resource) {
98
		List needReopening= new ArrayList();
99
		if(window.getActivePage()!=null) {
100
			IEditorReference[] es= window.getActivePage().getEditorReferences();
101
			for(int i=0; i<es.length; i++) {
102
				IEditorPart part= es[i].getEditor(false);
103
				if(part!=null) {
104
					IEditorInput iei= part.getEditorInput();
105
					if(resource!=null) {
106
						if(iei instanceof IFileEditorInput) {
107
							IFile file= ((IFileEditorInput) iei).getFile();
108
							IProject project= resource.getProject();
109
							if(file.getProject().equals(project) && CoreModel.hasCNature(project)) {
110
								needReopening.add(part);
111
							}
112
						}
113
					} else {
114
						if(iei instanceof ITranslationUnitEditorInput) {
115
							needReopening.add(part);
116
						}
117
					}
118
				}
119
			}
120
		}
121
		return (IEditorPart[]) needReopening.toArray(new IEditorPart[needReopening.size()]);
122
	}
123
124
	private boolean queryIfNeeded(Shell shell, IEditorPart[] editorParts) throws CoreException {
125
		boolean anyUnsaved= false;
126
		for(int j=0; j<editorParts.length; j++)
127
			if(editorParts[j].isSaveOnCloseNeeded())
128
				anyUnsaved= true;
129
130
		boolean saveAndReopen= !anyUnsaved;
131
		if(anyUnsaved) {
132
			String title= Messages.EditorReopener_ShouldSave_Title;
133
			String msg= Messages.EditorReopener_ShouldSave_Message; 
134
135
			if (MessageDialog.openQuestion(shell, title, msg))
136
				saveAndReopen= true;
137
		}
138
		return saveAndReopen;
139
	}
140
141
	private void reopenEditors(final IWorkbenchWindow window, final IEditorPart[] editorParts) throws CoreException {
142
		WorkbenchJob job= new WorkbenchJob(Messages.EditorReopener_ReopenJobStart) {
143
			public IStatus runInUIThread(IProgressMonitor monitor) {
144
				IEditorPart oldActive= window.getActivePage().getActiveEditor();
145
				IEditorPart newActive= null;
146
147
				for(int j=0; j<editorParts.length; j++) {
148
					IEditorPart oldPart= editorParts[j];
149
					oldPart.doSave(new NullProgressMonitor());
150
					window.getActivePage().closeEditor(oldPart, false);
151
					IEditorInput oldInput= oldPart.getEditorInput();
152
153
					try {
154
						IEditorPart newPart= null;
155
						if(oldInput instanceof IFileEditorInput) {
156
							newPart= EditorUtility.openInEditor(((IFileEditorInput)oldInput).getFile());
157
						} else if(oldInput instanceof ExternalEditorInput) {
158
							ExternalEditorInput eei= (ExternalEditorInput) oldInput;
159
							ICElement element= CoreModel.getDefault().create(eei.getMarkerResource());
160
							newPart= EditorUtility.openInEditor(eei.getPath(null), element);
161
						}
162
						if(oldPart == oldActive)
163
							newActive= newPart;
164
					} catch(PartInitException pie) {
165
						CCorePlugin.log(pie);
166
					} catch(CModelException cme) {
167
						CCorePlugin.log(cme);
168
					}
169
				}
170
171
				if(newActive != null) {
172
					window.getActivePage().activate(newActive);
173
				}
174
				return new Status(IStatus.OK, CUIPlugin.PLUGIN_ID, Messages.EditorReopener_ReopenJobComplete);
175
			}
176
		};
177
		job.schedule();
178
	}
179
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/docpp/tags.csv (+19 lines)
Added Link Here
1
args,,
2
author,,
3
deprecated,,
4
doc,,
5
exception,,
6
field,,
7
friends,,
8
invariant,,
9
memo,,
10
name,,
11
param,,
12
postcondition,,
13
precondition,,
14
return,,
15
see,,
16
since,,
17
type,,
18
version,,
19
(-)src/org/eclipse/cdt/internal/ui/text/doctools/docpp/DocppHelper.java (+65 lines)
Added Link Here
1
package org.eclipse.cdt.internal.ui.text.doctools.docpp;
2
import java.io.BufferedReader;
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.io.InputStreamReader;
6
import java.util.ArrayList;
7
import java.util.List;
8
9
import org.eclipse.core.runtime.FileLocator;
10
import org.eclipse.core.runtime.IPath;
11
import org.eclipse.core.runtime.Path;
12
import org.eclipse.jface.preference.IPreferenceStore;
13
import org.eclipse.jface.preference.PreferenceConverter;
14
import org.eclipse.swt.graphics.RGB;
15
16
import org.eclipse.cdt.ui.CUIPlugin;
17
import org.eclipse.cdt.ui.text.doctools.generic.GenericDocTag;
18
19
/**
20
 * Controls the life-cycle of the Doxygen comment editor support
21
 */
22
public class DocppHelper {
23
	/*
24
	 * TODO - This is a temporary location
25
	 */
26
	private static final IPath TAGS_CSV= new Path("src/org/eclipse/cdt/internal/ui/text/doctools/docpp/tags.csv"); //$NON-NLS-1$
27
	
28
	static {
29
		// TODO - I'll find a legitimate place to do this
30
		IPreferenceStore cuis= CUIPlugin.getDefault().getPreferenceStore();
31
		PreferenceConverter.setDefault(cuis, DocppHelper.DOCPP_MULTI_TOKEN, new RGB(63, 95, 191));
32
		PreferenceConverter.setDefault(cuis, DocppHelper.DOCPP_SINGLE_TOKEN, new RGB(63, 95, 191));
33
		PreferenceConverter.setDefault(cuis, DocppHelper.DOCPP_TAG_RECOGNIZED, new RGB(127, 159, 191));
34
	}
35
	
36
	
37
	private static GenericDocTag[] tags;
38
	public static final String DOCPP_TAG_RECOGNIZED= "org.eclipse.cdt.internal.ui.text.doctools.doxygen.recognizedTag"; //$NON-NLS-1$
39
	public static final String DOCPP_SINGLE_TOKEN= "org.eclipse.cdt.internal.ui.text.doctools.doxygen.single"; //$NON-NLS-1$
40
	public static final String DOCPP_MULTI_TOKEN= "org.eclipse.cdt.internal.ui.text.doctools.doxygen.multi"; //$NON-NLS-1$
41
	
42
	public static GenericDocTag[] getDocPPTags() {
43
		if(tags==null) {
44
			try {
45
				List temp= new ArrayList();
46
				InputStream is= FileLocator.openStream(CUIPlugin.getDefault().getBundle(), TAGS_CSV, false);
47
				BufferedReader br= new BufferedReader(new InputStreamReader(is));
48
				StringBuffer content= new StringBuffer();
49
				for(String line= br.readLine(); line!=null; line= br.readLine()) {
50
					content.append(line+"\n"); //$NON-NLS-1$
51
				}
52
				String[] values= content.toString().split("(\\s)*,(\\s)*"); //$NON-NLS-1$
53
				
54
				for(int i=0; i+1<values.length; i+=2) {
55
					temp.add(new GenericDocTag(values[i], values[i+1]));
56
				}
57
				tags= (GenericDocTag[]) temp.toArray(new GenericDocTag[temp.size()]);
58
			} catch(IOException ioe) {
59
				
60
			}
61
				
62
		}
63
		return tags;
64
	}
65
}
(-)schema/DocCommentOwner.exsd (+124 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.cdt.ui">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.cdt.ui" id="DocCommentOwner" name="DocCommentOwner"/>
7
      </appInfo>
8
      <documentation>
9
         [Enter description of this extension point.]
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <complexType>
15
         <choice>
16
            <element ref="owner"/>
17
         </choice>
18
         <attribute name="point" type="string" use="required">
19
            <annotation>
20
               <documentation>
21
                  
22
               </documentation>
23
            </annotation>
24
         </attribute>
25
         <attribute name="id" type="string">
26
            <annotation>
27
               <documentation>
28
                  
29
               </documentation>
30
            </annotation>
31
         </attribute>
32
         <attribute name="name" type="string">
33
            <annotation>
34
               <documentation>
35
                  
36
               </documentation>
37
               <appInfo>
38
                  <meta.attribute translatable="true"/>
39
               </appInfo>
40
            </annotation>
41
         </attribute>
42
      </complexType>
43
   </element>
44
45
   <element name="owner">
46
      <complexType>
47
         <attribute name="id" type="string" use="required">
48
            <annotation>
49
               <documentation>
50
                  
51
               </documentation>
52
            </annotation>
53
         </attribute>
54
         <attribute name="name" type="string" use="required">
55
            <annotation>
56
               <documentation>
57
                  
58
               </documentation>
59
               <appInfo>
60
                  <meta.attribute translatable="true"/>
61
               </appInfo>
62
            </annotation>
63
         </attribute>
64
         <attribute name="multiline" type="string" use="required">
65
            <annotation>
66
               <documentation>
67
                  
68
               </documentation>
69
               <appInfo>
70
                  <meta.attribute kind="java" basedOn=":org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration"/>
71
               </appInfo>
72
            </annotation>
73
         </attribute>
74
         <attribute name="singleline" type="string" use="required">
75
            <annotation>
76
               <documentation>
77
                  
78
               </documentation>
79
               <appInfo>
80
                  <meta.attribute kind="java" basedOn=":org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration"/>
81
               </appInfo>
82
            </annotation>
83
         </attribute>
84
      </complexType>
85
   </element>
86
87
   <annotation>
88
      <appInfo>
89
         <meta.section type="since"/>
90
      </appInfo>
91
      <documentation>
92
         5.0
93
      </documentation>
94
   </annotation>
95
96
   <annotation>
97
      <appInfo>
98
         <meta.section type="examples"/>
99
      </appInfo>
100
      <documentation>
101
         [Enter extension point usage example here.]
102
      </documentation>
103
   </annotation>
104
105
   <annotation>
106
      <appInfo>
107
         <meta.section type="apiInfo"/>
108
      </appInfo>
109
      <documentation>
110
         [Enter API information here.]
111
      </documentation>
112
   </annotation>
113
114
   <annotation>
115
      <appInfo>
116
         <meta.section type="implementation"/>
117
      </appInfo>
118
      <documentation>
119
         [Enter information about supplied implementation of this extension point.]
120
      </documentation>
121
   </annotation>
122
123
124
</schema>
(-)src/org/eclipse/cdt/ui/text/doctools/IDocCommentDictionary.java (+20 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.text.doctools;
12
13
/**
14
 * This interface is a place-holder for the future. Clients should implement the most
15
 * appropriate sub-interface (provided by CDT). Currently {@link IDocCommentSimpleDictionary} is
16
 * the only provided sub-interface, but it is expected a more subtle way of integrating spell-checking
17
 * will be available in the future.
18
 * @since 5.0
19
 */
20
public interface IDocCommentDictionary {}
(-)src/org/eclipse/cdt/ui/text/TaskTagRule.java (+119 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Anton Leherbauer (Wind River Systems)
11
 *     Sergey Prigogin  (Google)
12
 *     Andrew Ferguson  (Symbian)
13
 *******************************************************************************/
14
package org.eclipse.cdt.ui.text;
15
16
import org.eclipse.core.runtime.Preferences;
17
import org.eclipse.jface.preference.IPreferenceStore;
18
import org.eclipse.jface.text.rules.IToken;
19
import org.eclipse.jface.text.rules.IWordDetector;
20
import org.eclipse.jface.text.rules.Token;
21
import org.eclipse.jface.text.rules.WordRule;
22
import org.eclipse.jface.util.PropertyChangeEvent;
23
24
import org.eclipse.cdt.core.CCorePreferenceConstants;
25
import org.eclipse.cdt.ui.IPropertyChangeParticipant;
26
27
/**
28
 * 
29
 * Which words should be recognized as task tags is specified under {@link CCorePreferenceConstants#TODO_TASK_TAGS} as a
30
 * comma delimited list.
31
 * 
32
 * @see CCorePreferenceConstants#TODO_TASK_TAGS
33
 * @since 5.0
34
 */
35
public final class TaskTagRule extends WordRule implements IPropertyChangeParticipant {	
36
	private static class TaskTagDetector implements IWordDetector {
37
		public boolean isWordStart(char c) {
38
			return Character.isLetter(c);
39
		}
40
		public boolean isWordPart(char c) {
41
			return Character.isLetter(c);
42
		}
43
	}
44
45
	/**
46
	 * Convenience method for extracting a list of words that should be recognized as 
47
	 * task labels from an {@link IPreferenceStore} and a backup {@link Preferences}
48
	 * @param preferenceStore
49
	 * @param corePreferences
50
	 * @return a list of words that should be recognized as task labels in the format
51
	 * expected by TaskTagRule
52
	 */
53
	public static String getTaskWords(IPreferenceStore preferenceStore, Preferences corePreferences) {
54
		String result= null;
55
		if (preferenceStore.contains(CCorePreferenceConstants.TODO_TASK_TAGS)) {
56
			result= preferenceStore.getString(CCorePreferenceConstants.TODO_TASK_TAGS);
57
		} else if (corePreferences != null) {
58
			result= corePreferences.getString(CCorePreferenceConstants.TODO_TASK_TAGS);
59
		}
60
		return result;
61
	}
62
63
	private IToken fToken;
64
65
	/**
66
	 * Creates a new task tag rule
67
	 * @param token the token to return for words recognized as task tags
68
	 * @param taskWords a comma delimited list of words to recognize as task tags
69
	 */
70
	public TaskTagRule(IToken token, String taskWords) {
71
		super(new TaskTagDetector(), Token.UNDEFINED);
72
		fToken= token;
73
		if( taskWords!= null) {
74
			addTaskTags(taskWords);
75
		}
76
	}
77
78
	/**
79
	 * Removes the current list of words that should be
80
	 * recognized as task tags.
81
	 */
82
	public void clearTaskTags() {
83
		fWords.clear();
84
	}
85
86
	/**
87
	 * Adds tags from the specified string as task tags.
88
	 * @param value a comma delimited list of words to recognize as task tags
89
	 */
90
	public void addTaskTags(String value) {
91
		String[] tasks= value.split(","); //$NON-NLS-1$
92
		for (int i= 0; i < tasks.length; i++) {
93
			if (tasks[i].length() > 0) {
94
				addWord(tasks[i], fToken);
95
			}
96
		}
97
	}
98
99
	/*
100
	 * @see org.eclipse.cdt.ui.IPropertyChangeParticipant#affectsBehavior(org.eclipse.jface.util.PropertyChangeEvent)
101
	 */
102
	public boolean affectsBehavior(PropertyChangeEvent event) {
103
		return event.getProperty().equals(CCorePreferenceConstants.TODO_TASK_TAGS);
104
	}
105
106
	/*
107
	 * @see org.eclipse.cdt.ui.IPropertyChangeParticipant#adaptToPreferenceChange(org.eclipse.jface.util.PropertyChangeEvent)
108
	 */
109
	public void adaptToPreferenceChange(PropertyChangeEvent event) {
110
		if (event.getProperty().equals(CCorePreferenceConstants.TODO_TASK_TAGS)) {
111
			Object value= event.getNewValue();
112
113
			if (value instanceof String) {
114
				clearTaskTags();
115
				addTaskTags((String) value);
116
			}
117
		}
118
	}
119
}
(-)src/org/eclipse/cdt/ui/dialogs/DocCommentOwnerComposite.java (+62 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.dialogs;
12
13
import org.eclipse.jface.layout.GridDataFactory;
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.layout.GridData;
16
import org.eclipse.swt.layout.GridLayout;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Group;
19
import org.eclipse.swt.widgets.Label;
20
21
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
22
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
23
24
public class DocCommentOwnerComposite extends Composite {
25
	protected DocCommentOwnerCombo fDocCombo;
26
	protected Label desc, comboLabel;
27
	protected Group group;
28
	
29
	public DocCommentOwnerComposite(Composite parent, IDocCommentOwner initialOwner, String description, String label) {
30
		super(parent, SWT.NONE);
31
		GridLayout gl= new GridLayout();
32
		gl.marginHeight= gl.marginWidth= 0;
33
		setLayout(gl);
34
		
35
		group = ControlFactory.createGroup(this, DialogsMessages.DocCommentOwnerComposite_DocumentationToolGroupTitle, 2);
36
		group.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
37
		
38
		desc= new Label(group, SWT.WRAP);
39
		GridData gd = GridDataFactory.fillDefaults().grab(false, false).span(2, 1).create();
40
		gd.widthHint= 150;
41
		desc.setText(description);
42
		desc.setLayoutData(gd);
43
		
44
		comboLabel= new Label(group, SWT.NONE);
45
		comboLabel.setText(label);
46
		
47
		fDocCombo= new DocCommentOwnerCombo(group, SWT.NONE, initialOwner) {};
48
		gd = GridDataFactory.fillDefaults().grab(true, false).create();
49
		fDocCombo.setLayoutData(gd);
50
	}
51
	
52
	public IDocCommentOwner getSelectedDocCommentOwner() {
53
		return fDocCombo.getSelectedDocCommentOwner();
54
	}
55
	
56
	public void setEnabled(boolean enabled) {
57
		desc.setEnabled(enabled);
58
		comboLabel.setEnabled(enabled);
59
		fDocCombo.setEnabled(enabled);
60
		group.setEnabled(enabled);
61
	}
62
}
(-)src/org/eclipse/cdt/ui/text/doctools/generic/GenericTagSimpleDictionary.java (+39 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.text.doctools.generic;
12
13
import org.eclipse.cdt.ui.text.doctools.IDocCommentSimpleDictionary;
14
15
/**
16
 * An implementation of a trivial dictionary
17
 */
18
public class GenericTagSimpleDictionary implements IDocCommentSimpleDictionary {
19
	protected String[] fTags;
20
21
	/**
22
	 * @param tagMarkers the characters that may delimit the start of a tag
23
	 * @param tags the tags that should be recognised as correct
24
	 */
25
	public GenericTagSimpleDictionary(char[] tagMarkers, GenericDocTag[] tags) {
26
		fTags= new String[tags.length];
27
28
		for(int j=0; j<tags.length; j++) {
29
			fTags[j]= tags[j].getTagName();
30
		}
31
	}
32
33
	/**
34
	 * 
35
	 */
36
	public String[] getAdditionalWords() {
37
		return fTags;
38
	}
39
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/messages.properties (+5 lines)
Added Link Here
1
EditorReopener_ReopenJobComplete=Re-initializing editors complete
2
EditorReopener_ReopenJobStart=Re-initializing editors
3
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?
4
EditorReopener_ShouldSave_Title=Unsaved editors need reopening
5
NullDocCommentOwner_Name=None
(-)src/org/eclipse/cdt/internal/ui/text/doctools/DocCommentSpellDictionary.java (+56 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.text.doctools;
12
13
import java.net.URL;
14
15
import org.eclipse.core.runtime.Assert;
16
17
import org.eclipse.cdt.ui.text.doctools.IDocCommentSimpleDictionary;
18
19
import org.eclipse.cdt.internal.ui.text.spelling.engine.AbstractSpellDictionary;
20
import org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellDictionary;
21
22
/**
23
 * Adapter from interim public {@link IDocCommentSimpleDictionary} to internal {@link ISpellDictionary}
24
 */
25
public class DocCommentSpellDictionary extends AbstractSpellDictionary {
26
27
	protected IDocCommentSimpleDictionary fDict;
28
	
29
	/**
30
	 * @param dict
31
	 */
32
	public DocCommentSpellDictionary(IDocCommentSimpleDictionary dict) {
33
		Assert.isNotNull(dict);
34
		fDict= dict;
35
	}
36
	
37
	/*
38
	 * @see org.eclipse.cdt.internal.ui.text.spelling.engine.AbstractSpellDictionary#getName()
39
	 */
40
	protected final URL getURL() {
41
		return null;
42
	}
43
44
	/*
45
	 * @see org.eclipse.cdt.ui.text.spelling.engine.AbstractSpellDictionary#load(java.net.URL)
46
	 */
47
	protected synchronized boolean load(final URL url) {
48
		unload();
49
50
		String[] words= fDict.getAdditionalWords();
51
		for(int i=0; i<words.length; i++)
52
			hashWord(words[i]);
53
		
54
		return false;
55
	}
56
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/NullDocCommentViewerConfiguration.java (+52 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.text.doctools;
12
13
import org.eclipse.jface.text.IAutoEditStrategy;
14
import org.eclipse.jface.text.IDocument;
15
import org.eclipse.jface.text.ITextDoubleClickStrategy;
16
17
import org.eclipse.cdt.ui.text.ICTokenScanner;
18
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
19
import org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer;
20
import org.eclipse.cdt.ui.text.doctools.IDocCommentDictionary;
21
import org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration;
22
23
public class NullDocCommentViewerConfiguration implements IDocCommentViewerConfiguration {
24
	public static final IDocCommentViewerConfiguration INSTANCE= new NullDocCommentViewerConfiguration();
25
	
26
	public NullDocCommentViewerConfiguration() {
27
	}
28
	
29
	public IAutoEditStrategy createAutoEditStrategy() {		
30
		return null;
31
	}
32
33
	public ICTokenScanner createCommentScanner(ITokenStoreFactory tokenStoreFactory) {
34
		return null;
35
	}
36
37
	public ITextDoubleClickStrategy createDoubleClickStrategy() {
38
		return null;
39
	}
40
41
	public ICompletionProposalComputer createProposalComputer() {
42
		return null;
43
	}
44
45
	public boolean isDocumentationComment(IDocument doc, int offset, int length) {
46
		return false;
47
	}
48
	
49
	public IDocCommentDictionary getSpellingDictionary() {
50
		return null;
51
	}
52
}
(-)src/org/eclipse/cdt/ui/dialogs/DocCommentOwnerBlock.java (+115 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.dialogs;
12
13
import org.eclipse.core.resources.IProject;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.jface.layout.GridDataFactory;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.events.SelectionAdapter;
19
import org.eclipse.swt.events.SelectionEvent;
20
import org.eclipse.swt.layout.GridData;
21
import org.eclipse.swt.layout.GridLayout;
22
import org.eclipse.swt.widgets.Button;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Link;
25
import org.eclipse.ui.dialogs.PreferencesUtil;
26
27
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
28
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
29
30
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
31
32
/**
33
 * Project property page for setting documentation comment owner.
34
 */
35
public class DocCommentOwnerBlock extends AbstractCOptionPage {
36
	private static String EDITOR_PREF_PAGE_ID= "org.eclipse.cdt.ui.preferences.CEditorPreferencePage"; //$NON-NLS-1$
37
	DocCommentOwnerComposite fDocComboComposite;
38
	DocCommentOwnerManager fManager;
39
	
40
	Button fCheckbox;
41
	Link fLink;
42
	
43
	public DocCommentOwnerBlock() {
44
		fManager= DocCommentOwnerManager.getInstance();
45
	}
46
	
47
	void handleCheckBox() {
48
		fDocComboComposite.setEnabled(fCheckbox.getSelection());
49
		fLink.setVisible(!fCheckbox.getSelection());
50
	}
51
	
52
	public void createControl(final Composite parent) {
53
		Composite pane= new Composite(parent, SWT.NONE);
54
		pane.setLayout(new GridLayout(2, true));
55
		pane.setLayoutData(GridDataFactory.fillDefaults().grab(true,false).span(2, 1).create());
56
		
57
		setControl(pane);
58
		
59
		fCheckbox= ControlFactory.createCheckBox(pane, DialogsMessages.DocCommentOwnerBlock_EnableProjectSpecificSettings);
60
		fCheckbox.setLayoutData(GridDataFactory.fillDefaults().grab(true,false).create());
61
		fCheckbox.addSelectionListener(new SelectionAdapter(){
62
			public void widgetSelected(SelectionEvent e) {
63
				handleCheckBox();
64
			}
65
		});
66
		
67
		fLink= new Link(pane, SWT.NONE);
68
		fLink.setText(DialogsMessages.PreferenceScopeBlock_preferenceLink);
69
		fLink.setLayoutData(GridDataFactory.fillDefaults().align(GridData.CENTER, GridData.BEGINNING).grab(true,false).create());
70
		fLink.addSelectionListener(new SelectionAdapter() {
71
			public void widgetSelected(SelectionEvent e) {
72
				PreferencesUtil.createPreferenceDialogOn(parent.getShell(), EDITOR_PREF_PAGE_ID, null, null).open();
73
			}
74
		});
75
		
76
		String dsc= DialogsMessages.DocCommentOwnerBlock_SelectDocToolDescription;
77
		String msg= DialogsMessages.DocCommentOwnerBlock_DocToolLabel;
78
		
79
		IDocCommentOwner prjOwner= DocCommentOwnerManager.getInstance().getCommentOwner(getProject());
80
		fDocComboComposite= new DocCommentOwnerComposite(pane, prjOwner, dsc, msg);
81
		fDocComboComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true,false).span(2, 1).create());
82
		
83
		fCheckbox.setSelection(fManager.projectDefinesOwnership(getProject()));
84
		handleCheckBox();
85
	}
86
	
87
	public void performApply(IProgressMonitor monitor) throws CoreException {
88
		if(!fCheckbox.getSelection())
89
			fManager.setCommentOwner(getProject(), null, true);
90
		else {
91
			IDocCommentOwner newOwner= fDocComboComposite.getSelectedDocCommentOwner();
92
			IProject p= getProject();
93
			fManager.setCommentOwner(p, newOwner, true);
94
		}
95
	}
96
97
	public IProject getProject() {
98
		ICOptionContainer container = getContainer();
99
		if (container != null){
100
			if (container instanceof ICOptionContainerExtension) {
101
				try {
102
					return ((ICOptionContainerExtension) container).getProjectHandle();
103
				}
104
				catch (Exception e) {
105
					return null;
106
				}
107
			}
108
			return container.getProject();
109
		}
110
		return null;
111
	}
112
113
	public void performDefaults() {
114
	}
115
}
(-)src/org/eclipse/cdt/ui/text/doctools/generic/AbstractGenericTagDocCommentViewerConfiguration.java (+79 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.text.doctools.generic;
12
13
import org.eclipse.jface.text.ITextDoubleClickStrategy;
14
15
import org.eclipse.cdt.ui.text.ICTokenScanner;
16
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
17
import org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer;
18
import org.eclipse.cdt.ui.text.doctools.IDocCommentDictionary;
19
import org.eclipse.cdt.ui.text.doctools.IDocCommentSimpleDictionary;
20
import org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration;
21
22
/**
23
 * An abstract base-class for documentation tool contributions using the 'generic tag' framework
24
 */
25
public abstract class AbstractGenericTagDocCommentViewerConfiguration implements IDocCommentViewerConfiguration {
26
	protected GenericDocTag[] fTags;
27
	protected char[] fTagMarkers;
28
	
29
	protected ITextDoubleClickStrategy fDCStrategy;
30
	protected ICompletionProposalComputer fCPComputer;
31
	protected String fDefaultToken;
32
	protected String fTagToken;
33
	protected IDocCommentSimpleDictionary fDictionary;
34
	
35
	/**
36
	 * 
37
	 * @param tags a non-null array of tags this configuration should recognize
38
	 * @param tagMarkers a non-null array of characters used to prefix the tags (e.g. @ or \)
39
	 * @param defaultToken the default scanner token id
40
	 * @param tagToken the scanner token to use to mark used by this configuration
41
	 */
42
	public AbstractGenericTagDocCommentViewerConfiguration(GenericDocTag[] tags, char[] tagMarkers, String defaultToken, String tagToken) {
43
		fTags= tags;
44
		fTagMarkers= tagMarkers;
45
		fDCStrategy= new GenericTagDoubleClickStrategy(tagMarkers);
46
		fCPComputer= new GenericTagCompletionProposalComputer(fTags);
47
		fDefaultToken= defaultToken;
48
		fTagToken= tagToken;
49
		fDictionary= new GenericTagSimpleDictionary(fTagMarkers, fTags);
50
	}
51
52
	/*
53
	 * @see org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration#createCommentScanner(org.eclipse.cdt.ui.text.ITokenStoreFactory, java.lang.String)
54
	 */
55
	public ICTokenScanner createCommentScanner(ITokenStoreFactory tokenStoreFactory) {
56
		return new GenericTagCommentScanner(tokenStoreFactory, fDefaultToken, fTagToken, fTags, fTagMarkers);
57
	}
58
59
	/*
60
	 * @see org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration#createDoubleClickStrategy()
61
	 */
62
	public ITextDoubleClickStrategy createDoubleClickStrategy() {
63
		return fDCStrategy;
64
	}
65
66
	/*
67
	 * @see org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration#createProposalComputer()
68
	 */
69
	public ICompletionProposalComputer createProposalComputer() {
70
		return fCPComputer;
71
	}
72
	
73
	/*
74
	 * @see org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration#getSpellingDictionary()
75
	 */
76
	public IDocCommentDictionary getSpellingDictionary() {
77
		return fDictionary;
78
	}
79
}
(-)src/org/eclipse/cdt/ui/dialogs/DocCommentOwnerCombo.java (+83 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.dialogs;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
import org.eclipse.swt.layout.GridLayout;
17
import org.eclipse.swt.widgets.Combo;
18
import org.eclipse.swt.widgets.Composite;
19
20
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
21
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
22
23
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
24
import org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentOwner;
25
26
/**
27
 * Manages the population and selection of the doc-comment {@link Combo} box
28
 */
29
public class DocCommentOwnerCombo extends Composite {
30
	protected Combo fCombo;
31
	protected IDocCommentOwner fOwners[], fInitialOwner;
32
33
	public DocCommentOwnerCombo(Composite parent, int style, IDocCommentOwner initialOwner) {
34
		super(parent, style);
35
		setLayout(new GridLayout());
36
		fInitialOwner= initialOwner;
37
		fOwners= getNontestOwners();
38
		createControl(this);
39
	}
40
41
	public IDocCommentOwner getSelectedDocCommentOwner() {
42
		int index= fCombo.getSelectionIndex();
43
		return index == 0 ? NullDocCommentOwner.INSTANCE : fOwners[index-1];
44
	}
45
	
46
	/**
47
	 * @return the list of registered doc-comment owners, filtering out those from the
48
	 * test plug-in.
49
	 */
50
	private static IDocCommentOwner[] getNontestOwners() {
51
		IDocCommentOwner[] prefilter= DocCommentOwnerManager.getInstance().getRegisteredOwners();
52
		List result= new ArrayList();
53
		for(int i=0; i<prefilter.length; i++) {
54
			if(prefilter[i].getID().indexOf(".test.")==-1) //$NON-NLS-1$
55
				result.add(prefilter[i]);
56
		}
57
		return (IDocCommentOwner[]) result.toArray(new IDocCommentOwner[result.size()]);
58
	}
59
	
60
	public void createControl(Composite parent) {
61
		String[] items= new String[fOwners.length+1];
62
		items[0]= DialogsMessages.DocCommentOwnerCombo_None;
63
		for(int i=0; i<fOwners.length; i++) {
64
			items[i+1]= fOwners[i].getName();
65
		}
66
		fCombo = ControlFactory.createSelectCombo(parent, items, DialogsMessages.DocCommentOwnerCombo_None);
67
		selectInCombo(fInitialOwner);
68
	}
69
70
	public void selectInCombo(IDocCommentOwner owner) {
71
		for(int i=0; i<fOwners.length; i++) {
72
			if(fOwners[i].getID().equals(owner.getID())) {
73
				fCombo.select(i+1);
74
				return;
75
			}
76
		}
77
		fCombo.select(0);
78
	}
79
	
80
	public void setEnabled(boolean enabled) {
81
		fCombo.setEnabled(enabled);
82
	}
83
}
(-)src/org/eclipse/cdt/internal/ui/text/doctools/DocCommentMultilineProposalComputer.java (+21 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.text.doctools;
12
13
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
14
import org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration;
15
16
17
public class DocCommentMultilineProposalComputer extends AbstractDocCommentProposalComputer {
18
	protected IDocCommentViewerConfiguration getConfiguration(IDocCommentOwner owner) {
19
		return owner.getMultilineConfiguration();
20
	}
21
}
(-)src/org/eclipse/core/internal/filebuffers/TextFileBufferManager.java (-16 / +20 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Andrew Ferguson (Symbian)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.core.internal.filebuffers;
12
package org.eclipse.core.internal.filebuffers;
12
13
Lines 18-28 Link Here
18
import java.util.List;
19
import java.util.List;
19
import java.util.Map;
20
import java.util.Map;
20
21
22
import org.eclipse.core.filebuffers.IAnnotationModelFactory;
23
import org.eclipse.core.filebuffers.IDocumentFactory;
24
import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
25
import org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension;
26
import org.eclipse.core.filebuffers.IFileBuffer;
27
import org.eclipse.core.filebuffers.IFileBufferListener;
28
import org.eclipse.core.filebuffers.IFileBufferStatusCodes;
29
import org.eclipse.core.filebuffers.ISynchronizationContext;
30
import org.eclipse.core.filebuffers.ITextFileBuffer;
31
import org.eclipse.core.filebuffers.ITextFileBufferManager;
32
import org.eclipse.core.filebuffers.LocationKind;
21
import org.eclipse.core.filesystem.EFS;
33
import org.eclipse.core.filesystem.EFS;
22
import org.eclipse.core.filesystem.IFileInfo;
34
import org.eclipse.core.filesystem.IFileInfo;
23
import org.eclipse.core.filesystem.IFileStore;
35
import org.eclipse.core.filesystem.IFileStore;
24
import org.eclipse.core.filesystem.URIUtil;
36
import org.eclipse.core.filesystem.URIUtil;
25
26
import org.eclipse.core.runtime.Assert;
37
import org.eclipse.core.runtime.Assert;
27
import org.eclipse.core.runtime.CoreException;
38
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.IPath;
39
import org.eclipse.core.runtime.IPath;
Lines 35-52 Link Here
35
import org.eclipse.core.runtime.content.IContentDescription;
46
import org.eclipse.core.runtime.content.IContentDescription;
36
import org.eclipse.core.runtime.content.IContentType;
47
import org.eclipse.core.runtime.content.IContentType;
37
import org.eclipse.core.runtime.content.IContentTypeManager;
48
import org.eclipse.core.runtime.content.IContentTypeManager;
38
39
import org.eclipse.core.filebuffers.IAnnotationModelFactory;
40
import org.eclipse.core.filebuffers.IDocumentFactory;
41
import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
42
import org.eclipse.core.filebuffers.IFileBuffer;
43
import org.eclipse.core.filebuffers.IFileBufferListener;
44
import org.eclipse.core.filebuffers.IFileBufferStatusCodes;
45
import org.eclipse.core.filebuffers.ISynchronizationContext;
46
import org.eclipse.core.filebuffers.ITextFileBuffer;
47
import org.eclipse.core.filebuffers.ITextFileBufferManager;
48
import org.eclipse.core.filebuffers.LocationKind;
49
50
import org.eclipse.jface.text.IDocument;
49
import org.eclipse.jface.text.IDocument;
51
import org.eclipse.jface.text.IDocumentExtension4;
50
import org.eclipse.jface.text.IDocumentExtension4;
52
import org.eclipse.jface.text.source.IAnnotationModel;
51
import org.eclipse.jface.text.source.IAnnotationModel;
Lines 432-438 Link Here
432
	 * @see org.eclipse.core.filebuffers.ITextFileBufferManager#createEmptyDocument(org.eclipse.core.runtime.IPath, org.eclipse.core.filebuffers.LocationKind)
431
	 * @see org.eclipse.core.filebuffers.ITextFileBufferManager#createEmptyDocument(org.eclipse.core.runtime.IPath, org.eclipse.core.filebuffers.LocationKind)
433
	 * @since 3.3
432
	 * @since 3.3
434
	 */
433
	 */
435
	public IDocument createEmptyDocument(IPath location, LocationKind locationKind) {
434
	public IDocument createEmptyDocument(final IPath location, final LocationKind locationKind) {
436
		final IDocument[] runnableResult= new IDocument[1];
435
		final IDocument[] runnableResult= new IDocument[1];
437
		if (location != null) {
436
		if (location != null) {
438
			final IDocumentFactory factory= fRegistry.getDocumentFactory(location, locationKind);
437
			final IDocumentFactory factory= fRegistry.getDocumentFactory(location, locationKind);
Lines 473-479 Link Here
473
				final IDocumentSetupParticipant participant= participants[i];
472
				final IDocumentSetupParticipant participant= participants[i];
474
				ISafeRunnable runnable= new ISafeRunnable() {
473
				ISafeRunnable runnable= new ISafeRunnable() {
475
					public void run() throws Exception {
474
					public void run() throws Exception {
476
						participant.setup(document);
475
						if(participant instanceof IDocumentSetupParticipantExtension) {
476
							IDocumentSetupParticipantExtension extParticipant= (IDocumentSetupParticipantExtension) participant;
477
							extParticipant.setup(document, location, locationKind);
478
						} else {
479
							participant.setup(document);
480
						}
477
						if (document.getDocumentPartitioner() != null) {
481
						if (document.getDocumentPartitioner() != null) {
478
							String message= NLSUtility.format(FileBuffersMessages.TextFileBufferManager_warning_documentSetupInstallsDefaultPartitioner, participant.getClass());
482
							String message= NLSUtility.format(FileBuffersMessages.TextFileBufferManager_warning_documentSetupInstallsDefaultPartitioner, participant.getClass());
479
							IStatus status= new Status(IStatus.WARNING, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, message, null);
483
							IStatus status= new Status(IStatus.WARNING, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, message, null);
(-)src/org/eclipse/core/internal/filebuffers/ResourceTextFileBufferManager.java (-20 / +25 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-17 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Andrew Ferguson (Symbian)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.core.internal.filebuffers;
12
package org.eclipse.core.internal.filebuffers;
12
13
13
import java.util.ArrayList;
14
import java.util.ArrayList;
14
15
16
import org.eclipse.core.filebuffers.FileBuffers;
17
import org.eclipse.core.filebuffers.IAnnotationModelFactory;
18
import org.eclipse.core.filebuffers.IDocumentFactory;
19
import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
20
import org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension;
21
import org.eclipse.core.filebuffers.IFileBuffer;
22
import org.eclipse.core.filebuffers.IStateValidationSupport;
23
import org.eclipse.core.filebuffers.LocationKind;
24
import org.eclipse.core.resources.IFile;
25
import org.eclipse.core.resources.IResource;
26
import org.eclipse.core.resources.IResourceRuleFactory;
27
import org.eclipse.core.resources.IWorkspace;
28
import org.eclipse.core.resources.IWorkspaceRunnable;
29
import org.eclipse.core.resources.ProjectScope;
30
import org.eclipse.core.resources.ResourcesPlugin;
15
import org.eclipse.core.runtime.Assert;
31
import org.eclipse.core.runtime.Assert;
16
import org.eclipse.core.runtime.CoreException;
32
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IPath;
33
import org.eclipse.core.runtime.IPath;
Lines 27-49 Link Here
27
import org.eclipse.core.runtime.jobs.ISchedulingRule;
43
import org.eclipse.core.runtime.jobs.ISchedulingRule;
28
import org.eclipse.core.runtime.preferences.IScopeContext;
44
import org.eclipse.core.runtime.preferences.IScopeContext;
29
import org.eclipse.core.runtime.preferences.InstanceScope;
45
import org.eclipse.core.runtime.preferences.InstanceScope;
30
31
import org.eclipse.core.resources.IFile;
32
import org.eclipse.core.resources.IResource;
33
import org.eclipse.core.resources.IResourceRuleFactory;
34
import org.eclipse.core.resources.IWorkspace;
35
import org.eclipse.core.resources.IWorkspaceRunnable;
36
import org.eclipse.core.resources.ProjectScope;
37
import org.eclipse.core.resources.ResourcesPlugin;
38
39
import org.eclipse.core.filebuffers.FileBuffers;
40
import org.eclipse.core.filebuffers.IAnnotationModelFactory;
41
import org.eclipse.core.filebuffers.IDocumentFactory;
42
import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
43
import org.eclipse.core.filebuffers.IFileBuffer;
44
import org.eclipse.core.filebuffers.IStateValidationSupport;
45
import org.eclipse.core.filebuffers.LocationKind;
46
47
import org.eclipse.jface.text.IDocument;
46
import org.eclipse.jface.text.IDocument;
48
import org.eclipse.jface.text.IDocumentExtension4;
47
import org.eclipse.jface.text.IDocumentExtension4;
49
import org.eclipse.jface.text.source.IAnnotationModel;
48
import org.eclipse.jface.text.source.IAnnotationModel;
Lines 125-131 Link Here
125
		return null;
124
		return null;
126
	}
125
	}
127
126
128
	IDocument createEmptyDocument(IFile file) {
127
	public IDocument createEmptyDocument(final IFile file) {
129
		final IDocument[] runnableResult= new IDocument[1];
128
		final IDocument[] runnableResult= new IDocument[1];
130
		final IDocumentFactory factory= ((ResourceExtensionRegistry)fRegistry).getDocumentFactory(file);
129
		final IDocumentFactory factory= ((ResourceExtensionRegistry)fRegistry).getDocumentFactory(file);
131
		if (factory != null) {
130
		if (factory != null) {
Lines 162-168 Link Here
162
				final IDocumentSetupParticipant participant= participants[i];
161
				final IDocumentSetupParticipant participant= participants[i];
163
				ISafeRunnable runnable= new ISafeRunnable() {
162
				ISafeRunnable runnable= new ISafeRunnable() {
164
					public void run() throws Exception {
163
					public void run() throws Exception {
165
						participant.setup(document);
164
						if(participant instanceof IDocumentSetupParticipantExtension) {
165
							IDocumentSetupParticipantExtension ext= (IDocumentSetupParticipantExtension) participant;
166
							IPath path= file == null ? null : file.getFullPath();
167
							ext.setup(document, path, LocationKind.IFILE);
168
						} else {
169
							participant.setup(document);
170
						}
166
						if (document.getDocumentPartitioner() != null) {
171
						if (document.getDocumentPartitioner() != null) {
167
							String message= NLSUtility.format(FileBuffersMessages.TextFileBufferManager_warning_documentSetupInstallsDefaultPartitioner, participant.getClass());
172
							String message= NLSUtility.format(FileBuffersMessages.TextFileBufferManager_warning_documentSetupInstallsDefaultPartitioner, participant.getClass());
168
							IStatus status= new Status(IStatus.WARNING, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, message, null);
173
							IStatus status= new Status(IStatus.WARNING, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, message, null);
(-)src/org/eclipse/core/filebuffers/IDocumentSetupParticipant.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 29-34 Link Here
29
 *
29
 *
30
 * @since 3.0
30
 * @since 3.0
31
 * @see org.eclipse.jface.text.IDocumentExtension3
31
 * @see org.eclipse.jface.text.IDocumentExtension3
32
 * @see org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension
32
 */
33
 */
33
public interface IDocumentSetupParticipant {
34
public interface IDocumentSetupParticipant {
34
35
(-)src/org/eclipse/core/filebuffers/IDocumentSetupParticipantExtension.java (+38 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.core.filebuffers;
12
13
import org.eclipse.core.runtime.IPath;
14
import org.eclipse.jface.text.IDocument;
15
16
/**
17
 * Extension interface for {@link org.eclipse.core.filebuffers.IDocumentSetupParticipant}.<p>
18
 * 
19
 * This interface is additionally implemented by {@link IDocumentSetupParticipant}'s which
20
 * would like to alter their behavior based on the location of the file being opened.<p>
21
 * 
22
 * Note that when participants implement this interface, the original method from
23
 * {@link IDocumentSetupParticipant} will never be called.
24
 * 
25
 * @see org.eclipse.core.filebuffers.IDocumentSetupParticipant
26
 * @since 3.4
27
 */
28
public interface IDocumentSetupParticipantExtension {
29
30
	/**
31
	 * Sets up the document to be ready for use by a text file buffer.
32
	 *
33
	 * @param document the document to be set up
34
	 * @param location a path of the resource backing the new document. May be null.
35
	 * @param locationKind the LocationKind of the location specified. May be null.
36
	 */
37
	void setup(IDocument document, IPath location, LocationKind locationKind);
38
}
(-)suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java (-2 / +5 lines)
Lines 51-56 Link Here
51
import org.eclipse.core.runtime.Path;
51
import org.eclipse.core.runtime.Path;
52
import org.osgi.framework.Bundle;
52
import org.osgi.framework.Bundle;
53
53
54
/**
55
 * Utilities for reading test source code from plug-in .java sources
56
 */
54
public class TestSourceReader {
57
public class TestSourceReader {
55
58
56
	/**
59
	/**
Lines 85-91 Link Here
85
	    List contents = new ArrayList();
88
	    List contents = new ArrayList();
86
	    StringBuffer content = new StringBuffer();
89
	    StringBuffer content = new StringBuffer();
87
	    for(String line = br.readLine(); line!=null; line = br.readLine()) {
90
	    for(String line = br.readLine(); line!=null; line = br.readLine()) {
88
	    	line = line.trim();
91
	    	line = line.replaceFirst("^\\s*", ""); // replace leading whitespace, preserve trailing
89
	    	if(line.startsWith("//")) {
92
	    	if(line.startsWith("//")) {
90
	    		content.append(line.substring(2)+"\n");
93
	    		content.append(line.substring(2)+"\n");
91
	    	} else {
94
	    	} else {
Lines 113-119 Link Here
113
	 * @param lookfor string to be searched for
116
	 * @param lookfor string to be searched for
114
	 * @param fullPath full path of the workspace file
117
	 * @param fullPath full path of the workspace file
115
	 * @return the offset or -1
118
	 * @return the offset or -1
116
	 * @throws CoreException
119
	 * @throws Exception 
117
	 * @throws UnsupportedEncodingException 
120
	 * @throws UnsupportedEncodingException 
118
	 * @since 4.0
121
	 * @since 4.0
119
	 */
122
	 */
(-)ui/org/eclipse/cdt/ui/tests/text/TextTestSuite.java (+5 lines)
Lines 13-18 Link Here
13
13
14
import junit.framework.TestSuite;
14
import junit.framework.TestSuite;
15
15
16
import org.eclipse.cdt.ui.tests.text.doctools.DocCommentTestSuite;
17
16
public class TextTestSuite extends TestSuite {
18
public class TextTestSuite extends TestSuite {
17
19
18
    public static TestSuite suite() {
20
    public static TestSuite suite() {
Lines 22-27 Link Here
22
    public TextTestSuite() {
24
    public TextTestSuite() {
23
        super(TextTestSuite.class.getName());
25
        super(TextTestSuite.class.getName());
24
26
27
        // documentation tool extension tests
28
        addTest(DocCommentTestSuite.suite());
29
        
25
        // partitioning tests
30
        // partitioning tests
26
		addTest(PartitionTokenScannerTest.suite());
31
		addTest(PartitionTokenScannerTest.suite());
27
		addTest(CPartitionerTest.suite());
32
		addTest(CPartitionerTest.suite());
(-)ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java (-197 / +6 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
9
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
10
 *     Sergey Prigogin, Google
10
 *     Sergey Prigogin, Google
11
 *     Andrew Ferguson (Symbian)
11
 *******************************************************************************/
12
 *******************************************************************************/
12
13
13
package org.eclipse.cdt.ui.tests.text;
14
package org.eclipse.cdt.ui.tests.text;
Lines 16-22 Link Here
16
import java.util.Collections;
17
import java.util.Collections;
17
import java.util.HashMap;
18
import java.util.HashMap;
18
import java.util.List;
19
import java.util.List;
19
import java.util.Map;
20
20
21
import junit.framework.Test;
21
import junit.framework.Test;
22
import junit.framework.TestSuite;
22
import junit.framework.TestSuite;
Lines 26-239 Link Here
26
import org.eclipse.core.runtime.Plugin;
26
import org.eclipse.core.runtime.Plugin;
27
import org.eclipse.jface.text.BadLocationException;
27
import org.eclipse.jface.text.BadLocationException;
28
import org.eclipse.jface.text.Document;
28
import org.eclipse.jface.text.Document;
29
import org.eclipse.jface.text.DocumentCommand;
30
import org.eclipse.jface.text.IAutoEditStrategy;
31
import org.eclipse.jface.text.IDocument;
29
import org.eclipse.jface.text.IDocument;
32
import org.eclipse.jface.text.IRegion;
33
import org.eclipse.jface.text.TextUtilities;
34
30
35
import org.eclipse.cdt.core.CCorePlugin;
31
import org.eclipse.cdt.core.CCorePlugin;
36
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
37
import org.eclipse.cdt.ui.CUIPlugin;
32
import org.eclipse.cdt.ui.CUIPlugin;
38
import org.eclipse.cdt.ui.text.ICPartitions;
33
import org.eclipse.cdt.ui.text.ICPartitions;
34
import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy;
39
35
40
import org.eclipse.cdt.internal.formatter.DefaultCodeFormatterOptions;
36
import org.eclipse.cdt.internal.formatter.DefaultCodeFormatterOptions;
41
37
42
import org.eclipse.cdt.internal.ui.text.CAutoIndentStrategy;
38
import org.eclipse.cdt.internal.ui.text.CAutoIndentStrategy;
43
import org.eclipse.cdt.internal.ui.text.CCommentAutoIndentStrategy;
44
import org.eclipse.cdt.internal.ui.text.CTextTools;
39
import org.eclipse.cdt.internal.ui.text.CTextTools;
45
40
46
/**
41
/**
47
 * Testing the auto indent strategies.
42
 * Testing the auto indent strategies.
48
 */
43
 */
49
public class CAutoIndentTest extends BaseTestCase {
44
public class CAutoIndentTest extends AbstractAutoEditTest {
50
51
	/**
52
	 * Helper class to test the auto-edit strategies on a document.
53
	 */
54
	static class AutoEditTester {
55
56
		private Map fStrategyMap = new HashMap();
57
		private IDocument fDoc;
58
		private String fPartitioning;
59
		private int fCaretOffset;
60
61
		public AutoEditTester(IDocument doc, String partitioning) {
62
			super();
63
			fDoc = doc;
64
			fPartitioning = partitioning;
65
		}
66
67
		public void setAutoEditStrategy(String contentType, IAutoEditStrategy aes) {
68
			fStrategyMap.put(contentType, aes);
69
		}
70
71
		public IAutoEditStrategy getAutoEditStrategy(String contentType) {
72
			return (IAutoEditStrategy)fStrategyMap.get(contentType);
73
		}
74
75
		/**
76
		 * Empties the document, and returns the caret to the origin (0,0)
77
		 */
78
		public void reset() {
79
			try {
80
				goTo(0,0);
81
				fDoc.set("");
82
			} catch(BadLocationException ble) {
83
				fail(ble.getMessage());
84
			}
85
		}
86
		
87
		public void type(String text) throws BadLocationException {
88
			for (int i = 0; i < text.length(); ++i) {
89
				type(text.charAt(i));
90
			}
91
		}
92
93
		public void type(char c) throws BadLocationException {
94
			TestDocumentCommand command = new TestDocumentCommand(fCaretOffset, 0, new String(new char[] { c }));
95
			customizeDocumentCommand(command);
96
			fCaretOffset = command.exec(fDoc);
97
		}
98
99
		private void customizeDocumentCommand(TestDocumentCommand command) throws BadLocationException {
100
			IAutoEditStrategy aes = getAutoEditStrategy(getContentType());
101
			if (aes != null) {
102
				aes.customizeDocumentCommand(fDoc, command);
103
			}
104
		}
105
106
		public void type(int offset, String text) throws BadLocationException {
107
			fCaretOffset = offset;
108
			type(text);
109
		}
110
111
		public void type(int offset, char c) throws BadLocationException {
112
			fCaretOffset = offset;
113
			type(c);
114
		}
115
116
		public void paste(String text) throws BadLocationException {
117
			TestDocumentCommand command = new TestDocumentCommand(fCaretOffset, 0, text);
118
			customizeDocumentCommand(command);
119
			fCaretOffset = command.exec(fDoc);
120
		}
121
122
		public void paste(int offset, String text) throws BadLocationException {
123
			fCaretOffset = offset;
124
			paste(text);
125
		}
126
127
		public void backspace(int n) throws BadLocationException {
128
			for (int i = 0; i < n; ++i) {
129
				backspace();
130
			}
131
		}
132
		
133
		public void backspace() throws BadLocationException {
134
			TestDocumentCommand command = new TestDocumentCommand(fCaretOffset - 1, 1, ""); //$NON-NLS-1$
135
			customizeDocumentCommand(command);
136
			fCaretOffset = command.exec(fDoc);
137
		}
138
139
		public int getCaretOffset() {
140
			return fCaretOffset;
141
		}
142
143
		public int setCaretOffset(int offset) {
144
			fCaretOffset = offset;
145
			if (fCaretOffset < 0)
146
				fCaretOffset = 0;
147
			else if (fCaretOffset > fDoc.getLength())
148
				fCaretOffset = fDoc.getLength();
149
			return fCaretOffset;
150
		}
151
		
152
		/**
153
		 * Moves caret right or left by the given number of characters.
154
		 * 
155
		 * @param shift Move distance.
156
		 * @return New caret offset.
157
		 */
158
		public int moveCaret(int shift) {
159
			return setCaretOffset(fCaretOffset + shift);
160
		}
161
		
162
		public int goTo(int line) throws BadLocationException {
163
			fCaretOffset = fDoc.getLineOffset(line);
164
			return fCaretOffset;
165
		}
166
167
		public int goTo(int line, int column) throws BadLocationException {
168
			if (column < 0 || column > fDoc.getLineLength(line)) {
169
				throw new BadLocationException("No column " + column + " in line " + line); //$NON-NLS-1$ $NON-NLS-2$
170
			}
171
			fCaretOffset = fDoc.getLineOffset(line) + column;
172
			return fCaretOffset;
173
		}
174
175
		public int getCaretLine() throws BadLocationException {
176
			return fDoc.getLineOfOffset(fCaretOffset);
177
		}
178
179
		public int getCaretColumn() throws BadLocationException {
180
			IRegion region = fDoc.getLineInformationOfOffset(fCaretOffset);
181
			return fCaretOffset - region.getOffset();
182
		}
183
184
		public char getChar() throws BadLocationException {
185
			return getChar(0);
186
		}
187
		
188
		public char getChar(int i) throws BadLocationException {
189
			return fDoc.getChar(fCaretOffset+i);
190
		}
191
		
192
		public String getLine() throws BadLocationException {
193
			return getLine(0);
194
		}
195
196
		public String getLine(int i) throws BadLocationException {
197
			IRegion region = fDoc.getLineInformation(getCaretLine() + i);
198
			return fDoc.get(region.getOffset(), region.getLength());
199
		}
200
201
		public String getContentType() throws BadLocationException {
202
			return getContentType(0);
203
		}
204
205
		public String getContentType(int i) throws BadLocationException {
206
			return TextUtilities.getContentType(fDoc, fPartitioning, fCaretOffset + i, false);
207
		}
208
	}
209
210
	/**
211
	 * A DocumentCommand with public constructor and exec method.
212
	 */
213
	static class TestDocumentCommand extends DocumentCommand {
214
215
		public TestDocumentCommand(int offset, int length, String text) {
216
			super();
217
			doit = true;
218
			this.text = text;
219
220
			this.offset = offset;
221
			this.length = length;
222
223
			owner = null;
224
			caretOffset = -1;
225
		}
226
227
		/**
228
		 * Returns new caret position.
229
		 */
230
		public int exec(IDocument doc) throws BadLocationException {
231
			doc.replace(offset, length, text);
232
			return caretOffset != -1 ?
233
						caretOffset :
234
						offset + (text == null ? 0 : text.length());
235
		}
236
	}
237
45
238
	private HashMap fOptions;
46
	private HashMap fOptions;
239
	private List fStatusLog;
47
	private List fStatusLog;
Lines 289-296 Link Here
289
		IDocument doc = new Document();
97
		IDocument doc = new Document();
290
		textTools.setupCDocument(doc);
98
		textTools.setupCDocument(doc);
291
		AutoEditTester tester = new AutoEditTester(doc, ICPartitions.C_PARTITIONING);
99
		AutoEditTester tester = new AutoEditTester(doc, ICPartitions.C_PARTITIONING);
100
		
292
		tester.setAutoEditStrategy(IDocument.DEFAULT_CONTENT_TYPE, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null));
101
		tester.setAutoEditStrategy(IDocument.DEFAULT_CONTENT_TYPE, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null));
293
		tester.setAutoEditStrategy(ICPartitions.C_MULTI_LINE_COMMENT, new CCommentAutoIndentStrategy());
102
		tester.setAutoEditStrategy(ICPartitions.C_MULTI_LINE_COMMENT, new DefaultMultilineCommentAutoEditStrategy());
294
		tester.setAutoEditStrategy(ICPartitions.C_PREPROCESSOR, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null));
103
		tester.setAutoEditStrategy(ICPartitions.C_PREPROCESSOR, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null));
295
		return tester;
104
		return tester;
296
	}
105
	}
Lines 385-391 Link Here
385
	public void testCCommentAutoIndent() throws BadLocationException {
194
	public void testCCommentAutoIndent() throws BadLocationException {
386
		AutoEditTester tester = createAutoEditTester(); //$NON-NLS-1$
195
		AutoEditTester tester = createAutoEditTester(); //$NON-NLS-1$
387
		tester.type("/*\n"); //$NON-NLS-1$
196
		tester.type("/*\n"); //$NON-NLS-1$
388
		assertEquals(ICPartitions.C_MULTI_LINE_COMMENT, tester.getContentType(-1));
197
		assertEquals(ICPartitions.C_MULTI_LINE_COMMENT, tester.getContentType(tester.getCaretOffset()-1));
389
		assertEquals(1, tester.getCaretLine());
198
		assertEquals(1, tester.getCaretLine());
390
		assertEquals(3, tester.getCaretColumn());
199
		assertEquals(3, tester.getCaretColumn());
391
		assertEquals(" * ", tester.getLine()); //$NON-NLS-1$
200
		assertEquals(" * ", tester.getLine()); //$NON-NLS-1$
(-)ui/org/eclipse/cdt/ui/tests/text/PartitionTokenScannerTest.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 QNX Software Systems and others.
2
 * Copyright (c) 2005, 2008 QNX Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 41-47 Link Here
41
41
42
	protected void setUp() {
42
	protected void setUp() {
43
		fReference= new CPartitionScanner();
43
		fReference= new CPartitionScanner();
44
		fTestee= new FastCPartitionScanner(true);
44
		fTestee= new FastCPartitionScanner(true, null);
45
	}
45
	}
46
46
47
	// read sample C file
47
	// read sample C file
(-)ui/org/eclipse/cdt/ui/tests/text/CPartitionerTest.java (-1 / +1 lines)
Lines 49-55 Link Here
49
		fTextTools= new CTextTools(new PreferenceStore());
49
		fTextTools= new CTextTools(new PreferenceStore());
50
50
51
		fDocument= new Document();
51
		fDocument= new Document();
52
		IDocumentPartitioner partitioner= fTextTools.createDocumentPartitioner();
52
		IDocumentPartitioner partitioner= fTextTools.createDocumentPartitioner(null);
53
		partitioner.connect(fDocument);
53
		partitioner.connect(fDocument);
54
		fDocument.setDocumentPartitioner(partitioner);
54
		fDocument.setDocumentPartitioner(partitioner);
55
		fDocument.set("xxx\n/*xxx*/\nxxx\n/**xxx*/\nxxx\n/**/\nxxx\n/***/\nxxx");
55
		fDocument.set("xxx\n/*xxx*/\nxxx\n/**xxx*/\nxxx\n/**/\nxxx\n/***/\nxxx");
(-)ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java (-1 / +1 lines)
Lines 209-215 Link Here
209
209
210
	//int verylooooooooooooooooooooooooooooooooooongname = 0000000000000000000000000000000;
210
	//int verylooooooooooooooooooooooooooooooooooongname = 0000000000000000000000000000000;
211
	
211
	
212
	//int verylooooooooooooooooooooooooooooooooooongname = 
212
	//int verylooooooooooooooooooooooooooooooooooongname =
213
	//		0000000000000000000000000000000;
213
	//		0000000000000000000000000000000;
214
	public void testLineWrappingOfInitializerExpression_Bug200961() throws Exception {
214
	public void testLineWrappingOfInitializerExpression_Bug200961() throws Exception {
215
		assertFormatterResult();
215
		assertFormatterResult();
(-)plugin.xml (-3 / +85 lines)
Lines 32-41 Link Here
32
      <perspectiveExtension
32
      <perspectiveExtension
33
            targetID="org.eclipse.ui.resourcePerspective">
33
            targetID="org.eclipse.ui.resourcePerspective">
34
         <view
34
         <view
35
               id="org.eclipse.cdt.ui.tests.DOMAST.DOMAST"
35
               ratio="0.5"
36
               ratio="0.5"
36
               relative="org.eclipse.ui.views.TaskList"
37
               relationship="right"
37
               relationship="right"
38
               id="org.eclipse.cdt.ui.tests.DOMAST.DOMAST">
38
               relative="org.eclipse.ui.views.TaskList">
39
         </view>
39
         </view>
40
      </perspectiveExtension>
40
      </perspectiveExtension>
41
   </extension>
41
   </extension>
Lines 115-119 Link Here
115
            projectType="org.eclipse.cdt.build.core.buildArtefactType.exe">
115
            projectType="org.eclipse.cdt.build.core.buildArtefactType.exe">
116
      </template>
116
      </template>
117
   </extension>
117
   </extension>
118
118
   
119
   
120
   <!-- documentation tool comment test owners -->
121
   <extension
122
         point="org.eclipse.cdt.ui.DocCommentOwner">
123
     <owner id="org.cdt.test.DCOM1"
124
         name="Test comment owner1"
125
         singleline="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentViewerConfiguration"
126
         multiline="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentViewerConfiguration"
127
     />
128
   </extension>
129
    <extension
130
         point="org.eclipse.cdt.ui.DocCommentOwner">
131
      <owner  id="org.cdt.test.DCOM2"
132
         name="Test comment owner1"
133
           singleline="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentViewerConfiguration"
134
         multiline="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentViewerConfiguration"
135
         />
136
   </extension>
137
    <extension
138
          point="org.eclipse.cdt.ui.DocCommentOwner">
139
       <owner
140
             id="org.cdt.test.DCOM3"
141
             multiline="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentViewerConfiguration"
142
             name="Test comment owner1"
143
             singleline="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentViewerConfiguration">
144
       </owner>
145
    </extension>
146
    <extension
147
          point="org.eclipse.cdt.ui.DocCommentOwner">
148
       <owner
149
             id="org.cdt.test.ownerA"
150
             multiline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$A"
151
             name="name_A"
152
             singleline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$A">
153
       </owner>
154
    </extension>
155
      <extension
156
          point="org.eclipse.cdt.ui.DocCommentOwner">
157
       <owner
158
             id="org.cdt.test.ownerB"
159
             multiline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$B"
160
             name="name_B"
161
             singleline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$B">
162
       </owner>
163
    </extension>
164
      <extension
165
          point="org.eclipse.cdt.ui.DocCommentOwner">
166
       <owner
167
             id="org.cdt.test.ownerC"
168
             multiline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$C"
169
             name="name_C"
170
             singleline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$C">
171
       </owner>
172
    </extension>
173
    <extension
174
          point="org.eclipse.cdt.ui.DocCommentOwner">
175
       <owner
176
             id="org.cdt.test.ownerABC"
177
             multiline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$ABC"
178
             name="name_ABC"
179
             singleline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$ABC">
180
       </owner>
181
    </extension>
182
    <extension
183
          point="org.eclipse.cdt.ui.DocCommentOwner">
184
       <owner
185
             id="org.cdt.test.ownerBDFG"
186
             multiline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$BDFG"
187
             name="name_BDFG"
188
             singleline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$BDFG">
189
       </owner>
190
    </extension>
191
    <extension
192
          point="org.eclipse.cdt.ui.DocCommentOwner">
193
       <owner
194
             id="org.cdt.test.ownerPUNC"
195
             multiline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$PUNC"
196
             name="name_PUNC"
197
             singleline="org.eclipse.cdt.ui.tests.text.doctools.TestGenericTagConfiguration$PUNC">
198
       </owner>
199
    </extension>
200
    
119
</plugin>
201
</plugin>
(-)ui/org/eclipse/cdt/ui/tests/text/doctools/DocCommentTestSuite.java (+28 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.tests.text.doctools;
12
13
import junit.framework.TestSuite;
14
15
public class DocCommentTestSuite extends TestSuite {
16
17
    public static TestSuite suite() {
18
        return new DocCommentTestSuite();
19
    }
20
    
21
    public DocCommentTestSuite() {
22
        super(DocCommentTestSuite.class.getName());
23
24
        // partitioning tests
25
		addTest(CommentOwnerManagerTests.suite());
26
		addTest(DocCommentHighlightingTest.suite());
27
    }
28
}
(-)ui/org/eclipse/cdt/ui/tests/text/doctools/TestGenericTagConfiguration.java (+89 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.tests.text.doctools;
12
13
import org.eclipse.jface.preference.IPreferenceStore;
14
import org.eclipse.jface.preference.PreferenceConverter;
15
import org.eclipse.jface.text.BadLocationException;
16
import org.eclipse.jface.text.IAutoEditStrategy;
17
import org.eclipse.jface.text.IDocument;
18
import org.eclipse.swt.graphics.RGB;
19
20
import org.eclipse.cdt.ui.CUIPlugin;
21
import org.eclipse.cdt.ui.text.doctools.generic.AbstractGenericTagDocCommentViewerConfiguration;
22
import org.eclipse.cdt.ui.text.doctools.generic.GenericDocTag;
23
24
import org.eclipse.cdt.internal.ui.text.doctools.docpp.DocppHelper;
25
26
public class TestGenericTagConfiguration extends AbstractGenericTagDocCommentViewerConfiguration {
27
	public static final RGB DEFAULTRGB= new RGB(63, 95, 191);
28
	
29
	protected char[] fCommentMarkers;
30
	
31
	public TestGenericTagConfiguration(String commentMarkers, String tags, String tagMarkers, String defaultToken, String tagToken) {
32
		super(mkTags(tags.split("(\\s)*,(\\s)*")), tagMarkers.toCharArray(), defaultToken, tagToken);
33
		IPreferenceStore cuis= CUIPlugin.getDefault().getPreferenceStore();
34
		PreferenceConverter.setDefault(cuis, defaultToken, DEFAULTRGB);
35
		PreferenceConverter.setDefault(cuis, tagToken, new RGB(127, 159, 191));
36
		fCommentMarkers= commentMarkers.toCharArray();
37
	}
38
	
39
	public IAutoEditStrategy createAutoEditStrategy() {
40
		return null;
41
	}
42
	
43
	private static GenericDocTag[] mkTags(String[] tagNames) {
44
		GenericDocTag[] tags= new GenericDocTag[tagNames.length];
45
		for(int i=0; i<tagNames.length; i++) {
46
			tags[i]= new GenericDocTag(tagNames[i], "no description");
47
		}
48
		return tags;
49
	}
50
	
51
	public boolean isDocumentationComment(IDocument doc, int offset, int length) {
52
		try {
53
			if(offset+2 < doc.getLength()) {
54
				char c= doc.getChar(offset+2);
55
				for(int i=0; i<fCommentMarkers.length; i++)
56
					if(c == fCommentMarkers[i])
57
						return true;
58
				return false;
59
			}
60
		} catch(BadLocationException ble) {
61
			CUIPlugin.getDefault().log(ble);
62
		}
63
		return false;
64
	}
65
	
66
	public static class A extends TestGenericTagConfiguration {
67
		public A() {super("A", "", "@", "test.token.A.default", "test.token.A.tag");}
68
	}
69
	
70
	public static class B extends TestGenericTagConfiguration {
71
		public B() {super("B", "", "@", "test.token.B.default", "test.token.B.tag");}
72
	}
73
	
74
	public static class C extends TestGenericTagConfiguration {
75
		public C() {super("C", "", "@", "test.token.C.default", "test.token.C.tag");}
76
	}
77
	
78
	public static class ABC extends TestGenericTagConfiguration {
79
		public ABC() {super("ABC", "", "@", "test.token.ABC.default", "test.token.ABC.tag");}
80
	}
81
	
82
	public static class BDFG extends TestGenericTagConfiguration {
83
		public BDFG() {super("BDFG", "", "@", "test.token.BDFG.default", "test.token.BDFG.tag");}
84
	}
85
	
86
	public static class PUNC extends TestGenericTagConfiguration {
87
		public PUNC() {super("!*#", "", "@", "test.token.BDFG.default", "test.token.BDFG.tag");}
88
	}
89
}
(-)ui/org/eclipse/cdt/ui/tests/text/doctools/DocCommentHighlightingTest.java (+191 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
12
package org.eclipse.cdt.ui.tests.text.doctools;
13
14
import java.util.ArrayList;
15
import java.util.List;
16
17
import junit.framework.Assert;
18
import junit.framework.Test;
19
import junit.framework.TestSuite;
20
21
import org.eclipse.jface.text.BadLocationException;
22
import org.eclipse.jface.text.Position;
23
import org.eclipse.jface.text.TextViewer;
24
import org.eclipse.jface.text.source.ISourceViewer;
25
import org.eclipse.jface.text.source.SourceViewer;
26
import org.eclipse.swt.custom.StyleRange;
27
import org.eclipse.swt.custom.StyledText;
28
import org.eclipse.swt.graphics.RGB;
29
import org.eclipse.ui.IEditorPart;
30
import org.eclipse.ui.IEditorReference;
31
import org.eclipse.ui.IWorkbenchWindow;
32
import org.eclipse.ui.PlatformUI;
33
import org.eclipse.ui.texteditor.AbstractTextEditor;
34
35
import org.eclipse.cdt.core.model.ICProject;
36
import org.eclipse.cdt.core.testplugin.CProjectHelper;
37
import org.eclipse.cdt.ui.tests.BaseUITestCase;
38
import org.eclipse.cdt.ui.tests.text.Accessor;
39
import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
40
import org.eclipse.cdt.ui.tests.text.ResourceTestHelper;
41
42
import org.eclipse.cdt.internal.ui.editor.CEditor;
43
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
44
45
/**
46
 * 
47
 * @author andrewferguson
48
 */
49
public class DocCommentHighlightingTest extends BaseUITestCase {
50
	private static final DocCommentOwnerManager DCMAN= DocCommentOwnerManager.getInstance();
51
	private static final String LINKED_FOLDER= "resources/docComments";
52
	private static final String PROJECT= "DocCommentTests";
53
54
	// ordered by occurrence
55
	private static final int[] normal0= {114, 13};
56
	private static final int[] comment1= {129, 18};
57
	private static final int[] comment2= {149, 17};
58
	private static final int[] comment3= {168, 16};
59
	private static final int[] comment4= {184, 18};
60
	private static final int[] comment5= {204, 19};
61
	private static final int[] comment6= {223, 16};
62
	private static final int[] comment7= {241, 17};
63
	private static final int[] comment8= {258, 16};
64
	private static final int[] comment9= {274, 17};
65
	private static final int[] comment10= {293, 18};
66
	private static final int[] snormal0= {315, 13};
67
	private static final int[] scomment1= {328, 17};
68
	private static final int[] scomment2= {345, 16};
69
	private static final int[] scomment3= {361, 17};
70
	private static final int[] scomment4= {378, 16};
71
	private static final int[] scomment5= {394, 18};
72
	private static final int[] comment11= {414, 18};
73
	private static final int[] scomment6= {433, 16};
74
	private static final int[] comment12= {449, 19};
75
	private static final int[] scomment7= {469, 17};
76
	
77
	
78
	private ICProject fCProject;
79
	private final String fTestFilename= "/"+PROJECT+"/src/this.cpp";
80
81
	private static SourceViewer fSourceViewer;
82
83
	public static Test suite() {
84
		return new TestSuite(DocCommentHighlightingTest.class);
85
	}
86
87
	public DocCommentHighlightingTest(String name) {
88
		super(name);
89
	}
90
91
	protected void setUp() throws Exception {
92
		super.setUp();
93
		fCProject= EditorTestHelper.createCProject(PROJECT, LINKED_FOLDER);
94
95
		AbstractTextEditor fEditor= (CEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(fTestFilename), true);
96
		fSourceViewer= EditorTestHelper.getSourceViewer(fEditor);
97
		assertTrue(EditorTestHelper.joinReconciler(fSourceViewer, 0, 10000, 100));
98
	}
99
100
	protected void tearDown () throws Exception {
101
		EditorTestHelper.closeAllEditors();
102
103
		if (fCProject != null)
104
			CProjectHelper.delete(fCProject);
105
106
		super.tearDown();
107
	}
108
109
	protected List/*<Position>*/ findRangesColored(RGB rgb) {
110
		List result= new ArrayList();
111
		System.out.println("-------------");
112
		IEditorPart p= get();
113
		ISourceViewer vw= ((CEditor)p).getViewer();
114
		Accessor a= new Accessor(vw, TextViewer.class);
115
		StyledText st= (StyledText) a.get("fTextWidget");
116
		StyleRange[] rgs= st.getStyleRanges();
117
		for(int i=0; i<rgs.length; i++) {
118
			if(rgs[i].foreground != null && rgs[i].foreground.getRGB().equals(rgb)) {
119
				System.out.println(rgs[i].start +", "+ rgs[i].length);
120
				result.add(new Position(rgs[i].start, rgs[i].length));
121
			}
122
		}
123
		return result;
124
	}
125
126
	protected IEditorPart get(){
127
		IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
128
		if(window!=null) {
129
			if(window.getActivePage()!=null) {
130
				IEditorReference[] es= window.getActivePage().getEditorReferences();
131
				for(int i=0; i<es.length; i++) {
132
					IEditorPart part= es[i].getEditor(false);
133
					if(part != null)
134
						return part;
135
				}
136
			}
137
		}
138
		return null;
139
	}
140
141
	private List/*<Position>*/ mkPositions(int[][] raw) {
142
		List result= new ArrayList();
143
		for(int i=0; i<raw.length; i++) {
144
			Assert.assertEquals(2, raw[i].length);
145
			result.add(new Position(raw[i][0], raw[i][1]));
146
		}
147
		return result;
148
	}
149
	
150
	public void testDCOM_A() throws BadLocationException, InterruptedException {
151
		DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerA"), true);
152
		runEventQueue(1000);
153
		List/*<Position>*/ expected= mkPositions(new int[][] {comment1, scomment1});
154
		assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB));
155
	}
156
157
	public void testDCOM_B() throws BadLocationException, InterruptedException {
158
		DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerB"), true);
159
		runEventQueue(1000);
160
		List/*<Position>*/ expected= mkPositions(new int[][] {comment2, scomment2});
161
		assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB));
162
	}
163
164
	public void testDCOM_C() throws BadLocationException, InterruptedException  {
165
		DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerC"), true);
166
		runEventQueue(1000);
167
		List/*<Position>*/ expected= mkPositions(new int[][] {comment3, scomment3});
168
		assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB));
169
	}
170
171
	public void testDCOM_ABC() throws BadLocationException, InterruptedException {
172
		DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerABC"), true);
173
		runEventQueue(1000);
174
		List/*<Position>*/ expected= mkPositions(new int[][] {comment1, comment2, comment3, scomment1, scomment2, scomment3});
175
		assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB));
176
	}
177
	
178
	public void testDCOM_BDFG() throws BadLocationException, InterruptedException {
179
		DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerBDFG"), true);
180
		runEventQueue(1000);
181
		List/*<Position>*/ expected= mkPositions(new int[][] {comment2, comment4, comment6, comment7, comment8, scomment2});
182
		assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB));
183
	}
184
	
185
	public void testDCOM_PUNC() throws BadLocationException, InterruptedException {
186
		DCMAN.setCommentOwner(fCProject.getProject(), DCMAN.getOwner("org.cdt.test.ownerPUNC"), true);
187
		runEventQueue(1000);
188
		List/*<Position>*/ expected= mkPositions(new int[][] {comment9, comment10, scomment4, scomment5, comment11, comment12, scomment7});
189
		assertEquals(expected, findRangesColored(TestGenericTagConfiguration.DEFAULTRGB));
190
	}
191
}
(-)ui/org/eclipse/cdt/ui/tests/text/DefaultCCommentAutoEditStrategyTest.java (+629 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
10
 *     Sergey Prigogin, Google
11
 *     Andrew Ferguson (Symbian)
12
 *******************************************************************************/
13
14
package org.eclipse.cdt.ui.tests.text;
15
16
import java.io.IOException;
17
import java.util.HashMap;
18
19
import junit.framework.Test;
20
21
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.jface.text.BadLocationException;
24
import org.eclipse.jface.text.Document;
25
import org.eclipse.jface.text.IDocument;
26
27
import org.eclipse.cdt.core.CCorePlugin;
28
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
29
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
30
import org.eclipse.cdt.core.model.ICProject;
31
import org.eclipse.cdt.core.testplugin.CProjectHelper;
32
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
33
import org.eclipse.cdt.ui.CUIPlugin;
34
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
35
import org.eclipse.cdt.ui.text.ICPartitions;
36
import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy;
37
38
import org.eclipse.cdt.internal.ui.text.CAutoIndentStrategy;
39
import org.eclipse.cdt.internal.ui.text.CTextTools;
40
41
42
/**
43
 * Testing the auto indent strategies.
44
 */
45
public class DefaultCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
46
	private HashMap fOptions;
47
48
	/**
49
	 * @param name
50
	 */
51
	public DefaultCCommentAutoEditStrategyTest(String name) {
52
		super(name);
53
	}
54
55
	public static Test suite() {
56
		return suite(DefaultCCommentAutoEditStrategyTest.class);
57
	}
58
59
	protected void setUp() throws Exception {
60
		super.setUp();
61
//		Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();  
62
//		shell.forceActive();
63
//		shell.forceFocus();
64
		fOptions= CCorePlugin.getOptions();
65
	}
66
67
	/*
68
	 * @see junit.framework.TestCase#tearDown()
69
	 */
70
	protected void tearDown() throws Exception {
71
		CCorePlugin.setOptions(fOptions);
72
		super.tearDown();
73
	}
74
75
	private AutoEditTester createAutoEditTester() {
76
		CTextTools textTools = CUIPlugin.getDefault().getTextTools();
77
		IDocument doc = new Document();
78
		textTools.setupCDocument(doc);
79
		AutoEditTester tester = new AutoEditTester(doc, ICPartitions.C_PARTITIONING);
80
81
82
		tester.setAutoEditStrategy(IDocument.DEFAULT_CONTENT_TYPE, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null));
83
		tester.setAutoEditStrategy(ICPartitions.C_MULTI_LINE_COMMENT, new DefaultMultilineCommentAutoEditStrategy());
84
		tester.setAutoEditStrategy(ICPartitions.C_PREPROCESSOR, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null));
85
		return tester;
86
	}
87
88
	public void testIsMultilineNew() throws BadLocationException {
89
		DefaultMultilineCommentAutoEditStrategy ds= new DefaultMultilineCommentAutoEditStrategy();
90
		CTextTools textTools = CUIPlugin.getDefault().getTextTools();
91
		IDocument doc = new Document();
92
		textTools.setupCDocument(doc);
93
94
		doc.set(" /*  ");
95
		assertTrue(ds.shouldCloseMultiline(doc, 3));
96
		doc.set(" /*  \n");
97
		assertTrue(ds.shouldCloseMultiline(doc, 3));
98
		assertTrue(ds.shouldCloseMultiline(doc, 5));
99
		doc.set(" /*  \n  ");
100
		assertTrue(ds.shouldCloseMultiline(doc, 3));
101
		assertTrue(ds.shouldCloseMultiline(doc, 6));
102
		doc.set(" /*  */");
103
		assertFalse(ds.shouldCloseMultiline(doc, 5));
104
		doc.set(" /*  */ ");
105
		assertFalse(ds.shouldCloseMultiline(doc, 5));
106
		doc.set(" /* \n\n */ ");
107
		assertFalse(ds.shouldCloseMultiline(doc, 5));
108
		doc.set(" /* \n\n */ \n /*");
109
		assertTrue(ds.shouldCloseMultiline(doc, 14));
110
		doc.set(" /* \n\n */ \n /* ");
111
		assertTrue(ds.shouldCloseMultiline(doc, 14));
112
		doc.set(" /* \n\n */ \n /* \n");
113
		assertTrue(ds.shouldCloseMultiline(doc, 14));
114
		doc.set(" /* /* \n\n */ \n /* \n");
115
		assertTrue(ds.shouldCloseMultiline(doc, 3));
116
		doc.set(" /* \n/* \n\n */ \n /* \n");
117
		assertTrue(ds.shouldCloseMultiline(doc, 3));
118
		doc.set(" /* \n\n/* \n\n */ \n /* \n");
119
		assertTrue(ds.shouldCloseMultiline(doc, 3));
120
		doc.set(" /* \n\n/* \n\n */ \n /* \n");
121
		assertTrue(ds.shouldCloseMultiline(doc, 3));
122
		doc.set(" /* \n\n                 */ /* \n\n */ \n /* \n");
123
		assertFalse(ds.shouldCloseMultiline(doc, 3));
124
		doc.set(" /*\n /*\n * \n * \n */\n");
125
		assertFalse(ds.shouldCloseMultiline(doc, 8));
126
	}
127
128
	// /*X
129
130
	// /*
131
	//  * X
132
	//  */
133
	public void testInsertNewLine1() {
134
		assertNewLineBehaviour();
135
	}
136
137
	//   /*X
138
139
	//   /*
140
	//    * X
141
	//    */
142
	public void testInsertNewLine2() {
143
		assertNewLineBehaviour();
144
	}	
145
146
	// class A {};  /*X
147
148
	// class A {};  /*
149
	// X
150
	public void testInsertNewLine3() {
151
		assertNewLineBehaviour();
152
	}
153
154
	// class A {
155
	// /*X
156
	// };  
157
158
	// class A {
159
	// /*
160
	//  * X
161
	//  */
162
	// };  
163
	public void testInsertNewLine4() {
164
		assertNewLineBehaviour();
165
	}
166
167
	// class A {
168
	// /* X
169
	// };  
170
171
	// class A {
172
	// /* 
173
	//  * X
174
	//  */
175
	// };  
176
	public void testInsertNewLine5() {
177
		assertNewLineBehaviour();
178
	}
179
180
	
181
	
182
	// class A {
183
	// /*X
184
	//  * 
185
	//  */
186
	// };
187
188
	// class A {
189
	// /*
190
	//  * X
191
	//  * 
192
	//  */
193
	// };
194
	public void testInsertNewLine6() {
195
		assertNewLineBehaviour();
196
	}
197
198
	// class A {
199
	// /*  
200
	//  *X
201
	//  */
202
	// };
203
204
	// class A {
205
	// /*  
206
	//  *
207
	//  *X
208
	//  */
209
	// };
210
	public void testInsertNewLine7() {
211
		assertNewLineBehaviour();
212
	}
213
214
	// class A {
215
	// /*  
216
	//  *X 
217
	//  */
218
	// };
219
220
	// class A {
221
	// /*  
222
	//  *
223
	//  *X 
224
	//  */
225
	// };
226
	public void testInsertNewLine8() {
227
		assertNewLineBehaviour();
228
	}
229
230
	// class A {
231
	// /*  
232
	//  * abcd def ghiX
233
	//  */
234
	// };
235
236
	// class A {
237
	// /*  
238
	//  * abcd def ghi
239
	//  * X
240
	//  */
241
	// };
242
	public void testInsertNewLine9() {
243
		assertNewLineBehaviour();
244
	}
245
246
	// class A {
247
	// /*  
248
	//  * abcd deXf ghi
249
	//  */
250
	// };
251
252
	// class A {
253
	// /*  
254
	//  * abcd de
255
	//  * Xf ghi
256
	//  */
257
	// };
258
	public void testInsertNewLine10() {
259
		assertNewLineBehaviour();
260
	}
261
262
	// class A {
263
	// /* 
264
	//  * 
265
	//  */X
266
	// };
267
268
	// class A {
269
	// /* 
270
	//  * 
271
	//  */
272
	// X
273
	// };
274
	public void _testInsertNewLine11() { // this is correct - we're not in a dccaes partition
275
		assertNewLineBehaviour();
276
	}
277
278
	// /*X*/	
279
280
	// /*
281
	//  * X 
282
	//  */
283
	public void _testInsertNewLine12() {
284
		assertNewLineBehaviour();
285
	}
286
287
	// class A {
288
	// /*Xfoo
289
	// };  
290
291
	// class A {
292
	// /*
293
	//  * X
294
	//  */foo
295
	// };  
296
	public void testInsertNewLine13() {
297
		assertNewLineBehaviour();
298
	}
299
300
	// class A {
301
	// /*fooX
302
	// };  
303
304
	// class A {
305
	// /*foo
306
	//  * X
307
	//  */
308
	// };  
309
	public void testInsertNewLine14() {
310
		assertNewLineBehaviour();
311
	}
312
313
314
	// /*
315
	//  *
316
	//  *X
317
318
	// /*
319
	//  *
320
	//  *
321
	//  *X
322
	public void testInsertNewLine15() {
323
		assertNewLineBehaviour();
324
	}
325
326
	// /*
327
	//  *
328
	//  *Xxx
329
330
	// /*
331
	//  *
332
	//  *
333
	//  *Xxx
334
	public void testInsertNewLine16() {
335
		assertNewLineBehaviour();
336
	}
337
338
	// /*
339
	//   X
340
341
	// /*
342
	//   
343
	//   X
344
	public void testInsertNewLine17() {
345
		assertNewLineBehaviour();
346
	}
347
348
	// /*
349
	//   X
350
	//  */
351
352
	// /*
353
	//   
354
	//   X
355
	//  */
356
	public void testInsertNewLine18() {
357
		assertNewLineBehaviour();
358
	}
359
360
	//        /*
361
	//         *
362
	//         */   /*X
363
364
	//        /*
365
	//         *
366
	//         */   /*
367
	//               * X
368
	//               */
369
	public void _testInsertNewLine19() {
370
		assertNewLineBehaviour();
371
	}
372
	
373
	//        /*
374
	//        /*X
375
	//         *
376
	//         */
377
378
	//        /*
379
	//        /*
380
	//         * X
381
	//         *
382
	//         */
383
	public void testInsertNewLine20() {
384
		assertNewLineBehaviour();
385
	}
386
387
388
	//
389
	//  X
390
	//
391
	//  void foo() {}
392
	public void testFollowingDeclaration1() {
393
		assertDeclarationFollowingX("void foo() {}");
394
	}
395
	
396
	//  X
397
	//
398
	//  void foo() {}
399
	//  void bar() {}
400
	public void testFollowingDeclaration1b() {
401
		assertDeclarationFollowingX("void foo() {}");
402
	}
403
404
405
	//
406
	//  X
407
	//  class C {
408
	//  void foo() {}
409
	//  };
410
	public void testFollowingDeclaration2() {
411
		assertDeclarationFollowingX("class C {\n  void foo() {}\n  };");
412
	}
413
414
	//  class C {
415
	//  X
416
	//  void foo() {}
417
	//  };
418
	public void testFollowingDeclaration3() {
419
		assertDeclarationFollowingX("void foo() {}");
420
	}
421
	
422
	//  class C {
423
	//  void foo() {X}
424
	//  void bar(int x);
425
	//  };
426
	public void testFollowingDeclaration4() {
427
		assertDeclarationFollowingX(null);
428
	}
429
430
	//  class C {
431
	//  void foo() {} X
432
	//  void bar(int x);
433
	//  };
434
	public void testFollowingDeclaration4a() {
435
		assertDeclarationFollowingX("void bar(int x);");
436
	}
437
	
438
	//  class C {
439
	//  void foo()X{}
440
	//  void bar(int x);
441
	//  };
442
	public void _testFollowingDeclaration4b() { // XXX - this is likely invalid anyhow
443
		assertDeclarationFollowingX("void foo(){}"); // (X is just the cursor position)
444
	}
445
	
446
	//  class C {
447
	//  void foo()
448
	//  X
449
	//  {
450
	//     int x;
451
	//  }
452
	//  void bar(int x);
453
	//  };
454
	public void _testFollowingDeclaration4c() { // XXX - this is likely invalid anyhow
455
		assertDeclarationFollowingX("void foo()\n  {\n     int x;\n  }\n"); // (X is just the cursor position)
456
	}
457
	
458
	//  namespace n1 { X
459
	//		namespace n2 {
460
	//  		void foo() {}
461
	//  		void bar(int x) {}
462
	//          class C {
463
	//              int y;
464
	//              void baz(int x) {}
465
	//          };
466
	//		}
467
	//  }
468
	public void _testFollowingDeclaration5() {
469
		assertDeclarationFollowingX("namespace n2 {\n  		void foo() {}\n  		void bar(int x) {}\n          class C {\n              int y;\n              void baz(int x) {}\n          };\n		}");
470
	}
471
	
472
	//  namespace n1 {
473
	//		namespace n2 {X
474
	//  		void foo() {}
475
	//  		void bar(int x) {}
476
	//          class C {
477
	//              int y;
478
	//              void baz(int x) {}
479
	//          };
480
	//		}
481
	//  }
482
	public void testFollowingDeclaration6() {
483
		assertDeclarationFollowingX("void foo() {}");
484
	}
485
	
486
	//  namespace n1 {
487
	//		namespace n2 {
488
	//  		void foo() {}X
489
	//  		void bar(int x) {}
490
	//          class C {
491
	//              int y;
492
	//              void baz(int x) {}
493
	//          };
494
	//		}
495
	//  }
496
	public void testFollowingDeclaration7() {
497
		assertDeclarationFollowingX("void bar(int x) {}");
498
	}
499
	
500
	//  namespace n1 {
501
	//		namespace n2 {
502
	//  		void foo() {}
503
	//  		void bar(int x) {}
504
	//          class C {X
505
	//              int y;
506
	//              void baz(int x) {}
507
	//          };
508
	//		}
509
	//  }
510
	public void testFollowingDeclaration8() {
511
		assertDeclarationFollowingX("int y;");
512
	}
513
	
514
	//  namespace n1 {
515
	//		namespace n2 {
516
	//  		void foo() {}
517
	//  		void bar(int x) {}
518
	//          class C {
519
	//              int y;X
520
	//              void baz(int x) {}
521
	//          };
522
	//		}
523
	//  }
524
	public void testFollowingDeclaration9() {
525
		assertDeclarationFollowingX("void baz(int x) {}");
526
	}
527
528
	//  #define MM void foo()
529
	//  X
530
	//  MM {}
531
	public void testFollowingDeclaration10() {
532
		assertDeclarationFollowingX("MM {}");
533
	}
534
	
535
	//  #define NAME foo
536
	//  #define MM(V) void V(int y)
537
	//  X
538
	//  MM(NAME) {}
539
	public void testFollowingDeclaration11() {
540
		assertDeclarationFollowingX("MM(NAME) {}");
541
	}
542
	
543
	//  #define MAKEFUNC(V) void V()
544
	//  #define B(V) V
545
	//  #define C(V) foo ## x
546
	//  X
547
	//  MAKEFUNC(B(C(y))) {}
548
	public void testFollowingDeclaration12() {
549
		assertDeclarationFollowingX("MAKEFUNC(B(C(y))) {}");
550
	}
551
	
552
	/**
553
	 * @param rs - the raw signature of the declaration that should be returned
554
	 * or <code>null</code> if no declaration should be returned.
555
	 */
556
	protected void assertDeclarationFollowingX(String rs) {
557
		try {
558
			ICProject cproject= CProjectHelper.createCCProject("test"+System.currentTimeMillis(), "bin");
559
			try {
560
				String init= getTestContents1()[0].toString(); 
561
				int caretInit= init.indexOf('X');
562
				init= init.replaceFirst("X", "");
563
				IFile file= TestSourceReader.createFile(cproject.getProject(), "this.cpp", init);
564
				IASTTranslationUnit ast= TestSourceReader.createIndexBasedAST(null, cproject, file);
565
				assertNotNull(ast);
566
				IASTDeclaration decl= DefaultMultilineCommentAutoEditStrategy.findFollowingDeclaration(ast, caretInit);
567
				if(rs!=null) {
568
					assertNotNull(decl);
569
					assertEquals(rs, decl.getRawSignature());
570
				} else {
571
					assertNull(decl);
572
				}
573
			} finally {
574
				if(cproject!=null) {
575
					cproject.getProject().delete(true, NPM);
576
				}
577
			}
578
		} catch(CoreException ce) {
579
			fail(ce.getMessage());
580
		}
581
	}
582
583
	protected void assertNewLineBehaviour() {
584
		DefaultMultilineCommentAutoEditStrategy ds= new DefaultMultilineCommentAutoEditStrategy();
585
		CTextTools textTools = CUIPlugin.getDefault().getTextTools();
586
		IDocument doc = new Document();
587
		textTools.setupCDocument(doc);
588
589
		StringBuffer[] raw= getTestContents();
590
		String init= raw[0].toString(), expected= raw[1].toString();
591
592
		int caretInit= init.indexOf('X');
593
		init= init.replaceFirst("X", "");
594
595
		int caretExpected= expected.indexOf('X');
596
		expected= expected.replaceFirst("X", "");
597
598
		doc.set(init);
599
		int caretActual= -1;
600
		try {
601
			TestDocumentCommand dc= new TestDocumentCommand(caretInit, 0, "\n");
602
			ds.customizeDocumentCommand(doc, dc);
603
			caretActual= dc.exec(doc);
604
		} catch(BadLocationException ble) {
605
			fail(ble.getMessage());
606
		}
607
		String actual= doc.get();
608
		assertEquals(expected, actual);
609
		assertEquals(caretExpected, caretActual);
610
	}
611
612
	protected StringBuffer[] getTestContents() {
613
		try {
614
			return TestSourceReader.getContentsForTest(CTestPlugin.getDefault().getBundle(), "ui", this.getClass(), getName(), 2);
615
		} catch(IOException ioe) {
616
			fail(ioe.getMessage());
617
		}
618
		return null;
619
	}
620
	
621
	protected StringBuffer[] getTestContents1() {
622
		try {
623
			return TestSourceReader.getContentsForTest(CTestPlugin.getDefault().getBundle(), "ui", this.getClass(), getName(), 1);
624
		} catch(IOException ioe) {
625
			fail(ioe.getMessage());
626
		}
627
		return null;
628
	}
629
}
(-)resources/docComments/this.cpp (+24 lines)
Added Link Here
1
// N.B: Character positions in this file are hard-coded into expected results in
2
// DocCommentHightlightTest.
3
4
/* normal0 */
5
/*A comment1___ */
6
/*B comment2__ */
7
/*C comment3_ *//*D comment4___ */
8
/*E comment5____ *//*F comment6_ */
9
/*G comment7 
10
*//*F comment8_ *//*! __comment9 */
11
/**
12
comment10
13
*/
14
15
// snormal0
16
//A scomment1__
17
//B scomment2_
18
//C scomment3__
19
//! _scomment4
20
//* scomment5___
21
22
/*# comment11_ #*/ // scomment6__
23
/*# comment12__ #*/ //# __scomment7
24
(-)ui/org/eclipse/cdt/ui/tests/text/AbstractAutoEditTest.java (+223 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
10
 *     Sergey Prigogin, Google
11
 *     Andrew Ferguson (Symbian)
12
 *******************************************************************************/
13
package org.eclipse.cdt.ui.tests.text;
14
15
import java.util.HashMap;
16
import java.util.Map;
17
18
import org.eclipse.jface.text.BadLocationException;
19
import org.eclipse.jface.text.DocumentCommand;
20
import org.eclipse.jface.text.IAutoEditStrategy;
21
import org.eclipse.jface.text.IDocument;
22
import org.eclipse.jface.text.IRegion;
23
import org.eclipse.jface.text.TextUtilities;
24
25
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
26
27
/**
28
 * IAutoEditStrategy related tests
29
 */
30
public class AbstractAutoEditTest extends BaseTestCase {
31
	
32
	AbstractAutoEditTest(String name) {
33
		super(name);
34
	}
35
	
36
	/**
37
	 * Helper class to test the auto-edit strategies on a document.
38
	 * Split out from CAutoIndentTest.
39
	 */
40
	static class AutoEditTester {
41
42
		private Map fStrategyMap = new HashMap();
43
		IDocument fDoc;
44
		private String fPartitioning;
45
		private int fCaretOffset;
46
47
		public AutoEditTester(IDocument doc, String partitioning) {
48
			super();
49
			fDoc = doc;
50
			fPartitioning = partitioning;
51
		}
52
53
		public void setAutoEditStrategy(String contentType, IAutoEditStrategy aes) {
54
			fStrategyMap.put(contentType, aes);
55
		}
56
57
		public IAutoEditStrategy getAutoEditStrategy(String contentType) {
58
			return (IAutoEditStrategy)fStrategyMap.get(contentType);
59
		}
60
61
		/**
62
		 * Empties the document, and returns the caret to the origin (0,0)
63
		 * @return <code>this</code> for method chaining
64
		 */
65
		public AutoEditTester reset() {
66
			try {
67
				goTo(0,0);
68
				fDoc.set("");
69
			} catch(BadLocationException ble) {
70
				fail(ble.getMessage());
71
			}
72
			return this;
73
		}
74
		
75
		public void type(String text) throws BadLocationException {
76
			for (int i = 0; i < text.length(); ++i) {
77
				type(text.charAt(i));
78
			}
79
		}
80
81
		public void type(char c) throws BadLocationException {
82
			TestDocumentCommand command = new TestDocumentCommand(fCaretOffset, 0, new String(new char[] { c }));
83
			customizeDocumentCommand(command);
84
			fCaretOffset = command.exec(fDoc);
85
		}
86
87
		private void customizeDocumentCommand(TestDocumentCommand command) throws BadLocationException {
88
			IAutoEditStrategy aes = getAutoEditStrategy(getContentType(command.offset));
89
			if (aes != null) {
90
				aes.customizeDocumentCommand(fDoc, command);
91
			}
92
		}
93
94
		public void type(int offset, String text) throws BadLocationException {
95
			fCaretOffset = offset;
96
			type(text);
97
		}
98
99
		public void type(int offset, char c) throws BadLocationException {
100
			fCaretOffset = offset;
101
			type(c);
102
		}
103
104
		public void paste(String text) throws BadLocationException {
105
			TestDocumentCommand command = new TestDocumentCommand(fCaretOffset, 0, text);
106
			customizeDocumentCommand(command);
107
			fCaretOffset = command.exec(fDoc);
108
		}
109
110
		public void paste(int offset, String text) throws BadLocationException {
111
			fCaretOffset = offset;
112
			paste(text);
113
		}
114
115
		public void backspace(int n) throws BadLocationException {
116
			for (int i = 0; i < n; ++i) {
117
				backspace();
118
			}
119
		}
120
		
121
		public void backspace() throws BadLocationException {
122
			TestDocumentCommand command = new TestDocumentCommand(fCaretOffset - 1, 1, ""); //$NON-NLS-1$
123
			customizeDocumentCommand(command);
124
			fCaretOffset = command.exec(fDoc);
125
		}
126
127
		public int getCaretOffset() {
128
			return fCaretOffset;
129
		}
130
131
		public int setCaretOffset(int offset) {
132
			fCaretOffset = offset;
133
			if (fCaretOffset < 0)
134
				fCaretOffset = 0;
135
			else if (fCaretOffset > fDoc.getLength())
136
				fCaretOffset = fDoc.getLength();
137
			return fCaretOffset;
138
		}
139
		
140
		/**
141
		 * Moves caret right or left by the given number of characters.
142
		 * 
143
		 * @param shift Move distance.
144
		 * @return New caret offset.
145
		 */
146
		public int moveCaret(int shift) {
147
			return setCaretOffset(fCaretOffset + shift);
148
		}
149
		
150
		public int goTo(int line) throws BadLocationException {
151
			fCaretOffset = fDoc.getLineOffset(line);
152
			return fCaretOffset;
153
		}
154
155
		public int goTo(int line, int column) throws BadLocationException {
156
			if (column < 0 || column > fDoc.getLineLength(line)) {
157
				throw new BadLocationException("No column " + column + " in line " + line); //$NON-NLS-1$ $NON-NLS-2$
158
			}
159
			fCaretOffset = fDoc.getLineOffset(line) + column;
160
			return fCaretOffset;
161
		}
162
163
		public int getCaretLine() throws BadLocationException {
164
			return fDoc.getLineOfOffset(fCaretOffset);
165
		}
166
167
		public int getCaretColumn() throws BadLocationException {
168
			IRegion region = fDoc.getLineInformationOfOffset(fCaretOffset);
169
			return fCaretOffset - region.getOffset();
170
		}
171
172
		public char getChar() throws BadLocationException {
173
			return getChar(0);
174
		}
175
		
176
		public char getChar(int i) throws BadLocationException {
177
			return fDoc.getChar(fCaretOffset+i);
178
		}
179
		
180
		public String getLine() throws BadLocationException {
181
			return getLine(0);
182
		}
183
184
		public String getLine(int i) throws BadLocationException {
185
			IRegion region = fDoc.getLineInformation(getCaretLine() + i);
186
			return fDoc.get(region.getOffset(), region.getLength());
187
		}
188
189
		public String getContentType(int offset) throws BadLocationException {
190
			return TextUtilities.getContentType(fDoc, fPartitioning, offset, true);
191
		}
192
	}
193
	
194
	/**
195
	 * A DocumentCommand with public constructor and exec method.
196
	 */
197
	static class TestDocumentCommand extends DocumentCommand {
198
199
		public TestDocumentCommand(int offset, int length, String text) {
200
			super();
201
			doit = true;
202
			this.text = text;
203
204
			this.offset = offset;
205
			this.length = length;
206
207
			owner = null;
208
			caretOffset = -1;
209
		}
210
211
		/**
212
		 * @param doc
213
		 * @return the new caret position.
214
		 * @throws BadLocationException
215
		 */
216
		public int exec(IDocument doc) throws BadLocationException {
217
			doc.replace(offset, length, text);
218
			return caretOffset != -1 ?
219
						caretOffset :
220
						offset + (text == null ? 0 : text.length());
221
		}
222
	}
223
}
(-)ui/org/eclipse/cdt/ui/tests/text/doctools/CommentOwnerManagerTests.java (+126 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * Andrew Ferguson (Symbian) - Initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.tests.text.doctools;
12
13
import junit.framework.Test;
14
import junit.framework.TestSuite;
15
16
import org.eclipse.cdt.core.model.ICProject;
17
import org.eclipse.cdt.core.testplugin.CProjectHelper;
18
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
19
import org.eclipse.cdt.ui.text.doctools.IDocCommentOwner;
20
21
import org.eclipse.cdt.internal.ui.text.doctools.DocCommentOwnerManager;
22
import org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentOwner;
23
24
/**
25
 * Test comment ownership mapping
26
 */
27
public class CommentOwnerManagerTests extends BaseTestCase {
28
	IDocCommentOwner OWNER_1;
29
	IDocCommentOwner OWNER_2;
30
	IDocCommentOwner OWNER_3;
31
	DocCommentOwnerManager manager;
32
	
33
	ICProject projectA, projectB, projectC;
34
	
35
	protected void setUp() throws Exception {
36
		manager= DocCommentOwnerManager.getInstance();
37
		
38
		projectA= CProjectHelper.createCCProject("projectA", null);
39
		projectB= CProjectHelper.createCCProject("projectB", null);
40
		projectC= CProjectHelper.createCCProject("projectC", null);
41
		
42
		IDocCommentOwner[] owners= manager.getRegisteredOwners();
43
		OWNER_1= manager.getOwner("org.cdt.test.DCOM1");
44
		OWNER_2= manager.getOwner("org.cdt.test.DCOM2");
45
		OWNER_3= manager.getOwner("org.cdt.test.DCOM3");
46
	}
47
	
48
	protected void tearDown() throws Exception {
49
		if(projectA != null) {
50
			CProjectHelper.delete(projectA);
51
		}
52
		if(projectB != null) {
53
			CProjectHelper.delete(projectB);
54
		}
55
		if(projectC != null) {
56
			CProjectHelper.delete(projectC);			
57
		}
58
	}
59
	
60
	public static Test suite() {
61
		return new TestSuite(CommentOwnerManagerTests.class);
62
	}
63
	
64
	public void testProjectLevel() throws Exception {
65
		manager.setCommentOwner(projectA.getProject(), OWNER_3, true);
66
		manager.setCommentOwner(projectB.getProject(), OWNER_2, true);
67
		manager.setCommentOwner(projectC.getProject(), OWNER_1, true);
68
		
69
		assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectA.getProject()).getID());
70
		assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID());
71
		assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID());
72
		
73
		assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject()).getID());
74
		assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID());
75
		assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID());
76
77
		assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject()).getID());
78
		assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID());
79
		assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID());
80
		
81
		manager.setCommentOwner(projectA.getProject(), OWNER_2, true);
82
		manager.setCommentOwner(projectB.getProject(), OWNER_1, true);
83
		manager.setCommentOwner(projectC.getProject(), OWNER_3, true);
84
		
85
		assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject()).getID());
86
		assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID());
87
		assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID());
88
		
89
		assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject()).getID());
90
		assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID());
91
		assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID());
92
93
		assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject()).getID());
94
		assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID());
95
		assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID());
96
		
97
		projectA.getProject().close(NPM);
98
		projectB.getProject().close(NPM);
99
		projectC.getProject().close(NPM);
100
		
101
		projectA.getProject().open(NPM);
102
		projectB.getProject().open(NPM);
103
		projectC.getProject().open(NPM);
104
		
105
		assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject()).getID());
106
		assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject().getFile("foo/bar/baz")).getID());
107
		assertEquals(OWNER_2.getID(), manager.getCommentOwner(projectA.getProject().getFolder("foo/bar")).getID());
108
		
109
		assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject()).getID());
110
		assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject().getFile("foo/bar/baz")).getID());
111
		assertEquals(OWNER_1.getID(), manager.getCommentOwner(projectB.getProject().getFolder("foo/bar")).getID());
112
113
		assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject()).getID());
114
		assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject().getFile("foo/bar/baz")).getID());
115
		assertEquals(OWNER_3.getID(), manager.getCommentOwner(projectC.getProject().getFolder("foo/bar")).getID());
116
	}
117
	
118
	public void testBoundaryConditions() throws Exception {
119
		DocCommentOwnerManager manager= DocCommentOwnerManager.getInstance();
120
		assertEquals(NullDocCommentOwner.INSTANCE.getID(), manager.getCommentOwner(null).getID());
121
	}
122
	
123
	public void testWorkspaceRootLevel() throws Exception {
124
		// TODO
125
	}
126
}

Return to bug 208881