Skip to content
Snippets Groups Projects
Commit cdd098c9 authored by Luca Cristoforetti's avatar Luca Cristoforetti
Browse files

Improve marker generation and handling

parent 9767b0c5
No related branches found
No related tags found
No related merge requests found
......@@ -9,19 +9,15 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.polarsys.chess.contracts.profile.chesscontract.util.EntityUtil;
public abstract class Checker {
private static final Logger logger = Logger.getLogger(Checker.class);
private static String pluginID = "org.polarsys.chess.checkers";
// private static String pluginID = "org.polarsys.chess.checkers";
public final String unifiedName;
protected final Set<String> checkerTags;
......@@ -49,10 +45,6 @@ public abstract class Checker {
public void asyncCheck(boolean isFirstChecker) throws Exception {
Display defaultDisplay = Display.getDefault();
Shell activeShell = defaultDisplay.getActiveShell();
CheckerManager checkerManager = org.polarsys.chess.checkers.Activator.getCheckerManager();
org.eclipse.uml2.uml.Package pack = EntityUtil.getInstance().getCurrentSystemView();
......@@ -73,8 +65,8 @@ public abstract class Checker {
errors = new ArrayList<Exception>();
List<CheckerMessage> messages = check(monitor);
if (messages != null) {
checkerManager.deleteMarkers(iFile, unifiedName);
// checkerManager.deleteMarkers(iFile, unifiedName);
checkerManager.deleteProjectMarkers(iFile.getProject(), unifiedName);
checkerManager.addMessages(unifiedName, messages);
}
} catch (Exception e) {
......@@ -93,9 +85,29 @@ public abstract class Checker {
job.setUser(isFirstChecker);
job.schedule();
}
// /**
// * Recursively returns all the files in the given container
// * @param container the IContainer
// * @return
// */
// private List<IFile> getProjectFiles(IContainer container) {
// final List<IFile> files = new ArrayList<IFile>();
// try {
// for (IResource member : container.members()) {
// if (member instanceof IContainer) {
// files.addAll(getProjectFiles((IContainer) member));
// } else if (member instanceof IFile) {
// files.add((IFile) member);
// }
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// return files;
// }
/*
* private void syncWithUI(Shell shell) { Display.getDefault().asyncExec(new
* Runnable() { public void run() { MessageDialog.openInformation(shell,
......
......@@ -9,6 +9,7 @@ import java.util.Set;
import org.apache.log4j.Logger;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.ecore.EObject;
......@@ -118,14 +119,14 @@ public class CheckerManager {
} else if (msn.object != null && msn.object instanceof INode) {
try {
final INode node = (INode) msn.object;
if (msn.severity == 0) {
ReportProblemsUtil.reportInfo(msn.file, msn.message, node.getStartLine(),
if (msn.severity == IMarker.SEVERITY_INFO) {
ReportProblemsUtil.reportInfo(msn.file, CHECKER_NAME, msn.checkerName, msn.message, node.getStartLine(),
node.getOffset(), node.getEndOffset());
} else if (msn.severity == 1) {
ReportProblemsUtil.reportWarning(msn.file, msn.message, node.getStartLine(),
} else if (msn.severity == IMarker.SEVERITY_WARNING) {
ReportProblemsUtil.reportWarning(msn.file, CHECKER_NAME, msn.checkerName, msn.message, node.getStartLine(),
node.getOffset(), node.getEndOffset());
} else if (msn.severity == 2) {
ReportProblemsUtil.reportError(msn.file, msn.message, node.getStartLine(),
} else if (msn.severity == IMarker.SEVERITY_ERROR) {
ReportProblemsUtil.reportError(msn.file, CHECKER_NAME, msn.checkerName, msn.message, node.getStartLine(),
node.getOffset(), node.getEndOffset());
}
} catch (NullPointerException | CoreException e) {
......@@ -155,7 +156,21 @@ public class CheckerManager {
marker.delete();
}
}
}
/**
* Deletes all the matching markers inside the given project.
* @param project the active project
* @param checkerName the name of the creating checker
* @throws CoreException
*/
void deleteProjectMarkers(IProject project, String checkerName) throws CoreException {
IMarker[] markers = project.findMarkers(null, false, IResource.DEPTH_INFINITE);
for (IMarker marker : markers) {
if (marker != null && marker.exists() && marker.getAttribute(CHECKER_NAME, "").equals(checkerName)) {
marker.delete();
}
}
}
private ModelExplorerPageBookView getModelExplorerPageBookView() {
......
......@@ -6,6 +6,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.log4j.Logger;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
......@@ -154,7 +155,7 @@ public class NameDistance extends Checker {
if (distance == 0) {
final String msg = equalsMsg(first, second);
messages.add(createMessage(msg, 2, first, unifiedName));
messages.add(createMessage(msg, IMarker.SEVERITY_ERROR, first, unifiedName));
}
if (distance <= threshold) {
similarNames.add(second.getName());
......@@ -164,7 +165,7 @@ public class NameDistance extends Checker {
// If some similarities are found, store the entry in the warnings
if (similarNames.size() > 0) {
final String msg = similarMsg(first, similarNames);
messages.add(createMessage(msg, 1, first, unifiedName));
messages.add(createMessage(msg, IMarker.SEVERITY_WARNING, first, unifiedName));
}
}
return messages;
......
......@@ -7,6 +7,7 @@ import java.util.List;
import java.util.Set;
import org.apache.log4j.Logger;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
......@@ -128,7 +129,7 @@ public class StateStatus extends Checker {
}
if (dead) {
final String msg = deadMsg(state, block);
errors.add(createMessage(msg, 2, state, unifiedName));
errors.add(createMessage(msg, IMarker.SEVERITY_ERROR, state, unifiedName));
deadStates.add(state.getName());
}
......@@ -179,7 +180,7 @@ public class StateStatus extends Checker {
}
if (unreachable) {
final String msg = unreachableMsg(state, block);
errors.add(createMessage(msg, 2, state, unifiedName));
errors.add(createMessage(msg, IMarker.SEVERITY_ERROR, state, unifiedName));
unreachableStates.add(state.getName());
}
}
......@@ -254,13 +255,13 @@ public class StateStatus extends Checker {
if ((dead && stateCounter > 2)) {
final String msg = deadMsg(state, block);
errors.add(createMessage(msg, 2, state, unifiedName));
errors.add(createMessage(msg, IMarker.SEVERITY_ERROR, state, unifiedName));
deadStates.add(state.getName());
}
if ((unreachable)) {
final String msg = unreachableMsg(state, block);
errors.add(createMessage(msg, 2, state, unifiedName));
errors.add(createMessage(msg, IMarker.SEVERITY_ERROR, state, unifiedName));
unreachableStates.add(state.getName());
}
}
......
......@@ -36,6 +36,8 @@ public class ReportProblemsUtil {
/**
* Reports a warning in the Problems tab.
* @param resource the resource
* @param ownerField the name of the field to store the owner
* @param ownerName the name of the creator of this report
* @param msg the message to display
* @param lineNumber the line to select (or 0)
* @param charStart the start of selection (or 0)
......@@ -44,15 +46,17 @@ public class ReportProblemsUtil {
* @throws CoreException
* @throws NullPointerException
*/
public static IMarker reportWarning(IResource resource, String msg, int lineNumber,
public static IMarker reportWarning(IResource resource, String ownerField, String ownerName, String msg, int lineNumber,
int charStart, int charEnd) throws CoreException, NullPointerException {
return reportMessage(resource, msg, lineNumber, charStart, charEnd,
return reportMessage(resource, ownerField, ownerName, msg, lineNumber, charStart, charEnd,
IMarker.PROBLEM, IMarker.SEVERITY_WARNING);
}
/**
* Reports an error in the Problems tab.
* @param resource the resource
* @param ownerField the name of the field to store the owner
* @param ownerName the name of the creator of this report
* @param msg the message to display
* @param lineNumber the line to select (or 0)
* @param charStart the start of selection (or 0)
......@@ -61,15 +65,17 @@ public class ReportProblemsUtil {
* @throws CoreException
* @throws NullPointerException
*/
public static IMarker reportError(IResource resource, String msg, int lineNumber,
public static IMarker reportError(IResource resource, String ownerField, String ownerName, String msg, int lineNumber,
int charStart, int charEnd) throws CoreException, NullPointerException {
return reportMessage(resource, msg, lineNumber, charStart, charEnd,
return reportMessage(resource, ownerField, ownerName, msg, lineNumber, charStart, charEnd,
IMarker.PROBLEM, IMarker.SEVERITY_ERROR);
}
/**
* Reports an info in the Problems tab.
* @param resource the resource
* @param ownerField the name of the field to store the owner
* @param ownerName the name of the creator of this report
* @param msg the message to display
* @param lineNumber the line to select (or 0)
* @param charStart the start of selection (or 0)
......@@ -78,14 +84,14 @@ public class ReportProblemsUtil {
* @throws CoreException
* @throws NullPointerException
*/
public static IMarker reportInfo(IResource resource, String msg, int lineNumber,
public static IMarker reportInfo(IResource resource, String ownerField, String ownerName, String msg, int lineNumber,
int charStart, int charEnd) throws CoreException, NullPointerException {
return reportMessage(resource, msg, lineNumber, charStart, charEnd,
return reportMessage(resource, ownerField, ownerName, msg, lineNumber, charStart, charEnd,
IMarker.PROBLEM, IMarker.SEVERITY_INFO);
}
private static IMarker reportMessage(IResource resource, String msg, int lineNumber, int charStart,
int charEnd, String type, int severity) throws CoreException, NullPointerException {
private static IMarker reportMessage(IResource resource, String ownerField, String ownerName, String msg, int lineNumber,
int charStart, int charEnd, String type, int severity) throws CoreException, NullPointerException {
if (resource == null) {
throw new NullPointerException("Resource is null");
}
......@@ -100,7 +106,7 @@ public class ReportProblemsUtil {
if (charStart > 0) attributes.put(IMarker.CHAR_START, new Integer(charStart)); // Note: this value is from the beginning of the document
if (charEnd > 0) attributes.put(IMarker.CHAR_END, new Integer(charEnd)); // Note: this value is from the beginning of the document
// m.setAttribute(IMarker.LOCATION, "whole file"); // This is a generic info about location
attributes.put(ownerField, ownerName);
m.setAttributes(attributes);
return m;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment