@Override public void visitReferenceExpression(final PsiReferenceExpression reference) { if (myLineRange.intersects(reference.getTextRange())) { final PsiElement psiElement = reference.resolve(); if (psiElement instanceof PsiVariable) { final PsiVariable var = (PsiVariable) psiElement; if (var instanceof PsiField) { if (myCollectExpressions && !DebuggerUtils.hasSideEffectsOrReferencesMissingVars( reference, myVisibleLocals)) { /* if (var instanceof PsiEnumConstant && reference.getQualifier() == null) { final PsiClass enumClass = ((PsiEnumConstant)var).getContainingClass(); if (enumClass != null) { final PsiExpression expression = JavaPsiFacade.getInstance(var.getProject()).getParserFacade().createExpressionFromText(enumClass.getName() + "." + var.getName(), var); final PsiReference ref = expression.getReference(); if (ref != null) { ref.bindToElement(var); myExpressions.add(new TextWithImportsImpl(expression)); } } } else { myExpressions.add(new TextWithImportsImpl(reference)); } */ final PsiModifierList modifierList = var.getModifierList(); boolean isConstant = (var instanceof PsiEnumConstant) || (modifierList != null && modifierList.hasModifierProperty(PsiModifier.STATIC) && modifierList.hasModifierProperty(PsiModifier.FINAL)); if (!isConstant) { myExpressions.add(new TextWithImportsImpl(reference)); } } } else { if (myVisibleLocals.contains(var.getName())) { myVars.add(var.getName()); } else { // fix for variables used in inner classes if (!Comparing.equal( PsiTreeUtil.getParentOfType(reference, PsiClass.class), PsiTreeUtil.getParentOfType(var, PsiClass.class))) { myExpressions.add(new TextWithImportsImpl(reference)); } } } } } super.visitReferenceExpression(reference); }
@Override public void visitArrayAccessExpression(final PsiArrayAccessExpression expression) { if (myCollectExpressions && !DebuggerUtils.hasSideEffectsOrReferencesMissingVars(expression, myVisibleLocals)) { myExpressions.add(new TextWithImportsImpl(expression)); } super.visitArrayAccessExpression(expression); }
private static Set<TextWithImports> computeExtraVars( Pair<Set<String>, Set<TextWithImports>> usedVars, SourcePosition sourcePosition, EvaluationContextImpl evalContext) { Set<String> alreadyCollected = new HashSet<String>(usedVars.first); for (TextWithImports text : usedVars.second) { alreadyCollected.add(text.getText()); } Set<TextWithImports> extra = new HashSet<TextWithImports>(); for (FrameExtraVariablesProvider provider : FrameExtraVariablesProvider.EP_NAME.getExtensions()) { if (provider.isAvailable(sourcePosition, evalContext)) { extra.addAll(provider.collectVariables(sourcePosition, evalContext, alreadyCollected)); } } return extra; }
@Override public void visitMethodCallExpression(final PsiMethodCallExpression expression) { if (myCollectExpressions) { final PsiMethod psiMethod = expression.resolveMethod(); if (psiMethod != null && !DebuggerUtils.hasSideEffectsOrReferencesMissingVars(expression, myVisibleLocals)) { myExpressions.add(new TextWithImportsImpl(expression)); } } super.visitMethodCallExpression(expression); }
private void processVariable(final PsiVariable variable) { if (myLineRange.intersects(variable.getTextRange()) && myVisibleLocals.contains(variable.getName())) { myVars.add(variable.getName()); } }
// copied from FrameVariablesTree private void buildVariables( DebuggerContextImpl debuggerContext, final EvaluationContextImpl evaluationContext, @NotNull DebugProcessImpl debugProcess, XValueChildrenList children, ObjectReference thisObjectReference, Location location) throws EvaluateException { final Set<String> visibleLocals = new HashSet<String>(); if (NodeRendererSettings.getInstance().getClassRenderer().SHOW_VAL_FIELDS_AS_LOCAL_VARIABLES) { if (thisObjectReference != null && debugProcess.getVirtualMachineProxy().canGetSyntheticAttribute()) { final ReferenceType thisRefType = thisObjectReference.referenceType(); if (thisRefType instanceof ClassType && location != null && thisRefType.equals(location.declaringType()) && thisRefType.name().contains("$")) { // makes sense for nested classes only for (Field field : thisRefType.fields()) { if (DebuggerUtils.isSynthetic(field) && StringUtil.startsWith( field.name(), FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) { final FieldDescriptorImpl fieldDescriptor = myNodeManager.getFieldDescriptor(myDescriptor, thisObjectReference, field); children.add(JavaValue.create(fieldDescriptor, evaluationContext, myNodeManager)); visibleLocals.add(fieldDescriptor.calcValueName()); } } } } } boolean myAutoWatchMode = DebuggerSettings.getInstance().AUTO_VARIABLES_MODE; if (evaluationContext == null) { return; } final SourcePosition sourcePosition = debuggerContext.getSourcePosition(); if (sourcePosition == null) { return; } try { if (!XDebuggerSettingsManager.getInstance().getDataViewSettings().isAutoExpressions() && !myAutoWatchMode) { // optimization superBuildVariables(evaluationContext, children); } else { final Map<String, LocalVariableProxyImpl> visibleVariables = getVisibleVariables(getStackFrameProxy()); final Pair<Set<String>, Set<TextWithImports>> usedVars = ApplicationManager.getApplication() .runReadAction( new Computable<Pair<Set<String>, Set<TextWithImports>>>() { @Override public Pair<Set<String>, Set<TextWithImports>> compute() { return findReferencedVars( ContainerUtil.union(visibleVariables.keySet(), visibleLocals), sourcePosition); } }); // add locals if (myAutoWatchMode) { for (String var : usedVars.first) { LocalVariableProxyImpl local = visibleVariables.get(var); if (local != null) { children.add( JavaValue.create( myNodeManager.getLocalVariableDescriptor(null, local), evaluationContext, myNodeManager)); } } } else { superBuildVariables(evaluationContext, children); } final EvaluationContextImpl evalContextCopy = evaluationContext.createEvaluationContext(evaluationContext.getThisObject()); evalContextCopy.setAutoLoadClasses(false); final Set<TextWithImports> extraVars = computeExtraVars(usedVars, sourcePosition, evaluationContext); // add extra vars addToChildrenFrom(extraVars, children, evaluationContext); // add expressions addToChildrenFrom(usedVars.second, children, evalContextCopy); } } catch (EvaluateException e) { if (e.getCause() instanceof AbsentInformationException) { children.add( new DummyMessageValueNode( MessageDescriptor.LOCAL_VARIABLES_INFO_UNAVAILABLE.getLabel(), XDebuggerUIConstants.INFORMATION_MESSAGE_ICON)); // trying to collect values from variable slots try { for (Map.Entry<DecompiledLocalVariable, Value> entry : LocalVariablesUtil.fetchValues(getStackFrameProxy(), debugProcess).entrySet()) { children.add( JavaValue.create( myNodeManager.getArgumentValueDescriptor( null, entry.getKey(), entry.getValue()), evaluationContext, myNodeManager)); } } catch (Exception ex) { LOG.info(ex); } } else { throw e; } } }