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 3a77e3334 ICSSNode: add getParent()
3a77e3334 is described below

commit 3a77e3334bc351554e723aefbab545a49385f768
Author: Josh Tynjala <[email protected]>
AuthorDate: Wed May 8 14:05:55 2024 -0700

    ICSSNode: add getParent()
    
    CSSNodeBase: add getParent() and setParent()
    
    Accessing parents will be useful for tooling that uses the compiler, like 
editors/IDEs
---
 .../org/apache/royale/compiler/css/ICSSNode.java   |  7 ++++++
 .../compiler/internal/caches/CSSDocumentCache.java |  6 +++++
 .../internal/css/CSSArrayPropertyValue.java        |  4 ++++
 .../royale/compiler/internal/css/CSSDocument.java  |  9 ++++++++
 .../internal/css/CSSMultiValuePropertyValue.java   |  4 ++++
 .../royale/compiler/internal/css/CSSNodeBase.java  | 23 +++++++++++++++++-
 .../royale/compiler/internal/css/CSSRule.java      | 27 ++++++++++++++++++++++
 7 files changed, 79 insertions(+), 1 deletion(-)

diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/css/ICSSNode.java 
b/compiler/src/main/java/org/apache/royale/compiler/css/ICSSNode.java
index db1f3b03a..2e34f4eb8 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/css/ICSSNode.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/css/ICSSNode.java
@@ -57,4 +57,11 @@ public interface ICSSNode extends ISourceLocation
      * @return Node type.
      */
     CSSModelTreeType getOperator();
+
+    /**
+     * Get the parent of this node
+     * 
+     * @return the parent of this node
+     */
+    ICSSNode getParent();
 }
diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/internal/caches/CSSDocumentCache.java
 
b/compiler/src/main/java/org/apache/royale/compiler/internal/caches/CSSDocumentCache.java
index 10c7cd421..3ac5513a0 100644
--- 
a/compiler/src/main/java/org/apache/royale/compiler/internal/caches/CSSDocumentCache.java
+++ 
b/compiler/src/main/java/org/apache/royale/compiler/internal/caches/CSSDocumentCache.java
@@ -138,6 +138,12 @@ public class CSSDocumentCache extends 
ConcurrentCacheStoreBase<ICSSDocument> imp
             throw new IllegalStateException();
         }
 
+        @Override
+        public ICSSNode getParent()
+        {
+            return null;
+        }
+
         @Override
         public String getSourcePath()
         {
diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSArrayPropertyValue.java
 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSArrayPropertyValue.java
index a394c13ce..b80508b37 100644
--- 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSArrayPropertyValue.java
+++ 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSArrayPropertyValue.java
@@ -42,6 +42,10 @@ public class CSSArrayPropertyValue extends CSSPropertyValue
     {
         super(ast, tokens, CSSModelTreeType.PROPERTY_VALUE);
         this.elements = ImmutableList.copyOf(elements);
+        for (CSSPropertyValue element : elements)
+        {
+            element.setParent(this);
+        }
         super.children.addAll(elements);
     }
 
diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSDocument.java
 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSDocument.java
index 6327e374c..cdf1da24e 100644
--- 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSDocument.java
+++ 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSDocument.java
@@ -134,14 +134,23 @@ public class CSSDocument extends CSSNodeBase implements 
ICSSDocument
         this.namespaces = new 
ImmutableList.Builder<ICSSNamespaceDefinition>().addAll(namespaces).build();
         this.fontFaces = new 
ImmutableList.Builder<ICSSFontFace>().addAll(fontFaces).build();
         
+        for (CSSRule rule : rules)
+        {
+            rule.setParent(this);
+        }
         Map<String, CSSNamespaceDefinition> namespaceMap = new HashMap<String, 
CSSNamespaceDefinition>();
         for (CSSNamespaceDefinition namespace : namespaces)
         {
             final String prefix = namespace.getPrefix();
             final String key = prefix != null ? prefix : 
DEFAULT_NAMESPACE_SHORT_NAME;
             namespaceMap.put(key, namespace);
+            namespace.setParent(this);
         }
         this.namespacesLookup = ImmutableMap.copyOf(namespaceMap);
+        for (CSSFontFace fontFace : fontFaces)
+        {
+            fontFace.setParent(this);
+        }
 
         // setup tree
         children.add(new CSSTypedNode(CSSModelTreeType.NAMESPACE_LIST, 
this.namespaces));
diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSMultiValuePropertyValue.java
 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSMultiValuePropertyValue.java
index 42ab7399a..00a6f5bc4 100644
--- 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSMultiValuePropertyValue.java
+++ 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSMultiValuePropertyValue.java
@@ -42,6 +42,10 @@ public class CSSMultiValuePropertyValue extends 
CSSPropertyValue
     {
         super(ast, tokens, CSSModelTreeType.PROPERTY_VALUE);
         this.elements = ImmutableList.copyOf(elements);
+        for (CSSPropertyValue element : elements)
+        {
+            element.setParent(this);
+        }
         super.children.addAll(elements);
     }
 
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 af966c9da..2a8fed8f8 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
@@ -27,9 +27,9 @@ import java.util.List;
 import org.antlr.runtime.CommonToken;
 import org.antlr.runtime.TokenStream;
 import org.antlr.runtime.tree.CommonTree;
-
 import org.apache.royale.compiler.common.SourceLocation;
 import org.apache.royale.compiler.css.ICSSNode;
+
 import com.google.common.base.Function;
 import com.google.common.base.Joiner;
 
@@ -72,6 +72,11 @@ class CSSNodeBase extends SourceLocation implements ICSSNode
      */
     protected final List<ICSSNode> children;
 
+    /**
+     * Parent node.
+     */
+    protected ICSSNode parent;
+
     /**
      * Initialize source location information.
      * 
@@ -180,4 +185,20 @@ class CSSNodeBase extends SourceLocation implements 
ICSSNode
     {
         return type;
     }
+
+    @Override
+    public ICSSNode getParent()
+    {
+        return parent;
+    }
+
+    /**
+     * Set the parent node. Used during parsing.
+     * 
+     * @param parent parent node
+     */
+    public void setParent(CSSNodeBase parent)
+    {
+        this.parent = parent;
+    }
 }
diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRule.java 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRule.java
index 24a8c536f..46cc36098 100644
--- 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRule.java
+++ 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSRule.java
@@ -49,14 +49,41 @@ public class CSSRule extends CSSNodeBase implements ICSSRule
         this.selectorGroup = new 
ImmutableList.Builder<ICSSSelector>().addAll(selectorGroup).build();
 
         if (mediaQueries == null)
+        {
             this.mediaQueryList = ImmutableList.of();
+        }
         else
+        {
             this.mediaQueryList = new 
ImmutableList.Builder<ICSSMediaQueryCondition>().addAll(mediaQueries).build();
+        }
 
         if (properties == null)
+        {
             this.propertyList = ImmutableList.of();
+        }
         else
+        {
             this.propertyList = new 
ImmutableList.Builder<ICSSProperty>().addAll(properties).build();
+        }
+
+        for (CSSSelector selector : selectorGroup)
+        {
+            selector.setParent(this);
+        }
+        if (mediaQueries != null)
+        {
+            for (CSSMediaQueryCondition mediaQuery : mediaQueries)
+            {
+                mediaQuery.setParent(this);
+            }
+        }
+        if (properties != null)
+        {
+            for (CSSProperty property : properties)
+            {
+                property.setParent(this);
+            }
+        }
 
         // setup tree
         this.children.add(new CSSTypedNode(CSSModelTreeType.SELECTOR_GROUP, 
this.selectorGroup));

Reply via email to