コード例 #1
0
  @Override
  public List<ErrorDescription> run(CompilationInfo info, TreePath treePath) {
    Tree t = treePath.getLeaf();
    JTextComponent editor = EditorRegistry.lastFocusedComponent();
    Document doc = editor.getDocument();

    SourcePositions sp = info.getTrees().getSourcePositions();
    int start = (int) sp.getStartPosition(info.getCompilationUnit(), t);
    int end = (int) sp.getEndPosition(info.getCompilationUnit(), t);
    int endLine = info.getText().indexOf("\n", start);
    String line = info.getText().substring(start, endLine).trim();

    if (!Suppression.isSuppressed(line)) {
      return Collections.<ErrorDescription>singletonList(
          ErrorDescriptionFactory.createErrorDescription(
              Severity.HINT,
              ERROR_DESCRIPTION,
              createFixes(doc, start, endLine),
              info.getFileObject(),
              start,
              end));
    } else {
      return null;
    }
  }
コード例 #2
0
 @Override
 public void run() {
   JTextComponent component = EditorRegistry.focusedComponent();
   if (component != null) {
     DocumentPreprocessor.updateBlockChain(
         (NbEditorDocument) component.getDocument());
   }
 }
コード例 #3
0
  @Override
  protected final void actionPerformed(PhpModule phpModule) {
    // called via shortcut
    if (!CakePhpUtils.isCakePHP(phpModule)) {
      return;
    }

    JTextComponent editor = EditorRegistry.lastFocusedComponent();
    if (editor == null) {
      return;
    }

    Document document = editor.getDocument();
    if (document == null) {
      return;
    }

    FileObject fileObject = NbEditorUtilities.getFileObject(document);
    if (fileObject == null) {
      return;
    }
    // get go to files
    CakePhpGoToStatusFactory factory = CakePhpGoToStatusFactory.getInstance();
    CakePhpGoToStatus status = factory.create(fileObject, editor.getCaretPosition());
    final List<GoToItem> items = getGoToItems(status);
    if (items == null || items.isEmpty()) {
      return;
    }

    // if there are multiple items, show popup list
    if (items.size() == 1 && !CakePreferences.isShowPopupForOneItem(phpModule)) {
      for (GoToItem item : items) {
        UiUtils.open(item.getFileObject(), item.getOffset());
        return;
      }
    }

    // show popup
    try {
      Rectangle rectangle = editor.modelToView(editor.getCaretPosition());
      final Point point = new Point(rectangle.x, rectangle.y + rectangle.height);
      SwingUtilities.convertPointToScreen(point, editor);
      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              String title = getPopupTitle();
              if (title == null) {
                title = ""; // NOI18N
              }
              PopupUtil.showPopup(new GoToPopup(title, items), title, point.x, point.y, true, 0);
            }
          });
    } catch (BadLocationException ex) {
      Exceptions.printStackTrace(ex);
    }
  }
コード例 #4
0
 public void propertyChange(PropertyChangeEvent evt) {
   JTextComponent last = EditorRegistry.lastFocusedComponent();
   if (last != null) {
     final NbEditorDocument doc = (NbEditorDocument) last.getDocument();
     doc.getDocumentProperties().remove(TextSwitcher.TEXT_SWITCH_SUPPORT);
     doc.removeDocumentListener(dl);
   }
   JTextComponent current = EditorRegistry.focusedComponent();
   if (current != null) {
     final NbEditorDocument doc = (NbEditorDocument) current.getDocument();
     doc.addDocumentListener(dl);
     doc.getDocumentProperties()
         .put(
             TextSwitcher.TEXT_SWITCH_SUPPORT,
             new ChangeListener() {
               public void stateChanged(
                   @SuppressWarnings("unused") // NOI18N
                       final ChangeEvent e) {
                 restartTimer();
               }
             });
     restartTimer();
   }
 }
