/**
   * @see https://community.jboss.org/message/732539#732539
   * @param projectName
   * @param pkgName
   */
  private void jaxWsApi22RequirementWorkaround(String projectName, String pkgName) {
    SWTBotEclipseEditor editor =
        packageExplorer
            .openFile(projectName, "src", pkgName, "AreaService_Service.java")
            .toTextEditor();

    String text = editor.getText();
    boolean putComment = false;
    StringBuilder output = new StringBuilder();
    for (String line : text.split(System.getProperty("line.separator"))) {
      if (line.contains(
          "This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2")) {
        putComment = true;
      }
      if (putComment) {
        output.append("//");
        if (line.contains("}")) {
          putComment = false;
        }
      }
      output.append(line);
      output.append(System.getProperty("line.separator"));
    }
    editor.setText(output.toString());
    editor.saveAndClose();
  }
예제 #2
0
  /*
   * Verify that the POM XML editor is smart enough to offer proper content assist even if the POM does not explicitly
   * declare a schema (MNGECLIPSE-1770).
   */
  @Test
  public void testContentAssistWithoutSchema() throws Exception {
    String name = PROJECT_NAME + "/ca.pom";
    String str =
        "<project>\n" //
            + "<modelVersion>4.0.0</modelVersion>\n" //
            + "<groupId>test</groupId>\n" //
            + "<artifactId>ca</artifactId>\n" //
            + "<packaging>jar</packaging>\n" //
            + "<version>0.0.1-SNAPSHOT</version>\n" //
            + "<build>\n" //
            + "</build>\n" //
            + "</project>\n";
    createFile(name, str);

    openPomFile(name);

    selectEditorTab(TAB_POM_XML);
    findText("</build>");

    SWTBotEclipseEditor editor = bot.activeEditor().toTextEditor();
    editor.pressShortcut(KeyStroke.getInstance(SWT.ARROW_LEFT));
    editor.pressShortcut(SWT.CTRL, ' ');
    editor.pressShortcut(KeyStroke.getInstance(SWT.LF));
    String text = editor.getText();
    assertTrue(text, text.contains("<defaultGoal>"));
  }
  /**
   * Selects textToSelect within Source Pane of editor with title editorTitle
   *
   * @param bot
   * @param editorTitle
   * @param textToSelect
   * @param selectionOffset
   * @param selectionLength
   * @param textToSelectIndex
   * @return SWTBotEclipseEditor
   */
  public static SWTBotEclipseEditor selectTextInSourcePane(
      SWTBotExt bot,
      String editorTitle,
      String textToSelect,
      int selectionOffset,
      int selectionLength,
      int textToSelectIndex) {

    SWTBotEclipseEditor editor = bot.editorByTitle(editorTitle).toTextEditor();
    String editorText = editor.getText();
    boolean found = false;
    int iStartIndex = 0;
    int iRow = 0;
    if (editorText != null && editorText.length() > 0 && editorText.contains(textToSelect)) {
      int iOccurenceIndex = 0;
      while (!found && iRow < editor.getLineCount()) {
        String lineText = editor.getTextOnLine(iRow);
        iStartIndex = 0;
        while (!found && lineText.contains(textToSelect)) {
          if (iOccurenceIndex == textToSelectIndex) {
            found = true;
            iStartIndex += lineText.indexOf(textToSelect);
          } else {
            iOccurenceIndex++;
            int iNewStartIndex = lineText.indexOf(textToSelect) + textToSelect.length();
            iStartIndex += iNewStartIndex;
            lineText = lineText.substring(iNewStartIndex);
          }
        }
        if (!found) {
          iRow++;
        }
      }
    }

    if (found) {
      int column = iStartIndex + selectionOffset;
      editor.selectRange(iRow, column, selectionLength);
      bot.waitUntil(new CursorAtPosition(editor, new Position(iRow, column)));
    } else {
      throw new SelectTextInSourcePaneException(
          "Wrong parameters specified for method selectTextInSourcePane.\n"
              + "Unable to select required text '"
              + textToSelect
              + "' within editor with title "
              + editorTitle
              + ".\n"
              + "Editor text is: "
              + editorText);
    }
    return editor;
  }