org.eclipse.jdt.core.dom.Comment#getLength ( )源码实例Demo

下面列出了org.eclipse.jdt.core.dom.Comment#getLength ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Gets compilation unit's source
 *
 * @param unit
 *            affected compilation unit
 * @param comment
 *            comment to be replaced; set null if comment is not present
 * @return new compilation unit's source
 */
private String getNewUnitSource(final ICompilationUnit unit, final Comment comment) {
	String source = null;
	try {
		source = unit.getSource();
		if (comment != null) {
			final int endOfComment = comment.getLength() + comment.getStartPosition();
			source = source.replace(source.substring(0, endOfComment), getCopyrightText());
		}
	} catch (final JavaModelException e) {
		ConsoleUtils.printError(e.getMessage());
	}
	return source;
}
 
源代码2 项目: xtext-xtend   文件: JavaASTFlattener.java
private String commentContent(final Comment comment) {
  int _startPosition = comment.getStartPosition();
  int _startPosition_1 = comment.getStartPosition();
  int _length = comment.getLength();
  int _plus = (_startPosition_1 + _length);
  return this.javaSources.substring(_startPosition, _plus);
}
 
源代码3 项目: compiler   文件: UglyMathCommentsExtractor.java
private final CommentItem extractCommentItem(final int index) {
    if (commentsVisited[index]) {
        return null;
    } else {
        final Comment comment = (Comment) comments.get(index);
        if (comment.isDocComment()) {
            /* Interpret DocComment as Line or Block */
            comment.delete();
        }
        final int start = comment.getStartPosition();
        final int end = start + comment.getLength();
        final String value = this.src.substring(start, end);
        return new CommentItem(comment, value);
    }
}
 
源代码4 项目: compiler   文件: UglyMathCommentsExtractor.java
private final int getNodeFirstLeadingCommentIndex(final ASTNode node) {
    if (node instanceof PackageDeclaration) {
        if (commentsVisited.length > 0) {
            final Comment comment = (Comment) comments.get(0);
            if (comment.getStartPosition() + comment.getLength() <= ((PackageDeclaration) node).getName()
                    .getStartPosition()) {
                return 0;
            }
        }
        return -1;
    } else {
        return cu.firstLeadingCommentIndex(node);
    }
}
 
源代码5 项目: eip-designer   文件: CamelJavaFileParser.java
/** Extract comment content from source. */
private String getCommentContent(Comment comment) {
   int start = comment.getStartPosition();
   int end = start + comment.getLength();
   String content = routeSource.substring(start, end);
   if (content.startsWith("//")) {
      content = content.substring(2).trim();
   }
   return content;
}
 
源代码6 项目: JDeodorant   文件: ASTReader.java
private List<CommentObject> processComments(IFile iFile, IDocument iDocument,
		AbstractTypeDeclaration typeDeclaration, List<Comment> comments) {
	List<CommentObject> commentList = new ArrayList<CommentObject>();
	int typeDeclarationStartPosition = typeDeclaration.getStartPosition();
	int typeDeclarationEndPosition = typeDeclarationStartPosition + typeDeclaration.getLength();
	for(Comment comment : comments) {
		int commentStartPosition = comment.getStartPosition();
		int commentEndPosition = commentStartPosition + comment.getLength();
		int commentStartLine = 0;
		int commentEndLine = 0;
		String text = null;
		try {
			commentStartLine = iDocument.getLineOfOffset(commentStartPosition);
			commentEndLine = iDocument.getLineOfOffset(commentEndPosition);
			text = iDocument.get(commentStartPosition, comment.getLength());
		} catch (BadLocationException e) {
			e.printStackTrace();
		}
		CommentType type = null;
		if(comment.isLineComment()) {
			type = CommentType.LINE;
		}
		else if(comment.isBlockComment()) {
			type = CommentType.BLOCK;
		}
		else if(comment.isDocComment()) {
			type = CommentType.JAVADOC;
		}
		CommentObject commentObject = new CommentObject(text, type, commentStartLine, commentEndLine);
		commentObject.setComment(comment);
		String fileExtension = iFile.getFileExtension() != null ? "." + iFile.getFileExtension() : "";
		if(typeDeclarationStartPosition <= commentStartPosition && typeDeclarationEndPosition >= commentEndPosition) {
			commentList.add(commentObject);
		}
		else if(iFile.getName().equals(typeDeclaration.getName().getIdentifier() + fileExtension)) {
			commentList.add(commentObject);
		}
	}
	return commentList;
}