This is an automated email from the ASF dual-hosted git repository.

dbalek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 3a9cdc8  Support for TextMate injection grammars added. (#1249)
3a9cdc8 is described below

commit 3a9cdc8adaa1d65154a876e6b50b26c637b2a8a3
Author: Dusan Balek <[email protected]>
AuthorDate: Wed May 15 09:11:20 2019 +0200

    Support for TextMate injection grammars added. (#1249)
    
    * Support for TextMate injection grammars added.
    
    * Documentation improvements.
---
 ide/textmate.lexer/apichanges.xml                  | 15 ++++
 ide/textmate.lexer/arch.xml                        | 41 +++++++++-
 ide/textmate.lexer/manifest.mf                     |  2 +-
 .../lexer/CreateRegistrationProcessor.java         | 89 +++++++++++++++++++++-
 .../modules/textmate/lexer/SyntaxHighlighting.java | 32 ++++----
 .../modules/textmate/lexer/TextmateLexer.java      |  1 -
 .../modules/textmate/lexer/TextmateTokenId.java    | 17 ++++-
 ...ions.java => GrammarInjectionRegistration.java} | 24 ++++--
 ...ons.java => GrammarInjectionRegistrations.java} | 14 ++--
 .../textmate/lexer/api/GrammarRegistrations.java   |  4 +-
 .../lexer/CreateRegistrationProcessorTest.java     | 47 +++++++++++-
 11 files changed, 243 insertions(+), 43 deletions(-)

diff --git a/ide/textmate.lexer/apichanges.xml 
b/ide/textmate.lexer/apichanges.xml
index 397d1af..bb1fded 100644
--- a/ide/textmate.lexer/apichanges.xml
+++ b/ide/textmate.lexer/apichanges.xml
@@ -64,6 +64,21 @@
             </p>
         </description>
     </change>
+    <change id="injection_grammars" >
+        <api name="TextmateLexer"/>
+        <summary>Support for injection grammars added.</summary>
+        <version major="1" minor="3"/>
+        <date day="14" month="5" year="2019"/>
+        <author login="dbalek"/>
+        <compatibility addition="yes"/>
+        <description>
+            <p>
+                Support for injection grammars has been added. See the <a 
href="overview-summary.html#usecase-injection-grammar">use-cases</a> for more 
information.
+            </p>
+        </description>
+        <class name="GrammarInjectionRegistration" 
package="org.netbeans.modules.textmate.lexer.api"/>
+        <class name="GrammarInjectionRegistrations" 
package="org.netbeans.modules.textmate.lexer.api"/>
+    </change>
 </changes>
 
   <!-- Now the surrounding HTML text and document structure: -->
diff --git a/ide/textmate.lexer/arch.xml b/ide/textmate.lexer/arch.xml
index ec22011..893674f 100644
--- a/ide/textmate.lexer/arch.xml
+++ b/ide/textmate.lexer/arch.xml
@@ -49,7 +49,7 @@
 -->
  <answer id="arch-overall">
   <p>
-   This is a lexer an syntax highlighting for TextMate grammars. The grammars
+   This is a lexer and syntax highlighting for TextMate grammars. The grammars
    may be regitered using the system layer.
    <api name="register-grammar" group="layer" type="export" category="devel" />
   </p>
@@ -117,7 +117,7 @@
   <p>
       <usecase id="register-grammar" name="Register grammar">
           To register a new TextMate grammar, add it as a file into the system 
filesystem,
-          under "Editors/&lt;mime-type&gt;/", and make sure it has an 
attribute "textmate-grammar",&lt;/mime-type&gt;,
+          under "Editors/&lt;mime-type&gt;/", and make sure it has an 
attribute "textmate-grammar"
           whose value is a string representing the TextMate top-level scope. 
For example:
           <pre>
     &lt;folder name="Editors"&gt;
@@ -139,6 +139,37 @@
     {@literal @}GrammarRegistration(mimeType="text/x-kotlin", 
grammar="path/to/Kotlin.tmLanguage.json")
           </pre>
       </usecase>
