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

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git


The following commit(s) were added to refs/heads/develop by this push:
     new 2abad7b4e MXMLStyleNode, CSSNodeBase: fix line/column positions of CSS 
nodes
2abad7b4e is described below

commit 2abad7b4e2d217fc6ea3a033b7837b7ab3209805
Author: Josh Tynjala <joshtynj...@apache.org>
AuthorDate: Wed Feb 28 13:10:43 2024 -0800

    MXMLStyleNode, CSSNodeBase: fix line/column positions of CSS nodes
    
    Problems were being reported relative to the <fx:Style> element instead of 
to the full MXML document
---
 .../royale/compiler/internal/css/CSSNodeBase.java       | 17 ++++++++++++++++-
 .../compiler/internal/tree/mxml/MXMLStyleNode.java      |  8 ++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSNodeBase.java
 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSNodeBase.java
index ffa6c4bc8..af966c9da 100644
--- 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSNodeBase.java
+++ 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSNodeBase.java
@@ -82,6 +82,8 @@ class CSSNodeBase extends SourceLocation implements ICSSNode
     {
         int line = NOT_SET;
         int column = NOT_SET;
+        int endLine = NOT_SET;
+        int endColumn = NOT_SET;
         int start = NOT_SET;
         int stop = NOT_SET;
 
@@ -93,7 +95,7 @@ class CSSNodeBase extends SourceLocation implements ICSSNode
                     (CommonToken)tokenStream.get(tokenStartIndex);
             start = startToken.getStartIndex();
             line = startToken.getLine();
-            column = startToken.getCharPositionInLine() + 1;
+            column = startToken.getCharPositionInLine();
         }
 
         final int tokenStopIndex = tree.getTokenStopIndex();
@@ -102,12 +104,25 @@ class CSSNodeBase extends SourceLocation implements 
ICSSNode
             final CommonToken stopToken =
                     (CommonToken)tokenStream.get(tokenStopIndex);
             stop = stopToken.getStopIndex() + 1;
+            endLine = stopToken.getLine();
+            endColumn = stopToken.getCharPositionInLine() + 
stopToken.getText().length();
+        }
+
+        if (endLine == NOT_SET)
+        {
+            endLine = line;
+            if (endColumn == NOT_SET)
+            {
+                endColumn = column;
+            }
         }
 
         setStart(start);
         setEnd(stop);
         setLine(line);
         setColumn(column);
+        setEndLine(endLine);
+        setEndColumn(endColumn);
         setSourcePath(tokenStream.getSourceName());
     }
 
diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLStyleNode.java
 
b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLStyleNode.java
index 038f0345c..5d40c7e64 100644
--- 
a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLStyleNode.java
+++ 
b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLStyleNode.java
@@ -63,6 +63,8 @@ class MXMLStyleNode extends MXMLNodeBase implements 
IMXMLStyleNode
      * {@code <fx:Style src="styles.css" />}.
      */
     private String cssText;
+
+    private int cssTextStart = 0;
     
     /**
      * path of included css.
@@ -91,6 +93,8 @@ class MXMLStyleNode extends MXMLNodeBase implements 
IMXMLStyleNode
             {
                 ANTLRStringStream stream = new ANTLRStringStream(cssText);
                 stream.name = cssSourcePath != null ? cssSourcePath : 
getSourcePath();
+                stream.setLine(getLine());
+                stream.setCharPositionInLine(cssTextStart);
                 cssDocument = CSSDocument.parse(stream, problems);
             }
             else
@@ -122,6 +126,7 @@ class MXMLStyleNode extends MXMLNodeBase implements 
IMXMLStyleNode
             if (sourcePath != null)
             {
                 cssText = builder.readExternalFile(attribute, sourcePath);
+                cssTextStart = 0;
                 cssSourcePath = sourcePath;
             }
         }
@@ -154,7 +159,10 @@ class MXMLStyleNode extends MXMLNodeBase implements 
IMXMLStyleNode
 
         // If <fx:Style> tag has a valid 'source' attribute, the text of the 
node is ignored.
         if (cssText == null)
+        {
             cssText = tag.getCompilableText();
+            cssTextStart = tag.getEndColumn() + 1;
+        }
 
         // Register this "style" node with the root "MXMLFileNode".
         builder.getFileNode().getStyleNodes().add(this);

Reply via email to