Search in sources :

Example 1 with RuleMetadata

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

the class CheckstyleMarkerResolutionGenerator method getResolutions.

/**
 * {@inheritDoc}
 */
@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
    Collection<ICheckstyleMarkerResolution> fixes = new ArrayList<ICheckstyleMarkerResolution>();
    // get all fixes that apply to this marker instance
    String moduleName = marker.getAttribute(CheckstyleMarker.MODULE_NAME, null);
    RuleMetadata metadata = MetadataFactory.getRuleMetadata(moduleName);
    List<ICheckstyleMarkerResolution> potentialFixes = getInstantiatedQuickfixes(metadata);
    for (ICheckstyleMarkerResolution fix : potentialFixes) {
        if (fix.canFix(marker)) {
            fixes.add(fix);
        }
    }
    return fixes.toArray(new ICheckstyleMarkerResolution[fixes.size()]);
}
Also used : ArrayList(java.util.ArrayList) RuleMetadata(net.sf.eclipsecs.core.config.meta.RuleMetadata)

Example 2 with RuleMetadata

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

the class ConfigurationReader method getModules.

private static List<Module> getModules(final Document document) {
    final List<Module> modules = new ArrayList<>();
    document.accept(new VisitorSupport() {

        @Override
        public void visit(final Element node) {
            if (XMLTags.MODULE_TAG.equals(node.getName())) {
                final String name = node.attributeValue(XMLTags.NAME_TAG);
                final RuleMetadata metadata = MetadataFactory.getRuleMetadata(name);
                Module module = null;
                if (metadata != null) {
                    module = new Module(metadata, true);
                } else {
                    module = new Module(name);
                }
                addProperties(node, module);
                addMessages(node, module);
                addMetadata(node, module);
                // generic metadata
                if (module.getMetaData() == null) {
                    MetadataFactory.createGenericMetadata(module);
                }
                modules.add(module);
            }
        }
    });
    return modules;
}
Also used : Element(org.dom4j.Element) ArrayList(java.util.ArrayList) RuleMetadata(net.sf.eclipsecs.core.config.meta.RuleMetadata) VisitorSupport(org.dom4j.VisitorSupport)

Example 3 with RuleMetadata

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

the class CheckConfigurationConfigureDialog method createTreeViewer.

private Control createTreeViewer(Composite parent) {
    Group knownModules = new Group(parent, SWT.NULL);
    knownModules.setLayout(new GridLayout());
    knownModules.setText(Messages.CheckConfigurationConfigureDialog_lblKnownModules);
    mTxtTreeFilter = new Text(knownModules, SWT.SINGLE | SWT.BORDER);
    mTxtTreeFilter.setText(mDefaultFilterText);
    mTxtTreeFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    mTxtTreeFilter.addModifyListener(mController);
    mTxtTreeFilter.addKeyListener(mController);
    // select all of the default text on focus gain
    mTxtTreeFilter.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            if (mDefaultFilterText.equals(mTxtTreeFilter.getText())) {
                getShell().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        mTxtTreeFilter.selectAll();
                    }
                });
            }
        }

        @Override
        public void focusLost(FocusEvent e) {
        }
    });
    mTreeViewer = new TreeViewer(knownModules, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    mTreeViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    mTreeViewer.setContentProvider(new MetaDataContentProvider());
    mTreeViewer.setLabelProvider(new MetaDataLabelProvider());
    mTreeViewer.addSelectionChangedListener(mController);
    mTreeViewer.addDoubleClickListener(mController);
    mTreeViewer.getTree().addKeyListener(mController);
    // filter hidden elements
    mTreeViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            boolean passes = true;
            if (element instanceof RuleGroupMetadata) {
                passes = !((RuleGroupMetadata) element).isHidden();
            } else if (element instanceof RuleMetadata) {
                passes = !((RuleMetadata) element).isHidden();
            }
            return passes;
        }
    });
    mAddButton = new Button(knownModules, SWT.PUSH);
    mAddButton.setText((Messages.CheckConfigurationConfigureDialog_btnAdd));
    GridData gd = new GridData();
    gd.horizontalAlignment = GridData.END;
    mAddButton.setLayoutData(gd);
    mAddButton.addSelectionListener(mController);
    return knownModules;
}
Also used : Group(org.eclipse.swt.widgets.Group) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Text(org.eclipse.swt.widgets.Text) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) EnhancedCheckBoxTableViewer(net.sf.eclipsecs.ui.util.table.EnhancedCheckBoxTableViewer) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) RuleGroupMetadata(net.sf.eclipsecs.core.config.meta.RuleGroupMetadata) RuleMetadata(net.sf.eclipsecs.core.config.meta.RuleMetadata) FocusListener(org.eclipse.swt.events.FocusListener)

