Java Code Examples for org.eclipse.ui.texteditor.MarkerUtilities#getLineNumber()

The following examples show how to use org.eclipse.ui.texteditor.MarkerUtilities#getLineNumber() . 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: ProjectTestsUtils.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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.
 *
 * @param msg
 *            human-readable, informative message prepended to the standard message in case of assertion failure.
 * @param resource
 *            resource to be validated.
 * @param expectedMessages
 *            expected issues messages to check or empty array to assert no issues.
 * @throws CoreException
 *             in case of mishap.
 */
public static void assertIssues(String msg, final IResource resource, String... expectedMessages)
		throws CoreException {
	waitForAutoBuild();

	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);
	}
	Set<String> actual = new TreeSet<>(Arrays.asList(actualMessages));
	Set<String> expected = new TreeSet<>(Arrays.asList(expectedMessages));

	if (!actual.equals(expected)) {
		StringBuilder message = new StringBuilder(msg != null ? msg : "");
		message.append("\nexpected:\n");
		message.append(expectedMessages.length > 0 ? Joiner.on('\n').join(expectedMessages) : "<none>");
		message.append("\nactual:\n");
		message.append(actualMessages.length > 0 ? Joiner.on('\n').join(actualMessages) : "<none>");
		Assert.fail(message.toString());
	}
}
 
Example 2
Source File: XBookmarksDialogHandler.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
protected XBookmarksDialog.Model.Row getDescription (IMarker marker) {
    if (marker!= null && marker.exists()) {
        int markerNumber = marker.getAttribute(XBookmarksPlugin.BOOKMARK_NUMBER_ATTR, -1);
        if (markerNumber >=0 && markerNumber <= 9) {
            int    line       = MarkerUtilities.getLineNumber(marker);
            String resName    = marker.getResource().getName();
            
            String markerName = MarkerUtilities.getMessage(marker);
            String prefix     = mkBookmarkNamePrefix(markerNumber);
            if (markerName.startsWith(prefix)) {
                markerName = markerName.substring(prefix.length());
                if (markerName.startsWith(": ")) { //$NON-NLS-1$
                    markerName = markerName.substring(2);
                }
                markerName = markerName.trim();
                if (markerName.isEmpty()) {
                    markerName = prefix;
                }
            }
            return new XBookmarksDialog.Model.Row(new String[]{ "" + markerNumber + "."  //$NON-NLS-1$ //$NON-NLS-2$
                                                              , resName + ":" + line     //$NON-NLS-1$ 
                                                              , markerName}).setData(markerNumber);  
        }
    }
    return null;
}
 
Example 3
Source File: IResourcesSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static void assertNoErrorsInWorkspace() throws CoreException {
	IMarker[] findMarkers = ResourcesPlugin.getWorkspace().getRoot().findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
	String msg = "";
	for (IMarker iMarker : findMarkers) {
		if (MarkerUtilities.getSeverity(iMarker) == IMarker.SEVERITY_ERROR)
			msg += "\n - "+iMarker.getResource().getName()+":"+MarkerUtilities.getLineNumber(iMarker)+" - "+MarkerUtilities.getMessage(iMarker) + "("+MarkerUtilities.getMarkerType(iMarker)+")";
	}
	if (msg.length()>0)
		Assert.fail("Workspace contained errors: "+msg);
}
 
Example 4
Source File: IResourcesSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static void assertNoErrorsInWorkspace() throws CoreException {
	IMarker[] findMarkers = root().findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
	String msg = "";
	for (IMarker iMarker : findMarkers) {
		if (MarkerUtilities.getSeverity(iMarker) == IMarker.SEVERITY_ERROR)
			msg += "\n - "+iMarker.getResource().getName()+":"+MarkerUtilities.getLineNumber(iMarker)+" - "+MarkerUtilities.getMessage(iMarker) + "("+MarkerUtilities.getMarkerType(iMarker)+")";
	}
	if (msg.length()>0)
		Assert.fail("Workspace contained errors: "+msg);
}
 
Example 5
Source File: PyMarkerUIUtils.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @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;
}
 
Example 6
Source File: ExternalBreakpointWatcher.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
protected int getMarkerPosition(IMarker marker) throws BadLocationException {
	int line = MarkerUtilities.getLineNumber(marker);
	if (line > 0) {
		return document.getLineOffset(line - 1);
	}
	throw new BadLocationException();
}
 
Example 7
Source File: ReportXMLSourceEditorFormPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
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;
}