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 
     22 package com.github.javaparser.ast.expr;
     23 
     24 import com.github.javaparser.Range;
     25 import com.github.javaparser.ast.nodeTypes.NodeWithType;
     26 import com.github.javaparser.ast.ArrayCreationLevel;
     27 import com.github.javaparser.ast.type.Type;
     28 import com.github.javaparser.ast.visitor.GenericVisitor;
     29 import com.github.javaparser.ast.visitor.VoidVisitor;
     30 
     31 import java.util.List;
     32 
     33 import static com.github.javaparser.utils.Utils.ensureNotNull;
     34 
     35 /**
     36  * @author Julio Vilmar Gesser
     37  */
     38 public final class ArrayCreationExpr extends Expression implements NodeWithType<ArrayCreationExpr> {
     39 
     40     private List<ArrayCreationLevel> levels;
     41 
     42     private Type type;
     43 
     44     private ArrayInitializerExpr initializer;
     45 
     46     public ArrayCreationExpr() {
     47     }
     48 
     49     public ArrayCreationExpr(Type type, List<ArrayCreationLevel> levels, ArrayInitializerExpr initializer) {
     50         setLevels(levels);
     51         setType(type);
     52         setInitializer(initializer);
     53     }
     54 
     55     public ArrayCreationExpr(Range range, Type type, List<ArrayCreationLevel> levels, ArrayInitializerExpr initializer) {
     56         super(range);
     57         setLevels(levels);
     58         setType(type);
     59         setInitializer(initializer);
     60     }
     61 
     62     public ArrayCreationExpr(Type type) {
     63         setType(type);
     64         setInitializer(null);
     65     }
     66 
     67     public ArrayCreationExpr(Range range, Type type) {
     68         super(range);
     69         setType(type);
     70         setInitializer(null);
     71     }
     72 
     73     @Override
     74     public <R, A> R accept(GenericVisitor<R, A> v, A arg) {
     75         return v.visit(this, arg);
     76     }
     77 
     78     @Override
     79     public <A> void accept(VoidVisitor<A> v, A arg) {
     80         v.visit(this, arg);
     81     }
     82 
     83     public ArrayInitializerExpr getInitializer() {
     84         return initializer;
     85     }
     86 
     87     @Override
     88     public Type getType() {
     89         return type;
     90     }
     91 
     92     public ArrayCreationExpr setInitializer(ArrayInitializerExpr initializer) {
     93         this.initializer = initializer;
     94 		setAsParentNodeOf(this.initializer);
     95         return this;
     96     }
     97 
     98     @Override
     99     public ArrayCreationExpr setType(Type type) {
    100         this.type = type;
    101 		setAsParentNodeOf(this.type);
    102         return this;
    103     }
    104 
    105     public List<ArrayCreationLevel> getLevels() {
    106         levels = ensureNotNull(levels);
    107         return levels;
    108     }
    109 
    110     public ArrayCreationExpr setLevels(List<ArrayCreationLevel> levels) {
    111         this.levels = levels;
    112         setAsParentNodeOf(levels);
    113         return this;
    114     }
    115 }
    116