use of net.sourceforge.pmd.lang.LanguageVersion in project Gargoyle by callakrsos.
the class PMDCheckedListComposite method transformParametersIntoConfiguration.
public GargoylePMDConfiguration transformParametersIntoConfiguration(GargoylePMDParameters params) {
// if (null == params.getSourceDir() && null == params.getUri() && null
// == params.getFileListPath()
// && null == params.getSourceText()) {
// throw new IllegalArgumentException(
// "Please provide a parameter for source root directory (-dir or -d),
// database URI (-uri or -u), or file list path (-filelist).");
// }
GargoylePMDConfiguration configuration = new GargoylePMDConfiguration();
configuration.setInputPaths(params.getSourceDir());
// configuration.setInputFilePath(params.getFileListPath());
// configuration.setInputUri(params.getUri());
configuration.setReportFormat(REPORT_FILE_FORMAT);
configuration.setSourceFileName(params.getSourceFileName());
configuration.setSourceText(params.getSourceText());
// configuration.setBenchmark(params.isBenchmark());
configuration.setDebug(params.isDebug());
// configuration.setMinimumPriority(params.getMinimumPriority());
configuration.setReportFile(params.getReportfile());
configuration.setReportProperties(params.getProperties());
// configuration.setReportShortNames(params.isShortnames());
String language = params.getLanguage();
// String RESULTSET = new File(String.format(RULESETS_FILE_FORMAT,
// "java")).getAbsolutePath();
// if (null != language) {
// RESULTSET = new File(String.format(RULESETS_FILE_FORMAT,
// language)).getAbsolutePath();
// }
configuration.setRuleSets(getRuleSets(language));
// configuration.setRuleSetFactoryCompatibilityEnabled(true);
configuration.setShowSuppressedViolations(params.isShowsuppressed());
configuration.setSourceEncoding("UTF-8");
// configuration.setStressTest(params.isStress());
// configuration.setSuppressMarker(params.getSuppressmarker());
configuration.setThreads(1);
// configuration.setFailOnViolation(params.isFailOnViolation());
LanguageVersion languageVersion = LanguageRegistry.findLanguageVersionByTerseName(language + " " + params.getVersion());
if (languageVersion != null) {
configuration.getLanguageVersionDiscoverer().setDefaultLanguageVersion(languageVersion);
}
try {
configuration.prependClasspath(params.getAuxclasspath());
} catch (IOException e) {
throw new IllegalArgumentException("Invalid auxiliary classpath: " + e.getMessage(), e);
}
return configuration;
}
use of net.sourceforge.pmd.lang.LanguageVersion in project Gargoyle by callakrsos.
the class DesignerFx method createFxMenuBar.
// private JMenuBar createMenuBar() {
// JMenuBar menuBar = new JMenuBar();
// JMenu menu = new JMenu("Language");
// ButtonGroup group = new ButtonGroup();
//
// LanguageVersion[] languageVersions = getSupportedLanguageVersions();
// for (int i = 0; i < languageVersions.length; i++) {
// LanguageVersion languageVersion = languageVersions[i];
// MenuItem button = new MenuItem(languageVersion.getShortName());
// languageVersionMenuItems[i] = button;
// group.add(button);
// menu.add(button);
// }
// languageVersionMenuItems[DEFAULT_LANGUAGE_VERSION_SELECTION_INDEX].setSelected(true);
// menuBar.add(menu);
//
// JMenu actionsMenu = new JMenu("Actions");
// JMenuItem copyXMLItem = new JMenuItem("Copy xml to clipboard");
// copyXMLItem.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// copyXmlToClipboard();
// }
// });
// actionsMenu.add(copyXMLItem);
// JMenuItem createRuleXMLItem = new JMenuItem("Create rule XML");
// createRuleXMLItem.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// createRuleXML();
// }
// });
// actionsMenu.add(createRuleXMLItem);
// menuBar.add(actionsMenu);
//
// return menuBar;
// }
private MenuBar createFxMenuBar() {
MenuBar menuBar = new MenuBar();
Menu menu = new Menu("Language");
ToggleGroup group = new ToggleGroup();
LanguageVersion[] languageVersions = getSupportedLanguageVersions();
for (int i = 0; i < languageVersions.length; i++) {
LanguageVersion languageVersion = languageVersions[i];
// JRadioButtonMenuItem button = new JRadioButtonMenuItem(languageVersion.getShortName());
RadioMenuItem button = new RadioMenuItem(languageVersion.getShortName());
button.setToggleGroup(group);
languageVersionMenuItems[i] = button;
// group.add(button);
menu.getItems().add(button);
}
// languageVersionMenuItems[DEFAULT_LANGUAGE_VERSION_SELECTION_INDEX].setSelected(true);
languageVersionMenuItems[getDefaultLanguageVersionSelectionIndex()].setSelected(true);
menuBar.getMenus().add(menu);
Menu actionsMenu = new Menu("Actions");
MenuItem copyXMLItem = new MenuItem("Copy xml to clipboard");
copyXMLItem.setOnAction(e -> copyXmlToClipboard());
actionsMenu.getItems().add(copyXMLItem);
MenuItem createRuleXMLItem = new MenuItem("Create rule XML");
createRuleXMLItem.setOnAction(e -> createRuleXML());
actionsMenu.getItems().add(createRuleXMLItem);
menuBar.getMenus().add(actionsMenu);
return menuBar;
}
use of net.sourceforge.pmd.lang.LanguageVersion in project Gargoyle by callakrsos.
the class GargoylePMDParameters method transformParametersIntoConfiguration.
public static GargoylePMDConfiguration transformParametersIntoConfiguration(GargoylePMDParameters params) {
if (null == params.getSourceDir() && null == params.getUri() && null == params.getFileListPath() && null == params.getSourceText()) {
throw new IllegalArgumentException("Please provide a parameter for source root directory (-dir or -d), database URI (-uri or -u), or file list path (-filelist).");
}
GargoylePMDConfiguration configuration = new GargoylePMDConfiguration();
configuration.setInputPaths(params.getSourceDir());
configuration.setInputFilePath(params.getFileListPath());
configuration.setInputUri(params.getUri());
configuration.setReportFormat(params.getFormat());
configuration.setSourceText(params.getSourceText());
configuration.setBenchmark(params.isBenchmark());
configuration.setDebug(params.isDebug());
configuration.setMinimumPriority(params.getMinimumPriority());
configuration.setReportFile(params.getReportfile());
configuration.setReportProperties(params.getProperties());
configuration.setReportShortNames(params.isShortnames());
configuration.setRuleSets(params.getRulesets());
configuration.setRuleSetFactoryCompatibilityEnabled(!params.noRuleSetCompatibility);
configuration.setShowSuppressedViolations(params.isShowsuppressed());
configuration.setSourceEncoding(params.getEncoding());
configuration.setStressTest(params.isStress());
configuration.setSuppressMarker(params.getSuppressmarker());
configuration.setThreads(params.getThreads());
configuration.setFailOnViolation(params.isFailOnViolation());
LanguageVersion languageVersion = LanguageRegistry.findLanguageVersionByTerseName(params.getLanguage() + " " + params.getVersion());
if (languageVersion != null) {
configuration.getLanguageVersionDiscoverer().setDefaultLanguageVersion(languageVersion);
}
try {
configuration.prependClasspath(params.getAuxclasspath());
} catch (IOException e) {
throw new IllegalArgumentException("Invalid auxiliary classpath: " + e.getMessage(), e);
}
return configuration;
}
use of net.sourceforge.pmd.lang.LanguageVersion in project pmd by pmd.
the class Designer method createMenuBar.
private JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Language");
ButtonGroup group = new ButtonGroup();
LanguageVersion[] languageVersions = getSupportedLanguageVersions();
for (int i = 0; i < languageVersions.length; i++) {
LanguageVersion languageVersion = languageVersions[i];
JRadioButtonMenuItem button = new JRadioButtonMenuItem(languageVersion.getShortName());
languageVersionMenuItems[i] = button;
group.add(button);
menu.add(button);
}
languageVersionMenuItems[getDefaultLanguageVersionSelectionIndex()].setSelected(true);
menuBar.add(menu);
JMenu actionsMenu = new JMenu("Actions");
JMenuItem copyXMLItem = new JMenuItem("Copy xml to clipboard");
copyXMLItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
copyXmlToClipboard();
}
});
actionsMenu.add(copyXMLItem);
JMenuItem createRuleXMLItem = new JMenuItem("Create rule XML");
createRuleXMLItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
createRuleXML();
}
});
actionsMenu.add(createRuleXMLItem);
menuBar.add(actionsMenu);
return menuBar;
}
use of net.sourceforge.pmd.lang.LanguageVersion in project pmd by pmd.
the class StdCyclomaticComplexityRuleTest method entryStackMustBeEmpty.
/**
* Make sure the entry stack is empty, if show classes complexity is
* disabled.
*
* @see <a href="https://sourceforge.net/p/pmd/bugs/1501/">bug #1501</a>
*/
@Test
public void entryStackMustBeEmpty() {
StdCyclomaticComplexityRule rule = new StdCyclomaticComplexityRule();
rule.setProperty(StdCyclomaticComplexityRule.SHOW_CLASSES_COMPLEXITY_DESCRIPTOR, Boolean.FALSE);
RuleContext ctx = new RuleContext();
LanguageVersion javaLanguageVersion = LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getVersion("1.8");
ParserOptions parserOptions = javaLanguageVersion.getLanguageVersionHandler().getDefaultParserOptions();
Parser parser = javaLanguageVersion.getLanguageVersionHandler().getParser(parserOptions);
Node node = parser.parse("test", new StringReader("public class SampleClass {}"));
rule.apply(Arrays.asList(node), ctx);
Assert.assertTrue(rule.entryStack.isEmpty());
}
Aggregations