2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * Created by IntelliJ IDEA.
22 * To change template for new class use
23 * Code Style | Class Templates options (Tools | IDE Options).
25 package com
.intellij
.codeInspection
.dataFlow
.value
;
27 import com
.intellij
.psi
.PsiType
;
28 import com
.intellij
.util
.containers
.HashMap
;
29 import org
.jetbrains
.annotations
.NotNull
;
31 import java
.util
.ArrayList
;
33 public class DfaNotNullValue
extends DfaValue
{
34 public static class Factory
{
35 private final DfaNotNullValue mySharedInstance
;
36 private final HashMap
<String
,ArrayList
<DfaNotNullValue
>> myStringToObject
;
37 private final DfaValueFactory myFactory
;
39 Factory(DfaValueFactory factory
) {
41 mySharedInstance
= new DfaNotNullValue(factory
);
42 myStringToObject
= new HashMap
<String
, ArrayList
<DfaNotNullValue
>>();
46 public DfaValue
create(PsiType type
) {
47 if (type
== null) return DfaUnknownValue
.getInstance();
48 mySharedInstance
.myType
= type
;
50 String id
= mySharedInstance
.toString();
51 ArrayList
<DfaNotNullValue
> conditions
= myStringToObject
.get(id
);
52 if (conditions
== null) {
53 conditions
= new ArrayList
<DfaNotNullValue
>();
54 myStringToObject
.put(id
, conditions
);
57 for (DfaNotNullValue value
: conditions
) {
58 if (value
.hardEquals(mySharedInstance
)) return value
;
62 DfaNotNullValue result
= new DfaNotNullValue(type
, myFactory
);
63 conditions
.add(result
);
68 private PsiType myType
;
70 private DfaNotNullValue(PsiType myType
, DfaValueFactory factory
) {
75 private DfaNotNullValue(DfaValueFactory factory
) {
79 @SuppressWarnings({"HardCodedStringLiteral"})
80 public String
toString() {
81 return "@notnull " + myType
.getCanonicalText();
84 public PsiType
getType() {
88 private boolean hardEquals(DfaNotNullValue aNotNull
) {
89 return aNotNull
.myType
== myType
;