diff options
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors')
10 files changed, 822 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BBVariableTextHover.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BBVariableTextHover.java new file mode 100644 index 0000000..9478423 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BBVariableTextHover.java | |||
@@ -0,0 +1,118 @@ | |||
1 | /** | ||
2 | * | ||
3 | */ | ||
4 | package org.yocto.bc.ui.editors.bitbake; | ||
5 | |||
6 | import java.io.File; | ||
7 | import java.util.Map; | ||
8 | |||
9 | import org.eclipse.core.runtime.IProgressMonitor; | ||
10 | import org.eclipse.core.runtime.IStatus; | ||
11 | import org.eclipse.core.runtime.Status; | ||
12 | import org.eclipse.core.runtime.jobs.Job; | ||
13 | import org.eclipse.jface.text.IRegion; | ||
14 | import org.eclipse.jface.text.ITextHover; | ||
15 | import org.eclipse.jface.text.ITextViewer; | ||
16 | import org.eclipse.jface.text.Region; | ||
17 | |||
18 | import org.yocto.bc.bitbake.BBRecipe; | ||
19 | import org.yocto.bc.bitbake.BBSession; | ||
20 | import org.yocto.bc.ui.Activator; | ||
21 | |||
22 | /** | ||
23 | * Maps BB Variables in the editor to BBSession | ||
24 | * @author kgilmer | ||
25 | * | ||
26 | */ | ||
27 | class BBVariableTextHover implements ITextHover { | ||
28 | private final BBSession session; | ||
29 | private volatile Map envMap; | ||
30 | |||
31 | public BBVariableTextHover(BBSession session, String file) { | ||
32 | this.session = session; | ||
33 | envMap = session; | ||
34 | LoadRecipeJob loadRecipeJob = new LoadRecipeJob(getFilename(file), file); | ||
35 | loadRecipeJob.schedule(); | ||
36 | } | ||
37 | |||
38 | private String getFilename(String file) { | ||
39 | |||
40 | String [] elems = file.split(File.separator); | ||
41 | |||
42 | return elems[elems.length - 1]; | ||
43 | } | ||
44 | |||
45 | public IRegion getHoverRegion(ITextViewer tv, int off) { | ||
46 | return new Region(off, 0); | ||
47 | } | ||
48 | |||
49 | public String getHoverInfo(ITextViewer tv, IRegion r) { | ||
50 | try { | ||
51 | IRegion lineRegion = tv.getDocument().getLineInformationOfOffset(r.getOffset()); | ||
52 | |||
53 | return getBBVariable(tv.getDocument().get(lineRegion.getOffset(), lineRegion.getLength()).toCharArray(), r.getOffset() - lineRegion.getOffset()); | ||
54 | } catch (Exception e) { | ||
55 | return ""; | ||
56 | } | ||
57 | } | ||
58 | |||
59 | private String getBBVariable(char[] line, int offset) { | ||
60 | // Find start of word. | ||
61 | int i = offset; | ||
62 | |||
63 | while (line[i] != ' ' && line[i] != '$' && i > 0) { | ||
64 | i--; | ||
65 | } | ||
66 | |||
67 | if (i < 0 || line[i] != '$') { | ||
68 | return ""; //this is not a BB variable. | ||
69 | } | ||
70 | |||
71 | // find end of word | ||
72 | int start = i; | ||
73 | i = offset; | ||
74 | |||
75 | while (line[i] != ' ' && line[i] != '}' && i <= line.length) { | ||
76 | i++; | ||
77 | } | ||
78 | |||
79 | if (line[i] != '}') { | ||
80 | return ""; //this bb variable didn't terminate as expected | ||
81 | } | ||
82 | |||
83 | String key = new String(line, start + 2, i - start - 2); | ||
84 | String val = (String) envMap.get(key); | ||
85 | |||
86 | if (val == null) { | ||
87 | val = ""; | ||
88 | } | ||
89 | |||
90 | if (val.length() > 64) { | ||
91 | val = val.substring(0, 64) + '\n' + val.substring(65); | ||
92 | } | ||
93 | |||
94 | return val; | ||
95 | } | ||
96 | |||
97 | private class LoadRecipeJob extends Job { | ||
98 | private final String filePath; | ||
99 | |||
100 | public LoadRecipeJob(String name, String filePath) { | ||
101 | super("Extracting BitBake environment for " + name); | ||
102 | this.filePath = filePath; | ||
103 | } | ||
104 | |||
105 | @Override | ||
106 | protected IStatus run(IProgressMonitor mon) { | ||
107 | try { | ||
108 | BBRecipe recipe = Activator.getBBRecipe(session, filePath); | ||
109 | recipe.initialize(); | ||
110 | envMap = recipe; | ||
111 | } catch (Exception e) { | ||
112 | return new Status(IStatus.WARNING, Activator.PLUGIN_ID, "Unable to load session for " + filePath, e); | ||
113 | } | ||
114 | |||
115 | return Status.OK_STATUS; | ||
116 | } | ||
117 | } | ||
118 | } \ No newline at end of file | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeDocumentProvider.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeDocumentProvider.java new file mode 100644 index 0000000..4713bc3 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeDocumentProvider.java | |||
@@ -0,0 +1,62 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2009 Ken Gilmer | ||
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 | *******************************************************************************/ | ||
11 | package org.yocto.bc.ui.editors.bitbake; | ||
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 | /** | ||
24 | * Document provider for BB recipe. | ||
25 | * @author kgilmer | ||
26 | * | ||
27 | */ | ||
28 | public class BitBakeDocumentProvider extends FileDocumentProvider { | ||
29 | /** | ||
30 | * The recipe partitioning. It contains two partition types: {@link #RECIPE_CODE} and | ||
31 | * {@link #RECIPE_COMMENT}. | ||
32 | */ | ||
33 | public static final String RECIPE_PARTITIONING= "org.recipeeditor.recipepartitioning"; //$NON-NLS-1$ | ||
34 | |||
35 | public static final String RECIPE_CODE= IDocument.DEFAULT_CONTENT_TYPE; | ||
36 | public static final String RECIPE_COMMENT= "RECIPE_COMMENT"; //$NON-NLS-1$ | ||
37 | |||
38 | private static final String[] CONTENT_TYPES= { | ||
39 | RECIPE_CODE, | ||
40 | RECIPE_COMMENT | ||
41 | }; | ||
42 | |||
43 | private IDocumentPartitioner createRecipePartitioner() { | ||
44 | IPredicateRule[] rules= { new SingleLineRule("#", null, new Token(RECIPE_COMMENT), (char) 0, true, false) }; //$NON-NLS-1$ | ||
45 | |||
46 | RuleBasedPartitionScanner scanner= new RuleBasedPartitionScanner(); | ||
47 | scanner.setPredicateRules(rules); | ||
48 | |||
49 | return new FastPartitioner(scanner, CONTENT_TYPES); | ||
50 | } | ||
51 | |||
52 | @Override | ||
53 | protected void setupDocument(Object element,IDocument document) { | ||
54 | if (document instanceof IDocumentExtension3) { | ||
55 | IDocumentExtension3 ext= (IDocumentExtension3) document; | ||
56 | IDocumentPartitioner partitioner= createRecipePartitioner(); | ||
57 | ext.setDocumentPartitioner(RECIPE_PARTITIONING, partitioner); | ||
58 | partitioner.connect(document); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | } | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeFileEditor.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeFileEditor.java new file mode 100644 index 0000000..b33f030 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeFileEditor.java | |||
@@ -0,0 +1,75 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2009 Ken Gilmer | ||
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 | *******************************************************************************/ | ||
11 | package org.yocto.bc.ui.editors.bitbake; | ||
12 | |||
13 | import java.io.IOException; | ||
14 | import java.util.ResourceBundle; | ||
15 | |||
16 | import org.eclipse.core.resources.IFile; | ||
17 | import org.eclipse.core.resources.IProject; | ||
18 | import org.eclipse.core.runtime.Status; | ||
19 | import org.eclipse.ui.IEditorInput; | ||
20 | import org.eclipse.ui.IEditorSite; | ||
21 | import org.eclipse.ui.PartInitException; | ||
22 | import org.eclipse.ui.part.FileEditorInput; | ||
23 | import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor; | ||
24 | import org.eclipse.ui.texteditor.ContentAssistAction; | ||
25 | import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; | ||
26 | |||
27 | import org.yocto.bc.ui.Activator; | ||
28 | |||
29 | /** | ||
30 | * Editor for BB Recipe | ||
31 | * @author kgilmer | ||
32 | * | ||
33 | */ | ||
34 | public class BitBakeFileEditor extends AbstractDecoratedTextEditor { | ||
35 | |||
36 | public static final String EDITOR_ID = "org.yocto.bc.ui.editors.BitBakeFileEditor"; | ||
37 | static final String CONTENT_ASSIST= "ContentAssist"; | ||
38 | private BitBakeSourceViewerConfiguration viewerConfiguration; | ||
39 | private IFile targetFile; | ||
40 | |||
41 | public BitBakeFileEditor() { | ||
42 | super(); | ||
43 | viewerConfiguration = new BitBakeSourceViewerConfiguration(getSharedColors(), getPreferenceStore()); | ||
44 | setSourceViewerConfiguration(viewerConfiguration); | ||
45 | setDocumentProvider(new BitBakeDocumentProvider()); | ||
46 | } | ||
47 | |||
48 | @Override | ||
49 | protected void createActions() { | ||
50 | super.createActions(); | ||
51 | |||
52 | ResourceBundle bundle= RecipeEditorMessages.getBundle(); | ||
53 | ContentAssistAction action= new ContentAssistAction(bundle, "contentAssist.", this); //$NON-NLS-1$ | ||
54 | action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); | ||
55 | setAction(CONTENT_ASSIST, action); | ||
56 | } | ||
57 | |||
58 | @Override | ||
59 | public void init(IEditorSite site, IEditorInput input) throws PartInitException { | ||
60 | |||
61 | if (input instanceof FileEditorInput) { | ||
62 | IProject p = ((FileEditorInput)input).getFile().getProject(); | ||
63 | targetFile = ((FileEditorInput)input).getFile(); | ||
64 | viewerConfiguration.setTargetFile(targetFile); | ||
65 | |||
66 | try { | ||
67 | viewerConfiguration.setBBSession(Activator.getBBSession(p.getLocationURI().getPath())); | ||
68 | } catch (IOException e) { | ||
69 | e.printStackTrace(); | ||
70 | throw new PartInitException(Status.CANCEL_STATUS); | ||
71 | } | ||
72 | } | ||
73 | super.init(site, input); | ||
74 | } | ||
75 | } \ No newline at end of file | ||
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..56cd014 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeSourceViewerConfiguration.java | |||
@@ -0,0 +1,195 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2009 Ken Gilmer | ||
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 | *******************************************************************************/ | ||
11 | package org.yocto.bc.ui.editors.bitbake; | ||
12 | |||
13 | import org.eclipse.core.resources.IFile; | ||
14 | import org.eclipse.jface.preference.IPreferenceStore; | ||
15 | import org.eclipse.jface.text.ITextHover; | ||
16 | import org.eclipse.jface.text.TextAttribute; | ||
17 | import org.eclipse.jface.text.contentassist.ContentAssistant; | ||
18 | import org.eclipse.jface.text.contentassist.IContentAssistant; | ||
19 | import org.eclipse.jface.text.presentation.IPresentationReconciler; | ||
20 | import org.eclipse.jface.text.presentation.PresentationReconciler; | ||
21 | import org.eclipse.jface.text.reconciler.IReconciler; | ||
22 | import org.eclipse.jface.text.rules.DefaultDamagerRepairer; | ||
23 | import org.eclipse.jface.text.rules.IRule; | ||
24 | import org.eclipse.jface.text.rules.IToken; | ||
25 | import org.eclipse.jface.text.rules.IWordDetector; | ||
26 | import org.eclipse.jface.text.rules.RuleBasedScanner; | ||
27 | import org.eclipse.jface.text.rules.SingleLineRule; | ||
28 | import org.eclipse.jface.text.rules.Token; | ||
29 | import org.eclipse.jface.text.rules.WordRule; | ||
30 | import org.eclipse.jface.text.source.ISharedTextColors; | ||
31 | import org.eclipse.jface.text.source.ISourceViewer; | ||
32 | import org.eclipse.swt.SWT; | ||
33 | import org.eclipse.swt.graphics.Color; | ||
34 | import org.eclipse.swt.graphics.RGB; | ||
35 | import org.eclipse.ui.editors.text.TextSourceViewerConfiguration; | ||
36 | |||
37 | import org.yocto.bc.bitbake.BBLanguageHelper; | ||
38 | import org.yocto.bc.bitbake.BBSession; | ||
39 | |||
40 | public class BitBakeSourceViewerConfiguration extends TextSourceViewerConfiguration { | ||
41 | |||
42 | private static final class WordDetector implements IWordDetector { | ||
43 | public boolean isWordPart(char c) { | ||
44 | return !Character.isWhitespace(c); | ||
45 | } | ||
46 | |||
47 | public boolean isWordStart(char c) { | ||
48 | return !Character.isWhitespace(c); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | private final ISharedTextColors fSharedColors; | ||
53 | private BBSession session; | ||
54 | private IFile targetFile; | ||
55 | private BBVariableTextHover textHover = null; | ||
56 | |||
57 | public BitBakeSourceViewerConfiguration(ISharedTextColors sharedColors, IPreferenceStore store) { | ||
58 | super(store); | ||
59 | fSharedColors = sharedColors; | ||
60 | } | ||
61 | |||
62 | protected void setTargetFile(IFile targetFile) { | ||
63 | this.targetFile = targetFile; | ||
64 | } | ||
65 | |||
66 | public ITextHover getTextHover(ISourceViewer sv, String contentType) { | ||
67 | //only .bb file support Text Hover. | ||
68 | if (textHover == null && targetFile.getFileExtension().equals(BBLanguageHelper.BITBAKE_RECIPE_FILE_EXTENSION)) { | ||
69 | textHover = new BBVariableTextHover(session, targetFile.getLocationURI().getPath()); | ||
70 | } | ||
71 | |||
72 | return textHover; | ||
73 | } | ||
74 | |||
75 | private void addDamagerRepairer(PresentationReconciler reconciler, RuleBasedScanner commentScanner, String contentType) { | ||
76 | DefaultDamagerRepairer commentDamagerRepairer = new DefaultDamagerRepairer(commentScanner); | ||
77 | reconciler.setDamager(commentDamagerRepairer, contentType); | ||
78 | reconciler.setRepairer(commentDamagerRepairer, contentType); | ||
79 | } | ||
80 | |||
81 | private RuleBasedScanner createCommentScanner() { | ||
82 | Color green = fSharedColors.getColor(new RGB(16, 96, 16)); | ||
83 | RuleBasedScanner commentScanner = new RuleBasedScanner(); | ||
84 | commentScanner.setDefaultReturnToken(new Token(new TextAttribute(green, null, SWT.ITALIC))); | ||
85 | return commentScanner; | ||
86 | } | ||
87 | |||
88 | private IRule createCustomFunctionRule() { | ||
89 | Color blue = fSharedColors.getColor(new RGB(130, 0, 0)); | ||
90 | IRule rule = new CustomFunctionRule(new Token(new TextAttribute(blue, null, SWT.BOLD))); | ||
91 | |||
92 | return rule; | ||
93 | } | ||
94 | |||
95 | private SingleLineRule createFunctionNameRule() { | ||
96 | Color red = fSharedColors.getColor(new RGB(150, 0, 96)); | ||
97 | SingleLineRule stepRule = new SingleLineRule("do_", ")", new Token(new TextAttribute(red, null, SWT.BOLD))); //$NON-NLS-1$ //$NON-NLS-2$ | ||
98 | stepRule.setColumnConstraint(0); | ||
99 | return stepRule; | ||
100 | } | ||
101 | |||
102 | private SingleLineRule createInlineVariableRule() { | ||
103 | Color blue = fSharedColors.getColor(new RGB(50, 50, 100)); | ||
104 | SingleLineRule stepRule = new SingleLineRule("${", "}", new Token(new TextAttribute(blue, null, SWT.BOLD))); //$NON-NLS-1$ //$NON-NLS-2$ | ||
105 | return stepRule; | ||
106 | } | ||
107 | |||
108 | private WordRule createKeywordRule() { | ||
109 | WordRule keywordRule = new WordRule(new WordDetector()); | ||
110 | IToken token = new Token(new TextAttribute(fSharedColors.getColor(new RGB(96, 96, 0)), null, SWT.NONE)); | ||
111 | |||
112 | for (int i = 0; i < BBLanguageHelper.BITBAKE_KEYWORDS.length; ++i) { | ||
113 | |||
114 | keywordRule.addWord(BBLanguageHelper.BITBAKE_KEYWORDS[i], token); | ||
115 | keywordRule.setColumnConstraint(0); | ||
116 | } | ||
117 | |||
118 | return keywordRule; | ||
119 | } | ||
120 | |||
121 | private RuleBasedScanner createRecipeScanner() { | ||
122 | RuleBasedScanner recipeScanner = new RuleBasedScanner(); | ||
123 | |||
124 | IRule[] rules = { createKeywordRule(), createShellKeywordRule(), createStringLiteralRule(), createVariableRule(), createFunctionNameRule(), createCustomFunctionRule(), | ||
125 | createInlineVariableRule() }; | ||
126 | recipeScanner.setRules(rules); | ||
127 | return recipeScanner; | ||
128 | } | ||
129 | |||
130 | private WordRule createShellKeywordRule() { | ||
131 | WordRule keywordRule = new WordRule(new WordDetector()); | ||
132 | IToken token = new Token(new TextAttribute(fSharedColors.getColor(new RGB(0, 64, 92)), null, SWT.NONE)); | ||
133 | |||
134 | for (int i = 0; i < BBLanguageHelper.SHELL_KEYWORDS.length; ++i) { | ||
135 | keywordRule.addWord(BBLanguageHelper.SHELL_KEYWORDS[i], token); | ||
136 | } | ||
137 | |||
138 | return keywordRule; | ||
139 | } | ||
140 | |||
141 | private SingleLineRule createStringLiteralRule() { | ||
142 | Color red = fSharedColors.getColor(new RGB(50, 50, 100)); | ||
143 | SingleLineRule rule = new SingleLineRule("\"", "\"", new Token(new TextAttribute(red, null, SWT.NONE)), '\\'); | ||
144 | |||
145 | return rule; | ||
146 | } | ||
147 | |||
148 | private IRule createVariableRule() { | ||
149 | Color blue = fSharedColors.getColor(new RGB(0, 0, 200)); | ||
150 | IRule rule = new VariableRule(new Token(new TextAttribute(blue, null, SWT.NONE))); | ||
151 | |||
152 | return rule; | ||
153 | } | ||
154 | |||
155 | @Override | ||
156 | public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { | ||
157 | return new String[] { BitBakeDocumentProvider.RECIPE_CODE, BitBakeDocumentProvider.RECIPE_COMMENT }; | ||
158 | } | ||
159 | |||
160 | @Override | ||
161 | public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) { | ||
162 | return BitBakeDocumentProvider.RECIPE_PARTITIONING; | ||
163 | } | ||
164 | |||
165 | @Override | ||
166 | public IContentAssistant getContentAssistant(final ISourceViewer sourceViewer) { | ||
167 | ContentAssistant assistant = new ContentAssistant(); | ||
168 | assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); | ||
169 | |||
170 | // assistant.setContentAssistProcessor(new HippieProposalProcessor(), | ||
171 | // BitBakeDocumentProvider.RECIPE_COMMENT); | ||
172 | assistant.setContentAssistProcessor(new RecipeCompletionProcessor(), BitBakeDocumentProvider.RECIPE_CODE); | ||
173 | |||
174 | return assistant; | ||
175 | } | ||
176 | |||
177 | public IReconciler getReconciler(ISourceViewer sourceViewer) { | ||
178 | return null; | ||
179 | } | ||
180 | |||
181 | @Override | ||
182 | public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { | ||
183 | PresentationReconciler reconciler = new PresentationReconciler(); | ||
184 | reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); | ||
185 | |||
186 | addDamagerRepairer(reconciler, createCommentScanner(), BitBakeDocumentProvider.RECIPE_COMMENT); | ||
187 | addDamagerRepairer(reconciler, createRecipeScanner(), BitBakeDocumentProvider.RECIPE_CODE); | ||
188 | |||
189 | return reconciler; | ||
190 | } | ||
191 | |||
192 | public void setBBSession(BBSession session) { | ||
193 | this.session = session; | ||
194 | } | ||
195 | } | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/CustomFunctionRule.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/CustomFunctionRule.java new file mode 100644 index 0000000..223a25d --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/CustomFunctionRule.java | |||
@@ -0,0 +1,94 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2009 Ken Gilmer | ||
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 | *******************************************************************************/ | ||
11 | package org.yocto.bc.ui.editors.bitbake; | ||
12 | |||
13 | import org.eclipse.jface.text.rules.ICharacterScanner; | ||
14 | import org.eclipse.jface.text.rules.IRule; | ||
15 | import org.eclipse.jface.text.rules.IToken; | ||
16 | import org.eclipse.jface.text.rules.Token; | ||
17 | |||
18 | /** | ||
19 | * Rule for def_ BB Recipe functions | ||
20 | * @author kgilmer | ||
21 | * | ||
22 | */ | ||
23 | final class CustomFunctionRule implements IRule { | ||
24 | |||
25 | /** Token to return for this rule */ | ||
26 | private final IToken fToken; | ||
27 | |||
28 | /** | ||
29 | * Creates a new operator rule. | ||
30 | * | ||
31 | * @param token | ||
32 | * Token to use for this rule | ||
33 | */ | ||
34 | public CustomFunctionRule(IToken token) { | ||
35 | fToken = token; | ||
36 | } | ||
37 | |||
38 | public IToken evaluate(ICharacterScanner scanner) { | ||
39 | if (scanner.getColumn() > 0) { | ||
40 | return Token.UNDEFINED; | ||
41 | } | ||
42 | |||
43 | int i = scanner.read(); | ||
44 | int c = 1; | ||
45 | |||
46 | if (!Character.isLetter(i) && i != 10) { | ||
47 | scanner.unread(); | ||
48 | return Token.UNDEFINED; | ||
49 | } | ||
50 | |||
51 | if (i == 'd' && scanAhead(scanner, "o_".toCharArray())) { | ||
52 | scanner.unread(); | ||
53 | return Token.UNDEFINED; | ||
54 | } | ||
55 | |||
56 | while (i != ICharacterScanner.EOF && i != 10) { | ||
57 | i = scanner.read(); | ||
58 | c++; | ||
59 | |||
60 | if (i == '(') { | ||
61 | readUntil(scanner, ')'); | ||
62 | |||
63 | return fToken; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | for (int t = 0; t < c; t++) { | ||
68 | scanner.unread(); | ||
69 | } | ||
70 | |||
71 | return Token.UNDEFINED; | ||
72 | } | ||
73 | |||
74 | private void readUntil(ICharacterScanner scanner, int c) { | ||
75 | int i; | ||
76 | do { | ||
77 | i = scanner.read(); | ||
78 | } while (! (i == ICharacterScanner.EOF) && ! (i == c)); | ||
79 | } | ||
80 | |||
81 | private boolean scanAhead(ICharacterScanner scanner, char [] chars) { | ||
82 | boolean v = true; | ||
83 | for (int i = 0; i < chars.length; ++i) { | ||
84 | if (! (scanner.read() == chars[i])) { | ||
85 | v = false; | ||
86 | for (int j = 0; j < i; ++j) { | ||
87 | scanner.unread(); | ||
88 | } | ||
89 | break; | ||
90 | } | ||
91 | } | ||
92 | return v; | ||
93 | } | ||
94 | } \ No newline at end of file | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeCompletionProcessor.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeCompletionProcessor.java new file mode 100644 index 0000000..034187a --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeCompletionProcessor.java | |||
@@ -0,0 +1,127 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2009 Ken Gilmer | ||
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 | * Lianhao Lu (Intel) - remove compile warnings | ||
11 | *******************************************************************************/ | ||
12 | package org.yocto.bc.ui.editors.bitbake; | ||
13 | |||
14 | import java.util.ArrayList; | ||
15 | import java.util.Arrays; | ||
16 | import java.util.Iterator; | ||
17 | import java.util.List; | ||
18 | import java.util.Map; | ||
19 | |||
20 | import org.eclipse.jface.text.IDocument; | ||
21 | import org.eclipse.jface.text.ITextViewer; | ||
22 | import org.eclipse.jface.text.Region; | ||
23 | import org.eclipse.jface.text.contentassist.ICompletionProposal; | ||
24 | import org.eclipse.jface.text.contentassist.IContentAssistProcessor; | ||
25 | import org.eclipse.jface.text.contentassist.IContextInformation; | ||
26 | import org.eclipse.jface.text.contentassist.IContextInformationValidator; | ||
27 | import org.eclipse.jface.text.templates.DocumentTemplateContext; | ||
28 | import org.eclipse.jface.text.templates.Template; | ||
29 | import org.eclipse.jface.text.templates.TemplateContext; | ||
30 | import org.eclipse.jface.text.templates.TemplateContextType; | ||
31 | import org.eclipse.jface.text.templates.TemplateProposal; | ||
32 | import org.eclipse.swt.graphics.Image; | ||
33 | import org.eclipse.ui.ide.IDE.SharedImages; | ||
34 | import org.eclipse.ui.PlatformUI; | ||
35 | |||
36 | import org.yocto.bc.bitbake.BBLanguageHelper; | ||
37 | import org.yocto.bc.ui.Activator; | ||
38 | |||
39 | class RecipeCompletionProcessor implements IContentAssistProcessor { | ||
40 | |||
41 | private static final String CONTEXT_ID= "bitbake_variables"; //$NON-NLS-1$ | ||
42 | private final TemplateContextType fContextType= new TemplateContextType(CONTEXT_ID, "Common BitBake Variables"); //$NON-NLS-1$ | ||
43 | //private final TemplateContextType fKeywordContextType= new TemplateContextType("bitbake_keywords", "BitBake Keywords"); //$NON-NLS-1$ | ||
44 | private final TemplateContextType fFunctionContextType = new TemplateContextType("bitbake_functions", "BitBake Functions"); | ||
45 | |||
46 | RecipeCompletionProcessor() { | ||
47 | } | ||
48 | |||
49 | public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { | ||
50 | IDocument document= viewer.getDocument(); | ||
51 | Region region= new Region(offset, 0); | ||
52 | |||
53 | TemplateContext templateContext= new DocumentTemplateContext(fContextType, document, offset, 0); | ||
54 | //TemplateContext keywordContext = new DocumentTemplateContext(fKeywordContextType, document, offset, 0); | ||
55 | TemplateContext functionContext = new DocumentTemplateContext(fFunctionContextType, document, offset, 0); | ||
56 | |||
57 | List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(); | ||
58 | |||
59 | getVariableTemplateProposals(templateContext, region, proposals); | ||
60 | // getKeywordTemplateProposals(keywordContext, region, proposals); | ||
61 | getAddTaskTemplateProposals(templateContext, region, proposals); | ||
62 | getFunctionTemplateProposals(functionContext, region, proposals); | ||
63 | |||
64 | return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]); | ||
65 | } | ||
66 | |||
67 | public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) { | ||
68 | return null; | ||
69 | } | ||
70 | |||
71 | private Template generateVariableTemplate(String name, String description) { | ||
72 | |||
73 | return new Template(name, description, CONTEXT_ID, name + " = \"${" + name.toLowerCase() + "}\"", false); | ||
74 | } | ||
75 | |||
76 | private void getAddTaskTemplateProposals(TemplateContext templateContext, Region region, List<ICompletionProposal> p) { | ||
77 | p.add(new TemplateProposal(new Template("addtask", "addtask statement", CONTEXT_ID, "addtask ${task_name} after ${do_previous_task} before ${do_next_task}", false),templateContext, region, PlatformUI.getWorkbench().getSharedImages().getImage(SharedImages.IMG_OBJS_BKMRK_TSK))); | ||
78 | } | ||
79 | |||
80 | |||
81 | public char[] getCompletionProposalAutoActivationCharacters() { | ||
82 | return null; | ||
83 | } | ||
84 | |||
85 | public char[] getContextInformationAutoActivationCharacters() { | ||
86 | return null; | ||
87 | } | ||
88 | |||
89 | public IContextInformationValidator getContextInformationValidator() { | ||
90 | return null; | ||
91 | } | ||
92 | |||
93 | public String getErrorMessage() { | ||
94 | return null; | ||
95 | } | ||
96 | |||
97 | private void getFunctionTemplateProposals(TemplateContext templateContext, Region region, List<ICompletionProposal> p) { | ||
98 | String [] keywords = BBLanguageHelper.BITBAKE_STANDARD_FUNCTIONS; | ||
99 | Image img = Activator.getDefault().getImageRegistry().get(Activator.IMAGE_FUNCTION); | ||
100 | Arrays.sort(keywords); | ||
101 | |||
102 | for (int i = 0; i < keywords.length; ++i) { | ||
103 | p.add(new TemplateProposal(new Template(keywords[i], keywords[i] + " function", CONTEXT_ID, "do_" + keywords[i] + "() {\n\n}", false), templateContext, region, img)); | ||
104 | } | ||
105 | } | ||
106 | /* | ||
107 | private void getKeywordTemplateProposals(TemplateContext templateContext, Region region, List<TemplateProposal> p) { | ||
108 | String [] keywords = BBLanguageHelper.BITBAKE_KEYWORDS; | ||
109 | |||
110 | Arrays.sort(keywords); | ||
111 | |||
112 | for (int i = 0; i < keywords.length; ++i) { | ||
113 | p.add(new TemplateProposal(new Template(keywords[i], keywords[i] + " keyword", CONTEXT_ID, keywords[i] + " ", false),templateContext, region, null)); | ||
114 | } | ||
115 | } | ||
116 | */ | ||
117 | |||
118 | private void getVariableTemplateProposals(TemplateContext templateContext, Region region, List<ICompletionProposal> p) { | ||
119 | Map<String, String> n = BBLanguageHelper.getCommonBitbakeVariables(); | ||
120 | Image img = Activator.getDefault().getImageRegistry().get(Activator.IMAGE_VARIABLE); | ||
121 | for (Iterator<String> i = n.keySet().iterator(); i.hasNext();) { | ||
122 | String name = (String) i.next(); | ||
123 | String description = (String) n.get(name); | ||
124 | p.add(new TemplateProposal(generateVariableTemplate(name, description), templateContext, region, img)); | ||
125 | } | ||
126 | } | ||
127 | } \ No newline at end of file | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorActionContributor.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorActionContributor.java new file mode 100644 index 0000000..f27951b --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorActionContributor.java | |||
@@ -0,0 +1,47 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2009 Ken Gilmer | ||
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 | *******************************************************************************/ | ||
11 | package org.yocto.bc.ui.editors.bitbake; | ||
12 | |||
13 | import org.eclipse.jface.action.IMenuManager; | ||
14 | import org.eclipse.ui.IEditorPart; | ||
15 | import org.eclipse.ui.IWorkbenchActionConstants; | ||
16 | import org.eclipse.ui.editors.text.TextEditorActionContributor; | ||
17 | import org.eclipse.ui.texteditor.ITextEditor; | ||
18 | import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; | ||
19 | import org.eclipse.ui.texteditor.RetargetTextEditorAction; | ||
20 | |||
21 | public class RecipeEditorActionContributor extends TextEditorActionContributor { | ||
22 | |||
23 | private RetargetTextEditorAction fContentAssist; | ||
24 | |||
25 | public RecipeEditorActionContributor() { | ||
26 | fContentAssist= new RetargetTextEditorAction(RecipeEditorMessages.getBundle(), "contentAssist."); //$NON-NLS-1$ | ||
27 | fContentAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); | ||
28 | } | ||
29 | |||
30 | @Override | ||
31 | public void contributeToMenu(IMenuManager menu) { | ||
32 | super.contributeToMenu(menu); | ||
33 | |||
34 | IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); | ||
35 | if (editMenu != null) { | ||
36 | editMenu.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, fContentAssist); | ||
37 | } | ||
38 | } | ||
39 | |||
40 | @Override | ||
41 | public void setActiveEditor(IEditorPart part) { | ||
42 | super.setActiveEditor(part); | ||
43 | if (part instanceof ITextEditor) { | ||
44 | fContentAssist.setAction(getAction((ITextEditor) part, BitBakeFileEditor.CONTENT_ASSIST)); | ||
45 | } | ||
46 | } | ||
47 | } | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorMessages.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorMessages.java new file mode 100644 index 0000000..020a25a --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorMessages.java | |||
@@ -0,0 +1,21 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2009 Ken Gilmer | ||
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 | *******************************************************************************/ | ||
11 | package org.yocto.bc.ui.editors.bitbake; | ||
12 | |||
13 | import java.util.ResourceBundle; | ||
14 | |||
15 | public class RecipeEditorMessages { | ||
16 | |||
17 | public static ResourceBundle getBundle() { | ||
18 | return ResourceBundle.getBundle(RecipeEditorMessages.class.getName()); | ||
19 | } | ||
20 | |||
21 | } | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorMessages.properties b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorMessages.properties new file mode 100644 index 0000000..76c670b --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorMessages.properties | |||
@@ -0,0 +1,14 @@ | |||
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 | contentAssist.label=Content Assist | ||
12 | contentAssist.tooltip=Content Assist | ||
13 | contentAssist.image= | ||
14 | contentAssist.description= Invokes content assist \ No newline at end of file | ||
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/VariableRule.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/VariableRule.java new file mode 100644 index 0000000..750705a --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/VariableRule.java | |||
@@ -0,0 +1,69 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2009 Ken Gilmer | ||
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 | *******************************************************************************/ | ||
11 | package org.yocto.bc.ui.editors.bitbake; | ||
12 | |||
13 | import org.eclipse.jface.text.rules.ICharacterScanner; | ||
14 | import org.eclipse.jface.text.rules.IRule; | ||
15 | import org.eclipse.jface.text.rules.IToken; | ||
16 | import org.eclipse.jface.text.rules.Token; | ||
17 | |||
18 | final class VariableRule implements IRule { | ||
19 | |||
20 | /** Token to return for this rule */ | ||
21 | private final IToken fToken; | ||
22 | |||
23 | /** | ||
24 | * Creates a new operator rule. | ||
25 | * | ||
26 | * @param token | ||
27 | * Token to use for this rule | ||
28 | */ | ||
29 | public VariableRule(IToken token) { | ||
30 | fToken = token; | ||
31 | } | ||
32 | |||
33 | public IToken evaluate(ICharacterScanner scanner) { | ||
34 | if (scanner.getColumn() > 0) { | ||
35 | return Token.UNDEFINED; | ||
36 | } | ||
37 | |||
38 | int i = scanner.read(); | ||
39 | int c = 1; | ||
40 | |||
41 | if (!Character.isLetter(i) && i != 10) { | ||
42 | scanner.unread(); | ||
43 | return Token.UNDEFINED; | ||
44 | } | ||
45 | |||
46 | int p = i; | ||
47 | |||
48 | while (i != ICharacterScanner.EOF && i != 10) { | ||
49 | p = i; | ||
50 | i = scanner.read(); | ||
51 | c++; | ||
52 | |||
53 | if (i == '=') { | ||
54 | scanner.unread(); | ||
55 | |||
56 | if (p == '?' || p == '+') { | ||
57 | scanner.unread(); | ||
58 | } | ||
59 | return fToken; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | for (int t = 0; t < c; t++) { | ||
64 | scanner.unread(); | ||
65 | } | ||
66 | |||
67 | return Token.UNDEFINED; | ||
68 | } | ||
69 | } \ No newline at end of file | ||