java block comment_Java BlockComment類代碼示例

import org.eclipse.jdt.core.dom.BlockComment; //導入依賴的package包/類

@Override

public void modifyCompilationUnit(CompilationUnit astRoot,

IProgressMonitor monitor) throws JavaModelException, CoreException,

BadLocationException {

final ICompilationUnit adapter = (ICompilationUnit) astRoot

.getJavaElement().getAdapter(IOpenable.class);

modifiedDocument = false;

if (adapter != null) {

document = new Document(adapter.getSource());

List commentList = astRoot.getCommentList();

offset = 0;

for (Comment comment : commentList) {

comment.accept(new ASTVisitor() {

@Override

public boolean visit(BlockComment node) {

int startPosition = node.getStartPosition();

int endPosition = startPosition + node.getLength();

try {

int lineOfOffset = document

.getLineOfOffset(startPosition - offset);

startPosition = document

.getLineOffset(lineOfOffset);

int replaceLength = endPosition - startPosition

+ LINE_DELIMITER_LENGTH - offset;

if (startPosition > -1

&& document

.get()

.substring(

startPosition,

startPosition

+ replaceLength)

.contains(NON_JAVADOC_COMMENT)) {

int replaceStart = startPosition

- LINE_DELIMITER_LENGTH;

document.replace(replaceStart, replaceLength,

EMPTY_STRING);

offset = endPosition - startPosition

+ LINE_DELIMITER_LENGTH;

modifiedDocument = true;

}

} catch (BadLocationException e) {

e.printStackTrace();

}

return super.visit(node);

}

});

}

if (modifiedDocument) {

adapter.getBuffer().setContents(document.get());

adapter.save(monitor, true);

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值