use of org.eclipse.jdt.core.ISourceRange in project che by eclipse.
the class JavaTypeHierarchy method setRange.
private void setRange(Member member, IMember iMember) throws JavaModelException {
ISourceRange nameRange = iMember.getNameRange();
if (iMember.isBinary()) {
nameRange = iMember.getSourceRange();
}
if (nameRange == null) {
return;
}
member.setFileRegion(convertToRegionDTO(iMember.getSourceRange()));
}
use of org.eclipse.jdt.core.ISourceRange in project che by eclipse.
the class StubUtility2 method getNodeToInsertBefore.
/**
* Evaluates the insertion position of a new node.
*
* @param listRewrite The list rewriter to which the new node will be added
* @param sibling The Java element before which the new element should be added.
* @return the AST node of the list to insert before or null to insert as last.
* @throws JavaModelException thrown if accessing the Java element failed
*/
public static ASTNode getNodeToInsertBefore(ListRewrite listRewrite, IJavaElement sibling) throws JavaModelException {
if (sibling instanceof IMember) {
ISourceRange sourceRange = ((IMember) sibling).getSourceRange();
if (sourceRange == null) {
return null;
}
int insertPos = sourceRange.getOffset();
List<? extends ASTNode> members = listRewrite.getOriginalList();
for (int i = 0; i < members.size(); i++) {
ASTNode curr = members.get(i);
if (curr.getStartPosition() >= insertPos) {
return curr;
}
}
}
return null;
}
use of org.eclipse.jdt.core.ISourceRange in project che by eclipse.
the class Util method getUnresolvedJavaElement.
/**
* Returns the IInitializer that contains the given local variable in the given type
*/
public static JavaElement getUnresolvedJavaElement(int localSourceStart, int localSourceEnd, JavaElement type) {
try {
if (!(type instanceof IType))
return null;
IInitializer[] initializers = ((IType) type).getInitializers();
for (int i = 0; i < initializers.length; i++) {
IInitializer initializer = initializers[i];
ISourceRange sourceRange = initializer.getSourceRange();
if (sourceRange != null) {
int initializerStart = sourceRange.getOffset();
int initializerEnd = initializerStart + sourceRange.getLength();
if (initializerStart <= localSourceStart && localSourceEnd <= initializerEnd) {
return (JavaElement) initializer;
}
}
}
return null;
} catch (JavaModelException e) {
return null;
}
}
use of org.eclipse.jdt.core.ISourceRange in project che by eclipse.
the class JavadocContentAccess method internalGetContentReader.
/**
* Gets a reader for an IMember'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 member does not contain a Javadoc comment or if no source is available.
*
* @param member
* The member 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 org.eclipse.jdt.core.JavaModelException
* is thrown when the elements javadoc can not be accessed
* @since 3.4
*/
private static Reader internalGetContentReader(IMember member) throws JavaModelException {
IBuffer buf = member.getOpenable().getBuffer();
if (buf == null) {
// no source attachment found
return null;
}
ISourceRange javadocRange = member.getJavadocRange();
if (javadocRange != null) {
JavaDocCommentReader reader = new JavaDocCommentReader(buf, javadocRange.getOffset(), javadocRange.getOffset() + javadocRange.getLength() - 1);
if (!containsOnlyInheritDoc(reader, javadocRange.getLength())) {
reader.reset();
return reader;
}
}
return null;
}
use of org.eclipse.jdt.core.ISourceRange in project che by eclipse.
the class JavadocContentAccess2 method handleConstantValue.
private boolean handleConstantValue(IField field, boolean link) throws JavaModelException {
String text = null;
ISourceRange nameRange = field.getNameRange();
if (SourceRange.isAvailable(nameRange)) {
CompilationUnit cuNode = ASTProvider.createAST(field.getTypeRoot(), null);
if (cuNode != null) {
ASTNode nameNode = NodeFinder.perform(cuNode, nameRange);
if (nameNode instanceof SimpleName) {
IBinding binding = ((SimpleName) nameNode).resolveBinding();
if (binding instanceof IVariableBinding) {
IVariableBinding variableBinding = (IVariableBinding) binding;
Object constantValue = variableBinding.getConstantValue();
if (constantValue != null) {
if (constantValue instanceof String) {
text = ASTNodes.getEscapedStringLiteral((String) constantValue);
} else {
// Javadoc tool is even worse for chars...
text = constantValue.toString();
}
}
}
}
}
}
if (text == null) {
Object constant = field.getConstant();
if (constant != null) {
text = constant.toString();
}
}
if (text != null) {
text = HTMLPrinter.convertToHTMLContentWithWhitespace(text);
if (link) {
String uri;
try {
uri = JavaElementLinks.createURI(urlPrefix, field);
fBuf.append(JavaElementLinks.createLink(uri, text));
} catch (URISyntaxException e) {
LOG.error(e.getMessage(), e);
return false;
}
} else {
handleText(text);
}
return true;
}
return false;
}
Aggregations