update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / codeInspection / dataFlow / instructions / BranchingInstruction.java
blob2a036c3256d8f07534b7cb6d874ac6f5347c4c34
1 /*
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.
19 * User: max
20 * Date: Feb 8, 2002
21 * Time: 10:03:49 PM
22 * To change template for new class use
23 * Code Style | Class Templates options (Tools | IDE Options).
25 package com.intellij.codeInspection.dataFlow.instructions;
27 import com.intellij.psi.PsiElement;
28 import com.intellij.psi.PsiLiteralExpression;
29 import org.jetbrains.annotations.NonNls;
31 public abstract class BranchingInstruction extends Instruction {
32 private boolean myIsTrueReachable;
33 private boolean myIsFalseReachable;
34 private boolean isConstTrue;
35 private PsiElement myExpression;
37 protected BranchingInstruction() {
38 myIsTrueReachable = false;
39 myIsFalseReachable = false;
40 setPsiAnchor(null);
43 public boolean isTrueReachable() {
44 return myIsTrueReachable;
47 public boolean isFalseReachable() {
48 return myIsFalseReachable;
51 public PsiElement getPsiAnchor() {
52 return myExpression;
55 public void setTrueReachable() {
56 myIsTrueReachable = true;
59 public void setFalseReachable() {
60 myIsFalseReachable = true;
63 public boolean isConditionConst() {
64 return !isConstTrue && myIsTrueReachable != myIsFalseReachable;
67 private static boolean isBoolConst(PsiElement condition) {
68 if (!(condition instanceof PsiLiteralExpression)) return false;
69 @NonNls String text = condition.getText();
70 return "true".equals(text) || "false".equals(text);
73 protected void setPsiAnchor(PsiElement psiAcnchor) {
74 myExpression = psiAcnchor;
75 isConstTrue = psiAcnchor != null && isBoolConst(psiAcnchor);