|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
|
2 // Use of this source code is governed by a BSD-style license that can be |
|
3 // found in the LICENSE file. |
|
4 |
|
5 package org.chromium.debug.ui.editors; |
|
6 |
|
7 import org.eclipse.jface.text.IDocument; |
|
8 import org.eclipse.jface.text.ITextHover; |
|
9 import org.eclipse.jface.text.TextAttribute; |
|
10 import org.eclipse.jface.text.presentation.IPresentationReconciler; |
|
11 import org.eclipse.jface.text.presentation.PresentationReconciler; |
|
12 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner; |
|
13 import org.eclipse.jface.text.rules.DefaultDamagerRepairer; |
|
14 import org.eclipse.jface.text.rules.Token; |
|
15 import org.eclipse.jface.text.source.ISourceViewer; |
|
16 import org.eclipse.ui.editors.text.TextSourceViewerConfiguration; |
|
17 |
|
18 /** |
|
19 * A JavaScript source viewer configuration. |
|
20 */ |
|
21 public class JsSourceViewerConfiguration extends TextSourceViewerConfiguration { |
|
22 |
|
23 private static class MultilineCommentScanner extends BufferedRuleBasedScanner { |
|
24 public MultilineCommentScanner(TextAttribute attr) { |
|
25 setDefaultReturnToken(new Token(attr)); |
|
26 } |
|
27 } |
|
28 |
|
29 private static final String[] CONTENT_TYPES = new String[] { |
|
30 IDocument.DEFAULT_CONTENT_TYPE, |
|
31 JsPartitionScanner.JSDOC, |
|
32 JsPartitionScanner.MULTILINE_COMMENT |
|
33 }; |
|
34 |
|
35 private final JsCodeScanner scanner = new JsCodeScanner(); |
|
36 |
|
37 @Override |
|
38 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) { |
|
39 return new JsDebugTextHover(); |
|
40 } |
|
41 |
|
42 @Override |
|
43 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { |
|
44 PresentationReconciler pr = new PresentationReconciler(); |
|
45 pr.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); |
|
46 setDamagerRepairer(pr, new DefaultDamagerRepairer(scanner), IDocument.DEFAULT_CONTENT_TYPE); |
|
47 setDamagerRepairer( |
|
48 pr, new DefaultDamagerRepairer(new MultilineCommentScanner(scanner.getCommentAttribute())), |
|
49 JsPartitionScanner.MULTILINE_COMMENT); |
|
50 setDamagerRepairer( |
|
51 pr, new DefaultDamagerRepairer(new MultilineCommentScanner(scanner.getJsDocAttribute())), |
|
52 JsPartitionScanner.JSDOC); |
|
53 return pr; |
|
54 } |
|
55 |
|
56 private void setDamagerRepairer( |
|
57 PresentationReconciler pr, |
|
58 DefaultDamagerRepairer damagerRepairer, |
|
59 String tokenType) { |
|
60 pr.setDamager(damagerRepairer, tokenType); |
|
61 pr.setRepairer(damagerRepairer, tokenType); |
|
62 } |
|
63 |
|
64 @Override |
|
65 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { |
|
66 return CONTENT_TYPES; |
|
67 } |
|
68 |
|
69 } |