Example #1
0
 /**
  * Gets the Line Number at the give position of the editor component. The first line number is
  * ZERO
  *
  * @return line number
  * @throws javax.swing.text.BadLocationException
  */
 public static int getLineNumber(JTextComponent editor, int pos) throws BadLocationException {
   if (getSyntaxDocument(editor) != null) {
     SyntaxDocument sdoc = getSyntaxDocument(editor);
     return sdoc.getLineNumberAt(pos);
   } else {
     Document doc = editor.getDocument();
     return doc.getDefaultRootElement().getElementIndex(pos);
   }
 }
Example #2
0
 /** Returns the the Token at pos as a String */
 public static String getTokenStringAt(SyntaxDocument doc, int pos) {
   String word = "";
   Token t = doc.getTokenAt(pos);
   if (t != null) {
     try {
       word = doc.getText(t.start, t.length);
     } catch (BadLocationException ex) {
       Logger.getLogger(ActionUtils.class.getName()).log(Level.SEVERE, null, ex);
     }
   }
   return word;
 }
Example #3
0
  private boolean hasDeclaration(int pos) {

    SyntaxDocument sd = (SyntaxDocument) decompiledTextArea.getDocument();
    Token t = sd.getTokenAt(pos);
    if (t == null
        || (t.type != TokenType.IDENTIFIER
            && t.type != TokenType.KEYWORD
            && t.type != TokenType.REGEX)) {
      return false;
    }
    Reference<Integer> abcIndex = new Reference<>(0);
    Reference<Integer> classIndex = new Reference<>(0);
    Reference<Integer> traitIndex = new Reference<>(0);
    Reference<Integer> multinameIndexRef = new Reference<>(0);
    Reference<Boolean> classTrait = new Reference<>(false);

    if (decompiledTextArea.getPropertyTypeAtPos(
        pos, abcIndex, classIndex, traitIndex, classTrait, multinameIndexRef)) {
      return true;
    }
    int multinameIndex = decompiledTextArea.getMultinameAtPos(pos);
    if (multinameIndex > -1) {
      if (multinameIndex == 0) {
        return false;
      }
      List<MultinameUsage> usages = abc.findMultinameDefinition(multinameIndex);

      Multiname m = abc.constants.constant_multiname.get(multinameIndex);
      // search other ABC tags if this is not private multiname
      if (m.namespace_index > 0
          && abc.constants.constant_namespace.get(m.namespace_index).kind
              != Namespace.KIND_PRIVATE) {
        for (ABCContainerTag at : getAbcList()) {
          ABC a = at.getABC();
          if (a == abc) {
            continue;
          }
          int mid = a.constants.getMultinameId(m, false);
          if (mid > 0) {
            usages.addAll(a.findMultinameDefinition(mid));
          }
        }
      }

      // more than one? display list
      if (!usages.isEmpty()) {
        return true;
      }
    }

    return decompiledTextArea.getLocalDeclarationOfPos(pos, new Reference<>("")) != -1;
  }
Example #4
0
 public static int getLineCount(JTextComponent pane) {
   SyntaxDocument sdoc = getSyntaxDocument(pane);
   if (sdoc != null) {
     return sdoc.getLineCount();
   }
   int count = 0;
   try {
     int p = pane.getDocument().getLength() - 1;
     if (p > 0) {
       count = getLineNumber(pane, p);
     }
   } catch (BadLocationException ex) {
     Logger.getLogger(ActionUtils.class.getName()).log(Level.SEVERE, null, ex);
   }
   return count;
 }
 /** {@inheritDoc} */
 @Override
 public void actionPerformed(ActionEvent e) {
   JTextComponent target = getTextComponent(e);
   if (target != null) {
     SyntaxDocument sDoc = ActionUtils.getSyntaxDocument(target);
     int pos = target.getCaretPosition();
     int start = sDoc.getParagraphElement(pos).getStartOffset();
     String line = ActionUtils.getLine(target);
     if (ActionUtils.isEmptyOrBlanks(line)) {
       try {
         sDoc.insertString(pos, "}", null);
         Token t = sDoc.getPairFor(sDoc.getTokenAt(pos));
         if (null != t) {
           String pairLine = ActionUtils.getLineAt(target, t.start);
           String indent = ActionUtils.getIndent(pairLine);
           sDoc.replace(start, line.length() + 1, indent + "}", null);
         }
       } catch (BadLocationException ble) {
         target.replaceSelection("}");
       }
     } else {
       target.replaceSelection("}");
     }
   }
 }
Example #6
0
 @Override
 public void actionPerformed(JTextComponent target, SyntaxDocument sDoc, int dot, ActionEvent e) {
   if (sDoc != null) {
     sDoc.doRedo();
   }
 }
 private void updateDirty() {
   doc.setCanUndo(canUndo());
   doc.setCanRedo(canRedo());
 }
 public CompoundUndoManager(SyntaxDocument doc) {
   this.doc = doc;
   doc.addUndoableEditListener(this);
   lastLine = doc.getStartPosition().getOffset();
 }