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