[visualforce] Fix deprecated API usage

This commit is contained in:
Andreas Dangel 2023-12-15 20:38:51 +01:00
parent 4e02a21e3a
commit 3cdc99be81
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
8 changed files with 99 additions and 111 deletions

View File

@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.vf.ast;
import java.util.IdentityHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -90,8 +89,7 @@ public final class ASTExpression extends AbstractVfNode {
Map<VfTypedNode, String> result = new IdentityHashMap<>();
int numChildren = getNumChildren();
List<ASTIdentifier> identifiers = findChildrenOfType(ASTIdentifier.class);
for (ASTIdentifier identifier : identifiers) {
for (ASTIdentifier identifier : children(ASTIdentifier.class)) {
@SuppressWarnings("PMD.LooseCoupling") // see #1218 - we are calling getLast() which is LinkedList specific
LinkedList<VfTypedNode> identifierNodes = new LinkedList<>();

View File

@ -54,12 +54,12 @@ final class ApexClassPropertyTypesVisitor extends ApexVisitorBase<Void, Void> {
if (node.getArity() == 0
&& isVisibleToVisualForce(node)
&& !RETURN_TYPE_VOID.equalsIgnoreCase(node.getReturnType())
&& (node.hasRealLoc() || node.getFirstParentOfType(ASTProperty.class) != null)) {
&& (node.hasRealLoc() || node.ancestors(ASTProperty.class).first() != null)) {
StringBuilder sb = new StringBuilder();
List<ASTUserClass> parents = node.getParentsOfType(ASTUserClass.class);
List<ASTUserClass> parents = node.ancestors(ASTUserClass.class).toList();
Collections.reverse(parents);
for (ASTUserClass parent : parents) {
sb.append(parent.getImage()).append(".");
sb.append(parent.getSimpleName()).append(".");
}
String name = node.getImage();
for (String prefix : new String[]{BEAN_GETTER_PREFIX, PROPERTY_PREFIX_ACCESSOR}) {
@ -80,7 +80,7 @@ final class ApexClassPropertyTypesVisitor extends ApexVisitorBase<Void, Void> {
* @return true if the method is visible to Visualforce.
*/
private boolean isVisibleToVisualForce(ASTMethod node) {
ASTModifierNode modifier = node.getFirstChildOfType(ASTModifierNode.class);
ASTModifierNode modifier = node.firstChild(ASTModifierNode.class);
return modifier.isGlobal() | modifier.isPublic();
}
}

View File

@ -24,7 +24,7 @@ public class VfCsrfRule extends AbstractVfRule {
@Override
public Object visit(ASTElement node, Object data) {
if (APEX_PAGE.equalsIgnoreCase(node.getName())) {
List<ASTAttribute> attribs = node.findChildrenOfType(ASTAttribute.class);
List<ASTAttribute> attribs = node.children(ASTAttribute.class).toList();
boolean controller = false;
boolean isEl = false;
ASTElExpression valToReport = null;
@ -32,7 +32,7 @@ public class VfCsrfRule extends AbstractVfRule {
for (ASTAttribute attr : attribs) {
switch (attr.getName().toLowerCase(Locale.ROOT)) {
case "action":
ASTElExpression value = attr.getFirstDescendantOfType(ASTElExpression.class);
ASTElExpression value = attr.descendants(ASTElExpression.class).first();
if (value != null) {
if (doesElContainIdentifiers(value)) {
isEl = true;
@ -51,7 +51,7 @@ public class VfCsrfRule extends AbstractVfRule {
}
if (controller && isEl && valToReport != null) {
addViolation(data, valToReport);
asCtx(data).addViolation(valToReport);
}
}
@ -59,6 +59,6 @@ public class VfCsrfRule extends AbstractVfRule {
}
private boolean doesElContainIdentifiers(ASTElExpression value) {
return value.getFirstDescendantOfType(ASTIdentifier.class) != null;
return value.descendants(ASTIdentifier.class).first() != null;
}
}

View File

@ -8,6 +8,9 @@ import java.util.EnumSet;
import java.util.Set;
import java.util.regex.Pattern;
import org.checkerframework.checker.nullness.qual.NonNull;
import net.sourceforge.pmd.lang.rule.RuleTargetSelector;
import net.sourceforge.pmd.lang.vf.ast.ASTContent;
import net.sourceforge.pmd.lang.vf.ast.ASTElExpression;
import net.sourceforge.pmd.lang.vf.ast.ASTElement;
@ -24,8 +27,9 @@ public class VfHtmlStyleTagXssRule extends AbstractVfRule {
private static final Set<ElEscapeDetector.Escaping> ANY_ENCODE = EnumSet.of(ElEscapeDetector.Escaping.ANY);
private static final Pattern URL_METHOD_PATTERN = Pattern.compile("url\\s*\\([^)]*$", Pattern.CASE_INSENSITIVE);
public VfHtmlStyleTagXssRule() {
addRuleChainVisit(ASTElExpression.class);
@Override
protected @NonNull RuleTargetSelector buildTargetSelector() {
return RuleTargetSelector.forTypes(ASTElExpression.class);
}
/**
@ -107,8 +111,7 @@ public class VfHtmlStyleTagXssRule extends AbstractVfRule {
if (ElEscapeDetector.doesElContainAnyUnescapedIdentifiers(
elExpressionNode,
URLENCODE_JSINHTMLENCODE)) {
addViolationWithMessage(
data,
asCtx(data).addViolationWithMessage(
elExpressionNode,
"Dynamic EL content within URL in style tag should be URLENCODED or JSINHTMLENCODED as appropriate");
}
@ -119,8 +122,7 @@ public class VfHtmlStyleTagXssRule extends AbstractVfRule {
if (ElEscapeDetector.doesElContainAnyUnescapedIdentifiers(
elExpressionNode,
ANY_ENCODE)) {
addViolationWithMessage(
data,
asCtx(data).addViolationWithMessage(
elExpressionNode,
"Dynamic EL content in style tag should be appropriately encoded");
}

View File

@ -69,13 +69,13 @@ public class VfUnescapeElRule extends AbstractVfRule {
private void processElInScriptContext(ASTElExpression elExpression, Object data) {
if (!properlyEscaped(elExpression)) {
addViolation(data, elExpression);
asCtx(data).addViolation(elExpression);
}
}
private boolean properlyEscaped(ASTElExpression el) {
// Find the first Expression-type child of this top-level node.
ASTExpression expression = el.getFirstChildOfType(ASTExpression.class);
ASTExpression expression = el.firstChild(ASTExpression.class);
// If no such node was found, then there's nothing to escape, so we're fine.
return expression == null
@ -105,7 +105,7 @@ public class VfUnescapeElRule extends AbstractVfRule {
return;
}
final List<ASTAttribute> attributes = node.findChildrenOfType(ASTAttribute.class);
final List<ASTAttribute> attributes = node.children(ASTAttribute.class).toList();
boolean isEL = false;
final Set<ASTElExpression> toReport = new HashSet<>();
@ -116,7 +116,7 @@ public class VfUnescapeElRule extends AbstractVfRule {
if (HREF.equalsIgnoreCase(name) || SRC.equalsIgnoreCase(name)) {
boolean startingWithSlashText = false;
final ASTText attrText = attr.getFirstDescendantOfType(ASTText.class);
final ASTText attrText = attr.descendants(ASTText.class).first();
if (attrText != null) {
if (0 == attrText.getIndexInParent()) {
String lowerCaseImage = attrText.getImage().toLowerCase(Locale.ROOT);
@ -128,8 +128,7 @@ public class VfUnescapeElRule extends AbstractVfRule {
}
if (!startingWithSlashText) {
final List<ASTElExpression> elsInVal = attr.findDescendantsOfType(ASTElExpression.class);
for (ASTElExpression el : elsInVal) {
for (ASTElExpression el : attr.descendants(ASTElExpression.class)) {
if (startsWithSlashLiteral(el)) {
break;
}
@ -151,24 +150,22 @@ public class VfUnescapeElRule extends AbstractVfRule {
if (isEL) {
for (ASTElExpression expr : toReport) {
addViolation(data, expr);
asCtx(data).addViolation(expr);
}
}
}
private void checkAllOnEventTags(ASTElement node, Object data) {
final List<ASTAttribute> attributes = node.findChildrenOfType(ASTAttribute.class);
boolean isEL = false;
final Set<ASTElExpression> toReport = new HashSet<>();
for (ASTAttribute attr : attributes) {
for (ASTAttribute attr : node.children(ASTAttribute.class)) {
String name = attr.getName().toLowerCase(Locale.ROOT);
// look for onevents
if (ON_EVENT.matcher(name).matches()) {
final List<ASTElExpression> elsInVal = attr.findDescendantsOfType(ASTElExpression.class);
for (ASTElExpression el : elsInVal) {
for (ASTElExpression el : attr.descendants(ASTElExpression.class)) {
if (ElEscapeDetector.startsWithSafeResource(el)) {
continue;
}
@ -184,16 +181,16 @@ public class VfUnescapeElRule extends AbstractVfRule {
if (isEL) {
for (ASTElExpression expr : toReport) {
addViolation(data, expr);
asCtx(data).addViolation(expr);
}
}
}
private boolean startsWithSlashLiteral(final ASTElExpression elExpression) {
final ASTExpression expression = elExpression.getFirstChildOfType(ASTExpression.class);
final ASTExpression expression = elExpression.firstChild(ASTExpression.class);
if (expression != null) {
final ASTLiteral literal = expression.getFirstChildOfType(ASTLiteral.class);
final ASTLiteral literal = expression.firstChild(ASTLiteral.class);
if (literal != null && literal.getIndexInParent() == 0) {
String lowerCaseLiteral = literal.getImage().toLowerCase(Locale.ROOT);
if (lowerCaseLiteral.startsWith("'/") || lowerCaseLiteral.startsWith("\"/")
@ -209,18 +206,17 @@ public class VfUnescapeElRule extends AbstractVfRule {
}
private void checkApexTagsThatSupportEscaping(ASTElement node, Object data) {
final List<ASTAttribute> attributes = node.findChildrenOfType(ASTAttribute.class);
final Set<ASTElExpression> toReport = new HashSet<>();
boolean isUnescaped = false;
boolean isEL = false;
boolean hasPlaceholders = false;
for (ASTAttribute attr : attributes) {
for (ASTAttribute attr : node.children(ASTAttribute.class)) {
String name = attr.getName().toLowerCase(Locale.ROOT);
switch (name) {
case ESCAPE:
case ITEM_ESCAPED:
final ASTText text = attr.getFirstDescendantOfType(ASTText.class);
final ASTText text = attr.descendants(ASTText.class).first();
if (text != null) {
if (FALSE.equalsIgnoreCase(text.getImage())) {
isUnescaped = true;
@ -230,8 +226,7 @@ public class VfUnescapeElRule extends AbstractVfRule {
case VALUE:
case ITEM_VALUE:
final List<ASTElExpression> elsInVal = attr.findDescendantsOfType(ASTElExpression.class);
for (ASTElExpression el : elsInVal) {
for (ASTElExpression el : attr.descendants(ASTElExpression.class)) {
if (ElEscapeDetector.startsWithSafeResource(el)) {
continue;
}
@ -243,7 +238,7 @@ public class VfUnescapeElRule extends AbstractVfRule {
}
}
final ASTText textValue = attr.getFirstDescendantOfType(ASTText.class);
final ASTText textValue = attr.descendants(ASTText.class).first();
if (textValue != null) {
if (PLACEHOLDERS.matcher(textValue.getImage()).matches()) {
@ -260,13 +255,13 @@ public class VfUnescapeElRule extends AbstractVfRule {
if (hasPlaceholders && isUnescaped) {
for (ASTElExpression expr : hasELInInnerElements(node)) {
addViolation(data, expr);
asCtx(data).addViolation(expr);
}
}
if (isEL && isUnescaped) {
for (ASTElExpression expr : toReport) {
addViolation(data, expr);
asCtx(data).addViolation(expr);
}
}
}
@ -290,15 +285,12 @@ public class VfUnescapeElRule extends AbstractVfRule {
private Set<ASTElExpression> hasELInInnerElements(final ASTElement node) {
final Set<ASTElExpression> toReturn = new HashSet<>();
final ASTContent content = node.getFirstChildOfType(ASTContent.class);
final ASTContent content = node.firstChild(ASTContent.class);
if (content != null) {
final List<ASTElement> innerElements = content.findChildrenOfType(ASTElement.class);
for (final ASTElement element : innerElements) {
for (final ASTElement element : content.children(ASTElement.class)) {
if (APEX_PARAM.equalsIgnoreCase(element.getName())) {
final List<ASTAttribute> innerAttributes = element.findChildrenOfType(ASTAttribute.class);
for (ASTAttribute attrib : innerAttributes) {
final List<ASTElExpression> elsInVal = attrib.findDescendantsOfType(ASTElExpression.class);
for (final ASTElExpression el : elsInVal) {
for (ASTAttribute attrib : element.children(ASTAttribute.class)) {
for (final ASTElExpression el : attrib.descendants(ASTElExpression.class)) {
if (ElEscapeDetector.startsWithSafeResource(el)) {
continue;
}

View File

@ -121,7 +121,7 @@ public final class ElEscapeDetector {
}
// If none of those things are true, then we need to determine whether the field being accessed is
// definitely safe.
ASTIdentifier propId = child.getFirstChildOfType(ASTIdentifier.class);
ASTIdentifier propId = child.firstChild(ASTIdentifier.class);
// If there's an identifier for a field/property, we need to check whether that property is inherently safe,
// either because it corresponds to a safe field or because its data type is known to be safe.
if (propId != null && !isSafeProperty(propId.getImage()) && !typedNodeIsSafe(propId)) {
@ -278,24 +278,22 @@ public final class ElEscapeDetector {
}
public static boolean containsSafeFields(final VfNode expression) {
final ASTExpression ex = expression.getFirstChildOfType(ASTExpression.class);
final ASTExpression ex = expression.firstChild(ASTExpression.class);
return ex != null && innerContainsSafeFields(ex);
}
public static boolean startsWithSafeResource(final ASTElExpression el) {
final ASTExpression expression = el.getFirstChildOfType(ASTExpression.class);
final ASTExpression expression = el.firstChild(ASTExpression.class);
if (expression != null) {
final ASTNegationExpression negation = expression.getFirstChildOfType(ASTNegationExpression.class);
final ASTNegationExpression negation = expression.firstChild(ASTNegationExpression.class);
if (negation != null) {
return true;
}
final ASTIdentifier id = expression.getFirstChildOfType(ASTIdentifier.class);
final ASTIdentifier id = expression.firstChild(ASTIdentifier.class);
if (id != null) {
List<ASTArguments> args = expression.findChildrenOfType(ASTArguments.class);
if (!args.isEmpty()) {
if (expression.children(ASTArguments.class).nonEmpty()) {
return functionInherentlySafe(id.getImage());
} else {
return isSafeGlobal(id.getImage());
@ -317,8 +315,7 @@ public final class ElEscapeDetector {
final Set<ASTIdentifier> nonEscapedIds = new HashSet<>();
final List<ASTExpression> exprs = elExpression.findChildrenOfType(ASTExpression.class);
for (final ASTExpression expr : exprs) {
for (final ASTExpression expr : elExpression.children(ASTExpression.class)) {
if (innerContainsSafeFields(expr)) {
continue;
@ -328,8 +325,7 @@ public final class ElEscapeDetector {
continue;
}
final List<ASTIdentifier> ids = expr.findChildrenOfType(ASTIdentifier.class);
for (final ASTIdentifier id : ids) {
for (final ASTIdentifier id : expr.children(ASTIdentifier.class)) {
boolean isEscaped = false;
for (Escaping e : escapes) {

View File

@ -43,7 +43,7 @@ class VfDocStyleTest extends AbstractVfTest {
ASTCompilationUnit root = vf.parse(TEST_ELEMENT_AND_NAMESPACE);
List<ASTElement> elementNodes = root.findDescendantsOfType(ASTElement.class);
List<ASTElement> elementNodes = root.descendants(ASTElement.class).toList();
assertEquals(1, elementNodes.size(), "One element node expected!");
ASTElement element = elementNodes.iterator().next();
assertEquals("h:html", element.getName(), "Correct name expected!");
@ -52,7 +52,7 @@ class VfDocStyleTest extends AbstractVfTest {
assertEquals("h", element.getNamespacePrefix(), "Correct namespace prefix of element expected!");
assertEquals("html", element.getLocalName(), "Correct local name of element expected!");
List<ASTAttribute> attributeNodes = root.findDescendantsOfType(ASTAttribute.class);
List<ASTAttribute> attributeNodes = root.descendants(ASTAttribute.class).toList();
assertEquals(1, attributeNodes.size(), "One attribute node expected!");
ASTAttribute attribute = attributeNodes.iterator().next();
assertEquals("MyNsPrefix:MyAttr", attribute.getName(), "Correct name expected!");
@ -75,17 +75,17 @@ class VfDocStyleTest extends AbstractVfTest {
ASTAttribute attr = attributes.get(0);
assertEquals("something", attr.getName(), "Correct attribute name expected!");
assertEquals("#yes#", attr.getFirstDescendantOfType(ASTText.class).getImage(),
assertEquals("#yes#", attr.descendants(ASTText.class).first().getImage(),
"Correct attribute value expected!");
attr = attributes.get(1);
assertEquals("foo", attr.getName(), "Correct attribute name expected!");
assertEquals("CREATE", attr.getFirstDescendantOfType(ASTText.class).getImage(),
assertEquals("CREATE", attr.descendants(ASTText.class).first().getImage(),
"Correct attribute value expected!");
attr = attributes.get(2);
assertEquals("href", attr.getName(), "Correct attribute name expected!");
assertEquals("#", attr.getFirstDescendantOfType(ASTText.class).getImage(), "Correct attribute value expected!");
assertEquals("#", attr.descendants(ASTText.class).first().getImage(), "Correct attribute value expected!");
}
@ -108,12 +108,12 @@ class VfDocStyleTest extends AbstractVfTest {
void testDoctype() {
ASTCompilationUnit root = vf.parse(TEST_DOCTYPE);
List<ASTDoctypeDeclaration> docTypeDeclarations = root.findDescendantsOfType(ASTDoctypeDeclaration.class);
List<ASTDoctypeDeclaration> docTypeDeclarations = root.descendants(ASTDoctypeDeclaration.class).toList();
assertEquals(1, docTypeDeclarations.size(), "One doctype declaration expected!");
ASTDoctypeDeclaration docTypeDecl = docTypeDeclarations.iterator().next();
assertEquals("html", docTypeDecl.getName(), "Correct doctype-name expected!");
List<ASTDoctypeExternalId> externalIds = root.findDescendantsOfType(ASTDoctypeExternalId.class);
List<ASTDoctypeExternalId> externalIds = root.descendants(ASTDoctypeExternalId.class).toList();
assertEquals(1, externalIds.size(), "One doctype external id expected!");
ASTDoctypeExternalId externalId = externalIds.iterator().next();
assertEquals("-//W3C//DTD XHTML 1.1//EN", externalId.getPublicId(), "Correct external public id expected!");
@ -130,7 +130,7 @@ class VfDocStyleTest extends AbstractVfTest {
List<ASTHtmlScript> scripts = vf.getNodes(ASTHtmlScript.class, TEST_HTML_SCRIPT);
assertEquals(1, scripts.size(), "One script expected!");
ASTHtmlScript script = scripts.iterator().next();
ASTText text = script.getFirstChildOfType(ASTText.class);
ASTText text = script.firstChild(ASTText.class);
assertEquals("Script!", text.getImage(), "Correct script content expected!");
}
@ -142,8 +142,8 @@ class VfDocStyleTest extends AbstractVfTest {
List<ASTElement> elements = vf.getNodes(ASTElement.class, TEST_EL_IN_TAG_ATTRIBUTE);
assertEquals(1, elements.size(), "One element expected!");
ASTElement element = elements.iterator().next();
ASTAttributeValue attribute = element.getFirstDescendantOfType(ASTAttributeValue.class);
ASTIdentifier id = attribute.getFirstDescendantOfType(ASTIdentifier.class);
ASTAttributeValue attribute = element.descendants(ASTAttributeValue.class).first();
ASTIdentifier id = attribute.descendants(ASTIdentifier.class).first();
assertEquals("foo", id.getImage(), "Correct identifier expected");
}
@ -156,8 +156,8 @@ class VfDocStyleTest extends AbstractVfTest {
List<ASTElement> elements = vf.getNodes(ASTElement.class, TEST_EL_IN_TAG_ATTRIBUTE_WITH_COMMENT);
assertEquals(1, elements.size(), "One element expected!");
ASTElement element = elements.iterator().next();
ASTElExpression elExpr = element.getFirstDescendantOfType(ASTElExpression.class);
ASTIdentifier id = elExpr.getFirstDescendantOfType(ASTIdentifier.class);
ASTElExpression elExpr = element.descendants(ASTElExpression.class).first();
ASTIdentifier id = elExpr.descendants(ASTIdentifier.class).first();
assertEquals("init", id.getImage(), "Correct identifier expected");
}
@ -169,8 +169,8 @@ class VfDocStyleTest extends AbstractVfTest {
List<ASTElement> elements = vf.getNodes(ASTElement.class, TEST_EL_IN_TAG_ATTRIBUTE_WITH_COMMENT_SQ);
assertEquals(1, elements.size(), "One element expected!");
ASTElement element = elements.iterator().next();
ASTElExpression elExpr = element.getFirstDescendantOfType(ASTElExpression.class);
ASTIdentifier id = elExpr.getFirstDescendantOfType(ASTIdentifier.class);
ASTElExpression elExpr = element.descendants(ASTElExpression.class).first();
ASTIdentifier id = elExpr.descendants(ASTIdentifier.class).first();
assertEquals("init", id.getImage(), "Correct identifier expected");
}
@ -183,10 +183,10 @@ class VfDocStyleTest extends AbstractVfTest {
List<ASTHtmlScript> scripts = vf.getNodes(ASTHtmlScript.class, TEST_EL_IN_HTML_SCRIPT);
assertEquals(1, scripts.size(), "One script expected!");
ASTHtmlScript script = scripts.iterator().next();
ASTText text = script.getFirstChildOfType(ASTText.class);
ASTText text = script.firstChild(ASTText.class);
assertEquals("vartext=", text.getImage(), "Correct script content expected!");
ASTElExpression el = script.getFirstChildOfType(ASTElExpression.class);
ASTIdentifier id = el.getFirstDescendantOfType(ASTIdentifier.class);
ASTElExpression el = script.firstChild(ASTElExpression.class);
ASTIdentifier id = el.descendants(ASTIdentifier.class).first();
assertEquals("elInScript", id.getImage(), "Correct EL content expected!");
}
@ -198,10 +198,10 @@ class VfDocStyleTest extends AbstractVfTest {
List<ASTHtmlScript> scripts = vf.getNodes(ASTHtmlScript.class, TEST_EL_IN_HTML_SCRIPT_WITH_COMMENT);
assertEquals(1, scripts.size(), "One script expected!");
ASTHtmlScript script = scripts.iterator().next();
ASTText text = script.getFirstChildOfType(ASTText.class);
ASTText text = script.firstChild(ASTText.class);
assertEquals("vartext=", text.getImage(), "Correct script content expected!");
ASTElExpression el = script.getFirstChildOfType(ASTElExpression.class);
ASTIdentifier id = el.getFirstDescendantOfType(ASTIdentifier.class);
ASTElExpression el = script.firstChild(ASTElExpression.class);
ASTIdentifier id = el.descendants(ASTIdentifier.class).first();
assertEquals("elInScript", id.getImage(), "Correct EL content expected!");
}
@ -213,10 +213,10 @@ class VfDocStyleTest extends AbstractVfTest {
List<ASTHtmlScript> scripts = vf.getNodes(ASTHtmlScript.class, TEST_QUOTED_EL_IN_HTML_SCRIPT);
assertEquals(1, scripts.size(), "One script expected!");
ASTHtmlScript script = scripts.iterator().next();
ASTText text = script.getFirstChildOfType(ASTText.class);
ASTText text = script.firstChild(ASTText.class);
assertEquals("vartext='textHere", text.getImage(), "Correct script content expected!");
ASTElExpression el = script.getFirstChildOfType(ASTElExpression.class);
ASTIdentifier id = el.getFirstDescendantOfType(ASTIdentifier.class);
ASTElExpression el = script.firstChild(ASTElExpression.class);
ASTIdentifier id = el.descendants(ASTIdentifier.class).first();
assertEquals("elInScript", id.getImage(), "Correct EL content expected!");
}
@ -229,11 +229,11 @@ class VfDocStyleTest extends AbstractVfTest {
List<ASTHtmlScript> scripts = vf.getNodes(ASTHtmlScript.class, TEST_IMPORT_JAVASCRIPT);
assertEquals(1, scripts.size(), "One script expected!");
ASTHtmlScript script = scripts.iterator().next();
List<ASTAttribute> attr = script.findDescendantsOfType(ASTAttribute.class);
List<ASTAttribute> attr = script.descendants(ASTAttribute.class).toList();
assertEquals(1, attr.size(), "One script expected!");
ASTAttribute att = attr.iterator().next();
ASTAttributeValue val = att.getFirstChildOfType(ASTAttributeValue.class);
ASTText text = val.getFirstChildOfType(ASTText.class);
ASTAttributeValue val = att.firstChild(ASTAttributeValue.class);
ASTText text = val.firstChild(ASTText.class);
assertEquals("filename.js", text.getImage());
}
@ -245,9 +245,9 @@ class VfDocStyleTest extends AbstractVfTest {
List<ASTHtmlScript> scripts = vf.getNodes(ASTHtmlScript.class, TEST_HTML_SCRIPT_WITH_ATTRIBUTE);
assertEquals(1, scripts.size(), "One script expected!");
ASTHtmlScript script = scripts.iterator().next();
ASTText text = script.getFirstChildOfType(ASTText.class);
ASTText text = script.firstChild(ASTText.class);
assertEquals("Script!", text.getImage(), "Correct script content expected!");
List<ASTText> attrs = script.findDescendantsOfType(ASTText.class);
List<ASTText> attrs = script.descendants(ASTText.class).toList();
assertEquals("text/javascript", attrs.get(0).getImage());
}
@ -259,7 +259,7 @@ class VfDocStyleTest extends AbstractVfTest {
List<ASTHtmlScript> script = vf.getNodes(ASTHtmlScript.class, TEST_COMPLEX_SCRIPT);
assertEquals(1, script.size(), "One script expected!");
ASTHtmlScript next = script.iterator().next();
ASTText text = next.getFirstChildOfType(ASTText.class);
ASTText text = next.firstChild(ASTText.class);
assertTrue(text.getImage().contains("<!--"));
}
@ -321,15 +321,15 @@ class VfDocStyleTest extends AbstractVfTest {
assertEquals(1, element.size(), "One element expected!");
for (ASTElement elem : element) {
ASTContent content = elem.getFirstChildOfType(ASTContent.class);
List<ASTElExpression> els = content.findChildrenOfType(ASTElExpression.class);
ASTContent content = elem.firstChild(ASTContent.class);
List<ASTElExpression> els = content.children(ASTElExpression.class).toList();
assertEquals(2, els.size(), "Two EL expressions expected!");
ASTElExpression node = (ASTElExpression) content.getChild(0);
ASTIdentifier id = node.getFirstDescendantOfType(ASTIdentifier.class);
ASTIdentifier id = node.descendants(ASTIdentifier.class).first();
assertEquals("expr1", id.getImage(), "Correct content expected!");
node = (ASTElExpression) content.getChild(1);
id = node.getFirstDescendantOfType(ASTIdentifier.class);
id = node.descendants(ASTIdentifier.class).first();
assertEquals("expr2", id.getImage(), "Correct content expected!");
}
@ -356,10 +356,10 @@ class VfDocStyleTest extends AbstractVfTest {
List<ASTAttributeValue> attributes = vf.getNodes(ASTAttributeValue.class, TEST_QUOTE_EL);
assertEquals(1, attributes.size(), "One attribute expected!");
ASTAttributeValue attr = attributes.iterator().next();
List<ASTElExpression> els = attr.findChildrenOfType(ASTElExpression.class);
List<ASTElExpression> els = attr.children(ASTElExpression.class).toList();
assertEquals(1, els.size(), "Must be 1!");
ASTExpression expr = els.get(0).getFirstChildOfType(ASTExpression.class);
ASTIdentifier id = expr.getFirstChildOfType(ASTIdentifier.class);
ASTExpression expr = els.get(0).firstChild(ASTExpression.class);
ASTIdentifier id = expr.firstChild(ASTIdentifier.class);
assertEquals("something", id.getImage(), "Expected to detect proper value for attribute!");
}
@ -371,7 +371,7 @@ class VfDocStyleTest extends AbstractVfTest {
List<ASTAttributeValue> attributes = vf.getNodes(ASTAttributeValue.class, TEST_ATTR);
assertEquals(1, attributes.size(), "One attribute expected!");
ASTAttributeValue attr = attributes.iterator().next();
ASTText text = attr.getFirstChildOfType(ASTText.class);
ASTText text = attr.firstChild(ASTText.class);
assertEquals("yes|", text.getImage(), "Expected to detect proper value for attribute!");
}
@ -401,7 +401,7 @@ class VfDocStyleTest extends AbstractVfTest {
assertEquals(1, attributes.size(), "One attribute expected!");
Iterator<ASTAttributeValue> iterator = attributes.iterator();
ASTAttributeValue attr = iterator.next();
ASTText text = attr.getFirstChildOfType(ASTText.class);
ASTText text = attr.firstChild(ASTText.class);
assertEquals("\t", text.getImage(), "Expected to detect proper value for attribute!");
}
@ -665,7 +665,7 @@ class VfDocStyleTest extends AbstractVfTest {
assertEquals(1, attributes.size(), "One attribute expected!");
Iterator<ASTAttributeValue> iterator = attributes.iterator();
ASTAttributeValue attr = iterator.next();
ASTIdentifier id = attr.getFirstDescendantOfType(ASTIdentifier.class);
ASTIdentifier id = attr.descendants(ASTIdentifier.class).first();
assertEquals("something", id.getImage(), "Expected to detect proper value for EL in attribute!");
}

View File

@ -20,15 +20,15 @@ class VfPageStyleTest extends AbstractVfTest {
List<ASTElExpression> expressions = vf.getNodes(ASTElExpression.class, VF_EL_EXPRESSION);
assertEquals(1, expressions.size(), "One expression expected!");
ASTElExpression expression = expressions.iterator().next();
ASTExpression exp = expression.getFirstChildOfType(ASTExpression.class);
ASTIdentifier id = exp.getFirstChildOfType(ASTIdentifier.class);
ASTExpression exp = expression.firstChild(ASTExpression.class);
ASTIdentifier id = exp.firstChild(ASTIdentifier.class);
assertEquals("myBean", id.getImage(), "Correct expression content expected!");
ASTDotExpression dot = exp.getFirstChildOfType(ASTDotExpression.class);
ASTIdentifier dotid = dot.getFirstChildOfType(ASTIdentifier.class);
ASTDotExpression dot = exp.firstChild(ASTDotExpression.class);
ASTIdentifier dotid = dot.firstChild(ASTIdentifier.class);
assertEquals("get", dotid.getImage(), "Correct expression content expected!");
ASTArguments arguments = exp.getFirstChildOfType(ASTArguments.class);
ASTExpression innerExpression = arguments.getFirstChildOfType(ASTExpression.class);
ASTLiteral literal = innerExpression.getFirstChildOfType(ASTLiteral.class);
ASTArguments arguments = exp.firstChild(ASTArguments.class);
ASTExpression innerExpression = arguments.firstChild(ASTExpression.class);
ASTLiteral literal = innerExpression.firstChild(ASTLiteral.class);
assertEquals("\"{! World }\"", literal.getImage(), "Correct expression content expected!");
}
@ -40,15 +40,15 @@ class VfPageStyleTest extends AbstractVfTest {
List<ASTElExpression> expressions = vf.getNodes(ASTElExpression.class, VF_EL_EXPRESSION_IN_ATTRIBUTE);
assertEquals(1, expressions.size(), "One expression expected!");
ASTElExpression expression = expressions.iterator().next();
ASTExpression exp = expression.getFirstChildOfType(ASTExpression.class);
ASTIdentifier id = exp.getFirstChildOfType(ASTIdentifier.class);
ASTExpression exp = expression.firstChild(ASTExpression.class);
ASTIdentifier id = exp.firstChild(ASTIdentifier.class);
assertEquals("myValidator", id.getImage(), "Correct expression content expected!");
ASTDotExpression dot = exp.getFirstChildOfType(ASTDotExpression.class);
ASTIdentifier dotid = dot.getFirstChildOfType(ASTIdentifier.class);
ASTDotExpression dot = exp.firstChild(ASTDotExpression.class);
ASTIdentifier dotid = dot.firstChild(ASTIdentifier.class);
assertEquals("find", dotid.getImage(), "Correct expression content expected!");
ASTArguments arguments = exp.getFirstChildOfType(ASTArguments.class);
ASTExpression innerExpression = arguments.getFirstChildOfType(ASTExpression.class);
ASTLiteral literal = innerExpression.getFirstChildOfType(ASTLiteral.class);
ASTArguments arguments = exp.firstChild(ASTArguments.class);
ASTExpression innerExpression = arguments.firstChild(ASTExpression.class);
ASTLiteral literal = innerExpression.firstChild(ASTLiteral.class);
assertEquals("\"'vf'\"", literal.getImage(), "Correct expression content expected!");
}