Search in sources :

Example 1 with NoDataException

use of com.intellij.debugger.NoDataException 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");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PositionManagerImpl(com.intellij.debugger.engine.PositionManagerImpl) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) SourcePosition(com.intellij.debugger.SourcePosition) NoDataException(com.intellij.debugger.NoDataException) TestOnly(org.jetbrains.annotations.TestOnly)

Example 2 with NoDataException

use of com.intellij.debugger.NoDataException in project kotlin by JetBrains.

the class AbstractPositionManagerTest method performTest.

private void performTest() {
    Project project = getProject();
    List<KtFile> files = new ArrayList<KtFile>(PluginJetFilesProvider.allFilesInProject(project));
    if (files.isEmpty())
        return;
    final List<Breakpoint> breakpoints = Lists.newArrayList();
    for (KtFile file : files) {
        breakpoints.addAll(extractBreakpointsInfo(file, file.getText()));
    }
    CompilerConfiguration configuration = KotlinTestUtils.newConfiguration(ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK);
    // TODO: delete this once IDEVirtualFileFinder supports loading .kotlin_builtins files
    configuration.put(JVMConfigurationKeys.ADD_BUILT_INS_FROM_COMPILER_TO_DEPENDENCIES, true);
    GenerationState state = GenerationUtils.compileFiles(files, configuration, new Function1<GlobalSearchScope, PackagePartProvider>() {

        @Override
        public PackagePartProvider invoke(GlobalSearchScope scope) {
            return PackagePartProvider.Empty.INSTANCE;
        }
    });
    Map<String, ReferenceType> referencesByName = getReferenceMap(state.getFactory());
    debugProcess = createDebugProcess(referencesByName);
    final PositionManager positionManager = createPositionManager(debugProcess, files, state);
    ApplicationManager.getApplication().runReadAction(new Runnable() {

        @Override
        public void run() {
            try {
                for (Breakpoint breakpoint : breakpoints) {
                    assertBreakpointIsHandledCorrectly(breakpoint, positionManager);
                }
            } catch (NoDataException e) {
                throw ExceptionUtilsKt.rethrow(e);
            }
        }
    });
}
Also used : PositionManager(com.intellij.debugger.PositionManager) ArrayList(java.util.ArrayList) GenerationState(org.jetbrains.kotlin.codegen.state.GenerationState) ReferenceType(com.sun.jdi.ReferenceType) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PackagePartProvider(org.jetbrains.kotlin.descriptors.PackagePartProvider) CompilerConfiguration(org.jetbrains.kotlin.config.CompilerConfiguration) KtFile(org.jetbrains.kotlin.psi.KtFile) NoDataException(com.intellij.debugger.NoDataException)

Aggregations

NoDataException (com.intellij.debugger.NoDataException)2 PositionManager (com.intellij.debugger.PositionManager)1 SourcePosition (com.intellij.debugger.SourcePosition)1 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)1 PositionManagerImpl (com.intellij.debugger.engine.PositionManagerImpl)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 ReferenceType (com.sun.jdi.ReferenceType)1 ArrayList (java.util.ArrayList)1 TestOnly (org.jetbrains.annotations.TestOnly)1 GenerationState (org.jetbrains.kotlin.codegen.state.GenerationState)1 CompilerConfiguration (org.jetbrains.kotlin.config.CompilerConfiguration)1 PackagePartProvider (org.jetbrains.kotlin.descriptors.PackagePartProvider)1 KtFile (org.jetbrains.kotlin.psi.KtFile)1