| /******************************************************************************* |
| * Copyright (c) 2004-2008 Istvan Rath and Daniel Varro |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Istvan Rath - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.viatra2.errors.reporting.internal;
|
|
|
| import org.eclipse.core.resources.IMarker; |
| import org.eclipse.core.resources.IResource; |
| import org.eclipse.core.runtime.Assert; |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.viatra2.errors.info.ErrorInformation; |
| import org.eclipse.viatra2.errors.info.Location; |
| import org.eclipse.viatra2.errors.reporting.IErrorReporter; |
|
|
| public class MarkerManager implements IErrorReporter {
|
|
|
| protected IResource resource;
|
|
|
|
|
| public MarkerManager(IResource resource) {
|
| this.resource = resource;
|
| }
|
|
|
| /* (non-Javadoc) |
| * @see org.eclipse.viatra2.editor.text.light.vtcl.IVTCLErrorReporter#reportError(org.eclipse.viatra2.errors.info.ErrorInformation) |
| */ |
| public void reportError(ErrorInformation info)
|
| {
|
| try
|
| {
|
| Location location = info.getLocation(); |
| int offset = location.getBeginOffset(); |
| int endOffset = location.getEndOffset(); |
| Assert.isTrue(endOffset >= 0 && offset >= 0, "Error location must be set");
|
| int length = endOffset - offset + 1;
|
| if (length <= 0) length = 1;
|
| int severity;
|
| switch (info.getErrorSeverity()) {
|
| case INFO:
|
| severity = IMarker.SEVERITY_INFO;
|
| break;
|
| case WARNING:
|
| severity = IMarker.SEVERITY_WARNING;
|
| break;
|
| case ERROR:
|
| severity = IMarker.SEVERITY_ERROR;
|
| break;
|
|
|
| default:
|
| severity = IMarker.SEVERITY_ERROR;
|
| break;
|
| }
|
| createErrorMarker(info.getMessage(), info.getMarkerId(), severity, offset,length, location.getBeginLine());
|
| }
|
| catch (Exception e)
|
| {
|
| System.out.println("Editor::reportError exception occured!!!!");
|
| }
|
| }
|
|
|
| boolean createErrorMarker(String message, String markerId, int severity, int offset, int length, int line)
|
| {
|
|
|
| if (resource != null) {
|
| try
|
| {
|
| IMarker marker = resource.createMarker(markerId);
|
| marker.setAttribute(IMarker.SEVERITY, severity);
|
| marker.setAttribute(IMarker.MESSAGE, message);
|
| marker.setAttribute(IMarker.LINE_NUMBER, line);
|
| if (offset != 0)
|
| {
|
| marker.setAttribute(IMarker.CHAR_START,offset);
|
| marker.setAttribute(IMarker.CHAR_END,offset+length);
|
| }
|
| return true;
|
| }
|
| catch (Exception exc)
|
| {
|
| //System.err.println("exc");
|
| exc.printStackTrace(System.err);
|
| }
|
| }
|
| return false;
|
| }
|
|
|
| /* (non-Javadoc) |
| * @see org.eclipse.viatra2.editor.text.light.vtcl.IVTCLErrorReporter#deleteMarkers(org.eclipse.core.resources.IResource, java.lang.String) |
| */ |
| public void deleteMarkers(String type)
|
| {
|
| if (resource == null)
|
| return;
|
| try
|
| {
|
| resource.deleteMarkers(type, true, IResource.DEPTH_INFINITE);
|
| }
|
| catch (CoreException e)
|
| {
|
| }
|
| }
|
|
|
| }
|