All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sourceforge.pmd.lang.java.ast.ASTCharLiteral Maven / Gradle / Ivy

There is a newer version: 7.7.0
Show newest version
/**
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 */

package net.sourceforge.pmd.lang.java.ast;

import org.apache.commons.lang3.StringEscapeUtils;
import org.checkerframework.checker.nullness.qual.NonNull;


/**
 * Represents a character literal. The image of this node can be the literal as it appeared
 * in the source, but JavaCC performs its own unescaping and some escapes may be lost. At the
 * very least it has delimiters. {@link #getConstValue()} allows to recover the actual runtime value.
 */
public final class ASTCharLiteral extends AbstractLiteral implements ASTLiteral {


    ASTCharLiteral(int id) {
        super(id);
    }


    @Override
    protected  R acceptVisitor(JavaVisitor visitor, P data) {
        return visitor.visit(this, data);
    }


    /**
     * Gets the char value of this literal.
     */
    @Override
    public @NonNull Character getConstValue() {
        String image = getImage();
        String woDelims = image.substring(1, image.length() - 1);
        return StringEscapeUtils.unescapeJava(woDelims).charAt(0);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy