use of com.sun.jdi.ReferenceType in project intellij-community by JetBrains.
the class TrackInstancesToggleAction method isSelected.
@Override
public boolean isSelected(AnActionEvent e) {
ReferenceType selectedClass = getSelectedClass(e);
final Project project = e.getProject();
if (project != null && selectedClass != null && !project.isDisposed()) {
InstancesTracker tracker = InstancesTracker.getInstance(project);
return tracker.isTracked(selectedClass.name());
}
return false;
}
use of com.sun.jdi.ReferenceType in project intellij-community by JetBrains.
the class DefaultSourcePositionProvider method getSourcePositionForField.
@Nullable
private static SourcePosition getSourcePositionForField(@NotNull FieldDescriptor descriptor, @NotNull Project project, @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
String varName = fieldName.substring(fieldName.lastIndexOf('$') + 1);
PsiElement element = PositionUtil.getContextElement(context);
if (element == null) {
return null;
}
PsiClass aClass = PsiTreeUtil.getParentOfType(element, PsiClass.class, false);
if (aClass == null) {
return null;
}
PsiElement navigationElement = aClass.getNavigationElement();
if (!(navigationElement instanceof PsiClass)) {
return null;
}
aClass = (PsiClass) navigationElement;
PsiVariable psiVariable = facade.getResolveHelper().resolveReferencedVariable(varName, aClass);
if (psiVariable == null) {
return null;
}
if (nearest) {
return DebuggerContextUtil.findNearest(context, psiVariable, aClass.getContainingFile());
}
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) {
}
}
}
if (aClass != null) {
PsiField field = aClass.findFieldByName(fieldName, false);
if (field == null)
return null;
if (nearest) {
return DebuggerContextUtil.findNearest(context, field.getNavigationElement(), aClass.getContainingFile());
}
return SourcePosition.createFromElement(field);
}
return null;
}
}
use of com.sun.jdi.ReferenceType in project intellij-community by JetBrains.
the class PositionManagerImpl method findNested.
@Nullable
private ReferenceType findNested(final ReferenceType fromClass, final int currentDepth, final PsiClass classToFind, final int requiredDepth, final SourcePosition position) {
ApplicationManager.getApplication().assertReadAccessAllowed();
final VirtualMachineProxyImpl vmProxy = myDebugProcess.getVirtualMachineProxy();
if (fromClass.isPrepared()) {
if (currentDepth < requiredDepth) {
final List<ReferenceType> nestedTypes = vmProxy.nestedTypes(fromClass);
for (ReferenceType nested : nestedTypes) {
final ReferenceType found = findNested(nested, currentDepth + 1, classToFind, requiredDepth, position);
if (found != null) {
return found;
}
}
return null;
}
int rangeBegin = Integer.MAX_VALUE;
int rangeEnd = Integer.MIN_VALUE;
for (Location location : DebuggerUtilsEx.allLineLocations(fromClass)) {
final int lnumber = DebuggerUtilsEx.getLineNumber(location, false);
if (lnumber <= 1) {
// such locations are hardly correspond to real lines in code, so skipping them too
continue;
}
final Method method = DebuggerUtilsEx.getMethod(location);
if (method == null || DebuggerUtils.isSynthetic(method) || method.isBridge()) {
// do not take into account synthetic stuff
continue;
}
int locationLine = lnumber - 1;
PsiFile psiFile = position.getFile().getOriginalFile();
if (psiFile instanceof PsiCompiledFile) {
locationLine = DebuggerUtilsEx.bytecodeToSourceLine(psiFile, locationLine);
if (locationLine < 0)
continue;
}
rangeBegin = Math.min(rangeBegin, locationLine);
rangeEnd = Math.max(rangeEnd, locationLine);
}
final int positionLine = position.getLine();
if (positionLine >= rangeBegin && positionLine <= rangeEnd) {
// First offsets belong to parent class, and offsets inside te substring "new Runnable(){" belong to anonymous runnable.
if (!classToFind.isValid()) {
return null;
}
Set<PsiClass> lineClasses = getLineClasses(position.getFile(), rangeEnd);
if (lineClasses.size() > 1) {
// if there's more than one class on the line - try to match by name
for (PsiClass aClass : lineClasses) {
if (classToFind.equals(aClass)) {
return fromClass;
}
}
} else if (!lineClasses.isEmpty()) {
return classToFind.equals(lineClasses.iterator().next()) ? fromClass : null;
}
return null;
}
}
return null;
}
use of com.sun.jdi.ReferenceType in project intellij-community by JetBrains.
the class JumpToTypeSourceAction method getPsiClass.
@Nullable
private PsiClass getPsiClass(AnActionEvent e) {
final ReferenceType selectedClass = getSelectedClass(e);
final Project project = e.getProject();
if (selectedClass == null || project == null) {
return null;
}
final ReferenceType targetClass = getObjectType(selectedClass);
if (targetClass != null) {
return DebuggerUtils.findClass(targetClass.name(), project, GlobalSearchScope.allScope(project));
}
return null;
}
use of com.sun.jdi.ReferenceType in project intellij-community by JetBrains.
the class TypeEvaluator method evaluate.
/**
* @return ReferenceType in the target VM, with the given fully qualified name
*/
public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
ClassLoaderReference classLoader = context.getClassLoader();
ReferenceType lastRes = SoftReference.dereference(myLastResult);
if (lastRes != null && classLoader == SoftReference.dereference(myLastClassLoader)) {
// if class loader is null, check that vms match
if (classLoader != null || lastRes.virtualMachine().equals(context.getDebugProcess().getVirtualMachineProxy().getVirtualMachine())) {
return lastRes;
}
}
DebugProcessImpl debugProcess = context.getDebugProcess();
String typeName = myTypeName.getName(debugProcess);
ReferenceType type = debugProcess.findClass(context, typeName, classLoader);
if (type == null) {
throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("error.class.not.loaded", typeName));
}
myLastClassLoader = new WeakReference<>(classLoader);
myLastResult = new WeakReference<>(type);
return type;
}
Aggregations