REVERT ME Remove some diff
This commit is contained in:
@ -93,20 +93,10 @@
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-lang-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -0,0 +1,48 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.vf;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.Parser;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
|
||||
/**
|
||||
* @author sergey.gorbaty
|
||||
*
|
||||
*/
|
||||
public class VfParserTest {
|
||||
|
||||
@Test
|
||||
public void testSingleDoubleQuoteAndEL() {
|
||||
Node node = parse("<span escape='false' attrib=\"{!call}\">${!'yes'}</span>");
|
||||
Assert.assertNotNull(node);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleDoubleQuoteAndELFunction() {
|
||||
Node node = parse("<span escape='false' attrib=\"{!call}\">${!method}</span>");
|
||||
Assert.assertNotNull(node);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleDoubleQuote() {
|
||||
Node node = parse("<span escape='false' attrib=\"{!call}\">${\"yes\"}</span>");
|
||||
Assert.assertNotNull(node);
|
||||
}
|
||||
|
||||
private Node parse(String code) {
|
||||
LanguageVersionHandler vfLang = LanguageRegistry.getLanguage(VfLanguageModule.NAME).getDefaultVersion()
|
||||
.getLanguageVersionHandler();
|
||||
Parser parser = vfLang.getParser(vfLang.getDefaultParserOptions());
|
||||
Node node = parser.parse(null, new StringReader(code));
|
||||
return node;
|
||||
}
|
||||
}
|
@ -4,8 +4,70 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.vf.ast;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.JavaCharStream;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
|
||||
public abstract class AbstractVfNodesTest {
|
||||
|
||||
protected final VfParsingHelper vf = VfParsingHelper.DEFAULT.withResourceContext(getClass());
|
||||
public <T extends VfNode> void assertNumberOfNodes(Class<T> clazz, String source, int number) {
|
||||
Set<T> nodes = getNodes(clazz, source);
|
||||
assertEquals("Exactly " + number + " element(s) expected", number, nodes.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the VF parser on the source, and return the nodes of type clazz.
|
||||
*
|
||||
* @param clazz
|
||||
* @param source
|
||||
* @return Set
|
||||
*/
|
||||
public <T extends VfNode> Set<T> getNodes(Class<T> clazz, String source) {
|
||||
VfParser parser = new VfParser(new JavaCharStream(new StringReader(source)));
|
||||
Node rootNode = parser.CompilationUnit();
|
||||
Set<T> nodes = new HashSet<>();
|
||||
addNodeAndSubnodes(rootNode, nodes, clazz);
|
||||
return nodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a subset of allNodes, containing the items in allNodes that are of
|
||||
* the given type.
|
||||
*
|
||||
* @param clazz
|
||||
* @param allNodes
|
||||
* @return Set
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends VfNode> Set<T> getNodesOfType(Class<T> clazz, Set<VfNode> allNodes) {
|
||||
Set<T> result = new HashSet<>();
|
||||
for (Node node : allNodes) {
|
||||
if (clazz.equals(node.getClass())) {
|
||||
result.add((T) node);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given node and its subnodes to the set of nodes. If clazz is not
|
||||
* null, only nodes of the given class are put in the set of nodes.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends VfNode> void addNodeAndSubnodes(Node node, Set<T> nodes, Class<T> clazz) {
|
||||
if (null != node) {
|
||||
if ((null == clazz) || (clazz.equals(node.getClass()))) {
|
||||
nodes.add((T) node);
|
||||
}
|
||||
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
|
||||
addNodeAndSubnodes(node.jjtGetChild(i), nodes, clazz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,7 @@ package net.sourceforge.pmd.lang.vf.ast;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@ -17,7 +17,7 @@ public class VfPageStyleTest extends AbstractVfNodesTest {
|
||||
*/
|
||||
@Test
|
||||
public void testElExpression() {
|
||||
List<ASTElExpression> expressions = vf.getNodes(ASTElExpression.class, VF_EL_EXPRESSION);
|
||||
Set<ASTElExpression> expressions = getNodes(ASTElExpression.class, VF_EL_EXPRESSION);
|
||||
assertEquals("One expression expected!", 1, expressions.size());
|
||||
ASTElExpression expression = expressions.iterator().next();
|
||||
ASTExpression exp = expression.getFirstChildOfType(ASTExpression.class);
|
||||
@ -25,7 +25,7 @@ public class VfPageStyleTest extends AbstractVfNodesTest {
|
||||
assertEquals("Correct expression content expected!", "myBean", id.getImage());
|
||||
ASTDotExpression dot = exp.getFirstChildOfType(ASTDotExpression.class);
|
||||
ASTIdentifier dotid = dot.getFirstChildOfType(ASTIdentifier.class);
|
||||
assertEquals("Correct expression content expected!", "get", dotid.getImage());
|
||||
assertEquals("Correct expression content expected!", "get", dotid.getImage());
|
||||
ASTArguments arguments = exp.getFirstChildOfType(ASTArguments.class);
|
||||
ASTExpression innerExpression = arguments.getFirstChildOfType(ASTExpression.class);
|
||||
ASTLiteral literal = innerExpression.getFirstChildOfType(ASTLiteral.class);
|
||||
@ -37,7 +37,7 @@ public class VfPageStyleTest extends AbstractVfNodesTest {
|
||||
*/
|
||||
@Test
|
||||
public void testElExpressionInAttribute() {
|
||||
List<ASTElExpression> expressions = vf.getNodes(ASTElExpression.class, VF_EL_EXPRESSION_IN_ATTRIBUTE);
|
||||
Set<ASTElExpression> expressions = getNodes(ASTElExpression.class, VF_EL_EXPRESSION_IN_ATTRIBUTE);
|
||||
assertEquals("One expression expected!", 1, expressions.size());
|
||||
ASTElExpression expression = expressions.iterator().next();
|
||||
ASTExpression exp = expression.getFirstChildOfType(ASTExpression.class);
|
||||
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.vf.ast;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author sergey.gorbaty
|
||||
*/
|
||||
public class VfParserTest extends AbstractVfNodesTest {
|
||||
|
||||
@Test
|
||||
public void testSingleDoubleQuoteAndEL() {
|
||||
vf.parse("<span escape='false' attrib=\"{!call}\">${!'yes'}</span>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleDoubleQuoteAndELFunction() {
|
||||
vf.parse("<span escape='false' attrib=\"{!call}\">${!method}</span>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleDoubleQuote() {
|
||||
vf.parse("<span escape='false' attrib=\"{!call}\">${\"yes\"}</span>");
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.vf.ast;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.test.BaseParsingHelper;
|
||||
import net.sourceforge.pmd.lang.vf.VfLanguageModule;
|
||||
|
||||
public final class VfParsingHelper extends BaseParsingHelper<VfParsingHelper, ASTCompilationUnit> {
|
||||
|
||||
public static final VfParsingHelper DEFAULT = new VfParsingHelper(Params.getDefaultProcess());
|
||||
|
||||
private VfParsingHelper(Params params) {
|
||||
super(VfLanguageModule.NAME, ASTCompilationUnit.class, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected VfParsingHelper clone(Params params) {
|
||||
return new VfParsingHelper(params);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user