+      <a name="usecase-injection-grammar">
+      <usecase id="register-injection-grammar" name="Register injection 
grammar">
+          Injection grammars let existing grammars to be extended. An 
injection grammar is
+          a regular TextMate grammar that is injected into a specific scope 
within
+          an existing grammar. To register a new injection grammar, add it as 
a file
+          into the system filesystem under "Editors/", and make sure it has 
attributes
+          "textmate-grammar" whose value is a string representing the TextMate 
top-level
+          scope and "inject-to" whose value is a string representing comma 
separated
+          list of scopes that the grammar is injected to. For example, 
registration
+          of the injection grammar highlighting TODO keywords in JavaScript 
and TypeScript
+          comments:
+          <pre>
+    &lt;folder name="Editors"&gt;
+        &lt;file name="todo-comment-injection.json" 
url="todo-comment-injection.json"&gt;
+            &lt;attr name="textmate-grammar" 
stringvalue="todo-comment.injection" /&gt;
+            &lt;attr name="inject-to" stringvalue="source.js,source.ts" /&gt;
+        &lt;/file&gt;
+    &lt;/folder&gt;
+          </pre>
+      </usecase>
+      </a>
+      <a name="usecase-injection-grammar-java-api">
+      <usecase id="register-injection-grammar-using-java-api" name="Register 
injection grammar using Java API">
+          To register a new injection grammar using Java API, add the 
GrammarInjectionRegistration
+          annotation to an appropriate package-info file, or an appropriate 
Java class.
+          For example:
+          <pre>
+    {@literal 
@}GrammarInjectionRegistration(grammar="path/to/todo-comment-injection.json", 
injectTo = {"source.js","source.ts"})
+          </pre>
+      </usecase>
+      </a>
   </p>
  </answer>
 
@@ -156,8 +187,10 @@
 -->
  <answer id="arch-what">
   <p>
-   This project to allows to easily add syntax highlighting for languages by
-   using the TextMate grammar files.
+   <api category="stable" group="java" type="export" name="TextMateGrammars">
+    This project to allows to easily add syntax highlighting for languages by
+    using the TextMate grammar files.
+   </api>
   </p>
  </answer>
 
diff --git a/ide/textmate.lexer/manifest.mf b/ide/textmate.lexer/manifest.mf
index 4a250e4..2643ac6 100644
--- a/ide/textmate.lexer/manifest.mf
+++ b/ide/textmate.lexer/manifest.mf
@@ -3,5 +3,5 @@ AutoUpdate-Show-In-Client: false
 OpenIDE-Module: org.netbeans.modules.textmate.lexer/0
 OpenIDE-Module-Layer: org/netbeans/modules/textmate/lexer/resources/layer.xml
 OpenIDE-Module-Localizing-Bundle: 
org/netbeans/modules/textmate/lexer/Bundle.properties
-OpenIDE-Module-Specification-Version: 1.2
+OpenIDE-Module-Specification-Version: 1.3
 
diff --git 
a/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/CreateRegistrationProcessor.java
 
b/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/CreateRegistrationProcessor.java
index 90db05b..4bb8818 100644
--- 
a/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/CreateRegistrationProcessor.java
+++ 
b/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/CreateRegistrationProcessor.java
@@ -24,6 +24,7 @@ import java.io.InputStream;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map.Entry;
 import java.util.Set;
 import javax.annotation.processing.Completion;
@@ -52,9 +53,10 @@ import org.openide.util.lookup.ServiceProvider;
  *
  * @author Jan Lahoda
  */
-@SupportedAnnotationTypes({"org.netbeans.modules.textmate.lexer.api.GrammarRegistration",
 "org.netbeans.modules.textmate.lexer.api.GrammarRegistrations"})
+@SupportedAnnotationTypes({"org.netbeans.modules.textmate.lexer.api.GrammarRegistration",
 "org.netbeans.modules.textmate.lexer.api.GrammarRegistrations",
+    "org.netbeans.modules.textmate.lexer.api.GrammarInjectionRegistration", 
"org.netbeans.modules.textmate.lexer.api.GrammarInjectionRegistrations"})
 @SupportedSourceVersion(SourceVersion.RELEASE_8)
