1 11 12 package org.eclipse.ui.internal.cheatsheets.data; 13 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.osgi.util.NLS; 16 import org.eclipse.ui.internal.cheatsheets.Messages; 17 import org.eclipse.ui.internal.cheatsheets.composite.parser.IStatusContainer; 18 import org.w3c.dom.Node ; 19 20 23 24 public class IncompatibleSiblingChecker { 25 26 private IStatusContainer statusContainer; 27 private Node parentNode; 28 private String existingChild; 29 private boolean errorReported = false; 30 31 public IncompatibleSiblingChecker(IStatusContainer statusContainer, Node parentNode) { 32 this.statusContainer = statusContainer; 33 this.parentNode = parentNode; 34 } 35 36 43 public void checkElement(String elementKind) { 44 if (isExecutable(elementKind)) { 45 if (existingChild == null) { 46 existingChild = elementKind; 47 } else { 48 reportIncompatible(elementKind); 49 } 50 } else if (isSubitem(elementKind)) { 51 if (isExecutable(existingChild)) { 52 reportIncompatible(elementKind); 53 } 54 } 55 } 56 57 private boolean isSubitem(String elementKind) { 58 return IParserTags.SUBITEM.equals(elementKind) 59 || IParserTags.CONDITIONALSUBITEM.equals(elementKind) 60 || IParserTags.REPEATEDSUBITM.equals(elementKind); 61 } 62 63 private boolean isExecutable(String elementKind) { 64 return IParserTags.ACTION.equals(elementKind) 65 || IParserTags.COMMAND.equals(elementKind) 66 || IParserTags.PERFORMWHEN.equals(elementKind); 67 } 68 69 private void reportIncompatible(String elementKind) { 70 if (errorReported) { 71 return; } 73 errorReported = true; 74 String message; 75 if (elementKind.equals(existingChild)) { 76 message = NLS.bind(Messages.ERROR_PARSING_DUPLICATE_CHILD, (new Object [] {parentNode.getNodeName(), elementKind})); 77 } else { 78 message = NLS.bind(Messages.ERROR_PARSING_INCOMPATIBLE_CHILDREN, (new Object [] {parentNode.getNodeName(), existingChild, elementKind})); 79 } 80 statusContainer.addStatus(IStatus.ERROR, message, null); 81 } 82 } 83 | Popular Tags |