Search in sources :

Example 1 with Severity

use of net.sf.eclipsecs.core.config.Severity in project eclipse-cs by checkstyle.

the class MetadataFactory method processModules.

@SuppressWarnings("unchecked")
private static void processModules(Element groupElement, RuleGroupMetadata groupMetadata, ResourceBundle metadataBundle) throws CheckstylePluginException {
    List<Element> moduleElements = groupElement.elements(XMLTags.RULE_METADATA_TAG);
    for (Element moduleEl : moduleElements) {
        // default severity
        String defaultSeverity = moduleEl.attributeValue(XMLTags.DEFAULT_SEVERITY_TAG);
        Severity severity = defaultSeverity == null || defaultSeverity.trim().length() == 0 ? getDefaultSeverity() : Severity.valueOf(defaultSeverity);
        String name = moduleEl.attributeValue(XMLTags.NAME_TAG).trim();
        name = localize(name, metadataBundle);
        String internalName = moduleEl.attributeValue(XMLTags.INTERNAL_NAME_TAG).trim();
        String parentName = moduleEl.attributeValue(XMLTags.PARENT_TAG) != null ? moduleEl.attributeValue(XMLTags.PARENT_TAG).trim() : null;
        boolean hidden = Boolean.valueOf(moduleEl.attributeValue(XMLTags.HIDDEN_TAG)).booleanValue();
        boolean hasSeverity = !"false".equals(moduleEl.attributeValue(XMLTags.HAS_SEVERITY_TAG));
        // $NON-NLS-1$
        boolean deletable = !"false".equals(moduleEl.attributeValue(XMLTags.DELETABLE_TAG));
        boolean isSingleton = Boolean.valueOf(moduleEl.attributeValue(XMLTags.IS_SINGLETON_TAG)).booleanValue();
        // create rule metadata
        RuleMetadata module = new RuleMetadata(name, internalName, parentName, severity, hidden, hasSeverity, deletable, isSingleton, groupMetadata);
        groupMetadata.getRuleMetadata().add(module);
        // register internal name
        sRuleMetadata.put(internalName, module);
        // process description
        String description = moduleEl.elementTextTrim(XMLTags.DESCRIPTION_TAG);
        description = localize(description, metadataBundle);
        module.setDescription(description);
        // process properties
        processProperties(moduleEl, module, metadataBundle);
        // process alternative names
        for (Element altNameEl : (List<Element>) moduleEl.elements(XMLTags.ALTERNATIVE_NAME_TAG)) {
            String alternativeName = altNameEl.attributeValue(XMLTags.INTERNAL_NAME_TAG);
            // register alternative name
            sAlternativeNamesMap.put(alternativeName, module);
            module.addAlternativeName(alternativeName);
        }
        // process quickfixes
        for (Element quickfixEl : (List<Element>) moduleEl.elements(XMLTags.QUCKFIX_TAG)) {
            String quickfixClassName = quickfixEl.attributeValue(XMLTags.CLASSNAME_TAG);
            module.addQuickfix(quickfixClassName);
        }
        // process message keys
        for (Element quickfixEl : (List<Element>) moduleEl.elements(XMLTags.MESSAGEKEY_TAG)) {
            String messageKey = quickfixEl.attributeValue(XMLTags.KEY_TAG);
            module.addMessageKey(messageKey);
        }
    }
}
Also used : Element(org.dom4j.Element) Severity(net.sf.eclipsecs.core.config.Severity) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with Severity

use of net.sf.eclipsecs.core.config.Severity in project eclipse-cs by checkstyle.

the class RuleConfigurationEditDialog method okPressed.

/**
 * OK button was selected.
 */
@Override
protected void okPressed() {
    // 
    // Get the selected severity level.
    // 
    Severity severity = mRule.getSeverity();
    try {
        severity = (Severity) ((IStructuredSelection) mSeverityCombo.getSelection()).getFirstElement();
    } catch (IllegalArgumentException e) {
        CheckstyleLog.log(e);
    }
    // Get the comment.
    final String comment = Strings.emptyToNull(mCommentText.getText());
    // Get the id
    final String id = Strings.emptyToNull(mIdText.getText());
    // Get the custom message
    for (Map.Entry<String, Text> entry : mCustomMessages.entrySet()) {
        String msgKey = entry.getKey();
        String standardMessage = MetadataFactory.getStandardMessage(msgKey, mRule.getMetaData().getInternalName());
        if (standardMessage == null) {
            // $NON-NLS-1$
            standardMessage = "";
        }
        String message = Strings.emptyToNull(entry.getValue().getText());
        if (message != null && !message.equals(standardMessage)) {
            mRule.getCustomMessages().put(msgKey, message);
        } else {
            mRule.getCustomMessages().remove(msgKey);
        }
    }
    // 
    if (mConfigPropertyWidgets != null) {
        for (int i = 0; i < mConfigPropertyWidgets.length; i++) {
            IConfigPropertyWidget widget = mConfigPropertyWidgets[i];
            ConfigProperty property = widget.getConfigProperty();
            try {
                widget.validate();
            } catch (CheckstylePluginException e) {
                String message = NLS.bind(Messages.RuleConfigurationEditDialog_msgInvalidPropertyValue, property.getMetaData().getName());
                this.setErrorMessage(message);
                return;
            }
            property.setValue(widget.getValue());
        }
    }
    // 
    // If we made it this far then all of the user input validated and we
    // can
    // update the final rule with the values the user entered.
    // 
    mRule.setSeverity(severity);
    mRule.setComment(comment);
    mRule.setId(id);
    super.okPressed();
}
Also used : ConfigProperty(net.sf.eclipsecs.core.config.ConfigProperty) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) Severity(net.sf.eclipsecs.core.config.Severity) Text(org.eclipse.swt.widgets.Text) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) HashMap(java.util.HashMap) Map(java.util.Map) IConfigPropertyWidget(net.sf.eclipsecs.ui.config.widgets.IConfigPropertyWidget)

Aggregations

Severity (net.sf.eclipsecs.core.config.Severity)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ConfigProperty (net.sf.eclipsecs.core.config.ConfigProperty)1 CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)1 IConfigPropertyWidget (net.sf.eclipsecs.ui.config.widgets.IConfigPropertyWidget)1 Element (org.dom4j.Element)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Text (org.eclipse.swt.widgets.Text)1