Code style cleanup

This commit is contained in:
Sergey
2017-02-16 13:42:01 -08:00
parent 6974d5349b
commit e619c28f21
26 changed files with 39 additions and 79 deletions

View File

@@ -12,8 +12,8 @@ import org.apache.commons.io.IOUtils;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.LanguageVersionHandler;
import net.sourceforge.pmd.lang.TokenManager;
import net.sourceforge.pmd.lang.vf.ast.Token;
import net.sourceforge.pmd.lang.vf.VfLanguageModule;
import net.sourceforge.pmd.lang.vf.ast.Token;
import net.sourceforge.pmd.util.IOUtil;
/**

View File

@@ -5,9 +5,6 @@
package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.vf.ast.VfParser;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
public class ASTAttribute extends AbstractVFNode {
private String name;

View File

@@ -5,9 +5,6 @@
package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.vf.ast.VfParser;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
public class ASTAttributeValue extends AbstractVFNode {
public ASTAttributeValue(int id) {
super(id);

View File

@@ -5,9 +5,6 @@
package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.vf.ast.VfParser;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
public class ASTCData extends AbstractVFNode {
public ASTCData(int id) {
super(id);

View File

@@ -5,9 +5,6 @@
package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.vf.ast.VfParser;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
public class ASTCommentTag extends AbstractVFNode {
public ASTCommentTag(int id) {
super(id);

View File

@@ -6,8 +6,6 @@
package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.ast.RootNode;
import net.sourceforge.pmd.lang.vf.ast.VfParser;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
public class ASTCompilationUnit extends AbstractVFNode implements RootNode {
public ASTCompilationUnit(int id) {

View File

@@ -5,9 +5,6 @@
package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.vf.ast.VfParser;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
public class ASTDeclaration extends AbstractVFNode {
private String name;

View File

@@ -5,9 +5,6 @@
package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.vf.ast.VfParser;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
public class ASTDoctypeDeclaration extends AbstractVFNode {
/**

View File

@@ -5,9 +5,6 @@
package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.vf.ast.VfParser;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
public class ASTDoctypeExternalId extends AbstractVFNode {
/**

View File

@@ -5,9 +5,6 @@
package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.vf.ast.VfParser;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
public class ASTElExpression extends AbstractVFNode {
public ASTElExpression(int id) {
super(id);

View File

@@ -5,9 +5,6 @@
package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.vf.ast.VfParser;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
public class ASTElement extends AbstractVFNode {
/**

View File

@@ -6,9 +6,6 @@
package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.vf.ast.VfParser;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
public class ASTHtmlScript extends AbstractVFNode {
public ASTHtmlScript(int id) {
super(id);

View File

@@ -5,9 +5,6 @@
package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.vf.ast.VfParser;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
public class ASTText extends AbstractVFNode {
public ASTText(int id) {
super(id);

View File

@@ -5,9 +5,6 @@
package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.vf.ast.VfParser;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
public class ASTUnparsedText extends AbstractVFNode {
public ASTUnparsedText(int id) {
super(id);

View File

@@ -5,9 +5,6 @@
package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.ast.AbstractNode;
import net.sourceforge.pmd.lang.vf.ast.VfParser;
import net.sourceforge.pmd.lang.vf.ast.VfParserTreeConstants;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
public class AbstractVFNode extends AbstractNode implements VfNode {

View File

@@ -4,8 +4,6 @@
package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.vf.ast.ParseException;
/**
* Exception indicating that a syntactic error has been found.
*

View File

@@ -5,7 +5,6 @@
package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
public interface VfNode extends Node {
/**

View File

@@ -4,8 +4,6 @@
package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
public class VfParserVisitorAdapter implements VfParserVisitor {
public Object visit(VfNode node, Object data) {

View File

@@ -9,7 +9,6 @@ import java.util.List;
import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
import net.sourceforge.pmd.lang.rule.AbstractRule;
import net.sourceforge.pmd.lang.rule.ImmutableLanguage;
import net.sourceforge.pmd.lang.vf.VfLanguageModule;
@@ -27,6 +26,7 @@ import net.sourceforge.pmd.lang.vf.ast.ASTHtmlScript;
import net.sourceforge.pmd.lang.vf.ast.ASTText;
import net.sourceforge.pmd.lang.vf.ast.ASTUnparsedText;
import net.sourceforge.pmd.lang.vf.ast.VfNode;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
public abstract class AbstractVfRule extends AbstractRule implements VfParserVisitor, ImmutableLanguage {

View File

@@ -9,11 +9,11 @@ import java.util.List;
import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
import net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor;
import net.sourceforge.pmd.lang.rule.XPathRule;
import net.sourceforge.pmd.lang.vf.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.vf.ast.VfNode;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitorAdapter;
public class VfRuleChainVisitor extends AbstractRuleChainVisitor {

View File

@@ -20,9 +20,15 @@ import net.sourceforge.pmd.lang.vf.rule.AbstractVfRule;
*/
public class VfUnescapeElRule extends AbstractVfRule {
private static final String APEX_PARAM = "apex:param";
private static final String VALUE = "value";
private static final String ITEM_VALUE = "itemValue";
private static final String ESCAPE = "escape";
private static final String APEX_OUTPUT_TEXT = "apex:outputText";
private static final String ITEM_ESCAPED = "itemEscaped";
private static final String APEX_OUTPUT_TEXT = "apex:outputtext";
private static final String APEX_PAGE_MESSAGE = "apex:pagemessage";
private static final String APEX_PAGE_MESSAGES = "apex:pagemessages";
private static final String APEX_SELECT_OPTION = "apex:selectoption ";
private static final String FALSE = "false";
@Override
@@ -33,7 +39,7 @@ public class VfUnescapeElRule extends AbstractVfRule {
@Override
public Object visit(ASTElement node, Object data) {
if (node.getName().equalsIgnoreCase(APEX_OUTPUT_TEXT)) {
if (doesTagSupportEscaping(node)) {
final List<ASTAttribute> attributes = node.findChildrenOfType(ASTAttribute.class);
boolean isUnescaped = false;
boolean isEL = false;
@@ -44,6 +50,7 @@ public class VfUnescapeElRule extends AbstractVfRule {
String name = attr.getName();
switch (name) {
case ESCAPE:
case ITEM_ESCAPED:
final ASTUnparsedText text = attr.getFirstDescendantOfType(ASTUnparsedText.class);
if (text != null) {
if (text.getImage().equalsIgnoreCase(FALSE)) {
@@ -52,6 +59,7 @@ public class VfUnescapeElRule extends AbstractVfRule {
}
break;
case VALUE:
case ITEM_VALUE:
final ASTElExpression elInVal = attr.getFirstDescendantOfType(ASTElExpression.class);
if (elInVal != null) {
isEL = true;
@@ -86,10 +94,27 @@ public class VfUnescapeElRule extends AbstractVfRule {
return super.visit(node, data);
}
private boolean doesTagSupportEscaping(ASTElement node) {
if (node.getName() == null) {
return false;
}
switch (node.getName().toLowerCase()) { // vf is case insensitive?
case APEX_OUTPUT_TEXT:
case APEX_PAGE_MESSAGE:
case APEX_PAGE_MESSAGES:
case APEX_SELECT_OPTION:
return true;
default:
return false;
}
}
private boolean hasAnyEL(ASTElement node) {
final List<ASTElement> innerElements = node.findChildrenOfType(ASTElement.class);
for (ASTElement element : innerElements) {
if (element.getName().equalsIgnoreCase("apex:param")) {
if (element.getName().equalsIgnoreCase(APEX_PARAM)) {
final List<ASTAttribute> innerAttributes = element.findChildrenOfType(ASTAttribute.class);
for (ASTAttribute attrib : innerAttributes) {
final ASTElExpression elInVal = attrib.getFirstDescendantOfType(ASTElExpression.class);

View File

@@ -13,7 +13,6 @@ 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;
import net.sourceforge.pmd.lang.vf.VfLanguageModule;
/**
* @author sergey.gorbaty
@@ -23,19 +22,16 @@ public class VfParserTest {
@Test
public void testSingleDoubleQuoteAndEL() {
Node node = parse(
"<span escape='false' attrib=\"{!call}\">${!yes}</span>");
Node node = parse("<span escape='false' attrib=\"{!call}\">${!yes}</span>");
Assert.assertNotNull(node);
}
@Test
public void testSingleDoubleQuote() {
Node node = parse(
"<span escape='false' attrib=\"{!call}\">${yes}</span>");
Node node = parse("<span escape='false' attrib=\"{!call}\">${yes}</span>");
Assert.assertNotNull(node);
}
private Node parse(String code) {
LanguageVersionHandler jspLang = LanguageRegistry.getLanguage(VfLanguageModule.NAME).getDefaultVersion()
.getLanguageVersionHandler();

View File

@@ -12,8 +12,6 @@ import java.util.Set;
import net.sourceforge.pmd.lang.ast.JavaCharStream;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.vf.ast.VfNode;
import net.sourceforge.pmd.lang.vf.ast.VfParser;
public abstract class AbstractVfNodesTest {

View File

@@ -10,9 +10,6 @@ import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import net.sourceforge.pmd.lang.vf.ast.ASTElement;
import net.sourceforge.pmd.lang.vf.ast.OpenTagRegister;
public class OpenTagRegisterTest {
private OpenTagRegister tagList;
@@ -112,7 +109,8 @@ public class OpenTagRegisterTest {
}
/**
* &lt;a&gt; &lt;x&gt; &lt;a&gt; &lt;b&gt; &lt;b&gt; &lt;/z&gt; &lt;/a&gt; &lt;/x&gt;
* &lt;a&gt; &lt;x&gt; &lt;a&gt; &lt;b&gt; &lt;b&gt; &lt;/z&gt; &lt;/a&gt;
* &lt;/x&gt;
*/
@Test
public void openedIsolatedTag() {

View File

@@ -19,17 +19,6 @@ import org.junit.Ignore;
import org.junit.Test;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.vf.ast.ASTAttribute;
import net.sourceforge.pmd.lang.vf.ast.ASTAttributeValue;
import net.sourceforge.pmd.lang.vf.ast.ASTCData;
import net.sourceforge.pmd.lang.vf.ast.ASTCommentTag;
import net.sourceforge.pmd.lang.vf.ast.ASTDoctypeDeclaration;
import net.sourceforge.pmd.lang.vf.ast.ASTDoctypeExternalId;
import net.sourceforge.pmd.lang.vf.ast.ASTElExpression;
import net.sourceforge.pmd.lang.vf.ast.ASTElement;
import net.sourceforge.pmd.lang.vf.ast.ASTHtmlScript;
import net.sourceforge.pmd.lang.vf.ast.ASTText;
import net.sourceforge.pmd.lang.vf.ast.VfNode;
/**
* Test parsing of a VF in document style, by checking the generated AST.

View File

@@ -5,10 +5,10 @@
package net.sourceforge.pmd.lang.vf.ast;
import static org.junit.Assert.assertEquals;
import java.util.Set;
import org.junit.Test;
import net.sourceforge.pmd.lang.vf.ast.ASTElExpression;
import java.util.Set;
import org.junit.Test;
public class VfPageStyleTest extends AbstractVfNodesTest {