Search in sources :

Example 1 with LineNumbersMapping

use of com.intellij.execution.filters.LineNumbersMapping in project intellij-community by JetBrains.

the class CompoundPositionManager method locationsOfLine.

@Override
@NotNull
public List<Location> locationsOfLine(@NotNull final ReferenceType type, @NotNull SourcePosition position) {
    VirtualFile file = position.getFile().getVirtualFile();
    if (file != null) {
        LineNumbersMapping mapping = file.getUserData(LineNumbersMapping.LINE_NUMBERS_MAPPING_KEY);
        if (mapping != null) {
            int line = mapping.sourceToBytecode(position.getLine() + 1);
            if (line > -1) {
                position = SourcePosition.createFromLine(position.getFile(), line - 1);
            }
        }
    }
    final SourcePosition finalPosition = position;
    return iterate(positionManager -> positionManager.locationsOfLine(type, finalPosition), Collections.emptyList(), position);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LineNumbersMapping(com.intellij.execution.filters.LineNumbersMapping) SourcePosition(com.intellij.debugger.SourcePosition) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with LineNumbersMapping

use of com.intellij.execution.filters.LineNumbersMapping in project intellij-community by JetBrains.

the class ByteCodeViewerComponent method setText.

public void setText(final String bytecode, PsiElement element) {
    int offset = 0;
    VirtualFile file = PsiUtilCore.getVirtualFile(element);
    if (file != null) {
        final Document document = FileDocumentManager.getInstance().getDocument(file);
        if (document != null) {
            int lineNumber = document.getLineNumber(element.getTextOffset());
            LineNumbersMapping mapping = file.getUserData(LineNumbersMapping.LINE_NUMBERS_MAPPING_KEY);
            if (mapping != null) {
                int mappedLine = mapping.sourceToBytecode(lineNumber);
                while (mappedLine == -1 && lineNumber < document.getLineCount()) {
                    mappedLine = mapping.sourceToBytecode(++lineNumber);
                }
                if (mappedLine > 0) {
                    lineNumber = mappedLine;
                }
            }
            offset = bytecode.indexOf("LINENUMBER " + lineNumber);
            while (offset == -1 && lineNumber < document.getLineCount()) {
                offset = bytecode.indexOf("LINENUMBER " + (lineNumber++));
            }
        }
    }
    setText(bytecode, Math.max(0, offset));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LineNumbersMapping(com.intellij.execution.filters.LineNumbersMapping)

Aggregations

LineNumbersMapping (com.intellij.execution.filters.LineNumbersMapping)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 SourcePosition (com.intellij.debugger.SourcePosition)1 NotNull (org.jetbrains.annotations.NotNull)1