Skip to main content
summaryrefslogtreecommitdiffstats
blob: cd173a7d5d8e30e4f7705f3f197e8de9e95d4bf8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * <copyright>
 *
 * Copyright (c) 2005-2006 Sven Efftinge and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Sven Efftinge - Initial API and implementation
 *
 * </copyright>
 */

package org.eclipse.xtend.ui.editor;

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.ITokenScanner;
import org.eclipse.jface.text.source.IAnnotationHover;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.ui.IEditorPart;
import org.eclipse.xtend.shared.ui.core.builder.XtendXpandProblemHover;
import org.eclipse.xtend.shared.ui.editor.AbstractXtendXandSourceViewerConfiguration;
import org.eclipse.xtend.ui.editor.codeassist.XtendContentAssistProcessor;
import org.eclipse.xtend.ui.editor.scanning.CommentScanner;
import org.eclipse.xtend.ui.editor.scanning.ContentScanner;
import org.eclipse.xtend.ui.editor.scanning.StringLiteralScanner;
import org.eclipse.xtend.ui.editor.scanning.XtendPartitionScanner;

public class XtendSourceViewerConfiguration extends AbstractXtendXandSourceViewerConfiguration {

	private ContentScanner contentScanner;

	private CommentScanner commentScanner;

	private StringLiteralScanner stringLiteralScanner;

	public XtendSourceViewerConfiguration(final IEditorPart editor) {
		super(editor);
	}

	@Override
	public String[] getConfiguredContentTypes(final ISourceViewer aSourceViewer) {
		return new String[] { IDocument.DEFAULT_CONTENT_TYPE, XtendPartitionScanner.COMMENT,
				XtendPartitionScanner.STRING_LIT };
	}

	@Override
	protected void createContentAssistProcessor(ContentAssistant contentAssistant) {
		final XtendContentAssistProcessor processor = new XtendContentAssistProcessor(getEditor());
		contentAssistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE);
	}

	@Override
	public String[] getIndentPrefixes(final ISourceViewer aSourceViewer, final String aContentType) {
		return new String[] { "\t", "    " }; // see also 'getTabWidth' ...
	}

	@Override
	public IPresentationReconciler getPresentationReconciler(final ISourceViewer aSourceViewer) {
		final PresentationReconciler reconciler = new PresentationReconciler();
		DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getCommentScanner());
		reconciler.setDamager(dr, XtendPartitionScanner.COMMENT);
		reconciler.setRepairer(dr, XtendPartitionScanner.COMMENT);

		dr = new DefaultDamagerRepairer(getStringLiteralScanner());
		reconciler.setDamager(dr, XtendPartitionScanner.STRING_LIT);
		reconciler.setRepairer(dr, XtendPartitionScanner.STRING_LIT);

		dr = new DefaultDamagerRepairer(getContentScanner());
		reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
		reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
		return reconciler;
	}

	private CommentScanner getCommentScanner() {
		if (commentScanner == null) {
			commentScanner = new CommentScanner();
		}
		return commentScanner;
	}

	private StringLiteralScanner getStringLiteralScanner() {
		if (stringLiteralScanner == null) {
			stringLiteralScanner = new StringLiteralScanner();
		}
		return stringLiteralScanner;
	}

	protected ITokenScanner getContentScanner() {
		if (contentScanner == null) {
			contentScanner = new ContentScanner();
		}
		return contentScanner;
	}

	@Override
	public IAnnotationHover getAnnotationHover(final ISourceViewer sourceViewer) {
		return new XtendXpandProblemHover(sourceViewer);
	}

	@Override
	public ITextHover getTextHover(final ISourceViewer sourceViewer, final String contentType) {
		return new XtendXpandProblemHover(sourceViewer);
	}

}

Back to the top