📄 atlproblemsmanager.java
字号:
package com.thalesgroup.cheddar.MARTE2cheddar.tools;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.ecore.impl.DynamicEObjectImpl;
import org.eclipse.emf.ecore.impl.EAttributeImpl;
import org.eclipse.emf.ecore.impl.EEnumLiteralImpl;
import org.eclipse.emf.ecore.resource.Resource;
import com.thalesgroup.cheddar.MARTE2cheddar.tools.ATLProblem.Severity;
/**
* Manager for ATL Problems
* - transforms a PROBLEM model into a list of ATLProblem
* - manages the markers of theses problems for user notification
* <copyright>
* Thales MARTE to Cheddar (Copyright (c) THALES 2007 All rights reserved) is free software; you can redistribute itand/or modify
* it under the terms of the Eclipse Public License as published in http://www.eclipse.org/legal/epl-v10.html
*
* Thales MARTE to Cheddar is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Eclipse Public License for more details.
* </copyright>
* @author Nicolas Vienne
* @version 0.0.2, 13/09/2007
*/
public class ATLProblemsManager {
protected Resource modelResource = null;
protected int critic_count = 0;
protected int error_count = 0;
protected int warning_count = 0;
protected ArrayList<ATLProblem> problems = new ArrayList<ATLProblem>();
protected static Map<IResource, List<IMarker>> markers = new HashMap<IResource, List<IMarker>>();
public static final String INFO_PREFIX = "INFO: ";
public void importModel(Resource model) {
this.modelResource = model;
problems.clear();
critic_count = 0;
error_count = 0;
warning_count = 0;
for(Object o : model.getContents()) {
if (o instanceof DynamicEObjectImpl) {
DynamicEObjectImpl dob = (DynamicEObjectImpl) o;
if(dob.eClass().getName().toString().equals("Problem")) {
ATLProblem p = new ATLProblem();
for(Object o2 : dob.eClass().getEAttributes()) {
EAttributeImpl a = (EAttributeImpl) o2;
if(a.getName().equals("location")) {
String s = (String) dob.eGet(a);
p.setLocation(s);
}
if(a.getName().equals("description")) {
String s = (String)dob.eGet(a);
p.setDescription(s);
}
if(a.getName().equals("severity")) {
EEnumLiteralImpl eli = (EEnumLiteralImpl) dob.eGet(a);
String s = eli.toString();
if(s.equals("critic")) {
p.setSeverity(Severity.critic);
} else if (s.equals("warning")){
p.setSeverity(Severity.warning);
} else {
p.setSeverity(Severity.error);
}
}
}
// Avoid duplicate data
if(!problems.contains(p)) {
problems.add(p);
}
}
}
}
// Computes the number of problems
for(ATLProblem p : problems) {
switch (p.getSeverity()) {
case critic:
critic_count++;
break;
case error:
error_count++;
break;
case warning:
warning_count++;
break;
default:
break;
}
}
}
public int getCriticsCount() {
return critic_count;
}
public int getWarningsCount() {
return warning_count;
}
public int getErrorsCount() {
return error_count;
}
public int getProblemsCount() {
return problems.size();
}
public List<ATLProblem> getProblems() {
return problems;
}
public void PrintResume(PrintStream ps) {
ps.println(getCriticsCount()+getErrorsCount() + " error(s), "
+ getWarningsCount() + " warning(s)");
}
public void PrintDetails(PrintStream ps) {
for(ATLProblem p : problems) {
System.out.println(p.toString());
}
}
protected static IMarker createMarker(ATLProblem p, IResource resource) throws CoreException {
IMarker marker = resource.createMarker(IMarker.PROBLEM);
if (marker.exists()) {
String descr = p.getDescription();
if(p.getSeverity() == Severity.critic ||
p.getSeverity() == Severity.error) {
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
} else if(p.getSeverity() == Severity.warning) {
if(!descr.startsWith(INFO_PREFIX)) {
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
} else {
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
descr = descr.substring(INFO_PREFIX.length());
}
}
marker.setAttribute(IMarker.MESSAGE, descr);
marker.setAttribute(IMarker.LOCATION, p.getLocation());
}
return marker;
}
protected static void appendMarker(IMarker marker, IResource resource) throws CoreException {
if(!markers.containsKey(resource)) {
markers.put(resource, new ArrayList<IMarker>());
}
markers.get(resource).add(marker);
}
public void signalProblems(IResource resource) throws CoreException {
for(ATLProblem p : problems) {
IMarker marker = createMarker(p, resource);
appendMarker(marker, resource);
}
}
public void cleanProblems(IResource resource) throws CoreException {
cleanProblems(resource, false);
}
public static void cleanProblems(IResource resource, Boolean flush_all) throws CoreException {
if(flush_all) {
IMarker[] problems = null;
int depth = IResource.DEPTH_INFINITE;
problems = resource.findMarkers(IMarker.PROBLEM, true, depth);
for(IMarker m : problems) {
m.delete();
}
} else {
if(markers.containsKey(resource)) {
List<IMarker> ml = markers.get(resource);
for(IMarker m : ml) {
if(m.exists()) {
m.delete();
}
}
ml.clear();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -