Search in sources :

Example 31 with ReferenceType

use of com.sun.jdi.ReferenceType in project intellij-community by JetBrains.

the class ShowInstancesByClassAction method perform.

@Override
protected void perform(XValueNodeImpl node, @NotNull String nodeName, AnActionEvent e) {
    final Project project = e.getProject();
    if (project != null) {
        final XDebugSession debugSession = XDebuggerManager.getInstance(project).getCurrentSession();
        final ObjectReference ref = getObjectReference(node);
        if (debugSession != null && ref != null) {
            final ReferenceType referenceType = ref.referenceType();
            new InstancesWindow(debugSession, l -> {
                final List<ObjectReference> instances = referenceType.instances(l);
                return instances == null ? Collections.emptyList() : instances;
            }, referenceType.name()).show();
        }
    }
}
Also used : List(java.util.List) XValueNodeImpl(com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl) StringUtil(com.intellij.openapi.util.text.StringUtil) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ReferenceType(com.sun.jdi.ReferenceType) Project(com.intellij.openapi.project.Project) XDebuggerManager(com.intellij.xdebugger.XDebuggerManager) InstancesWindow(com.intellij.debugger.memory.ui.InstancesWindow) ObjectReference(com.sun.jdi.ObjectReference) NotNull(org.jetbrains.annotations.NotNull) XDebugSession(com.intellij.xdebugger.XDebugSession) Collections(java.util.Collections) Project(com.intellij.openapi.project.Project) XDebugSession(com.intellij.xdebugger.XDebugSession) InstancesWindow(com.intellij.debugger.memory.ui.InstancesWindow) ObjectReference(com.sun.jdi.ObjectReference) List(java.util.List) ReferenceType(com.sun.jdi.ReferenceType)

Example 32 with ReferenceType

use of com.sun.jdi.ReferenceType in project intellij-community by JetBrains.

the class DebuggerTreeNodeExpression method castToRuntimeType.

public static PsiExpression castToRuntimeType(PsiExpression expression, Value value) throws EvaluateException {
    if (!(value instanceof ObjectReference)) {
        return expression;
    }
    ReferenceType valueType = ((ObjectReference) value).referenceType();
    if (valueType == null) {
        return expression;
    }
    Project project = expression.getProject();
    PsiType type = RuntimeTypeEvaluator.getCastableRuntimeType(project, value);
    if (type == null) {
        return expression;
    }
    PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
    String typeName = type.getCanonicalText();
    try {
        PsiParenthesizedExpression parenthExpression = (PsiParenthesizedExpression) elementFactory.createExpressionFromText("((" + typeName + ")expression)", null);
        //noinspection ConstantConditions
        ((PsiTypeCastExpression) parenthExpression.getExpression()).getOperand().replace(expression);
        Set<String> imports = expression.getUserData(ADDITIONAL_IMPORTS_KEY);
        if (imports == null) {
            imports = new SmartHashSet<>();
        }
        imports.add(typeName);
        parenthExpression.putUserData(ADDITIONAL_IMPORTS_KEY, imports);
        return parenthExpression;
    } catch (IncorrectOperationException e) {
        throw new EvaluateException(DebuggerBundle.message("error.invalid.type.name", typeName), e);
    }
}
Also used : Project(com.intellij.openapi.project.Project) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) ObjectReference(com.sun.jdi.ObjectReference) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ReferenceType(com.sun.jdi.ReferenceType)

Example 33 with ReferenceType

use of com.sun.jdi.ReferenceType in project intellij-community by JetBrains.

the class NodeManagerImpl method getContextKeyForFrame.

@Nullable
public static String getContextKeyForFrame(final StackFrameProxyImpl frame) {
    if (frame == null) {
        return null;
    }
    try {
        final Location location = frame.location();
        final Method method = DebuggerUtilsEx.getMethod(location);
        if (method == null) {
            return null;
        }
        final ReferenceType referenceType = location.declaringType();
        final StringBuilder builder = StringBuilderSpinAllocator.alloc();
        try {
            return builder.append(referenceType.signature()).append("#").append(method.name()).append(method.signature()).toString();
        } finally {
            StringBuilderSpinAllocator.dispose(builder);
        }
    } catch (EvaluateException ignored) {
    } catch (InternalException ie) {
        if (ie.errorCode() != 23) {
            // INVALID_METHODID
            throw ie;
        }
    }
    return null;
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) Method(com.sun.jdi.Method) ReferenceType(com.sun.jdi.ReferenceType) Location(com.sun.jdi.Location) InternalException(com.sun.jdi.InternalException) Nullable(org.jetbrains.annotations.Nullable)

