use of com.archimatetool.hammer.validation.issues.WarningType 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.WarningType in project archi by archimatetool.
the class UnusedElementsChecker method findUnusedElements.
List<IIssue> findUnusedElements() {
List<IIssue> issues = new ArrayList<IIssue>();
for (IArchimateElement element : fArchimateElements) {
if (!DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element)) {
String name = ArchiLabelProvider.INSTANCE.getLabel(element);
String description = NLS.bind(DESCRIPTION, name);
String explanation = NLS.bind(EXPLANATION, name);
IIssue issue = new WarningType(NAME, description, explanation, element);
issues.add(issue);
}
}
return issues;
}
use of com.archimatetool.hammer.validation.issues.WarningType in project archi by archimatetool.
the class UnusedRelationsChecker method findUnusedRelations.
List<IIssue> findUnusedRelations() {
List<IIssue> issues = new ArrayList<IIssue>();
for (IArchimateRelationship relation : fRelations) {
if (!DiagramModelUtils.isArchimateConceptReferencedInDiagrams(relation)) {
String name = ArchiLabelProvider.INSTANCE.getLabel(relation);
String description = NLS.bind(DESCRIPTION, name);
String explanation = NLS.bind(EXPLANATION, name);
IIssue issue = new WarningType(NAME, description, explanation, relation);
issues.add(issue);
}
}
return issues;
}
use of com.archimatetool.hammer.validation.issues.WarningType in project archi by archimatetool.
the class DuplicateElementChecker method findDuplicateNamesElements.
List<IIssue> findDuplicateNamesElements() {
List<IIssue> issues = new ArrayList<IIssue>();
Set<IArchimateElement> dupes = new LinkedHashSet<IArchimateElement>();
for (int i = 0; i < fArchimateElements.size(); i++) {
for (int j = i + 1; j < fArchimateElements.size(); j++) {
IArchimateElement element1 = fArchimateElements.get(i);
IArchimateElement element2 = fArchimateElements.get(j);
if (isDuplicate(element1, element2)) {
dupes.add(element1);
dupes.add(element2);
}
}
}
for (IArchimateElement element : dupes) {
String description = NLS.bind(DESCRIPTION, new Object[] { element.getName(), ArchiLabelProvider.INSTANCE.getDefaultName(element.eClass()) });
IIssue issue = new WarningType(NAME, description, EXPLANATION, element);
issues.add(issue);
}
return issues;
}
use of com.archimatetool.hammer.validation.issues.WarningType in project archi by archimatetool.
the class DuplicateElementCheckerTests method testGetIssues.
@Test
public void testGetIssues() {
List<IArchimateElement> elements = new ArrayList<IArchimateElement>();
IArchimateElement e1 = IArchimateFactory.eINSTANCE.createBusinessActor();
e1.setName("fido1");
elements.add(e1);
IArchimateElement e2 = IArchimateFactory.eINSTANCE.createBusinessActor();
e2.setName("fido2");
elements.add(e2);
DuplicateElementChecker checker = new DuplicateElementChecker(elements);
// Should be OK
List<IIssue> issues = checker.getIssues();
assertTrue(issues.isEmpty());
// Set name the same
e2.setName("fido1");
issues = checker.getIssues();
assertEquals(2, issues.size());
assertTrue(issues.get(0) instanceof WarningType);
assertTrue(issues.get(1) instanceof WarningType);
assertSame(e1, issues.get(0).getObject());
assertSame(e2, issues.get(1).getObject());
}
Aggregations