use of com.archimatetool.hammer.validation.issues.AdviceType in project archi by archimatetool.
the class Validator method validate.
/**
* @return The list of Issue Categories and Issues
*/
public List<Object> validate() {
if (fModel == null) {
return null;
}
// Collect interesting objects
fElements = new ArrayList<IArchimateElement>();
fRelations = new ArrayList<IArchimateRelationship>();
fViews = new ArrayList<IArchimateDiagramModel>();
for (Iterator<EObject> iter = fModel.eAllContents(); iter.hasNext(); ) {
EObject eObject = iter.next();
if (eObject instanceof IArchimateRelationship) {
fRelations.add((IArchimateRelationship) eObject);
} else if (eObject instanceof IArchimateElement) {
fElements.add((IArchimateElement) eObject);
} else if (eObject instanceof IArchimateDiagramModel) {
fViews.add((IArchimateDiagramModel) eObject);
}
}
// Analyse
List<Object> result = new ArrayList<Object>();
fErrorList = new ArrayList<ErrorType>();
fWarningList = new ArrayList<WarningType>();
fAdviceList = new ArrayList<AdviceType>();
// ------------------ Checkers -----------------------------
IPreferenceStore store = ArchiHammerPlugin.INSTANCE.getPreferenceStore();
// Invalid Relations
if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_INVALID_RELATIONS)) {
collectIssues(new InvalidRelationsChecker(getArchimateRelationships()));
}
// Unused Elements
if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_UNUSED_ELEMENTS)) {
collectIssues(new UnusedElementsChecker(getArchimateElements()));
}
// Unused Relations
if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_UNUSED_RELATIONS)) {
collectIssues(new UnusedRelationsChecker(getArchimateRelationships()));
}
// Empty Views
if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_EMPTY_VIEWS)) {
collectIssues(new EmptyViewsChecker(getArchimateViews()));
}
// Components in wrong Viewpoints
if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_VIEWPOINT)) {
collectIssues(new ViewpointChecker(getArchimateViews()));
}
// Nested elements
if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_NESTING)) {
collectIssues(new NestedElementsChecker(getArchimateViews()));
}
// Possible Duplicates
if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_DUPLICATE_ELEMENTS)) {
collectIssues(new DuplicateElementChecker(getArchimateElements()));
}
// Junctions
if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_JUNCTIONS)) {
collectIssues(new JunctionsChecker(getArchimateElements()));
}
if (!fErrorList.isEmpty()) {
IIssueCategory category = new ErrorsCategory(fErrorList);
result.add(category);
}
if (!fWarningList.isEmpty()) {
IIssueCategory category = new WarningsCategory(fWarningList);
result.add(category);
}
if (!fAdviceList.isEmpty()) {
IIssueCategory category = new AdviceCategory(fAdviceList);
result.add(category);
}
if (result.isEmpty()) {
result.add(new OKType());
}
return result;
}
use of com.archimatetool.hammer.validation.issues.AdviceType in project archi by archimatetool.
the class EmptyViewsCheckerTests method testGetIssues.
@Test
public void testGetIssues() {
List<IArchimateDiagramModel> views = new ArrayList<IArchimateDiagramModel>();
IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
dm.setName("view");
views.add(dm);
EmptyViewsChecker checker = new EmptyViewsChecker(views);
// Should be warning
List<IIssue> issues = checker.getIssues();
assertEquals(1, issues.size());
assertTrue(issues.get(0) instanceof AdviceType);
assertSame(dm, issues.get(0).getObject());
// Add something to view for no issues
dm.getChildren().add(IArchimateFactory.eINSTANCE.createDiagramModelGroup());
issues = checker.getIssues();
assertEquals(0, issues.size());
}
use of com.archimatetool.hammer.validation.issues.AdviceType in project archi by archimatetool.
the class EmptyViewsChecker method findEmptyViews.
// Empty Views
List<IIssue> findEmptyViews() {
List<IIssue> issues = new ArrayList<IIssue>();
for (IArchimateDiagramModel view : fViews) {
if (view.getChildren().isEmpty()) {
String viewName = ArchiLabelProvider.INSTANCE.getLabel(view);
String description = NLS.bind(fDescription, viewName);
String explanation = NLS.bind(fExplanation, viewName);
IIssue issue = new AdviceType(fName, description, explanation, view);
issues.add(issue);
}
}
return issues;
}
use of com.archimatetool.hammer.validation.issues.AdviceType in project archi by archimatetool.
the class NestedElementsChecker method findWrongNestedElements.
// Nested diagram elements without correct relationships
List<IIssue> findWrongNestedElements() {
List<IIssue> issues = new ArrayList<IIssue>();
for (IArchimateDiagramModel dm : fViews) {
for (Iterator<EObject> iter = dm.eAllContents(); iter.hasNext(); ) {
EObject eObject = iter.next();
if (eObject instanceof IDiagramModelArchimateObject) {
IDiagramModelArchimateObject parent = (IDiagramModelArchimateObject) eObject;
for (IDiagramModelObject dmoChild : parent.getChildren()) {
if (dmoChild instanceof IDiagramModelArchimateObject) {
IDiagramModelArchimateObject child = (IDiagramModelArchimateObject) dmoChild;
if (isNestedWithoutValidRelation(parent, child)) {
String description = NLS.bind(fDescription, new Object[] { child.getName(), parent.getName() });
IIssue issue = new AdviceType(fName, description, fExplanation, child);
issues.add(issue);
}
}
}
}
}
}
return issues;
}
Aggregations