示例#1
0
 /* (non-Javadoc)
  * @see org.eclipse.jdt.internal.debug.ui.actions.OpenTypeAction#getTypeToOpen(org.eclipse.debug.core.model.IDebugElement)
  */
 protected IJavaType getTypeToOpen(IDebugElement element) throws CoreException {
   if (element instanceof IJavaStackFrame) {
     IJavaStackFrame frame = (IJavaStackFrame) element;
     return frame.getReferenceType();
   }
   return null;
 }
示例#2
0
 /* (non-Javadoc)
  * @see org.eclipse.jdt.internal.debug.ui.contentassist.IJavaDebugContentAssistContext#isStatic()
  */
 public boolean isStatic() throws CoreException {
   IJavaStackFrame frame = getStackFrame();
   if (frame != null) {
     return frame.isStatic();
   }
   return false;
 }
示例#3
0
 /**
  * Resolves and returns a type from the Java model that corresponds to the declaring type of the
  * given stack frame, or <code>null</code> if none.
  *
  * @param frame frame to resolve declaring type for
  * @return corresponding Java model type or <code>null</code>
  * @exception CoreException if an exception occurs during the resolution
  * @since 3.2
  */
 public static IType resolveDeclaringType(IJavaStackFrame frame) throws CoreException {
   IJavaElement javaElement = resolveJavaElement(frame, frame.getLaunch());
   if (javaElement != null) {
     return resolveType(frame.getDeclaringTypeName(), javaElement);
   }
   return null;
 }
 /**
  * Returns the source name associated with the given object, or <code>null</code> if none.
  *
  * @param object an object with an <code>IJavaStackFrame</code> adapter, an IJavaValue or an
  *     IJavaType
  * @return the source name associated with the given object, or <code>null</code> if none
  * @exception CoreException if unable to retrieve the source name
  */
 public static String getSourceName(Object object) throws CoreException {
   if (object instanceof String) {
     // assume it's a file name
     return (String) object;
   }
   IJavaStackFrame frame = null;
   if (object instanceof IAdaptable) {
     frame = ((IAdaptable) object).getAdapter(IJavaStackFrame.class);
   }
   String typeName = null;
   try {
     if (frame != null) {
       if (frame.isObsolete()) {
         return null;
       }
       String sourceName = frame.getSourcePath();
       // TODO: this may break fix to bug 21518
       if (sourceName == null) {
         // no debug attributes, guess at source name
         typeName = frame.getDeclaringTypeName();
       } else {
         return sourceName;
       }
     } else {
       if (object instanceof IJavaValue) {
         // look at its type
         object = ((IJavaValue) object).getJavaType();
       }
       if (object instanceof IJavaReferenceType) {
         IJavaReferenceType refType = (IJavaReferenceType) object;
         IJavaDebugTarget target = ((IJavaDebugTarget) refType.getDebugTarget());
         String[] sourcePaths = refType.getSourcePaths(target.getDefaultStratum());
         if (sourcePaths != null && sourcePaths.length > 0) {
           return sourcePaths[0];
         }
       }
       if (object instanceof IJavaType) {
         typeName = ((IJavaType) object).getName();
       }
     }
   } catch (DebugException e) {
     int code = e.getStatus().getCode();
     if (code == IJavaThread.ERR_THREAD_NOT_SUSPENDED
         || code == IJavaStackFrame.ERR_INVALID_STACK_FRAME
         || e.getStatus().getException() instanceof VMDisconnectedException) {
       return null;
     }
     throw e;
   }
   if (typeName != null) {
     return generateSourceName(typeName);
   }
   return null;
 }
示例#5
0
 @Override
 public boolean filter(IJavaStackFrame frame, IEGLJavaDebugTarget target) {
   try {
     return frame.getDeclaringTypeName().startsWith("org.apache."); // $NON-NLS-1$
   } catch (DebugException de) {
     return false;
   }
 }
  /**
   * tests the hit count of an exception breakpoint
   *
   * @throws Exception
   */
  public void testHitCountException() throws Exception {
    String typeName = "HitCountException";
    IJavaExceptionBreakpoint ex =
        createExceptionBreakpoint("java.lang.NullPointerException", true, true);
    ex.setHitCount(2);

    IJavaThread thread = null;
    try {
      thread = launchToBreakpoint(typeName);
      IJavaStackFrame frame = (IJavaStackFrame) thread.getTopStackFrame();
      assertEquals("Should have been suspended at linenumber", 35, frame.getLineNumber());

      ex.delete();
    } finally {
      terminateAndRemove(thread);
      removeAllBreakpoints();
    }
  }
示例#7
0
 /* (non-Javadoc)
  * @see org.eclipse.jdt.internal.debug.ui.contentassist.IJavaDebugContentAssistContext#getLocalVariables()
  */
 public String[][] getLocalVariables() throws CoreException {
   IJavaStackFrame frame = getStackFrame();
   if (frame != null) {
     IVariable[] variables = frame.getVariables();
     int index = 0;
     if (!frame.isStatic()) {
       index = 1;
     }
     String[][] locals = new String[2][variables.length - index];
     for (int i = 0; i < locals[0].length; i++) {
       IJavaVariable var = (IJavaVariable) variables[index];
       locals[0][i] = var.getName();
       locals[1][i] = var.getJavaType().getName();
       index++;
     }
     return locals;
   }
   return super.getLocalVariables();
 }
  /**
   * tests that breakpoint suspends on uncaught exceptions
   *
   * @throws Exception
   */
  public void testUncaughtException() throws Exception {
    String typeName = "HitCountException";
    IJavaExceptionBreakpoint ex =
        createExceptionBreakpoint("java.lang.NullPointerException", false, true);

    IJavaThread thread = null;
    try {
      thread = launchToBreakpoint(typeName);
      assertNotNull("Breakpoint not hit within timeout period", thread);

      IBreakpoint hit = getBreakpoint(thread);
      assertNotNull("suspended, but not by breakpoint", hit);
      assertEquals("suspended, but not by exception breakpoint", ex, hit);
      IJavaStackFrame frame = (IJavaStackFrame) thread.getTopStackFrame();
      assertTrue(
          "Should have been suspended at line number 35, not " + frame.getLineNumber(),
          frame.getLineNumber() == 35);
      ex.delete();
    } finally {
      terminateAndRemove(thread);
      removeAllBreakpoints();
    }
  }
 /**
  * Resolves the {@link IJavaProject} within the context of the given {@link IJavaStackFrame}
  *
  * @param frame
  * @return the {@link IJavaProject} or <code>null</code>
  * @since 3.8.0
  */
 public static IJavaProject resolveJavaProject(IJavaStackFrame frame) {
   ILaunch launch = frame.getLaunch();
   if (launch != null) {
     try {
       Object sourceElement = resolveSourceElement(frame, JAVA_STRATUM, launch);
       IJavaElement element = getJavaElement(sourceElement);
       if (element != null) {
         return element.getJavaProject();
       }
       // If Source element is not a Java element
       if (sourceElement instanceof IResource) {
         IJavaProject project = JavaCore.create(((IResource) sourceElement).getProject());
         if (project.exists()) {
           return project;
         }
       }
     } catch (CoreException ce) {
       // do nothing, return null
     }
   }
   return null;
 }