summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake')
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BBVariableTextHover.java127
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeDocumentProvider.java101
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeFileEditor.java89
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeSourceViewerConfiguration.java210
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/CustomFunctionRule.java94
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeCompletionProcessor.java127
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorActionContributor.java47
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorMessages.java21
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeEditorMessages.properties14
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/VariableRule.java69
10 files changed, 899 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..5a90fca
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BBVariableTextHover.java
@@ -0,0 +1,127 @@
1/*******************************************************************************
2 * Copyright (c) 2013 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 * Intel - initial API and implementation
10 *******************************************************************************/
11package org.yocto.bc.ui.editors.bitbake;
12
13import java.net.URI;
14import java.util.Map;
15
16import org.eclipse.core.runtime.IProgressMonitor;
17import org.eclipse.core.runtime.IStatus;
18import org.eclipse.core.runtime.Status;
19import org.eclipse.core.runtime.jobs.Job;
20import org.eclipse.jface.text.IRegion;
21import org.eclipse.jface.text.ITextHover;
22import org.eclipse.jface.text.ITextViewer;
23import org.eclipse.jface.text.Region;
24import org.yocto.bc.bitbake.BBRecipe;
25import org.yocto.bc.bitbake.BBSession;
26import org.yocto.bc.ui.Activator;
27
28/**
29 * Maps BB Variables in the editor to BBSession
30 * @author kgilmer
31 *
32 */
33class BBVariableTextHover implements ITextHover {
34 private final BBSession session;
35 private volatile Map<String, String> envMap;
36
37 public BBVariableTextHover(BBSession session, URI file) {
38 this.session = session;
39 envMap = getEnvironmentMap();
40 LoadRecipeJob loadRecipeJob = new LoadRecipeJob(getFilename(file), file);
41 loadRecipeJob.schedule();
42 }
43
44 private Map<String, String> getEnvironmentMap() {
45 if (envMap == null)
46 envMap = this.session.getProperties();
47 return envMap;
48 }
49
50 private String getFilename(URI uri) {
51 return uri.getPath();
52 }
53
54 public IRegion getHoverRegion(ITextViewer tv, int off) {
55 return new Region(off, 0);
56 }
57
58 public String getHoverInfo(ITextViewer tv, IRegion r) {
59 try {
60 IRegion lineRegion = tv.getDocument().getLineInformationOfOffset(r.getOffset());
61
62 return getBBVariable(tv.getDocument().get(lineRegion.getOffset(), lineRegion.getLength()).toCharArray(), r.getOffset() - lineRegion.getOffset());
63 } catch (Exception e) {
64 return "";
65 }
66 }
67
68 private String getBBVariable(char[] line, int offset) {
69 // Find start of word.
70 int i = offset;
71
72 while (line[i] != ' ' && line[i] != '$' && i > 0) {
73 i--;
74 }
75
76 if (i < 0 || line[i] != '$') {
77 return ""; //this is not a BB variable.
78 }
79
80 // find end of word
81 int start = i;
82 i = offset;
83
84 while (line[i] != ' ' && line[i] != '}' && i <= line.length) {
85 i++;
86 }
87
88 if (line[i] != '}') {
89 return ""; //this bb variable didn't terminate as expected
90 }
91
92 String key = new String(line, start + 2, i - start - 2);
93 String val = (String) getEnvironmentMap().get(key);
94
95 if (val == null) {
96 val = "";
97 }
98
99 if (val.length() > 64) {
100 val = val.substring(0, 64) + '\n' + val.substring(65);
101 }
102
103 return val;
104 }
105
106 private class LoadRecipeJob extends Job {
107 private final URI filePath;
108
109 public LoadRecipeJob(String name, URI filePath) {
110 super("Extracting BitBake environment for " + name);
111 this.filePath = filePath;
112 }
113
114 @Override
115 protected IStatus run(IProgressMonitor mon) {
116 try {
117 BBRecipe recipe = Activator.getBBRecipe(session, filePath);
118 recipe.initialize();
119 envMap = recipe;
120 } catch (Exception e) {
121 return new Status(IStatus.WARNING, Activator.PLUGIN_ID, "Unable to load session for " + filePath, e);
122 }
123
124 return Status.OK_STATUS;
125 }
126 }
127}
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..140a3da
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeDocumentProvider.java
@@ -0,0 +1,101 @@
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 *******************************************************************************/
12package org.yocto.bc.ui.editors.bitbake;
13
14import java.net.URI;
15import java.net.URISyntaxException;
16
17import org.eclipse.core.runtime.NullProgressMonitor;
18import org.eclipse.jface.text.IDocument;
19import org.eclipse.jface.text.IDocumentExtension3;
20import org.eclipse.jface.text.IDocumentPartitioner;
21import org.eclipse.jface.text.rules.FastPartitioner;
22import org.eclipse.jface.text.rules.IPredicateRule;
23import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
24import org.eclipse.jface.text.rules.SingleLineRule;
25import org.eclipse.jface.text.rules.Token;
26import org.eclipse.rse.core.model.IHost;
27import org.eclipse.ui.IFileEditorInput;
28import org.eclipse.ui.editors.text.FileDocumentProvider;
29import org.yocto.remote.utils.RemoteHelper;
30
31/**
32 * Document provider for BB recipe.
33 * @author kgilmer
34 *
35 */
36public class BitBakeDocumentProvider extends FileDocumentProvider {
37 /**
38 * The recipe partitioning. It contains two partition types: {@link #RECIPE_CODE} and
39 * {@link #RECIPE_COMMENT}.
40 */
41 public static final String RECIPE_PARTITIONING= "org.recipeeditor.recipepartitioning"; //$NON-NLS-1$
42
43 public static final String RECIPE_CODE= IDocument.DEFAULT_CONTENT_TYPE;
44 public static final String RECIPE_COMMENT= "RECIPE_COMMENT"; //$NON-NLS-1$
45
46 private IHost connection;
47
48 private final BitBakeSourceViewerConfiguration viewerConfiguration;
49
50 private static final String[] CONTENT_TYPES= {
51 RECIPE_CODE,
52 RECIPE_COMMENT
53 };
54
55 public BitBakeDocumentProvider(BitBakeSourceViewerConfiguration viewerConfiguration) {
56 this.viewerConfiguration = viewerConfiguration;
57 }
58
59 private IDocumentPartitioner createRecipePartitioner() {
60 IPredicateRule[] rules= { new SingleLineRule("#", null, new Token(RECIPE_COMMENT), (char) 0, true, false) }; //$NON-NLS-1$
61
62 RuleBasedPartitionScanner scanner= new RuleBasedPartitionScanner();
63 scanner.setPredicateRules(rules);
64
65 return new FastPartitioner(scanner, CONTENT_TYPES);
66 }
67
68 @Override
69 protected void setupDocument(Object element,IDocument document) {
70 if (document instanceof IDocumentExtension3) {
71 IDocumentExtension3 ext= (IDocumentExtension3) document;
72 IDocumentPartitioner partitioner= createRecipePartitioner();
73 ext.setDocumentPartitioner(RECIPE_PARTITIONING, partitioner);
74 partitioner.connect(document);
75 }
76 }
77
78 @Override
79 public boolean isDeleted(Object element) {
80 if (element instanceof IFileEditorInput) {
81 IFileEditorInput input= (IFileEditorInput) element;
82
83 URI root = viewerConfiguration.getBBSession().getProjInfoRoot();
84 String relPath = input.getFile().getProjectRelativePath().toPortableString();
85 try {
86 URI fileURI = new URI(root.getScheme(), root.getHost(), root.getPath() + "/" + relPath, root.getFragment());
87 if (connection == null)
88 connection = viewerConfiguration.getBBSession().getProjectInfo().getConnection();
89 return !RemoteHelper.fileExistsRemote(connection, new NullProgressMonitor(), fileURI.getPath());
90 } catch (URISyntaxException e) {
91 e.printStackTrace();
92 }
93 }
94
95 return super.isDeleted(element);
96 }
97
98 public void setActiveConnection(IHost connection) {
99 this.connection = connection;
100 }
101}
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..11dd335
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/BitBakeFileEditor.java
@@ -0,0 +1,89 @@
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 *******************************************************************************/
12package org.yocto.bc.ui.editors.bitbake;
13
14import java.io.IOException;
15import java.lang.reflect.InvocationTargetException;
16import java.util.ResourceBundle;
17
18import org.eclipse.core.resources.IFile;
19import org.eclipse.core.resources.IProject;
20import org.eclipse.core.runtime.CoreException;
21import org.eclipse.core.runtime.NullProgressMonitor;
22import org.eclipse.core.runtime.Status;
23import org.eclipse.ui.IEditorInput;
24import org.eclipse.ui.IEditorSite;
25import org.eclipse.ui.PartInitException;
26import org.eclipse.ui.part.FileEditorInput;
27import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
28import org.eclipse.ui.texteditor.ContentAssistAction;
29import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
30import org.yocto.bc.ui.Activator;
31import org.yocto.bc.ui.model.ProjectInfo;
32
33/**
34 * Editor for BB Recipe
35 * @author kgilmer
36 *
37 */
38public class BitBakeFileEditor extends AbstractDecoratedTextEditor {
39
40 public static final String EDITOR_ID = "org.yocto.bc.ui.editors.BitBakeFileEditor";
41 static final String CONTENT_ASSIST= "ContentAssist";
42 private BitBakeSourceViewerConfiguration viewerConfiguration;
43 private IFile targetFile;
44
45 public BitBakeFileEditor() {
46 super();
47 viewerConfiguration = new BitBakeSourceViewerConfiguration(getSharedColors(), getPreferenceStore());
48 setSourceViewerConfiguration(viewerConfiguration);
49 setDocumentProvider(new BitBakeDocumentProvider(viewerConfiguration));
50 }
51
52 @Override
53 protected void createActions() {
54 super.createActions();
55
56 ResourceBundle bundle= RecipeEditorMessages.getBundle();
57 ContentAssistAction action= new ContentAssistAction(bundle, "contentAssist.", this); //$NON-NLS-1$
58 action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
59 setAction(CONTENT_ASSIST, action);
60 }
61
62 @Override
63 public void init(IEditorSite site, IEditorInput input) throws PartInitException {
64
65 if (input instanceof FileEditorInput) {
66 IProject p = ((FileEditorInput)input).getFile().getProject();
67 targetFile = ((FileEditorInput)input).getFile();
68 viewerConfiguration.setTargetFile(targetFile);
69
70 try {
71 ProjectInfo projInfo = Activator.getProjInfo(p.getLocationURI());
72 ((BitBakeDocumentProvider)getDocumentProvider()).setActiveConnection(projInfo.getConnection());
73 viewerConfiguration.setBBSession(Activator.getBBSession(projInfo, new NullProgressMonitor()));
74 } catch (IOException e) {
75 e.printStackTrace();
76 throw new PartInitException(Status.CANCEL_STATUS);
77 } catch (InvocationTargetException e) {
78 e.printStackTrace();
79 } catch (CoreException e) {
80 e.printStackTrace();
81 } catch (InterruptedException e) {
82 e.printStackTrace();
83 } catch (Exception e) {
84 e.printStackTrace();
85 }
86 }
87 super.init(site, input);
88 }
89}
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 *******************************************************************************/
12package org.yocto.bc.ui.editors.bitbake;
13
14import java.net.URI;
15import java.net.URISyntaxException;
16
17import org.eclipse.core.resources.IFile;
18import org.eclipse.jface.preference.IPreferenceStore;
19import org.eclipse.jface.text.ITextHover;
20import org.eclipse.jface.text.TextAttribute;
21import org.eclipse.jface.text.contentassist.ContentAssistant;
22import org.eclipse.jface.text.contentassist.IContentAssistant;
23import org.eclipse.jface.text.presentation.IPresentationReconciler;
24import org.eclipse.jface.text.presentation.PresentationReconciler;
25import org.eclipse.jface.text.reconciler.IReconciler;
26import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
27import org.eclipse.jface.text.rules.IRule;
28import org.eclipse.jface.text.rules.IToken;
29import org.eclipse.jface.text.rules.IWordDetector;
30import org.eclipse.jface.text.rules.RuleBasedScanner;
31import org.eclipse.jface.text.rules.SingleLineRule;
32import org.eclipse.jface.text.rules.Token;
33import org.eclipse.jface.text.rules.WordRule;
34import org.eclipse.jface.text.source.ISharedTextColors;
35import org.eclipse.jface.text.source.ISourceViewer;
36import org.eclipse.swt.SWT;
37import org.eclipse.swt.graphics.Color;
38import org.eclipse.swt.graphics.RGB;
39import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
40import org.yocto.bc.bitbake.BBLanguageHelper;
41import org.yocto.bc.bitbake.BBSession;
42
43public 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}
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 *******************************************************************************/
11package org.yocto.bc.ui.editors.bitbake;
12
13import org.eclipse.jface.text.rules.ICharacterScanner;
14import org.eclipse.jface.text.rules.IRule;
15import org.eclipse.jface.text.rules.IToken;
16import org.eclipse.jface.text.rules.Token;
17
18/**
19 * Rule for def_ BB Recipe functions
20 * @author kgilmer
21 *
22 */
23final 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 *******************************************************************************/
12package org.yocto.bc.ui.editors.bitbake;
13
14import java.util.ArrayList;
15import java.util.Arrays;
16import java.util.Iterator;
17import java.util.List;
18import java.util.Map;
19
20import org.eclipse.jface.text.IDocument;
21import org.eclipse.jface.text.ITextViewer;
22import org.eclipse.jface.text.Region;
23import org.eclipse.jface.text.contentassist.ICompletionProposal;
24import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
25import org.eclipse.jface.text.contentassist.IContextInformation;
26import org.eclipse.jface.text.contentassist.IContextInformationValidator;
27import org.eclipse.jface.text.templates.DocumentTemplateContext;
28import org.eclipse.jface.text.templates.Template;
29import org.eclipse.jface.text.templates.TemplateContext;
30import org.eclipse.jface.text.templates.TemplateContextType;
31import org.eclipse.jface.text.templates.TemplateProposal;
32import org.eclipse.swt.graphics.Image;
33import org.eclipse.ui.ide.IDE.SharedImages;
34import org.eclipse.ui.PlatformUI;
35
36import org.yocto.bc.bitbake.BBLanguageHelper;
37import org.yocto.bc.ui.Activator;
38
39class 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 *******************************************************************************/
11package org.yocto.bc.ui.editors.bitbake;
12
13import org.eclipse.jface.action.IMenuManager;
14import org.eclipse.ui.IEditorPart;
15import org.eclipse.ui.IWorkbenchActionConstants;
16import org.eclipse.ui.editors.text.TextEditorActionContributor;
17import org.eclipse.ui.texteditor.ITextEditor;
18import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
19import org.eclipse.ui.texteditor.RetargetTextEditorAction;
20
21public 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 *******************************************************************************/
11package org.yocto.bc.ui.editors.bitbake;
12
13import java.util.ResourceBundle;
14
15public 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##########################################################
11contentAssist.label=Content Assist
12contentAssist.tooltip=Content Assist
13contentAssist.image=
14contentAssist.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 *******************************************************************************/
11package org.yocto.bc.ui.editors.bitbake;
12
13import org.eclipse.jface.text.rules.ICharacterScanner;
14import org.eclipse.jface.text.rules.IRule;
15import org.eclipse.jface.text.rules.IToken;
16import org.eclipse.jface.text.rules.Token;
17
18final 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