Search in sources :

Example 1 with SourceLocation

use of com.google.api.services.clouddebugger.v2.model.SourceLocation in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugProcessStateTest method createBreakpoint.

private static Breakpoint createBreakpoint(String id, Boolean isFinal, int finalTimeSeconds, String locationPath, Integer locationLine, Boolean isError, String statusMessage) {
    Breakpoint result = new Breakpoint();
    result.setId(id);
    result.setIsFinalState(isFinal);
    if (Boolean.TRUE.equals(isFinal)) {
        Calendar calendar = // gets a calendar using the default time zone and locale.
        Calendar.getInstance();
        calendar.add(Calendar.SECOND, finalTimeSeconds);
        DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
        result.setFinalTime(formatter.print(calendar.getTimeInMillis()));
    }
    SourceLocation location = new SourceLocation();
    location.setPath(locationPath);
    location.setLine(locationLine);
    result.setLocation(location);
    StatusMessage status = new StatusMessage();
    status.setIsError(isError);
    FormatMessage message = new FormatMessage();
    message.setFormat(statusMessage);
    status.setDescription(message);
    result.setStatus(status);
    return result;
}
Also used : SourceLocation(com.google.api.services.clouddebugger.v2.model.SourceLocation) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) FormatMessage(com.google.api.services.clouddebugger.v2.model.FormatMessage) Calendar(java.util.Calendar) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) StatusMessage(com.google.api.services.clouddebugger.v2.model.StatusMessage)

Example 2 with SourceLocation

use of com.google.api.services.clouddebugger.v2.model.SourceLocation in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudBreakpointHandlerTest method testConflictingRegister.

public void testConflictingRegister() {
    Breakpoint existingServerBp = new Breakpoint();
    SourceLocation location = new SourceLocation();
    location.setPath("com/google/foo.java");
    location.setLine(124);
    existingServerBp.setLocation(location);
    existingServerBp.setId("todelete");
    existingBreakpoints.add(existingServerBp);
    registerMockBreakpoint(new String[] { "foowatch1" }, "condition == true", 123, "foo.java", "com.google", false, "b_id");
    existingBreakpoints.clear();
    assertNotNull(addedBp.get());
    assertContainsElements(addedBp.get().getExpressions(), "foowatch1");
    assertTrue(addedBp.get().getLocation().getLine() == 124);
    assertTrue(addedBp.get().getLocation().getPath().equals("com/google/foo.java"));
    assertTrue(addedBp.get().getCondition().equals("condition == true"));
}
Also used : SourceLocation(com.google.api.services.clouddebugger.v2.model.SourceLocation) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint)

Example 3 with SourceLocation

use of com.google.api.services.clouddebugger.v2.model.SourceLocation in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudBreakpointHandlerTest method testCreateIdeRepresentationsIfNecessary.

public void testCreateIdeRepresentationsIfNecessary() {
    List<Breakpoint> breakpoints = ImmutableList.of(new Breakpoint().setId("expected_path").setLocation(new SourceLocation().setLine(1).setPath("app/mod/src/main/java/b/f/pkg/Class.java")), new Breakpoint().setId("unexpected_path").setLocation(new SourceLocation().setLine(2).setPath("app/mod/src/m/j/a/b/c/Class.java")), new Breakpoint().setId("unexpected_path_2").setLocation(new SourceLocation().setLine(3).setPath("b/f/pkg/Class.java")));
    when(breakpointManager.findBreakpointAtLine(isA(XLineBreakpointType.class), isA(VirtualFile.class), anyInt())).thenReturn(null);
    XLineBreakpoint mockLineBreakpoint = mock(XLineBreakpoint.class);
    when(breakpointManager.addLineBreakpoint(isA(XLineBreakpointType.class), anyString(), anyInt(), isA(CloudLineBreakpointProperties.class))).thenReturn(mockLineBreakpoint);
    when(mockLineBreakpoint.getProperties()).thenReturn(new CloudLineBreakpointProperties());
    VirtualFile projectDir = mock(VirtualFile.class);
    when(projectDir.getPath()).thenReturn("/project/dir");
    project.setBaseDir(projectDir);
    VirtualFile classFile = mock(VirtualFile.class);
    when(classFile.getUrl()).thenReturn("file:///URL");
    when(fileResolver.getFileFromPath(isA(Project.class), eq("app/mod/src/main/java/b/f/pkg/Class.java"))).thenReturn(classFile);
    handler.createIdeRepresentationsIfNecessary(breakpoints);
    verify(breakpointManager, times(1)).addLineBreakpoint(isA(XLineBreakpointType.class), anyString(), anyInt(), isA(XBreakpointProperties.class));
}
Also used : SourceLocation(com.google.api.services.clouddebugger.v2.model.SourceLocation) VirtualFile(com.intellij.openapi.vfs.VirtualFile) XBreakpointProperties(com.intellij.xdebugger.breakpoints.XBreakpointProperties) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) Project(com.intellij.openapi.project.Project) XLineBreakpointType(com.intellij.xdebugger.breakpoints.XLineBreakpointType) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint)