コード例 #5
0
  /*
   * Main constructor to parse Javascript file
   * @param input. The string containing the file data
   */
  public VariableNameComboModel() throws FileNotFoundException {
    String input = EditorRegistry.lastFocusedComponent().getText();
    String replaceInput = removeComment(input).replaceAll("[)(;+}={,.]", "");
    // enter entries (split) by whitespace
    String words[] = replaceInput.split("\\s+");
    int counter = 0;
    // while there are still words, add them to the variableNamesArray ArrayList
    for (int i = 0; i < words.length; i++) {
      if (words[i].equals("var")) {
        variableNamesArray.add(words[i + 1]);
      } else {

      }
      counter++;
    }
    counter = 1;
    while (counter < words.length) {
      if (words[counter - 1].equals("function")) {

        functionNamesArray.add("   " + words[counter]);
      }
      counter++;
    }
    counter = 1;

    while (counter < words.length) {
      if (words[counter - 1].equals("class")) {

        classNamesArray.add("   " + words[counter]);
      }
      counter++;
    }
    int i = 0;
    // convert the arraylist to an array
    if (!variableNamesArray.isEmpty()) {
      MyList.add("Variables");
      MyList.addAll(variableNamesArray);
    }
    if (!functionNamesArray.isEmpty()) {
      MyList.add("Functions");
      MyList.addAll(functionNamesArray);
    }
    if (!classNamesArray.isEmpty()) {
      MyList.add("Classes");
      MyList.addAll(classNamesArray);
    }
    this.variableNames = (String[]) MyList.toArray(new String[0]);
  }
コード例 #6
0
  protected synchronized Dialog createGotoDialog() {
    if (gotoDialog == null) {
      gotoDialog =
          DialogSupport.createDialog(
              NbBundle.getBundle(org.netbeans.editor.BaseKit.class)
                  .getString("goto-title"), // NOI18N
              gotoPanel,
              false, // non-modal
              gotoButtons,
              false, // sidebuttons,
              0, // defaultIndex = 0 => gotoButton
              1, // cancelIndex = 1 => cancelButton
              this // listener
              );

      gotoDialog.pack();

      // Position the dialog according to the history
      Rectangle lastBounds = (Rectangle) EditorState.get(BOUNDS_KEY);
      if (lastBounds != null) {
        gotoDialog.setBounds(lastBounds);
      } else { // no history, center it on the screen
        Dimension dim = gotoDialog.getPreferredSize();
        int x;
        int y;
        JTextComponent c = EditorRegistry.lastFocusedComponent();
        Window w = c != null ? SwingUtilities.getWindowAncestor(c) : null;
        if (w != null) {
          x = Math.max(0, w.getX() + (w.getWidth() - dim.width) / 2);
          y = Math.max(0, w.getY() + (w.getHeight() - dim.height) / 2);
        } else {
          Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
          x = Math.max(0, (screen.width - dim.width) / 2);
          y = Math.max(0, (screen.height - dim.height) / 2);
        }
        gotoDialog.setLocation(x, y);
      }

      return gotoDialog;
    } else {
      gotoDialog.setVisible(true);
      gotoDialog.toFront();
      return null;
    }
  }
コード例 #7
0
  public DocumentPreprocessor() {

    dl = new DL();

    JTextComponent component = EditorRegistry.focusedComponent();
    if (component != null) {
      updateBlockChain((NbEditorDocument) component.getDocument());

      final NbEditorDocument doc = (NbEditorDocument) component.getDocument();
      doc.addDocumentListener(dl);
      doc.getDocumentProperties()
          .put(
              TextSwitcher.TEXT_SWITCH_SUPPORT,
              new ChangeListener() {
                public void stateChanged(@SuppressWarnings("unused") final ChangeEvent e) {
                  updateBlockChain(doc);
                }
              });
    }
  }
コード例 #8
0
  /**
   * Perform the goto operation.
   *
   * @return whether the dialog should be made invisible or not
   */
  protected boolean performGoto() {
    JTextComponent c = EditorRegistry.lastFocusedComponent();
    if (c != null) {
      try {
        int line = Integer.parseInt(getGotoValueText());

        // issue 188976
        if (line == 0) line = 1;
        // end of issue 188976

        BaseDocument doc = Utilities.getDocument(c);
        if (doc != null) {
          int rowCount = Utilities.getRowCount(doc);
          if (line > rowCount) line = rowCount;

          // Obtain the offset where to jump
          int pos = Utilities.getRowStartFromLineOffset(doc, line - 1);

          BaseKit kit = Utilities.getKit(c);
          if (kit != null) {
            Action a = kit.getActionByName(ExtKit.gotoAction);
            if (a instanceof ExtKit.GotoAction) {
              pos = ((ExtKit.GotoAction) a).getOffsetFromLine(doc, line - 1);
            }
          }

          if (pos != -1) {
            Caret caret = c.getCaret();
            caret.setDot(pos);
          } else {
            c.getToolkit().beep();
            return false;
          }
        }
      } catch (NumberFormatException e) {
        c.getToolkit().beep();
        return false;
      }
    }
    return true;
  }