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.calls.autocasts;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
021 import org.jetbrains.jet.lang.types.JetType;
022
023 public class DataFlowValue {
024
025 public static final DataFlowValue NULL = new DataFlowValue(new Object(), KotlinBuiltIns.getInstance().getNullableNothingType(), false, Nullability.NULL);
026 public static final DataFlowValue NULLABLE = new DataFlowValue(new Object(), KotlinBuiltIns.getInstance().getNullableAnyType(), false, Nullability.UNKNOWN);
027
028 private final boolean stableIdentifier;
029 private final JetType type;
030 private final Object id;
031 private final Nullability immanentNullability;
032
033 // Use DataFlowValueFactory
034 /*package*/ DataFlowValue(Object id, JetType type, boolean stableIdentifier, Nullability immanentNullability) {
035 this.stableIdentifier = stableIdentifier;
036 this.type = type;
037 this.id = id;
038 this.immanentNullability = immanentNullability;
039 }
040
041 @NotNull
042 public Nullability getImmanentNullability() {
043 return immanentNullability;
044 }
045
046 /**
047 * Stable identifier is a non-literal value that is statically known to be immutable
048 * @return
049 */
050 public boolean isStableIdentifier() {
051 return stableIdentifier;
052 }
053
054 @NotNull
055 public JetType getType() {
056 return type;
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 DataFlowValue that = (DataFlowValue) o;
065
066 if (stableIdentifier != that.stableIdentifier) return false;
067 if (id != null ? !id.equals(that.id) : that.id != null) return false;
068 if (type != null ? !type.equals(that.type) : that.type != null) return false;
069
070 return true;
071 }
072
073 @Override
074 public String toString() {
075 return (stableIdentifier ? "stable " : "unstable ") + (id == null ? null : id.toString()) + " " + immanentNullability;
076 }
077
078 @Override
079 public int hashCode() {
080 int result = (stableIdentifier ? 1 : 0);
081 result = 31 * result + (type != null ? type.hashCode() : 0);
082 result = 31 * result + (id != null ? id.hashCode() : 0);
083 return result;
084 }
085 }