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

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

The 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;

import net.sourceforge.pmd.lang.document.Chars;


/**
 * Represents a character literal. {@link #getConstValue()} allows to
 * retrieve the actual runtime value. Use {@link #getLiteralText()} to
 * retrieve the text.
 */
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() {
        Chars image = getLiteralText();
        Chars woDelims = image.subSequence(1, image.length() - 1);
        return StringEscapeUtils.UNESCAPE_JAVA.translate(woDelims).charAt(0);
    }

    @Override
    public Chars getLiteralText() {
        return super.getLiteralText();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy