Search in sources :

Example 1 with StreamEx

use of one.util.streamex.StreamEx in project intellij-community by JetBrains.

the class MethodBreakpoint method createRequestForPreparedClassEmulated.

static void createRequestForPreparedClassEmulated(@NotNull MethodBreakpointBase breakpoint, @NotNull DebugProcessImpl debugProcess, @NotNull ReferenceType classType, boolean base) {
    if (!base && !shouldCreateRequest(breakpoint, breakpoint.getXBreakpoint(), debugProcess, true)) {
        return;
    }
    try {
        Method lambdaMethod = MethodBytecodeUtil.getLambdaMethod(classType, debugProcess.getVirtualMachineProxy());
        StreamEx<Method> methods = lambdaMethod != null ? StreamEx.of(lambdaMethod) : breakpoint.matchingMethods(StreamEx.of(classType.methods()).filter(m -> base || !m.isAbstract()), debugProcess);
        boolean found = false;
        for (Method method : methods) {
            found = true;
            if (base && method.isNative()) {
                breakpoint.disableEmulation();
                return;
            }
            Method target = MethodBytecodeUtil.getBridgeTargetMethod(method, debugProcess.getVirtualMachineProxy());
            if (target != null && !DebuggerUtilsEx.allLineLocations(target).isEmpty()) {
                method = target;
            }
            List<Location> allLineLocations = DebuggerUtilsEx.allLineLocations(method);
            if (!allLineLocations.isEmpty()) {
                if (breakpoint.isWatchEntry()) {
                    createLocationBreakpointRequest(breakpoint, ContainerUtil.getFirstItem(allLineLocations), debugProcess);
                }
                if (breakpoint.isWatchExit()) {
                    MethodBytecodeUtil.visit(method, new MethodVisitor(Opcodes.API_VERSION) {

                        int myLastLine = 0;

                        @Override
                        public void visitLineNumber(int line, Label start) {
                            myLastLine = line;
                        }

                        @Override
                        public void visitInsn(int opcode) {
                            switch(opcode) {
                                case Opcodes.RETURN:
                                case Opcodes.IRETURN:
                                case Opcodes.FRETURN:
                                case Opcodes.ARETURN:
                                case Opcodes.LRETURN:
                                case Opcodes.DRETURN:
                                    //case Opcodes.ATHROW:
                                    allLineLocations.stream().filter(l -> l.lineNumber() == myLastLine).findFirst().ifPresent(location -> createLocationBreakpointRequest(breakpoint, location, debugProcess));
                            }
                        }
                    }, true);
                }
            }
        }
        if (base && found) {
            // desired class found - now also track all new classes
            createRequestForSubClasses(breakpoint, debugProcess, classType);
        }
    } catch (Exception e) {
        LOG.debug(e);
    }
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) MethodEntryEvent(com.sun.jdi.event.MethodEntryEvent) JVMNameUtil(com.intellij.debugger.engine.JVMNameUtil) AllIcons(com.intellij.icons.AllIcons) Document(com.intellij.openapi.editor.Document) Opcodes(org.jetbrains.org.objectweb.asm.Opcodes) DebuggerUtilsEx(com.intellij.debugger.impl.DebuggerUtilsEx) EventRequest(com.sun.jdi.request.EventRequest) EvaluationContextImpl(com.intellij.debugger.engine.evaluation.EvaluationContextImpl) StringBuilderSpinAllocator(com.intellij.util.StringBuilderSpinAllocator) ProgressWindowWithNotification(com.intellij.openapi.progress.util.ProgressWindowWithNotification) Logger(com.intellij.openapi.diagnostic.Logger) MultiMap(com.intellij.util.containers.MultiMap) MethodEntryRequest(com.sun.jdi.request.MethodEntryRequest) DebuggerManagerThreadImpl(com.intellij.debugger.engine.DebuggerManagerThreadImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) ProgressManager(com.intellij.openapi.progress.ProgressManager) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) MethodExitRequest(com.sun.jdi.request.MethodExitRequest) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) PositionUtil(com.intellij.debugger.impl.PositionUtil) MethodExitEvent(com.sun.jdi.event.MethodExitEvent) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) Stream(java.util.stream.Stream) StreamEx(one.util.streamex.StreamEx) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Requestor(com.intellij.debugger.requests.Requestor) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) SourcePosition(com.intellij.debugger.SourcePosition) LocatableEvent(com.sun.jdi.event.LocatableEvent) Label(org.jetbrains.org.objectweb.asm.Label) NonNls(org.jetbrains.annotations.NonNls) MethodBytecodeUtil(com.intellij.debugger.jdi.MethodBytecodeUtil) ContainerUtil(com.intellij.util.containers.ContainerUtil) AtomicReference(java.util.concurrent.atomic.AtomicReference) RequestManagerImpl(com.intellij.debugger.engine.requests.RequestManagerImpl) Project(com.intellij.openapi.project.Project) DebuggerBundle(com.intellij.debugger.DebuggerBundle) JavaMethodBreakpointProperties(org.jetbrains.java.debugger.breakpoints.properties.JavaMethodBreakpointProperties) MethodVisitor(org.jetbrains.org.objectweb.asm.MethodVisitor) JVMName(com.intellij.debugger.engine.JVMName) Consumer(java.util.function.Consumer) ClassPrepareRequest(com.sun.jdi.request.ClassPrepareRequest) DebuggerManagerEx(com.intellij.debugger.DebuggerManagerEx) com.sun.jdi(com.sun.jdi) Element(org.jdom.Element) javax.swing(javax.swing) Label(org.jetbrains.org.objectweb.asm.Label) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) MethodVisitor(org.jetbrains.org.objectweb.asm.MethodVisitor)

