use of com.intellij.debugger.SourcePosition in project intellij-community by JetBrains.
the class JSR45PositionManager method getSourcePosition.
@Override
public SourcePosition getSourcePosition(final Location location) throws NoDataException {
SourcePosition sourcePosition = null;
try {
String sourcePath = getRelativeSourcePathByLocation(location);
PsiFile file = mySourcesFinder.findSourceFile(sourcePath, myDebugProcess.getProject(), myScope);
if (file != null) {
int lineNumber = getLineNumber(location);
sourcePosition = SourcePosition.createFromLine(file, lineNumber - 1);
}
} catch (AbsentInformationException ignored) {
// ignored
} catch (Throwable e) {
LOG.info(e);
}
if (sourcePosition == null) {
throw NoDataException.INSTANCE;
}
return sourcePosition;
}
use of com.intellij.debugger.SourcePosition in project intellij-community by JetBrains.
the class ExceptionBreakpoint method createRequest.
public void createRequest(final DebugProcessImpl debugProcess) {
DebuggerManagerThreadImpl.assertIsManagerThread();
if (!shouldCreateRequest(debugProcess)) {
return;
}
SourcePosition classPosition = ApplicationManager.getApplication().runReadAction(new Computable<SourcePosition>() {
public SourcePosition compute() {
PsiClass psiClass = DebuggerUtils.findClass(getQualifiedName(), myProject, debugProcess.getSearchScope());
return psiClass != null ? SourcePosition.createFromElement(psiClass) : null;
}
});
if (classPosition == null) {
createOrWaitPrepare(debugProcess, getQualifiedName());
} else {
createOrWaitPrepare(debugProcess, classPosition);
}
}
use of com.intellij.debugger.SourcePosition in project intellij-community by JetBrains.
the class LineBreakpoint method isInScopeOf.
private boolean isInScopeOf(DebugProcessImpl debugProcess, String className) {
final SourcePosition position = getSourcePosition();
if (position != null) {
final VirtualFile breakpointFile = position.getFile().getVirtualFile();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
if (breakpointFile != null && fileIndex.isUnderSourceRootOfType(breakpointFile, JavaModuleSourceRootTypes.SOURCES)) {
if (debugProcess.getSearchScope().contains(breakpointFile)) {
return true;
}
// apply filtering to breakpoints from content sources only, not for sources attached to libraries
final Collection<VirtualFile> candidates = findClassCandidatesInSourceContent(className, debugProcess.getSearchScope(), fileIndex);
if (LOG.isDebugEnabled()) {
LOG.debug("Found " + (candidates == null ? "null" : candidates.size()) + " candidate containing files for class " + className);
}
if (candidates == null) {
// If no candidates are found in scope then assume that class is loaded dynamically and allow breakpoint
return true;
}
//}
if (LOG.isDebugEnabled()) {
final GlobalSearchScope scope = debugProcess.getSearchScope();
final boolean contains = scope.contains(breakpointFile);
List<VirtualFile> files = ContainerUtil.map(JavaFullClassNameIndex.getInstance().get(className.hashCode(), myProject, scope), aClass -> aClass.getContainingFile().getVirtualFile());
List<VirtualFile> allFiles = ContainerUtil.map(JavaFullClassNameIndex.getInstance().get(className.hashCode(), myProject, new EverythingGlobalScope(myProject)), aClass -> aClass.getContainingFile().getVirtualFile());
final VirtualFile contentRoot = fileIndex.getContentRootForFile(breakpointFile);
final Module module = fileIndex.getModuleForFile(breakpointFile);
LOG.debug("Did not find '" + className + "' in " + scope + "; contains=" + contains + "; contentRoot=" + contentRoot + "; module = " + module + "; all files in index are: " + files + "; all possible files are: " + allFiles);
}
return false;
}
}
return true;
}
use of com.intellij.debugger.SourcePosition in project intellij-community by JetBrains.
the class SourceCodeChecker method checkAllClasses.
@TestOnly
@SuppressWarnings("UseOfSystemOutOrSystemErr")
private static void checkAllClasses(DebuggerContextImpl debuggerContext) {
DebugProcessImpl process = debuggerContext.getDebugProcess();
@SuppressWarnings("ConstantConditions") VirtualMachine machine = process.getVirtualMachineProxy().getVirtualMachine();
// only default position manager for now
PositionManagerImpl positionManager = new PositionManagerImpl(process);
List<ReferenceType> types = machine.allClasses();
System.out.println("Checking " + types.size() + " classes");
int i = 0;
for (ReferenceType type : types) {
i++;
try {
for (Location loc : type.allLineLocations()) {
SourcePosition position = ReadAction.compute(() -> {
try {
return positionManager.getSourcePosition(loc);
} catch (NoDataException ignore) {
return null;
}
});
if (position == null) {
continue;
}
if (position.getFile() instanceof PsiCompiledFile) {
VirtualFile file = position.getFile().getVirtualFile();
if (file == null || file.getUserData(LineNumbersMapping.LINE_NUMBERS_MAPPING_KEY) == null) {
// no mapping - skip the whole file
break;
}
if (DebuggerUtilsEx.bytecodeToSourceLine(position.getFile(), loc.lineNumber()) == -1) {
continue;
}
}
if (check(loc, position, process.getProject()) == ThreeState.NO) {
System.out.println("failed " + type);
break;
}
}
} catch (AbsentInformationException ignored) {
}
}
System.out.println("Done checking");
}
use of com.intellij.debugger.SourcePosition in project intellij-community by JetBrains.
the class SourceCodeChecker method check.
private static ThreeState check(Location location, SourcePosition position, Project project) {
Method method = DebuggerUtilsEx.getMethod(location);
// for now skip constructors, bridges, lambdas etc.
if (method == null || method.isConstructor() || method.isSynthetic() || method.isBridge() || method.isStaticInitializer() || (method.declaringType() instanceof ClassType && ((ClassType) method.declaringType()).isEnum()) || DebuggerUtilsEx.isLambda(method)) {
return ThreeState.UNSURE;
}
List<Location> locations = DebuggerUtilsEx.allLineLocations(method);
if (ContainerUtil.isEmpty(locations)) {
return ThreeState.UNSURE;
}
if (position != null) {
return ReadAction.compute(() -> {
PsiFile psiFile = position.getFile();
if (!psiFile.getLanguage().isKindOf(JavaLanguage.INSTANCE)) {
// only for java for now
return ThreeState.UNSURE;
}
Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
if (document == null) {
return ThreeState.UNSURE;
}
boolean res = false;
PsiElement psiMethod = DebuggerUtilsEx.getContainingMethod(position);
if (psiMethod != null) {
TextRange range = psiMethod.getTextRange();
if (psiMethod instanceof PsiDocCommentOwner) {
PsiDocComment comment = ((PsiDocCommentOwner) psiMethod).getDocComment();
if (comment != null) {
range = new TextRange(comment.getTextRange().getEndOffset() + 1, range.getEndOffset());
}
}
int startLine = document.getLineNumber(range.getStartOffset()) + 1;
int endLine = document.getLineNumber(range.getEndOffset()) + 1;
res = getLinesStream(locations, psiFile).allMatch(line -> startLine <= line && line <= endLine);
if (!res) {
LOG.debug("Source check failed: Method " + method.name() + ", source: " + ((NavigationItem) psiMethod).getName() + "\nLines: " + getLinesStream(locations, psiFile).joining(", ") + "\nExpected range: " + startLine + "-" + endLine);
}
} else {
LOG.debug("Source check failed: method " + method.name() + " not found in sources");
}
if (!res) {
FileEditor editor = FileEditorManager.getInstance(project).getSelectedEditor(position.getFile().getVirtualFile());
if (editor instanceof TextEditor) {
AppUIUtil.invokeOnEdt(() -> HintManager.getInstance().showErrorHint(((TextEditor) editor).getEditor(), DebuggerBundle.message("warning.source.code.not.match")));
} else {
XDebugSessionImpl.NOTIFICATION_GROUP.createNotification(DebuggerBundle.message("warning.source.code.not.match"), NotificationType.WARNING).notify(project);
}
return ThreeState.NO;
}
return ThreeState.YES;
});
}
return ThreeState.YES;
}
Aggregations