-@ServiceProvider(service=Processor.class)
+@ServiceProvider(service = Processor.class)
 public class CreateRegistrationProcessor extends LayerGeneratingProcessor {
 
     @Override
@@ -89,6 +91,36 @@ public class CreateRegistrationProcessor extends 
LayerGeneratingProcessor {
             }
         }
 
+        TypeElement grammarInjectionRegistration = 
processingEnv.getElementUtils().getTypeElement("org.netbeans.modules.textmate.lexer.api.GrammarInjectionRegistration");
+
+        for (Element el : 
roundEnv.getElementsAnnotatedWith(grammarInjectionRegistration)) {
+            for (AnnotationMirror am : el.getAnnotationMirrors()) {
+                if 
(!grammarInjectionRegistration.equals(am.getAnnotationType().asElement())) {
+                    continue;
+                }
+
+                processInjection(el, am);
+            }
+        }
+
+        TypeElement grammarInjectionRegistrations = 
processingEnv.getElementUtils().getTypeElement("org.netbeans.modules.textmate.lexer.api.GrammarInjectionRegistrations");
+
+        for (Element el : 
roundEnv.getElementsAnnotatedWith(grammarInjectionRegistrations)) {
+            for (AnnotationMirror am : el.getAnnotationMirrors()) {
+                if 
(!grammarInjectionRegistrations.equals(am.getAnnotationType().asElement())) {
+                    continue;
+                }
+
+                for (Entry<? extends ExecutableElement, ? extends 
AnnotationValue> e : am.getElementValues().entrySet()) {
+                    if (!e.getKey().getSimpleName().contentEquals("value")) 
continue;
+
+                    for (AnnotationMirror r : 
NbCollections.iterable(NbCollections.checkedIteratorByFilter(((Iterable) 
e.getValue().getValue()).iterator(), AnnotationMirror.class, true))) {
+                        processInjection(el, r);
+                    }
+                }
+            }
+        }
+
         return true;
     }
 
