matthiasblaesing commented on code in PR #8367:
URL: https://github.com/apache/netbeans/pull/8367#discussion_r2019799532


##########
webcommon/javascript2.vue/src/org/netbeans/modules/javascript2/vue/editor/StringUtils.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.javascript2.vue.editor;
+
+/**
+ *
+ * @author bogdan.haidu
+ */
+public class StringUtils {
+
+    private StringUtils() {
+
+    }
+
+    public static String replaceLinesAndTabs(String input) {

Review Comment:
   Only used in test and there used for creating golden/test files. I would 
move it to `VueLexerTest`, make it private there and drop it in this file.



##########
webcommon/javascript2.vue/build.xml:
##########
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+-->
+<project basedir="." default="build" name="webcommon/javascript2.vue">
+    <description>Builds, tests, and runs the project 
org.netbeans.modules.js.vue.</description>
+    <import file="../../nbbuild/templates/projectized.xml"/>
+    <target name="build-init" description="Regenerate the ANTLRv4 parser" 
depends="projectized.build-init" extensionOf="-pre-compile">
+        <property name="lexer.outdir" 
location="${src.dir}/org/netbeans/modules/javascript2/vue/grammar/antlr4/coloring"/>
+        
+        <!--coloring-->
+        <java classname="org.antlr.v4.Tool"  fork="true" dir="${lexer.outdir}">
+            <arg value="-o"/>
+            <arg value="${lexer.outdir}"/>
+            <arg value="VueAntlrColoringLexer.g4"/>
+        </java>
+        
+        <delete dir="${lexer.outdir}" includes="*.tokens"/>
+        <delete dir="${lexer.outdir}" includes="*.interp"/>
+    </target>

Review Comment:
   This fails to build:
   
   ```
   projectized.build-init:
   Loading module list from /tmp/nb-scan-cache-bd6651d1-full.ser
   
   build-init:
        [java] Error: Could not find or load main class org.antlr.v4.Tool
        [java] Caused by: java.lang.ClassNotFoundException: org.antlr.v4.Tool
        [java] Java Result: 1
   
   -javac-init-nbjdk:
   Trying to override old definition of task custom-javac
   ```
   
   The missing lexer will later cause problems.



##########
webcommon/javascript2.vue/src/org/netbeans/modules/javascript2/vue/editor/VueUtils.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.javascript2.vue.editor;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+
+/**
+ *
+ * @author bogdan.haidu
+ */
+public class VueUtils {
+
+    private VueUtils() {
+
+    }
+
+    public static String getFileContent(File file) throws Exception {

Review Comment:
   This is unused, please remove.



##########
webcommon/javascript2.vue/licenseinfo.xml:
##########
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+-->
+<licenseinfo>
+    <fileset>
+        
<file>src/org/netbeans/modules/javascript2/vue/resources/vueTemplate.vue</file>
+        
<file>src/org/netbeans/modules/javascript2/vue/resources/coloring.vue</file>
+        <license ref="Apache-2.0-ASF" />
+        <comment type="GUI_USABILITY" />
+    </fileset>
+    <fileset>
+        
<file>src/org/netbeans/modules/javascript2/vue/resources/vue16.png</file>

Review Comment:
   I assume, that you created this yourself?



##########
webcommon/javascript2.vue/test/unit/src/org/netbeans/modules/javascript2/vue/editor/lexer/VueLexerUtils.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.javascript2.vue.editor.lexer;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author bogdan
+ */
+public class VueLexerUtils extends TestCase {
+
+    public static String getFileContent(File file) throws Exception {

Review Comment:
   Can be removed (see comment in `VueLexerTest`)



##########
webcommon/javascript2.vue/src/org/netbeans/modules/javascript2/vue/editor/embedding/VueHtmlEmbeddingProvider.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.javascript2.vue.editor.embedding;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenId;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.javascript2.vue.editor.VueLanguage;
+import org.netbeans.modules.javascript2.vue.editor.lexer.VueTokenId;
+import org.netbeans.modules.parsing.api.Embedding;
+import org.netbeans.modules.parsing.api.Snapshot;
+import org.netbeans.modules.parsing.spi.EmbeddingProvider;
+
+/**
+ * this will enable braces matches of html elements
+ * 
+ * @author bhaidu
+ */
+@EmbeddingProvider.Registration(
+        mimeType = VueLanguage.MIME_TYPE,
+        targetMimeType = "text/html")
+public class VueHtmlEmbeddingProvider extends EmbeddingProvider {
+    public static final String FILLER = " "; //NOI18N
+    public static final String TARGET_MIME_TYPE = "text/html"; //NOI18N
+
+    @Override
+    public List<Embedding> getEmbeddings(final Snapshot snapshot) {
+        TokenHierarchy<?> tokenHierarchy = snapshot.getTokenHierarchy();
+        TokenSequence<?> sequence = tokenHierarchy.tokenSequence();
+        
+        if (sequence == null || !sequence.isValid()) {
+            return Collections.emptyList();
+        }
+        sequence.moveStart();
+        List<Embedding> embeddings = new ArrayList<>();
+
+        int offset = 0;
+        int len = 0;
+
+        String fake;
+
+        try {
+            while (sequence.moveNext()) {
+                Token<?> t = sequence.token();
+                offset = sequence.offset();
+                TokenId id = t.id();
+                len += t.length();
+                String tText = t.text().toString();
+                if (len == 0) {
+                    continue;
+                }
+                if (id.equals(VueTokenId.HTML)) {
+                    embeddings.add(snapshot.create(offset, t.length(), 
TARGET_MIME_TYPE));
+                } else {
+                    fake = new String(new char[tText.length()]).replace("\0", 
FILLER); //NOI18N
+                    embeddings.add(snapshot.create(fake, TARGET_MIME_TYPE));

Review Comment:
   Why? There is no embedding, why fake one?



##########
webcommon/javascript2.vue/src/org/netbeans/modules/javascript2/vue/grammar/antlr4/coloring/ColoringLexerAdaptor.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.javascript2.vue.grammar.antlr4.coloring;
+
+import org.antlr.v4.runtime.CharStream;
+import org.antlr.v4.runtime.Lexer;
+
+/**
+ *
+ * @author bogdan
+ */
+public abstract class ColoringLexerAdaptor extends Lexer {
+
+    private boolean insideTemplateTag = false;
+    private boolean insideStyleTag = false;
+    private boolean attrQuoteOpened = false;
+    private boolean varInterpolationOpened = false;
+
+    public ColoringLexerAdaptor(CharStream input) {
+        super(input);
+    }
+
+    @Override
+    public void reset() {
+        insideTemplateTag = false;

Review Comment:
   Why is only one of four fields reset?



##########
webcommon/javascript2.vue/test/unit/src/org/netbeans/modules/javascript2/vue/editor/lexer/VueLexerTest.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.javascript2.vue.editor.lexer;
+
+import java.io.File;
+import static junit.framework.TestCase.assertNotNull;
+import org.netbeans.api.lexer.Language;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.lib.lexer.test.LexerTestUtilities;
+import org.netbeans.modules.javascript2.vue.editor.StringUtils;
+import org.netbeans.modules.javascript2.vue.editor.VueLanguage;
+import org.netbeans.modules.javascript2.vue.editor.VueTestBase;
+
+/**
+ *
+ * @author bogdan.haidu
+ */
+public class VueLexerTest extends VueTestBase {
+
+    public VueLexerTest(String name) {
+        super(name);
+    }
+
+    @Override
+    public void setUp() throws Exception {
+        LexerTestUtilities.setTesting(true);
+    }
+
+    public void testAttributeBindingLexer_01() throws Exception {
+        checkLexer("testfiles/lexer/vue/attribute_binding_01.vue");
+    }
+
+    public void testTemplateLexer_01() throws Exception {
+        checkLexer("testfiles/lexer/vue/template_01.vue");
+    }
+
+    public void testUserInputLexer_01() throws Exception {
+        checkLexer("testfiles/lexer/vue/user_input_01.vue");
+    }
+
+    public void testComponentLexer_01() throws Exception {
+        checkLexer("testfiles/lexer/vue/component_01.vue");
+    }
+
+    private void checkLexer(final String filePath) throws Exception {
+        String fileContent = VueLexerUtils.getFileContent(new 
File(getDataDir(), filePath));

Review Comment:
   Add:
   
   ```
   import java.nio.file.Files;
   ```
   
   then:
   
   ```suggestion
           String fileContent = Files.getString(new File(getDataDir(), 
filePath).toPath());
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org
For additional commands, e-mail: notifications-h...@netbeans.apache.org

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

Reply via email to