IDEA-183340 'Jump to Source' on a field in 'Variables' window opens source code for class in project's JDK, not in JDK application is launched

This commit is contained in:
Egor Ushakov
2017-12-06 15:52:44 +03:00
parent b7f68ecec1
commit feee7d9867
@@ -1,17 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package com.intellij.debugger.engine;
@@ -32,6 +20,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.containers.ContainerUtil;
import com.sun.jdi.AbsentInformationException;
import com.sun.jdi.ClassNotPreparedException;
import com.sun.jdi.Location;
@@ -81,7 +70,6 @@ public class DefaultSourcePositionProvider extends SourcePositionProvider {
@NotNull DebuggerContextImpl context,
boolean nearest) {
final ReferenceType type = descriptor.getField().declaringType();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
final String fieldName = descriptor.getField().name();
if (fieldName.startsWith(FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) {
// this field actually mirrors a local variable in the outer class
@@ -99,7 +87,7 @@ public class DefaultSourcePositionProvider extends SourcePositionProvider {
return null;
}
aClass = (PsiClass)navigationElement;
PsiVariable psiVariable = facade.getResolveHelper().resolveReferencedVariable(varName, aClass);
PsiVariable psiVariable = JavaPsiFacade.getInstance(project).getResolveHelper().resolveReferencedVariable(varName, aClass);
if (psiVariable == null) {
return null;
}
@@ -109,25 +97,24 @@ public class DefaultSourcePositionProvider extends SourcePositionProvider {
return SourcePosition.createFromElement(psiVariable);
}
else {
final DebuggerSession session = context.getDebuggerSession();
final GlobalSearchScope scope = session != null? session.getSearchScope() : GlobalSearchScope.allScope(project);
PsiClass aClass = facade.findClass(type.name().replace('$', '.'), scope);
if (aClass == null) {
// trying to search, assuming declaring class is an anonymous class
final DebugProcessImpl debugProcess = context.getDebugProcess();
if (debugProcess != null) {
try {
final List<Location> locations = type.allLineLocations();
if (!locations.isEmpty()) {
// important: use the last location to be sure the position will be within the anonymous class
final Location lastLocation = locations.get(locations.size() - 1);
final SourcePosition position = debugProcess.getPositionManager().getSourcePosition(lastLocation);
aClass = JVMNameUtil.getClassAt(position);
}
}
catch (AbsentInformationException | ClassNotPreparedException ignored) {
PsiClass aClass = null;
DebugProcessImpl debugProcess = context.getDebugProcess();
if (debugProcess != null) {
try {
List<Location> locations = type.allLineLocations();
if (!locations.isEmpty()) {
// important: use the last location to be sure the position will be within the anonymous class
aClass = JVMNameUtil.getClassAt(debugProcess.getPositionManager().getSourcePosition(ContainerUtil.getLastItem(locations)));
}
}
catch (AbsentInformationException | ClassNotPreparedException ignored) {
}
}
if (aClass == null) { // fallback
DebuggerSession session = context.getDebuggerSession();
GlobalSearchScope scope = session != null ? session.getSearchScope() : GlobalSearchScope.allScope(project);
aClass = DebuggerUtils.findClass(type.name(), project, scope);
}
if (aClass != null) {