001 /* 002 * Copyright 2010-2013 JetBrains s.r.o. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package org.jetbrains.jet.lang.resolve.constants; 018 019 import org.jetbrains.annotations.NotNull; 020 import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor; 021 import org.jetbrains.jet.lang.types.JetType; 022 import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; 023 024 import java.util.List; 025 026 public class ArrayValue extends CompileTimeConstant<List<CompileTimeConstant<?>>> { 027 028 private final JetType type; 029 030 public ArrayValue(@NotNull List<CompileTimeConstant<?>> value, @NotNull JetType type, boolean canBeUsedInAnnotations) { 031 super(value, canBeUsedInAnnotations); 032 this.type = type; 033 } 034 035 @NotNull 036 @Override 037 public List<CompileTimeConstant<?>> getValue() { 038 List<CompileTimeConstant<?>> value = super.getValue(); 039 assert value != null : "Guaranteed by constructor"; 040 return value; 041 } 042 043 @NotNull 044 @Override 045 public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) { 046 return type; 047 } 048 049 @Override 050 public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) { 051 return visitor.visitArrayValue(this, data); 052 } 053 054 @Override 055 public String toString() { 056 return value.toString(); 057 } 058 059 @Override 060 public boolean equals(Object o) { 061 if (this == o) return true; 062 if (o == null || getClass() != o.getClass()) return false; 063 064 ArrayValue that = (ArrayValue) o; 065 066 if (value == null) { 067 return that.value == null; 068 } 069 070 int i = 0; 071 for (Object thisObject : value) { 072 if (!thisObject.equals(that.value.get(i))) { 073 return false; 074 } 075 i++; 076 } 077 078 return true; 079 } 080 081 @Override 082 public int hashCode() { 083 int hashCode = 0; 084 if (value == null) return hashCode; 085 for (Object o : value) { 086 hashCode += o.hashCode(); 087 } 088 return hashCode; 089 } 090 } 091