Added
Link Here
|
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
4 |
* Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
5 |
* |
6 |
* The contents of this file are subject to the terms of either the GNU |
7 |
* General Public License Version 2 only ("GPL") or the Common |
8 |
* Development and Distribution License("CDDL") (collectively, the |
9 |
* "License"). You may not use this file except in compliance with the |
10 |
* License. You can obtain a copy of the License at |
11 |
* http://www.netbeans.org/cddl-gplv2.html |
12 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the |
13 |
* specific language governing permissions and limitations under the |
14 |
* License. When distributing the software, include this License Header |
15 |
* Notice in each file and include the License file at |
16 |
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this |
17 |
* particular file as subject to the "Classpath" exception as provided |
18 |
* by Sun in the GPL Version 2 section of the License file that |
19 |
* accompanied this code. If applicable, add the following below the |
20 |
* License Header, with the fields enclosed by brackets [] replaced by |
21 |
* your own identifying information: |
22 |
* "Portions Copyrighted [year] [name of copyright owner]" |
23 |
* |
24 |
* If you wish your version of this file to be governed by only the CDDL |
25 |
* or only the GPL Version 2, indicate your decision by adding |
26 |
* "[Contributor] elects to include this software in this distribution |
27 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a |
28 |
* single choice of license, a recipient has the option to distribute |
29 |
* your version of this file under either the CDDL, the GPL Version 2 or |
30 |
* to extend the choice of license to its licensees as provided above. |
31 |
* However, if you add GPL Version 2 code and therefore, elected the GPL |
32 |
* Version 2 license, then the option applies only if the new code is |
33 |
* made subject to such option by the copyright holder. |
34 |
* |
35 |
* Contributor(s): |
36 |
* |
37 |
* Portions Copyrighted 2009 Sun Microsystems, Inc. |
38 |
*/ |
39 |
|
40 |
package org.netbeans.modules.csl.impl; |
41 |
|
42 |
import java.util.Set; |
43 |
import javax.annotation.processing.Processor; |
44 |
import javax.annotation.processing.RoundEnvironment; |
45 |
import javax.annotation.processing.SupportedAnnotationTypes; |
46 |
import javax.annotation.processing.SupportedSourceVersion; |
47 |
import javax.lang.model.SourceVersion; |
48 |
import javax.lang.model.element.Element; |
49 |
import javax.lang.model.element.TypeElement; |
50 |
import javax.lang.model.util.Elements; |
51 |
import org.netbeans.modules.csl.spi.LanguageRegistration; |
52 |
import org.openide.filesystems.annotations.LayerBuilder.File; |
53 |
import org.openide.filesystems.annotations.LayerGeneratingProcessor; |
54 |
import org.openide.filesystems.annotations.LayerGenerationException; |
55 |
import org.openide.util.lookup.ServiceProvider; |
56 |
|
57 |
/** |
58 |
* |
59 |
* @author mslama |
60 |
*/ |
61 |
@ServiceProvider(service=Processor.class) |
62 |
@SupportedAnnotationTypes("org.netbeans.modules.csl.spi.LanguageRegistration") |
63 |
@SupportedSourceVersion(SourceVersion.RELEASE_6) |
64 |
public class LanguageProcessor extends LayerGeneratingProcessor { |
65 |
|
66 |
@Override |
67 |
protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws LayerGenerationException { |
68 |
Elements elements = processingEnv.getElementUtils(); |
69 |
|
70 |
for (Element e : roundEnv.getElementsAnnotatedWith(LanguageRegistration.class)) { |
71 |
LanguageRegistration l = e.getAnnotation(LanguageRegistration.class); |
72 |
|
73 |
TypeElement te = (TypeElement)e.getEnclosingElement(); |
74 |
String teName = elements.getBinaryName(te).toString(); |
75 |
boolean hasDeclarationFinder = l.declarationFinder() != NoDeclarationFinder.class; |
76 |
//boolean hasDeclarationFinder = true; |
77 |
boolean hasStructureScanner = true; |
78 |
registerEditorServices(e,"marek",teName,l.lineCommentPrefix(),l.displayName(),hasStructureScanner,hasDeclarationFinder); |
79 |
} |
80 |
return true; |
81 |
} |
82 |
|
83 |
private void registerEditorServices(Element el, String mimeType, String gsfLanguageClass, String linePrefix, String displayName, boolean hasStructureScanner, boolean hasDeclarationFinder) { |
84 |
//Element mimeFolder = mkdirs(doc, "Editors/" + mimeType); // NOI18N |
85 |
// Hyperlinks |
86 |
File f; |
87 |
|
88 |
if (hasDeclarationFinder) { |
89 |
f = layer(el).file("Editors/" + mimeType + "/HyperlinkProviders/GsfHyperlinkProvider.instance"); |
90 |
f.stringvalue("instanceClass", "org.netbeans.modules.csl.editor.hyperlink.GsfHyperlinkProvider"); |
91 |
f.stringvalue("instanceOf", "org.netbeans.lib.editor.hyperlink.spi.HyperlinkProviderExt"); |
92 |
f.write(); |
93 |
} |
94 |
/* |
95 |
// Code Completion |
96 |
Element completionFolder = mkdirs(doc, "Editors/" + mimeType + "/CompletionProviders"); // NOI18N |
97 |
createFile(doc, completionFolder, "org-netbeans-lib-editor-codetemplates-CodeTemplateCompletionProvider.instance"); // NOI18N |
98 |
createFile(doc, completionFolder, "org-netbeans-modules-csl-editor-completion-GsfCompletionProvider.instance"); // NOI18N*/ |
99 |
f = layer(el).file("Editors/" + mimeType |
100 |
+ "/CompletionProviders/org-netbeans-lib-editor-codetemplates-CodeTemplateCompletionProvider.instance"); |
101 |
f.write(); |
102 |
f = layer(el).file("Editors/" + mimeType |
103 |
+ "/CompletionProviders/org-netbeans-modules-csl-editor-completion-GsfCompletionProvider.instance"); |
104 |
f.write(); |
105 |
|
106 |
// Context menu |
107 |
/*Element popupFolder = mkdirs(doc, "Editors/" + mimeType + "/Popup"); // NOI18N |
108 |
|
109 |
Element renameFile = createFile(doc, popupFolder, "in-place-refactoring"); // NOI18N |
110 |
setFileAttribute(doc, renameFile, "position", INTVALUE, "680"); // NOI18N*/ |
111 |
|
112 |
f = layer(el).file("Editors/" + mimeType + "/Popup/in-place-refactoring"); |
113 |
f.position(680); |
114 |
f.write(); |
115 |
|
116 |
/*boolean alreadyLocalized = false; |
117 |
boolean alreadyPositioned = false; |
118 |
List<Element> gotoAttributes = getAttributeElements(doc, "Editors/" + mimeType + "/Popup/goto"); // NOI18N |
119 |
for (Element gotoAttribute : gotoAttributes) { |
120 |
if (gotoAttribute.getAttribute(FILENAME).equals("SystemFileSystem.localizingBundle") || //NOI18N |
121 |
gotoAttribute.getAttribute(FILENAME).equals("displayName") //NOI18N |
122 |
) { |
123 |
alreadyLocalized = true; |
124 |
} |
125 |
if (gotoAttribute.getAttribute(FILENAME).equals("position")) { // NOI18N |
126 |
alreadyPositioned = true; |
127 |
} |
128 |
} |
129 |
|
130 |
Element gotoFolder = findPath(mimeFolder, "Popup/goto"); |
131 |
if (gotoFolder == null) { |
132 |
gotoFolder = mkdirs(mimeFolder, "Popup/goto"); // NOI18N |
133 |
} |
134 |
if (!alreadyPositioned) { |
135 |
setFileAttribute(doc, gotoFolder, "position", INTVALUE, "500"); // NOI18N |
136 |
} |
137 |
|
138 |
if (!alreadyLocalized) { |
139 |
setFileAttribute(doc, gotoFolder, "displayName", BUNDLEVALUE, "org.netbeans.modules.csl.core.Bundle#generate-goto-popup"); |
140 |
}*/ |
141 |
|
142 |
f = layer(el).file("Editors/" + mimeType + "/Popup/goto"); |
143 |
f.position(500); |
144 |
try { |
145 |
f.bundlevalue("displayName", "org.netbeans.modules.csl.core.Bundle#generate-goto-popup"); |
146 |
} catch (LayerGenerationException ex) { |
147 |
ex.printStackTrace(); |
148 |
} |
149 |
f.write(); |
150 |
|
151 |
/*Element item; |
152 |
if (hasDeclarationFinder) { |
153 |
item = createFile(doc, gotoFolder, "goto-declaration"); // NOI18N |
154 |
setFileAttribute(doc, item, "position", INTVALUE, "500"); // NOI18N |
155 |
} |
156 |
|
157 |
// Goto by linenumber |
158 |
item = createFile(doc, gotoFolder, "goto"); // NOI18N |
159 |
setFileAttribute(doc, item, "position", INTVALUE, "600"); // NOI18N*/ |
160 |
|
161 |
if (hasDeclarationFinder) { |
162 |
f = layer(el).file("Editors/" + mimeType + "/Popup/goto/goto-declaration"); |
163 |
f.position(500); |
164 |
f.write(); |
165 |
} |
166 |
|
167 |
// Goto by linenumber |
168 |
f = layer(el).file("Editors/" + mimeType + "/Popup/goto/goto"); |
169 |
f.position(600); |
170 |
f.write(); |
171 |
|
172 |
// What about goto-source etc? |
173 |
// TODO: Goto Type (integrate with Java's GotoType) |
174 |
// popupFolder = "Editors/" + mimeType + "/Popup" |
175 |
|
176 |
/*item = createFile(doc, popupFolder, "SeparatorBeforeCut.instance"); // NOI18N |
177 |
setFileAttribute(doc, item, "position", INTVALUE, "1200"); // NOI18N |
178 |
setFileAttribute(doc, item, "instanceClass", STRINGVALUE, "javax.swing.JSeparator"); // NOI18N*/ |
179 |
|
180 |
f = layer(el).file("Editors/" + mimeType + "/Popup/SeparatorBeforeCut.instance"); |
181 |
f.position(1200); |
182 |
f.stringvalue("instanceClass", "javax.swing.JSeparator"); |
183 |
f.write(); |
184 |
|
185 |
/*item = createFile(doc, popupFolder, "format"); // NOI18N |
186 |
setFileAttribute(doc, item, "position", INTVALUE, "750"); // NOI18N |
187 |
|
188 |
item = createFile(doc, popupFolder, "SeparatorAfterFormat.instance"); // NOI18N |
189 |
// Should be between org-openide-actions-PasteAction.instance and format |
190 |
setFileAttribute(doc, item, "position", INTVALUE, "780"); // NOI18N |
191 |
setFileAttribute(doc, item, "instanceClass", STRINGVALUE, "javax.swing.JSeparator"); // NOI18N |
192 |
|
193 |
// UpToDateStatusProviders |
194 |
Element upToDateFolder = mkdirs(doc, "Editors/" + mimeType + "/UpToDateStatusProvider"); // NOI18N |
195 |
item = createFile(doc, upToDateFolder, "org-netbeans-modules-csl-hints-GsfUpToDateStateProviderFactory.instance"); // NOI18N |
196 |
item = createFile(doc, upToDateFolder, "org-netbeans-modules-csl-editor-semantic-OccurrencesMarkProviderCreator.instance"); // NOI18N |
197 |
|
198 |
// Code Folding |
199 |
if (hasStructureScanner) { |
200 |
Element sideBarFolder = mkdirs(doc, "Editors/" + mimeType + "/SideBar"); // NOI18N |
201 |
Element sidebarFile = createFile(doc, sideBarFolder, "org-netbeans-modules-csl-editor-GsfCodeFoldingSideBarFactory.instance"); // NOI18N |
202 |
setFileAttribute(doc, sidebarFile, "position", INTVALUE, "1200"); // NOI18N |
203 |
|
204 |
Element foldingFolder = mkdirs(doc, "Editors/" + mimeType + "/FoldManager"); // NOI18N |
205 |
createFile(doc, foldingFolder, "org-netbeans-modules-csl-editor-fold-GsfFoldManagerFactory.instance"); // NOI18N |
206 |
} |
207 |
|
208 |
// Highlighting Factories |
209 |
item = createFile(doc, mimeFolder, "org-netbeans-modules-csl-editor-semantic-HighlightsLayerFactoryImpl.instance"); // NOI18N |
210 |
|
211 |
// Toolbar |
212 |
if (linePrefix != null && linePrefix.length() > 0) { |
213 |
// Yes, found line comment prefix - register comment/uncomment toolbar buttons! |
214 |
Element toolbarFolder = mkdirs(mimeFolder, "Toolbars/Default"); // NOI18N |
215 |
|
216 |
item = createFile(doc, toolbarFolder, "Separator-before-comment.instance"); // NOI18N |
217 |
setFileAttribute(doc, item, "instanceClass", STRINGVALUE, "javax.swing.JSeparator"); // NOI18N |
218 |
setFileAttribute(doc, item, "position", INTVALUE, "30000"); // NOI18N |
219 |
|
220 |
item = createFile(doc, toolbarFolder, "comment"); // NOI18N |
221 |
setFileAttribute(doc, item, "position", INTVALUE, "30100"); // NOI18N |
222 |
|
223 |
item = createFile(doc, toolbarFolder, "uncomment"); // NOI18N |
224 |
setFileAttribute(doc, item, "position", INTVALUE, "30200"); // NOI18N |
225 |
} |
226 |
|
227 |
// Code Templates |
228 |
Element codeProcessorFolder = mkdirs(mimeFolder, "CodeTemplateProcessorFactories"); // NOI18N |
229 |
item = createFile(doc, codeProcessorFolder, "org-netbeans-modules-csl-editor-codetemplates-GsfCodeTemplateProcessor$Factory.instance"); // NOI18N |
230 |
|
231 |
// Code Template Filters |
232 |
Element codeFilter = mkdirs(mimeFolder, "CodeTemplateFilterFactories"); // NOI18N |
233 |
item = createFile(doc, codeFilter, "org-netbeans-modules-csl-editor-codetemplates-GsfCodeTemplateFilter$Factory.instance"); // NOI18N |
234 |
|
235 |
// Parser factory |
236 |
item = createFile(doc, mimeFolder, "org-netbeans-modules-csl-core-GsfParserFactory.instance"); // NOI18N |
237 |
setFileAttribute(doc, item, "instanceCreate", METHODVALUE, "org.netbeans.modules.csl.core.GsfParserFactory.create"); //NOI18N |
238 |
setFileAttribute(doc, item, "instanceOf", STRINGVALUE, "org.netbeans.modules.parsing.spi.ParserFactory"); //NOI18N |
239 |
|
240 |
// Indexer factory |
241 |
item = createFile(doc, mimeFolder, "org-netbeans-modules-csl-core-EmbeddingIndexerFactoryImpl.instance"); // NOI18N |
242 |
setFileAttribute(doc, item, "instanceCreate", METHODVALUE, "org.netbeans.modules.csl.core.EmbeddingIndexerFactoryImpl.create"); //NOI18N |
243 |
setFileAttribute(doc, item, "instanceOf", STRINGVALUE, "org.netbeans.modules.parsing.spi.indexing.EmbeddingIndexerFactory"); //NOI18N*/ |
244 |
} |
245 |
|
246 |
|
247 |
} |