Search in sources :

Example 1 with LanguageVersion

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;
}
Also used : GargoylePMDConfiguration(com.kyj.fx.voeditor.visual.framework.pmd.GargoylePMDConfiguration) LanguageVersion(net.sourceforge.pmd.lang.LanguageVersion) IOException(java.io.IOException)

Example 2 with LanguageVersion

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;
}
Also used : ToggleGroup(javafx.scene.control.ToggleGroup) JMenuBar(javax.swing.JMenuBar) MenuBar(javafx.scene.control.MenuBar) LanguageVersion(net.sourceforge.pmd.lang.LanguageVersion) MenuItem(javafx.scene.control.MenuItem) RadioMenuItem(javafx.scene.control.RadioMenuItem) Menu(javafx.scene.control.Menu) RadioMenuItem(javafx.scene.control.RadioMenuItem)

Example 3 with LanguageVersion

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;
}
Also used : LanguageVersion(net.sourceforge.pmd.lang.LanguageVersion) IOException(java.io.IOException)

Example 4 with LanguageVersion

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;
}
Also used : ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) ActionEvent(java.awt.event.ActionEvent) LanguageVersion(net.sourceforge.pmd.lang.LanguageVersion) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JMenuItem(javax.swing.JMenuItem) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 5 with LanguageVersion

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());
}
Also used : ParserOptions(net.sourceforge.pmd.lang.ParserOptions) RuleContext(net.sourceforge.pmd.RuleContext) Node(net.sourceforge.pmd.lang.ast.Node) StringReader(java.io.StringReader) LanguageVersion(net.sourceforge.pmd.lang.LanguageVersion) Parser(net.sourceforge.pmd.lang.Parser) Test(org.junit.Test)

Aggregations

LanguageVersion (net.sourceforge.pmd.lang.LanguageVersion)35 Test (org.junit.Test)14 LanguageVersionDiscoverer (net.sourceforge.pmd.lang.LanguageVersionDiscoverer)10 File (java.io.File)9 IOException (java.io.IOException)8 RuleContext (net.sourceforge.pmd.RuleContext)7 Language (net.sourceforge.pmd.lang.Language)7 Parser (net.sourceforge.pmd.lang.Parser)7 StringReader (java.io.StringReader)5 Node (net.sourceforge.pmd.lang.ast.Node)5 PMDConfiguration (net.sourceforge.pmd.PMDConfiguration)4 ParserOptions (net.sourceforge.pmd.lang.ParserOptions)4 ArrayList (java.util.ArrayList)3 Rule (net.sourceforge.pmd.Rule)3 PropertyDescriptor (net.sourceforge.pmd.properties.PropertyDescriptor)3 GargoylePMDConfiguration (com.kyj.fx.voeditor.visual.framework.pmd.GargoylePMDConfiguration)2 FileNotFoundException (java.io.FileNotFoundException)2 Reader (java.io.Reader)2 HashSet (java.util.HashSet)2 JMenuBar (javax.swing.JMenuBar)2