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()]);
}
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;
}
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;
}
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;
}
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;
}
Aggregations