View | Details | Raw Unified | Return to bug 335309
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java (-1 / +11 lines)
Lines 62-68 Link Here
62
	Map formatterOptions;
62
	Map formatterOptions;
63
63
64
	static {
64
	static {
65
//		TESTS_NUMBERS = new int[] { 736 };
65
//		TESTS_NUMBERS = new int[] { 738 };
66
//		TESTS_RANGE = new int[] { 734, -1 };
66
//		TESTS_RANGE = new int[] { 734, -1 };
67
	}
67
	}
68
	public static Test suite() {
68
	public static Test suite() {
Lines 11102-11105 Link Here
11102
		"}\n"
11102
		"}\n"
11103
	);
11103
	);
11104
}
11104
}
11105
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=332843
11106
public void test738() {
11107
	final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
11108
	DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
11109
	DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
11110
	IRegion[] regions = new IRegion[] {
11111
			new Region(705, 0)
11112
	};
11113
	runTest(codeFormatter, "test738", "RecipeDocumentProvider.java", CodeFormatter.K_COMPILATION_UNIT, 0, true, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
11114
}
11105
}
11115
}
(-)workspace/Formatter/test738/RecipeDocumentProvider_in.java (+62 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.recipeeditor;
12
13
import org.eclipse.jface.text.IDocument;
14
import org.eclipse.jface.text.IDocumentExtension3;
15
import org.eclipse.jface.text.IDocumentPartitioner;
16
import org.eclipse.jface.text.rules.FastPartitioner;
17
import org.eclipse.jface.text.rules.IPredicateRule;
18
import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
19
import org.eclipse.jface.text.rules.SingleLineRule;
20
import org.eclipse.jface.text.rules.Token;
21
import org.eclipse.ui.editors.text.FileDocumentProvider;
22
23
public class RecipeDocumentProvider extends FileDocumentProvider {
24
	/**
25
	 * The recipe partitioning. It contains two partition types: {@link #RECIPE_CODE} and
26
	 * {@link #RECIPE_COMMENT}.
27
	 */
28
	public static final String RECIPE_PARTITIONING= "org.recipeeditor.recipepartitioning"; //$NON-NLS-1$
29
30
	/**
31
	 * The identifier of the comment body type.
32
	 */
33
	public static final String RECIPE_CODE= IDocument.DEFAULT_CONTENT_TYPE;
34
	/**
35
	 * The identifier of the comment partition type.
36
	 */
37
	public static final String RECIPE_COMMENT= "RECIPE_COMMENT"; //$NON-NLS-1$
38
	
39
	private static final String[] CONTENT_TYPES= {
40
			RECIPE_CODE,
41
			RECIPE_COMMENT
42
	};
43
44
	protected void setupDocument(Object element,IDocument document) {
45
		if (document instanceof IDocumentExtension3) {
46
			IDocumentExtension3 ext= (IDocumentExtension3) document;
47
			IDocumentPartitioner partitioner= createRecipePartitioner();
48
			ext.setDocumentPartitioner(RECIPE_PARTITIONING, partitioner);
49
			partitioner.connect(document);
50
		}
51
	}
52
53
	private IDocumentPartitioner createRecipePartitioner() {
54
		IPredicateRule[] rules= { new SingleLineRule("#", null, new Token(RECIPE_COMMENT), (char) 0, true, false) }; //$NON-NLS-1$
55
56
		RuleBasedPartitionScanner scanner= new RuleBasedPartitionScanner();
57
		scanner.setPredicateRules(rules);
58
		
59
		return new FastPartitioner(scanner, CONTENT_TYPES);
60
	}
61
62
}
(-)workspace/Formatter/test738/RecipeDocumentProvider_out.java (+62 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.recipeeditor;
12
13
import org.eclipse.jface.text.IDocument;
14
import org.eclipse.jface.text.IDocumentExtension3;
15
import org.eclipse.jface.text.IDocumentPartitioner;
16
import org.eclipse.jface.text.rules.FastPartitioner;
17
import org.eclipse.jface.text.rules.IPredicateRule;
18
import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
19
import org.eclipse.jface.text.rules.SingleLineRule;
20
import org.eclipse.jface.text.rules.Token;
21
import org.eclipse.ui.editors.text.FileDocumentProvider;
22
23
public class RecipeDocumentProvider extends FileDocumentProvider {
24
	/**
25
	 * The recipe partitioning. It contains two partition types: {@link #RECIPE_CODE} and
26
	 * {@link #RECIPE_COMMENT}.
27
	 */
28
	public static final String RECIPE_PARTITIONING= "org.recipeeditor.recipepartitioning"; //$NON-NLS-1$
29
30
	/**
31
	 * The identifier of the comment body type.
32
	 */
33
	public static final String RECIPE_CODE= IDocument.DEFAULT_CONTENT_TYPE;
34
	/**
35
	 * The identifier of the comment partition type.
36
	 */
37
	public static final String RECIPE_COMMENT= "RECIPE_COMMENT"; //$NON-NLS-1$
38
	
39
	private static final String[] CONTENT_TYPES= {
40
			RECIPE_CODE,
41
			RECIPE_COMMENT
42
	};
43
44
	protected void setupDocument(Object element,IDocument document) {
45
		if (document instanceof IDocumentExtension3) {
46
			IDocumentExtension3 ext= (IDocumentExtension3) document;
47
			IDocumentPartitioner partitioner= createRecipePartitioner();
48
			ext.setDocumentPartitioner(RECIPE_PARTITIONING, partitioner);
49
			partitioner.connect(document);
50
		}
51
	}
52
53
	private IDocumentPartitioner createRecipePartitioner() {
54
		IPredicateRule[] rules= { new SingleLineRule("#", null, new Token(RECIPE_COMMENT), (char) 0, true, false) }; //$NON-NLS-1$
55
56
		RuleBasedPartitionScanner scanner= new RuleBasedPartitionScanner();
57
		scanner.setPredicateRules(rules);
58
		
59
		return new FastPartitioner(scanner, CONTENT_TYPES);
60
	}
61
62
}

Return to bug 335309