本文整理汇总了Java中org.eclipse.ui.texteditor.MarkerUtilities.getLineNumber方法的典型用法代码示例。如果您正苦于以下问题:Java MarkerUtilities.getLineNumber方法的具体用法?Java MarkerUtilities.getLineNumber怎么用?Java MarkerUtilities.getLineNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.ui.texteditor.MarkerUtilities
的用法示例。
在下文中一共展示了MarkerUtilities.getLineNumber方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertIssues
import org.eclipse.ui.texteditor.MarkerUtilities; //导入方法依赖的package包/类
/**
* Asserts that the given resource (usually an N4JS file) contains issues with the given messages and no other
* issues. Each message given should be prefixed with the line numer where the issues occurs, e.g.:
*
* <pre>
* line 5: Couldn't resolve reference to identifiable element 'unknown'.
* </pre>
*
* Column information is not provided, so this method is not intended for several issues within a single line.
*/
public static void assertIssues(final IResource resource, String... expectedMessages) throws CoreException {
final IMarker[] markers = resource.findMarkers(MarkerTypes.ANY_VALIDATION, true, IResource.DEPTH_INFINITE);
final String[] actualMessages = new String[markers.length];
for (int i = 0; i < markers.length; i++) {
final IMarker m = markers[i];
actualMessages[i] = "line " + MarkerUtilities.getLineNumber(m) + ": " + m.getAttribute(IMarker.MESSAGE);
}
if (!Objects.equals(
new HashSet<>(Arrays.asList(actualMessages)),
new HashSet<>(Arrays.asList(expectedMessages)))) {
final Joiner joiner = Joiner.on("\n ");
final String msg = "expected these issues:\n"
+ " " + joiner.join(expectedMessages) + "\n"
+ "but got these:\n"
+ " " + joiner.join(actualMessages);
System.out.println("*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*");
System.out.println(msg);
System.out.println("*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*");
Assert.fail(msg);
}
}
示例2: getMarkerPosition
import org.eclipse.ui.texteditor.MarkerUtilities; //导入方法依赖的package包/类
/**
* @return the position for a marker.
*/
public static Position getMarkerPosition(IDocument document, IMarker marker, IAnnotationModel model) {
if (model instanceof AbstractMarkerAnnotationModel) {
Position ret = ((AbstractMarkerAnnotationModel) model).getMarkerPosition(marker);
if (ret != null) {
return ret;
}
}
int start = MarkerUtilities.getCharStart(marker);
int end = MarkerUtilities.getCharEnd(marker);
if (start > end) {
end = start + end;
start = end - start;
end = end - start;
}
if (start == -1 && end == -1) {
// marker line number is 1-based
int line = MarkerUtilities.getLineNumber(marker);
if (line > 0 && document != null) {
try {
start = document.getLineOffset(line - 1);
end = start;
} catch (BadLocationException x) {
}
}
}
if (start > -1 && end > -1) {
return new Position(start, end - start);
}
return null;
}
示例3: getMarkerPosition
import org.eclipse.ui.texteditor.MarkerUtilities; //导入方法依赖的package包/类
protected int getMarkerPosition(IMarker marker) throws BadLocationException {
int line = MarkerUtilities.getLineNumber(marker);
if (line > 0) {
return document.getLineOffset(line - 1);
}
throw new BadLocationException();
}
示例4: validateTrimTrailingWhiteSpace
import org.eclipse.ui.texteditor.MarkerUtilities; //导入方法依赖的package包/类
/**
* Validate 'trim_trailing_whitespace' of the lines where region changed if
* needed and update the given set of marker.
*
* @param partition
* the region which changed
* @param remainingMarkers
* set of markers to update.
* @throws BadLocationException
*/
private void validateTrimTrailingWhiteSpace(IDocument document, IRegion partition, Set<IMarker> remainingMarkers)
throws BadLocationException, CoreException {
boolean trimTrailingWhiteSpace = preferenceStore.getBoolean(EDITOR_TRIM_TRAILING_WHITESPACE);
if (!trimTrailingWhiteSpace) {
return;
}
int startLine = document.getLineOfOffset(partition.getOffset());
int endLine = document.getLineOfOffset(partition.getOffset() + partition.getLength());
IRegion region = null;
for (int i = startLine; i < endLine + 1; i++) {
region = document.getLineInformation(i);
if (region.getLength() == 0)
continue;
int lineStart = region.getOffset();
int lineExclusiveEnd = lineStart + region.getLength();
int j = lineExclusiveEnd - 1;
while (j >= lineStart && Character.isWhitespace(document.getChar(j)))
--j;
++j;
if (j < lineExclusiveEnd) {
addOrUpdateMarker(j, lineExclusiveEnd, trimTrailingWhitespaceType, document, remainingMarkers);
}
}
if (region != null) {
for (IMarker marker : new HashSet<>(remainingMarkers)) {
if (MarkerUtils.getOptionType(marker) == trimTrailingWhitespaceType) {
int line = MarkerUtilities.getLineNumber(marker) + 1;
if (line < startLine || line > endLine) {
remainingMarkers.remove(marker);
}
}
}
}
}
示例5: selectReveal
import org.eclipse.ui.texteditor.MarkerUtilities; //导入方法依赖的package包/类
public boolean selectReveal( Object marker )
{
int start = MarkerUtilities.getCharStart( (IMarker) marker );
int end = MarkerUtilities.getCharEnd( (IMarker) marker );
boolean selectLine = start < 0 || end < 0;
// look up the current range of the marker when the document has been
// edited
IAnnotationModel model = reportXMLEditor.getDocumentProvider( )
.getAnnotationModel( reportXMLEditor.getEditorInput( ) );
if ( model instanceof AbstractMarkerAnnotationModel )
{
AbstractMarkerAnnotationModel markerModel = (AbstractMarkerAnnotationModel) model;
Position pos = markerModel.getMarkerPosition( (IMarker) marker );
if ( pos != null )
{
if ( !pos.isDeleted( ) )
{
// use position instead of marker values
start = pos.getOffset( );
end = pos.getOffset( ) + pos.getLength( );
}
else
{
return false;
}
}
}
IDocument document = reportXMLEditor.getDocumentProvider( )
.getDocument( reportXMLEditor.getEditorInput( ) );
if ( selectLine )
{
int line;
try
{
if ( start >= 0 )
line = document.getLineOfOffset( start );
else
{
line = MarkerUtilities.getLineNumber( (IMarker) marker );
// Marker line numbers are 1-based
if ( line >= 1 )
{
line--;
}
start = document.getLineOffset( line );
}
end = start + document.getLineLength( line ) - 1;
}
catch ( BadLocationException e )
{
return false;
}
}
int length = document.getLength( );
if ( end - 1 < length && start < length )
reportXMLEditor.selectAndReveal( start, end - start );
return true;
}