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 implements CompileTimeConstant<List<CompileTimeConstant<?>>> {
027
028 private final List<CompileTimeConstant<?>> value;
029 private final JetType type;
030
031 public ArrayValue(@NotNull List<CompileTimeConstant<?>> value, @NotNull JetType type) {
032 this.value = value;
033 this.type = type;
034 }
035
036 @Override
037 @NotNull
038 public List<CompileTimeConstant<?>> getValue() {
039 return value;
040 }
041
042 @NotNull
043 @Override
044 public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
045 return type;
046 }
047
048 @Override
049 public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
050 return visitor.visitArrayValue(this, data);
051 }
052
053 @Override
054 public String toString() {
055 return value.toString();
056 }
057
058 @Override
059 public boolean equals(Object o) {
060 if (this == o) return true;
061 if (o == null || getClass() != o.getClass()) return false;
062
063 ArrayValue that = (ArrayValue) o;
064
065 if (value == null) {
066 return that.value == null;
067 }
068
069 int i = 0;
070 for (Object thisObject : value) {
071 if (!thisObject.equals(that.value.get(i))) {
072 return false;
073 }
074 i++;
075 }
076
077 return true;
078 }
079
080 @Override
081 public int hashCode() {
082 int hashCode = 0;
083 if (value == null) return hashCode;
084 for (Object o : value) {
085 hashCode += o.hashCode();
086 }
087 return hashCode;
088 }
089 }
090