Home | History | Annotate | Download | only in expr
      1 /*
      2  * Copyright (C) 2007-2010 Jlio Vilmar Gesser.
      3  * Copyright (C) 2011, 2013-2016 The JavaParser Team.
      4  *
      5  * This file is part of JavaParser.
      6  *
      7  * JavaParser can be used either under the terms of
      8  * a) the GNU Lesser General Public License as published by
      9  *     the Free Software Foundation, either version 3 of the License, or
     10  *     (at your option) any later version.
     11  * b) the terms of the Apache License
     12  *
     13  * You should have received a copy of both licenses in LICENCE.LGPL and
     14  * LICENCE.APACHE. Please refer to those files for details.
     15  *
     16  * JavaParser is distributed in the hope that it will be useful,
     17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19  * GNU Lesser General Public License for more details.
     20  */
     21 package com.github.javaparser.ast.expr;
     22 
     23 import com.github.javaparser.ast.AllFieldsConstructor;
     24 import com.github.javaparser.ast.Node;
     25 import com.github.javaparser.ast.observer.ObservableProperty;
     26 import com.github.javaparser.ast.visitor.CloneVisitor;
     27 import com.github.javaparser.metamodel.JavaParserMetaModel;
     28 import com.github.javaparser.metamodel.LiteralStringValueExprMetaModel;
     29 import static com.github.javaparser.utils.Utils.assertNotNull;
     30 import javax.annotation.Generated;
     31 import com.github.javaparser.TokenRange;
     32 import java.util.function.Consumer;
     33 import java.util.Optional;
     34 
     35 /**
     36  * Any literal value that is stored internally as a String.
     37  */
     38 public abstract class LiteralStringValueExpr extends LiteralExpr {
     39 
     40     protected String value;
     41 
     42     @AllFieldsConstructor
     43     public LiteralStringValueExpr(final String value) {
     44         this(null, value);
     45     }
     46 
     47     /**
     48      * This constructor is used by the parser and is considered private.
     49      */
     50     @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
     51     public LiteralStringValueExpr(TokenRange tokenRange, String value) {
     52         super(tokenRange);
     53         setValue(value);
     54         customInitialization();
     55     }
     56 
     57     @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
     58     public String getValue() {
     59         return value;
     60     }
     61 
     62     @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
     63     public LiteralStringValueExpr setValue(final String value) {
     64         assertNotNull(value);
     65         if (value == this.value) {
     66             return (LiteralStringValueExpr) this;
     67         }
     68         notifyPropertyChange(ObservableProperty.VALUE, this.value, value);
     69         this.value = value;
     70         return this;
     71     }
     72 
     73     @Override
     74     @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
     75     public boolean remove(Node node) {
     76         if (node == null)
     77             return false;
     78         return super.remove(node);
     79     }
     80 
     81     @Override
     82     @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
     83     public LiteralStringValueExpr clone() {
     84         return (LiteralStringValueExpr) accept(new CloneVisitor(), null);
     85     }
     86 
     87     @Override
     88     @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
     89     public LiteralStringValueExprMetaModel getMetaModel() {
     90         return JavaParserMetaModel.literalStringValueExprMetaModel;
     91     }
     92 
     93     @Override
     94     @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
     95     public boolean replace(Node node, Node replacementNode) {
     96         if (node == null)
     97             return false;
     98         return super.replace(node, replacementNode);
     99     }
    100 
    101     @Override
    102     @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
    103     public boolean isLiteralStringValueExpr() {
    104         return true;
    105     }
    106 
    107     @Override
    108     @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
    109     public LiteralStringValueExpr asLiteralStringValueExpr() {
    110         return this;
    111     }
    112 
    113     @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
    114     public void ifLiteralStringValueExpr(Consumer<LiteralStringValueExpr> action) {
    115         action.accept(this);
    116     }
    117 
    118     @Override
    119     @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
    120     public Optional<LiteralStringValueExpr> toLiteralStringValueExpr() {
    121         return Optional.of(this);
    122     }
    123 }
    124