下面列出了org.eclipse.ui.texteditor.MarkerUtilities#getCharStart ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Instantiates a new MarkerIdentity.
*
* @param annotation
* the Annotation
* @return MarkerIdentity - this
*/
public MarkerIdentity create(final Annotation annotation) {
MarkerIdentity result = provider.get();
if (annotation instanceof XtextAnnotation) {
Issue issue = ((XtextAnnotation) annotation).getIssue();
result.start = issue.getOffset();
result.end = result.start == ATTRIBUTE_MISSING ? ATTRIBUTE_MISSING : result.start + issue.getLength();
result.message = issue.getMessage();
} else if (annotation instanceof org.eclipse.ui.texteditor.MarkerAnnotation) {
result.start = MarkerUtilities.getCharStart(((org.eclipse.ui.texteditor.MarkerAnnotation) annotation).getMarker());
result.end = MarkerUtilities.getCharEnd(((org.eclipse.ui.texteditor.MarkerAnnotation) annotation).getMarker());
result.message = MarkerUtilities.getMessage(((org.eclipse.ui.texteditor.MarkerAnnotation) annotation).getMarker());
} else {
result.end = ATTRIBUTE_MISSING;
result.start = ATTRIBUTE_MISSING;
result.message = null; // NOPMD
}
result.problemCode = issueUtil.getCode(annotation);
result.problemURI = issueUtil.getUriToProblem(annotation);
result.resourceURI = result.problemURI == null ? null : result.problemURI.trimFragment();
return result;
}
/**
* Instantiates a new MarkerIdentity.
*
* @param marker
* the marker
* @return MarkerIdentity - this
*/
public MarkerIdentity create(final IMarker marker) {
MarkerIdentity result = provider.get();
result.start = MarkerUtilities.getCharStart(marker);
result.end = MarkerUtilities.getCharEnd(marker);
result.problemCode = issueUtil.getCode(marker);
result.problemURI = issueUtil.getUriToProblem(marker);
result.resourceURI = result.problemURI == null ? null : result.problemURI.trimFragment();
result.message = MarkerUtilities.getMessage(marker);
return result;
}
/**
* @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;
}
@Override
public void run(IMarker[] markers, IProgressMonitor monitor) {
if (isBasedOnN4Modification()) {
// applying an N4Modification to one or more markers
try {
// collect all changes
final List<IChange> changes = new ArrayList<>();
for (IMarker currMarker : markers) {
if (!isMarkerStillValid(currMarker))
continue;
final Issue currIssue = issueUtil.createIssue(currMarker);
final IModificationContext currContext = modificationContextFactory
.createModificationContext(currIssue);
final int offset = MarkerUtilities.getCharStart(currMarker);
final int length = MarkerUtilities.getCharEnd(currMarker) - offset;
final EObject element = getElementForMarker(currContext, currMarker);
Collection<? extends IChange> changeSet = getN4Modification().computeChanges(
currContext, currMarker, offset, length, element);
changes.addAll(changeSet);
}
// perform changes
changeManager.applyAll(changes);
} catch (Exception e) {
throw new WrappedException(
"exception while applying resolution for quick fix '" + resolution.getLabel() + "'", e);
}
} else {
// support for applying modifications other than N4Modification
// applying a single quick fix to multiple markers only supported for N4Modifications (see
// #findOtherMarkers(IMarker[]) below), so we assert markers.length==1 here
if (markers.length != 1)
throw new IllegalStateException();
// default Xtext implementation
resolution.apply();
}
}
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;
}