net.sourceforge.pmd.lang.java.ast.ASTTemplateExpression Maven / Gradle / Ivy
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java.ast;
import net.sourceforge.pmd.annotation.Experimental;
import net.sourceforge.pmd.lang.java.ast.ASTAssignableExpr.ASTNamedReferenceExpr;
/**
* This is a Java 21 Preview feature.
*
*
*
* TemplateExpression ::= ({@link ASTVariableAccess VariableAccess} | {@link ASTFieldAccess FieldAccess})
* ({@link ASTTemplate Template} | {@link ASTStringLiteral StringLiteral})
*
*
*
* @see JEP 430: String Templates (Preview)
*/
@Experimental
public final class ASTTemplateExpression extends AbstractJavaExpr {
ASTTemplateExpression(int i) {
super(i);
}
@Override
protected R acceptVisitor(JavaVisitor super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public ASTExpression getTemplateProcessor() {
return (ASTExpression) getChild(0);
}
public JavaNode getTemplateArgument() {
return getChild(1);
}
public boolean isStringTemplate() {
String name;
if (getTemplateProcessor() instanceof ASTNamedReferenceExpr) {
name = ((ASTNamedReferenceExpr) getTemplateProcessor()).getName();
} else {
name = getTemplateProcessor().getFirstToken().getImage();
}
return "STR".equals(name);
}
}