diff options
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeCompletionProcessor.java')
-rw-r--r-- | plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/RecipeCompletionProcessor.java | 127 |
1 files changed, 127 insertions, 0 deletions
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 | ||