Java Code Examples for org.eclipse.jdt.core.dom.Comment#getStartPosition()
The following examples show how to use
org.eclipse.jdt.core.dom.Comment#getStartPosition() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CopyrightManager.java From hybris-commerce-eclipse-plugin with Apache License 2.0 | 5 votes |
/** * 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; }
Example 2
Source File: JavaASTFlattener.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
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); }
Example 3
Source File: UglyMathCommentsExtractor.java From compiler with Apache License 2.0 | 5 votes |
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); } }
Example 4
Source File: UglyMathCommentsExtractor.java From compiler with Apache License 2.0 | 5 votes |
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); } }
Example 5
Source File: CamelJavaFileParser.java From eip-designer with Apache License 2.0 | 5 votes |
/** 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; }
Example 6
Source File: ASTReader.java From JDeodorant with MIT License | 5 votes |
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; }