Ejemplo n.º 1
0
 private GroovyStructureItem(ASTElement node, ParserResult info) {
   this.node = node;
   this.kind = node.getKind();
   this.info = info;
   // FIXME true or false ?
   this.doc = (BaseDocument) info.getSnapshot().getSource().getDocument(false);
 }
Ejemplo n.º 2
0
 private static boolean isVisible(ASTElement element) {
   // FIXME perhaps we should store synthetic atributte in AstElement
   if ((element.getKind() == ElementKind.METHOD)) {
     ASTMethod method = (ASTMethod) element;
     ASTNode node = method.getNode();
     return !(node instanceof MethodNode)
         || (!((MethodNode) node).isSynthetic() && ((MethodNode) node).getLineNumber() >= 0);
   }
   return true;
 }
Ejemplo n.º 3
0
  private void addFolds(
      BaseDocument doc,
      List<? extends ASTElement> elements,
      Map<String, List<OffsetRange>> folds,
      List<OffsetRange> codeblocks)
      throws BadLocationException {
    for (ASTElement element : elements) {
      ElementKind kind = element.getKind();
      switch (kind) {
        case FIELD:
        case METHOD:
        case CONSTRUCTOR:
        case CLASS:
        case MODULE:
          ASTNode node = element.getNode();
          OffsetRange range = ASTUtils.getRangeFull(node, doc);

          // beware of synthetic elements
          if ((kind == ElementKind.METHOD && !((MethodNode) node).isSynthetic())
              || (kind == ElementKind.CONSTRUCTOR && !((ConstructorNode) node).isSynthetic())
              || (kind == ElementKind.FIELD
                  && ((FieldNode) node).getInitialExpression() instanceof ClosureExpression)
              // Only make nested classes/modules foldable, similar to what the java editor is doing
              || (range.getStart() > Utilities.getRowStart(doc, range.getStart()))
                  && kind != ElementKind.FIELD) {

            int start = range.getStart();
            // Start the fold at the END of the line behind last non-whitespace, remove curly brace,
            // if any
            start = Utilities.getRowLastNonWhite(doc, start);
            if (start >= 0 && doc.getChars(start, 1)[0] != '{') {
              start++;
            }
            int end = range.getEnd();
            if (start != (-1) && end != (-1) && start < end && end <= doc.getLength()) {
              range = new OffsetRange(start, end);
              codeblocks.add(range);
            }
          }
          break;
      }

      List<? extends ASTElement> children = element.getChildren();

      if (children != null && children.size() > 0) {
        addFolds(doc, children, folds, codeblocks);
      }
    }
  }