@@ -131,7 +163,58 @@ public class CreateRegistrationProcessor extends 
LayerGeneratingProcessor {
                 String simpleName = grammar.lastIndexOf('/') != (-1) ? 
grammar.substring(grammar.lastIndexOf('/') + 1) : grammar;
                 layer.file("Editors" + mimeType + "/" + simpleName)
                      .url("nbresloc:/" + grammar)
-                     .stringvalue("textmate-grammar", scopeName).write();    
//NOI18N
+                     
.stringvalue(TextmateTokenId.LanguageHierarchyImpl.GRAMMAR_MARK, 
scopeName).write();    //NOI18N
+            } catch (Exception ex) {
+                throw (LayerGenerationException) new 
LayerGenerationException(ex.getMessage()).initCause(ex);
+            }
+        }
+    }
+
+    private void processInjection(Element toRegister, AnnotationMirror 
injectionRegistration) throws LayerGenerationException {
+        String grammar = null;
+        String injectTo = null;
+        for (Entry<? extends ExecutableElement, ? extends AnnotationValue> e : 
injectionRegistration.getElementValues().entrySet()) {
+            Name simpleName = e.getKey().getSimpleName();
+            if (simpleName.contentEquals("grammar")) {
+                grammar = (String) e.getValue().getValue();
+                continue;
+            }
+            if (simpleName.contentEquals("injectTo")) {
+                List<? extends AnnotationValue> values = (List<? extends 
AnnotationValue>) e.getValue().getValue();
+                for (AnnotationValue value : values) {
+                    if (injectTo == null) {
+                        injectTo = (String) value.getValue();
+                    } else {
+                        injectTo += "," + value.getValue();
+                    }
+                }
+            }
+        }
+
+        if (injectTo != null && grammar != null) {
+            LayerBuilder layer = layer(toRegister);
+            javax.tools.FileObject file = layer.validateResource(grammar, 
toRegister, null, null, false);
+            try (InputStream in = file.openInputStream()) {
+                IRegistryOptions opts = new IRegistryOptions() {
+                    @Override
+                    public String getFilePath(String scopeName) {
+                        return null;
+                    }
+                    @Override
+                    public InputStream getInputStream(String scopeName) throws 
IOException {
+                        return null;
+                    }
+                    @Override
+                    public Collection<String> getInjections(String scopeName) {
+                        return null;
+                    }
+                };
+                String scopeName = new 
Registry(opts).loadGrammarFromPathSync(grammar, in).getScopeName();
+                String simpleName = grammar.lastIndexOf('/') != (-1) ? 
grammar.substring(grammar.lastIndexOf('/') + 1) : grammar;
+                layer.file("Editors" + "/" + simpleName)
+                     .url("nbresloc:/" + grammar)
+                     
.stringvalue(TextmateTokenId.LanguageHierarchyImpl.GRAMMAR_MARK, scopeName)
+                     
.stringvalue(TextmateTokenId.LanguageHierarchyImpl.INJECTION_MARK, 
injectTo).write();    //NOI18N
             } catch (Exception ex) {
                 throw (LayerGenerationException) new 
LayerGenerationException(ex.getMessage()).initCause(ex);
             }
diff --git 
a/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/SyntaxHighlighting.java
 
b/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/SyntaxHighlighting.java
index 6cdfd9a..dae2064 100644
--- 
a/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/SyntaxHighlighting.java
+++ 
b/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/SyntaxHighlighting.java
@@ -675,26 +675,30 @@ implements TokenHierarchyListener, ChangeListener {
             List<String> categories = (List<String>) 
token.getProperty("categories");
             
             for (String category : categories) {
-                attrs.add(scopeName2Coloring.computeIfAbsent(category, c -> {
-                    String cat = category;
+                if (category.startsWith("meta.embedded")) {
+                    attrs.clear();
+                } else {
+                    attrs.add(scopeName2Coloring.computeIfAbsent(category, c 
-> {
+                        String cat = category;
 
-                    while (true) {
-                        AttributeSet currentAttrs = 
fcs.getTokenFontColors(cat);
+                        while (true) {
+                            AttributeSet currentAttrs = 
fcs.getTokenFontColors(cat);
 
-                        if (currentAttrs != null) {
-                            return currentAttrs;
-                        }
+                            if (currentAttrs != null) {
+                                return currentAttrs;
+                            }
 
-                        int dot = cat.lastIndexOf('.');
+                            int dot = cat.lastIndexOf('.');
 
-                        if (dot == (-1))
-                            break;
+                            if (dot == (-1))
+                                break;
 
-                        cat = cat.substring(0, dot);
-                    }
+                            cat = cat.substring(0, dot);
+                        }
 
-                    return SimpleAttributeSet.EMPTY;
-                }));
+                        return SimpleAttributeSet.EMPTY;
+                    }));
+                }
             }
 
             return AttributesUtilities.createComposite(attrs.toArray(new 
AttributeSet[0]));
diff --git 
a/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/TextmateLexer.java 
b/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/TextmateLexer.java
index f60a57b..ea833d5 100644
--- 
a/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/TextmateLexer.java
+++ 
b/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/TextmateLexer.java
@@ -70,7 +70,6 @@ public class TextmateLexer implements Lexer<TextmateTokenId>{
             while ((read = li.read()) != LexerInput.EOF && read != '\n');
             if (!forceReadLine) {
                 if (li.readLength() != 0) {
-                    System.err.println(li.readText().toString());
                     lineLen = li.readText().length();
                     currentOffset = 0;
                     ITokenizeLineResult tokenized = 
grammar.tokenizeLine(li.readText().toString(), state);
diff --git 
a/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/TextmateTokenId.java
 
b/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/TextmateTokenId.java
index 152ffba..7440639 100644
--- 
a/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/TextmateTokenId.java
+++ 
b/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/TextmateTokenId.java
@@ -20,6 +20,7 @@ package org.netbeans.modules.textmate.lexer;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Enumeration;
@@ -55,11 +56,14 @@ public enum TextmateTokenId implements TokenId {
     public static class LanguageHierarchyImpl extends 
LanguageHierarchy<TextmateTokenId> {
 
         public static final String GRAMMAR_MARK = "textmate-grammar";
+        public static final String INJECTION_MARK = "inject-to";
         private static final Map<String, FileObject> scope2File;
+        private static final Map<String, Collection<String>> scope2Injections;
         private static final Map<String, String> mimeType2Scope;
-        
+
         static {
             scope2File = new HashMap<>();
+            scope2Injections = new HashMap<>();
             mimeType2Scope = new HashMap<>();
             FileObject editors = 
FileUtil.getSystemConfigRoot().getFileObject("Editors");
             if (editors != null) {
@@ -70,7 +74,14 @@ public enum TextmateTokenId implements TokenId {
                     if (attr != null && attr instanceof String) {
                         String scope = (String) attr;
                         scope2File.put(scope, candidate);
-                        mimeType2Scope.put(FileUtil.getRelativePath(editors, 
candidate.getParent()), scope);
+                        attr = candidate.getAttribute(INJECTION_MARK);
+                        if (attr != null && attr instanceof String) {
+                            for (String s : ((String)attr).split(",")) {
+                                scope2Injections.computeIfAbsent(s, str -> new 
ArrayList<>()).add(scope);
+                            }
+                        } else {
+                            
mimeType2Scope.put(FileUtil.getRelativePath(editors, candidate.getParent()), 
scope);
+                        }
                     }
                 }
             }
@@ -94,7 +105,7 @@ public enum TextmateTokenId implements TokenId {
                 }
                 @Override
                 public Collection<String> getInjections(String scopeName) {
-                    return null;
+                    return scope2Injections.get(scopeName);
                 }
             };
             this.grammar = new Registry(opts).loadGrammar(scope);
diff --git 
a/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/api/GrammarRegistrations.java
 
b/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/api/GrammarInjectionRegistration.java
similarity index 56%
copy from 
ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/api/GrammarRegistrations.java
copy to 
ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/api/GrammarInjectionRegistration.java
index 7c7463b..f1bdc78 100644
--- 
a/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/api/GrammarRegistrations.java
+++ 
b/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/api/GrammarInjectionRegistration.java
@@ -19,19 +19,29 @@
 package org.netbeans.modules.textmate.lexer.api;
 
 import java.lang.annotation.ElementType;
+import java.lang.annotation.Repeatable;
 import java.lang.annotation.Target;
 
-/** Register multiple grammars.
- * 
- * @since 1.2
+/** Register the given TextMate grammar injection for use in the IDE.
+ * <p>For example, to register the injection grammar highlighting TODO keywords
+ * in JavaScript and TypeScript comments, add the following annotation to
+ * an appropriate package-info file or to an appropriate Java class:
+ * <p>{@code 
@GrammarInjectionRegistration(grammar="path/to/todo-injection.json", injectTo = 
{"source.js","source.ts"})}
+ * @since 1.3
  */
+@Repeatable(GrammarInjectionRegistrations.class)
 @Target({ElementType.PACKAGE, ElementType.TYPE})
-public @interface GrammarRegistrations {
+public @interface GrammarInjectionRegistration {
 
-    /**The grammar registration to delegate to.
+    /** The grammar to register.
      *
-     * @return grammar resitrations
+     * @return grammar
      */
-    public GrammarRegistration[] value();
+    public String grammar();
 
+    /** Target language scopes to inject the grammar into.
+     *
+     * @return array of scopes
+     */
+    public String[] injectTo();
 }
diff --git 
a/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/api/GrammarRegistrations.java
 
b/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/api/GrammarInjectionRegistrations.java
similarity index 79%
copy from 
ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/api/GrammarRegistrations.java
copy to 
ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/api/GrammarInjectionRegistrations.java
index 7c7463b..783a7c7 100644
--- 
a/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/api/GrammarRegistrations.java
+++ 
b/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/api/GrammarInjectionRegistrations.java
@@ -21,17 +21,17 @@ package org.netbeans.modules.textmate.lexer.api;
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Target;
 
-/** Register multiple grammars.
- * 
- * @since 1.2
+/** Register multiple grammar injections.
+ *
+ * @since 1.3
  */
 @Target({ElementType.PACKAGE, ElementType.TYPE})
-public @interface GrammarRegistrations {
+public @interface GrammarInjectionRegistrations {
 
-    /**The grammar registration to delegate to.
+    /**The grammar injection registration to delegate to.
      *
-     * @return grammar resitrations
+     * @return grammar injection registrations
      */
-    public GrammarRegistration[] value();
+    public GrammarInjectionRegistration[] value();
 
 }
diff --git 
a/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/api/GrammarRegistrations.java
 
b/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/api/GrammarRegistrations.java
index 7c7463b..d8988d3 100644
--- 
a/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/api/GrammarRegistrations.java
+++ 
b/ide/textmate.lexer/src/org/netbeans/modules/textmate/lexer/api/GrammarRegistrations.java
@@ -22,7 +22,7 @@ import java.lang.annotation.ElementType;
 import java.lang.annotation.Target;
 
 /** Register multiple grammars.
- * 
+ *
  * @since 1.2
  */
 @Target({ElementType.PACKAGE, ElementType.TYPE})
@@ -30,7 +30,7 @@ public @interface GrammarRegistrations {
 
     /**The grammar registration to delegate to.
      *
-     * @return grammar resitrations
+     * @return grammar registrations
      */
     public GrammarRegistration[] value();
 
diff --git 
a/ide/textmate.lexer/test/unit/src/org/netbeans/modules/textmate/lexer/CreateRegistrationProcessorTest.java
 
b/ide/textmate.lexer/test/unit/src/org/netbeans/modules/textmate/lexer/CreateRegistrationProcessorTest.java
index a9cbdc9..5579a5c 100644
--- 
a/ide/textmate.lexer/test/unit/src/org/netbeans/modules/textmate/lexer/CreateRegistrationProcessorTest.java
+++ 
b/ide/textmate.lexer/test/unit/src/org/netbeans/modules/textmate/lexer/CreateRegistrationProcessorTest.java
@@ -25,6 +25,7 @@ import java.io.InputStreamReader;
 import java.io.Reader;
 import java.io.Writer;
 import org.netbeans.junit.NbTestCase;
+import org.netbeans.modules.textmate.lexer.api.GrammarInjectionRegistration;
 import org.netbeans.modules.textmate.lexer.api.GrammarRegistration;
 import org.openide.util.test.AnnotationProcessorTestUtils;
 
@@ -90,5 +91,49 @@ public class CreateRegistrationProcessorTest extends 
NbTestCase {
                          content.toString());
         }
     }
-    
+
+    public void testInjectionGrammarOK() throws Exception {
+        System.setProperty("executed", "false");
+        AnnotationProcessorTestUtils.makeSource(getWorkDir(),
+                                                "Test",
+                                                "import " + 
GrammarInjectionRegistration.class.getCanonicalName() + ";\n" +
+                                                
"@GrammarInjectionRegistration(grammar=\"injection-grammar.json\", 
injectTo={\"test\"})\n" +
+                                                "public class Test {}\n");
+        try (Writer w = new FileWriter(new File(getWorkDir(), 
"injection-grammar.json"))) {
+            w.write("{ \"scopeName\": \"test.injection\", " +
+                    " \"patterns\": [\n" +
+                    "]}\n");
+        }
+
+        File outDir = new File(getWorkDir(), "out");
+
+        outDir.mkdirs();
+
+        assertTrue("Compiles OK",
+            AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, outDir, 
null, System.err)
+            );
+
+        try (Reader r = new InputStreamReader(new FileInputStream(new File(new 
File(outDir, "META-INF"), "generated-layer.xml")), "UTF-8")) {
+            StringBuilder content = new StringBuilder();
+            int read;
+
+            while ((read = r.read()) != (-1)) {
+                content.append((char) read);
+            }
+
+            assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+                         "<!DOCTYPE filesystem PUBLIC \"-//NetBeans//DTD 
Filesystem 1.2//EN\"\n" +
+                         "                            
\"http://www.netbeans.org/dtds/filesystem-1_2.dtd\";>\n" +
+                         "<filesystem>\n" +
+                         "    <folder name=\"Editors\">\n" +
+                         "        <file name=\"injection-grammar.json\" 
url=\"nbresloc:/injection-grammar.json\">\n" +
+                         "            <!--Test-->\n" +
+                         "            <attr name=\"textmate-grammar\" 
stringvalue=\"test.injection\"/>\n" +
+                         "            <attr name=\"inject-to\" 
stringvalue=\"test\"/>\n" +
+                         "        </file>\n" +
+                         "    </folder>\n" +
+                         "</filesystem>\n",
+                         content.toString());
+        }
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to