2 * Copyright 2000-2015 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.
16 package com.intellij.debugger.ui.impl.watch;
18 import com.intellij.debugger.DebuggerBundle;
19 import com.intellij.debugger.DebuggerContext;
20 import com.intellij.debugger.engine.DebuggerUtils;
21 import com.intellij.debugger.engine.evaluation.EvaluateException;
22 import com.intellij.debugger.engine.evaluation.EvaluationContextImpl;
23 import com.intellij.debugger.impl.PositionUtil;
24 import com.intellij.debugger.jdi.LocalVariableProxyImpl;
25 import com.intellij.debugger.jdi.StackFrameProxyImpl;
26 import com.intellij.debugger.ui.tree.LocalVariableDescriptor;
27 import com.intellij.debugger.ui.tree.NodeDescriptor;
28 import com.intellij.debugger.ui.tree.NodeDescriptorNameAdjuster;
29 import com.intellij.openapi.project.Project;
30 import com.intellij.psi.JavaPsiFacade;
31 import com.intellij.psi.PsiElementFactory;
32 import com.intellij.psi.PsiExpression;
33 import com.intellij.util.IncorrectOperationException;
34 import com.sun.jdi.Value;
35 import org.jetbrains.annotations.NotNull;
36 import org.jetbrains.annotations.Nullable;
38 public class LocalVariableDescriptorImpl extends ValueDescriptorImpl implements LocalVariableDescriptor {
39 private final StackFrameProxyImpl myFrameProxy;
40 private final LocalVariableProxyImpl myLocalVariable;
42 private String myTypeName = DebuggerBundle.message("label.unknown.value");
43 private boolean myIsPrimitive;
45 private boolean myIsNewLocal = true;
47 public LocalVariableDescriptorImpl(Project project,
48 @NotNull LocalVariableProxyImpl local) {
51 myFrameProxy = local.getFrame();
52 myLocalVariable = local;
56 public LocalVariableProxyImpl getLocalVariable() {
57 return myLocalVariable;
60 public boolean isNewLocal() {
65 public boolean isPrimitive() {
70 public Value calcValue(EvaluationContextImpl evaluationContext) throws EvaluateException {
71 boolean isVisible = myFrameProxy.isLocalVariableVisible(getLocalVariable());
73 final String typeName = getLocalVariable().typeName();
74 myTypeName = typeName;
75 myIsPrimitive = DebuggerUtils.isPrimitiveType(typeName);
76 return myFrameProxy.getValue(getLocalVariable());
82 public void setNewLocal(boolean aNew) {
87 public void displayAs(NodeDescriptor descriptor) {
88 super.displayAs(descriptor);
89 if(descriptor instanceof LocalVariableDescriptorImpl) {
90 myIsNewLocal = ((LocalVariableDescriptorImpl)descriptor).myIsNewLocal;
95 public String getName() {
96 String varName = myLocalVariable.name();
97 NodeDescriptorNameAdjuster nameAdjuster = NodeDescriptorNameAdjuster.findFor(this);
98 if (nameAdjuster != null) {
99 return nameAdjuster.fixName(varName, this);
106 public String getDeclaredType() {
107 return myLocalVariable.typeName();
111 public PsiExpression getDescriptorEvaluation(DebuggerContext context) throws EvaluateException {
112 PsiElementFactory elementFactory = JavaPsiFacade.getInstance(context.getProject()).getElementFactory();
114 return elementFactory.createExpressionFromText(getName(), PositionUtil.getContextElement(context));
116 catch (IncorrectOperationException e) {
117 throw new EvaluateException(DebuggerBundle.message("error.invalid.local.variable.name", getName()), e);