本文整理汇总了Java中org.eclipse.jdt.core.ISourceReference.getSource方法的典型用法代码示例。如果您正苦于以下问题:Java ISourceReference.getSource方法的具体用法?Java ISourceReference.getSource怎么用?Java ISourceReference.getSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.ISourceReference
的用法示例。
在下文中一共展示了ISourceReference.getSource方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSourceOfDeclararationNode
import org.eclipse.jdt.core.ISourceReference; //导入方法依赖的package包/类
private static String getSourceOfDeclararationNode(IJavaElement elem, ICompilationUnit cu) throws JavaModelException, CoreException {
Assert.isTrue(elem.getElementType() != IJavaElement.IMPORT_CONTAINER);
if (elem instanceof ISourceReference) {
ISourceReference reference= (ISourceReference) elem;
String source= reference.getSource();
if (source != null)
return Strings.trimIndentation(source, cu.getJavaProject(), false);
}
return ""; //$NON-NLS-1$
}
示例2: getExtendedSource
import org.eclipse.jdt.core.ISourceReference; //导入方法依赖的package包/类
private String getExtendedSource(ISourceReference ref) throws JavaModelException {
// get parent
if (ref instanceof IJavaElement) {
IJavaElement parent= ((IJavaElement) ref).getParent();
if (parent instanceof ISourceReference) {
ISourceReference sr= (ISourceReference) parent;
String parentContent= sr.getSource();
if (parentContent != null) {
ISourceRange parentRange= sr.getSourceRange();
ISourceRange childRange= ref.getSourceRange();
int start= childRange.getOffset() - parentRange.getOffset();
int end= start + childRange.getLength();
// search backwards for beginning of line
while (start > 0) {
char c= parentContent.charAt(start-1);
if (c == '\n' || c == '\r')
break;
start--;
}
return parentContent.substring(start, end);
}
}
}
return ref.getSource();
}
示例3: computeInput
import org.eclipse.jdt.core.ISourceReference; //导入方法依赖的package包/类
@Override
protected Object computeInput(Object input) {
if (fViewer == null || !(input instanceof ISourceReference))
return null;
ISourceReference sourceRef= (ISourceReference)input;
if (fLastOpenedElement != null && input instanceof IJavaElement && ((IJavaElement)input).getHandleIdentifier().equals(fLastOpenedElement.getHandleIdentifier())) {
fLastOpenedElement= null;
return null;
} else {
fLastOpenedElement= null;
}
String source;
try {
source= sourceRef.getSource();
} catch (JavaModelException ex) {
return ""; //$NON-NLS-1$
}
if (source == null)
return ""; //$NON-NLS-1$
source= removeLeadingComments(source);
String delim= StubUtility.getLineDelimiterUsed((IJavaElement) input);
String[] sourceLines= Strings.convertIntoLines(source);
if (sourceLines == null || sourceLines.length == 0)
return ""; //$NON-NLS-1$
String firstLine= sourceLines[0];
boolean firstCharNotWhitespace= firstLine != null && firstLine.length() > 0 && !Character.isWhitespace(firstLine.charAt(0));
if (firstCharNotWhitespace)
sourceLines[0]= ""; //$NON-NLS-1$
IJavaProject project;
if (input instanceof IJavaElement)
project= ((IJavaElement) input).getJavaProject();
else
project= null;
Strings.trimIndentation(sourceLines, project);
if (firstCharNotWhitespace)
sourceLines[0]= firstLine;
return Strings.concatenate(sourceLines, delim);
}