1 /* 2 * Copyright (C) 2007-2010 Jlio Vilmar Gesser. 3 * Copyright (C) 2011, 2013-2015 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.type; 23 24 import com.github.javaparser.ast.expr.AnnotationExpr; 25 import com.github.javaparser.ast.visitor.GenericVisitor; 26 import com.github.javaparser.ast.visitor.VoidVisitor; 27 28 import java.util.List; 29 30 /** 31 * @author Julio Vilmar Gesser 32 */ 33 public final class ReferenceType extends Type { 34 35 private Type type; 36 37 private int arrayCount; 38 39 private List<List<AnnotationExpr>> arraysAnnotations; 40 41 public ReferenceType() { 42 } 43 44 public ReferenceType(final Type type) { 45 setType(type); 46 } 47 48 public ReferenceType(final Type type, final int arrayCount) { 49 setType(type); 50 setArrayCount(arrayCount); 51 } 52 53 public ReferenceType(final int beginLine, final int beginColumn, final int endLine, final int endColumn, 54 final Type type, final int arrayCount) { 55 super(beginLine, beginColumn, endLine, endColumn); 56 setType(type); 57 setArrayCount(arrayCount); 58 } 59 60 public ReferenceType(int beginLine, int beginColumn, int endLine, 61 int endColumn, Type type, int arrayCount, 62 List<AnnotationExpr> annotations, 63 List<List<AnnotationExpr>> arraysAnnotations) { 64 super(beginLine, beginColumn, endLine, endColumn, annotations); 65 setType(type); 66 setArrayCount(arrayCount); 67 this.arraysAnnotations = arraysAnnotations; 68 } 69 70 @Override public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { 71 return v.visit(this, arg); 72 } 73 74 @Override public <A> void accept(final VoidVisitor<A> v, final A arg) { 75 v.visit(this, arg); 76 } 77 78 public int getArrayCount() { 79 return arrayCount; 80 } 81 82 public Type getType() { 83 return type; 84 } 85 86 public void setArrayCount(final int arrayCount) { 87 this.arrayCount = arrayCount; 88 } 89 90 public void setType(final Type type) { 91 this.type = type; 92 setAsParentNodeOf(this.type); 93 } 94 95 /** 96 * <p>Arrays annotations are annotations on the arrays modifiers of the type. 97 * Consider this example:</p> 98 * 99 * <p><pre> 100 * {@code 101 * int @Ann1 [] @Ann2 [] array; 102 * }</pre></p> 103 * 104 * <p>in this this method will return a list with the annotation expressions <pre>@Ann1</pre> 105 * and <pre>@Ann2</pre></p> 106 * 107 * <p>Note that the first list element of arraysAnnotations will refer to the first array modifier encountered. 108 * Considering the example the first element will be a list containing just @Ann1 while the second element will 109 * be a list containing just @Ann2. 110 * </p> 111 * 112 * <p>This property is guaranteed to hold: <pre>{@code getArraysAnnotations().size() == getArrayCount()}</pre> 113 * If a certain array modifier has no annotation the corresponding entry of arraysAnnotations will be null</p> 114 */ 115 public List<List<AnnotationExpr>> getArraysAnnotations() { 116 return arraysAnnotations; 117 } 118 119 /** 120 * For a description of the arrayAnnotations field refer to {@link #getArraysAnnotations()} 121 */ 122 public void setArraysAnnotations(List<List<AnnotationExpr>> arraysAnnotations) { 123 this.arraysAnnotations = arraysAnnotations; 124 } 125 } 126