Skip to content

Commit

Permalink
CSSDocumentUtils: use getters for certain children of ICSSNode implem…
Browse files Browse the repository at this point in the history
…entations

Those children can't be direct children, unfortunately, due to JBurg restrictions in the compiler
  • Loading branch information
joshtynjala committed Dec 9, 2024
1 parent 509d9e1 commit 98b89e8
Showing 1 changed file with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@

import java.util.ArrayList;

import org.apache.royale.compiler.css.ICSSCombinator;
import org.apache.royale.compiler.css.ICSSDocument;
import org.apache.royale.compiler.css.ICSSFontFace;
import org.apache.royale.compiler.css.ICSSNamespaceDefinition;
import org.apache.royale.compiler.css.ICSSNode;
import org.apache.royale.compiler.css.ICSSProperty;
import org.apache.royale.compiler.css.ICSSPropertyValue;
import org.apache.royale.compiler.css.ICSSSelector;
import org.apache.royale.compiler.css.ICSSSelectorCondition;
import org.apache.royale.compiler.problems.ICompilerProblem;
import org.apache.royale.compiler.tree.mxml.IMXMLStyleNode;

import com.google.common.collect.ImmutableList;

public class CSSDocumentUtils {
public static ICSSNamespaceDefinition getNamespaceForPrefix(String prefix, ICSSDocument cssDocument) {
if (prefix == null) {
Expand Down Expand Up @@ -51,6 +59,55 @@ public static ICSSNode getContainingCSSNodeIncludingStart(ICSSNode node, int off
if (!containsWithStart(node, offset)) {
return null;
}
// certain children don't appear with getNthChild()
if (node instanceof ICSSProperty) {
ICSSProperty cssProperty = (ICSSProperty) node;
ICSSPropertyValue cssPropertyValue = cssProperty.getValue();
if (cssPropertyValue != null) {
ICSSNode result = getContainingCSSNodeIncludingStart(cssPropertyValue, offset);
if (result != null) {
return result;
}
}
} else if (node instanceof ICSSCombinator) {
ICSSCombinator cssCombinator = (ICSSCombinator) node;
ICSSSelector cssSelector = cssCombinator.getSelector();
if (cssSelector != null) {
ICSSNode result = getContainingCSSNodeIncludingStart(cssSelector, offset);
if (result != null) {
return result;
}
}
} else if (node instanceof ICSSSelector) {
ICSSSelector cssSelector = (ICSSSelector) node;
ICSSCombinator cssCombinator = cssSelector.getCombinator();
if (cssCombinator != null) {
ICSSNode result = getContainingCSSNodeIncludingStart(cssCombinator, offset);
if (result != null) {
return result;
}
}
ImmutableList<ICSSSelectorCondition> cssConditions = cssSelector.getConditions();
if (cssConditions != null) {
for (ICSSSelectorCondition cssCondition : cssConditions) {
ICSSNode result = getContainingCSSNodeIncludingStart(cssCondition, offset);
if (result != null) {
return result;
}
}
}
} else if (node instanceof ICSSFontFace) {
ICSSFontFace cssFontFace = (ICSSFontFace) node;
ImmutableList<ICSSProperty> cssProperties = cssFontFace.getProperties();
if (cssProperties != null) {
for (ICSSProperty cssProperty : cssProperties) {
ICSSNode result = getContainingCSSNodeIncludingStart(cssProperty, offset);
if (result != null) {
return result;
}
}
}
}
for (int i = 0, count = node.getArity(); i < count; i++) {
ICSSNode child = node.getNthChild(i);
if (child.getAbsoluteStart() == -1) {
Expand Down

0 comments on commit 98b89e8

Please sign in to comment.