Search in sources :

Example 11 with LanguageVersion

use of net.sourceforge.pmd.lang.LanguageVersion in project pmd by pmd.

the class LanguageVersionDiscovererTest method testComponentFile.

@Test
public void testComponentFile() {
    LanguageVersionDiscoverer discoverer = new LanguageVersionDiscoverer();
    File vfFile = new File("/path/to/MyPage.component");
    LanguageVersion languageVersion = discoverer.getDefaultLanguageVersionForFile(vfFile);
    assertEquals("LanguageVersion must be VF!", LanguageRegistry.getLanguage(VfLanguageModule.NAME).getDefaultVersion(), languageVersion);
}
Also used : LanguageVersion(net.sourceforge.pmd.lang.LanguageVersion) LanguageVersionDiscoverer(net.sourceforge.pmd.lang.LanguageVersionDiscoverer) File(java.io.File) Test(org.junit.Test)

Example 12 with LanguageVersion

use of net.sourceforge.pmd.lang.LanguageVersion in project pmd by pmd.

the class LanguageVersionDiscovererTest method testVFFile.

/**
 * Test on VF file.
 */
@Test
public void testVFFile() {
    LanguageVersionDiscoverer discoverer = new LanguageVersionDiscoverer();
    File vfFile = new File("/path/to/MyPage.page");
    LanguageVersion languageVersion = discoverer.getDefaultLanguageVersionForFile(vfFile);
    assertEquals("LanguageVersion must be VF!", LanguageRegistry.getLanguage(VfLanguageModule.NAME).getDefaultVersion(), languageVersion);
}
Also used : LanguageVersion(net.sourceforge.pmd.lang.LanguageVersion) LanguageVersionDiscoverer(net.sourceforge.pmd.lang.LanguageVersionDiscoverer) File(java.io.File) Test(org.junit.Test)

Example 13 with LanguageVersion

use of net.sourceforge.pmd.lang.LanguageVersion in project pmd by pmd.

the class RuleTstTest method shouldCallStartAndEnd.

@Test
public void shouldCallStartAndEnd() {
    RuleTst ruleTester = new RuleTst() {
    };
    LanguageVersion languageVersion = LanguageRegistry.findLanguageByTerseName("dummy").getDefaultVersion();
    Report report = new Report();
    Rule rule = mock(Rule.class);
    when(rule.getLanguage()).thenReturn(languageVersion.getLanguage());
    when(rule.getName()).thenReturn("test rule");
    ruleTester.runTestFromString("the code", rule, report, languageVersion, false);
    verify(rule).start(any(RuleContext.class));
    verify(rule).end(any(RuleContext.class));
    verify(rule, times(5)).getLanguage();
    verify(rule).isDfa();
    verify(rule).isTypeResolution();
    verify(rule).isMultifile();
    verify(rule, times(2)).isRuleChain();
    verify(rule).getMinimumLanguageVersion();
    verify(rule).getMaximumLanguageVersion();
    verify(rule).apply(anyList(), any(RuleContext.class));
    verify(rule, times(4)).getName();
    verify(rule).getPropertiesByPropertyDescriptor();
    verifyNoMoreInteractions(rule);
}
Also used : RuleContext(net.sourceforge.pmd.RuleContext) Report(net.sourceforge.pmd.Report) LanguageVersion(net.sourceforge.pmd.lang.LanguageVersion) Rule(net.sourceforge.pmd.Rule) Test(org.junit.Test)

Example 14 with LanguageVersion

use of net.sourceforge.pmd.lang.LanguageVersion in project pmd by pmd.

the class AbstractLanguageVersionTest method testFindVersionsForLanguageNameAndVersion.

/**
 * Checks that the expected {@link LanguageVersion} can be found via
 * {@link #name} and {@link #version}.
 */
@Test
public void testFindVersionsForLanguageNameAndVersion() {
    SourceLanguage sourceLanguage = new SourceLanguage();
    sourceLanguage.setName(name);
    sourceLanguage.setVersion(version);
    Language language = LanguageRegistry.getLanguage(sourceLanguage.getName());
    LanguageVersion languageVersion = null;
    if (language != null) {
        languageVersion = language.getVersion(sourceLanguage.getVersion());
    }
    assertEquals(expected, languageVersion);
}
Also used : SourceLanguage(net.sourceforge.pmd.ant.SourceLanguage) SourceLanguage(net.sourceforge.pmd.ant.SourceLanguage) Language(net.sourceforge.pmd.lang.Language) LanguageVersion(net.sourceforge.pmd.lang.LanguageVersion) Test(org.junit.Test)

Example 15 with LanguageVersion

use of net.sourceforge.pmd.lang.LanguageVersion in project pmd by pmd.

the class DesignerUtil method getSupportedLanguageVersions.

public static synchronized List<LanguageVersion> getSupportedLanguageVersions() {
    if (supportedLanguageVersions == null) {
        List<LanguageVersion> languageVersions = new ArrayList<>();
        for (LanguageVersion languageVersion : LanguageRegistry.findAllVersions()) {
            Optional.ofNullable(languageVersion.getLanguageVersionHandler()).map(handler -> handler.getParser(handler.getDefaultParserOptions())).filter(Parser::canParse).ifPresent(p -> languageVersions.add(languageVersion));
        }
        supportedLanguageVersions = languageVersions;
    }
    return supportedLanguageVersions;
}
Also used : ArrayList(java.util.ArrayList) LanguageVersion(net.sourceforge.pmd.lang.LanguageVersion)

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