Example 4 with RuleMetadata

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

the class MarkerPropertyPage method createContents.

@Override
protected Control createContents(Composite parent) {
    noDefaultAndApplyButton();
    final Composite composite = new Composite(parent, SWT.NULL);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    final GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    try {
        new Label(composite, SWT.NONE).setImage(getSeverityImage(getIssue().getAttribute(IMarker.SEVERITY, -1)));
        new Label(composite, SWT.NONE).setText(Messages.MarkerPropertyPage_Issue);
        String message = (String) getIssue().getAttribute(IMarker.MESSAGE);
        Label labelMessage = new Label(composite, SWT.NONE);
        labelMessage.setText(message);
        new Label(composite, SWT.NONE).setImage(CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.MODULEGROUP_ICON));
        new Label(composite, SWT.NONE).setText(Messages.MarkerPropertyPage_Group);
        String moduleName = (String) getIssue().getAttribute(CheckstyleMarker.MODULE_NAME);
        RuleMetadata metaData = MetadataFactory.getRuleMetadata(moduleName);
        new Label(composite, SWT.NONE).setText(metaData.getGroup().getGroupName());
        new Label(composite, SWT.NONE).setImage(CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.MODULE_ICON));
        new Label(composite, SWT.NONE).setText(Messages.MarkerPropertyPage_Module);
        new Label(composite, SWT.NONE).setText(metaData.getRuleName());
        Label descriptionLabel = new Label(composite, SWT.NONE);
        descriptionLabel.setText(Messages.MarkerPropertyPage_Description);
        GridData gridData = new GridData();
        gridData.horizontalSpan = 3;
        gridData.verticalIndent = 20;
        descriptionLabel.setLayoutData(gridData);
        gridData = new GridData(GridData.FILL_BOTH);
        gridData.heightHint = 100;
        gridData.horizontalSpan = 3;
        Browser browserDescription = new Browser(composite, SWT.BORDER);
        browserDescription.setLayoutData(gridData);
        browserDescription.setText(CheckConfigurationConfigureDialog.getDescriptionHtml(metaData.getDescription()));
    } catch (CoreException e) {
        CheckstyleLog.log(e);
    }
    return composite;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) CoreException(org.eclipse.core.runtime.CoreException) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) RuleMetadata(net.sf.eclipsecs.core.config.meta.RuleMetadata) Browser(org.eclipse.swt.browser.Browser)

Example 5 with RuleMetadata

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

the class CheckstyleMarkerResolutionGenerator method hasResolutions.

/**
 * {@inheritDoc}
 */
@Override
public boolean hasResolutions(IMarker marker) {
    boolean hasAtLeastOneFix = false;
    // check if there is at least one fix that really applies to the module
    String moduleName = marker.getAttribute(CheckstyleMarker.MODULE_NAME, null);
    RuleMetadata metadata = MetadataFactory.getRuleMetadata(moduleName);
    if (metadata != null) {
        List<ICheckstyleMarkerResolution> fixes = getInstantiatedQuickfixes(metadata);
        for (ICheckstyleMarkerResolution fix : fixes) {
            if (fix.canFix(marker)) {
                hasAtLeastOneFix = true;
                break;
            }
        }
    }
    return hasAtLeastOneFix;
}
Also used : RuleMetadata(net.sf.eclipsecs.core.config.meta.RuleMetadata)

Aggregations

RuleMetadata (net.sf.eclipsecs.core.config.meta.RuleMetadata)5 ArrayList (java.util.ArrayList)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 RuleGroupMetadata (net.sf.eclipsecs.core.config.meta.RuleGroupMetadata)1 EnhancedCheckBoxTableViewer (net.sf.eclipsecs.ui.util.table.EnhancedCheckBoxTableViewer)1 Element (org.dom4j.Element)1 VisitorSupport (org.dom4j.VisitorSupport)1 CoreException (org.eclipse.core.runtime.CoreException)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 Browser (org.eclipse.swt.browser.Browser)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 FocusListener (org.eclipse.swt.events.FocusListener)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Group (org.eclipse.swt.widgets.Group)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1