Java Code Examples for org.eclipse.jdt.core.dom.Javadoc#getStartPosition()

The following examples show how to use org.eclipse.jdt.core.dom.Javadoc#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: JavadocContentAccess.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Gets a reader for an package fragment's Javadoc comment content from the source attachment.
 * The content does contain only the text from the comment without the Javadoc leading star characters.
 * Returns <code>null</code> if the package fragment does not contain a Javadoc comment or if no source is available.
 * @param fragment The package fragment to get the Javadoc of.
 * @return Returns a reader for the Javadoc comment content or <code>null</code> if the member
 * does not contain a Javadoc comment or if no source is available
 * @throws JavaModelException is thrown when the package fragment's javadoc can not be accessed
 * @since 3.4
 */
private static Reader internalGetContentReader(IPackageFragment fragment) throws JavaModelException {
	IPackageFragmentRoot root= (IPackageFragmentRoot) fragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);

	//1==> Handle the case when the documentation is present in package-info.java or package-info.class file
	boolean isBinary= root.getKind() == IPackageFragmentRoot.K_BINARY;
	ITypeRoot packageInfo;
	if (isBinary) {
		packageInfo= fragment.getClassFile(PACKAGE_INFO_CLASS);
	} else {
		packageInfo= fragment.getCompilationUnit(PACKAGE_INFO_JAVA);
	}
	if (packageInfo != null && packageInfo.exists()) {
		String source = packageInfo.getSource();
		//the source can be null for some of the class files
		if (source != null) {
			Javadoc javadocNode = getPackageJavadocNode(fragment, source);
			if (javadocNode != null) {
				int start = javadocNode.getStartPosition();
				int length = javadocNode.getLength();
				return new JavaDocCommentReader(source, start, start + length - 1);
			}
		}
	}
	return null;
}
 
Example 2
Source File: SimilarElementsRequestor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static ICompilationUnit createPreparedCU(ICompilationUnit cu, Javadoc comment, int wordStart) throws JavaModelException {
	int startpos= comment.getStartPosition();
	boolean isTopLevel= comment.getParent().getParent() instanceof CompilationUnit;
	char[] content= cu.getBuffer().getCharacters().clone();
	if (isTopLevel && (wordStart + 6 < content.length)) {
		content[startpos++]= 'i'; content[startpos++]= 'm'; content[startpos++]= 'p';
		content[startpos++]= 'o'; content[startpos++]= 'r'; content[startpos++]= 't';
	}
	if (wordStart < content.length) {
		for (int i= startpos; i < wordStart; i++) {
			content[i]= ' ';
		}
	}

	/*
	 * Explicitly create a new non-shared working copy.
	 */
	ICompilationUnit newCU= cu.getWorkingCopy(null);
	newCU.getBuffer().setContents(content);
	return newCU;
}
 
Example 3
Source File: SimilarElementsRequestor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static ICompilationUnit createPreparedCU(ICompilationUnit cu, Javadoc comment, int wordStart) throws JavaModelException {
	int startpos= comment.getStartPosition();
	boolean isTopLevel= comment.getParent().getParent() instanceof CompilationUnit;
	char[] content= cu.getBuffer().getCharacters().clone();
	if (isTopLevel && (wordStart + 6 < content.length)) {
		content[startpos++]= 'i'; content[startpos++]= 'm'; content[startpos++]= 'p';
		content[startpos++]= 'o'; content[startpos++]= 'r'; content[startpos++]= 't';
	}
	if (wordStart < content.length) {
		for (int i= startpos; i < wordStart; i++) {
			content[i]= ' ';
		}
	}

	/*
	 * Explicitly create a new non-shared working copy.
	 */
	ICompilationUnit newCU= cu.getWorkingCopy(null);
	newCU.getBuffer().setContents(content);
	return newCU;
}