Example 2 with StreamEx

use of one.util.streamex.StreamEx in project intellij-community by JetBrains.

the class DescriptionCheckerUtil method allDescriptionDirs.

/**
   * Unlike getDescriptionsDirs this includes dirs in dependent modules and even project dirs ordered by
   * search scopes (first dirs in current module, then dirs in module dependencies, then dirs in
   * dependent modules, finally other project dirs).
   *
   * @param module module to search description directories for
   * @param descriptionType type of description directory to search
   * @return lazily populated stream of candidate directories
   */
public static StreamEx<PsiDirectory> allDescriptionDirs(Module module, DescriptionType descriptionType) {
    final JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(module.getProject());
    final PsiPackage psiPackage = javaPsiFacade.findPackage(descriptionType.getDescriptionFolder());
    if (psiPackage == null)
        return StreamEx.empty();
    return searchScopes(module).flatMap(scope -> StreamEx.of(psiPackage.getDirectories(scope))).distinct();
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) PsiPackage(com.intellij.psi.PsiPackage) Nullable(org.jetbrains.annotations.Nullable) PsiClass(com.intellij.psi.PsiClass) GlobalSearchScopesCore(com.intellij.psi.search.GlobalSearchScopesCore) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) StreamEx(one.util.streamex.StreamEx) JavaPsiFacade(com.intellij.psi.JavaPsiFacade) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module) Supplier(java.util.function.Supplier) PsiPackage(com.intellij.psi.PsiPackage)

Aggregations

StreamEx (one.util.streamex.StreamEx)2 Nullable (org.jetbrains.annotations.Nullable)2 DebuggerBundle (com.intellij.debugger.DebuggerBundle)1 DebuggerManagerEx (com.intellij.debugger.DebuggerManagerEx)1 SourcePosition (com.intellij.debugger.SourcePosition)1 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)1 DebuggerManagerThreadImpl (com.intellij.debugger.engine.DebuggerManagerThreadImpl)1 JVMName (com.intellij.debugger.engine.JVMName)1 JVMNameUtil (com.intellij.debugger.engine.JVMNameUtil)1 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)1 EvaluationContextImpl (com.intellij.debugger.engine.evaluation.EvaluationContextImpl)1 RequestManagerImpl (com.intellij.debugger.engine.requests.RequestManagerImpl)1 DebuggerUtilsEx (com.intellij.debugger.impl.DebuggerUtilsEx)1 PositionUtil (com.intellij.debugger.impl.PositionUtil)1 MethodBytecodeUtil (com.intellij.debugger.jdi.MethodBytecodeUtil)1 Requestor (com.intellij.debugger.requests.Requestor)1 AllIcons (com.intellij.icons.AllIcons)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Document (com.intellij.openapi.editor.Document)1