Example 4 with SourceLocation

use of com.google.api.services.clouddebugger.v2.model.SourceLocation in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugHistoricalSnapshotsTest method testOnBreakpointListChanged.

@Test
public void testOnBreakpointListChanged() throws InterruptedException {
    CloudDebugHistoricalSnapshots snapshots = new CloudDebugHistoricalSnapshots(handler);
    Breakpoint bp1 = new Breakpoint();
    bp1.setId("an ID");
    bp1.setFinalTime("2015-08-22T05:23:34.123Z");
    bp1.setIsFinalState(true);
    SourceLocation location = new SourceLocation();
    location.setPath("foo/bar/baz");
    location.setLine(12);
    bp1.setLocation(location);
    List<Breakpoint> breakpoints = new ArrayList<Breakpoint>();
    breakpoints.add(bp1);
    Mockito.when(mockProcess.getCurrentBreakpointList()).thenReturn(breakpoints);
    Mockito.when(mockProcess.getCurrentSnapshot()).thenReturn(bp1);
    CloudBreakpointHandler breakpointHandler = Mockito.mock(CloudBreakpointHandler.class);
    Mockito.when(mockProcess.getBreakpointHandler()).thenReturn(breakpointHandler);
    runModelSetter(snapshots);
    Assert.assertEquals(0, snapshots.table.getSelectedRow());
}
Also used : SourceLocation(com.google.api.services.clouddebugger.v2.model.SourceLocation) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) CloudBreakpointHandler(com.google.cloud.tools.intellij.debugger.CloudBreakpointHandler) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with SourceLocation

use of com.google.api.services.clouddebugger.v2.model.SourceLocation in project google-cloud-intellij by GoogleCloudPlatform.

the class BreakpointComparer method compare.

@SuppressWarnings("ConstantConditions")
@Override
public int compare(Breakpoint o1, Breakpoint o2) {
    if (o2.getFinalTime() == null && o1.getFinalTime() != null) {
        return 1;
    }
    if (o2.getFinalTime() != null && o1.getFinalTime() == null) {
        return -1;
    }
    if (o2.getFinalTime() == null && o1.getFinalTime() == null) {
        // compare file and line
        SourceLocation s1 = o1.getLocation();
        SourceLocation s2 = o2.getLocation();
        boolean s1Valid = isSourceLocationValid(s1);
        boolean s2Valid = isSourceLocationValid(s2);
        if (!s1Valid && !s2Valid) {
            return 0;
        }
        if (s1Valid && !s2Valid) {
            return -1;
        }
        if (!s1Valid && s2Valid) {
            return 1;
        }
        if (s1.getPath().equals(s2.getPath())) {
            long s1Line = toLongValue(s1.getLine().longValue());
            long s2Line = toLongValue(s2.getLine().longValue());
            if (s1Line > s2Line) {
                return 1;
            }
            if (s1Line < s2Line) {
                return -1;
            }
            return 0;
        }
        return s1.getPath().compareTo(s2.getPath());
    }
    Date d1, d2;
    try {
        d1 = ISODateTimeFormat.dateTime().parseDateTime(o1.getFinalTime()).toDate();
        d2 = ISODateTimeFormat.dateTime().parseDateTime(o2.getFinalTime()).toDate();
    } catch (IllegalArgumentException iae) {
        d1 = MINIMUM_DATE;
        d2 = MINIMUM_DATE;
    }
    return d2.compareTo(d1);
}
Also used : SourceLocation(com.google.api.services.clouddebugger.v2.model.SourceLocation) Date(java.util.Date)

Aggregations

SourceLocation (com.google.api.services.clouddebugger.v2.model.SourceLocation)9 Breakpoint (com.google.api.services.clouddebugger.v2.model.Breakpoint)7 CloudLineBreakpoint (com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint)3 XBreakpoint (com.intellij.xdebugger.breakpoints.XBreakpoint)3 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 CloudBreakpointHandler (com.google.cloud.tools.intellij.debugger.CloudBreakpointHandler)2 Debugger (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger)1 FormatMessage (com.google.api.services.clouddebugger.v2.model.FormatMessage)1 SetBreakpointResponse (com.google.api.services.clouddebugger.v2.model.SetBreakpointResponse)1 StackFrame (com.google.api.services.clouddebugger.v2.model.StackFrame)1 StatusMessage (com.google.api.services.clouddebugger.v2.model.StatusMessage)1 Variable (com.google.api.services.clouddebugger.v2.model.Variable)1 SetBreakpointHandler (com.google.cloud.tools.intellij.debugger.CloudDebugProcessStateController.SetBreakpointHandler)1 PluginInfoService (com.google.cloud.tools.intellij.service.PluginInfoService)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 PsiJavaFile (com.intellij.psi.PsiJavaFile)1