예제 #1
0
 /** {@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("}");
     }
   }
 }
예제 #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;
 }
예제 #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;
  }