junichi11 commented on code in PR #4485:
URL: https://github.com/apache/netbeans/pull/4485#discussion_r1303762946


##########
ide/html.editor/src/org/netbeans/modules/html/editor/utils/HtmlTagContextUtils.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.html.editor.utils;
+
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.text.Document;
+import org.netbeans.api.html.lexer.HTMLTokenId;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.html.editor.api.Utils;
+
+/**
+ *
+ * @author Christian Lenz
+ */
+public class HtmlTagContextUtils {
+    private HtmlTagContextUtils() {
+    }
+
+    public static OffsetRange adjustContextRange(final Document doc, final int 
from, final int to, final boolean beforeClosingToken) {
+        final AtomicReference<OffsetRange> ret = new AtomicReference<>();
+        ret.set(new OffsetRange(from, to)); //return the same pair by default
+        doc.render(() -> {
+            TokenSequence<HTMLTokenId> ts = Utils.getJoinedHtmlSequence(doc, 
from);
+
+            if (ts == null) {
+                //no html token sequence at the offset, try to
+                //TODO possibly try to travese the top level sequence backward
+                //and try to find an html embedding.
+                return;
+            }
+
+            Token<HTMLTokenId> openTag = Utils.findTagOpenToken(ts);
+
+            if (openTag == null) {
+                return;
+            }
+
+            int adjustedFrom = ts.offset();
+
+            //now try to find the tag's end
+            ts.move(to);
+            int adjustedTo = -1;
+            while (ts.moveNext()) {
+                Token<HTMLTokenId> t = ts.token();

Review Comment:
   Need `null` Check



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
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