update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / codeInspection / dataFlow / instructions / MethodCallInstruction.java
blob3fe63d1b1fcd480ee628d94db35f21651a3b74c8
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: Jan 26, 2002
21 * Time: 10:48:52 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.codeInspection.dataFlow.DataFlowRunner;
28 import com.intellij.codeInspection.dataFlow.DfaInstructionState;
29 import com.intellij.codeInspection.dataFlow.DfaMemoryState;
30 import com.intellij.codeInspection.dataFlow.InstructionVisitor;
31 import com.intellij.psi.*;
32 import org.jetbrains.annotations.NotNull;
33 import org.jetbrains.annotations.Nullable;
36 public class MethodCallInstruction extends Instruction {
37 @Nullable private final PsiCallExpression myCall;
38 @Nullable private PsiType myType;
39 @NotNull private final PsiExpression[] myArgs;
40 private boolean myShouldFlushFields;
41 @NotNull private final PsiExpression myContext;
42 private final MethodType myMethodType;
43 public static enum MethodType {
44 BOXING, UNBOXING, REGULAR_METHOD_CALL, CAST
47 public MethodCallInstruction(@NotNull PsiCallExpression callExpression) {
48 this(callExpression, MethodType.REGULAR_METHOD_CALL);
51 public MethodCallInstruction(@NotNull PsiExpression context, MethodType methodType, PsiType resultType) {
52 this(context, methodType);
53 myType = resultType;
54 myShouldFlushFields = false;
57 public MethodCallInstruction(@NotNull PsiExpression context, MethodType methodType) {
58 myContext = context;
59 myMethodType = methodType;
60 myCall = context instanceof PsiCallExpression ? (PsiCallExpression)context : null;
61 final PsiExpressionList argList = myCall == null ? null : myCall.getArgumentList();
62 myArgs = argList != null ? argList.getExpressions() : PsiExpression.EMPTY_ARRAY;
64 myType = myCall == null ? null : myCall.getType();
66 myShouldFlushFields = true;
67 if (myCall instanceof PsiNewExpression && myType != null && myType.getArrayDimensions() > 0) {
68 myShouldFlushFields = false;
72 @Nullable
73 public PsiType getResultType() {
74 return myType;
77 @NotNull
78 public PsiExpression[] getArgs() {
79 return myArgs;
82 public MethodType getMethodType() {
83 return myMethodType;
86 public boolean shouldFlushFields() {
87 return myShouldFlushFields;
90 @Override
91 public DfaInstructionState[] accept(DataFlowRunner runner, DfaMemoryState stateBefore, InstructionVisitor visitor) {
92 return visitor.visitMethodCall(this, runner, stateBefore);
95 @Nullable
96 public PsiCallExpression getCallExpression() {
97 return myCall;
100 @NotNull
101 public PsiExpression getContext() {
102 return myContext;
105 public String toString() {
106 return myMethodType == MethodType.UNBOXING ? "UNBOX" : myMethodType == MethodType.BOXING ? "BOX" : "CALL_METHOD: " + myCall.getText();