Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jsp] #1276 add support for jspf and tag extensions #1277

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -6,6 +6,6 @@

public class JSPLanguage extends AbstractLanguage {
public JSPLanguage() {
super("JSP", "jsp", new JSPTokenizer(), ".jsp", ".jspx");
super("JSP", "jsp", new JSPTokenizer(), ".jsp", ".jspx", ".jspf", ".tag");
}
}
Expand Up @@ -16,7 +16,7 @@ public class JspLanguageModule extends BaseLanguageModule {
public static final String TERSE_NAME = "jsp";

public JspLanguageModule() {
super(NAME, "JSP", TERSE_NAME, JspRuleChainVisitor.class, "jsp");
super(NAME, "JSP", TERSE_NAME, JspRuleChainVisitor.class, "jsp", "jspx", "jspf", "tag");
addVersion("", new JspHandler(), true);
}
}
Expand Up @@ -4,12 +4,16 @@

package net.sourceforge.pmd.lang.jsp;

import java.io.File;
import java.io.StringReader;
import java.nio.file.Paths;

import org.junit.Assert;
import org.junit.Test;

import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.LanguageVersion;
import net.sourceforge.pmd.lang.LanguageVersionDiscoverer;
import net.sourceforge.pmd.lang.LanguageVersionHandler;
import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ast.Node;
Expand Down Expand Up @@ -40,6 +44,28 @@ public void testParseBooleanAttribute() {
Assert.assertNotNull(node);
}

@Test
public void testParseJsp() {
testInternalJspFile(Paths.get("sample.jsp").toFile());
}

@Test
public void testParseTag() {
testInternalJspFile(Paths.get("sample.tag").toFile());
}

@Test(expected = AssertionError.class)
public void testParseWrong() {
testInternalJspFile(Paths.get("sample.xxx").toFile());
}

private void testInternalJspFile(File jspFile) {
LanguageVersionDiscoverer discoverer = new LanguageVersionDiscoverer();
LanguageVersion languageVersion = discoverer.getDefaultLanguageVersionForFile(jspFile);
Assert.assertEquals("LanguageVersion must be JSP!",
LanguageRegistry.getLanguage(JspLanguageModule.NAME).getDefaultVersion(), languageVersion);
}

private Node parse(String code) {
LanguageVersionHandler jspLang = LanguageRegistry.getLanguage(JspLanguageModule.NAME).getDefaultVersion()
.getLanguageVersionHandler();
Expand Down