Example 34 with ReferenceType

use of com.sun.jdi.ReferenceType in project intellij-community by JetBrains.

the class GroovyPositionManager method getAllClasses.

@Override
@NotNull
public List<ReferenceType> getAllClasses(@NotNull final SourcePosition position) throws NoDataException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("getAllClasses: " + position);
    }
    checkGroovyFile(position);
    List<ReferenceType> result = ApplicationManager.getApplication().runReadAction(new Computable<List<ReferenceType>>() {

        @Override
        public List<ReferenceType> compute() {
            GroovyPsiElement sourceImage = findReferenceTypeSourceImage(position);
            if (sourceImage instanceof GrTypeDefinition && !((GrTypeDefinition) sourceImage).isAnonymous()) {
                String qName = getClassNameForJvm((GrTypeDefinition) sourceImage);
                if (qName != null)
                    return myDebugProcess.getVirtualMachineProxy().classesByName(qName);
            } else if (sourceImage == null) {
                final String scriptName = getScriptQualifiedName(position);
                if (scriptName != null)
                    return myDebugProcess.getVirtualMachineProxy().classesByName(scriptName);
            } else {
                String enclosingName = findEnclosingName(position);
                if (enclosingName == null)
                    return null;
                final List<ReferenceType> outers = myDebugProcess.getVirtualMachineProxy().classesByName(enclosingName);
                final List<ReferenceType> result = new ArrayList<>(outers.size());
                for (ReferenceType outer : outers) {
                    final ReferenceType nested = findNested(outer, sourceImage, position);
                    if (nested != null) {
                        result.add(nested);
                    }
                }
                return result;
            }
            return null;
        }
    });
    if (LOG.isDebugEnabled()) {
        LOG.debug("getAllClasses = " + result);
    }
    if (result == null)
        throw NoDataException.INSTANCE;
    return result;
}
Also used : GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ReferenceType(com.sun.jdi.ReferenceType) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with ReferenceType

use of com.sun.jdi.ReferenceType in project intellij-community by JetBrains.

the class GroovyPositionManager method createPrepareRequest.

@Override
public ClassPrepareRequest createPrepareRequest(@NotNull final ClassPrepareRequestor requestor, @NotNull final SourcePosition position) throws NoDataException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("createPrepareRequest: " + position);
    }
    checkGroovyFile(position);
    String qName = getOuterClassName(position);
    if (qName != null) {
        return myDebugProcess.getRequestsManager().createClassPrepareRequest(requestor, qName);
    }
    qName = findEnclosingName(position);
    if (qName == null)
        throw NoDataException.INSTANCE;
    ClassPrepareRequestor waitRequestor = new ClassPrepareRequestor() {

        @Override
        public void processClassPrepare(DebugProcess debuggerProcess, ReferenceType referenceType) {
            final CompoundPositionManager positionManager = ((DebugProcessImpl) debuggerProcess).getPositionManager();
            if (!positionManager.locationsOfLine(referenceType, position).isEmpty()) {
                requestor.processClassPrepare(debuggerProcess, referenceType);
            }
        }
    };
    return myDebugProcess.getRequestsManager().createClassPrepareRequest(waitRequestor, qName + "$*");
}
Also used : ClassPrepareRequestor(com.intellij.debugger.requests.ClassPrepareRequestor) DebugProcess(com.intellij.debugger.engine.DebugProcess) CompoundPositionManager(com.intellij.debugger.engine.CompoundPositionManager) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) ReferenceType(com.sun.jdi.ReferenceType)

Aggregations

ReferenceType (com.sun.jdi.ReferenceType)40 Nullable (org.jetbrains.annotations.Nullable)9 Project (com.intellij.openapi.project.Project)8 Location (com.sun.jdi.Location)5 ObjectReference (com.sun.jdi.ObjectReference)5 AbsentInformationException (com.sun.jdi.AbsentInformationException)4 Method (com.sun.jdi.Method)4 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)3 ClassesTable (com.intellij.debugger.memory.ui.ClassesTable)3 InstancesWindow (com.intellij.debugger.memory.ui.InstancesWindow)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 XDebugSession (com.intellij.xdebugger.XDebugSession)3 SourcePosition (com.intellij.debugger.SourcePosition)2 DebugProcess (com.intellij.debugger.engine.DebugProcess)2 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)2 InstancesTracker (com.intellij.debugger.memory.component.InstancesTracker)2 InstancesProvider (com.intellij.debugger.memory.utils.InstancesProvider)2 ClassPrepareRequestor (com.intellij.debugger.requests.ClassPrepareRequestor)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 PsiClass (com.intellij.psi.PsiClass)2