Exemplo n.º 1
0
 /* (non-Javadoc)
  * @see org.eclipse.jdt.internal.compiler.parser.AbstractCommentParser#createArgumentReference(char[], java.lang.Object, int)
  */
 protected Object createArgumentReference(
     char[] name, int dim, boolean isVarargs, Object typeRef, long[] dimPositions, long argNamePos)
     throws InvalidInputException {
   try {
     MethodRefParameter argument = this.ast.newMethodRefParameter();
     ASTNode node = (ASTNode) typeRef;
     int argStart = node.getStartPosition();
     int argEnd = node.getStartPosition() + node.getLength() - 1;
     if (dim > 0) argEnd = (int) dimPositions[dim - 1];
     if (argNamePos >= 0) argEnd = (int) argNamePos;
     if (name.length != 0) {
       final SimpleName argName = new SimpleName(this.ast);
       argName.internalSetIdentifier(new String(name));
       argument.setName(argName);
       int argNameStart = (int) (argNamePos >>> 32);
       argName.setSourceRange(argNameStart, argEnd - argNameStart + 1);
     }
     Type argType = null;
     if (node.getNodeType() == ASTNode.PRIMITIVE_TYPE) {
       argType = (PrimitiveType) node;
       //				if (dim > 0) {
       //					argType = this.ast.newArrayType(argType, dim);
       //					argType.setSourceRange(argStart, ((int) dimPositions[dim-1])-argStart+1);
       //				}
     } else {
       Name argTypeName = (Name) node;
       argType = this.ast.newSimpleType(argTypeName);
       argType.setSourceRange(argStart, node.getLength());
     }
     if (dim > 0 && !isVarargs) {
       for (int i = 0; i < dim; i++) {
         argType = this.ast.newArrayType(argType);
         argType.setSourceRange(argStart, ((int) dimPositions[i]) - argStart + 1);
       }
     }
     argument.setType(argType);
     argument.setSourceRange(argStart, argEnd - argStart + 1);
     return argument;
   } catch (ClassCastException ex) {
     throw new InvalidInputException();
   }
 }
Exemplo n.º 2
0
 /* (non-Javadoc)
  * @see org.eclipse.jdt.internal.compiler.parser.AbstractCommentParser#pushSeeRef(java.lang.Object)
  */
 protected boolean pushSeeRef(Object statement) {
   TagElement seeTag = this.ast.newTagElement();
   ASTNode node = (ASTNode) statement;
   seeTag.fragments().add(node);
   int end = node.getStartPosition() + node.getLength() - 1;
   if (this.inlineTagStarted) {
     seeTag.setSourceRange(this.inlineTagStart, end - this.inlineTagStart + 1);
     switch (this.tagValue) {
       case TAG_LINK_VALUE:
         seeTag.setTagName(TagElement.TAG_LINK);
         break;
       case TAG_LINKPLAIN_VALUE:
         seeTag.setTagName(TagElement.TAG_LINKPLAIN);
         break;
       case TAG_VALUE_VALUE:
         seeTag.setTagName(TagElement.TAG_VALUE);
         break;
     }
     TagElement previousTag = null;
     int previousStart = this.inlineTagStart;
     if (this.astPtr == -1) {
       previousTag = this.ast.newTagElement();
       pushOnAstStack(previousTag, true);
     } else {
       previousTag = (TagElement) this.astStack[this.astPtr];
       previousStart = previousTag.getStartPosition();
     }
     previousTag.fragments().add(seeTag);
     previousTag.setSourceRange(previousStart, end - previousStart + 1);
   } else {
     seeTag.setTagName(TagElement.TAG_SEE);
     seeTag.setSourceRange(this.tagSourceStart, end - this.tagSourceStart + 1);
     pushOnAstStack(seeTag, true);
   }
   return true;
 }
Exemplo n.º 3
0
    protected boolean apply(ASTNode node) {

      // Get default previous end
      ASTNode parent = node.getParent();
      int previousEnd = parent.getStart();

      // Look for sibling node
      ASTNode sibling =
          parent == this.topSiblingParent ? (ASTNode) this.siblings[this.siblingPtr] : null;
      if (sibling != null) {
        // Found one previous sibling, so compute its trailing comments
        // using current node start position
        try {
          previousEnd =
              storeTrailingComments(
                  sibling, node.getStart(), false, this.parentLineRange[this.siblingPtr]);
        } catch (Exception ex) {
          // Give up extended ranges at this level if unexpected
          // exception happens...
        }
      }

      // Stop visit for malformed node (see bug
      // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84049)
      if (node.getType() == ASTNode.AST_ERROR) {
        return false;
      }

      // Compute leading comments for current node
      int[] previousLineRange =
          this.siblingPtr > -1
              ? this.parentLineRange[this.siblingPtr]
              : new int[] {1, DefaultCommentMapper.this.document.getNumberOfLines()};
      try {
        storeLeadingComments(node, previousEnd, previousLineRange);
      } catch (Exception ex) {
        // Give up extended ranges at this level if unexpected exception
        // happens...
      }

      // Store current node as waiting sibling for its parent
      if (this.topSiblingParent != parent) {
        if (this.siblings.length == ++this.siblingPtr) {
          System.arraycopy(
              this.siblings,
              0,
              this.siblings = new ASTNode[this.siblingPtr * 2],
              0,
              this.siblingPtr);
          System.arraycopy(
              this.parentLineRange,
              0,
              this.parentLineRange = new int[this.siblingPtr * 2][],
              0,
              this.siblingPtr);
        }
        if (this.topSiblingParent == null) {
          // node is a CompilationUnit
          this.parentLineRange[this.siblingPtr] = previousLineRange;
        } else {
          int parentStart = parent.getStart();
          int firstLine = getLineNumber(parentStart, previousLineRange);
          int lastLine = getLineNumber(parentStart + parent.getLength() - 1, previousLineRange);
          if (this.parentLineRange[this.siblingPtr] == null) {
            this.parentLineRange[this.siblingPtr] = new int[] {firstLine, lastLine};
          } else {
            int[] lineRange = this.parentLineRange[this.siblingPtr];
            lineRange[0] = firstLine;
            lineRange[1] = lastLine;
          }
        }
        this.topSiblingParent = parent;
      }
      this.siblings[this.siblingPtr] = node;

      // We're always ok to visit sub-levels
      return true;
    }
 private void setRange(IASTNode node, IASTNode from, IASTNode to) {
   final int offset = ((ASTNode) from).getOffset();
   final ASTNode t = (ASTNode) to;
   ((ASTNode) node).setOffsetAndLength(offset, t.getOffset() + t.getLength() - offset);
 }
 private void setStart(IASTNode node, IASTNode start) {
   final ASTNode target = (ASTNode) node;
   final int offset = ((ASTNode) start).getOffset();
   target.setOffsetAndLength(offset, target.getOffset() + target.getLength() - offset);
 }
 private void setEnd(IASTNode node, IASTNode end) {
   final ASTNode target = (ASTNode) node;
   final ASTNode e = (ASTNode) end;
   target.setLength(e.getOffset() + e.getLength() - target.getOffset());
 }