diff options
author | Adrian Dudau <adrian.dudau@enea.com> | 2014-06-26 13:23:09 +0200 |
---|---|---|
committer | Adrian Dudau <adrian.dudau@enea.com> | 2014-06-26 13:24:09 +0200 |
commit | c7da892cb23d50d4d85746c9a0b6b14bf570989d (patch) | |
tree | e7136073f386d6156f51766c498c52c30c8df85f /plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeSourceViewerConfiguration.java | |
download | eclipse-poky-kepler-c7da892cb23d50d4d85746c9a0b6b14bf570989d.tar.gz |
initial commit for Enea Linux 4.0daisy
Migrated from the internal git server on the daisy-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeSourceViewerConfiguration.java')
-rw-r--r-- | plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeSourceViewerConfiguration.java | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeSourceViewerConfiguration.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeSourceViewerConfiguration.java new file mode 100644 index 0000000..87a51d2 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeSourceViewerConfiguration.java | |||
@@ -0,0 +1,210 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2013 Ken Gilmer, Intel Corporation | ||
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 | * Ken Gilmer - initial API and implementation | ||
10 | * Ioana Grigoropol (Intel) - adapt class for remote support | ||
11 | *******************************************************************************/ | ||
12 | package org.yocto.bc.ui.editors.bitbake; | ||
13 | |||
14 | import java.net.URI; | ||
15 | import java.net.URISyntaxException; | ||
16 | |||
17 | import org.eclipse.core.resources.IFile; | ||
18 | import org.eclipse.jface.preference.IPreferenceStore; | ||
19 | import org.eclipse.jface.text.ITextHover; | ||
20 | import org.eclipse.jface.text.TextAttribute; | ||
21 | import org.eclipse.jface.text.contentassist.ContentAssistant; | ||
22 | import org.eclipse.jface.text.contentassist.IContentAssistant; | ||
23 | import org.eclipse.jface.text.presentation.IPresentationReconciler; | ||
24 | import org.eclipse.jface.text.presentation.PresentationReconciler; | ||
25 | import org.eclipse.jface.text.reconciler.IReconciler; | ||
26 | import org.eclipse.jface.text.rules.DefaultDamagerRepairer; | ||
27 | import org.eclipse.jface.text.rules.IRule; | ||
28 | import org.eclipse.jface.text.rules.IToken; | ||
29 | import org.eclipse.jface.text.rules.IWordDetector; | ||
30 | import org.eclipse.jface.text.rules.RuleBasedScanner; | ||
31 | import org.eclipse.jface.text.rules.SingleLineRule; | ||
32 | import org.eclipse.jface.text.rules.Token; | ||
33 | import org.eclipse.jface.text.rules.WordRule; | ||
34 | import org.eclipse.jface.text.source.ISharedTextColors; | ||
35 | import org.eclipse.jface.text.source.ISourceViewer; | ||
36 | import org.eclipse.swt.SWT; | ||
37 | import org.eclipse.swt.graphics.Color; | ||
38 | import org.eclipse.swt.graphics.RGB; | ||
39 | import org.eclipse.ui.editors.text.TextSourceViewerConfiguration; | ||
40 | import org.yocto.bc.bitbake.BBLanguageHelper; | ||
41 | import org.yocto.bc.bitbake.BBSession; | ||
42 | |||
43 | public class BitBakeSourceViewerConfiguration extends TextSourceViewerConfiguration { | ||
44 | |||
45 | private static final class WordDetector implements IWordDetector { | ||
46 | public boolean isWordPart(char c) { | ||
47 | return !Character.isWhitespace(c); | ||
48 | } | ||
49 | |||
50 | public boolean isWordStart(char c) { | ||
51 | return !Character.isWhitespace(c); | ||
52 | } | ||
53 | } | ||
54 | |||
55 | private final ISharedTextColors fSharedColors; | ||
56 | private BBSession session; | ||
57 | private IFile targetFile; | ||
58 | private BBVariableTextHover textHover = null; | ||
59 | |||
60 | public BitBakeSourceViewerConfiguration(ISharedTextColors sharedColors, IPreferenceStore store) { | ||
61 | super(store); | ||
62 | fSharedColors = sharedColors; | ||
63 | } | ||
64 | |||
65 | protected void setTargetFile(IFile targetFile) { | ||
66 | this.targetFile = targetFile; | ||
67 | } | ||
68 | |||
69 | public ITextHover getTextHover(ISourceViewer sv, String contentType) { | ||
70 | //only .bb file support Text Hover. | ||
71 | if (textHover == null && targetFile.getFileExtension().equals(BBLanguageHelper.BITBAKE_RECIPE_FILE_EXTENSION)) { | ||
72 | URI root = session.getProjInfoRoot(); | ||
73 | try { | ||
74 | String targetFileProjPath = targetFile.getProjectRelativePath().toPortableString(); | ||
75 | URI targetFileURI = new URI(root.getScheme(), root.getHost(), root.getPath() + "/" + | ||
76 | targetFileProjPath, root.getFragment()); | ||
77 | textHover = new BBVariableTextHover(session, targetFileURI); | ||
78 | } catch (URISyntaxException e) { | ||
79 | e.printStackTrace(); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | return textHover; | ||
84 | } | ||
85 | |||
86 | private void addDamagerRepairer(PresentationReconciler reconciler, RuleBasedScanner commentScanner, String contentType) { | ||
87 | DefaultDamagerRepairer commentDamagerRepairer = new DefaultDamagerRepairer(commentScanner); | ||
88 | reconciler.setDamager(commentDamagerRepairer, contentType); | ||
89 | reconciler.setRepairer(commentDamagerRepairer, contentType); | ||
90 | } | ||
91 | |||
92 | private RuleBasedScanner createCommentScanner() { | ||
93 | Color green = fSharedColors.getColor(new RGB(16, 96, 16)); | ||
94 | RuleBasedScanner commentScanner = new RuleBasedScanner(); | ||
95 | commentScanner.setDefaultReturnToken(new Token(new TextAttribute(green, null, SWT.ITALIC))); | ||
96 | return commentScanner; | ||
97 | } | ||
98 | |||
99 | private IRule createCustomFunctionRule() { | ||
100 | Color blue = fSharedColors.getColor(new RGB(130, 0, 0)); | ||
101 | IRule rule = new CustomFunctionRule(new Token(new TextAttribute(blue, null, SWT.BOLD))); | ||
102 | |||
103 | return rule; | ||
104 | } | ||
105 | |||
106 | private SingleLineRule createFunctionNameRule() { | ||
107 | Color red = fSharedColors.getColor(new RGB(150, 0, 96)); | ||
108 | SingleLineRule stepRule = new SingleLineRule("do_", ")", new Token(new TextAttribute(red, null, SWT.BOLD))); //$NON-NLS-1$ //$NON-NLS-2$ | ||
109 | stepRule.setColumnConstraint(0); | ||
110 | return stepRule; | ||
111 | } | ||
112 | |||
113 | private SingleLineRule createInlineVariableRule() { | ||
114 | Color blue = fSharedColors.getColor(new RGB(50, 50, 100)); | ||
115 | SingleLineRule stepRule = new SingleLineRule("${", "}", new Token(new TextAttribute(blue, null, SWT.BOLD))); //$NON-NLS-1$ //$NON-NLS-2$ | ||
116 | return stepRule; | ||
117 | } | ||
118 | |||
119 | private WordRule createKeywordRule() { | ||
120 | WordRule keywordRule = new WordRule(new WordDetector()); | ||
121 | IToken token = new Token(new TextAttribute(fSharedColors.getColor(new RGB(96, 96, 0)), null, SWT.NONE)); | ||
122 | |||
123 | for (int i = 0; i < BBLanguageHelper.BITBAKE_KEYWORDS.length; ++i) { | ||
124 | |||
125 | keywordRule.addWord(BBLanguageHelper.BITBAKE_KEYWORDS[i], token); | ||
126 | keywordRule.setColumnConstraint(0); | ||
127 | } | ||
128 | |||
129 | return keywordRule; | ||
130 | } | ||
131 | |||
132 | private RuleBasedScanner createRecipeScanner() { | ||
133 | RuleBasedScanner recipeScanner = new RuleBasedScanner(); | ||
134 | |||
135 | IRule[] rules = { createKeywordRule(), createShellKeywordRule(), createStringLiteralRule(), createVariableRule(), createFunctionNameRule(), createCustomFunctionRule(), | ||
136 | createInlineVariableRule() }; | ||
137 | recipeScanner.setRules(rules); | ||
138 | return recipeScanner; | ||
139 | } | ||
140 | |||
141 | private WordRule createShellKeywordRule() { | ||
142 | WordRule keywordRule = new WordRule(new WordDetector()); | ||
143 | IToken token = new Token(new TextAttribute(fSharedColors.getColor(new RGB(0, 64, 92)), null, SWT.NONE)); | ||
144 | |||
145 | for (int i = 0; i < BBLanguageHelper.SHELL_KEYWORDS.length; ++i) { | ||
146 | keywordRule.addWord(BBLanguageHelper.SHELL_KEYWORDS[i], token); | ||
147 | } | ||
148 | |||
149 | return keywordRule; | ||
150 | } | ||
151 | |||
152 | private SingleLineRule createStringLiteralRule() { | ||
153 | Color red = fSharedColors.getColor(new RGB(50, 50, 100)); | ||
154 | SingleLineRule rule = new SingleLineRule("\"", "\"", new Token(new TextAttribute(red, null, SWT.NONE)), '\\'); | ||
155 | |||
156 | return rule; | ||
157 | } | ||
158 | |||
159 | private IRule createVariableRule() { | ||
160 | Color blue = fSharedColors.getColor(new RGB(0, 0, 200)); | ||
161 | IRule rule = new VariableRule(new Token(new TextAttribute(blue, null, SWT.NONE))); | ||
162 | |||
163 | return rule; | ||
164 | } | ||
165 | |||
166 | @Override | ||
167 | public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { | ||
168 | return new String[] { BitBakeDocumentProvider.RECIPE_CODE, BitBakeDocumentProvider.RECIPE_COMMENT }; | ||
169 | } | ||
170 | |||
171 | @Override | ||
172 | public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) { | ||
173 | return BitBakeDocumentProvider.RECIPE_PARTITIONING; | ||
174 | } | ||
175 | |||
176 | @Override | ||
177 | public IContentAssistant getContentAssistant(final ISourceViewer sourceViewer) { | ||
178 | ContentAssistant assistant = new ContentAssistant(); | ||
179 | assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); | ||
180 | |||
181 | // assistant.setContentAssistProcessor(new HippieProposalProcessor(), | ||
182 | // BitBakeDocumentProvider.RECIPE_COMMENT); | ||
183 | assistant.setContentAssistProcessor(new RecipeCompletionProcessor(), BitBakeDocumentProvider.RECIPE_CODE); | ||
184 | |||
185 | return assistant; | ||
186 | } | ||
187 | |||
188 | public IReconciler getReconciler(ISourceViewer sourceViewer) { | ||
189 | return null; | ||
190 | } | ||
191 | |||
192 | @Override | ||
193 | public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { | ||
194 | PresentationReconciler reconciler = new PresentationReconciler(); | ||
195 | reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); | ||
196 | |||
197 | addDamagerRepairer(reconciler, createCommentScanner(), BitBakeDocumentProvider.RECIPE_COMMENT); | ||
198 | addDamagerRepairer(reconciler, createRecipeScanner(), BitBakeDocumentProvider.RECIPE_CODE); | ||
199 | |||
200 | return reconciler; | ||
201 | } | ||
202 | |||
203 | public void setBBSession(BBSession session) { | ||
204 | this.session = session; | ||
205 | } | ||
206 | |||
207 | public BBSession getBBSession() { | ||
208 | return this.session; | ||
209 | } | ||
210 | } | ||